aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/analysis
diff options
context:
space:
mode:
authorRJ Catalano <rcatalano@macsales.com>2016-02-19 06:39:11 +0800
committerVoR0220 <catalanor0220@gmail.com>2016-05-10 00:41:02 +0800
commit9a075458ad104921c9d747cd34d3e5c299638406 (patch)
treec2005fb8b8032c54c7ab65196e952d01ab747327 /libsolidity/analysis
parent9e36bdda8a9552f1885e0a63a85db588623b39b2 (diff)
downloaddexon-solidity-9a075458ad104921c9d747cd34d3e5c299638406.tar.gz
dexon-solidity-9a075458ad104921c9d747cd34d3e5c299638406.tar.zst
dexon-solidity-9a075458ad104921c9d747cd34d3e5c299638406.zip
initial work for fixed types...potentially needing a constant literal type for this
notation Rational implemented...trying to figure out exponential fix for token bug, also quick fix for the wei and seconds fixed problem with var...probably a conversion problem for fixed in size capabilities adding fixed type tests Removing bitshift and regrouping fixed type tests together size capabilities functioning properly for fixed types got exponents up and working with their inverse, changed a few of the tests....something is working that likely shouldn't be slight changes to how to flip the rational negative around...still trying to figure it out tests added updated tests odd differences in trying soltest from solc binary, let me know if you can replicate test not working for odd reason fixed test problem with fixed literals...still need a way to log this error broken up the tests, added some, changed some things in types and began compiler work moar tests and prepping for rebuilding much of the types.cpp file further fixing initial work for fixed types...potentially needing a constant literal type for this
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r--libsolidity/analysis/ConstantEvaluator.cpp6
-rw-r--r--libsolidity/analysis/ReferencesResolver.cpp5
-rw-r--r--libsolidity/analysis/TypeChecker.cpp22
3 files changed, 19 insertions, 14 deletions
diff --git a/libsolidity/analysis/ConstantEvaluator.cpp b/libsolidity/analysis/ConstantEvaluator.cpp
index 6beb655e..a86e3967 100644
--- a/libsolidity/analysis/ConstantEvaluator.cpp
+++ b/libsolidity/analysis/ConstantEvaluator.cpp
@@ -31,7 +31,7 @@ using namespace dev::solidity;
void ConstantEvaluator::endVisit(UnaryOperation const& _operation)
{
TypePointer const& subType = _operation.subExpression().annotation().type;
- if (!dynamic_cast<IntegerConstantType const*>(subType.get()))
+ if (!dynamic_cast<ConstantNumberType const*>(subType.get()))
BOOST_THROW_EXCEPTION(_operation.subExpression().createTypeError("Invalid constant expression."));
TypePointer t = subType->unaryOperatorResult(_operation.getOperator());
_operation.annotation().type = t;
@@ -41,9 +41,9 @@ void ConstantEvaluator::endVisit(BinaryOperation const& _operation)
{
TypePointer const& leftType = _operation.leftExpression().annotation().type;
TypePointer const& rightType = _operation.rightExpression().annotation().type;
- if (!dynamic_cast<IntegerConstantType const*>(leftType.get()))
+ if (!dynamic_cast<ConstantNumberType const*>(leftType.get()))
BOOST_THROW_EXCEPTION(_operation.leftExpression().createTypeError("Invalid constant expression."));
- if (!dynamic_cast<IntegerConstantType const*>(rightType.get()))
+ if (!dynamic_cast<ConstantNumberType const*>(rightType.get()))
BOOST_THROW_EXCEPTION(_operation.rightExpression().createTypeError("Invalid constant expression."));
TypePointer commonType = leftType->binaryOperatorResult(_operation.getOperator(), rightType);
if (Token::isCompareOp(_operation.getOperator()))
diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp
index d7542bf3..3351c716 100644
--- a/libsolidity/analysis/ReferencesResolver.cpp
+++ b/libsolidity/analysis/ReferencesResolver.cpp
@@ -103,10 +103,11 @@ void ReferencesResolver::endVisit(ArrayTypeName const& _typeName)
{
if (!length->annotation().type)
ConstantEvaluator e(*length);
-
- auto const* lengthType = dynamic_cast<IntegerConstantType const*>(length->annotation().type.get());
+ auto const* lengthType = dynamic_cast<ConstantNumberType const*>(length->annotation().type.get());
if (!lengthType)
fatalTypeError(length->location(), "Invalid array length.");
+ else if (lengthType->denominator() != 1)
+ fatalTypeError(length->location(), "Invalid input for array length, expected integer.");
else
_typeName.annotation().type = make_shared<ArrayType>(DataLocation::Storage, baseType, lengthType->literalValue(nullptr));
}
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index bc342b58..ad93b38c 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -773,8 +773,8 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
// Infer type from value.
solAssert(!var.typeName(), "");
if (
- valueComponentType->category() == Type::Category::IntegerConstant &&
- !dynamic_pointer_cast<IntegerConstantType const>(valueComponentType)->integerType()
+ valueComponentType->category() == Type::Category::NumberConstant &&
+ !dynamic_pointer_cast<ConstantNumberType const>(valueComponentType)->integerType()
)
fatalTypeError(_statement.initialValue()->location(), "Invalid integer constant " + valueComponentType->toString() + ".");
var.annotation().type = valueComponentType->mobileType();
@@ -799,8 +799,8 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement)
void TypeChecker::endVisit(ExpressionStatement const& _statement)
{
- if (type(_statement.expression())->category() == Type::Category::IntegerConstant)
- if (!dynamic_pointer_cast<IntegerConstantType const>(type(_statement.expression()))->integerType())
+ if (type(_statement.expression())->category() == Type::Category::NumberConstant)
+ if (!dynamic_pointer_cast<ConstantNumberType const>(type(_statement.expression()))->integerType())
typeError(_statement.expression().location(), "Invalid integer constant.");
}
@@ -1106,7 +1106,7 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
auto const& argType = type(*arguments[i]);
if (functionType->takesArbitraryParameters())
{
- if (auto t = dynamic_cast<IntegerConstantType const*>(argType.get()))
+ if (auto t = dynamic_cast<ConstantNumberType const*>(argType.get()))
if (!t->integerType())
typeError(arguments[i]->location(), "Integer constant too large.");
}
@@ -1341,9 +1341,13 @@ bool TypeChecker::visit(IndexAccess const& _access)
else
{
expectType(*index, IntegerType(256));
- if (auto integerType = dynamic_cast<IntegerConstantType const*>(type(*index).get()))
- if (!actualType.isDynamicallySized() && actualType.length() <= integerType->literalValue(nullptr))
+ if (auto numberType = dynamic_cast<ConstantNumberType const*>(type(*index).get()))
+ {
+ if (numberType->denominator() != 1)
+ typeError(_access.location(), "Invalid type for array access.");
+ if (!actualType.isDynamicallySized() && actualType.length() <= numberType->literalValue(nullptr))
typeError(_access.location(), "Out of bounds array access.");
+ }
}
resultType = actualType.baseType();
isLValue = actualType.location() != DataLocation::CallData;
@@ -1368,7 +1372,7 @@ bool TypeChecker::visit(IndexAccess const& _access)
else
{
index->accept(*this);
- if (auto length = dynamic_cast<IntegerConstantType const*>(type(*index).get()))
+ if (auto length = dynamic_cast<ConstantNumberType const*>(type(*index).get()))
resultType = make_shared<TypeType>(make_shared<ArrayType>(
DataLocation::Memory,
typeType.actualType(),
@@ -1387,7 +1391,7 @@ bool TypeChecker::visit(IndexAccess const& _access)
else
{
expectType(*index, IntegerType(256));
- if (auto integerType = dynamic_cast<IntegerConstantType const*>(type(*index).get()))
+ if (auto integerType = dynamic_cast<ConstantNumberType const*>(type(*index).get()))
if (bytesType.numBytes() <= integerType->literalValue(nullptr))
typeError(_access.location(), "Out of bounds array access.");
}