source: dev/trunk/jenga/src/smoothie/Namespace.cpp@ 183

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