source: dev/trunk/jenga/src/smoothie/TypeDef.cpp@ 181

Last change on this file since 181 was 181, checked in by dai_9181, 17 years ago
File size: 5.8 KB
Line 
1#include <jenga/include/smoothie/Smoothie.h>
2#include <jenga/include/smoothie/Class.h>
3#include <jenga/include/smoothie/TypeDef.h>
4#include <jenga/include/smoothie/SmoothieException.h>
5
6TypeDef::TypeDef( const NamespaceScopes &namespaceScopes, const string &name, const string &baseName, int nowLine )
7 : namespaceScopes( namespaceScopes )
8 , name( name )
9 , baseName( baseName )
10{
11 if( !Type::StringToType( baseName, baseType ) ){
12 throw SmoothieException(3, baseName, nowLine );
13 return;
14 }
15}
16TypeDef::~TypeDef(){
17}
18
19bool TypeDef::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const
20{
21 if( GetName() != name ){
22 return false;
23 }
24 return NamespaceScopes::IsSameArea( this->namespaceScopes, namespaceScopes );
25}
26bool TypeDef::IsEqualSymbol( const string &fullName ) const
27{
28 char AreaName[VN_SIZE] = ""; //オブジェクト変数
29 char NestName[VN_SIZE] = ""; //入れ子メンバ
30 bool isNest = CClass::SplitName( fullName.c_str(), AreaName, NestName );
31
32 if( IsEqualSymbol( NamespaceScopes( AreaName ), NestName ) ){
33 return true;
34 }
35
36 if( isNest ){
37 // 静的メンバを考慮
38
39 char AreaName2[VN_SIZE] = ""; //オブジェクト変数
40 char NestName2[VN_SIZE] = ""; //入れ子メンバ
41 bool isNest = CClass::SplitName( AreaName, AreaName2, NestName2 );
42 lstrcat( NestName2, "." );
43 lstrcat( NestName2, NestName );
44
45 return IsEqualSymbol( NamespaceScopes( AreaName2 ), NestName2 );
46 }
47
48 return false;
49}
50
51
52
53TypeDefCollection::TypeDefCollection(){
54}
55TypeDefCollection::~TypeDefCollection(){
56}
57void TypeDefCollection::Add( const NamespaceScopes &namespaceScopes, const string &name, const string &baseName, int nowLine ){
58 TypeDef typeDef( namespaceScopes, name, baseName, nowLine );
59 this->push_back( typeDef );
60}
61int TypeDefCollection::GetIndex( const NamespaceScopes &namespaceScopes, const string &name ) const{
62 int max = (int)(*this).size();
63 for( int i=0; i<max; i++ ){
64 if( (*this)[i].IsEqualSymbol( namespaceScopes, name ) ){
65 return i;
66 }
67 }
68 return -1;
69}
70int TypeDefCollection::GetIndex( const string &fullName ) const{
71 char AreaName[VN_SIZE] = ""; //オブジェクト変数
72 char NestName[VN_SIZE] = ""; //入れ子メンバ
73 bool isNest = CClass::SplitName( fullName.c_str(), AreaName, NestName );
74
75 return GetIndex( NamespaceScopes( AreaName ), NestName );
76}
77
78void TypeDefCollection::Add( const NamespaceScopes &namespaceScopes, const string &expression, int nowLine ){
79 int i;
80 char temporary[VN_SIZE];
81
82 for(i=0;;i++){
83 if(expression[i]=='='||expression[i]=='\0'){
84 temporary[i]=0;
85 break;
86 }
87 temporary[i]=expression[i];
88 }
89
90 if(expression[i]!='='){
91 throw SmoothieException(10,"TypeDef",nowLine);
92 return;
93 }
94
95 const char *pTemp=expression.c_str()+i+1;
96
97 //識別文字のエラーチェック(新しい型)
98 i=0;
99 for(;;i++){
100 if(temporary[i]=='\0') break;
101 if(!IsVariableChar(temporary[i])){
102 throw SmoothieException(10,"TypeDef",nowLine);
103 return;
104 }
105 }
106
107 //識別文字のエラーチェック(コピー元の型)
108 if(pTemp[0]=='*'&&pTemp[1]==1&&(pTemp[2]==ESC_FUNCTION||pTemp[2]==ESC_SUB)){
109 //関数ポインタ
110 if(pTemp[3]!='('){
111 throw SmoothieException(10,"TypeDef",nowLine);
112 return;
113 }
114 }
115 else{
116 i=0;
117 while(pTemp[i]=='*') i++;
118 for(;;i++){
119 if(pTemp[i]=='\0') break;
120 if(!IsVariableChar(pTemp[i])){
121 throw SmoothieException(10,"TypeDef",nowLine);
122 return;
123 }
124 }
125 }
126
127 //識別子が重複している場合はエラーにする
128 if(lstrcmp(temporary,pTemp)==0){
129 throw SmoothieException(1,NULL,nowLine);
130 return;
131 }
132
133
134
135 //////////////////////////
136 // TypeDef情報を追加
137 //////////////////////////
138
139 Add( namespaceScopes, temporary, pTemp, nowLine );
140}
141
142void TypeDefCollection::Init(){
143 // 初期化
144 clear();
145
146 // 名前空間管理
147 NamespaceScopes &namespaceScopes = Smoothie::Temp::liveingNamespaceScopes;
148 namespaceScopes.clear();
149
150 // Importsされた名前空間の管理
151 NamespaceScopesCollection &importedNamespaces = Smoothie::Temp::importedNamespaces;
152 importedNamespaces.clear();
153
154 int i=-1, i2;
155 char temporary[VN_SIZE];
156 while(1){
157 extern char *basbuf;
158
159 i++;
160
161 if( basbuf[i] == 1 && basbuf[i+1] == ESC_NAMESPACE ){
162 for(i+=2,i2=0;;i2++,i++){
163 if( IsCommandDelimitation( basbuf[i] ) ){
164 temporary[i2]=0;
165 break;
166 }
167 temporary[i2]=basbuf[i];
168 }
169 namespaceScopes.push_back( temporary );
170
171 continue;
172 }
173 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENDNAMESPACE ){
174 if( namespaceScopes.size() <= 0 ){
175 throw SmoothieException(12, "End Namespace", i );
176 }
177 else{
178 namespaceScopes.pop_back();
179 }
180
181 i += 2;
182 continue;
183 }
184 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPORTS ){
185 for(i+=2,i2=0;;i2++,i++){
186 if( IsCommandDelimitation( basbuf[i] ) ){
187 temporary[i2]=0;
188 break;
189 }
190 temporary[i2]=basbuf[i];
191 }
192 if( !importedNamespaces.Imports( temporary ) )
193 {
194 throw SmoothieException(64,temporary,i );
195 }
196
197 continue;
198 }
199 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
200 importedNamespaces.clear();
201 continue;
202 }
203
204 if( basbuf[i]==1 ){
205 char temporary[VN_SIZE];
206 if(basbuf[i+1]==ESC_TYPEDEF){
207 int i2 = 0;
208 for(i+=2;;i2++,i++){
209 if(basbuf[i]=='\n'){
210 temporary[i2]=0;
211 break;
212 }
213 temporary[i2]=basbuf[i];
214 if(basbuf[i]=='\0') break;
215 }
216 Add( namespaceScopes, temporary, i );
217
218 continue;
219 }
220 else if( basbuf[i+1] == ESC_CONST && basbuf[i+2] == 1 && basbuf[i+3] == ESC_ENUM ){
221 int i2 = 0;
222 for(i+=4;;i2++,i++){
223 if(!IsVariableChar(basbuf[i])){
224 temporary[i2]=0;
225 break;
226 }
227 temporary[i2]=basbuf[i];
228 if(basbuf[i]=='\0') break;
229 }
230 Add( namespaceScopes, temporary, "Long", i );
231 }
232 }
233
234 //次の行
235 for(;;i++){
236 if(IsCommandDelimitation(basbuf[i])) break;
237 }
238 if(basbuf[i]=='\0') break;
239 }
240}
Note: See TracBrowser for help on using the repository browser.