source: dev/BasicCompiler_Common/Subroutine.cpp@ 141

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

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

File size: 20.2 KB
RevLine 
[4]1#include "../BasicCompiler_Common/common.h"
2
3#ifdef _AMD64_
4#include "../BasicCompiler64/opcode.h"
5#else
[5]6#include "../BasicCompiler32/opcode.h"
[4]7#endif
8
9int GetCallProcName(char *buffer,char *name){
10 int i2,i3,IsStr=0;
11
12 for(i2=0;;i2++){
13 if(buffer[i2]=='\"') IsStr^=1;
14 if(IsDBCSLeadByte(buffer[i2])){
15 name[i2]=buffer[i2];
16 i2++;
17 name[i2]=buffer[i2];
18 continue;
19 }
20 if(buffer[i2]=='['&&IsStr==0){
21 i3=GetStringInBracket(name+i2,buffer+i2);
22 i2+=i3-1;
23 continue;
24 }
25 if(buffer[i2]=='('&&IsStr==0){
26 name[i2]=0;
27 break;
28 }
29 if(buffer[i2]=='='&&IsStr==0){
30 name[i2]=0;
31 break;
32 }
33
34 name[i2]=buffer[i2];
35 if(buffer[i2]=='\0') break;
36 }
37 return i2;
38}
39
40int GetProc(char *name,void **ppInfo){
41
42 //ユーザー定義関数
43 *ppInfo=(void *)GetSubHash(name);
44 if(*ppInfo) return PROC_DEFAULT;
45
46 //DLL関数
47 *ppInfo=(void *)GetDeclareHash(name);
48 if(*ppInfo) return PROC_DLL;
49
50 //コンパイラ埋め込み型
51 *ppInfo=(void *)(_int64)GetFunctionFromName(name);
52 if(*ppInfo) return PROC_BUILTIN;
53
54 //関数ポインタ
[75]55 Type type;
56 if( !GetVarType( name, type, false ) ){
57 return 0;
58 }
59 if( type.IsProcPtr() ){
60 return PROC_PTR;
61 }
[4]62
63 return 0;
64}
65
[46]66void SplitObjectName(const char *name,char *ObjectName,int *pRefType){
[4]67 int i4;
68 for(i4=lstrlen(name)-1;i4>=0;i4--){
69 if(name[i4]=='.'||(name[i4]==1&&name[i4+1]==ESC_PSMEM))
70 break;
71 }
72 if(i4==-1) ObjectName[0]=0;
73 else{
74 //参照タイプを判別
75 if(name[i4]=='.') *pRefType=DEF_OBJECT;
76 else *pRefType=DEF_PTR_OBJECT;
77
78 if(i4==0) GetWithName(ObjectName);
79 else{
80 memcpy(ObjectName,name,i4);
81 ObjectName[i4]=0;
82 }
83 }
84}
[97]85bool SplitMemberName( const char *desc, char *object, char *member, CClass::RefType &refType ){
86 int lastIndex = -1;
87 for( int i=0; desc[i]; i++ ){
88 if( desc[i] == '(' ){
89 i=JumpStringInPare(desc,i+1);
90 continue;
91 }
92 else if( desc[i] == '[' ){
93 i=JumpStringInBracket(desc,i+1);
94 continue;
95 }
96 else if(desc[i]=='.'||(desc[i]==1&&desc[i+1]==ESC_PSMEM)){
97 lastIndex = i;
98 }
[28]99 }
[97]100 if( lastIndex == -1 ){
[100]101 lstrcpy( member, desc );
[97]102 return false;
103 }
104
105 if(desc[lastIndex]=='.'){
106 lstrcpy(member,desc+lastIndex+1);
107 refType = CClass::Dot;
108 }
[28]109 else{
[97]110 lstrcpy(member,desc+lastIndex+2);
111 refType = CClass::Pointer;
112 }
[28]113
[97]114 if( object ){
115 lstrcpy( object, desc );
116 object[lastIndex]=0;
[28]117 }
118
119 return true;
120}
[97]121bool SplitMemberName( const char *desc, char *object, char *member ){
122 CClass::RefType dummyRefType;
123 return SplitMemberName( desc, object, member, dummyRefType );
124}
[50]125
[75]126bool CallProc( int kind, const void *pProc, const char *fullCallName, const char *lpszParms, Type &resultType, bool isCallOn ){
[50]127
[75]128 //GetSubHash内でエラー提示が行われた場合
129 if(pProc==(Procedure *)-1){
130 return false;
131 }
[50]132
[75]133 if(kind==PROC_DEFAULT){
[50]134 /////////////////////
135 // ユーザー定義関数
136 /////////////////////
137
[75]138 UserProc *pUserProc = (UserProc *)pProc;
[50]139
140 //オブジェクト名を取得
141 char ObjectName[VN_SIZE];
142 int RefType;
[75]143 SplitObjectName(fullCallName,ObjectName,&RefType);
[50]144
145
146 ////////////////////////
147 // オーバーロードを解決
148 ////////////////////////
149
[75]150 std::vector<UserProc *> subs;
151 GetOverloadSubHash(fullCallName,subs);
[50]152 if(subs.size()){
153 //オーバーロードを解決
[75]154 pUserProc=OverloadSolutionWithStrParam(fullCallName,subs,lpszParms,ObjectName);
[50]155
[75]156 if(!pUserProc){
157 return false;
158 }
[50]159 }
160
[75]161 resultType = pUserProc->ReturnType();
[50]162
[75]163 if( isCallOn ){
164 if( !Opcode_CallProc(lpszParms,pUserProc,0,ObjectName,RefType) ){
165 return false;
166 }
[50]167 }
168 }
[75]169 else if(kind==PROC_DLL){
[50]170 /////////////////////////
171 // DLL関数
172 /////////////////////////
[75]173 DllProc *pDllProc = (DllProc *)pProc;
[50]174
[75]175 resultType = pDllProc->ReturnType();
176
177 if( isCallOn ){
178 if( !Opcode_CallDllProc(lpszParms,pDllProc) ){
179 return false;
180 }
181 }
[50]182 }
[75]183 else if(kind==PROC_BUILTIN){
[50]184 /////////////////////////
185 // 組み込み関数
186 /////////////////////////
[75]187 int FuncId = (int)(_int64)pProc;
[50]188
[75]189 if( !Opcode_CallFunc( lpszParms, FuncId, resultType, isCallOn ) ){
190 return false;
[50]191 }
192 }
[75]193 else if(kind==PROC_PTR){
[50]194 /////////////////
195 // 関数ポインタ
196 /////////////////
197
[75]198 Type type;
199 GetVarType(fullCallName,type,false);
[50]200
[88]201 ProcPointer *pProcPtr = Smoothie::Meta::procPointers[type.GetIndex()];
[75]202 resultType = pProcPtr->ReturnType();
203
204 if( isCallOn ){
205 if( !Opcode_CallProcPtr(fullCallName,lpszParms,pProcPtr) ){
206 return false;
207 }
208 }
[50]209 }
[75]210 else{
211 return false;
212 }
[50]213
[75]214 return true;
[50]215}
[75]216bool CallPropertyMethod( const char *variable, const char *rightSide, Type &resultType){
[50]217 //プロパティ用のメソッドを呼び出す
218
219 //配列要素を取得
220 char VarName[VN_SIZE],ArrayElements[VN_SIZE];
221 GetArrayElement(variable,VarName,ArrayElements);
222
223 //オブジェクト名を取得
224 char ObjectName[VN_SIZE];
225 int RefType;
226 SplitObjectName(VarName,ObjectName,&RefType);
227
228 //オーバーロード用の関数リストを作成
[75]229 std::vector<UserProc *> subs;
[50]230 GetOverloadSubHash(VarName,subs);
231 if(subs.size()==0){
[75]232 return false;
[50]233 }
234
235 //パラメータを整備
236 char *Parameter;
[75]237 Parameter=(char *)HeapAlloc(hHeap,0,lstrlen(ArrayElements)+lstrlen(rightSide)+32);
[50]238 lstrcpy(Parameter,ArrayElements);
[75]239 if(rightSide){
240 if(Parameter[0]&&rightSide[0]) lstrcat(Parameter,",");
241 lstrcat(Parameter,rightSide);
[50]242 }
243
244 //オーバーロードを解決
[75]245 UserProc *pUserProc;
246 pUserProc=OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName);
[50]247
[75]248 if(pUserProc){
[50]249 //呼び出し
[75]250 Opcode_CallProc(Parameter,pUserProc,0,ObjectName,RefType);
[50]251
[75]252 resultType = pUserProc->ReturnType();
[50]253 }
254
255 HeapDefaultFree(Parameter);
256
[75]257 return true;
[50]258}
259
[75]260bool GetReturnTypeOfPropertyMethod( const char *variable, const char *rightSide, Type &resultType ){
[4]261 //プロパティ用のメソッドを呼び出す
262
263 //配列要素を取得
264 char VarName[VN_SIZE],ArrayElements[VN_SIZE];
265 GetArrayElement(variable,VarName,ArrayElements);
266
267 //オブジェクト名を取得
268 char ObjectName[VN_SIZE];
269 int RefType;
[28]270 SplitObjectName(VarName,ObjectName,&RefType);
[4]271
272 //オーバーロード用の関数リストを作成
[75]273 std::vector<UserProc *> subs;
[50]274 GetOverloadSubHash(VarName,subs);
275 if(subs.size()==0){
[4]276 return 0;
277 }
278
279 //パラメータを整備
280 char *Parameter;
[75]281 Parameter=(char *)HeapAlloc(hHeap,0,lstrlen(ArrayElements)+lstrlen(rightSide)+32);
[4]282 lstrcpy(Parameter,ArrayElements);
[75]283 if(rightSide){
284 if(Parameter[0]&&rightSide[0]) lstrcat(Parameter,",");
285 lstrcat(Parameter,rightSide);
[4]286 }
287
288 //オーバーロードを解決
[75]289 UserProc *pUserProc;
290 pUserProc=OverloadSolutionWithStrParam(VarName,subs,Parameter,ObjectName);
[4]291
[75]292 if(pUserProc){
293 resultType = pUserProc->ReturnType();
[4]294 }
295
296 return 1;
297}
298
[38]299//インデクサ(getter)の戻り値を取得
[75]300bool GetReturnTypeOfIndexerGetterProc( const CClass &objClass, Type &resultType ){
[100]301 vector<UserProc *> subs;
[135]302 objClass.GetMethods().Enum( CALC_ARRAY_GET, subs );
[50]303 if( subs.size() == 0 ){
[38]304 return false;
305 }
306
[75]307 resultType = subs[0]->ReturnType();
[38]308
309 return true;
310}
311
312
[100]313void AddDeclareData(const NamespaceScopes &namespaceScopes, char *buffer,int nowLine){
[4]314 extern HANDLE hHeap;
[75]315 int i2;
[4]316
[75]317 int i=0;
[4]318
[75]319 //Sub/Function
320 Procedure::Kind kind = Procedure::Sub;
321 if(buffer[i]==ESC_SUB){
[4]322 }
[75]323 else if(buffer[i]==ESC_FUNCTION){
324 kind = Procedure::Function;
325 }
[4]326 else{
[75]327 SetError(1,NULL,nowLine);
[4]328 return;
329 }
330 i++;
331
332 //プロシージャ名
[75]333 char procName[VN_SIZE];
334 bool isCdecl = false;
[4]335 for(i2=0;;i++,i2++){
336 if(buffer[i]==1&&buffer[i+1]==ESC_CDECL){
[75]337 isCdecl = true;
[4]338
339 i+=2;
[75]340 procName[i2]=0;
[4]341 break;
342 }
343 if(buffer[i]==','){
[75]344 procName[i2]=0;
[4]345 break;
346 }
347 if(buffer[i]=='\0'){
[75]348 SetError(1,NULL,nowLine);
[4]349 return;
350 }
[75]351 procName[i2]=buffer[i];
[4]352 }
[75]353 i++;
[4]354
355 //ユーザー定義関数との重複チェック
[75]356 if(GetSubHash(procName)){
357 SetError(15,procName,nowLine);
[4]358 return;
359 }
360
361
362 //ライブラリ
[75]363 char dllFileName[MAX_PATH];
364 i = GetOneParameter( buffer, i, dllFileName );
365 Type resultType;
[54]366 _int64 i64data;
[75]367 if( !StaticCalculation( true, dllFileName, 0, &i64data, resultType ) ){
[4]368 return;
369 }
[75]370 if( resultType.GetBasicType() != typeOfPtrChar ){
371 SetError(1,NULL,nowLine);
372 return;
373 }
374 lstrcpy( dllFileName, (char *)i64data );
375 CharUpper(dllFileName);
376 if(!strstr(dllFileName,".")){
377 lstrcat(dllFileName,".DLL");
378 if(lstrlen(dllFileName)>=16){
379 SetError(7,NULL,nowLine);
380 return;
[4]381 }
382 }
383
[54]384 //エイリアス
[75]385 char alias[VN_SIZE];
386 i = GetOneParameter( buffer, i, alias );
387 if( alias[0] ){
388 if( !StaticCalculation( true, alias, 0, &i64data, resultType ) ){
[4]389 return;
390 }
[75]391 if( resultType.GetBasicType() != typeOfPtrChar ){
392 SetError(1,NULL,nowLine);
393 return;
394 }
395 lstrcpy( alias, (char *)i64data );
[4]396 }
397 else{
[54]398 //省略されたときは関数名
[75]399 lstrcpy( alias, procName );
[4]400 }
401
402
[75]403 // オブジェクトを生成
[100]404 DllProc *pDllProc = new DllProc( namespaceScopes, procName, kind, isCdecl, dllFileName, alias );
[4]405
[75]406 // パラメータを解析
407 // ※第1パラメータにに指定するデータの例:"( s As String ) As String"
408 pDllProc->SetParamsAndReturnType( buffer + i, nowLine );
[4]409
[75]410 // パラメータのエラーチェック
411 foreach( const Parameter *pParam, pDllProc->Params() ){
412 if( pParam->IsObject() ){
413 SetError(25,pParam->GetVarName(),nowLine);
[4]414 }
[75]415 if( !pParam->IsRef() ){
416 if( pParam->IsStruct() ){
417 SetError(28,pParam->GetVarName(),nowLine);
418 }
[4]419 }
[75]420 }
[4]421
[75]422 //戻り値のエラーチェック
423 if( pDllProc->IsFunction() ){
424 // Function定義
[4]425
[75]426 if( pDllProc->ReturnType().IsObject() ){
427 // DLL関数ではオブジェクトを戻り値にできない
428 SetError(40,pDllProc->GetName(),nowLine);
[4]429 }
[75]430 }
[4]431
432
[75]433 /////////////////////////////////
434 // 格納位置を計算してppDeclareHashにセット
435 /////////////////////////////////
[4]436
[75]437 //ハッシュ値を取得
438 int key;
439 key=hash_default(procName);
[4]440
[75]441 extern DllProc **ppDeclareHash;
442 if(ppDeclareHash[key]){
[113]443 DllProc *pTempProc = ppDeclareHash[key];
[75]444 while(1){
[113]445 if( pTempProc->IsEqualSymbol( pDllProc->GetNamespaceScopes(), pDllProc->GetName() ) ){
[75]446 //重複エラー
447 SetError(15,procName,nowLine);
448 return;
449 }
[4]450
[75]451 if(pTempProc->pNextData==0){
452 pTempProc->pNextData=pDllProc;
453 break;
454 }
455 pTempProc=pTempProc->pNextData;
[4]456 }
[75]457 pTempProc=pTempProc->pNextData;
[4]458 }
[75]459 else{
460 ppDeclareHash[key]=pDllProc;
[4]461 }
462}
463
[135]464GlobalProc *AddSubData( const NamespaceScopes &namespaceScopes, const NamespaceScopesCollection &importedNamespaces, char *buffer,int nowLine,bool isVirtual,CClass *pobj_c, bool isStatic){
[75]465 int i2,i3;
466 char temporary[8192];
[4]467
[75]468 int i=1;
[4]469
[100]470 Procedure::Kind kind = Procedure::Sub;
[75]471 bool isMacro = false;
472 if(buffer[i]==ESC_FUNCTION) kind = Procedure::Function;
473 if(buffer[i]==ESC_MACRO){
474 isMacro = true;
[4]475 }
476
477 i++;
478
[75]479 bool isCdecl = false;
480 bool isExport = false;
[4]481 while(1){
[75]482 if(buffer[i]==1&&buffer[i+1]==ESC_CDECL&& isCdecl == false ){
483 isCdecl = true;
[4]484
485 i+=2;
486 }
[75]487 else if(buffer[i]==1&&buffer[i+1]==ESC_EXPORT&& isExport == false ){
488 isExport = true;
[4]489
490 i+=2;
491 }
492 else break;
493 }
494
495 i2=0;
496 if(buffer[i]==1&&buffer[i+1]==ESC_OPERATOR){
497 if(!pobj_c){
[75]498 SetError(126,NULL,nowLine);
[4]499 return 0;
500 }
501
502 //オペレータの場合
503 temporary[i2++]=buffer[i++];
504 temporary[i2++]=buffer[i++];
505
506 int iCalcId;
507 if(buffer[i]=='='&&buffer[i+1]=='='){
508 iCalcId=CALC_EQUAL;
509 i3=2;
510 }
511 else if(buffer[i]=='='){
512 iCalcId=CALC_SUBSITUATION;
513 i3=1;
514 }
515 else if(buffer[i]=='('){
516 iCalcId=CALC_AS;
517 i3=0;
518 }
519 else if(buffer[i]=='['&&buffer[i+1]==']'&&buffer[i+2]=='='){
520 iCalcId=CALC_ARRAY_SET;
521 i3=3;
522 }
523 else if(buffer[i]=='['&&buffer[i+1]==']'){
524 iCalcId=CALC_ARRAY_GET;
525 i3=2;
526 }
527 else{
528 iCalcId=GetCalcId(buffer+i,&i3);
529 i3++;
530 }
531 if(!iCalcId){
[75]532 SetError(1,NULL,nowLine);
[4]533 return 0;
534 }
535 temporary[i2++]=iCalcId;
536 temporary[i2]=0;
537
538 i+=i3;
539 }
540 else{
541 if(pobj_c){
542 //クラスメンバの場合、デストラクタには~が付くことを考慮
543 if(buffer[i]=='~'){
544 temporary[i2]='~';
545 i++;
546 i2++;
547 }
548 }
549
550 for(;;i++,i2++){
551 if(!IsVariableChar(buffer[i])){
552 temporary[i2]=0;
553 break;
554 }
555 temporary[i2]=buffer[i];
556 }
557 }
558
[75]559 if( isMacro ){
[4]560 //大文字に変換
561 CharUpper(temporary);
562
563 //マクロ関数の場合は名前リストに追加
564 extern char **ppMacroNames;
565 extern int MacroNum;
566 ppMacroNames=(char **)HeapReAlloc(hHeap,0,ppMacroNames,(MacroNum+1)*sizeof(char *));
567 ppMacroNames[MacroNum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
568 lstrcpy(ppMacroNames[MacroNum],temporary);
569 MacroNum++;
570 }
571
[30]572 if(!pobj_c){
[4]573 //クラスメンバ以外の場合のみ
574 //重複チェック
575
576 if(GetDeclareHash(temporary)){
[75]577 SetError(15,temporary,nowLine);
[4]578 return 0;
579 }
580 }
581
582 extern int SubNum;
583 SubNum++;
584
[108]585 GlobalProc *pUserProc = new GlobalProc( namespaceScopes, importedNamespaces, temporary, kind, isMacro, isCdecl, isExport );
[75]586 pUserProc->SetParentClass( pobj_c );
[112]587 if( Smoothie::isFullCompile ){
588 // すべての関数・メソッドをコンパイルする
589 pUserProc->Using();
590 }
[4]591
592 //ID
[5]593 static int id_base=0;
[75]594 pUserProc->id = (id_base++);
[4]595
[75]596 if(isExport){
597 pUserProc->Using();
[4]598 }
599
[75]600 // パラメータを解析
601 // ※第1パラメータにに指定するデータの例:"( s As String ) As String"
602 pUserProc->SetParamsAndReturnType( buffer + i, nowLine, isStatic );
[4]603
[97]604 pUserProc->_paramStr = buffer + i;
[4]605
[97]606
[4]607 /////////////////////////////////
608 // ハッシュデータに追加
609 /////////////////////////////////
610
611 int key;
[75]612 key=hash_default(pUserProc->GetName().c_str());
[4]613
[100]614 extern GlobalProc **ppSubHash;
[4]615 if(ppSubHash[key]){
[100]616 GlobalProc *psi2;
[4]617 psi2=ppSubHash[key];
618 while(1){
[75]619 if(pobj_c==psi2->GetParentClassPtr()){
[4]620 //重複エラーチェックを行う
[101]621 if( pUserProc->IsEqualSymbol( *psi2 ) ){
[120]622 if( psi2->Params().Equals( pUserProc->Params() ) ){
[75]623 SetError(15,pUserProc->GetName().c_str(),nowLine);
[4]624 return 0;
625 }
626 }
627 }
628
629 if(psi2->pNextData==0) break;
630 psi2=psi2->pNextData;
631 }
[75]632 psi2->pNextData=pUserProc;
[4]633 }
634 else{
[75]635 ppSubHash[key]=pUserProc;
[4]636 }
637
[75]638 return pUserProc;
[4]639}
640
641void GetSubInfo(void){ //サブルーチン情報を取得
642 extern HANDLE hHeap;
643 extern char *basbuf;
644 int i,i2,i3;
645 char temporary[8192];
646
647 //Declare(DLL関数)情報を初期化
[75]648 extern DllProc **ppDeclareHash;
649 ppDeclareHash=(DllProc **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(DllProc *));
[4]650
651 //サブルーチン(ユーザー定義)情報を初期化
[100]652 extern GlobalProc **ppSubHash;
[4]653 extern int SubNum;
[100]654 ppSubHash=(GlobalProc **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(GlobalProc *));
[4]655 SubNum=0;
656
657 //マクロ関数の名前リストを初期化
658 extern char **ppMacroNames;
659 extern int MacroNum;
660 ppMacroNames=(char **)HeapAlloc(hHeap,0,1);
661 MacroNum=0;
662
[99]663 // 名前空間管理
[101]664 NamespaceScopes &namespaceScopes = Smoothie::Lexical::liveingNamespaceScopes;
665 namespaceScopes.clear();
[99]666
[108]667 // Importsされた名前空間の管理
668 NamespaceScopesCollection &importedNamespaces = Smoothie::Meta::importedNamespaces;
669 importedNamespaces.clear();
670
[4]671 i=-1;
672 while(1){
673 i++;
674
675 if(basbuf[i]==1&&(basbuf[i+1]==ESC_CLASS||basbuf[i+1]==ESC_INTERFACE)){
676 /* Class ~ End Class
677 Interface ~ End Interface
678 を飛び越す */
679 i3=GetEndXXXCommand(basbuf[i+1]);
680 for(i+=2,i2=0;;i++,i2++){
681 if(basbuf[i]=='\0') break;
682 if(basbuf[i]==1&&basbuf[i+1]==(char)i3){
683 i++;
684 break;
685 }
686 }
687 if(basbuf[i]=='\0') break;
688 continue;
689 }
690
[99]691 if( basbuf[i] == 1 && basbuf[i+1] == ESC_NAMESPACE ){
692 for(i+=2,i2=0;;i2++,i++){
693 if( IsCommandDelimitation( basbuf[i] ) ){
694 temporary[i2]=0;
695 break;
696 }
697 temporary[i2]=basbuf[i];
698 }
699 namespaceScopes.push_back( temporary );
700
701 continue;
702 }
703 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_ENDNAMESPACE ){
704 if( namespaceScopes.size() <= 0 ){
705 SetError(12, "End Namespace", i );
706 }
707 else{
708 namespaceScopes.pop_back();
709 }
710
711 i += 2;
712 continue;
713 }
[108]714 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_IMPORTS ){
715 for(i+=2,i2=0;;i2++,i++){
716 if( IsCommandDelimitation( basbuf[i] ) ){
717 temporary[i2]=0;
718 break;
719 }
720 temporary[i2]=basbuf[i];
721 }
722 importedNamespaces.Imports( temporary );
[99]723
[108]724 continue;
725 }
726 else if( basbuf[i] == 1 && basbuf[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
727 importedNamespaces.clear();
728 continue;
729 }
730
[4]731 if(basbuf[i]==1&&basbuf[i+1]==ESC_DECLARE){
732 for(i+=2,i2=0;;i2++,i++){
733 if(basbuf[i]=='\n'){
734 temporary[i2]=0;
735 break;
736 }
737 temporary[i2]=basbuf[i];
738 if(basbuf[i]=='\0') break;
739 }
[100]740 AddDeclareData(namespaceScopes,temporary,i);
[4]741
742 continue;
743 }
744 if(basbuf[i]==1&&(basbuf[i+1]==ESC_SUB||basbuf[i+1]==ESC_FUNCTION||basbuf[i+1]==ESC_MACRO)){
[108]745 char statementChar = basbuf[i+1];
746
[4]747 for(i2=0;;i2++,i++){
748 if(IsCommandDelimitation(basbuf[i])){
749 temporary[i2]=0;
750 break;
751 }
752 temporary[i2]=basbuf[i];
753 if(basbuf[i]=='\0') break;
754 }
[108]755 AddSubData(namespaceScopes, importedNamespaces, temporary,i,0,0);
[4]756
[108]757 /* Sub ~ End Sub
758 Function ~ End Function
759 Macro ~ End Macro
760 を飛び越す */
761 char endStatementChar = GetEndXXXCommand( statementChar );
762 for(i2=0;;i++,i2++){
763 if( basbuf[i] == '\0' ) break;
764 if( basbuf[i] == 1 && basbuf[i+1] == endStatementChar ){
765 i++;
766 break;
767 }
768 }
769 if(basbuf[i]=='\0') break;
[4]770 continue;
771 }
772
773 //次の行
774 for(;;i++){
775 if(IsCommandDelimitation(basbuf[i])) break;
776 }
777 if(basbuf[i]=='\0') break;
778 }
779
780 ////////////
781 // 特殊関数
782 ////////////
[100]783 namespaceScopes.clear();
[108]784 importedNamespaces.clear();
[4]785
786 sprintf(temporary,"%c%c_allrem()",1,ESC_SUB);
[108]787 AddSubData( namespaceScopes, importedNamespaces, temporary,0,0,0);
[4]788
789 sprintf(temporary,"%c%c_aullrem()",1,ESC_SUB);
[108]790 AddSubData( namespaceScopes, importedNamespaces, temporary,0,0,0);
[4]791
792 sprintf(temporary,"%c%c_allmul()",1,ESC_SUB);
[108]793 AddSubData( namespaceScopes, importedNamespaces, temporary,0,0,0);
[4]794
795 sprintf(temporary,"%c%c_alldiv()",1,ESC_SUB);
[108]796 AddSubData( namespaceScopes, importedNamespaces, temporary,0,0,0);
[4]797
798 sprintf(temporary,"%c%c_aulldiv()",1,ESC_SUB);
[108]799 AddSubData( namespaceScopes, importedNamespaces, temporary,0,0,0);
[4]800
801 sprintf(temporary,"%c%c_allshl()",1,ESC_SUB);
[108]802 AddSubData( namespaceScopes, importedNamespaces, temporary,0,0,0);
[4]803
804 sprintf(temporary,"%c%c_allshr()",1,ESC_SUB);
[108]805 AddSubData( namespaceScopes, importedNamespaces, temporary,0,0,0);
[4]806
807 sprintf(temporary,"%c%c_aullshr()",1,ESC_SUB);
[108]808 AddSubData( namespaceScopes, importedNamespaces, temporary,0,0,0);
[4]809
810 sprintf(temporary,"%c%c_System_InitStaticLocalVariables()",1,ESC_SUB);
[108]811 AddSubData( namespaceScopes, importedNamespaces, temporary,0,0,0);
[4]812}
[100]813void Delete_si(GlobalProc *pUserProc){
[75]814 if(pUserProc->pNextData) Delete_si(pUserProc->pNextData);
815 delete pUserProc;
[4]816}
[100]817void DeleteSubInfo(GlobalProc **ppSubHash,char **ppMacroNames,int MacroNum){ //サブルーチン情報のメモリ解放
[4]818 int i;
819 for(i=0;i<MAX_HASH;i++){
820 if(!ppSubHash[i]) continue;
821
822 Delete_si(ppSubHash[i]);
823 }
824 HeapDefaultFree(ppSubHash);
825
826 //マクロの名前リスト
827 if(ppMacroNames){
828 for(i=0;i<MacroNum;i++){
829 HeapDefaultFree(ppMacroNames[i]);
830 }
831 HeapDefaultFree(ppMacroNames);
832 }
833}
[75]834void Delete_di(DllProc *pDllProc){
835 if(pDllProc->pNextData) Delete_di(pDllProc->pNextData);
[4]836
[75]837 delete pDllProc;
[4]838}
839void DeleteDeclareInfo(void){
840 //DLL情報を解放
[75]841 extern DllProc **ppDeclareHash;
[4]842 int i;
843 for(i=0;i<MAX_HASH;i++){
844 if(!ppDeclareHash[i]) continue;
845
846 Delete_di(ppDeclareHash[i]);
847 }
848 HeapDefaultFree(ppDeclareHash);
849}
850
851
852
853///////////////////////
854// 関数ポインタの管理
855///////////////////////
856
[78]857int AddProcPtrInfo( const string &typeExpression, int nowLine ){
858 DWORD dwProcType = (DWORD)typeExpression[2];
859 const string &paramStr = typeExpression.substr( 3 );
[4]860
[75]861 Procedure::Kind kind = Procedure::Sub;
862 if( dwProcType == ESC_FUNCTION ){
863 kind = Procedure::Function;
864 }
[4]865
[75]866 ProcPointer *pProcPointer = new ProcPointer( kind );
[4]867
868 //buffer[0]は'('となっている
[78]869 pProcPointer->SetParamsAndReturnType( paramStr.c_str(), nowLine );
[4]870
[88]871 Smoothie::Meta::procPointers.push_back( pProcPointer );
[4]872
[88]873 return (int)Smoothie::Meta::procPointers.size()-1;
[4]874}
875void DeleteProcPtrInfo(void){
[88]876 BOOST_FOREACH( ProcPointer *pProcPointer, Smoothie::Meta::procPointers ){
[78]877 delete pProcPointer;
[4]878 }
879
[88]880 Smoothie::Meta::procPointers.clear();
[4]881}
[94]882
883
884
885bool IsNeedProcCompile(){
886 for(int i2=0;i2<MAX_HASH;i2++){
[100]887 extern GlobalProc **ppSubHash;
888 GlobalProc *pUserProc=ppSubHash[i2];
[94]889 while(pUserProc){
890 if( pUserProc->IsUsing() && pUserProc->IsCompiled() == false ){
891 return true;
892 }
893
894 pUserProc=pUserProc->pNextData;
895 }
896 }
897 return false;
898}
Note: See TracBrowser for help on using the repository browser.