aboutsummaryrefslogtreecommitdiffstats
path: root/AST.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-10-20 18:41:56 +0800
committerChristian <c@ethdev.com>2014-10-25 01:38:13 +0800
commit59b5e950f42781c083d14a210845148b01e39eb2 (patch)
treed695de0d746da87c773b10800a2698faa4a6087a /AST.cpp
parentc6e0f82d2ebcbb77a24a287767d81674f78c62d7 (diff)
downloaddexon-solidity-59b5e950f42781c083d14a210845148b01e39eb2.tar.gz
dexon-solidity-59b5e950f42781c083d14a210845148b01e39eb2.tar.zst
dexon-solidity-59b5e950f42781c083d14a210845148b01e39eb2.zip
Expression compiler.
Diffstat (limited to 'AST.cpp')
-rw-r--r--AST.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/AST.cpp b/AST.cpp
index 91b4a42b..414de9b2 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -328,7 +328,7 @@ void Assignment::checkTypeRequirements()
m_type = m_leftHandSide->getType();
if (m_assigmentOperator != Token::ASSIGN)
{
- // complex assignment
+ // compound assignment
if (!m_type->acceptsBinaryOperator(Token::AssignmentToBinaryOp(m_assigmentOperator)))
BOOST_THROW_EXCEPTION(createTypeError("Operator not compatible with type."));
}
@@ -339,7 +339,7 @@ void UnaryOperation::checkTypeRequirements()
// INC, DEC, NOT, BIT_NOT, DELETE
m_subExpression->checkTypeRequirements();
m_type = m_subExpression->getType();
- if (m_type->acceptsUnaryOperator(m_operator))
+ if (!m_type->acceptsUnaryOperator(m_operator))
BOOST_THROW_EXCEPTION(createTypeError("Unary operator not compatible with type."));
}
@@ -369,11 +369,11 @@ void FunctionCall::checkTypeRequirements()
m_expression->checkTypeRequirements();
for (ASTPointer<Expression> const& argument: m_arguments)
argument->checkTypeRequirements();
- Type const& expressionType = *m_expression->getType();
- Type::Category const category = expressionType.getCategory();
- if (category == Type::Category::TYPE)
+
+ Type const* expressionType = m_expression->getType().get();
+ if (isTypeConversion())
{
- TypeType const* type = dynamic_cast<TypeType const*>(&expressionType);
+ TypeType const* type = dynamic_cast<TypeType const*>(expressionType);
BOOST_ASSERT(type);
//@todo for structs, we have to check the number of arguments to be equal to the
// number of non-mapping members
@@ -384,12 +384,12 @@ void FunctionCall::checkTypeRequirements()
BOOST_THROW_EXCEPTION(createTypeError("Explicit type conversion not allowed."));
m_type = type->getActualType();
}
- else if (category == Type::Category::FUNCTION)
+ else
{
//@todo would be nice to create a struct type from the arguments
// and then ask if that is implicitly convertible to the struct represented by the
// function parameters
- FunctionType const* function = dynamic_cast<FunctionType const*>(&expressionType);
+ FunctionType const* function = dynamic_cast<FunctionType const*>(expressionType);
BOOST_ASSERT(function);
FunctionDefinition const& fun = function->getFunction();
std::vector<ASTPointer<VariableDeclaration>> const& parameters = fun.getParameters();
@@ -405,8 +405,11 @@ void FunctionCall::checkTypeRequirements()
else
m_type = fun.getReturnParameterList()->getParameters().front()->getType();
}
- else
- BOOST_THROW_EXCEPTION(createTypeError("Type does not support invocation."));
+}
+
+bool FunctionCall::isTypeConversion() const
+{
+ return m_expression->getType()->getCategory() == Type::Category::TYPE;
}
void MemberAccess::checkTypeRequirements()