Changeset 73 in dev for BasicCompiler_Common/ParamImpl.cpp
- Timestamp:
- Mar 16, 2007, 11:07:14 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler_Common/ParamImpl.cpp
r71 r73 73 73 ReturnTypeInfo.u.lpIndex=-1; 74 74 } 75 ParamImpl::ParamImpl(const Parameters ¶ms){ 76 int count = 0; 77 foreach( Parameter *pParam, params ){ 78 types[count].type = pParam->GetBasicType(); 79 types[count].u.lpIndex = pParam->GetIndex(); 80 count++; 81 } 82 this->ParmsNum=params.size(); 83 84 ReturnTypeInfo.type=DEF_NON; 85 ReturnTypeInfo.u.lpIndex=-1; 86 } 75 87 ParamImpl::~ParamImpl(){ 76 88 int i2; … … 88 100 } 89 101 90 BOOL ParamImpl::_overload_check( PARAMETER_INFO *ppi,int pi_num,TYPEINFO *pReturnTypeInfo,int overload_level){102 BOOL ParamImpl::_overload_check( Parameters ¶ms,TYPEINFO *pReturnTypeInfo,int overload_level){ 91 103 //パラメータを識別してオーバーロードを解決 92 104 93 105 //パラメータの個数が不一致の場合 94 if(pi_num!=ParmsNum) return 0; 95 96 int i,type; 97 LONG_PTR lpIndex; 98 for(i=0;i<pi_num;i++){ 106 int max = (int)params.size(); 107 if(max!=ParmsNum) return 0; 108 109 Type argType; 110 for(int i=0;i<max;i++){ 111 Parameter ¶m = *params[i]; 112 99 113 if(Parms[i]){ 100 TYPEINFO BaseType={ppi[i].type,ppi[i].u.index}; 101 type=NumOpe_GetType(Parms[i], 102 (overload_level==OVERLOAD_LEVEL0) ? NULL : &BaseType, 103 &lpIndex); 114 Type nullParam( DEF_NON ); 115 116 NumOpe_GetType(Parms[i], 117 (overload_level==OVERLOAD_LEVEL0)? nullParam : param, 118 argType); 104 119 } 105 120 else{ 106 type=types[i].type; 107 lpIndex=types[i].u.lpIndex; 108 } 109 110 if(type!=ppi[i].type){ 121 argType.SetType( types[i].type, types[i].u.lpIndex ); 122 } 123 124 if(argType.GetBasicType()!=param.GetBasicType()){ 111 125 if(overload_level==OVERLOAD_LEVEL1 || overload_level == OVERLOAD_LEVEL0){ 112 126 return 0; … … 114 128 else if(overload_level==OVERLOAD_LEVEL2){ 115 129 if(!( 116 IsWholeNumberType( type)&&IsWholeNumberType(ppi[i].type)||117 IsRealNumberType( type)&&IsRealNumberType(ppi[i].type)130 IsWholeNumberType(argType.GetBasicType())&&IsWholeNumberType(param.GetBasicType())|| 131 IsRealNumberType(argType.GetBasicType())&&IsRealNumberType(param.GetBasicType()) 118 132 )) return 0; 119 133 } 120 134 else if(overload_level==OVERLOAD_LEVEL3){ 121 if( type==DEF_OBJECT||ppi[i].type==DEF_OBJECT) return 0;135 if(argType.GetBasicType()==DEF_OBJECT||param.GetBasicType()==DEF_OBJECT) return 0; 122 136 } 123 137 } 124 138 else{ 125 if(NATURAL_TYPE( type)==DEF_OBJECT || NATURAL_TYPE(type)==DEF_STRUCT){126 if( lpIndex!=ppi[i].u.index) return 0;139 if(NATURAL_TYPE(argType.GetBasicType())==DEF_OBJECT || NATURAL_TYPE(argType.GetBasicType())==DEF_STRUCT){ 140 if(argType.GetIndex()!=param.GetIndex()) return 0; 127 141 } 128 142 } … … 143 157 } 144 158 145 S UBINFO *ParamImpl::OverloadSolutionWithReturnType( const char *name, std::vector<SUBINFO*> &subs ){159 SubInfo *ParamImpl::OverloadSolutionWithReturnType( const char *name, std::vector<SubInfo *> &subs ){ 146 160 int sw=0; 147 S UBINFO*psi;161 SubInfo *psi; 148 162 psi=0; 149 163 150 164 for( int level=OVERLOAD_MIN_LEVEL; level<=OVERLOAD_MAX_LEVEL; level++ ){ 151 foreach( S UBINFO*temp_psi, subs ){165 foreach( SubInfo *temp_psi, subs ){ 152 166 153 167 TYPEINFO ReturnTypeInfo; … … 156 170 157 171 //エラーチェック 158 if(_overload_check(temp_psi->p ParmInfo,temp_psi->ParmNum,&ReturnTypeInfo,level)){172 if(_overload_check(temp_psi->params,&ReturnTypeInfo,level)){ 159 173 if(sw){ 160 174 SetError(52,name,cp); … … 178 192 return psi; 179 193 } 180 S UBINFO *ParamImpl::OverloadSolution( const char *name, std::vector<SUBINFO*> &subs ){194 SubInfo *ParamImpl::OverloadSolution( const char *name, std::vector<SubInfo *> &subs ){ 181 195 int sw=0; 182 S UBINFO*psi;196 SubInfo *psi; 183 197 psi=0; 184 198 185 199 for( int level=OVERLOAD_MIN_LEVEL; level<=OVERLOAD_MAX_LEVEL; level++ ){ 186 200 187 foreach( S UBINFO*temp_psi, subs ){201 foreach( SubInfo *temp_psi, subs ){ 188 202 189 203 //エラーチェック 190 if(_overload_check(temp_psi->p ParmInfo,temp_psi->ParmNum,NULL,level)){204 if(_overload_check(temp_psi->params,NULL,level)){ 191 205 if(sw){ 192 206 return OverloadSolutionWithReturnType(name,subs); … … 202 216 203 217 if(!sw){ 204 S UBINFO*temp_psi;218 SubInfo *temp_psi; 205 219 foreach( temp_psi, subs ){ 206 220 207 221 //エラーチェック 208 if(temp_psi-> ParmNum==this->ParmsNum){222 if(temp_psi->params.size()==this->ParmsNum){ 209 223 if(sw){ 210 224 sw=0; … … 258 272 return 1; 259 273 } 274 bool ParamImpl::ErrorCheck( const char *procName, const Parameters ¶ms, int SecondParmNum ){ 275 if(ParmsNum>(int)params.size()){ 276 if(params[params.size()-1]->GetBasicType()!=DEF_ELLIPSE){ 277 //パラメータが多すぎるとき 278 SetError(10,procName,cp); 279 return false; 280 } 281 } 282 else if(ParmsNum<(int)params.size()){ 283 if(ParmsNum<SecondParmNum){ 284 if(params[ParmsNum]->GetBasicType()==DEF_ELLIPSE){ 285 return true; 286 } 287 288 //パラメータが少なすぎるとき 289 SetError(10,procName,cp); 290 return false; 291 } 292 293 //省略パラメータに "0" を指定する 294 for(;ParmsNum < (int)params.size();ParmsNum++){ 295 extern HANDLE hHeap; 296 char temporary[64]; 297 if(params[ParmsNum]->IsRef() == false) lstrcpy(temporary,"0"); 298 else sprintf(temporary,"%c%c0",1,ESC_BYVAL); 299 Parms[ParmsNum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1); 300 lstrcpy(Parms[ParmsNum],temporary); 301 } 302 } 303 304 return true; 305 } 260 306 261 307 void ParamImpl::MacroParameterSupport(PARAMETER_INFO *ppi){ 262 int i; 263 for(i=0;i<ParmsNum;i++){ 308 for(int i=0;i<ParmsNum;i++){ 264 309 if(Parms[i][0]=='\0'){ 265 310 extern HANDLE hHeap; … … 273 318 } 274 319 } 320 void ParamImpl::MacroParameterSupport( const Parameters ¶ms ){ 321 for(int i=0;i<ParmsNum;i++){ 322 if(Parms[i][0]=='\0'){ 323 extern HANDLE hHeap; 324 char temporary[64]; 325 if( params[i]->IsRef() == false ) lstrcpy(temporary,"0"); 326 else sprintf(temporary,"%c%c0",1,ESC_BYVAL); 327 HeapDefaultFree(Parms[i]); 328 Parms[i]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1); 329 lstrcpy(Parms[i],temporary); 330 } 331 } 332 }
Note:
See TracChangeset
for help on using the changeset viewer.