[300] | 1 | #include <jenga/include/common/Exception.h>
|
---|
[205] | 2 | #include <jenga/include/smoothie/SmoothieException.h>
|
---|
[173] | 3 | #include <jenga/include/smoothie/LexicalAnalysis.h>
|
---|
[205] | 4 | #include <jenga/include/smoothie/BasicFixed.h>
|
---|
[173] | 5 |
|
---|
| 6 | #include <windows.h>
|
---|
| 7 |
|
---|
| 8 | bool IsVariableTopChar(char c){
|
---|
| 9 | if((c>='A'&&c<='Z')||(c>='a'&&c<='z')||c=='_')
|
---|
| 10 | {
|
---|
| 11 | return true;
|
---|
| 12 | }
|
---|
| 13 | return false;
|
---|
| 14 | }
|
---|
| 15 | bool IsVariableChar(char c){
|
---|
| 16 | if((c>='A'&&c<='Z')||(c>='a'&&c<='z')||(c>='0'&&c<='9')||
|
---|
| 17 | c=='%'||c=='!'||c=='#'||c=='$'||
|
---|
| 18 | c=='_'||c=='.')
|
---|
| 19 | {
|
---|
| 20 | return true;
|
---|
| 21 | }
|
---|
| 22 | return false;
|
---|
| 23 | }
|
---|
| 24 | bool IsBlank(char c){
|
---|
| 25 | if(c==' '||c=='\t') return 1;
|
---|
| 26 | return 0;
|
---|
| 27 | }
|
---|
| 28 | int GetOneParameter(const char *Parameter,int pos,char *retAns){
|
---|
| 29 | int i,i2,i3,IsStr;
|
---|
| 30 | for(i=pos,i2=0,IsStr=0;;i++,i2++){
|
---|
| 31 | if(Parameter[i]=='\"') IsStr^=1;
|
---|
| 32 | else if(Parameter[i]=='('&&IsStr==0){
|
---|
| 33 | i3=GetStringInPare(retAns+i2,Parameter+i);
|
---|
| 34 | i+=i3-1;
|
---|
| 35 | i2+=i3-1;
|
---|
| 36 | continue;
|
---|
| 37 | }
|
---|
| 38 | else if(Parameter[i]=='['&&IsStr==0){
|
---|
| 39 | i3=GetStringInBracket(retAns+i2,Parameter+i);
|
---|
| 40 | i+=i3-1;
|
---|
| 41 | i2+=i3-1;
|
---|
| 42 | continue;
|
---|
| 43 | }
|
---|
| 44 | else if(Parameter[i]==','&&IsStr==0){
|
---|
| 45 | retAns[i2]=0;
|
---|
| 46 | i++;
|
---|
| 47 | break;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | if(IsCommandDelimitation(Parameter[i])&&IsStr==0
|
---|
| 51 | || Parameter[i] == ')' && IsStr == 0 ){
|
---|
| 52 | retAns[i2]=0;
|
---|
| 53 | break;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | retAns[i2]=Parameter[i];
|
---|
| 57 | }
|
---|
| 58 | return i;
|
---|
| 59 | }
|
---|
| 60 | int JumpOneParameter(char *Parameter,int i){
|
---|
| 61 | int i2,IsStr;
|
---|
| 62 | for(i2=0,IsStr=0;;i++,i2++){
|
---|
| 63 | if(Parameter[i]=='\"') IsStr^=1;
|
---|
| 64 | else if(Parameter[i]=='('&&IsStr==0){
|
---|
| 65 | i=JumpStringInPare(Parameter,i+1);
|
---|
| 66 | continue;
|
---|
| 67 | }
|
---|
| 68 | else if(Parameter[i]=='['&&IsStr==0){
|
---|
| 69 | i=JumpStringInBracket(Parameter,i+1);
|
---|
| 70 | continue;
|
---|
| 71 | }
|
---|
| 72 | else if(Parameter[i]==','&&IsStr==0){
|
---|
| 73 | i++;
|
---|
| 74 | break;
|
---|
| 75 | }
|
---|
| 76 | if(IsCommandDelimitation(Parameter[i])) break;
|
---|
| 77 | }
|
---|
| 78 | return i;
|
---|
| 79 | }
|
---|
| 80 | int GetStringInQuotation(char *buffer,char *ReadBuffer){
|
---|
| 81 | int i;
|
---|
| 82 |
|
---|
| 83 | if(ReadBuffer[0]=='\"'){
|
---|
| 84 | buffer[0]=ReadBuffer[0];
|
---|
| 85 | i=1;
|
---|
| 86 | }
|
---|
| 87 | else i=0;
|
---|
| 88 |
|
---|
| 89 | for(;;i++){
|
---|
| 90 | buffer[i]=ReadBuffer[i];
|
---|
| 91 | if(IsDBCSLeadByte(ReadBuffer[i])){
|
---|
| 92 | i++;
|
---|
| 93 | buffer[i]=ReadBuffer[i];
|
---|
| 94 | continue;
|
---|
| 95 | }
|
---|
| 96 | if(ReadBuffer[i]=='\"'){
|
---|
| 97 | i++;
|
---|
| 98 | buffer[i]=0;
|
---|
| 99 | break;
|
---|
| 100 | }
|
---|
| 101 | if(ReadBuffer[i]=='\0') return 0;
|
---|
| 102 | }
|
---|
| 103 | return i;
|
---|
| 104 | }
|
---|
| 105 | int GetStringInPare(char *buffer,const char *ReadBuffer){
|
---|
| 106 | int i,IsStr,PareNum;
|
---|
| 107 | for(i=0,IsStr=0,PareNum=0;;i++){
|
---|
| 108 | buffer[i]=ReadBuffer[i];
|
---|
| 109 | if(IsDBCSLeadByte(ReadBuffer[i])){
|
---|
| 110 | i++;
|
---|
| 111 | buffer[i]=ReadBuffer[i];
|
---|
| 112 | continue;
|
---|
| 113 | }
|
---|
| 114 | if(ReadBuffer[i]=='\"') IsStr^=1;
|
---|
| 115 | else if(ReadBuffer[i]=='('&&IsStr==0) PareNum++;
|
---|
| 116 | else if(ReadBuffer[i]==')'&&IsStr==0){
|
---|
| 117 | PareNum--;
|
---|
| 118 | if(PareNum==0){
|
---|
| 119 | i++;
|
---|
| 120 | buffer[i]=0;
|
---|
| 121 | break;
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 | else if(ReadBuffer[i]=='\0') return 0;
|
---|
| 125 | }
|
---|
| 126 | return i;
|
---|
| 127 | }
|
---|
| 128 | int GetStringInBracket(char *buffer,const char *ReadBuffer){
|
---|
| 129 | int i,IsStr,PareNum;
|
---|
| 130 | for(i=0,IsStr=0,PareNum=0;;i++){
|
---|
| 131 | buffer[i]=ReadBuffer[i];
|
---|
| 132 | if(IsDBCSLeadByte(ReadBuffer[i])){
|
---|
| 133 | i++;
|
---|
| 134 | buffer[i]=ReadBuffer[i];
|
---|
| 135 | continue;
|
---|
| 136 | }
|
---|
| 137 | if(ReadBuffer[i]=='\"') IsStr^=1;
|
---|
| 138 | else if(ReadBuffer[i]=='['&&IsStr==0) PareNum++;
|
---|
| 139 | else if(ReadBuffer[i]==']'&&IsStr==0){
|
---|
| 140 | PareNum--;
|
---|
| 141 | if(PareNum==0){
|
---|
| 142 | i++;
|
---|
| 143 | buffer[i]=0;
|
---|
| 144 | break;
|
---|
| 145 | }
|
---|
| 146 | }
|
---|
| 147 | else if(ReadBuffer[i]=='\0') return 0;
|
---|
| 148 | }
|
---|
| 149 | return i;
|
---|
| 150 | }
|
---|
[300] | 151 | int GetStringInGenericBracket(char *buffer,const char *ReadBuffer){
|
---|
| 152 | int i,IsStr,PareNum;
|
---|
| 153 | for(i=0,IsStr=0,PareNum=0;;i++){
|
---|
| 154 | buffer[i]=ReadBuffer[i];
|
---|
| 155 | if(IsDBCSLeadByte(ReadBuffer[i])){
|
---|
| 156 | i++;
|
---|
| 157 | buffer[i]=ReadBuffer[i];
|
---|
| 158 | continue;
|
---|
| 159 | }
|
---|
| 160 | if(ReadBuffer[i]=='\"') IsStr^=1;
|
---|
| 161 | else if(ReadBuffer[i]=='<'&&IsStr==0) PareNum++;
|
---|
| 162 | else if(ReadBuffer[i]=='>'&&IsStr==0){
|
---|
| 163 | PareNum--;
|
---|
| 164 | if(PareNum==0){
|
---|
| 165 | i++;
|
---|
| 166 | buffer[i]=0;
|
---|
| 167 | break;
|
---|
| 168 | }
|
---|
| 169 | }
|
---|
| 170 | else if(ReadBuffer[i]=='\0') return 0;
|
---|
| 171 | }
|
---|
| 172 | return i;
|
---|
| 173 | }
|
---|
[173] | 174 | int JumpStringInPare(const char *buffer,int pos){
|
---|
| 175 | int PareNum;
|
---|
| 176 | for(PareNum=1;;pos++){
|
---|
| 177 | if(buffer[pos]=='\"'){
|
---|
| 178 | for(pos++;;pos++){
|
---|
| 179 | if(buffer[pos]=='\"') break;
|
---|
| 180 | }
|
---|
| 181 | continue;
|
---|
| 182 | }
|
---|
| 183 | else if(buffer[pos]=='(') PareNum++;
|
---|
| 184 | else if(buffer[pos]==')'){
|
---|
| 185 | PareNum--;
|
---|
| 186 | if(PareNum==0) return pos;
|
---|
| 187 | }
|
---|
| 188 | else if(buffer[pos]=='\0') break;
|
---|
| 189 | }
|
---|
| 190 | return 0;
|
---|
| 191 | }
|
---|
| 192 | int JumpStringInBracket(const char *buffer,int pos){
|
---|
| 193 | int PareNum;
|
---|
| 194 | for(PareNum=1;;pos++){
|
---|
| 195 | if(buffer[pos]=='\"'){
|
---|
| 196 | for(pos++;;pos++){
|
---|
| 197 | if(buffer[pos]=='\"') break;
|
---|
| 198 | }
|
---|
| 199 | continue;
|
---|
| 200 | }
|
---|
| 201 | else if(buffer[pos]=='[') PareNum++;
|
---|
| 202 | else if(buffer[pos]==']'){
|
---|
| 203 | PareNum--;
|
---|
| 204 | if(PareNum==0) return pos;
|
---|
| 205 | }
|
---|
| 206 | else if(buffer[pos]=='\0') break;
|
---|
| 207 | }
|
---|
| 208 | return 0;
|
---|
| 209 | }
|
---|
| 210 | bool IsCommandDelimitation( char c ){
|
---|
| 211 | if( c == '\n' || c == ':' || c == '\0' ){
|
---|
| 212 | return true;
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | return false;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | int GetStringInPare_RemovePare(char *buffer,const char *ReadBuffer){
|
---|
| 219 | int i,IsStr,PareNum;
|
---|
| 220 | for(i=0,IsStr=0,PareNum=1;;i++){
|
---|
| 221 | buffer[i]=ReadBuffer[i];
|
---|
| 222 | if(IsDBCSLeadByte(ReadBuffer[i])){
|
---|
| 223 | i++;
|
---|
| 224 | buffer[i]=ReadBuffer[i];
|
---|
| 225 | continue;
|
---|
| 226 | }
|
---|
| 227 | if(ReadBuffer[i]=='\"') IsStr^=1;
|
---|
| 228 | else if(ReadBuffer[i]=='('&&IsStr==0) PareNum++;
|
---|
| 229 | else if(ReadBuffer[i]==')'&&IsStr==0){
|
---|
| 230 | PareNum--;
|
---|
| 231 | if(PareNum==0){
|
---|
| 232 | buffer[i]=0;
|
---|
| 233 | break;
|
---|
| 234 | }
|
---|
| 235 | }
|
---|
| 236 | else if(ReadBuffer[i]=='\0') return 0;
|
---|
| 237 | }
|
---|
| 238 | return i;
|
---|
| 239 | }
|
---|
[205] | 240 |
|
---|
| 241 | bool SplitMemberName( const char *desc, char *object, char *member, ReferenceKind &refType ){
|
---|
| 242 | int lastIndex = -1;
|
---|
| 243 | for( int i=0; desc[i]; i++ ){
|
---|
| 244 | if( desc[i] == '(' ){
|
---|
| 245 | i=JumpStringInPare(desc,i+1);
|
---|
| 246 | continue;
|
---|
| 247 | }
|
---|
| 248 | else if( desc[i] == '[' ){
|
---|
| 249 | i=JumpStringInBracket(desc,i+1);
|
---|
| 250 | continue;
|
---|
| 251 | }
|
---|
| 252 | else if(desc[i]=='.'||(desc[i]==1&&desc[i+1]==ESC_PSMEM)){
|
---|
| 253 | lastIndex = i;
|
---|
| 254 | }
|
---|
| 255 | }
|
---|
| 256 | if( lastIndex == -1 ){
|
---|
| 257 | lstrcpy( member, desc );
|
---|
| 258 | return false;
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | if(desc[lastIndex]=='.'){
|
---|
| 262 | lstrcpy(member,desc+lastIndex+1);
|
---|
| 263 | refType = RefDot;
|
---|
| 264 | }
|
---|
| 265 | else{
|
---|
| 266 | lstrcpy(member,desc+lastIndex+2);
|
---|
| 267 | refType = RefPointer;
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | if( object ){
|
---|
| 271 | lstrcpy( object, desc );
|
---|
| 272 | object[lastIndex]=0;
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | return true;
|
---|
| 276 | }
|
---|
| 277 | bool SplitMemberName( const char *desc, char *object, char *member ){
|
---|
| 278 | ReferenceKind dummyRefType;
|
---|
| 279 | return SplitMemberName( desc, object, member, dummyRefType );
|
---|
| 280 | }
|
---|
| 281 |
|
---|
| 282 | char *calcNames[255] = {
|
---|
| 283 | "xor",
|
---|
| 284 | };
|
---|
| 285 | void InitCalcNames()
|
---|
| 286 | {
|
---|
| 287 | if( calcNames[CALC_XOR] )
|
---|
| 288 | {
|
---|
| 289 | return;
|
---|
| 290 | }
|
---|
| 291 |
|
---|
| 292 | memset( calcNames, 0, 255 * sizeof(char *) );
|
---|
| 293 | calcNames[CALC_XOR] = "xor";
|
---|
| 294 | calcNames[CALC_OR] = "or";
|
---|
| 295 | calcNames[CALC_AND] = "and";
|
---|
| 296 | calcNames[CALC_NOT] = "Not";
|
---|
| 297 | calcNames[CALC_PE] = "<=";
|
---|
| 298 | calcNames[CALC_QE] = ">=";
|
---|
| 299 | calcNames[CALC_NOTEQUAL] = "<>";
|
---|
| 300 | calcNames[CALC_EQUAL] = "=(compare)";
|
---|
| 301 | calcNames[CALC_P] = "<";
|
---|
| 302 | calcNames[CALC_Q] = ">";
|
---|
| 303 | calcNames[CALC_SHL] = "<<";
|
---|
| 304 | calcNames[CALC_SHR] = ">>";
|
---|
| 305 | calcNames[CALC_ADDITION] = "+";
|
---|
| 306 | calcNames[CALC_SUBTRACTION] = "-";
|
---|
[211] | 307 | calcNames[CALC_STRPLUS] = "&";
|
---|
[205] | 308 | calcNames[CALC_MOD] = "mod";
|
---|
| 309 | calcNames[CALC_PRODUCT] = "*";
|
---|
| 310 | calcNames[CALC_QUOTIENT] = "/";
|
---|
| 311 | calcNames[CALC_INTQUOTIENT] = "\\";
|
---|
| 312 | calcNames[CALC_AS] = "As";
|
---|
| 313 | calcNames[CALC_BYVAL] = "ByVal";
|
---|
| 314 | calcNames[CALC_MINUSMARK] = "-(mark)";
|
---|
| 315 | calcNames[CALC_POWER] = "^";
|
---|
| 316 | calcNames[CALC_SUBSITUATION] = "=";
|
---|
| 317 | calcNames[CALC_ARRAY_GET] = "[]";
|
---|
| 318 | calcNames[CALC_ARRAY_SET] = "[]=";
|
---|
| 319 | }
|
---|
| 320 | void GetCalcName(int idCalc,char *name){
|
---|
| 321 | InitCalcNames();
|
---|
| 322 |
|
---|
| 323 | if( calcNames[idCalc] == NULL )
|
---|
| 324 | {
|
---|
| 325 | SmoothieException::Throw();
|
---|
| 326 | }
|
---|
| 327 | lstrcpy( name, calcNames[idCalc] );
|
---|
| 328 | }
|
---|
| 329 | BYTE ToCalcId( const char *name )
|
---|
| 330 | {
|
---|
| 331 | InitCalcNames();
|
---|
| 332 |
|
---|
| 333 | for( int i=0; i<255; i++ )
|
---|
| 334 | {
|
---|
| 335 | if( calcNames[i] )
|
---|
| 336 | {
|
---|
| 337 | if( lstrcmp( name, calcNames[i] ) == 0 )
|
---|
| 338 | {
|
---|
| 339 | return i;
|
---|
| 340 | }
|
---|
| 341 | }
|
---|
| 342 | }
|
---|
| 343 | SmoothieException::Throw();
|
---|
| 344 | return 0;
|
---|
| 345 | }
|
---|
| 346 |
|
---|
| 347 | std::string Operator_NaturalStringToCalcMarkString( const std::string &name )
|
---|
| 348 | {
|
---|
| 349 | if( name[0] == 1 && name[1] == ESC_OPERATOR )
|
---|
| 350 | {
|
---|
| 351 | BYTE calcId = ToCalcId( name.c_str()+2 );
|
---|
| 352 | char temporary[255];
|
---|
| 353 | temporary[0] = name[0];
|
---|
| 354 | temporary[1] = name[1];
|
---|
| 355 | temporary[2] = calcId;
|
---|
| 356 | temporary[3] = 0;
|
---|
| 357 | return temporary;
|
---|
| 358 | }
|
---|
| 359 | return name;
|
---|
| 360 | }
|
---|
| 361 | std::string Operator_CalcMarkStringToNaturalString( const std::string &name )
|
---|
| 362 | {
|
---|
| 363 | if( name[0] == 1 && name[1] == ESC_OPERATOR )
|
---|
| 364 | {
|
---|
| 365 | BYTE calcId = name[2];
|
---|
| 366 | char temporary[255], calcName[255];
|
---|
| 367 | GetCalcName( calcId, calcName );
|
---|
| 368 | temporary[0] = name[0];
|
---|
| 369 | temporary[1] = name[1];
|
---|
| 370 | lstrcpy( temporary+2, calcName );
|
---|
| 371 | return temporary;
|
---|
| 372 | }
|
---|
| 373 | return name;
|
---|
| 374 | }
|
---|
[300] | 375 |
|
---|
| 376 | bool IsGenericTypeSourcePart( const char *buffer )
|
---|
| 377 | {
|
---|
| 378 | if( buffer[0] != '<' )
|
---|
| 379 | {
|
---|
| 380 | Jenga::Throw( "意図しない文字列に対してIsGenericTypeSourcePart関数が呼ばれた" );
|
---|
| 381 | return false;
|
---|
| 382 | }
|
---|
| 383 |
|
---|
| 384 | int i=1, scopeCount=1;
|
---|
| 385 | for( ; ; i++ )
|
---|
| 386 | {
|
---|
| 387 | if( buffer[i] == '\0' )
|
---|
| 388 | {
|
---|
| 389 | break;
|
---|
| 390 | }
|
---|
| 391 | if( buffer[i] == '<' )
|
---|
| 392 | {
|
---|
| 393 | scopeCount++;
|
---|
| 394 | }
|
---|
| 395 | else if( buffer[i] == '>' )
|
---|
| 396 | {
|
---|
| 397 | scopeCount--;
|
---|
| 398 |
|
---|
| 399 | if( scopeCount == 0 )
|
---|
| 400 | {
|
---|
| 401 | break;
|
---|
| 402 | }
|
---|
| 403 | }
|
---|
| 404 | }
|
---|
| 405 |
|
---|
| 406 | if( buffer[i] != '>' )
|
---|
| 407 | {
|
---|
| 408 | return false;
|
---|
| 409 | }
|
---|
| 410 |
|
---|
| 411 |
|
---|
| 412 | /////////////////////////////////////////////////////////////////
|
---|
| 413 | // '>'に続く文字を判定する
|
---|
| 414 | /////////////////////////////////////////////////////////////////
|
---|
| 415 |
|
---|
| 416 | i++;
|
---|
| 417 | while( IsBlank( buffer[i] ) )
|
---|
| 418 | {
|
---|
| 419 | i++;
|
---|
| 420 | }
|
---|
| 421 |
|
---|
| 422 | if( IsVariableChar( buffer[i] ) )
|
---|
| 423 | {
|
---|
| 424 | return false;
|
---|
| 425 | }
|
---|
| 426 |
|
---|
| 427 | return true;
|
---|
| 428 | }
|
---|