[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[266] | 3 | #include <Source.h>
|
---|
| 4 |
|
---|
[4] | 5 | #include "../BasicCompiler_Common/common.h"
|
---|
| 6 |
|
---|
| 7 | void KillSpaces(char *str1,char *str2){
|
---|
| 8 | int i,i2,i3,IsStr;
|
---|
| 9 | for(i=0,i2=0,IsStr=0;;i++,i2++){
|
---|
| 10 | if((str1[i]==' '||str1[i]=='\t')&&IsStr==0){
|
---|
| 11 | i3=i+1;
|
---|
| 12 | while(str1[i3]==' '||str1[i3]=='\t') i3++;
|
---|
| 13 | if(i!=0){
|
---|
| 14 | if(i==1){
|
---|
| 15 | if(IsVariableChar(str1[i-1])&&
|
---|
| 16 | IsVariableChar(str1[i3])){
|
---|
| 17 | //識別子間にある省略すべきでない空白
|
---|
| 18 | str2[i2++]=' ';
|
---|
| 19 | }
|
---|
| 20 | }
|
---|
| 21 | else{
|
---|
| 22 | if(str1[i-2]!=1&&IsVariableChar(str1[i-1])&&
|
---|
| 23 | IsVariableChar(str1[i3])){
|
---|
| 24 | //識別子間にある省略すべきでない空白
|
---|
| 25 | str2[i2++]=' ';
|
---|
| 26 | }
|
---|
| 27 | }
|
---|
| 28 | }
|
---|
| 29 | i=i3;
|
---|
| 30 | }
|
---|
| 31 | if(str1[i]=='\"') IsStr^=1;
|
---|
| 32 | str2[i2]=str1[i];
|
---|
| 33 | if(str1[i]=='\0') break;
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
| 36 | void KillStringSpaces(char *str){
|
---|
| 37 | char *s2;
|
---|
| 38 |
|
---|
| 39 | extern HANDLE hHeap;
|
---|
| 40 | s2=(char *)HeapAlloc(hHeap,0,lstrlen(str)+1);
|
---|
| 41 | lstrcpy(s2,str);
|
---|
| 42 | KillSpaces(s2,str);
|
---|
| 43 | HeapDefaultFree(s2);
|
---|
| 44 | return;
|
---|
| 45 | }
|
---|
| 46 | BOOL RemoveStringQuotes(char *str){
|
---|
| 47 | int i;
|
---|
| 48 | if(str[0]!='\"') return 0;
|
---|
| 49 | for(i=0;;i++){
|
---|
| 50 | str[i]=str[i+1];
|
---|
| 51 | if(str[i]=='\"') break;
|
---|
| 52 | }
|
---|
| 53 | str[i]=0;
|
---|
| 54 | if(str[i+2]!='\0') return 0;
|
---|
| 55 | return 1;
|
---|
| 56 | }
|
---|
[387] | 57 | bool RemoveStringQuotes( std::string &str )
|
---|
| 58 | {
|
---|
| 59 | if( str[0] != '\"' )
|
---|
| 60 | {
|
---|
| 61 | return false;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | str = str.substr( 1, str.length() - 2 );
|
---|
| 65 | return true;
|
---|
| 66 | }
|
---|
[4] | 67 | void RemoveStringPare(char *str){
|
---|
| 68 | int i;
|
---|
| 69 | i=lstrlen(str);
|
---|
| 70 | if(str[0]!='('||str[i-1]!=')') return;
|
---|
| 71 | SlideString(str+1,-1);
|
---|
| 72 | str[i-2]=0;
|
---|
| 73 | }
|
---|
| 74 | void RemoveStringBracket(char *str){
|
---|
| 75 | int i;
|
---|
| 76 | i=lstrlen(str);
|
---|
| 77 | if(str[0]!='['||str[i-1]!=']') return;
|
---|
| 78 | SlideString(str+1,-1);
|
---|
| 79 | str[i-2]=0;
|
---|
| 80 | }
|
---|
| 81 | void SetStringQuotes(char *str){
|
---|
| 82 | int i;
|
---|
| 83 | if(str[0]=='\"') return;
|
---|
| 84 | i=lstrlen(str);
|
---|
| 85 | SlideString(str,1);
|
---|
| 86 | str[0]='\"';
|
---|
| 87 | str[i+1]='\"';
|
---|
| 88 | str[i+2]=0;
|
---|
| 89 | }
|
---|
| 90 | int FormatString_EscapeSequence(char *buffer){
|
---|
| 91 | int i2,i3,i4;
|
---|
| 92 |
|
---|
| 93 | for(i2=0,i3=0;;i2++,i3++){
|
---|
| 94 | if(IsDBCSLeadByte(buffer[i3])){
|
---|
| 95 | buffer[i2++]=buffer[i3++];
|
---|
| 96 | buffer[i2]=buffer[i3];
|
---|
| 97 | if(buffer[i3]=='\0') break;
|
---|
| 98 | continue;
|
---|
| 99 | }
|
---|
| 100 | if(buffer[i3]=='\\'){
|
---|
| 101 | switch(buffer[i3+1]){
|
---|
| 102 | case '\\':
|
---|
| 103 | buffer[i2]='\\';
|
---|
| 104 | i3++;
|
---|
| 105 | break;
|
---|
| 106 | case '0':
|
---|
| 107 | buffer[i2]='\0';
|
---|
| 108 | i3++;
|
---|
| 109 | break;
|
---|
| 110 | case 'n':
|
---|
| 111 | buffer[i2]='\n';
|
---|
| 112 | i3++;
|
---|
| 113 | break;
|
---|
| 114 | case 'q':
|
---|
| 115 | buffer[i2]='\"';
|
---|
| 116 | i3++;
|
---|
| 117 | break;
|
---|
| 118 | case 'r':
|
---|
| 119 | buffer[i2]='\r';
|
---|
| 120 | i3++;
|
---|
| 121 | break;
|
---|
| 122 | case 't':
|
---|
| 123 | buffer[i2]='\t';
|
---|
| 124 | i3++;
|
---|
| 125 | break;
|
---|
| 126 | case 'x':
|
---|
| 127 | //16進表記
|
---|
| 128 | char temporary[8];
|
---|
| 129 | temporary[0]=buffer[i3+2];
|
---|
| 130 | temporary[1]=buffer[i3+3];
|
---|
| 131 | temporary[2]=0;
|
---|
| 132 | CharUpper(temporary);
|
---|
| 133 |
|
---|
| 134 | i4=temporary[0]-0x30;
|
---|
| 135 | if(i4<0||9<i4){
|
---|
| 136 | i4=temporary[0]-0x41+10;
|
---|
| 137 | if(i4<0xA||0xF<i4){
|
---|
| 138 | buffer[i2]=buffer[i3];
|
---|
| 139 | break;
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
| 142 | temporary[0]=i4;
|
---|
| 143 |
|
---|
| 144 | i4=temporary[1]-0x30;
|
---|
| 145 | if(i4<0||9<i4){
|
---|
| 146 | i4=temporary[1]-0x41+10;
|
---|
| 147 | if(i4<0xA||0xF<i4){
|
---|
| 148 | buffer[i2]=buffer[i3];
|
---|
| 149 | break;
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 | temporary[1]=i4;
|
---|
| 153 |
|
---|
| 154 | buffer[i2]=temporary[0]*0x10+temporary[1];
|
---|
| 155 | i3+=3;
|
---|
| 156 | break;
|
---|
| 157 | default:
|
---|
| 158 | buffer[i2]=buffer[i3];
|
---|
| 159 | break;
|
---|
| 160 | }
|
---|
| 161 | }
|
---|
| 162 | else{
|
---|
| 163 | buffer[i2]=buffer[i3];
|
---|
| 164 | if(buffer[i3]=='\0') break;
|
---|
| 165 | }
|
---|
| 166 | }
|
---|
| 167 | return i2;
|
---|
| 168 | }
|
---|
| 169 | void SlideString(char *buffer, int slide){
|
---|
| 170 | char *temp;
|
---|
| 171 | temp=(char *)malloc(lstrlen(buffer)+1);
|
---|
| 172 | lstrcpy(temp,buffer);
|
---|
| 173 | lstrcpy(buffer+slide,temp);
|
---|
| 174 | free(temp);
|
---|
| 175 | }
|
---|
| 176 | void SlideBuffer(char *buffer,int length,int slide){
|
---|
| 177 | void *temp;
|
---|
| 178 | temp=malloc(length+1);
|
---|
| 179 | memcpy(temp,buffer,length);
|
---|
| 180 | memcpy(buffer+slide,temp,length);
|
---|
| 181 | free(temp);
|
---|
| 182 | }
|
---|
[77] | 183 |
|
---|
[313] | 184 | int GetSourceCodeIndexFromLine( const char *source, int LineNum ){
|
---|
[4] | 185 | int i,nCount=0;
|
---|
| 186 | for(i=0;;i++){
|
---|
[313] | 187 | if(source[i]=='\n'){
|
---|
[4] | 188 | nCount++;
|
---|
| 189 | if(LineNum==nCount){
|
---|
| 190 | for(i++;;i++){
|
---|
[313] | 191 | if(IsCommandDelimitation(source[i])) break;
|
---|
[4] | 192 | }
|
---|
| 193 | return i;
|
---|
| 194 | }
|
---|
| 195 | }
|
---|
| 196 | }
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | char GetEndXXXCommand(char es){
|
---|
| 200 | switch(es){
|
---|
| 201 | case ESC_SUB:
|
---|
| 202 | return ESC_ENDSUB;
|
---|
| 203 | case ESC_FUNCTION:
|
---|
| 204 | return ESC_ENDFUNCTION;
|
---|
| 205 | case ESC_MACRO:
|
---|
| 206 | return ESC_ENDMACRO;
|
---|
| 207 | case ESC_TYPE:
|
---|
| 208 | return ESC_ENDTYPE;
|
---|
| 209 | case ESC_CLASS:
|
---|
| 210 | return ESC_ENDCLASS;
|
---|
| 211 | case ESC_INTERFACE:
|
---|
| 212 | return ESC_ENDINTERFACE;
|
---|
| 213 | case ESC_ENUM:
|
---|
| 214 | return ESC_ENDENUM;
|
---|
| 215 | }
|
---|
| 216 | return 0;
|
---|
| 217 | }
|
---|
| 218 | void GetDefaultNameFromES(char es,char *name){
|
---|
| 219 | name[0]=0;
|
---|
| 220 | switch(es){
|
---|
| 221 | case ESC_PSMEM:
|
---|
| 222 | lstrcpy(name,"->");
|
---|
| 223 | break;
|
---|
| 224 | case ESC_MOD:
|
---|
| 225 | lstrcpy(name,"Mod");
|
---|
| 226 | break;
|
---|
| 227 | case ESC_AND:
|
---|
| 228 | lstrcpy(name,"And");
|
---|
| 229 | break;
|
---|
| 230 | case ESC_OR:
|
---|
| 231 | lstrcpy(name,"Or");
|
---|
| 232 | break;
|
---|
| 233 | case ESC_XOR:
|
---|
| 234 | lstrcpy(name,"Xor");
|
---|
| 235 | break;
|
---|
| 236 | case ESC_NOT:
|
---|
| 237 | lstrcpy(name,"Not");
|
---|
| 238 | break;
|
---|
| 239 | case ESC_AS:
|
---|
| 240 | lstrcpy(name,"As");
|
---|
| 241 | break;
|
---|
| 242 | case ESC_THEN:
|
---|
| 243 | lstrcpy(name,"Then");
|
---|
| 244 | break;
|
---|
| 245 | case ESC_ELSE:
|
---|
| 246 | lstrcpy(name,"Else");
|
---|
| 247 | break;
|
---|
| 248 | case ESC_IF:
|
---|
| 249 | lstrcpy(name,"If");
|
---|
| 250 | break;
|
---|
| 251 | case ESC_ELSEIF:
|
---|
| 252 | lstrcpy(name,"ElseIf");
|
---|
| 253 | break;
|
---|
| 254 | case ESC_ENDIF:
|
---|
| 255 | lstrcpy(name,"End If");
|
---|
| 256 | break;
|
---|
| 257 | case ESC_DEF:
|
---|
| 258 | lstrcpy(name,"Def");
|
---|
| 259 | break;
|
---|
| 260 | case ESC_DECLARE:
|
---|
| 261 | lstrcpy(name,"Declare");
|
---|
| 262 | break;
|
---|
| 263 | case ESC_ABSTRACT:
|
---|
| 264 | lstrcpy(name,"Abstract");
|
---|
| 265 | break;
|
---|
| 266 | case ESC_VIRTUAL:
|
---|
| 267 | lstrcpy(name,"Virtual");
|
---|
| 268 | break;
|
---|
| 269 | case ESC_OVERRIDE:
|
---|
| 270 | lstrcpy(name,"Override");
|
---|
| 271 | break;
|
---|
| 272 | case ESC_SUB:
|
---|
| 273 | lstrcpy(name,"Sub");
|
---|
| 274 | break;
|
---|
| 275 | case ESC_ENDSUB:
|
---|
| 276 | lstrcpy(name,"End Sub");
|
---|
| 277 | break;
|
---|
| 278 | case ESC_EXITSUB:
|
---|
| 279 | lstrcpy(name,"Exit Sub");
|
---|
| 280 | break;
|
---|
| 281 | case ESC_FUNCTION:
|
---|
| 282 | lstrcpy(name,"Function");
|
---|
| 283 | break;
|
---|
| 284 | case ESC_ENDFUNCTION:
|
---|
| 285 | lstrcpy(name,"End Function");
|
---|
| 286 | break;
|
---|
| 287 | case ESC_EXITFUNCTION:
|
---|
| 288 | lstrcpy(name,"Exit Function");
|
---|
| 289 | break;
|
---|
| 290 | case ESC_BYVAL:
|
---|
| 291 | lstrcpy(name,"ByVal ");
|
---|
| 292 | break;
|
---|
| 293 | case ESC_BYREF:
|
---|
| 294 | lstrcpy(name,"ByRef ");
|
---|
| 295 | break;
|
---|
| 296 | case ESC_TYPE:
|
---|
| 297 | lstrcpy(name,"Type");
|
---|
| 298 | break;
|
---|
| 299 | case ESC_ENDTYPE:
|
---|
| 300 | lstrcpy(name,"End Type");
|
---|
| 301 | break;
|
---|
| 302 | case ESC_EXITFOR:
|
---|
| 303 | lstrcpy(name,"Exit For");
|
---|
| 304 | break;
|
---|
| 305 | case ESC_EXITWHILE:
|
---|
| 306 | lstrcpy(name,"Exit While");
|
---|
| 307 | break;
|
---|
| 308 | case ESC_EXITDO:
|
---|
| 309 | lstrcpy(name,"Exit Do");
|
---|
| 310 | break;
|
---|
| 311 | case ESC_SELECTCASE:
|
---|
| 312 | lstrcpy(name,"Select Case");
|
---|
| 313 | break;
|
---|
| 314 | case ESC_CASE:
|
---|
| 315 | lstrcpy(name,"Case");
|
---|
| 316 | break;
|
---|
| 317 | case ESC_CASEELSE:
|
---|
| 318 | lstrcpy(name,"Case Else");
|
---|
| 319 | break;
|
---|
| 320 | case ESC_ENDSELECT:
|
---|
| 321 | lstrcpy(name,"End Select");
|
---|
| 322 | break;
|
---|
| 323 | case ESC_CONST:
|
---|
| 324 | lstrcpy(name,"Const");
|
---|
| 325 | break;
|
---|
| 326 | case ESC_TYPEDEF:
|
---|
| 327 | lstrcpy(name,"TypeDef");
|
---|
| 328 | break;
|
---|
| 329 | case ESC_WITH:
|
---|
| 330 | lstrcpy(name,"With");
|
---|
| 331 | break;
|
---|
| 332 | case ESC_ENDWITH:
|
---|
| 333 | lstrcpy(name,"End With");
|
---|
| 334 | break;
|
---|
| 335 | case ESC_CDECL:
|
---|
| 336 | lstrcpy(name,"cdecl");
|
---|
| 337 | break;
|
---|
| 338 | case ESC_MACRO:
|
---|
| 339 | lstrcpy(name,"Macro");
|
---|
| 340 | break;
|
---|
| 341 | case ESC_ENDMACRO:
|
---|
| 342 | lstrcpy(name,"End Macro");
|
---|
| 343 | break;
|
---|
| 344 | case ESC_EXITMACRO:
|
---|
| 345 | lstrcpy(name,"Exit Macro");
|
---|
| 346 | break;
|
---|
| 347 | case ESC_EXPORT:
|
---|
| 348 | lstrcpy(name,"Export");
|
---|
| 349 | break;
|
---|
| 350 | case ESC_CONTINUE:
|
---|
| 351 | lstrcpy(name,"Continue");
|
---|
| 352 | break;
|
---|
| 353 | case ESC_CLASS:
|
---|
| 354 | lstrcpy(name,"Class");
|
---|
| 355 | break;
|
---|
| 356 | case ESC_ENDCLASS:
|
---|
| 357 | lstrcpy(name,"End Class");
|
---|
| 358 | break;
|
---|
| 359 | case ESC_INTERFACE:
|
---|
| 360 | lstrcpy(name,"Interface");
|
---|
| 361 | break;
|
---|
| 362 | case ESC_ENDINTERFACE:
|
---|
| 363 | lstrcpy(name,"End Interface");
|
---|
| 364 | break;
|
---|
| 365 | case ESC_ENUM:
|
---|
| 366 | lstrcpy(name,"Enum");
|
---|
| 367 | break;
|
---|
| 368 | case ESC_ENDENUM:
|
---|
| 369 | lstrcpy(name,"End Enum");
|
---|
| 370 | break;
|
---|
| 371 | }
|
---|
| 372 | }
|
---|
[206] | 373 | const std::string &FormatEscapeSequenceStringToDefaultString( const std::string &source )
|
---|
| 374 | {
|
---|
| 375 | int maxLength = (int)source.size();
|
---|
[4] | 376 |
|
---|
[206] | 377 | char *temporary = (char *)malloc( source.size() + 8192 );
|
---|
| 378 | lstrcpy( temporary, source.c_str() );
|
---|
[4] | 379 |
|
---|
[206] | 380 | for( int i=0; i<maxLength-1; i++ )
|
---|
| 381 | {
|
---|
| 382 | if( temporary[i] == 1 )
|
---|
| 383 | {
|
---|
| 384 | char temp2[255];
|
---|
| 385 | GetDefaultNameFromES( temporary[i+1], temp2 );
|
---|
| 386 | if( i>0 )
|
---|
| 387 | {
|
---|
| 388 | char temp3[255];
|
---|
| 389 | wsprintf( temp3, " %s", temp2 );
|
---|
| 390 | lstrcpy( temp2, temp3 );
|
---|
| 391 | }
|
---|
| 392 | if( i<maxLength-2 )
|
---|
| 393 | {
|
---|
| 394 | lstrcat( temp2, " " );
|
---|
| 395 | }
|
---|
[4] | 396 |
|
---|
[206] | 397 | int length = lstrlen( temp2 );
|
---|
| 398 | SlideString( temporary + i+2, length-2 );
|
---|
| 399 | memcpy( temporary + i, temp2, length );
|
---|
| 400 | maxLength = lstrlen( temporary );
|
---|
| 401 | }
|
---|
[4] | 402 | }
|
---|
[206] | 403 |
|
---|
| 404 | static std::string resultStr = "";
|
---|
| 405 | resultStr = temporary;
|
---|
| 406 |
|
---|
| 407 | free( temporary );
|
---|
| 408 |
|
---|
| 409 | return resultStr;
|
---|
[4] | 410 | }
|
---|
| 411 |
|
---|
[279] | 412 | bool IsFileExist(const char *path){
|
---|
[4] | 413 | WIN32_FIND_DATA wfd;
|
---|
| 414 | HANDLE hFind;
|
---|
| 415 |
|
---|
| 416 | hFind=FindFirstFile(path,&wfd);
|
---|
| 417 | if(hFind==INVALID_HANDLE_VALUE){
|
---|
[279] | 418 | return false;
|
---|
[4] | 419 | }
|
---|
| 420 | FindClose(hFind);
|
---|
| 421 |
|
---|
[279] | 422 | return true;
|
---|
[4] | 423 | }
|
---|
| 424 | BOOL GetFolder(HWND hWnd,char *folder,char *OpenFolderTitle){
|
---|
| 425 | BROWSEINFO BrowseInfo;
|
---|
| 426 | LPITEMIDLIST pidlBrowse;
|
---|
| 427 | LPMALLOC g_pMalloc;
|
---|
| 428 | char temporary[MAX_PATH];
|
---|
| 429 |
|
---|
| 430 | BrowseInfo.hwndOwner=hWnd;
|
---|
| 431 | BrowseInfo.pszDisplayName=temporary;
|
---|
| 432 | BrowseInfo.pidlRoot=NULL;
|
---|
| 433 | BrowseInfo.lpszTitle=OpenFolderTitle;
|
---|
| 434 | BrowseInfo.ulFlags=BIF_RETURNONLYFSDIRS;
|
---|
| 435 | BrowseInfo.lpfn=NULL;
|
---|
| 436 | BrowseInfo.lParam=(LPARAM)0;
|
---|
| 437 | BrowseInfo.iImage=0;
|
---|
| 438 | pidlBrowse=SHBrowseForFolder(&BrowseInfo);
|
---|
| 439 | if(pidlBrowse){
|
---|
| 440 | if(SHGetMalloc(&g_pMalloc)!=0) return 0;
|
---|
| 441 | SHGetPathFromIDList(pidlBrowse,folder);
|
---|
| 442 | g_pMalloc->Free(pidlBrowse);
|
---|
| 443 | g_pMalloc->Release();
|
---|
| 444 | return 1;
|
---|
| 445 | }
|
---|
| 446 | return 0;
|
---|
| 447 | }
|
---|
[31] | 448 |
|
---|
| 449 | void ShortPathToLongPath(const char *ShortPath,char *LongPath){
|
---|
| 450 | HANDLE hFind;
|
---|
| 451 | WIN32_FIND_DATA wfd;
|
---|
| 452 | int i;
|
---|
| 453 | char dummy[MAX_PATH];
|
---|
| 454 | for(i=0;i<MAX_PATH;i++){
|
---|
| 455 | LongPath[i]=ShortPath[i];
|
---|
| 456 | if((ShortPath[i-1]==':'&&ShortPath[i]=='\\')||(ShortPath[i-1]=='\\'&&ShortPath[i]=='\\')){
|
---|
| 457 | LongPath[i+1]=0;
|
---|
| 458 | break;
|
---|
| 459 | }
|
---|
| 460 | }
|
---|
| 461 | if(ShortPath[i-1]=='\\'&&ShortPath[i]=='\\'){
|
---|
| 462 | for(i++;i<MAX_PATH;i++){
|
---|
| 463 | if(IsDBCSLeadByte(ShortPath[i])){
|
---|
| 464 | i++;
|
---|
| 465 | continue;
|
---|
| 466 | }
|
---|
| 467 | LongPath[i]=ShortPath[i];
|
---|
| 468 | if(ShortPath[i]=='\\'){
|
---|
| 469 | LongPath[i+1]=0;
|
---|
| 470 | break;
|
---|
| 471 | }
|
---|
| 472 | }
|
---|
| 473 | for(i++;i<MAX_PATH;i++){
|
---|
| 474 | if(IsDBCSLeadByte(ShortPath[i])){
|
---|
| 475 | i++;
|
---|
| 476 | continue;
|
---|
| 477 | }
|
---|
| 478 | LongPath[i]=ShortPath[i];
|
---|
| 479 | if(ShortPath[i]=='\\'){
|
---|
| 480 | LongPath[i+1]=0;
|
---|
| 481 | break;
|
---|
| 482 | }
|
---|
| 483 | }
|
---|
| 484 | }
|
---|
| 485 | for(i++;i<MAX_PATH;i++){
|
---|
| 486 | if(IsDBCSLeadByte(ShortPath[i])){
|
---|
| 487 | i++;
|
---|
| 488 | continue;
|
---|
| 489 | }
|
---|
| 490 | if(ShortPath[i]=='\\'||ShortPath[i]=='\0'){
|
---|
| 491 | strncpy(dummy,ShortPath,i);
|
---|
| 492 | dummy[i]=0;
|
---|
| 493 | if((hFind=FindFirstFile(dummy,&wfd))!=INVALID_HANDLE_VALUE) FindClose(hFind);
|
---|
| 494 | lstrcat(LongPath,wfd.cFileName);
|
---|
| 495 |
|
---|
| 496 | if(ShortPath[i]=='\0') break;
|
---|
| 497 | lstrcat(LongPath,"\\");
|
---|
| 498 |
|
---|
| 499 | if(ShortPath[i]=='\\'&&ShortPath[i+1]=='\0'){
|
---|
| 500 | break;
|
---|
| 501 | }
|
---|
| 502 | }
|
---|
| 503 | }
|
---|
| 504 | }
|
---|
[400] | 505 |
|
---|
| 506 |
|
---|
| 507 | bool IsVariableTopChar(char c){
|
---|
| 508 | if((c>='A'&&c<='Z')||(c>='a'&&c<='z')||c=='_')
|
---|
| 509 | {
|
---|
| 510 | return true;
|
---|
| 511 | }
|
---|
| 512 | return false;
|
---|
| 513 | }
|
---|
| 514 | bool IsVariableChar( char c, bool isGenericsChars ){
|
---|
| 515 | if((c>='A'&&c<='Z')||(c>='a'&&c<='z')||(c>='0'&&c<='9')||
|
---|
| 516 | c=='%'||c=='!'||c=='#'||c=='$'||
|
---|
| 517 | c=='_'||c=='.')
|
---|
| 518 | {
|
---|
| 519 | return true;
|
---|
| 520 | }
|
---|
| 521 |
|
---|
| 522 | if( isGenericsChars )
|
---|
| 523 | {
|
---|
| 524 | if( c == '<' || c == '>' )
|
---|
| 525 | {
|
---|
| 526 | return true;
|
---|
| 527 | }
|
---|
| 528 | }
|
---|
| 529 |
|
---|
| 530 | return false;
|
---|
| 531 | }
|
---|
| 532 | bool IsBlank(char c){
|
---|
| 533 | if(c==' '||c=='\t') return 1;
|
---|
| 534 | return 0;
|
---|
| 535 | }
|
---|
| 536 | int GetOneParameter(const char *Parameter,int pos,char *retAns){
|
---|
| 537 | int i,i2,i3,IsStr;
|
---|
| 538 | for(i=pos,i2=0,IsStr=0;;i++,i2++){
|
---|
| 539 | if(Parameter[i]=='\"') IsStr^=1;
|
---|
| 540 | else if(Parameter[i]=='('&&IsStr==0){
|
---|
| 541 | i3=GetStringInPare(retAns+i2,Parameter+i);
|
---|
| 542 | i+=i3-1;
|
---|
| 543 | i2+=i3-1;
|
---|
| 544 | continue;
|
---|
| 545 | }
|
---|
| 546 | else if(Parameter[i]=='['&&IsStr==0){
|
---|
| 547 | i3=GetStringInBracket(retAns+i2,Parameter+i);
|
---|
| 548 | i+=i3-1;
|
---|
| 549 | i2+=i3-1;
|
---|
| 550 | continue;
|
---|
| 551 | }
|
---|
| 552 | else if(Parameter[i]==','&&IsStr==0){
|
---|
| 553 | retAns[i2]=0;
|
---|
| 554 | i++;
|
---|
| 555 | break;
|
---|
| 556 | }
|
---|
| 557 |
|
---|
| 558 | if(IsCommandDelimitation(Parameter[i])&&IsStr==0
|
---|
| 559 | || Parameter[i] == ')' && IsStr == 0 ){
|
---|
| 560 | retAns[i2]=0;
|
---|
| 561 | break;
|
---|
| 562 | }
|
---|
| 563 |
|
---|
| 564 | retAns[i2]=Parameter[i];
|
---|
| 565 | }
|
---|
| 566 | return i;
|
---|
| 567 | }
|
---|
| 568 | int JumpOneParameter(char *Parameter,int i){
|
---|
| 569 | int i2,IsStr;
|
---|
| 570 | for(i2=0,IsStr=0;;i++,i2++){
|
---|
| 571 | if(Parameter[i]=='\"') IsStr^=1;
|
---|
| 572 | else if(Parameter[i]=='('&&IsStr==0){
|
---|
| 573 | i=JumpStringInPare(Parameter,i+1);
|
---|
| 574 | continue;
|
---|
| 575 | }
|
---|
| 576 | else if(Parameter[i]=='['&&IsStr==0){
|
---|
| 577 | i=JumpStringInBracket(Parameter,i+1);
|
---|
| 578 | continue;
|
---|
| 579 | }
|
---|
| 580 | else if(Parameter[i]==','&&IsStr==0){
|
---|
| 581 | i++;
|
---|
| 582 | break;
|
---|
| 583 | }
|
---|
| 584 | if(IsCommandDelimitation(Parameter[i])) break;
|
---|
| 585 | }
|
---|
| 586 | return i;
|
---|
| 587 | }
|
---|
| 588 | int GetStringInQuotation(char *buffer,char *ReadBuffer){
|
---|
| 589 | int i;
|
---|
| 590 |
|
---|
| 591 | if(ReadBuffer[0]=='\"'){
|
---|
| 592 | buffer[0]=ReadBuffer[0];
|
---|
| 593 | i=1;
|
---|
| 594 | }
|
---|
| 595 | else i=0;
|
---|
| 596 |
|
---|
| 597 | for(;;i++){
|
---|
| 598 | buffer[i]=ReadBuffer[i];
|
---|
| 599 | if(IsDBCSLeadByte(ReadBuffer[i])){
|
---|
| 600 | i++;
|
---|
| 601 | buffer[i]=ReadBuffer[i];
|
---|
| 602 | continue;
|
---|
| 603 | }
|
---|
| 604 | if(ReadBuffer[i]=='\"'){
|
---|
| 605 | i++;
|
---|
| 606 | buffer[i]=0;
|
---|
| 607 | break;
|
---|
| 608 | }
|
---|
| 609 | if(ReadBuffer[i]=='\0') return 0;
|
---|
| 610 | }
|
---|
| 611 | return i;
|
---|
| 612 | }
|
---|
| 613 | int GetStringInPare( char *buffer, const char *ReadBuffer, bool isRemovePare ){
|
---|
| 614 | int i,IsStr,PareNum;
|
---|
| 615 | for(i=0,IsStr=0,PareNum=0;;i++){
|
---|
| 616 | buffer[i]=ReadBuffer[i];
|
---|
| 617 | if(IsDBCSLeadByte(ReadBuffer[i])){
|
---|
| 618 | i++;
|
---|
| 619 | buffer[i]=ReadBuffer[i];
|
---|
| 620 | continue;
|
---|
| 621 | }
|
---|
| 622 | if(ReadBuffer[i]=='\"') IsStr^=1;
|
---|
| 623 | else if(ReadBuffer[i]=='('&&IsStr==0) PareNum++;
|
---|
| 624 | else if(ReadBuffer[i]==')'&&IsStr==0){
|
---|
| 625 | PareNum--;
|
---|
| 626 | if(PareNum==0){
|
---|
| 627 | i++;
|
---|
| 628 | buffer[i]=0;
|
---|
| 629 | break;
|
---|
| 630 | }
|
---|
| 631 | }
|
---|
| 632 | else if(ReadBuffer[i]=='\0') return 0;
|
---|
| 633 | }
|
---|
| 634 |
|
---|
| 635 | if( isRemovePare )
|
---|
| 636 | {
|
---|
| 637 | RemoveStringPare( buffer );
|
---|
| 638 | }
|
---|
| 639 |
|
---|
| 640 | return i;
|
---|
| 641 | }
|
---|
| 642 | int GetStringInBracket(char *buffer,const char *ReadBuffer){
|
---|
| 643 | int i,IsStr,PareNum;
|
---|
| 644 | for(i=0,IsStr=0,PareNum=0;;i++){
|
---|
| 645 | buffer[i]=ReadBuffer[i];
|
---|
| 646 | if(IsDBCSLeadByte(ReadBuffer[i])){
|
---|
| 647 | i++;
|
---|
| 648 | buffer[i]=ReadBuffer[i];
|
---|
| 649 | continue;
|
---|
| 650 | }
|
---|
| 651 | if(ReadBuffer[i]=='\"') IsStr^=1;
|
---|
| 652 | else if(ReadBuffer[i]=='['&&IsStr==0) PareNum++;
|
---|
| 653 | else if(ReadBuffer[i]==']'&&IsStr==0){
|
---|
| 654 | PareNum--;
|
---|
| 655 | if(PareNum==0){
|
---|
| 656 | i++;
|
---|
| 657 | buffer[i]=0;
|
---|
| 658 | break;
|
---|
| 659 | }
|
---|
| 660 | }
|
---|
| 661 | else if(ReadBuffer[i]=='\0') return 0;
|
---|
| 662 | }
|
---|
| 663 | return i;
|
---|
| 664 | }
|
---|
| 665 | int GetStringInGenericBracket(char *buffer,const char *ReadBuffer){
|
---|
| 666 | int i,IsStr,PareNum;
|
---|
| 667 | for(i=0,IsStr=0,PareNum=0;;i++){
|
---|
| 668 | buffer[i]=ReadBuffer[i];
|
---|
| 669 | if(IsDBCSLeadByte(ReadBuffer[i])){
|
---|
| 670 | i++;
|
---|
| 671 | buffer[i]=ReadBuffer[i];
|
---|
| 672 | continue;
|
---|
| 673 | }
|
---|
| 674 | if(ReadBuffer[i]=='\"') IsStr^=1;
|
---|
| 675 | else if(ReadBuffer[i]=='<'&&IsStr==0) PareNum++;
|
---|
| 676 | else if(ReadBuffer[i]=='>'&&IsStr==0){
|
---|
| 677 | PareNum--;
|
---|
| 678 | if(PareNum==0){
|
---|
| 679 | i++;
|
---|
| 680 | buffer[i]=0;
|
---|
| 681 | break;
|
---|
| 682 | }
|
---|
| 683 | }
|
---|
| 684 | else if(ReadBuffer[i]=='\0') return 0;
|
---|
| 685 | }
|
---|
| 686 | return i;
|
---|
| 687 | }
|
---|
| 688 | int JumpStringInPare(const char *buffer,int pos){
|
---|
| 689 | int PareNum;
|
---|
| 690 | for(PareNum=1;;pos++){
|
---|
| 691 | if(buffer[pos]=='\"'){
|
---|
| 692 | for(pos++;;pos++){
|
---|
| 693 | if(buffer[pos]=='\"') break;
|
---|
| 694 | }
|
---|
| 695 | continue;
|
---|
| 696 | }
|
---|
| 697 | else if(buffer[pos]=='(') PareNum++;
|
---|
| 698 | else if(buffer[pos]==')'){
|
---|
| 699 | PareNum--;
|
---|
| 700 | if(PareNum==0) return pos;
|
---|
| 701 | }
|
---|
| 702 | else if(buffer[pos]=='\0') break;
|
---|
| 703 | }
|
---|
| 704 | return 0;
|
---|
| 705 | }
|
---|
| 706 | int JumpStringInBracket(const char *buffer,int pos){
|
---|
| 707 | int PareNum;
|
---|
| 708 | for(PareNum=1;;pos++){
|
---|
| 709 | if(buffer[pos]=='\"'){
|
---|
| 710 | for(pos++;;pos++){
|
---|
| 711 | if(buffer[pos]=='\"') break;
|
---|
| 712 | }
|
---|
| 713 | continue;
|
---|
| 714 | }
|
---|
| 715 | else if(buffer[pos]=='[') PareNum++;
|
---|
| 716 | else if(buffer[pos]==']'){
|
---|
| 717 | PareNum--;
|
---|
| 718 | if(PareNum==0) return pos;
|
---|
| 719 | }
|
---|
| 720 | else if(buffer[pos]=='\0') break;
|
---|
| 721 | }
|
---|
| 722 | return 0;
|
---|
| 723 | }
|
---|
| 724 | bool IsCommandDelimitation( char c ){
|
---|
| 725 | if( c == '\n' || c == ':' || c == '\0' ){
|
---|
| 726 | return true;
|
---|
| 727 | }
|
---|
| 728 |
|
---|
| 729 | return false;
|
---|
| 730 | }
|
---|
| 731 |
|
---|
| 732 | int GetStringInPare_RemovePare(char *buffer,const char *ReadBuffer){
|
---|
| 733 | int i,IsStr,PareNum;
|
---|
| 734 | for(i=0,IsStr=0,PareNum=1;;i++){
|
---|
| 735 | buffer[i]=ReadBuffer[i];
|
---|
| 736 | if(IsDBCSLeadByte(ReadBuffer[i])){
|
---|
| 737 | i++;
|
---|
| 738 | buffer[i]=ReadBuffer[i];
|
---|
| 739 | continue;
|
---|
| 740 | }
|
---|
| 741 | if(ReadBuffer[i]=='\"') IsStr^=1;
|
---|
| 742 | else if(ReadBuffer[i]=='('&&IsStr==0) PareNum++;
|
---|
| 743 | else if(ReadBuffer[i]==')'&&IsStr==0){
|
---|
| 744 | PareNum--;
|
---|
| 745 | if(PareNum==0){
|
---|
| 746 | buffer[i]=0;
|
---|
| 747 | break;
|
---|
| 748 | }
|
---|
| 749 | }
|
---|
| 750 | else if(ReadBuffer[i]=='\0') return 0;
|
---|
| 751 | }
|
---|
| 752 | return i;
|
---|
| 753 | }
|
---|
| 754 |
|
---|
| 755 | void SplitParameter( const std::string &src, Jenga::Common::Strings &dests, bool isClear )
|
---|
| 756 | {
|
---|
| 757 | const char *buffer = src.c_str();
|
---|
| 758 | int i = 0;
|
---|
| 759 |
|
---|
| 760 | if( isClear )
|
---|
| 761 | {
|
---|
| 762 | dests.clear();
|
---|
| 763 | }
|
---|
| 764 |
|
---|
| 765 | while( buffer[i] )
|
---|
| 766 | {
|
---|
| 767 | char result[8192];
|
---|
| 768 | i = GetOneParameter( buffer, i, result );
|
---|
| 769 | dests.push_back( result );
|
---|
| 770 | }
|
---|
| 771 | }
|
---|
| 772 |
|
---|
| 773 |
|
---|
| 774 | bool SplitMemberName( const char *desc, char *object, char *member, ReferenceKind &refType ){
|
---|
| 775 | int lastIndex = -1;
|
---|
| 776 | for( int i=0; desc[i]; i++ ){
|
---|
| 777 | if( desc[i] == '(' ){
|
---|
| 778 | i=JumpStringInPare(desc,i+1);
|
---|
| 779 | continue;
|
---|
| 780 | }
|
---|
| 781 | else if( desc[i] == '[' ){
|
---|
| 782 | i=JumpStringInBracket(desc,i+1);
|
---|
| 783 | continue;
|
---|
| 784 | }
|
---|
| 785 | else if(desc[i]=='.'||(desc[i]==1&&desc[i+1]==ESC_PSMEM)){
|
---|
| 786 | lastIndex = i;
|
---|
| 787 | }
|
---|
| 788 | }
|
---|
| 789 | if( lastIndex == -1 ){
|
---|
| 790 | if( object )
|
---|
| 791 | {
|
---|
| 792 | object[0] = 0;
|
---|
| 793 | }
|
---|
| 794 | lstrcpy( member, desc );
|
---|
| 795 | return false;
|
---|
| 796 | }
|
---|
| 797 |
|
---|
| 798 | if(desc[lastIndex]=='.'){
|
---|
| 799 | lstrcpy(member,desc+lastIndex+1);
|
---|
| 800 | refType = RefDot;
|
---|
| 801 | }
|
---|
| 802 | else{
|
---|
| 803 | lstrcpy(member,desc+lastIndex+2);
|
---|
| 804 | refType = RefPointer;
|
---|
| 805 | }
|
---|
| 806 |
|
---|
| 807 | if( object ){
|
---|
| 808 | lstrcpy( object, desc );
|
---|
| 809 | object[lastIndex]=0;
|
---|
| 810 | }
|
---|
| 811 |
|
---|
| 812 | return true;
|
---|
| 813 | }
|
---|
| 814 | bool SplitMemberName( const char *desc, char *object, char *member ){
|
---|
| 815 | ReferenceKind dummyRefType;
|
---|
| 816 | return SplitMemberName( desc, object, member, dummyRefType );
|
---|
| 817 | }
|
---|
| 818 |
|
---|
| 819 | void SplitSyntacticForAs( const char *src, char *varName, char *typeName)
|
---|
| 820 | {
|
---|
| 821 | int i = 0;
|
---|
| 822 | for( ; ; i++ )
|
---|
| 823 | {
|
---|
| 824 | if( src[i] == '\0' || src[i] == 1 && src[i+1] == ESC_AS )
|
---|
| 825 | {
|
---|
| 826 | varName[i] = 0;
|
---|
| 827 | break;
|
---|
| 828 | }
|
---|
| 829 | varName[i] = src[i];
|
---|
| 830 | }
|
---|
| 831 |
|
---|
| 832 | if( src[i] )
|
---|
| 833 | {
|
---|
| 834 | lstrcpy( typeName, src + i + 2 );
|
---|
| 835 | }
|
---|
| 836 | else
|
---|
| 837 | {
|
---|
| 838 | typeName[i] = 0;
|
---|
| 839 | }
|
---|
| 840 | }
|
---|
| 841 |
|
---|
| 842 | char *calcNames[255] = {
|
---|
| 843 | "xor",
|
---|
| 844 | };
|
---|
| 845 | void InitCalcNames()
|
---|
| 846 | {
|
---|
| 847 | if( calcNames[CALC_XOR] )
|
---|
| 848 | {
|
---|
| 849 | return;
|
---|
| 850 | }
|
---|
| 851 |
|
---|
| 852 | memset( calcNames, 0, 255 * sizeof(char *) );
|
---|
| 853 | calcNames[CALC_XOR] = "xor";
|
---|
| 854 | calcNames[CALC_OR] = "or";
|
---|
| 855 | calcNames[CALC_AND] = "and";
|
---|
| 856 | calcNames[CALC_NOT] = "Not";
|
---|
| 857 | calcNames[CALC_PE] = "<=";
|
---|
| 858 | calcNames[CALC_QE] = ">=";
|
---|
| 859 | calcNames[CALC_NOTEQUAL] = "<>";
|
---|
| 860 | calcNames[CALC_EQUAL] = "=(compare)";
|
---|
| 861 | calcNames[CALC_P] = "<";
|
---|
| 862 | calcNames[CALC_Q] = ">";
|
---|
| 863 | calcNames[CALC_SHL] = "<<";
|
---|
| 864 | calcNames[CALC_SHR] = ">>";
|
---|
| 865 | calcNames[CALC_ADDITION] = "+";
|
---|
| 866 | calcNames[CALC_SUBTRACTION] = "-";
|
---|
| 867 | calcNames[CALC_STRPLUS] = "&";
|
---|
| 868 | calcNames[CALC_MOD] = "mod";
|
---|
| 869 | calcNames[CALC_PRODUCT] = "*";
|
---|
| 870 | calcNames[CALC_QUOTIENT] = "/";
|
---|
| 871 | calcNames[CALC_INTQUOTIENT] = "\\";
|
---|
| 872 | calcNames[CALC_AS] = "As";
|
---|
| 873 | calcNames[CALC_BYVAL] = "ByVal";
|
---|
| 874 | calcNames[CALC_MINUSMARK] = "-(mark)";
|
---|
| 875 | calcNames[CALC_POWER] = "^";
|
---|
| 876 | calcNames[CALC_SUBSITUATION] = "=";
|
---|
| 877 | calcNames[CALC_ARRAY_GET] = "[]";
|
---|
| 878 | calcNames[CALC_ARRAY_SET] = "[]=";
|
---|
| 879 | }
|
---|
| 880 | void GetCalcName(int idCalc,char *name){
|
---|
| 881 | InitCalcNames();
|
---|
| 882 |
|
---|
| 883 | if( calcNames[idCalc] == NULL )
|
---|
| 884 | {
|
---|
| 885 | SetError();
|
---|
| 886 | }
|
---|
| 887 | lstrcpy( name, calcNames[idCalc] );
|
---|
| 888 | }
|
---|
| 889 | BYTE ToCalcId( const char *name )
|
---|
| 890 | {
|
---|
| 891 | InitCalcNames();
|
---|
| 892 |
|
---|
| 893 | for( int i=0; i<255; i++ )
|
---|
| 894 | {
|
---|
| 895 | if( calcNames[i] )
|
---|
| 896 | {
|
---|
| 897 | if( lstrcmp( name, calcNames[i] ) == 0 )
|
---|
| 898 | {
|
---|
| 899 | return i;
|
---|
| 900 | }
|
---|
| 901 | }
|
---|
| 902 | }
|
---|
| 903 | SetError();
|
---|
| 904 | return 0;
|
---|
| 905 | }
|
---|
| 906 |
|
---|
| 907 | std::string Operator_NaturalStringToCalcMarkString( const std::string &name )
|
---|
| 908 | {
|
---|
| 909 | if( name[0] == 1 && name[1] == ESC_OPERATOR )
|
---|
| 910 | {
|
---|
| 911 | BYTE calcId = ToCalcId( name.c_str()+2 );
|
---|
| 912 | char temporary[255];
|
---|
| 913 | temporary[0] = name[0];
|
---|
| 914 | temporary[1] = name[1];
|
---|
| 915 | temporary[2] = calcId;
|
---|
| 916 | temporary[3] = 0;
|
---|
| 917 | return temporary;
|
---|
| 918 | }
|
---|
| 919 | return name;
|
---|
| 920 | }
|
---|
| 921 | std::string Operator_CalcMarkStringToNaturalString( const std::string &name )
|
---|
| 922 | {
|
---|
| 923 | if( name[0] == 1 && name[1] == ESC_OPERATOR )
|
---|
| 924 | {
|
---|
| 925 | BYTE calcId = name[2];
|
---|
| 926 | char temporary[255], calcName[255];
|
---|
| 927 | GetCalcName( calcId, calcName );
|
---|
| 928 | temporary[0] = name[0];
|
---|
| 929 | temporary[1] = name[1];
|
---|
| 930 | lstrcpy( temporary+2, calcName );
|
---|
| 931 | return temporary;
|
---|
| 932 | }
|
---|
| 933 | return name;
|
---|
| 934 | }
|
---|
| 935 |
|
---|
| 936 | bool IsGenericTypeSourcePart( const char *buffer )
|
---|
| 937 | {
|
---|
| 938 | if( buffer[0] != '<' )
|
---|
| 939 | {
|
---|
| 940 | Jenga::Throw( "意図しない文字列に対してIsGenericTypeSourcePart関数が呼ばれた" );
|
---|
| 941 | return false;
|
---|
| 942 | }
|
---|
| 943 |
|
---|
| 944 | int i=1, scopeCount=1;
|
---|
| 945 | for( ; ; i++ )
|
---|
| 946 | {
|
---|
| 947 | if( buffer[i] == '\0' )
|
---|
| 948 | {
|
---|
| 949 | break;
|
---|
| 950 | }
|
---|
| 951 | if( buffer[i] == '<' )
|
---|
| 952 | {
|
---|
| 953 | scopeCount++;
|
---|
| 954 | }
|
---|
| 955 | else if( buffer[i] == '>' )
|
---|
| 956 | {
|
---|
| 957 | scopeCount--;
|
---|
| 958 |
|
---|
| 959 | if( scopeCount == 0 )
|
---|
| 960 | {
|
---|
| 961 | break;
|
---|
| 962 | }
|
---|
| 963 | }
|
---|
| 964 | }
|
---|
| 965 |
|
---|
| 966 | if( buffer[i] != '>' )
|
---|
| 967 | {
|
---|
| 968 | return false;
|
---|
| 969 | }
|
---|
| 970 |
|
---|
| 971 |
|
---|
| 972 | /////////////////////////////////////////////////////////////////
|
---|
| 973 | // '>'に続く文字を判定する
|
---|
| 974 | /////////////////////////////////////////////////////////////////
|
---|
| 975 |
|
---|
| 976 | i++;
|
---|
| 977 | while( IsBlank( buffer[i] ) )
|
---|
| 978 | {
|
---|
| 979 | i++;
|
---|
| 980 | }
|
---|
| 981 |
|
---|
| 982 | if( IsVariableChar( buffer[i] ) )
|
---|
| 983 | {
|
---|
| 984 | return false;
|
---|
| 985 | }
|
---|
| 986 |
|
---|
| 987 | return true;
|
---|
| 988 | }
|
---|