system/corennnnn
リビジョン | b96ebd7ef928b82e9c4cf1d943cc002c25c3ca7e (tree) |
---|---|
日時 | 2009-06-13 05:56:12 |
作者 | Android (Google) Code Review <android-gerrit@goog...> |
コミッター | Android (Google) Code Review |
Merge change 4092
* changes:
@@ -1502,6 +1502,41 @@ class Compiler : public ErrorSink { | ||
1502 | 1502 | // be able to have symbols named pragma or define. |
1503 | 1503 | put("pragma", TOK_PRAGMA); |
1504 | 1504 | put("define", TOK_DEFINE); |
1505 | + | |
1506 | + const char* unsupported[] = { | |
1507 | + "auto", | |
1508 | + "case", | |
1509 | + "const", | |
1510 | + "continue", | |
1511 | + "default", | |
1512 | + "do", | |
1513 | + "double", | |
1514 | + "enum", | |
1515 | + "extern", | |
1516 | + "float", | |
1517 | + "goto", | |
1518 | + "long", | |
1519 | + "register", | |
1520 | + "short", | |
1521 | + "signed", | |
1522 | + "sizeof", | |
1523 | + "static", | |
1524 | + "struct", | |
1525 | + "switch", | |
1526 | + "typedef", | |
1527 | + "union", | |
1528 | + "unsigned", | |
1529 | + "volatile", | |
1530 | + "_Bool", | |
1531 | + "_Complex", | |
1532 | + "_Imaginary", | |
1533 | + "inline", | |
1534 | + "restrict", | |
1535 | + 0}; | |
1536 | + | |
1537 | + for(int i = 0; unsupported[i]; i++) { | |
1538 | + put(unsupported[i], TOK_UNSUPPORTED_KEYWORD); | |
1539 | + } | |
1505 | 1540 | } |
1506 | 1541 | |
1507 | 1542 | ~KeywordTable() { |
@@ -1773,6 +1808,7 @@ class Compiler : public ErrorSink { | ||
1773 | 1808 | static const int TOK_FOR = TOK_KEYWORD + 8; |
1774 | 1809 | static const int TOK_PRAGMA = TOK_KEYWORD + 9; |
1775 | 1810 | static const int TOK_DEFINE = TOK_KEYWORD + 10; |
1811 | + static const int TOK_UNSUPPORTED_KEYWORD = TOK_KEYWORD + 0xff; | |
1776 | 1812 | |
1777 | 1813 | static const int TOK_UNDEFINED_SYMBOL = 0x200; |
1778 | 1814 |
@@ -2463,12 +2499,6 @@ class Compiler : public ErrorSink { | ||
2463 | 2499 | } |
2464 | 2500 | } |
2465 | 2501 | |
2466 | - void checkSymbol() { | |
2467 | - if (tok < TOK_SYMBOL) { | |
2468 | - error("Expected a symbol"); | |
2469 | - } | |
2470 | - } | |
2471 | - | |
2472 | 2502 | void addGlobalSymbol() { |
2473 | 2503 | tok = (intptr_t) mSymbolTable.addGlobal( |
2474 | 2504 | new String(mTokenString)); |
@@ -2494,10 +2524,12 @@ class Compiler : public ErrorSink { | ||
2494 | 2524 | while (acceptType(base)) { |
2495 | 2525 | while (tok != ';' && tok != EOF) { |
2496 | 2526 | Type t = acceptPointerDeclaration(t); |
2497 | - addLocalSymbol(); | |
2498 | - if (tok) { | |
2499 | - loc = loc + 4; | |
2500 | - *(int *) tok = -loc; | |
2527 | + if (checkSymbol()) { | |
2528 | + addLocalSymbol(); | |
2529 | + if (tok) { | |
2530 | + loc = loc + 4; | |
2531 | + *(int *) tok = -loc; | |
2532 | + } | |
2501 | 2533 | } |
2502 | 2534 | next(); |
2503 | 2535 | if (tok == ',') |
@@ -2507,11 +2539,37 @@ class Compiler : public ErrorSink { | ||
2507 | 2539 | } |
2508 | 2540 | } |
2509 | 2541 | |
2542 | + bool checkSymbol() { | |
2543 | + bool result = isSymbol(); | |
2544 | + if (!result) { | |
2545 | + String temp; | |
2546 | + if (tok >= 0 && tok < 256) { | |
2547 | + temp.printf("char \'%c\'", tok); | |
2548 | + } else if (tok >= TOK_KEYWORD && tok < TOK_UNSUPPORTED_KEYWORD) { | |
2549 | + temp.printf("keyword \"%s\"", mTokenString.getUnwrapped()); | |
2550 | + } else { | |
2551 | + temp.printf("reserved keyword \"%s\"", | |
2552 | + mTokenString.getUnwrapped()); | |
2553 | + } | |
2554 | + error("Expected symbol. Got %s", temp.getUnwrapped()); | |
2555 | + } | |
2556 | + return result; | |
2557 | + } | |
2558 | + | |
2559 | + /* Is a possibly undefined symbol */ | |
2560 | + bool isSymbol() { | |
2561 | + return tok < EOF || tok >= TOK_UNDEFINED_SYMBOL; | |
2562 | + } | |
2563 | + | |
2510 | 2564 | void globalDeclarations() { |
2511 | 2565 | while (tok != EOF) { |
2512 | 2566 | Type base; |
2513 | 2567 | expectType(base); |
2514 | 2568 | Type t = acceptPointerDeclaration(t); |
2569 | + if (tok >= 0 && tok < TOK_UNDEFINED_SYMBOL) { | |
2570 | + error("Unexpected token %d", tok); | |
2571 | + break; | |
2572 | + } | |
2515 | 2573 | if (tok == TOK_UNDEFINED_SYMBOL) { |
2516 | 2574 | addGlobalSymbol(); |
2517 | 2575 | } |
@@ -2553,11 +2611,13 @@ class Compiler : public ErrorSink { | ||
2553 | 2611 | Type aType; |
2554 | 2612 | expectType(aType); |
2555 | 2613 | aType = acceptPointerDeclaration(aType); |
2556 | - addLocalSymbol(); | |
2557 | - if (tok) { | |
2558 | - /* read param name and compute offset */ | |
2559 | - *(int *) tok = a; | |
2560 | - a = a + 4; | |
2614 | + if (checkSymbol()) { | |
2615 | + addLocalSymbol(); | |
2616 | + if (tok) { | |
2617 | + /* read param name and compute offset */ | |
2618 | + *(int *) tok = a; | |
2619 | + a = a + 4; | |
2620 | + } | |
2561 | 2621 | } |
2562 | 2622 | next(); |
2563 | 2623 | if (tok == ',') |