MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / MakeIndex

Function MakeIndex

src/Chain/libraries/glua/glua_decompile.cpp:1615–1659  ·  view source on GitHub ↗

** 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] */

Source from the content-addressed store, hash-verified

1613** SB ["a"] [" a"] ["or"] [a] [a+2]
1614*/
1615IndexType 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
1661void ShowState(GluaDecompileContextP ctx, Function* F) {
1662 int i;

Callers 2

PrintTableItemKeyedFunction · 0.85
ProcessCodeFunction · 0.85

Calls 3

isIdentifierFunction · 0.85
lengthMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected