source: dev/BasicCompiler_Common/src/Namespace.cpp@ 105

Last change on this file since 105 was 105, checked in by dai_9181, 17 years ago

名前空間収集モジュール(NamespaceScopesCollectionクラス)を追加。

File size: 3.1 KB
Line 
1#include "../common.h"
2
3
4NamespaceScopes::NamespaceScopes( const string &namespaceStr ){
5 int i = 0;
6 while( i < (int)namespaceStr.size() ){
7 char temporary[VN_SIZE];
8 for( int i2=0; ; i2++, i++ ){
9 if( namespaceStr[i] == '.' || namespaceStr[i] == '\0' ){
10 temporary[i2] = 0;
11 break;
12 }
13 temporary[i2] = namespaceStr[i];
14 }
15 push_back( temporary );
16
17 if( namespaceStr[i] == '.' ){
18 i++;
19 }
20 }
21}
22
23bool NamespaceScopes::IsLiving() const
24{
25 if( IsBelong( *this, Smoothie::Lexical::liveingNamespaceScopes ) ){
26 return true;
27 }
28 return false;
29}
30
31// 包括しているかをチェック
32// 例:
33// this = "Discoversoft.ActiveBasic"
34// living = "Discoversoft.ActiveBasic"
35// name = "ActiveBasic"
36// この場合、living は name を包括している。
37bool NamespaceScopes::IsCoverd( const string &name ) const
38{
39 if( IsEqual( name ) ){
40 return true;
41 }
42
43 string thisStr = ToString();
44
45 NamespaceScopes tempLivingNamespaceScopes = Smoothie::Lexical::liveingNamespaceScopes;
46
47 while( tempLivingNamespaceScopes.size() ){
48 NamespaceScopes tempNamespaceScopes = tempLivingNamespaceScopes;
49
50 string tempStr = tempNamespaceScopes.ToString() + "." + name;
51 if( thisStr == tempStr ){
52 return true;
53 }
54
55 tempLivingNamespaceScopes.pop_back();
56 }
57 return false;
58}
59bool NamespaceScopes::IsCoverd( const NamespaceScopes &namespaceScopes ) const
60{
61 return IsCoverd( namespaceScopes.ToString() );
62}
63
64
65void NamespaceScopesCollection::SplitNamespace( const char *fullName, char *namespaceStr, char *simpleName ) const
66{
67 NamespaceScopes namespaceScopes( fullName );
68 bool hasSimpleName = false;
69 while( namespaceScopes.size() > 0 ){
70 if( IsExist( namespaceScopes ) ){
71 break;
72 }
73 namespaceScopes.pop_back();
74
75 hasSimpleName = true;
76 }
77
78 lstrcpy( namespaceStr, namespaceScopes.ToString().c_str() );
79
80 bool hasNamespace = false;
81 if( namespaceStr[0] ){
82 hasNamespace = true;
83 }
84
85 int dotLength = 0;
86 if( hasSimpleName && hasNamespace ){
87 dotLength = 1;
88 }
89
90 lstrcpy( simpleName, fullName + lstrlen( namespaceStr ) + dotLength );
91}
92bool NamespaceScopesCollection::CollectNamespaces( const char *source, NamespaceScopesCollection &namespaceScopesCollection )
93{
94 int i, i2;
95 char temporary[VN_SIZE];
96
97 bool isSuccessful = true;
98
99 // 名前空間管理
100 NamespaceScopes namespaceScopes;
101
102 for(i=0;;i++){
103 if(source[i]=='\0') break;
104
105 if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
106 for(i+=2,i2=0;;i2++,i++){
107 if( IsCommandDelimitation( source[i] ) ){
108 temporary[i2]=0;
109 break;
110 }
111 temporary[i2]=source[i];
112 }
113 namespaceScopes.push_back( temporary );
114
115 if( !namespaceScopesCollection.IsExist( namespaceScopes ) ){
116 namespaceScopesCollection.push_back( namespaceScopes );
117 }
118
119 continue;
120 }
121 else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){
122 if( namespaceScopes.size() <= 0 ){
123 SetError(12, "End Namespace", i );
124 isSuccessful = false;
125 }
126 else{
127 namespaceScopes.pop_back();
128 }
129
130 i += 2;
131 continue;
132 }
133 }
134
135 if( namespaceScopes.size() > 0 ){
136 SetError(63,NULL,-1);
137 isSuccessful = false;
138 }
139
140 return isSuccessful;
141}
Note: See TracBrowser for help on using the repository browser.