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

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

traceログ機能を搭載
動的メンバをstl::vectorにまとめた
シンボルをクラス化した

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