1 | #include <jenga/include/smoothie/Class.h>
|
---|
2 | #include <jenga/include/smoothie/SmoothieException.h>
|
---|
3 |
|
---|
4 | string UserProc::GetFullName() const
|
---|
5 | {
|
---|
6 | if( HasParentClass() ){
|
---|
7 | return GetParentClass().GetName() + "." + GetName();
|
---|
8 | }
|
---|
9 |
|
---|
10 | return GetName();
|
---|
11 | }
|
---|
12 | /*
|
---|
13 | bool UserProc::SetParamsAndReturnType( const char *sourceOfParams, int nowLine, bool isStatic ){
|
---|
14 | int i = 0;
|
---|
15 | int i2,i3,sw;
|
---|
16 | char temporary[8192],temp2[VN_SIZE];
|
---|
17 |
|
---|
18 | //ソースコードの位置
|
---|
19 | this->codePos = nowLine;
|
---|
20 |
|
---|
21 | //パラメータ
|
---|
22 | if(sourceOfParams[i]!='('){
|
---|
23 | throw SmoothieException(1,NULL,nowLine);
|
---|
24 | return 0;
|
---|
25 | }
|
---|
26 | i++;
|
---|
27 | if(sourceOfParams[i]!=')'&& this->pParentClass ){
|
---|
28 | //クラスのメンバ関数の場合のみ、デストラクタにパラメータがある場合にエラーをだす
|
---|
29 | if(this->GetName()[0]=='~'){
|
---|
30 | throw SmoothieException(114,NULL,nowLine);
|
---|
31 | i=JumpStringInPare(sourceOfParams,i);
|
---|
32 | }
|
---|
33 | }
|
---|
34 | while(1){
|
---|
35 | if(sourceOfParams[i]==')') break;
|
---|
36 |
|
---|
37 | //ByRef
|
---|
38 | bool isRef;
|
---|
39 | if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){
|
---|
40 | isRef = false;
|
---|
41 | i+=2;
|
---|
42 | }
|
---|
43 | else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){
|
---|
44 | isRef = true;
|
---|
45 | i+=2;
|
---|
46 | }
|
---|
47 | else isRef = false;
|
---|
48 |
|
---|
49 | //パラメータ名
|
---|
50 | bool isArray = false;
|
---|
51 | int subScripts[MAX_ARRAYDIM];
|
---|
52 | char name[VN_SIZE];
|
---|
53 | sw=0;
|
---|
54 | for(i2=0;;i++,i2++){
|
---|
55 | if(sourceOfParams[i]=='('){
|
---|
56 | if(!sw) sw=1;
|
---|
57 |
|
---|
58 | i3=GetStringInPare(name+i2,sourceOfParams+i);
|
---|
59 | i2+=i3-1;
|
---|
60 | i+=i3-1;
|
---|
61 | continue;
|
---|
62 | }
|
---|
63 | if(sourceOfParams[i]=='['){
|
---|
64 | if(!sw) sw=1;
|
---|
65 |
|
---|
66 | i3=GetStringInBracket(name+i2,sourceOfParams+i);
|
---|
67 | i2+=i3-1;
|
---|
68 | i+=i3-1;
|
---|
69 | continue;
|
---|
70 | }
|
---|
71 | if(!IsVariableChar(sourceOfParams[i])){
|
---|
72 | name[i2]=0;
|
---|
73 | break;
|
---|
74 | }
|
---|
75 | name[i2]=sourceOfParams[i];
|
---|
76 | }
|
---|
77 | if(sw){
|
---|
78 | //配列パラメータ
|
---|
79 | if( isRef == false ) throw SmoothieException(29,NULL,nowLine);
|
---|
80 | isArray = true;
|
---|
81 |
|
---|
82 | if((name[i2-2]=='('&&name[i2-1]==')')||
|
---|
83 | (name[i2-2]=='['&&name[i2-1]==']')){
|
---|
84 | subScripts[0]=LONG_MAX;
|
---|
85 | subScripts[1]=-1;
|
---|
86 |
|
---|
87 | name[i2-2]=0;
|
---|
88 | }
|
---|
89 | else{
|
---|
90 | GetArrange(name,temp2,subScripts);
|
---|
91 | lstrcpy(name,temp2);
|
---|
92 | }
|
---|
93 |
|
---|
94 | i2=lstrlen(name);
|
---|
95 | }
|
---|
96 |
|
---|
97 | Type type( DEF_NON );
|
---|
98 | char initValue[8192] = "";
|
---|
99 | if( sourceOfParams[i] == '=' ){
|
---|
100 | i++;
|
---|
101 | i = GetOneParameter( sourceOfParams, i, initValue );
|
---|
102 |
|
---|
103 | //エラー用
|
---|
104 | cp = nowLine;
|
---|
105 |
|
---|
106 | NumOpe_GetType( initValue, Type::String(), type );
|
---|
107 | }
|
---|
108 | else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){
|
---|
109 | // As指定
|
---|
110 | i+=2;
|
---|
111 |
|
---|
112 | i2=0;
|
---|
113 | while(sourceOfParams[i]=='*'){
|
---|
114 | temporary[i2]=sourceOfParams[i];
|
---|
115 | i++;
|
---|
116 | i2++;
|
---|
117 | }
|
---|
118 | for(;;i++,i2++){
|
---|
119 | if(!IsVariableChar(sourceOfParams[i])){
|
---|
120 | if(sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){
|
---|
121 | temporary[i2++]=sourceOfParams[i++];
|
---|
122 | temporary[i2]=sourceOfParams[i];
|
---|
123 | continue;
|
---|
124 | }
|
---|
125 | temporary[i2]=0;
|
---|
126 | break;
|
---|
127 | }
|
---|
128 | temporary[i2]=sourceOfParams[i];
|
---|
129 | }
|
---|
130 |
|
---|
131 | Type::StringToType( temporary, type );
|
---|
132 |
|
---|
133 | if( type.IsNull() ){
|
---|
134 | throw SmoothieException(3,temporary,nowLine);
|
---|
135 | type.SetBasicType( DEF_PTR_VOID );
|
---|
136 | }
|
---|
137 |
|
---|
138 | if( type.IsObject() ){
|
---|
139 | if( type.GetClass().IsBlittableType() ){
|
---|
140 | // Blittable型のときは基本型として扱う
|
---|
141 | type = type.GetClass().GetBlittableType();
|
---|
142 | }
|
---|
143 | }
|
---|
144 | }
|
---|
145 | else{
|
---|
146 | type.SetBasicType( Type::GetBasicTypeFromSimpleName(temporary) );
|
---|
147 | throw SmoothieException(-103,temporary,nowLine);
|
---|
148 | }
|
---|
149 |
|
---|
150 | Parameter *pParam = new Parameter( name, type, isRef, initValue );
|
---|
151 | if( isArray ){
|
---|
152 | pParam->SetArray( subScripts );
|
---|
153 | }
|
---|
154 |
|
---|
155 | //パラメータを追加
|
---|
156 | this->params.push_back( pParam );
|
---|
157 |
|
---|
158 | if(sourceOfParams[i]==','){
|
---|
159 | i++;
|
---|
160 | continue;
|
---|
161 | }
|
---|
162 | else if(sourceOfParams[i]==')') continue;
|
---|
163 | else{
|
---|
164 | throw SmoothieException(1,NULL,nowLine);
|
---|
165 | break;
|
---|
166 | }
|
---|
167 | }
|
---|
168 | this->secondParmNum = (int)this->params.size();
|
---|
169 | i++;
|
---|
170 | if(sourceOfParams[i]=='('){
|
---|
171 | i++;
|
---|
172 | while(1){
|
---|
173 | if(sourceOfParams[i]==')') break;
|
---|
174 |
|
---|
175 | //ByRef
|
---|
176 | bool isRef;
|
---|
177 | if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){
|
---|
178 | isRef = false;
|
---|
179 | i+=2;
|
---|
180 | }
|
---|
181 | else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){
|
---|
182 | isRef = true;
|
---|
183 | i+=2;
|
---|
184 | }
|
---|
185 | else isRef = false;
|
---|
186 |
|
---|
187 | //パラメータ名
|
---|
188 | bool isArray = false;
|
---|
189 | int subScripts[MAX_ARRAYDIM];
|
---|
190 | char name[VN_SIZE];
|
---|
191 | sw=0;
|
---|
192 | for(i2=0;;i++,i2++){
|
---|
193 | if(sourceOfParams[i]=='('){
|
---|
194 | if(!sw) sw=1;
|
---|
195 |
|
---|
196 | i3=GetStringInPare(name+i2,sourceOfParams+i);
|
---|
197 | i2+=i3-1;
|
---|
198 | i+=i3-1;
|
---|
199 | continue;
|
---|
200 | }
|
---|
201 | if(sourceOfParams[i]=='['){
|
---|
202 | if(!sw) sw=1;
|
---|
203 |
|
---|
204 | i3=GetStringInBracket(name+i2,sourceOfParams+i);
|
---|
205 | i2+=i3-1;
|
---|
206 | i+=i3-1;
|
---|
207 | continue;
|
---|
208 | }
|
---|
209 | if(!IsVariableChar(sourceOfParams[i])){
|
---|
210 | name[i2]=0;
|
---|
211 | break;
|
---|
212 | }
|
---|
213 | name[i2]=sourceOfParams[i];
|
---|
214 | }
|
---|
215 | if(sw){
|
---|
216 | //配列パラメータ
|
---|
217 | if( isRef == false ) throw SmoothieException(29,NULL,nowLine);
|
---|
218 | isArray = true;
|
---|
219 |
|
---|
220 | if((name[i2-2]=='('&&name[i2-1]==')')||
|
---|
221 | (name[i2-2]=='['&&name[i2-1]==']')){
|
---|
222 | subScripts[0]=LONG_MAX;
|
---|
223 | subScripts[1]=-1;
|
---|
224 |
|
---|
225 | name[i2-2]=0;
|
---|
226 | }
|
---|
227 | else{
|
---|
228 | GetArrange(name,temp2,subScripts);
|
---|
229 | lstrcpy(name,temp2);
|
---|
230 | }
|
---|
231 |
|
---|
232 | i2=lstrlen(name);
|
---|
233 | }
|
---|
234 |
|
---|
235 | //型
|
---|
236 | Type type( DEF_NON );
|
---|
237 | if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){
|
---|
238 | i+=2;
|
---|
239 |
|
---|
240 | i2=0;
|
---|
241 | while(sourceOfParams[i]=='*'){
|
---|
242 | temporary[i2]=sourceOfParams[i];
|
---|
243 | i++;
|
---|
244 | i2++;
|
---|
245 | }
|
---|
246 | for(;;i++,i2++){
|
---|
247 | if(!IsVariableChar(sourceOfParams[i])){
|
---|
248 | if(sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){
|
---|
249 | temporary[i2++]=sourceOfParams[i++];
|
---|
250 | temporary[i2]=sourceOfParams[i];
|
---|
251 | continue;
|
---|
252 | }
|
---|
253 | temporary[i2]=0;
|
---|
254 | break;
|
---|
255 | }
|
---|
256 | temporary[i2]=sourceOfParams[i];
|
---|
257 | }
|
---|
258 |
|
---|
259 | Type::StringToType( temporary, type );
|
---|
260 |
|
---|
261 | if( type.IsNull() ){
|
---|
262 | throw SmoothieException(3,temporary,nowLine);
|
---|
263 | type.SetBasicType( DEF_PTR_VOID );
|
---|
264 | }
|
---|
265 | }
|
---|
266 | else{
|
---|
267 | type.SetBasicType( Type::GetBasicTypeFromSimpleName(temporary) );
|
---|
268 | throw SmoothieException(-103,temporary,nowLine);
|
---|
269 | }
|
---|
270 |
|
---|
271 | Parameter *pParam = new Parameter( name, type, isRef );
|
---|
272 | if( isArray ){
|
---|
273 | pParam->SetArray( subScripts );
|
---|
274 | }
|
---|
275 |
|
---|
276 | //パラメータを追加
|
---|
277 | this->params.push_back( pParam );
|
---|
278 |
|
---|
279 | if(sourceOfParams[i]==','){
|
---|
280 | i++;
|
---|
281 | continue;
|
---|
282 | }
|
---|
283 | else if(sourceOfParams[i]==')') continue;
|
---|
284 | else{
|
---|
285 | throw SmoothieException(1,NULL,nowLine);
|
---|
286 | break;
|
---|
287 | }
|
---|
288 | }
|
---|
289 | i++;
|
---|
290 | }
|
---|
291 |
|
---|
292 | if(sourceOfParams[i]){
|
---|
293 | ///////////////////
|
---|
294 | // 戻り値を取得
|
---|
295 | ///////////////////
|
---|
296 |
|
---|
297 | if( !this->IsFunction() ){
|
---|
298 | // Sub/Macroの場合
|
---|
299 | throw SmoothieException(38,this->GetName(),nowLine);
|
---|
300 | }
|
---|
301 |
|
---|
302 | if( this->pParentClass ){
|
---|
303 | if( this->GetName() == this->pParentClass->GetName() ||
|
---|
304 | this->GetName()[0]=='~'){
|
---|
305 | //クラスのコンストラクタ、デストラクタがFunction定義の場合はエラーをだす
|
---|
306 | throw SmoothieException(115,NULL,nowLine);
|
---|
307 | }
|
---|
308 | }
|
---|
309 |
|
---|
310 |
|
---|
311 | i2=lstrlen(sourceOfParams)-2;
|
---|
312 |
|
---|
313 | int sw_as=0;
|
---|
314 | for(;i2>0;i2--){
|
---|
315 | if(sourceOfParams[i2]==')') break;
|
---|
316 |
|
---|
317 | if(sourceOfParams[i2]==1&&sourceOfParams[i2+1]==ESC_AS){
|
---|
318 | i2+=2;
|
---|
319 | i3=0;
|
---|
320 | while(sourceOfParams[i2]=='*') temporary[i3++]=sourceOfParams[i2++];
|
---|
321 | for(;;i2++,i3++){
|
---|
322 | if(!IsVariableChar(sourceOfParams[i2])){
|
---|
323 | temporary[i3]=0;
|
---|
324 | break;
|
---|
325 | }
|
---|
326 | temporary[i3]=sourceOfParams[i2];
|
---|
327 | }
|
---|
328 | Type::StringToType( temporary, this->returnType );
|
---|
329 | if( this->returnType.IsNull() ) throw SmoothieException(3,temporary,nowLine);
|
---|
330 |
|
---|
331 | sw_as=1;
|
---|
332 | break;
|
---|
333 | }
|
---|
334 | }
|
---|
335 |
|
---|
336 | if(!sw_as){
|
---|
337 | throw SmoothieException(-104,this->GetName().c_str(),nowLine);
|
---|
338 |
|
---|
339 | this->returnType.SetBasicType( DEF_DOUBLE );
|
---|
340 | }
|
---|
341 | }
|
---|
342 | else{
|
---|
343 | //戻り値なしのSub定義
|
---|
344 | this->returnType.SetNull();
|
---|
345 | }
|
---|
346 |
|
---|
347 | //リアルパラメータ領域を取得(_System_LocalThisを考慮して2つだけ多く確保する場合がある)
|
---|
348 |
|
---|
349 | if( this->pParentClass && isStatic == false ){
|
---|
350 | //オブジェクトメンバの場合は、第一パラメータを_System_LocalThis引き渡し用として利用
|
---|
351 | string name = "_System_LocalThis";
|
---|
352 | Type type( DEF_PTR_VOID );
|
---|
353 | this->realParams.push_back( new Parameter( name, type ) );
|
---|
354 | }
|
---|
355 |
|
---|
356 | if( this->returnType.IsStruct() ){
|
---|
357 | //構造体を戻り値として持つ場合
|
---|
358 | //※第一パラメータ(Thisポインタありの場合は第二パラメータ)を戻り値用の参照宣言にする
|
---|
359 |
|
---|
360 | string name = this->GetName();
|
---|
361 | if(name[0]==1&&name[1]==ESC_OPERATOR){
|
---|
362 | name="_System_ReturnValue";
|
---|
363 | }
|
---|
364 | Type type( DEF_STRUCT, this->returnType.GetIndex() );
|
---|
365 | this->realParams.push_back( new Parameter( name, type, true ) );
|
---|
366 | }
|
---|
367 |
|
---|
368 | //パラメータをコピー
|
---|
369 | foreach( Parameter *pParam, params ){
|
---|
370 | this->realParams.push_back( new Parameter( *pParam ) );
|
---|
371 | }
|
---|
372 |
|
---|
373 | return true;
|
---|
374 | }*/
|
---|
375 | bool UserProc::IsVirtual() const
|
---|
376 | {
|
---|
377 | if( pMethod == NULL ){
|
---|
378 | return false;
|
---|
379 | }
|
---|
380 | return ( pMethod->IsVirtual() != 0 );
|
---|
381 | }
|
---|
382 | const NamespaceScopes &UserProc::GetNamespaceScopes() const
|
---|
383 | {
|
---|
384 | if( !pParentClass ){
|
---|
385 | throw SmoothieException();
|
---|
386 | }
|
---|
387 | return pParentClass->GetNamespaceScopes();
|
---|
388 | }
|
---|
389 | const NamespaceScopesCollection &UserProc::GetImportedNamespaces() const
|
---|
390 | {
|
---|
391 | if( !pParentClass ){
|
---|
392 | throw SmoothieException();
|
---|
393 | }
|
---|
394 | return pParentClass->GetImportedNamespaces();
|
---|
395 | }
|
---|
396 | bool UserProc::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const
|
---|
397 | {
|
---|
398 | throw SmoothieException();
|
---|
399 | return false;
|
---|
400 | }
|
---|
401 |
|
---|
402 | /*
|
---|
403 | GlobalProc *GlobalProc::Create( const NamespaceScopes &namespaceScopes, char *buffer,int nowLine ){
|
---|
404 | int i2;
|
---|
405 | char temporary[8192];
|
---|
406 |
|
---|
407 | int i=1;
|
---|
408 |
|
---|
409 | Procedure::Kind kind = Procedure::Sub;
|
---|
410 | bool isMacro = false;
|
---|
411 | if(buffer[i]==ESC_FUNCTION) kind = Procedure::Function;
|
---|
412 | if(buffer[i]==ESC_MACRO){
|
---|
413 | isMacro = true;
|
---|
414 | }
|
---|
415 |
|
---|
416 | i++;
|
---|
417 |
|
---|
418 | bool isCdecl = false;
|
---|
419 | bool isExport = false;
|
---|
420 | while(1){
|
---|
421 | if(buffer[i]==1&&buffer[i+1]==ESC_CDECL&& isCdecl == false ){
|
---|
422 | isCdecl = true;
|
---|
423 |
|
---|
424 | i+=2;
|
---|
425 | }
|
---|
426 | else if(buffer[i]==1&&buffer[i+1]==ESC_EXPORT&& isExport == false ){
|
---|
427 | isExport = true;
|
---|
428 |
|
---|
429 | i+=2;
|
---|
430 | }
|
---|
431 | else break;
|
---|
432 | }
|
---|
433 |
|
---|
434 | i2=0;
|
---|
435 | if(buffer[i]==1&&buffer[i+1]==ESC_OPERATOR){
|
---|
436 | throw SmoothieException(126,NULL,nowLine);
|
---|
437 | return 0;
|
---|
438 | }
|
---|
439 | else{
|
---|
440 | for(;;i++,i2++){
|
---|
441 | if(!IsVariableChar(buffer[i])){
|
---|
442 | temporary[i2]=0;
|
---|
443 | break;
|
---|
444 | }
|
---|
445 | temporary[i2]=buffer[i];
|
---|
446 | }
|
---|
447 | }
|
---|
448 |
|
---|
449 | if( isMacro ){
|
---|
450 | //大文字に変換
|
---|
451 | CharUpper(temporary);
|
---|
452 |
|
---|
453 | //マクロ関数の場合は名前リストに追加
|
---|
454 | extern char **ppMacroNames;
|
---|
455 | extern int MacroNum;
|
---|
456 | ppMacroNames=(char **)HeapReAlloc(hHeap,0,ppMacroNames,(MacroNum+1)*sizeof(char *));
|
---|
457 | ppMacroNames[MacroNum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
|
---|
458 | lstrcpy(ppMacroNames[MacroNum],temporary);
|
---|
459 | MacroNum++;
|
---|
460 | }
|
---|
461 |
|
---|
462 | //重複チェック
|
---|
463 | if(GetDeclareHash(temporary)){
|
---|
464 | throw SmoothieException(15,temporary,nowLine);
|
---|
465 | return 0;
|
---|
466 | }
|
---|
467 |
|
---|
468 | extern int SubNum;
|
---|
469 | SubNum++;
|
---|
470 |
|
---|
471 | GlobalProc *pGlobalProc = new GlobalProc( namespaceScopes, temporary, kind, isMacro, isCdecl, isExport );
|
---|
472 |
|
---|
473 | //ID
|
---|
474 | static int id_base=0;
|
---|
475 | pGlobalProc->id = (id_base++);
|
---|
476 |
|
---|
477 | if(isExport){
|
---|
478 | pGlobalProc->Using();
|
---|
479 | }
|
---|
480 |
|
---|
481 | // パラメータを解析
|
---|
482 | // ※第1パラメータにに指定するデータの例:"( s As String ) As String"
|
---|
483 | pGlobalProc->SetParamsAndReturnType( buffer + i, nowLine, true );
|
---|
484 |
|
---|
485 |
|
---|
486 | pGlobalProc->_paramStr = buffer + i;
|
---|
487 |
|
---|
488 |
|
---|
489 |
|
---|
490 | return pGlobalProc;
|
---|
491 | }
|
---|
492 | bool GlobalProc::AddGlobalProc( const NamespaceScopes &namespaceScopes, char *buffer,int nowLine ){
|
---|
493 | GlobalProc *pGlobalProc = Create( namespaceScopes, buffer, nowLine );
|
---|
494 | if( pGlobalProc == NULL ){
|
---|
495 | return false;
|
---|
496 | }
|
---|
497 |
|
---|
498 |
|
---|
499 | /////////////////////////////////
|
---|
500 | // ハッシュデータに追加
|
---|
501 | /////////////////////////////////
|
---|
502 |
|
---|
503 | int key;
|
---|
504 | key=hash_default(pGlobalProc->GetName().c_str());
|
---|
505 |
|
---|
506 | extern GlobalProc **ppSubHash;
|
---|
507 | if(ppSubHash[key]){
|
---|
508 | GlobalProc *psi2;
|
---|
509 | psi2=ppSubHash[key];
|
---|
510 | while(1){
|
---|
511 | //重複エラーチェックを行う
|
---|
512 | if( pGlobalProc->GetName() == psi2->GetName() ){
|
---|
513 | if( Parameter::Equals( psi2->Params(), pGlobalProc->Params() ) ){
|
---|
514 | throw SmoothieException(15,pGlobalProc->GetName().c_str(),nowLine);
|
---|
515 | return 0;
|
---|
516 | }
|
---|
517 | }
|
---|
518 |
|
---|
519 | if(psi2->pNextData==0) break;
|
---|
520 | psi2=psi2->pNextData;
|
---|
521 | }
|
---|
522 | psi2->pNextData=pGlobalProc;
|
---|
523 | }
|
---|
524 | else{
|
---|
525 | ppSubHash[key]=pGlobalProc;
|
---|
526 | }
|
---|
527 |
|
---|
528 | return true;
|
---|
529 | }*/
|
---|
530 | const NamespaceScopes &GlobalProc::GetNamespaceScopes() const
|
---|
531 | {
|
---|
532 | if( HasParentClass() ){
|
---|
533 | return GetParentClassPtr()->GetNamespaceScopes();
|
---|
534 | }
|
---|
535 | return namespaceScopes;
|
---|
536 | }
|
---|
537 | bool GlobalProc::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const
|
---|
538 | {
|
---|
539 | if( GetName() != name ){
|
---|
540 | return false;
|
---|
541 | }
|
---|
542 |
|
---|
543 | return NamespaceScopes::IsSameArea( GetNamespaceScopes(), namespaceScopes );
|
---|
544 | }
|
---|
545 | bool GlobalProc::IsEqualSymbol( const GlobalProc &globalProc ) const
|
---|
546 | {
|
---|
547 | return IsEqualSymbol( globalProc.GetNamespaceScopes(), globalProc.GetName() );
|
---|
548 | }
|
---|
549 | bool GlobalProc::IsEqualSymbol( const string &fullName ) const
|
---|
550 | {
|
---|
551 | char AreaName[VN_SIZE] = ""; //オブジェクト変数
|
---|
552 | char NestName[VN_SIZE] = ""; //入れ子メンバ
|
---|
553 | bool isNest = CClass::SplitName( fullName.c_str(), AreaName, NestName );
|
---|
554 |
|
---|
555 | return IsEqualSymbol( NamespaceScopes( AreaName ), NestName );
|
---|
556 | }
|
---|
557 |
|
---|
558 | bool DllProc::IsEqualSymbol( const NamespaceScopes &namespaceScopes, const string &name ) const
|
---|
559 | {
|
---|
560 | if( GetName() != name ){
|
---|
561 | return false;
|
---|
562 | }
|
---|
563 | return NamespaceScopes::IsSameArea( this->namespaceScopes, namespaceScopes );
|
---|
564 | }
|
---|
565 | bool DllProc::IsEqualSymbol( const string &fullName ) const
|
---|
566 | {
|
---|
567 | char AreaName[VN_SIZE] = ""; //オブジェクト変数
|
---|
568 | char NestName[VN_SIZE] = ""; //入れ子メンバ
|
---|
569 | bool isNest = CClass::SplitName( fullName.c_str(), AreaName, NestName );
|
---|
570 |
|
---|
571 | if( IsEqualSymbol( NamespaceScopes( AreaName ), NestName ) ){
|
---|
572 | return true;
|
---|
573 | }
|
---|
574 |
|
---|
575 | if( isNest ){
|
---|
576 | // 静的メンバを考慮
|
---|
577 |
|
---|
578 | char AreaName2[VN_SIZE] = ""; //オブジェクト変数
|
---|
579 | char NestName2[VN_SIZE] = ""; //入れ子メンバ
|
---|
580 | bool isNest = CClass::SplitName( AreaName, AreaName2, NestName2 );
|
---|
581 | lstrcat( NestName2, "." );
|
---|
582 | lstrcat( NestName2, NestName );
|
---|
583 |
|
---|
584 | return IsEqualSymbol( NamespaceScopes( AreaName2 ), NestName2 );
|
---|
585 | }
|
---|
586 |
|
---|
587 | return false;
|
---|
588 | }
|
---|
589 |
|
---|
590 |
|
---|
591 | bool DllProc::SetParamsAndReturnType( const char *sourceOfParams, int nowLine ){
|
---|
592 | int i = 0;
|
---|
593 | int i2,i3,sw;
|
---|
594 | char temporary[8192],temp2[VN_SIZE];
|
---|
595 |
|
---|
596 | //ソースコードの位置
|
---|
597 | this->codePos = nowLine;
|
---|
598 |
|
---|
599 | //パラメータ
|
---|
600 | if(sourceOfParams[i]!='('){
|
---|
601 | throw SmoothieException(1,NULL,nowLine);
|
---|
602 | return 0;
|
---|
603 | }
|
---|
604 | i++;
|
---|
605 |
|
---|
606 | while(1){
|
---|
607 | if(sourceOfParams[i]==')') break;
|
---|
608 |
|
---|
609 | //ByRef
|
---|
610 | bool isRef;
|
---|
611 | if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){
|
---|
612 | isRef = false;
|
---|
613 | i+=2;
|
---|
614 | }
|
---|
615 | else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){
|
---|
616 | isRef = true;
|
---|
617 | i+=2;
|
---|
618 | }
|
---|
619 | else isRef = false;
|
---|
620 |
|
---|
621 | //パラメータ名
|
---|
622 | bool isArray = false;
|
---|
623 | int subScripts[MAX_ARRAYDIM];
|
---|
624 | char name[VN_SIZE];
|
---|
625 | sw=0;
|
---|
626 | for(i2=0;;i++,i2++){
|
---|
627 | if(sourceOfParams[i]=='('){
|
---|
628 | if(!sw) sw=1;
|
---|
629 |
|
---|
630 | i3=GetStringInPare(name+i2,sourceOfParams+i);
|
---|
631 | i2+=i3-1;
|
---|
632 | i+=i3-1;
|
---|
633 | continue;
|
---|
634 | }
|
---|
635 | if(sourceOfParams[i]=='['){
|
---|
636 | if(!sw) sw=1;
|
---|
637 |
|
---|
638 | i3=GetStringInBracket(name+i2,sourceOfParams+i);
|
---|
639 | i2+=i3-1;
|
---|
640 | i+=i3-1;
|
---|
641 | continue;
|
---|
642 | }
|
---|
643 | if(!IsVariableChar(sourceOfParams[i])){
|
---|
644 | name[i2]=0;
|
---|
645 | break;
|
---|
646 | }
|
---|
647 | name[i2]=sourceOfParams[i];
|
---|
648 | }
|
---|
649 | if(sw){
|
---|
650 | //配列パラメータ
|
---|
651 | if( isRef == false ) throw SmoothieException(29,NULL,nowLine);
|
---|
652 | isArray = true;
|
---|
653 |
|
---|
654 | if((name[i2-2]=='('&&name[i2-1]==')')||
|
---|
655 | (name[i2-2]=='['&&name[i2-1]==']')){
|
---|
656 | subScripts[0]=LONG_MAX;
|
---|
657 | subScripts[1]=-1;
|
---|
658 |
|
---|
659 | name[i2-2]=0;
|
---|
660 | }
|
---|
661 | else{
|
---|
662 | GetArrange(name,temp2,subScripts);
|
---|
663 | lstrcpy(name,temp2);
|
---|
664 | }
|
---|
665 |
|
---|
666 | i2=lstrlen(name);
|
---|
667 | }
|
---|
668 |
|
---|
669 | //型
|
---|
670 | Type type( DEF_NON );
|
---|
671 | if(lstrcmp(name,"...")==0) type.SetBasicType( DEF_ELLIPSE );
|
---|
672 | else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){
|
---|
673 | i+=2;
|
---|
674 |
|
---|
675 | i2=0;
|
---|
676 | while(sourceOfParams[i]=='*'){
|
---|
677 | temporary[i2]=sourceOfParams[i];
|
---|
678 | i++;
|
---|
679 | i2++;
|
---|
680 | }
|
---|
681 | for(;;i++,i2++){
|
---|
682 | if(!IsVariableChar(sourceOfParams[i])){
|
---|
683 | if(sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){
|
---|
684 | temporary[i2++]=sourceOfParams[i++];
|
---|
685 | temporary[i2]=sourceOfParams[i];
|
---|
686 | continue;
|
---|
687 | }
|
---|
688 | temporary[i2]=0;
|
---|
689 | break;
|
---|
690 | }
|
---|
691 | temporary[i2]=sourceOfParams[i];
|
---|
692 | }
|
---|
693 |
|
---|
694 | Type::StringToType( temporary, type );
|
---|
695 |
|
---|
696 | if( type.IsNull() ){
|
---|
697 | throw SmoothieException(3,temporary,nowLine);
|
---|
698 | type.SetBasicType( DEF_PTR_VOID );
|
---|
699 | }
|
---|
700 | }
|
---|
701 | else{
|
---|
702 | type.SetBasicType( Type::GetBasicTypeFromSimpleName(temporary) );
|
---|
703 | throw SmoothieException(-103,temporary,nowLine);
|
---|
704 | }
|
---|
705 |
|
---|
706 | Parameter *pParam = new Parameter( name, type, isRef );
|
---|
707 | if( isArray ){
|
---|
708 | pParam->SetArray( subScripts );
|
---|
709 | }
|
---|
710 |
|
---|
711 | //パラメータを追加
|
---|
712 | this->params.push_back( pParam );
|
---|
713 |
|
---|
714 | if(sourceOfParams[i]==','){
|
---|
715 | i++;
|
---|
716 | continue;
|
---|
717 | }
|
---|
718 | else if(sourceOfParams[i]==')') continue;
|
---|
719 | else{
|
---|
720 | throw SmoothieException(1,NULL,nowLine);
|
---|
721 | break;
|
---|
722 | }
|
---|
723 | }
|
---|
724 | i++;
|
---|
725 |
|
---|
726 | if(sourceOfParams[i]){
|
---|
727 | ///////////////////
|
---|
728 | // 戻り値を取得
|
---|
729 | ///////////////////
|
---|
730 |
|
---|
731 | i2=lstrlen(sourceOfParams)-2;
|
---|
732 |
|
---|
733 | int sw_as=0;
|
---|
734 | for(;i2>0;i2--){
|
---|
735 | if(sourceOfParams[i2]==')') break;
|
---|
736 |
|
---|
737 | if(sourceOfParams[i2]==1&&sourceOfParams[i2+1]==ESC_AS){
|
---|
738 | i2+=2;
|
---|
739 | i3=0;
|
---|
740 | while(sourceOfParams[i2]=='*') temporary[i3++]=sourceOfParams[i2++];
|
---|
741 | for(;;i2++,i3++){
|
---|
742 | if(!IsVariableChar(sourceOfParams[i2])){
|
---|
743 | temporary[i3]=0;
|
---|
744 | break;
|
---|
745 | }
|
---|
746 | temporary[i3]=sourceOfParams[i2];
|
---|
747 | }
|
---|
748 | Type::StringToType( temporary, this->returnType );
|
---|
749 | if( this->returnType.IsNull() ) throw SmoothieException(3,temporary,nowLine);
|
---|
750 |
|
---|
751 | sw_as=1;
|
---|
752 | break;
|
---|
753 | }
|
---|
754 | }
|
---|
755 | }
|
---|
756 | else{
|
---|
757 | //戻り値なしのSub定義
|
---|
758 | this->returnType.SetNull();
|
---|
759 | }
|
---|
760 |
|
---|
761 | return true;
|
---|
762 | }
|
---|
763 |
|
---|
764 | bool ProcPointer::SetParamsAndReturnType( const char *sourceOfParams, int nowLine ){
|
---|
765 | int i = 0;
|
---|
766 | int i2,i3,sw;
|
---|
767 | char temporary[8192],temp2[VN_SIZE];
|
---|
768 |
|
---|
769 | //ソースコードの位置
|
---|
770 | this->codePos = nowLine;
|
---|
771 |
|
---|
772 | //パラメータ
|
---|
773 | if(sourceOfParams[i]!='('){
|
---|
774 | throw SmoothieException(1,NULL,nowLine);
|
---|
775 | return 0;
|
---|
776 | }
|
---|
777 | i++;
|
---|
778 | while(1){
|
---|
779 | if(sourceOfParams[i]==')') break;
|
---|
780 |
|
---|
781 | //ByRef
|
---|
782 | bool isRef;
|
---|
783 | if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){
|
---|
784 | isRef = false;
|
---|
785 | i+=2;
|
---|
786 | }
|
---|
787 | else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){
|
---|
788 | isRef = true;
|
---|
789 | i+=2;
|
---|
790 | }
|
---|
791 | else isRef = false;
|
---|
792 |
|
---|
793 | //パラメータ名
|
---|
794 | bool isArray = false;
|
---|
795 | int subScripts[MAX_ARRAYDIM];
|
---|
796 | char name[VN_SIZE];
|
---|
797 | sw=0;
|
---|
798 | for(i2=0;;i++,i2++){
|
---|
799 | if(sourceOfParams[i]=='('){
|
---|
800 | if(!sw) sw=1;
|
---|
801 |
|
---|
802 | i3=GetStringInPare(name+i2,sourceOfParams+i);
|
---|
803 | i2+=i3-1;
|
---|
804 | i+=i3-1;
|
---|
805 | continue;
|
---|
806 | }
|
---|
807 | if(sourceOfParams[i]=='['){
|
---|
808 | if(!sw) sw=1;
|
---|
809 |
|
---|
810 | i3=GetStringInBracket(name+i2,sourceOfParams+i);
|
---|
811 | i2+=i3-1;
|
---|
812 | i+=i3-1;
|
---|
813 | continue;
|
---|
814 | }
|
---|
815 | if(!IsVariableChar(sourceOfParams[i])){
|
---|
816 | name[i2]=0;
|
---|
817 | break;
|
---|
818 | }
|
---|
819 | name[i2]=sourceOfParams[i];
|
---|
820 | }
|
---|
821 | if(sw){
|
---|
822 | //配列パラメータ
|
---|
823 | if( isRef == false ) throw SmoothieException(29,NULL,nowLine);
|
---|
824 | isArray = true;
|
---|
825 |
|
---|
826 | if((name[i2-2]=='('&&name[i2-1]==')')||
|
---|
827 | (name[i2-2]=='['&&name[i2-1]==']')){
|
---|
828 | subScripts[0]=LONG_MAX;
|
---|
829 | subScripts[1]=-1;
|
---|
830 |
|
---|
831 | name[i2-2]=0;
|
---|
832 | }
|
---|
833 | else{
|
---|
834 | GetArrange(name,temp2,subScripts);
|
---|
835 | lstrcpy(name,temp2);
|
---|
836 | }
|
---|
837 |
|
---|
838 | i2=lstrlen(name);
|
---|
839 | }
|
---|
840 |
|
---|
841 | //型
|
---|
842 | Type type( DEF_NON );
|
---|
843 | if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){
|
---|
844 | i+=2;
|
---|
845 |
|
---|
846 | i2=0;
|
---|
847 | while(sourceOfParams[i]=='*'){
|
---|
848 | temporary[i2]=sourceOfParams[i];
|
---|
849 | i++;
|
---|
850 | i2++;
|
---|
851 | }
|
---|
852 | for(;;i++,i2++){
|
---|
853 | if(!IsVariableChar(sourceOfParams[i])){
|
---|
854 | if(sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){
|
---|
855 | temporary[i2++]=sourceOfParams[i++];
|
---|
856 | temporary[i2]=sourceOfParams[i];
|
---|
857 | continue;
|
---|
858 | }
|
---|
859 | temporary[i2]=0;
|
---|
860 | break;
|
---|
861 | }
|
---|
862 | temporary[i2]=sourceOfParams[i];
|
---|
863 | }
|
---|
864 |
|
---|
865 | Type::StringToType( temporary, type );
|
---|
866 |
|
---|
867 | if( type.IsNull() ){
|
---|
868 | throw SmoothieException(3,temporary,nowLine);
|
---|
869 | type.SetBasicType( DEF_PTR_VOID );
|
---|
870 | }
|
---|
871 | }
|
---|
872 | else{
|
---|
873 | type.SetBasicType( Type::GetBasicTypeFromSimpleName(temporary) );
|
---|
874 | throw SmoothieException(-103,temporary,nowLine);
|
---|
875 | }
|
---|
876 |
|
---|
877 | Parameter *pParam = new Parameter( name, type, isRef );
|
---|
878 | if( isArray ){
|
---|
879 | pParam->SetArray( subScripts );
|
---|
880 | }
|
---|
881 |
|
---|
882 | //パラメータを追加
|
---|
883 | this->params.push_back( pParam );
|
---|
884 |
|
---|
885 | if(sourceOfParams[i]==','){
|
---|
886 | i++;
|
---|
887 | continue;
|
---|
888 | }
|
---|
889 | else if(sourceOfParams[i]==')') continue;
|
---|
890 | else{
|
---|
891 | throw SmoothieException(1,NULL,nowLine);
|
---|
892 | break;
|
---|
893 | }
|
---|
894 | }
|
---|
895 | i++;
|
---|
896 |
|
---|
897 | if(sourceOfParams[i]){
|
---|
898 | ///////////////////
|
---|
899 | // 戻り値を取得
|
---|
900 | ///////////////////
|
---|
901 |
|
---|
902 | i2=lstrlen(sourceOfParams)-2;
|
---|
903 |
|
---|
904 | int sw_as=0;
|
---|
905 | for(;i2>0;i2--){
|
---|
906 | if(sourceOfParams[i2]==')') break;
|
---|
907 |
|
---|
908 | if(sourceOfParams[i2]==1&&sourceOfParams[i2+1]==ESC_AS){
|
---|
909 | i2+=2;
|
---|
910 | i3=0;
|
---|
911 | while(sourceOfParams[i2]=='*') temporary[i3++]=sourceOfParams[i2++];
|
---|
912 | for(;;i2++,i3++){
|
---|
913 | if(!IsVariableChar(sourceOfParams[i2])){
|
---|
914 | temporary[i3]=0;
|
---|
915 | break;
|
---|
916 | }
|
---|
917 | temporary[i3]=sourceOfParams[i2];
|
---|
918 | }
|
---|
919 | Type::StringToType( temporary, this->returnType );
|
---|
920 | if( this->returnType.IsNull() ) throw SmoothieException(3,temporary,nowLine);
|
---|
921 |
|
---|
922 | sw_as=1;
|
---|
923 | break;
|
---|
924 | }
|
---|
925 | }
|
---|
926 | }
|
---|
927 | else{
|
---|
928 | //戻り値なしのSub定義
|
---|
929 | this->returnType.SetNull();
|
---|
930 | }
|
---|
931 |
|
---|
932 | //戻り値のエラーチェック
|
---|
933 | if( IsFunction() ){
|
---|
934 | // Function定義
|
---|
935 |
|
---|
936 | if( this->ReturnType().IsNull() ){
|
---|
937 | // 戻り値がない
|
---|
938 | throw SmoothieException(26,this->GetName(),nowLine);
|
---|
939 | }
|
---|
940 | }
|
---|
941 | else{
|
---|
942 | if( !this->ReturnType().IsNull() ){
|
---|
943 | // Sub定義なのに、戻り値がある
|
---|
944 | throw SmoothieException(38,this->GetName(),nowLine);
|
---|
945 | }
|
---|
946 | }
|
---|
947 |
|
---|
948 | return true;
|
---|
949 | }
|
---|
950 |
|
---|
951 | UserProc *UserProc::pCompilingUserProc = NULL;
|
---|