Changeset 828 in dev for trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Const.cpp
- Timestamp:
- Mar 19, 2012, 1:59:48 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to
/branches/egtra merged eligible
-
Property svn:mergeinfo
set to
-
trunk/ab5.0/abdev
-
Property svn:ignore
set to
*.opensdf
*.sdf
*.suo
*.user
int
ipch
out
-
Property svn:ignore
set to
-
trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_Const.cpp
r637 r828 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 ); … … 206 205 } 207 206 } 208 209 // イテレータを初期化 210 compiler.GetObjectModule().meta.GetGlobalConsts().Iterator_Init(); 211 compiler.GetObjectModule().meta.GetGlobalConstMacros().Iterator_Init(); 212 } 213 214 bool LexicalAnalyzer::ConstMacroToExpression( const ConstMacro &constMacro, const char *parameterStr, char *dest ) 215 { 216 extern HANDLE hHeap; 217 int i2,i3,i4,num; 207 } 208 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; 218 220 char temporary[VN_SIZE]; 219 char *pParms[MAX_PARMS];220 num=0;221 std::vector<std::string> Parms; 222 dest.reserve(8192); 221 223 i2=0; 222 224 while(1){ 223 225 i2=GetOneParameter(parameterStr,i2,temporary); 224 226 225 pParms[num]=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1); 226 lstrcpy(pParms[num],temporary); 227 228 num++; 227 Parms.push_back(temporary); 228 229 229 if(parameterStr[i2]=='\0') break; 230 230 } 231 if( num!= constMacro.GetParameters().size() ){231 if( Parms.size() != constMacro.GetParameters().size() ){ 232 232 extern int cp; 233 for(i2=0;i2<num;i2++) HeapDefaultFree(pParms[i2]);234 233 compiler.errorMessenger.Output(10,constMacro.GetName().c_str(),cp); 235 lstrcpy(dest,"0");234 dest = '0'; 236 235 return true; 237 236 } 238 237 239 238 i2=0; 240 i4=0;241 239 while(1){ 242 240 … … 257 255 if( i3 == (int)constMacro.GetParameters().size() ){ 258 256 //パラメータでないとき 259 lstrcpy(dest+i4,temporary); 260 i4+=lstrlen(temporary); 257 dest += temporary; 261 258 } 262 259 else{ 263 260 //パラメータのとき 264 lstrcpy(dest+i4,pParms[i3]); 265 i4+=lstrlen(pParms[i3]); 261 dest += Parms[i3]; 266 262 } 267 263 268 264 //演算子をコピー 269 for(;;i2++ ,i4++){265 for(;;i2++){ 270 266 if( constMacro.GetExpression()[i2] == 1 ){ 271 dest [i4++]= constMacro.GetExpression()[i2++];272 dest [i4]= constMacro.GetExpression()[i2];267 dest += constMacro.GetExpression()[i2++]; 268 dest += constMacro.GetExpression()[i2]; 273 269 continue; 274 270 } 275 271 if(IsVariableTopChar( constMacro.GetExpression()[i2] )) break; 276 dest [i4]= constMacro.GetExpression()[i2];272 dest += constMacro.GetExpression()[i2]; 277 273 if( constMacro.GetExpression()[i2] == '\0' ) break; 278 274 } … … 281 277 } 282 278 283 for(i2=0;i2<num;i2++) HeapDefaultFree(pParms[i2]);284 285 279 return true; 286 280 }
Note:
See TracChangeset
for help on using the changeset viewer.