aboutsummaryrefslogtreecommitdiffstats
path: root/Types.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-11-04 20:24:35 +0800
committerChristian <c@ethdev.com>2014-11-06 09:22:24 +0800
commitde493c673f2e850505d79185d104012825a7eabc (patch)
tree9496584d066c4454e85a795a053ea0037860785a /Types.cpp
parente30d3f8d539882376b29a1fe8f4bf6bcaf8c1762 (diff)
downloaddexon-solidity-de493c673f2e850505d79185d104012825a7eabc.tar.gz
dexon-solidity-de493c673f2e850505d79185d104012825a7eabc.tar.zst
dexon-solidity-de493c673f2e850505d79185d104012825a7eabc.zip
Detect integer length from literals and remove "std::".
Diffstat (limited to 'Types.cpp')
-rw-r--r--Types.cpp41
1 files changed, 23 insertions, 18 deletions
diff --git a/Types.cpp b/Types.cpp
index a4d70e3a..8a1db174 100644
--- a/Types.cpp
+++ b/Types.cpp
@@ -25,12 +25,14 @@
#include <libsolidity/Types.h>
#include <libsolidity/AST.h>
+using namespace std;
+
namespace dev
{
namespace solidity
{
-std::shared_ptr<Type> Type::fromElementaryTypeName(Token::Value _typeToken)
+shared_ptr<Type> Type::fromElementaryTypeName(Token::Value _typeToken)
{
if (asserts(Token::isElementaryTypeName(_typeToken)))
BOOST_THROW_EXCEPTION(InternalCompilerError());
@@ -44,52 +46,55 @@ std::shared_ptr<Type> Type::fromElementaryTypeName(Token::Value _typeToken)
else
bits = (1 << (bits - 1)) * 32;
int modifier = offset / 5;
- return std::make_shared<IntegerType>(bits,
+ return make_shared<IntegerType>(bits,
modifier == 0 ? IntegerType::Modifier::SIGNED :
modifier == 1 ? IntegerType::Modifier::UNSIGNED :
IntegerType::Modifier::HASH);
}
else if (_typeToken == Token::ADDRESS)
- return std::make_shared<IntegerType>(0, IntegerType::Modifier::ADDRESS);
+ return make_shared<IntegerType>(0, IntegerType::Modifier::ADDRESS);
else if (_typeToken == Token::BOOL)
- return std::make_shared<BoolType>();
+ return make_shared<BoolType>();
else
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unable to convert elementary typename " +
std::string(Token::toString(_typeToken)) + " to type."));
- return std::shared_ptr<Type>();
+ return shared_ptr<Type>();
}
-std::shared_ptr<Type> Type::fromUserDefinedTypeName(UserDefinedTypeName const& _typeName)
+shared_ptr<Type> Type::fromUserDefinedTypeName(UserDefinedTypeName const& _typeName)
{
- return std::make_shared<StructType>(*_typeName.getReferencedStruct());
+ return make_shared<StructType>(*_typeName.getReferencedStruct());
}
-std::shared_ptr<Type> Type::fromMapping(Mapping const&)
+shared_ptr<Type> Type::fromMapping(Mapping const&)
{
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Mapping types not yet implemented."));
- return std::shared_ptr<Type>();
+ return shared_ptr<Type>();
}
-std::shared_ptr<Type> Type::forLiteral(Literal const& _literal)
+shared_ptr<Type> Type::forLiteral(Literal const& _literal)
{
switch (_literal.getToken())
{
case Token::TRUE_LITERAL:
case Token::FALSE_LITERAL:
- return std::make_shared<BoolType>();
+ return make_shared<BoolType>();
case Token::NUMBER:
return IntegerType::smallestTypeForLiteral(_literal.getValue());
case Token::STRING_LITERAL:
- return std::shared_ptr<Type>(); // @todo
+ return shared_ptr<Type>(); // @todo
default:
- return std::shared_ptr<Type>();
+ return shared_ptr<Type>();
}
}
-std::shared_ptr<IntegerType> IntegerType::smallestTypeForLiteral(std::string const&)
+shared_ptr<IntegerType> IntegerType::smallestTypeForLiteral(string const& _literal)
{
- //@todo
- return std::make_shared<IntegerType>(256, Modifier::UNSIGNED);
+ bigint value(_literal);
+ unsigned bytes = max(bytesRequired(value), 1u);
+ if (bytes > 32)
+ return shared_ptr<IntegerType>();
+ return make_shared<IntegerType>(bytes * 8, Modifier::UNSIGNED);
}
IntegerType::IntegerType(int _bits, IntegerType::Modifier _modifier):
@@ -155,11 +160,11 @@ bool IntegerType::operator==(Type const& _other) const
return other.m_bits == m_bits && other.m_modifier == m_modifier;
}
-std::string IntegerType::toString() const
+string IntegerType::toString() const
{
if (isAddress())
return "address";
- std::string prefix = isHash() ? "hash" : (isSigned() ? "int" : "uint");
+ string prefix = isHash() ? "hash" : (isSigned() ? "int" : "uint");
return prefix + dev::toString(m_bits);
}