** type: DOT, SELF, TABLE, SQUARE_BRACKET ** input and output ** rstr "a" " a" "or" a a+2 ** SELF :a ERROR ERROR ERROR ERROR ** DOT .a [" a"] ["or"] [a] [a+2] ** TABLE a [" a"] ["or"] [a] [a+2] ** SB ["a"] [" a"] ["or"] [a] [a+2] */
| 1613 | ** SB ["a"] [" a"] ["or"] [a] [a+2] |
| 1614 | */ |
| 1615 | IndexType MakeIndex(GluaDecompileContextP ctx, Function* F, std::stringstream &str, std::string rstr, IndexType type) { |
| 1616 | int ret; |
| 1617 | int len = (int) rstr.length(); |
| 1618 | if (type == SQUARE_BRACKET) { |
| 1619 | str << "[" << rstr << "]"; |
| 1620 | return SQUARE_BRACKET; |
| 1621 | } |
| 1622 | /* |
| 1623 | * see if index can be expressed without quotes |
| 1624 | */ |
| 1625 | if (rstr[0] == '\"' && rstr[len - 1] == '\"') { |
| 1626 | rstr[len - 1] = '\0'; |
| 1627 | if (isIdentifier((rstr.c_str() + 1))) { |
| 1628 | switch (type) { |
| 1629 | case SELF: |
| 1630 | str << ":" << (rstr.c_str() + 1); |
| 1631 | ret = SELF; |
| 1632 | break; |
| 1633 | case DOT: |
| 1634 | str << "." << (rstr.c_str() + 1); |
| 1635 | ret = DOT; |
| 1636 | break; |
| 1637 | case TABLE: |
| 1638 | str << (rstr.c_str() + 1); |
| 1639 | ret = TABLE; |
| 1640 | break; |
| 1641 | } |
| 1642 | rstr[len - 1] = '\"'; |
| 1643 | return (IndexType_) ret; |
| 1644 | } |
| 1645 | rstr[len - 1] = '\"'; |
| 1646 | } |
| 1647 | |
| 1648 | if (type != SELF) { |
| 1649 | str << "[" << rstr << "]"; |
| 1650 | return SQUARE_BRACKET; |
| 1651 | } |
| 1652 | else { |
| 1653 | std::string errorbuff; |
| 1654 | str << ":[" << rstr << "]"; |
| 1655 | errorbuff = "[" + rstr + "] should be a SELF Operator"; |
| 1656 | SET_ERROR(ctx, F, errorbuff); |
| 1657 | return SQUARE_BRACKET; |
| 1658 | } |
| 1659 | } |
| 1660 | |
| 1661 | void ShowState(GluaDecompileContextP ctx, Function* F) { |
| 1662 | int i; |
no test coverage detected