Changeset 75 in dev for BasicCompiler_Common/ParamImpl.cpp
- Timestamp:
- Mar 20, 2007, 4:36:16 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BasicCompiler_Common/ParamImpl.cpp
r73 r75 7 7 #endif 8 8 9 ParamImpl::ParamImpl(const char *buffer){ 9 ParamImpl::ParamImpl(const char *buffer): 10 returnType() 11 { 10 12 /////////////////////////// 11 13 // パラメータ文字列を整理 … … 55 57 ParmsNum++; 56 58 59 types.push_back( Type() ); 60 57 61 if(buffer[i]==',') i++; 58 62 } 59 60 ReturnTypeInfo.type=DEF_NON; 61 ReturnTypeInfo.u.lpIndex=-1; 62 } 63 ParamImpl::ParamImpl(const PARAMETER_INFO *pParamInfo,const int ParmNum){ 64 int i; 65 for(i=0;i<ParmNum;i++){ 66 Parms[i]=0; 67 types[i].type=pParamInfo[i].type; 68 types[i].u.lpIndex=pParamInfo[i].u.index; 69 } 70 this->ParmsNum=ParmNum; 71 72 ReturnTypeInfo.type=DEF_NON; 73 ReturnTypeInfo.u.lpIndex=-1; 74 } 75 ParamImpl::ParamImpl(const Parameters ¶ms){ 76 int count = 0; 63 } 64 ParamImpl::ParamImpl(const Parameters ¶ms): 65 returnType() 66 { 67 ParmsNum = 0; 77 68 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; 69 Parms[ParmsNum]=0; 70 ParmsNum++; 71 72 types.push_back( *pParam ); 73 } 86 74 } 87 75 ParamImpl::~ParamImpl(){ … … 96 84 } 97 85 98 void ParamImpl::SetReturnType( TYPEINFO *pTypeInfo){99 ReturnTypeInfo=*pTypeInfo;100 } 101 102 BOOL ParamImpl::_overload_check( Parameters ¶ms,TYPEINFO *pReturnTypeInfo,int overload_level){86 void ParamImpl::SetReturnType( const Type &returnType ){ 87 this->returnType = returnType; 88 } 89 90 bool ParamImpl::_overload_check( int level, const Parameters &targetParms, const Type &targetResultType ){ 103 91 //パラメータを識別してオーバーロードを解決 104 92 105 93 //パラメータの個数が不一致の場合 106 int max = (int)params.size(); 107 if(max!=ParmsNum) return 0; 94 int max = (int)targetParms.size(); 95 if(max!=ParmsNum){ 96 return false; 97 } 108 98 109 99 Type argType; 110 100 for(int i=0;i<max;i++){ 111 Parameter ¶m = * params[i];101 Parameter ¶m = *targetParms[i]; 112 102 113 103 if(Parms[i]){ … … 115 105 116 106 NumOpe_GetType(Parms[i], 117 ( overload_level==OVERLOAD_LEVEL0)? nullParam : param,107 (level==OVERLOAD_LEVEL0)? nullParam : param, 118 108 argType); 119 109 } 120 110 else{ 121 argType .SetType( types[i].type, types[i].u.lpIndex );111 argType = types[i]; 122 112 } 123 113 124 114 if(argType.GetBasicType()!=param.GetBasicType()){ 125 if( overload_level==OVERLOAD_LEVEL1 || overload_level == OVERLOAD_LEVEL0){126 return 0;127 } 128 else if( overload_level==OVERLOAD_LEVEL2){115 if(level==OVERLOAD_LEVEL1 || level == OVERLOAD_LEVEL0){ 116 return false; 117 } 118 else if(level==OVERLOAD_LEVEL2){ 129 119 if(!( 130 120 IsWholeNumberType(argType.GetBasicType())&&IsWholeNumberType(param.GetBasicType())|| 131 121 IsRealNumberType(argType.GetBasicType())&&IsRealNumberType(param.GetBasicType()) 132 )) return 0; 133 } 134 else if(overload_level==OVERLOAD_LEVEL3){ 122 )){ 123 return false; 124 } 125 } 126 else if(level==OVERLOAD_LEVEL3){ 135 127 if(argType.GetBasicType()==DEF_OBJECT||param.GetBasicType()==DEF_OBJECT) return 0; 136 128 } … … 138 130 else{ 139 131 if(NATURAL_TYPE(argType.GetBasicType())==DEF_OBJECT || NATURAL_TYPE(argType.GetBasicType())==DEF_STRUCT){ 140 if(argType.GetIndex()!=param.GetIndex()) return 0; 141 } 142 } 143 } 144 145 if(pReturnTypeInfo){ 132 if(argType.GetIndex()!=param.GetIndex()){ 133 return false; 134 } 135 } 136 } 137 } 138 139 if( !targetResultType.IsNull() ){ 146 140 //戻り値も比較対象にする 147 if(ReturnTypeInfo.type==pReturnTypeInfo->type){ 148 if(NATURAL_TYPE(ReturnTypeInfo.type)==DEF_OBJECT 149 || NATURAL_TYPE(ReturnTypeInfo.type)==DEF_STRUCT ){ 150 if(ReturnTypeInfo.u.lpIndex != pReturnTypeInfo->u.lpIndex) return 0; 151 } 152 } 153 else return 0; 154 } 155 156 return 1; 157 } 158 159 SubInfo *ParamImpl::OverloadSolutionWithReturnType( const char *name, std::vector<SubInfo *> &subs ){ 141 if( !returnType.Equals( targetResultType ) ){ 142 return false; 143 } 144 } 145 146 return true; 147 } 148 149 UserProc *ParamImpl::OverloadSolutionWithReturnType( const char *name, std::vector<UserProc *> &subs ){ 160 150 int sw=0; 161 SubInfo *psi; 162 psi=0; 151 UserProc *pUserProc = NULL; 163 152 164 153 for( int level=OVERLOAD_MIN_LEVEL; level<=OVERLOAD_MAX_LEVEL; level++ ){ 165 foreach( SubInfo *temp_psi, subs ){ 166 167 TYPEINFO ReturnTypeInfo; 168 ReturnTypeInfo.type=temp_psi->ReturnType; 169 ReturnTypeInfo.u.lpIndex=temp_psi->u.ReturnIndex; 154 foreach( UserProc *pTempUserProc, subs ){ 170 155 171 156 //エラーチェック 172 if(_overload_check( temp_psi->params,&ReturnTypeInfo,level)){157 if(_overload_check( level, pTempUserProc->Params(), pTempUserProc->ReturnType() )){ 173 158 if(sw){ 174 159 SetError(52,name,cp); … … 177 162 sw=1; 178 163 179 p si = temp_psi;164 pUserProc = pTempUserProc; 180 165 break; 181 166 } … … 190 175 } 191 176 192 return p si;193 } 194 SubInfo *ParamImpl::OverloadSolution( const char *name, std::vector<SubInfo*> &subs ){177 return pUserProc; 178 } 179 UserProc *ParamImpl::OverloadSolution( const char *name, std::vector<UserProc *> &subs ){ 195 180 int sw=0; 196 SubInfo *psi;197 p si=0;181 UserProc *pUserProc; 182 pUserProc=0; 198 183 199 184 for( int level=OVERLOAD_MIN_LEVEL; level<=OVERLOAD_MAX_LEVEL; level++ ){ 200 185 201 foreach( SubInfo *temp_psi, subs ){186 foreach( UserProc *pTempUserProc, subs ){ 202 187 203 188 //エラーチェック 204 if(_overload_check( temp_psi->params,NULL,level)){189 if(_overload_check( level, pTempUserProc->Params(), Type() )){ 205 190 if(sw){ 206 191 return OverloadSolutionWithReturnType(name,subs); … … 208 193 sw=1; 209 194 210 p si = temp_psi;195 pUserProc = pTempUserProc; 211 196 } 212 197 } … … 216 201 217 202 if(!sw){ 218 SubInfo *temp_psi; 219 foreach( temp_psi, subs ){ 203 foreach( UserProc *pTempUserProc, subs ){ 220 204 221 205 //エラーチェック 222 if( temp_psi->params.size()==this->ParmsNum){206 if(pTempUserProc->Params().size()==this->ParmsNum){ 223 207 if(sw){ 224 208 sw=0; … … 227 211 sw=1; 228 212 229 p si=temp_psi;213 pUserProc=pTempUserProc; 230 214 } 231 215 } … … 237 221 } 238 222 239 return psi; 240 } 241 242 BOOL ParamImpl::ErrorCheck(const char *FuncName,PARAMETER_INFO *ppi,int pi_num,int SecondParmNum){ 243 if(ParmsNum>pi_num){ 244 if(ppi[pi_num-1].type!=DEF_ELLIPSE){ 245 //パラメータが多すぎるとき 246 SetError(10,FuncName,cp); 247 return 0; 248 } 249 } 250 else if(ParmsNum<pi_num){ 251 if(ParmsNum<SecondParmNum){ 252 if(ppi[ParmsNum].type==DEF_ELLIPSE){ 253 return 1; 254 } 255 256 //パラメータが少なすぎるとき 257 SetError(10,FuncName,cp); 258 return 0; 259 } 260 261 //省略パラメータに "0" を指定する 262 for(;ParmsNum < pi_num;ParmsNum++){ 263 extern HANDLE hHeap; 264 char temporary[64]; 265 if(ppi[ParmsNum].bByVal) lstrcpy(temporary,"0"); 266 else sprintf(temporary,"%c%c0",1,ESC_BYVAL); 267 Parms[ParmsNum]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1); 268 lstrcpy(Parms[ParmsNum],temporary); 269 } 270 } 271 272 return 1; 273 } 274 bool ParamImpl::ErrorCheck( const char *procName, const Parameters ¶ms, int SecondParmNum ){ 223 return pUserProc; 224 } 225 226 bool ParamImpl::ErrorCheck( const string &procName, const Parameters ¶ms, int SecondParmNum ){ 227 if( SecondParmNum == -1 ) SecondParmNum = (int)params.size(); 228 275 229 if(ParmsNum>(int)params.size()){ 276 230 if(params[params.size()-1]->GetBasicType()!=DEF_ELLIPSE){ … … 305 259 } 306 260 307 void ParamImpl::MacroParameterSupport(PARAMETER_INFO *ppi){308 for(int i=0;i<ParmsNum;i++){309 if(Parms[i][0]=='\0'){310 extern HANDLE hHeap;311 char temporary[64];312 if(ppi[i].bByVal) lstrcpy(temporary,"0");313 else sprintf(temporary,"%c%c0",1,ESC_BYVAL);314 HeapDefaultFree(Parms[i]);315 Parms[i]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);316 lstrcpy(Parms[i],temporary);317 }318 }319 }320 261 void ParamImpl::MacroParameterSupport( const Parameters ¶ms ){ 321 262 for(int i=0;i<ParmsNum;i++){
Note:
See TracChangeset
for help on using the changeset viewer.