mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
- changed implementation
- style fixes Conflicts: libsolidity/AST.cpp
This commit is contained in:
parent
7dbff2489f
commit
e4eb40036b
@ -58,11 +58,11 @@ void ContractDefinition::checkTypeRequirements()
|
|||||||
checkAbstractFunctions();
|
checkAbstractFunctions();
|
||||||
checkAbstractConstructors();
|
checkAbstractConstructors();
|
||||||
|
|
||||||
FunctionDefinition const* function = constructor();
|
FunctionDefinition const* functionDefinition = constructor();
|
||||||
if (function && !function->returnParameters().empty())
|
if (functionDefinition && !functionDefinition->getReturnParameters().empty())
|
||||||
BOOST_THROW_EXCEPTION(
|
BOOST_THROW_EXCEPTION(functionDefinition->getReturnParameterList()->createTypeError(
|
||||||
function->returnParameterList()->createTypeError("Non-empty \"returns\" directive for constructor.")
|
"Non-empty \"returns\" directive for constructor."
|
||||||
);
|
));
|
||||||
|
|
||||||
FunctionDefinition const* fallbackFunction = nullptr;
|
FunctionDefinition const* fallbackFunction = nullptr;
|
||||||
for (ASTPointer<FunctionDefinition> const& function: definedFunctions())
|
for (ASTPointer<FunctionDefinition> const& function: definedFunctions())
|
||||||
@ -119,8 +119,7 @@ map<FixedHash<4>, FunctionTypePointer> ContractDefinition::interfaceFunctions()
|
|||||||
for (auto const& it: exportedFunctionList)
|
for (auto const& it: exportedFunctionList)
|
||||||
exportedFunctions.insert(it);
|
exportedFunctions.insert(it);
|
||||||
|
|
||||||
solAssert(
|
solAssert(exportedFunctionList.size() == exportedFunctions.size(),
|
||||||
exportedFunctionList.size() == exportedFunctions.size(),
|
|
||||||
"Hash collision at Function Definition Hash calculation"
|
"Hash collision at Function Definition Hash calculation"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -178,7 +177,9 @@ void ContractDefinition::checkDuplicateFunctions() const
|
|||||||
errinfo_sourceLocation(overloads[j]->location()) <<
|
errinfo_sourceLocation(overloads[j]->location()) <<
|
||||||
errinfo_comment("Function with same name and arguments defined twice.") <<
|
errinfo_comment("Function with same name and arguments defined twice.") <<
|
||||||
errinfo_secondarySourceLocation(SecondarySourceLocation().append(
|
errinfo_secondarySourceLocation(SecondarySourceLocation().append(
|
||||||
"Other declaration is here:", overloads[i]->location()))
|
"Other declaration is here:", overloads[i]->location())
|
||||||
|
)
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -767,8 +768,10 @@ void Return::checkTypeRequirements()
|
|||||||
if (!m_returnParameters)
|
if (!m_returnParameters)
|
||||||
BOOST_THROW_EXCEPTION(createTypeError("Return arguments not allowed."));
|
BOOST_THROW_EXCEPTION(createTypeError("Return arguments not allowed."));
|
||||||
if (m_returnParameters->parameters().size() != 1)
|
if (m_returnParameters->parameters().size() != 1)
|
||||||
BOOST_THROW_EXCEPTION(createTypeError("Different number of arguments in return statement "
|
BOOST_THROW_EXCEPTION(createTypeError(
|
||||||
"than in returns declaration."));
|
"Different number of arguments in return statement "
|
||||||
|
"than in returns declaration."
|
||||||
|
));
|
||||||
// this could later be changed such that the paramaters type is an anonymous struct type,
|
// this could later be changed such that the paramaters type is an anonymous struct type,
|
||||||
// but for now, we only allow one return parameter
|
// but for now, we only allow one return parameter
|
||||||
m_expression->expectType(*m_returnParameters->parameters().front()->type());
|
m_expression->expectType(*m_returnParameters->parameters().front()->type());
|
||||||
@ -795,10 +798,14 @@ void Assignment::checkTypeRequirements(TypePointers const*)
|
|||||||
TypePointer resultType = m_type->binaryOperatorResult(Token::AssignmentToBinaryOp(m_assigmentOperator),
|
TypePointer resultType = m_type->binaryOperatorResult(Token::AssignmentToBinaryOp(m_assigmentOperator),
|
||||||
m_rightHandSide->type());
|
m_rightHandSide->type());
|
||||||
if (!resultType || *resultType != *m_type)
|
if (!resultType || *resultType != *m_type)
|
||||||
BOOST_THROW_EXCEPTION(createTypeError("Operator " + string(Token::toString(m_assigmentOperator)) +
|
BOOST_THROW_EXCEPTION(createTypeError(
|
||||||
" not compatible with types " +
|
"Operator " +
|
||||||
m_type->toString() + " and " +
|
string(Token::toString(m_assigmentOperator)) +
|
||||||
m_rightHandSide->type()->toString()));
|
" not compatible with types " +
|
||||||
|
m_type->toString() +
|
||||||
|
" and " +
|
||||||
|
m_rightHandSide->type()->toString()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -850,16 +857,13 @@ void BinaryOperation::checkTypeRequirements(TypePointers const*)
|
|||||||
m_right->checkTypeRequirements(nullptr);
|
m_right->checkTypeRequirements(nullptr);
|
||||||
m_commonType = m_left->type()->binaryOperatorResult(m_operator, m_right->type());
|
m_commonType = m_left->type()->binaryOperatorResult(m_operator, m_right->type());
|
||||||
if (!m_commonType)
|
if (!m_commonType)
|
||||||
BOOST_THROW_EXCEPTION(
|
BOOST_THROW_EXCEPTION(createTypeError(
|
||||||
createTypeError(
|
"Operator " + string(Token::toString(m_operator)) +
|
||||||
"Operator " +
|
" not compatible with types " +
|
||||||
string(Token::toString(m_operator)) +
|
m_left->type()->toString() +
|
||||||
" not compatible with types " +
|
" and " +
|
||||||
m_left->type()->toString() +
|
m_right->type()->toString()
|
||||||
" and " +
|
));
|
||||||
m_right->type()->toString()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
m_type = Token::isCompareOp(m_operator) ? make_shared<BoolType>() : m_commonType;
|
m_type = Token::isCompareOp(m_operator) ? make_shared<BoolType>() : m_commonType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1040,7 +1044,8 @@ void NewExpression::checkTypeRequirements(TypePointers const*)
|
|||||||
TypePointers{contractType},
|
TypePointers{contractType},
|
||||||
strings(),
|
strings(),
|
||||||
strings(),
|
strings(),
|
||||||
FunctionType::Location::Creation);
|
FunctionType::Location::Creation
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemberAccess::checkTypeRequirements(TypePointers const* _argumentTypes)
|
void MemberAccess::checkTypeRequirements(TypePointers const* _argumentTypes)
|
||||||
@ -1069,19 +1074,25 @@ void MemberAccess::checkTypeRequirements(TypePointers const* _argumentTypes)
|
|||||||
);
|
);
|
||||||
if (!storageType->members().membersByName(*m_memberName).empty())
|
if (!storageType->members().membersByName(*m_memberName).empty())
|
||||||
BOOST_THROW_EXCEPTION(createTypeError(
|
BOOST_THROW_EXCEPTION(createTypeError(
|
||||||
"Member \"" + *m_memberName + "\" is not available in " +
|
"Member \"" +
|
||||||
|
*m_memberName +
|
||||||
|
"\" is not available in " +
|
||||||
type.toString() +
|
type.toString() +
|
||||||
" outside of storage."
|
" outside of storage."
|
||||||
));
|
));
|
||||||
BOOST_THROW_EXCEPTION(createTypeError(
|
BOOST_THROW_EXCEPTION(createTypeError(
|
||||||
"Member \"" + *m_memberName + "\" not found or not visible "
|
"Member \"" +
|
||||||
"after argument-dependent lookup in " + type.toString()
|
*m_memberName +
|
||||||
|
"\" not found or not visible after argument-dependent lookup in " +
|
||||||
|
type.toString()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
else if (possibleMembers.size() > 1)
|
else if (possibleMembers.size() > 1)
|
||||||
BOOST_THROW_EXCEPTION(createTypeError(
|
BOOST_THROW_EXCEPTION(createTypeError(
|
||||||
"Member \"" + *m_memberName + "\" not unique "
|
"Member \"" +
|
||||||
"after argument-dependent lookup in " + type.toString()
|
*m_memberName +
|
||||||
|
"\" not unique after argument-dependent lookup in " +
|
||||||
|
type.toString()
|
||||||
));
|
));
|
||||||
|
|
||||||
m_referencedDeclaration = possibleMembers.front().declaration;
|
m_referencedDeclaration = possibleMembers.front().declaration;
|
||||||
@ -1114,10 +1125,12 @@ void IndexAccess::checkTypeRequirements(TypePointers const*)
|
|||||||
if (type.isString())
|
if (type.isString())
|
||||||
BOOST_THROW_EXCEPTION(createTypeError("Index access for string is not possible."));
|
BOOST_THROW_EXCEPTION(createTypeError("Index access for string is not possible."));
|
||||||
m_index->expectType(IntegerType(256));
|
m_index->expectType(IntegerType(256));
|
||||||
if (type.isByteArray())
|
|
||||||
m_type = make_shared<FixedBytesType>(1);
|
m_type = type.baseType();
|
||||||
else
|
if(IntegerConstantType const* integerType = dynamic_cast<IntegerConstantType const*>(m_index->type().get()))
|
||||||
m_type = type.baseType();
|
if (!type.isDynamicallySized() && type.length() <= integerType->literalValue(nullptr))
|
||||||
|
BOOST_THROW_EXCEPTION(createTypeError("Out of bounds access."));
|
||||||
|
|
||||||
m_isLValue = type.location() != DataLocation::CallData;
|
m_isLValue = type.location() != DataLocation::CallData;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1143,7 +1156,8 @@ void IndexAccess::checkTypeRequirements(TypePointers const*)
|
|||||||
if (!length)
|
if (!length)
|
||||||
BOOST_THROW_EXCEPTION(m_index->createTypeError("Integer constant expected."));
|
BOOST_THROW_EXCEPTION(m_index->createTypeError("Integer constant expected."));
|
||||||
m_type = make_shared<TypeType>(make_shared<ArrayType>(
|
m_type = make_shared<TypeType>(make_shared<ArrayType>(
|
||||||
DataLocation::Memory, type.actualType(),
|
DataLocation::Memory,
|
||||||
|
type.actualType(),
|
||||||
length->literalValue(nullptr)
|
length->literalValue(nullptr)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -1151,7 +1165,10 @@ void IndexAccess::checkTypeRequirements(TypePointers const*)
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
BOOST_THROW_EXCEPTION(m_base->createTypeError(
|
BOOST_THROW_EXCEPTION(m_base->createTypeError(
|
||||||
"Indexed expression has to be a type, mapping or array (is " + m_base->type()->toString() + ")"));
|
"Indexed expression has to be a type, mapping or array (is " +
|
||||||
|
m_base->type()->toString() +
|
||||||
|
")"
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user