Changeset 50 in dev for BasicCompiler64/CParameter.cpp
- Timestamp:
- Feb 10, 2007, 5:44:58 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler64/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 void CParameter::SetReturnType(TYPEINFO *pTypeInfo){82 ReturnTypeInfo=*pTypeInfo;83 }84 85 BOOL CParameter::_overload_check(PARAMETER_INFO *ppi,int pi_num,TYPEINFO *pReturnTypeInfo,int overload_level){86 //パラメータを識別してオーバーロードを解決87 88 //パラメータの個数が不一致の場合89 if(pi_num!=ParmsNum) return 0;90 91 int i,type;92 LONG_PTR lpIndex;93 for(i=0;i<pi_num;i++){94 if(Parms[i]){95 TYPEINFO BaseType={ppi[i].type,ppi[i].u.index};96 type=NumOpe_GetType(Parms[i],&BaseType,&lpIndex);97 }98 else{99 type=types[i].type;100 lpIndex=types[i].u.lpIndex;101 }102 103 if(type!=ppi[i].type){104 if(overload_level==OVERLOAD_LEVEL1){105 return 0;106 }107 else if(overload_level==OVERLOAD_LEVEL2){108 if(!(109 IsWholeNumberType(type)&&IsWholeNumberType(ppi[i].type)||110 IsRealNumberType(type)&&IsRealNumberType(ppi[i].type)111 )) return 0;112 }113 else if(overload_level==OVERLOAD_LEVEL3){114 if(type==DEF_OBJECT||ppi[i].type==DEF_OBJECT) return 0;115 }116 }117 else{118 if(NATURAL_TYPE(type)==DEF_OBJECT){119 if(lpIndex!=ppi[i].u.index) return 0;120 }121 }122 }123 124 if(pReturnTypeInfo){125 //戻り値も比較対象にする126 if(ReturnTypeInfo.type==pReturnTypeInfo->type){127 if(NATURAL_TYPE(ReturnTypeInfo.type)==DEF_OBJECT){128 if(ReturnTypeInfo.u.lpIndex != pReturnTypeInfo->u.lpIndex) return 0;129 }130 }131 else return 0;132 }133 134 return 1;135 }136 SUBINFO *CParameter::OverloadSolutionWithReturnType(const char *name,SUBINFO **ppsi,int num){137 int i,sw=0;138 SUBINFO *psi;139 psi=0;140 for(i=0;i<num;i++){141 psi=ppsi[i];142 143 TYPEINFO ReturnTypeInfo;144 ReturnTypeInfo.type=psi->ReturnType;145 ReturnTypeInfo.u.lpIndex=psi->u.ReturnIndex;146 147 //エラーチェック148 if(_overload_check(psi->pParmInfo,psi->ParmNum,&ReturnTypeInfo,OVERLOAD_LEVEL1)){149 if(sw){150 SetError(52,name,cp);151 return 0;152 }153 sw=1;154 break;155 }156 }157 158 if(!sw){159 for(i=0;i<num;i++){160 psi=ppsi[i];161 162 TYPEINFO ReturnTypeInfo;163 ReturnTypeInfo.type=psi->ReturnType;164 ReturnTypeInfo.u.lpIndex=psi->u.ReturnIndex;165 166 //エラーチェック167 if(_overload_check(psi->pParmInfo,psi->ParmNum,&ReturnTypeInfo,OVERLOAD_LEVEL2)){168 if(sw){169 SetError(52,name,cp);170 return 0;171 }172 sw=1;173 break;174 }175 }176 }177 178 if(!sw){179 for(i=0;i<num;i++){180 psi=ppsi[i];181 182 TYPEINFO ReturnTypeInfo;183 ReturnTypeInfo.type=psi->ReturnType;184 ReturnTypeInfo.u.lpIndex=psi->u.ReturnIndex;185 186 //エラーチェック187 if(_overload_check(psi->pParmInfo,psi->ParmNum,&ReturnTypeInfo,OVERLOAD_LEVEL3)){188 if(sw){189 SetError(52,name,cp);190 return 0;191 }192 sw=1;193 break;194 }195 }196 }197 198 if(!sw){199 SetError(52,name,cp);200 return 0;201 }202 203 return psi;204 }205 206 SUBINFO *CParameter::OverloadSolution(const char *name,SUBINFO **ppsi,int num){207 int i,sw=0;208 SUBINFO *psi;209 psi=0;210 for(i=0;i<num;i++){211 psi=ppsi[i];212 213 //エラーチェック214 if(_overload_check(psi->pParmInfo,psi->ParmNum,NULL,OVERLOAD_LEVEL1)){215 if(sw){216 return OverloadSolutionWithReturnType(name,ppsi,num);217 }218 sw=1;219 break;220 }221 }222 223 if(!sw){224 for(i=0;i<num;i++){225 psi=ppsi[i];226 227 //エラーチェック228 if(_overload_check(psi->pParmInfo,psi->ParmNum,NULL,OVERLOAD_LEVEL2)){229 if(sw){230 return OverloadSolutionWithReturnType(name,ppsi,num);231 }232 sw=1;233 break;234 }235 }236 }237 238 if(!sw){239 for(i=0;i<num;i++){240 psi=ppsi[i];241 242 //エラーチェック243 if(_overload_check(psi->pParmInfo,psi->ParmNum,NULL,OVERLOAD_LEVEL3)){244 if(sw){245 return OverloadSolutionWithReturnType(name,ppsi,num);246 }247 sw=1;248 break;249 }250 }251 }252 253 if(!sw){254 SUBINFO *temp_psi;255 for(i=0;i<num;i++){256 temp_psi=ppsi[i];257 258 //エラーチェック259 if(temp_psi->ParmNum==this->ParmsNum){260 if(sw){261 sw=0;262 break;263 }264 sw=1;265 266 psi=temp_psi;267 }268 }269 }270 271 if(!sw){272 SetError(52,name,cp);273 return 0;274 }275 276 return psi;277 }278 279 BOOL CParameter::ErrorCheck(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum){280 if(ParmsNum>pi_num){281 if(ppi[pi_num-1].type!=DEF_ELLIPSE){282 //パラメータが多すぎるとき283 SetError(10,FuncName,cp);284 return 0;285 }286 }287 else if(ParmsNum<pi_num){288 if(ParmsNum<SecondParmNum){289 if(ppi[ParmsNum].type==DEF_ELLIPSE){290 return 1;291 }292 293 //パラメータが少なすぎるとき294 SetError(10,FuncName,cp);295 return 0;296 }297 298 //省略パラメータに "0" を指定する299 for(;ParmsNum < pi_num;ParmsNum++){300 extern HANDLE hHeap;301 char temporary[64];302 if(ppi[ParmsNum].bByVal) lstrcpy(temporary,"0");303 else sprintf(temporary,"%c%c0",1,ESC_BYVAL);304 Parms[ParmsNum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);305 lstrcpy(Parms[ParmsNum],temporary);306 }307 }308 309 return 1;310 }311 void CParameter::MacroParameterSupport(PARAMETER_INFO *ppi){312 int i;313 for(i=0;i<ParmsNum;i++){314 if(Parms[i][0]=='\0'){315 extern HANDLE hHeap;316 char temporary[64];317 if(ppi[i].bByVal) lstrcpy(temporary,"0");318 else sprintf(temporary,"%c%c0",1,ESC_BYVAL);319 HeapDefaultFree(Parms[i]);320 Parms[i]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);321 lstrcpy(Parms[i],temporary);322 }323 }324 }325 3 326 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.