aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/parsing/Token.h
diff options
context:
space:
mode:
Diffstat (limited to 'libsolidity/parsing/Token.h')
-rw-r--r--libsolidity/parsing/Token.h139
1 files changed, 40 insertions, 99 deletions
diff --git a/libsolidity/parsing/Token.h b/libsolidity/parsing/Token.h
index 88e77345..a64eded5 100644
--- a/libsolidity/parsing/Token.h
+++ b/libsolidity/parsing/Token.h
@@ -187,107 +187,13 @@ namespace solidity
K(SubWeek, "weeks", 0) \
K(SubYear, "years", 0) \
K(After, "after", 0) \
- /* type keywords, keep them in this order, keep int as first keyword
- * the implementation in Types.cpp has to be synced to this here */\
+ /* type keywords*/ \
K(Int, "int", 0) \
- K(Int8, "int8", 0) \
- K(Int16, "int16", 0) \
- K(Int24, "int24", 0) \
- K(Int32, "int32", 0) \
- K(Int40, "int40", 0) \
- K(Int48, "int48", 0) \
- K(Int56, "int56", 0) \
- K(Int64, "int64", 0) \
- K(Int72, "int72", 0) \
- K(Int80, "int80", 0) \
- K(Int88, "int88", 0) \
- K(Int96, "int96", 0) \
- K(Int104, "int104", 0) \
- K(Int112, "int112", 0) \
- K(Int120, "int120", 0) \
- K(Int128, "int128", 0) \
- K(Int136, "int136", 0) \
- K(Int144, "int144", 0) \
- K(Int152, "int152", 0) \
- K(Int160, "int160", 0) \
- K(Int168, "int168", 0) \
- K(Int176, "int176", 0) \
- K(Int184, "int184", 0) \
- K(Int192, "int192", 0) \
- K(Int200, "int200", 0) \
- K(Int208, "int208", 0) \
- K(Int216, "int216", 0) \
- K(Int224, "int224", 0) \
- K(Int232, "int232", 0) \
- K(Int240, "int240", 0) \
- K(Int248, "int248", 0) \
- K(Int256, "int256", 0) \
+ T(IntM, "intM", 0) \
K(UInt, "uint", 0) \
- K(UInt8, "uint8", 0) \
- K(UInt16, "uint16", 0) \
- K(UInt24, "uint24", 0) \
- K(UInt32, "uint32", 0) \
- K(UInt40, "uint40", 0) \
- K(UInt48, "uint48", 0) \
- K(UInt56, "uint56", 0) \
- K(UInt64, "uint64", 0) \
- K(UInt72, "uint72", 0) \
- K(UInt80, "uint80", 0) \
- K(UInt88, "uint88", 0) \
- K(UInt96, "uint96", 0) \
- K(UInt104, "uint104", 0) \
- K(UInt112, "uint112", 0) \
- K(UInt120, "uint120", 0) \
- K(UInt128, "uint128", 0) \
- K(UInt136, "uint136", 0) \
- K(UInt144, "uint144", 0) \
- K(UInt152, "uint152", 0) \
- K(UInt160, "uint160", 0) \
- K(UInt168, "uint168", 0) \
- K(UInt176, "uint176", 0) \
- K(UInt184, "uint184", 0) \
- K(UInt192, "uint192", 0) \
- K(UInt200, "uint200", 0) \
- K(UInt208, "uint208", 0) \
- K(UInt216, "uint216", 0) \
- K(UInt224, "uint224", 0) \
- K(UInt232, "uint232", 0) \
- K(UInt240, "uint240", 0) \
- K(UInt248, "uint248", 0) \
- K(UInt256, "uint256", 0) \
- K(Bytes1, "bytes1", 0) \
- K(Bytes2, "bytes2", 0) \
- K(Bytes3, "bytes3", 0) \
- K(Bytes4, "bytes4", 0) \
- K(Bytes5, "bytes5", 0) \
- K(Bytes6, "bytes6", 0) \
- K(Bytes7, "bytes7", 0) \
- K(Bytes8, "bytes8", 0) \
- K(Bytes9, "bytes9", 0) \
- K(Bytes10, "bytes10", 0) \
- K(Bytes11, "bytes11", 0) \
- K(Bytes12, "bytes12", 0) \
- K(Bytes13, "bytes13", 0) \
- K(Bytes14, "bytes14", 0) \
- K(Bytes15, "bytes15", 0) \
- K(Bytes16, "bytes16", 0) \
- K(Bytes17, "bytes17", 0) \
- K(Bytes18, "bytes18", 0) \
- K(Bytes19, "bytes19", 0) \
- K(Bytes20, "bytes20", 0) \
- K(Bytes21, "bytes21", 0) \
- K(Bytes22, "bytes22", 0) \
- K(Bytes23, "bytes23", 0) \
- K(Bytes24, "bytes24", 0) \
- K(Bytes25, "bytes25", 0) \
- K(Bytes26, "bytes26", 0) \
- K(Bytes27, "bytes27", 0) \
- K(Bytes28, "bytes28", 0) \
- K(Bytes29, "bytes29", 0) \
- K(Bytes30, "bytes30", 0) \
- K(Bytes31, "bytes31", 0) \
- K(Bytes32, "bytes32", 0) \
+ T(UIntM, "uintM", 0) \
K(Bytes, "bytes", 0) \
+ T(BytesM, "bytesM", 0) \
K(Byte, "byte", 0) \
K(String, "string", 0) \
K(Address, "address", 0) \
@@ -394,14 +300,49 @@ public:
return m_precedence[tok];
}
- static Token::Value fromIdentifierOrKeyword(std::string const& _name);
+ static std::tuple<Token::Value, unsigned short, unsigned short> fromIdentifierOrKeyword(std::string const& _literal);
private:
+ // extractM provides a safe way to extract numbers,
+ // if out_of_range error is thrown, they returns 0s, therefore securing
+ // the variable's identity as an identifier.
+ static unsigned extractM(std::string const& _literal);
+ // @returns the keyword with name @a _name or Token::Identifier of no such keyword exists.
+ static Token::Value keywordByName(std::string const& _name);
static char const* const m_name[NUM_TOKENS];
static char const* const m_string[NUM_TOKENS];
static int8_t const m_precedence[NUM_TOKENS];
static char const m_tokenType[NUM_TOKENS];
};
+class ElementaryTypeNameToken
+{
+public:
+ ElementaryTypeNameToken(Token::Value _token, unsigned const& _firstNumber, unsigned const& _secondNumber)
+ {
+ assertDetails(_token, _firstNumber, _secondNumber);
+ }
+
+ unsigned int firstNumber() const { return m_firstNumber; }
+ unsigned int secondNumber() const { return m_secondNumber; }
+ Token::Value token() const { return m_token; }
+ ///if tokValue is set to true, then returns the actual token type name, otherwise, returns full type
+ std::string toString(bool const& tokenValue = false) const
+ {
+ std::string name = Token::toString(m_token);
+ if (tokenValue || (firstNumber() == 0 && secondNumber() == 0))
+ return name;
+ //need to set it up this way for fixed types construction in future
+ return name.substr(0, name.size() - 1) + std::to_string(m_firstNumber);
+ }
+
+private:
+ Token::Value m_token;
+ unsigned int m_firstNumber;
+ unsigned int m_secondNumber;
+ /// throws if type is not properly sized
+ void assertDetails(Token::Value _baseType, unsigned const& _first, unsigned const& _second);
+};
+
}
}