aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/ast
diff options
context:
space:
mode:
authorRJ Catalano <rcatalano@macsales.com>2016-02-09 05:43:22 +0800
committerRJ Catalano <rcatalano@macsales.com>2016-02-19 01:22:52 +0800
commit7b918a7bc7a3c619682266b1c2566dacb9dcc765 (patch)
treea8763b90b26cafff938c3cbc261fa85627ac4a8a /libsolidity/ast
parentfca27b9ea00eb580f771820e967f62b58478c9a2 (diff)
downloaddexon-solidity-7b918a7bc7a3c619682266b1c2566dacb9dcc765.tar
dexon-solidity-7b918a7bc7a3c619682266b1c2566dacb9dcc765.tar.gz
dexon-solidity-7b918a7bc7a3c619682266b1c2566dacb9dcc765.tar.bz2
dexon-solidity-7b918a7bc7a3c619682266b1c2566dacb9dcc765.tar.lz
dexon-solidity-7b918a7bc7a3c619682266b1c2566dacb9dcc765.tar.xz
dexon-solidity-7b918a7bc7a3c619682266b1c2566dacb9dcc765.tar.zst
dexon-solidity-7b918a7bc7a3c619682266b1c2566dacb9dcc765.zip
changes to redefine the token list, the scanner, and the parser and how they pass around variable types of different sizes
not ready for change to FixedPoint just yet made this more const correct and added a switch statement for easier reading
Diffstat (limited to 'libsolidity/ast')
-rw-r--r--libsolidity/ast/AST.h25
-rw-r--r--libsolidity/ast/ASTJsonConverter.cpp4
-rw-r--r--libsolidity/ast/ASTPrinter.cpp4
-rw-r--r--libsolidity/ast/Types.cpp66
-rw-r--r--libsolidity/ast/Types.h2
5 files changed, 51 insertions, 50 deletions
diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h
index e1063467..d32d76a4 100644
--- a/libsolidity/ast/AST.h
+++ b/libsolidity/ast/AST.h
@@ -756,18 +756,17 @@ public:
class ElementaryTypeName: public TypeName
{
public:
- ElementaryTypeName(SourceLocation const& _location, Token::Value _type):
- TypeName(_location), m_type(_type)
- {
- solAssert(Token::isElementaryTypeName(_type), "");
- }
+ ElementaryTypeName(SourceLocation const& _location, ElementaryTypeNameToken const& _elem):
+ TypeName(_location), m_type(_elem)
+ {}
+
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
- Token::Value typeName() const { return m_type; }
+ ElementaryTypeNameToken const& typeName() const { return m_type; }
private:
- Token::Value m_type;
+ ElementaryTypeNameToken m_type;
};
/**
@@ -1408,18 +1407,16 @@ private:
class ElementaryTypeNameExpression: public PrimaryExpression
{
public:
- ElementaryTypeNameExpression(SourceLocation const& _location, Token::Value _typeToken):
- PrimaryExpression(_location), m_typeToken(_typeToken)
- {
- solAssert(Token::isElementaryTypeName(_typeToken), "");
- }
+ ElementaryTypeNameExpression(SourceLocation const& _location, ElementaryTypeNameToken const& _type):
+ PrimaryExpression(_location), m_typeToken(_type)
+ {}
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
- Token::Value typeToken() const { return m_typeToken; }
+ ElementaryTypeNameToken const& typeName() const { return m_typeToken; }
private:
- Token::Value m_typeToken;
+ ElementaryTypeNameToken m_typeToken;
};
/**
diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp
index df836afe..163e22f4 100644
--- a/libsolidity/ast/ASTJsonConverter.cpp
+++ b/libsolidity/ast/ASTJsonConverter.cpp
@@ -139,7 +139,7 @@ bool ASTJsonConverter::visit(TypeName const&)
bool ASTJsonConverter::visit(ElementaryTypeName const& _node)
{
- addJsonNode("ElementaryTypeName", { make_pair("name", Token::toString(_node.typeName())) });
+ addJsonNode("ElementaryTypeName", { make_pair("name", _node.typeName().toString()) });
return true;
}
@@ -297,7 +297,7 @@ bool ASTJsonConverter::visit(Identifier const& _node)
bool ASTJsonConverter::visit(ElementaryTypeNameExpression const& _node)
{
addJsonNode("ElementaryTypenameExpression",
- { make_pair("value", Token::toString(_node.typeToken())), make_pair("type", type(_node)) });
+ { make_pair("value", _node.typeName().toString()), make_pair("type", type(_node)) });
return true;
}
diff --git a/libsolidity/ast/ASTPrinter.cpp b/libsolidity/ast/ASTPrinter.cpp
index bc981f7d..283bc8f9 100644
--- a/libsolidity/ast/ASTPrinter.cpp
+++ b/libsolidity/ast/ASTPrinter.cpp
@@ -145,7 +145,7 @@ bool ASTPrinter::visit(TypeName const& _node)
bool ASTPrinter::visit(ElementaryTypeName const& _node)
{
- writeLine(string("ElementaryTypeName ") + Token::toString(_node.typeName()));
+ writeLine(string("ElementaryTypeName ") + _node.typeName().toString());
printSourcePart(_node);
return goDeeper();
}
@@ -331,7 +331,7 @@ bool ASTPrinter::visit(Identifier const& _node)
bool ASTPrinter::visit(ElementaryTypeNameExpression const& _node)
{
- writeLine(string("ElementaryTypeNameExpression ") + Token::toString(_node.typeToken()));
+ writeLine(string("ElementaryTypeNameExpression ") + _node.typeName().toString());
printType(_node);
printSourcePart(_node);
return goDeeper();
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index c889e6a0..df96d412 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -115,51 +115,55 @@ u256 const& MemberList::storageSize() const
return m_storageOffsets->storageSize();
}
-TypePointer Type::fromElementaryTypeName(Token::Value _typeToken)
+TypePointer Type::fromElementaryTypeName(ElementaryTypeNameToken const& _type)
{
- char const* tokenCstr = Token::toString(_typeToken);
- solAssert(Token::isElementaryTypeName(_typeToken),
- "Expected an elementary type name but got " + ((tokenCstr) ? string(Token::toString(_typeToken)) : ""));
+ string tokenString = _type.toString();
+ solAssert(Token::isElementaryTypeName(_type.returnTok()),
+ "Expected an elementary type name but got " + tokenString);
- if (Token::Int <= _typeToken && _typeToken <= Token::Bytes32)
+ Token::Value token = _type.returnTok();
+ unsigned int M = _type.returnM();
+
+ switch (token)
{
- int offset = _typeToken - Token::Int;
- int bytes = offset % 33;
- if (bytes == 0 && _typeToken != Token::Bytes1)
- bytes = 32;
- int modifier = offset / 33;
- switch(modifier)
- {
- case 0:
- return make_shared<IntegerType>(bytes * 8, IntegerType::Modifier::Signed);
- case 1:
- return make_shared<IntegerType>(bytes * 8, IntegerType::Modifier::Unsigned);
- case 2:
- return make_shared<FixedBytesType>(bytes + 1);
- default:
- solAssert(false, "Unexpected modifier value. Should never happen");
- return TypePointer();
- }
- }
- else if (_typeToken == Token::Byte)
+ case Token::IntM:
+ return make_shared<IntegerType>(M, IntegerType::Modifier::Signed);
+ case Token::UIntM:
+ return make_shared<IntegerType>(M, IntegerType::Modifier::Unsigned);
+ case Token::BytesM:
+ return make_shared<FixedBytesType>(M);
+ case Token::Int:
+ return make_shared<IntegerType>(256, IntegerType::Modifier::Signed);
+ case Token::UInt:
+ return make_shared<IntegerType>(256, IntegerType::Modifier::Unsigned);
+ case Token::Byte:
return make_shared<FixedBytesType>(1);
- else if (_typeToken == Token::Address)
+ case Token::Address:
return make_shared<IntegerType>(0, IntegerType::Modifier::Address);
- else if (_typeToken == Token::Bool)
+ case Token::Bool:
return make_shared<BoolType>();
- else if (_typeToken == Token::Bytes)
+ case Token::Bytes:
return make_shared<ArrayType>(DataLocation::Storage);
- else if (_typeToken == Token::String)
+ case Token::String:
return make_shared<ArrayType>(DataLocation::Storage, true);
- else
+ //no types found
+ default:
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment(
- "Unable to convert elementary typename " + string(Token::toString(_typeToken)) + " to type."
+ "Unable to convert elementary typename " + _type.toString() + " to type."
));
+ }
}
TypePointer Type::fromElementaryTypeName(string const& _name)
{
- return fromElementaryTypeName(Token::fromIdentifierOrKeyword(_name));
+ string keyword = _name.substr(0, _name.find_first_of("0123456789"));
+ string info = "";
+ if (_name.find_first_of("0123456789") != string::npos)
+ {
+ keyword += "M";
+ info = _name.substr(_name.find_first_of("0123456789"));
+ }
+ return fromElementaryTypeName(ElementaryTypeNameToken(Token::fromIdentifierOrKeyword(keyword), info));
}
TypePointer Type::forLiteral(Literal const& _literal)
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index 90a0509b..b4a2d573 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -140,7 +140,7 @@ public:
/// @{
/// @name Factory functions
/// Factory functions that convert an AST @ref TypeName to a Type.
- static TypePointer fromElementaryTypeName(Token::Value _typeToken);
+ static TypePointer fromElementaryTypeName(ElementaryTypeNameToken const& _type);
static TypePointer fromElementaryTypeName(std::string const& _name);
/// @}