Changeset 50 in dev for BasicCompiler32/CParameter.cpp
- Timestamp:
- Feb 10, 2007, 5:44:58 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler32/CParameter.cpp
r47 r50 1 1 #include "../BasicCompiler_Common/common.h" 2 2 #include "opcode.h" 3 4 CParameter::CParameter(char *buffer){5 ///////////////////////////6 // パラメータ文字列を整理7 ///////////////////////////8 9 extern HANDLE hHeap;10 int i,i2,i3;11 char temporary[VN_SIZE];12 13 i=0;14 ParmsNum=0;15 while(1){16 if(buffer[i]=='\0') break;17 18 for(i2=0;;i2++,i++){19 if(buffer[i]=='\"'){20 temporary[i2]=buffer[i];21 for(i++,i2++;;i++,i2++){22 temporary[i2]=buffer[i];23 if(buffer[i]=='\"') break;24 }25 continue;26 }27 28 if(buffer[i]=='('){29 i3=GetStringInPare(temporary+i2,buffer+i);30 i2+=i3-1;31 i+=i3-1;32 continue;33 }34 if(buffer[i]=='['){35 i3=GetStringInBracket(temporary+i2,buffer+i);36 i2+=i3-1;37 i+=i3-1;38 continue;39 }40 41 if(buffer[i]==','||buffer[i]=='\0'){42 temporary[i2]=0;43 break;44 }45 temporary[i2]=buffer[i];46 }47 48 Parms[ParmsNum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);49 lstrcpy(Parms[ParmsNum],temporary);50 ParmsNum++;51 52 if(buffer[i]==',') i++;53 }54 55 ReturnTypeInfo.type=0;56 ReturnTypeInfo.u.lpIndex=0;57 }58 CParameter::CParameter(PARAMETER_INFO *pParamInfo,int ParmNum){59 int i;60 for(i=0;i<ParmNum;i++){61 Parms[i]=0;62 types[i].type=pParamInfo[i].type;63 types[i].u.lpIndex=pParamInfo[i].u.index;64 }65 this->ParmsNum=ParmNum;66 67 ReturnTypeInfo.type=0;68 ReturnTypeInfo.u.lpIndex=0;69 }70 CParameter::~CParameter(){71 int i2;72 73 //パラメータ文字列を解放74 for(i2=0;i2<ParmsNum;i2++){75 if(Parms[i2]==(char *)-1) continue;76 77 if(Parms[i2]) HeapDefaultFree(Parms[i2]);78 }79 }80 81 82 void CParameter::SetReturnType(TYPEINFO *pTypeInfo){83 ReturnTypeInfo=*pTypeInfo;84 }85 86 BOOL CParameter::_overload_check(PARAMETER_INFO *ppi,int pi_num,TYPEINFO *pReturnTypeInfo,int overload_level){87 //パラメータを識別してオーバーロードを解決88 89 //パラメータの個数が不一致の場合90 if(pi_num!=ParmsNum) return 0;91 92 int i,type;93 LONG_PTR lpIndex;94 for(i=0;i<pi_num;i++){95 if(Parms[i]){96 TYPEINFO BaseType={ppi[i].type,ppi[i].u.index};97 type=NumOpe_GetType(Parms[i],&BaseType,&lpIndex);98 }99 else{100 type=types[i].type;101 lpIndex=types[i].u.lpIndex;102 }103 104 if(type!=ppi[i].type){105 if(overload_level==OVERLOAD_LEVEL1){106 return 0;107 }108 else if(overload_level==OVERLOAD_LEVEL2){109 if(!(110 IsWholeNumberType(type)&&IsWholeNumberType(ppi[i].type)||111 IsRealNumberType(type)&&IsRealNumberType(ppi[i].type)112 )) return 0;113 }114 else if(overload_level==OVERLOAD_LEVEL3){115 if(type==DEF_OBJECT||ppi[i].type==DEF_OBJECT) return 0;116 }117 }118 else{119 if(NATURAL_TYPE(type)==DEF_OBJECT){120 if(lpIndex!=ppi[i].u.index) return 0;121 }122 }123 }124 125 if(pReturnTypeInfo){126 //戻り値も比較対象にする127 if(ReturnTypeInfo.type==pReturnTypeInfo->type){128 if(NATURAL_TYPE(ReturnTypeInfo.type)==DEF_OBJECT){129 if(ReturnTypeInfo.u.lpIndex != pReturnTypeInfo->u.lpIndex) return 0;130 }131 }132 else return 0;133 }134 135 return 1;136 }137 SUBINFO *CParameter::OverloadSolutionWithReturnType(const char *name,SUBINFO **ppsi,int num){138 int i,sw=0;139 SUBINFO *psi;140 psi=0;141 for(i=0;i<num;i++){142 psi=ppsi[i];143 144 TYPEINFO ReturnTypeInfo;145 ReturnTypeInfo.type=psi->ReturnType;146 ReturnTypeInfo.u.lpIndex=psi->u.ReturnIndex;147 148 //エラーチェック149 if(_overload_check(psi->pParmInfo,psi->ParmNum,&ReturnTypeInfo,OVERLOAD_LEVEL1)){150 if(sw){151 SetError(52,name,cp);152 return 0;153 }154 sw=1;155 break;156 }157 }158 159 if(!sw){160 for(i=0;i<num;i++){161 psi=ppsi[i];162 163 TYPEINFO ReturnTypeInfo;164 ReturnTypeInfo.type=psi->ReturnType;165 ReturnTypeInfo.u.lpIndex=psi->u.ReturnIndex;166 167 //エラーチェック168 if(_overload_check(psi->pParmInfo,psi->ParmNum,&ReturnTypeInfo,OVERLOAD_LEVEL2)){169 if(sw){170 SetError(52,name,cp);171 return 0;172 }173 sw=1;174 break;175 }176 }177 }178 179 if(!sw){180 for(i=0;i<num;i++){181 psi=ppsi[i];182 183 TYPEINFO ReturnTypeInfo;184 ReturnTypeInfo.type=psi->ReturnType;185 ReturnTypeInfo.u.lpIndex=psi->u.ReturnIndex;186 187 //エラーチェック188 if(_overload_check(psi->pParmInfo,psi->ParmNum,&ReturnTypeInfo,OVERLOAD_LEVEL3)){189 if(sw){190 SetError(52,name,cp);191 return 0;192 }193 sw=1;194 break;195 }196 }197 }198 199 if(!sw){200 SetError(52,name,cp);201 return 0;202 }203 204 return psi;205 }206 207 SUBINFO *CParameter::OverloadSolution(const char *name,SUBINFO **ppsi,int num){208 int i,sw=0;209 SUBINFO *psi;210 psi=0;211 212 for(i=0;i<num;i++){213 psi=ppsi[i];214 215 //エラーチェック216 if(_overload_check(psi->pParmInfo,psi->ParmNum,NULL,OVERLOAD_LEVEL1)){217 if(sw){218 return OverloadSolutionWithReturnType(name,ppsi,num);219 }220 sw=1;221 break;222 }223 }224 225 if(!sw){226 for(i=0;i<num;i++){227 psi=ppsi[i];228 229 //エラーチェック230 if(_overload_check(psi->pParmInfo,psi->ParmNum,NULL,OVERLOAD_LEVEL2)){231 if(sw){232 return OverloadSolutionWithReturnType(name,ppsi,num);233 }234 sw=1;235 break;236 }237 }238 }239 240 if(!sw){241 for(i=0;i<num;i++){242 psi=ppsi[i];243 244 //エラーチェック245 if(_overload_check(psi->pParmInfo,psi->ParmNum,NULL,OVERLOAD_LEVEL3)){246 if(sw){247 return OverloadSolutionWithReturnType(name,ppsi,num);248 }249 sw=1;250 break;251 }252 }253 }254 255 if(!sw){256 SUBINFO *temp_psi;257 for(i=0;i<num;i++){258 temp_psi=ppsi[i];259 260 //エラーチェック261 if(temp_psi->ParmNum==this->ParmsNum){262 if(sw){263 sw=0;264 break;265 }266 sw=1;267 268 psi=temp_psi;269 }270 }271 }272 273 if(!sw){274 SetError(52,name,cp);275 return 0;276 }277 278 return psi;279 }280 281 BOOL CParameter::ErrorCheck(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum){282 if(ParmsNum>pi_num){283 if(ppi[pi_num-1].type!=DEF_ELLIPSE){284 //パラメータが多すぎるとき285 SetError(10,FuncName,cp);286 return 0;287 }288 }289 else if(ParmsNum<pi_num){290 if(ParmsNum<SecondParmNum){291 if(ppi[ParmsNum].type==DEF_ELLIPSE){292 return 1;293 }294 295 //パラメータが少なすぎるとき296 SetError(10,FuncName,cp);297 return 0;298 }299 300 //省略パラメータに "0" を指定する301 for(;ParmsNum < pi_num;ParmsNum++){302 extern HANDLE hHeap;303 char temporary[64];304 if(ppi[ParmsNum].bByVal) lstrcpy(temporary,"0");305 else sprintf(temporary,"%c%c0",1,ESC_BYVAL);306 Parms[ParmsNum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);307 lstrcpy(Parms[ParmsNum],temporary);308 }309 }310 311 return 1;312 }313 void CParameter::MacroParameterSupport(PARAMETER_INFO *ppi){314 int i;315 for(i=0;i<ParmsNum;i++){316 if(Parms[i][0]=='\0'){317 extern HANDLE hHeap;318 char temporary[64];319 if(ppi[i].bByVal) lstrcpy(temporary,"0");320 else sprintf(temporary,"%c%c0",1,ESC_BYVAL);321 HeapDefaultFree(Parms[i]);322 Parms[i]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);323 lstrcpy(Parms[i],temporary);324 }325 }326 }327 3 328 4 void CParameter::NewTempParameters( const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum ){
Note:
See TracChangeset
for help on using the changeset viewer.