changed the test so constructor will have input parameters

This commit is contained in:
Liana Husikyan 2015-04-22 18:53:58 +02:00
parent 648ce85256
commit 88536f90e8
4 changed files with 83 additions and 31 deletions

View File

@ -817,8 +817,11 @@ void NewExpression::checkTypeRequirements(TypePointers const*)
BOOST_THROW_EXCEPTION(createTypeError("Trying to create an instance of an abstract contract.")); BOOST_THROW_EXCEPTION(createTypeError("Trying to create an instance of an abstract contract."));
shared_ptr<ContractType const> contractType = make_shared<ContractType>(*m_contract); shared_ptr<ContractType const> contractType = make_shared<ContractType>(*m_contract);
TypePointers const& parameterTypes = contractType->getConstructorType()->getParameterTypes(); TypePointers const& parameterTypes = contractType->getConstructorType()->getParameterTypes();
m_type = make_shared<FunctionType>(parameterTypes, TypePointers{contractType}, m_type = make_shared<FunctionType>(
FunctionType::Location::Creation); parameterTypes,
TypePointers{contractType},
strings(),
FunctionType::Location::Creation);
} }
void MemberAccess::checkTypeRequirements(TypePointers const* _argumentTypes) void MemberAccess::checkTypeRequirements(TypePointers const* _argumentTypes)

View File

@ -521,8 +521,19 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
arguments.front()->accept(*this); arguments.front()->accept(*this);
appendTypeConversion(*arguments.front()->getType(), appendTypeConversion(*arguments.front()->getType(),
*function.getParameterTypes().front(), true); *function.getParameterTypes().front(), true);
appendExternalFunctionCall(FunctionType(TypePointers{}, TypePointers{}, appendExternalFunctionCall(
Location::External, false, true, true), {}, true); FunctionType(
TypePointers{},
TypePointers{},
strings(),
Location::External,
false,
true,
true
),
{},
true
);
break; break;
case Location::Suicide: case Location::Suicide:
arguments.front()->accept(*this); arguments.front()->accept(*this);

View File

@ -1143,7 +1143,7 @@ FunctionTypePointer FunctionType::externalFunctionType() const
return FunctionTypePointer(); return FunctionTypePointer();
retParamTypes.push_back(type->externalType()); retParamTypes.push_back(type->externalType());
} }
return make_shared<FunctionType>(paramTypes, retParamTypes, m_location, m_arbitraryParameters); return make_shared<FunctionType>(paramTypes, retParamTypes, m_parameterNames, m_location, m_arbitraryParameters);
} }
MemberList const& FunctionType::getMembers() const MemberList const& FunctionType::getMembers() const
@ -1159,14 +1159,34 @@ MemberList const& FunctionType::getMembers() const
if (!m_members) if (!m_members)
{ {
MemberList::MemberMap members{ MemberList::MemberMap members{
{"value", make_shared<FunctionType>(parseElementaryTypeVector({"uint"}), {
TypePointers{copyAndSetGasOrValue(false, true)}, "value",
Location::SetValue, false, m_gasSet, m_valueSet)}}; make_shared<FunctionType>(
parseElementaryTypeVector({"uint"}),
TypePointers{copyAndSetGasOrValue(false, true)},
strings(),
Location::SetValue,
false,
m_gasSet,
m_valueSet
)
}
};
if (m_location != Location::Creation) if (m_location != Location::Creation)
members.push_back(MemberList::Member("gas", make_shared<FunctionType>( members.push_back(
parseElementaryTypeVector({"uint"}), MemberList::Member(
TypePointers{copyAndSetGasOrValue(true, false)}, "gas",
Location::SetGas, false, m_gasSet, m_valueSet))); make_shared<FunctionType>(
parseElementaryTypeVector({"uint"}),
TypePointers{copyAndSetGasOrValue(true, false)},
strings(),
Location::SetGas,
false,
m_gasSet,
m_valueSet
)
)
);
m_members.reset(new MemberList(members)); m_members.reset(new MemberList(members));
} }
return *m_members; return *m_members;
@ -1244,9 +1264,15 @@ TypePointers FunctionType::parseElementaryTypeVector(strings const& _types)
TypePointer FunctionType::copyAndSetGasOrValue(bool _setGas, bool _setValue) const TypePointer FunctionType::copyAndSetGasOrValue(bool _setGas, bool _setValue) const
{ {
return make_shared<FunctionType>(m_parameterTypes, m_returnParameterTypes, m_location, return make_shared<FunctionType>(
m_arbitraryParameters, m_parameterTypes,
m_gasSet || _setGas, m_valueSet || _setValue); m_returnParameterTypes,
strings(),
m_location,
m_arbitraryParameters,
m_gasSet || _setGas,
m_valueSet || _setValue
);
} }
vector<string> const FunctionType::getParameterTypeNames() const vector<string> const FunctionType::getParameterTypeNames() const

44
Types.h
View File

@ -564,24 +564,36 @@ public:
explicit FunctionType(FunctionDefinition const& _function, bool _isInternal = true); explicit FunctionType(FunctionDefinition const& _function, bool _isInternal = true);
explicit FunctionType(VariableDeclaration const& _varDecl); explicit FunctionType(VariableDeclaration const& _varDecl);
explicit FunctionType(EventDefinition const& _event); explicit FunctionType(EventDefinition const& _event);
FunctionType(strings const& _parameterTypes, strings const& _returnParameterTypes,
Location _location = Location::Internal, bool _arbitraryParameters = false):
FunctionType(parseElementaryTypeVector(_parameterTypes), parseElementaryTypeVector(_returnParameterTypes),
_location, _arbitraryParameters) {}
FunctionType( FunctionType(
TypePointers const& _parameterTypes, strings const& _parameterTypes,
TypePointers const& _returnParameterTypes, strings const& _returnParameterTypes,
Location _location = Location::Internal, Location _location = Location::Internal,
bool _arbitraryParameters = false, bool _arbitraryParameters = false
bool _gasSet = false, ): FunctionType(
bool _valueSet = false parseElementaryTypeVector(_parameterTypes),
parseElementaryTypeVector(_returnParameterTypes),
strings(),
_location,
_arbitraryParameters
)
{
}
FunctionType(
TypePointers const& _parameterTypes,
TypePointers const& _returnParameterTypes,
strings _parameterNames = strings(),
Location _location = Location::Internal,
bool _arbitraryParameters = false,
bool _gasSet = false,
bool _valueSet = false
): ):
m_parameterTypes (_parameterTypes), m_parameterTypes (_parameterTypes),
m_returnParameterTypes (_returnParameterTypes), m_returnParameterTypes (_returnParameterTypes),
m_location (_location), m_parameterNames (_parameterNames),
m_arbitraryParameters (_arbitraryParameters), m_location (_location),
m_gasSet (_gasSet), m_arbitraryParameters (_arbitraryParameters),
m_valueSet (_valueSet) m_gasSet (_gasSet),
m_valueSet (_valueSet)
{} {}
TypePointers const& getParameterTypes() const { return m_parameterTypes; } TypePointers const& getParameterTypes() const { return m_parameterTypes; }