Changeset 206 in dev for trunk/abdev/BasicCompiler_Common/Intermediate_Step2.cpp
- Timestamp:
- Jul 12, 2007, 2:58:26 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler_Common/Intermediate_Step2.cpp
r199 r206 1 #include "stdafx.h" 2 1 3 #include <jenga/include/smoothie/Smoothie.h> 2 4 #include <jenga/include/smoothie/LexicalAnalysis.h> … … 6 8 #include "../BasicCompiler_Common/common.h" 7 9 8 CONSTINFO *GetNewConstHash(char *name){ 9 extern int cp; 10 CONSTINFO *pci; 11 12 int key; 13 key=hash_default(name); 14 15 extern CONSTINFO **ppConstHash; 16 if(ppConstHash[key]){ 17 pci=ppConstHash[key]; 18 while(1){ 19 if(lstrcmp(pci->name,name)==0){ 20 //重複エラー 21 SetError(15,name,cp); 22 return 0; 23 } 24 25 if(pci->pNextData==0){ 26 pci->pNextData=(CONSTINFO *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,sizeof(CONSTINFO)); 27 break; 28 } 29 pci=pci->pNextData; 30 } 31 pci=pci->pNextData; 32 } 33 else{ 34 ppConstHash[key]=(CONSTINFO *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,sizeof(CONSTINFO)); 35 pci=ppConstHash[key]; 36 } 37 38 return pci; 39 } 40 41 // マクロ定数を追加するための関数 42 void AddConstData(char *Command){ 43 extern HANDLE hHeap; 44 extern int cp; 45 int i,i2; 46 char temporary[VN_SIZE]; 47 48 for(i=0;;i++){ 49 if(Command[i]=='\0'){ 50 SetError(10,"Const",cp); 51 return; 52 } 53 if(Command[i]=='=' || Command[i] == 1 && Command[i+1] == ESC_AS ){ 54 //定数定義は新しいクラスモジュール(CDBConst)へ移行 55 // ※この関数はマクロ定数のみを扱う 56 return; 57 } 58 if(Command[i]=='('){ 59 temporary[i]=0; 60 break; 61 } 62 temporary[i]=Command[i]; 63 } 64 65 66 ///////////////////////////////// 67 // 格納位置を計算してpciにセット 68 ///////////////////////////////// 69 70 CONSTINFO *pci; 71 pci=GetNewConstHash(temporary); 72 if(!pci) return; 73 74 75 76 //////////////////// 77 // 定数情報を取得 78 //////////////////// 79 80 //定数名 81 pci->name=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1); 82 lstrcpy(pci->name,temporary); 83 84 if(Command[i]=='('){ 85 pci->ppParm=(char **)HeapAlloc(hHeap,0,1); 86 pci->ParmNum=0; 87 for(i++,i2=0;;i++,i2++){ 88 if(Command[i]=='\0'){ 89 SetError(1,NULL,cp); 90 return; 91 } 92 if(Command[i]==','||Command[i]==')'){ 93 temporary[i2]=0; 94 pci->ppParm=(char **)HeapReAlloc(hHeap,0,pci->ppParm,(pci->ParmNum+1)*sizeof(char *)); 95 pci->ppParm[pci->ParmNum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1); 96 lstrcpy(pci->ppParm[pci->ParmNum],temporary); 97 pci->ParmNum++; 98 if(Command[i]==')'){ 99 i++; 100 if(Command[i]!='='){ 101 SetError(1,NULL,cp); 102 return; 103 } 104 break; 105 } 106 107 i2=-1; 108 continue; 109 } 110 temporary[i2]=Command[i]; 111 } 112 } 113 else pci->ParmNum=0; 114 115 //データ 116 lstrcpy(temporary,Command+i+1); 117 if(pci->ParmNum){ 118 pci->StrValue=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1); 119 lstrcpy(pci->StrValue,temporary); 120 } 121 else if(temporary[0]=='\"'){ 122 //文字列定数 123 RemoveStringQuotes(temporary); 124 i2=lstrlen(temporary); 125 126 pci->StrValue=(char *)HeapAlloc(hHeap,0,i2+1); 127 memcpy(pci->StrValue,temporary,i2); 128 pci->StrValue[i2]=0; 129 130 pci->DblValue=(double)i2; 131 132 pci->type=DEF_STRING; 133 pci->lpIndex=-1; 134 } 135 else if((temporary[0]=='e'||temporary[0]=='E')&& 136 (temporary[1]=='x'||temporary[1]=='X')&& 137 temporary[2]=='\"'){ 138 //文字列定数 139 RemoveStringQuotes(temporary+2); 140 i2=FormatString_EscapeSequence(temporary+2); 141 pci->StrValue=(char *)HeapAlloc(hHeap,0,i2+1); 142 memcpy(pci->StrValue,temporary+2,i2); 143 pci->StrValue[i2]=0; 144 145 pci->DblValue=(double)i2; 146 147 pci->type=DEF_STRING; 148 pci->lpIndex=-1; 149 } 150 else{ 151 //数値定数 152 _int64 i64data; 153 Type resultType; 154 StaticCalculation(true, temporary,0,&i64data,resultType); 155 pci->type=resultType.GetBasicType(); 156 if(IsRealNumberType(pci->type)){ 157 //実数型 158 memcpy(&pci->DblValue,&i64data,sizeof(double)); 159 } 160 else if(Is64Type(pci->type)){ 161 //64ビット型 162 pci->i64Value=i64data; 163 } 164 else if(IsWholeNumberType(pci->type)){ 165 //その他整数型 166 pci->DblValue=(double)i64data; 167 } 168 169 pci->StrValue=0; 170 } 171 } 10 172 11 void AddConstEnum( const NamespaceScopes &namespaceScopes, char *buffer){ 173 12 extern int cp; … … 240 79 241 80 //定数を追加 242 CDBConst::obj.AddConst( namespaceScopes, temporary, NextValue);81 compiler.GetMeta().GetGlobalConsts().Add( namespaceScopes, temporary, NextValue); 243 82 } 244 83 } … … 255 94 namespaceScopes.clear(); 256 95 257 //定数に関する情報 258 extern CONSTINFO **ppConstHash;259 ppConstHash=(CONSTINFO **)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,MAX_HASH*sizeof(CONSTINFO *));96 //定数に関する情報を初期化 97 compiler.GetMeta().GetGlobalConsts().Clear(); 98 compiler.GetMeta().GetGlobalConstMacros().Clear(); 260 99 261 100 extern char *basbuf; … … 315 154 temporary[i2]=basbuf[i]; 316 155 } 317 CDBConst::obj.Add( namespaceScopes, temporary);156 AddConst( namespaceScopes, temporary); 318 157 if(basbuf[i]=='\0') break; 319 158 } … … 331 170 } 332 171 } 172 173 // イテレータを初期化 174 compiler.GetMeta().GetGlobalConsts().Iterator_Init(); 175 compiler.GetMeta().GetGlobalConstMacros().Iterator_Init(); 176 333 177 return true; 334 178 }
Note:
See TracChangeset
for help on using the changeset viewer.