From bfc238c8d11e118443d373d819deeada9fe1ea3b Mon Sep 17 00:00:00 2001 From: VoR0220 Date: Tue, 12 Apr 2016 12:36:34 -0500 Subject: updated algorithm for bit finding...now to figure out literal value tiny fixups changed location of the check got rid of extra space and fixed a couple of things added binary results bits change back literal value --- libsolidity/analysis/ReferencesResolver.cpp | 6 ++---- libsolidity/analysis/TypeChecker.cpp | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) (limited to 'libsolidity/analysis') diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp index f4e0f838..9f83971b 100644 --- a/libsolidity/analysis/ReferencesResolver.cpp +++ b/libsolidity/analysis/ReferencesResolver.cpp @@ -104,10 +104,8 @@ void ReferencesResolver::endVisit(ArrayTypeName const& _typeName) if (!length->annotation().type) ConstantEvaluator e(*length); auto const* lengthType = dynamic_cast(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."); + if (!lengthType || lengthType->denominator() != 1) + fatalTypeError(length->location(), "Invalid array length, expected integer literal."); else _typeName.annotation().type = make_shared(DataLocation::Storage, baseType, lengthType->literalValue(nullptr)); } diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index fb0c665c..1b37d42e 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -774,9 +774,10 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement) solAssert(!var.typeName(), ""); if ( valueComponentType->category() == Type::Category::RationalNumber && - !dynamic_pointer_cast(valueComponentType)->integerType() + !dynamic_pointer_cast(valueComponentType)->integerType() && + !dynamic_pointer_cast(valueComponentType)->fixedPointType() ) - fatalTypeError(_statement.initialValue()->location(), "Invalid integer constant " + valueComponentType->toString() + "."); + fatalTypeError(_statement.initialValue()->location(), "Invalid rational " + valueComponentType->toString() + "."); var.annotation().type = valueComponentType->mobileType(); var.accept(*this); } @@ -800,8 +801,11 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement) void TypeChecker::endVisit(ExpressionStatement const& _statement) { if (type(_statement.expression())->category() == Type::Category::RationalNumber) - if (!dynamic_pointer_cast(type(_statement.expression()))->integerType()) - typeError(_statement.expression().location(), "Invalid integer constant."); + if ( + !dynamic_pointer_cast(type(_statement.expression()))->integerType() && + !dynamic_pointer_cast(type(_statement.expression()))->fixedPointType() + ) + typeError(_statement.expression().location(), "Invalid rational number."); } bool TypeChecker::visit(Conditional const& _conditional) @@ -1107,8 +1111,8 @@ bool TypeChecker::visit(FunctionCall const& _functionCall) if (functionType->takesArbitraryParameters()) { if (auto t = dynamic_cast(argType.get())) - if (!t->integerType()) - typeError(arguments[i]->location(), "Integer constant too large."); + if (!t->integerType() && !t->fixedPointType()) + typeError(arguments[i]->location(), "Rational number too large."); } else if (!type(*arguments[i])->isImplicitlyConvertibleTo(*parameterTypes[i])) typeError( @@ -1343,8 +1347,7 @@ bool TypeChecker::visit(IndexAccess const& _access) expectType(*index, IntegerType(256)); if (auto numberType = dynamic_cast(type(*index).get())) { - if (numberType->denominator() != 1) - typeError(_access.location(), "Invalid type for array access."); + solAssert(!numberType->denominator() != 1 ,"Invalid type for array access."); if (!actualType.isDynamicallySized() && actualType.length() <= numberType->literalValue(nullptr)) typeError(_access.location(), "Out of bounds array access."); } @@ -1371,7 +1374,7 @@ bool TypeChecker::visit(IndexAccess const& _access) resultType = make_shared(make_shared(DataLocation::Memory, typeType.actualType())); else { - index->accept(*this); + expectType(*index, IntegerType(256)); if (auto length = dynamic_cast(type(*index).get())) resultType = make_shared(make_shared( DataLocation::Memory, -- cgit