Changeset 814 in dev for branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Const.cpp
- Timestamp:
- Mar 19, 2011, 1:29:12 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/egtra/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Const.cpp
r803 r814 85 85 86 86 int i2; 87 char temporary[1024];88 87 89 88 // 名前空間管理 … … 91 90 namespaceScopes.clear(); 92 91 93 for(int i=0;;i++){ 92 for (int i = 0; ; ++i) 93 { 94 94 if( source[i] == '\0' ) break; 95 95 96 96 if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){ 97 for(i+=2,i2=0;;i2++,i++){ 98 if( IsCommandDelimitation( source[i] ) ){ 99 temporary[i2]=0; 100 break; 101 } 102 temporary[i2]=source[i]; 103 } 104 namespaceScopes.push_back( temporary ); 97 i+=2; 98 char const* p = &source[i]; 99 while (!IsCommandDelimitation(source[i])) 100 { 101 ++i; 102 } 103 namespaceScopes.push_back(std::string(p, &source[i])); 105 104 106 105 continue; … … 131 130 } 132 131 132 char const* beginTemp = &source[i]; 133 char const* endTemp = &source[i]; 134 133 135 for(i2=0;;i++,i2++){ 134 136 if(source[i]=='\"'){ 135 temporary[i2]=source[i];136 137 for(i++,i2++;;i++,i2++){ 137 temporary[i2]=source[i];138 138 if(source[i]=='\"') break; 139 139 } … … 141 141 } 142 142 if(IsCommandDelimitation(source[i])){ 143 temporary[i2]=0;143 endTemp = beginTemp + i2; 144 144 break; 145 145 } 146 temporary[i2]=source[i];147 146 } 148 147 149 148 //名前を取得 150 char name[VN_SIZE];149 char const* nameEnd; 151 150 for(i2=0;;i2++){ 152 if( temporary[i2]=='\0'){151 if(beginTemp[i2]=='\0'){ 153 152 compiler.errorMessenger.Output(10,"Const",cp); 154 153 return; 155 154 } 156 if( temporary[i2]=='='||temporary[i2]=='('){157 name [i2]=0;155 if(beginTemp[i2]=='='||beginTemp[i2]=='('){ 156 nameEnd = beginTemp + i2; 158 157 break; 159 158 } 160 name[i2]=temporary[i2];161 }159 } 160 std::string name(beginTemp, nameEnd); 162 161 163 162 //重複チェック … … 165 164 || compiler.GetObjectModule().meta.GetGlobalConsts().IsExistDuplicationKeyName( name ) ) 166 165 { 167 compiler.errorMessenger.Output(15, name,cp);166 compiler.errorMessenger.Output(15, name, cp); 168 167 return; 169 168 } 170 169 171 if( temporary[i2] == '=' )170 if( beginTemp[i2] == '=' ) 172 171 { 173 172 // 定数 174 const char *expression = temporary + i2 + 1;173 std::string expression(beginTemp + i2 + 1, endTemp); 175 174 176 175 _int64 i64data; 177 176 Type resultType; 178 if( StaticCalculation(false, expression , 0, &i64data, resultType) )177 if( StaticCalculation(false, expression.c_str(), 0, &i64data, resultType) ) 179 178 { 180 179 consts.Add( Symbol( namespaceScopes, name ), i64data, resultType ); … … 184 183 { 185 184 // 定数マクロ 186 const char *params = temporary + i2;187 if( !constMacros.Add( Symbol( namespaceScopes, name ), params ) )185 std::string params(beginTemp + i2, endTemp); 186 if( !constMacros.Add( Symbol( namespaceScopes, name ), params.c_str() ) ) 188 187 { 189 188 compiler.errorMessenger.Output( 1, NULL, i ); … … 208 207 } 209 208 210 bool LexicalAnalyzer::ConstMacroToExpression( const ConstMacro &constMacro, const char *parameterStr, char *dest ) 211 { 212 extern HANDLE hHeap; 213 int i2,i3,i4,num; 209 bool LexicalAnalyzer::ConstMacroToExpression( const ConstMacro &constMacro, const char *parameterStr, char *dest, std::size_t destSize ) 210 { 211 std::string s; 212 auto ret = ConstMacroToExpression(constMacro, parameterStr, s); 213 strcpy_s(dest, destSize, s.c_str()); 214 return ret; 215 } 216 217 bool LexicalAnalyzer::ConstMacroToExpression( const ConstMacro &constMacro, const char *parameterStr, std::string& dest ) 218 { 219 int i2,i3; 214 220 char temporary[VN_SIZE]; 215 char *pParms[MAX_PARMS];216 num=0;221 std::vector<std::string> Parms; 222 dest.reserve(8192); 217 223 i2=0; 218 224 while(1){ 219 225 i2=GetOneParameter(parameterStr,i2,temporary); 220 226 221 pParms[num]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1); 222 lstrcpy(pParms[num],temporary); 223 224 num++; 227 Parms.push_back(temporary); 228 225 229 if(parameterStr[i2]=='\0') break; 226 230 } 227 if( num!= constMacro.GetParameters().size() ){231 if( Parms.size() != constMacro.GetParameters().size() ){ 228 232 extern int cp; 229 for(i2=0;i2<num;i2++) HeapDefaultFree(pParms[i2]);230 233 compiler.errorMessenger.Output(10,constMacro.GetName().c_str(),cp); 231 lstrcpy(dest,"0");234 dest = '0'; 232 235 return true; 233 236 } 234 237 235 238 i2=0; 236 i4=0;237 239 while(1){ 238 240 … … 253 255 if( i3 == (int)constMacro.GetParameters().size() ){ 254 256 //パラメータでないとき 255 lstrcpy(dest+i4,temporary); 256 i4+=lstrlen(temporary); 257 dest += temporary; 257 258 } 258 259 else{ 259 260 //パラメータのとき 260 lstrcpy(dest+i4,pParms[i3]); 261 i4+=lstrlen(pParms[i3]); 261 dest += Parms[i3]; 262 262 } 263 263 264 264 //演算子をコピー 265 for(;;i2++ ,i4++){265 for(;;i2++){ 266 266 if( constMacro.GetExpression()[i2] == 1 ){ 267 dest [i4++]= constMacro.GetExpression()[i2++];268 dest [i4]= constMacro.GetExpression()[i2];267 dest += constMacro.GetExpression()[i2++]; 268 dest += constMacro.GetExpression()[i2]; 269 269 continue; 270 270 } 271 271 if(IsVariableTopChar( constMacro.GetExpression()[i2] )) break; 272 dest [i4]= constMacro.GetExpression()[i2];272 dest += constMacro.GetExpression()[i2]; 273 273 if( constMacro.GetExpression()[i2] == '\0' ) break; 274 274 } … … 277 277 } 278 278 279 for(i2=0;i2<num;i2++) HeapDefaultFree(pParms[i2]);280 281 279 return true; 282 280 }
Note:
See TracChangeset
for help on using the changeset viewer.