Browse Source

renamed externalTypes to externalSignature

cl-refactor
Liana Husikyan 10 years ago
parent
commit
ba8d0f615c
  1. 12
      libsolidity/AST.cpp
  2. 6
      libsolidity/AST.h
  3. 2
      libsolidity/ExpressionCompiler.cpp
  4. 4
      libsolidity/InterfaceHandler.cpp
  5. 2
      libsolidity/Types.cpp
  6. 4
      libsolidity/Types.h
  7. 2
      mix/QFunctionDefinition.cpp
  8. 27
      test/SolidityNameAndTypeResolution.cpp
  9. 1
      test/SolidityTypes.cpp

12
libsolidity/AST.cpp

@ -88,7 +88,7 @@ void ContractDefinition::checkTypeRequirements()
if (hashes.count(hash)) if (hashes.count(hash))
BOOST_THROW_EXCEPTION(createTypeError( BOOST_THROW_EXCEPTION(createTypeError(
std::string("Function signature hash collision for ") + std::string("Function signature hash collision for ") +
it.second->externalTypes())); it.second->externalSignature()));
hashes.insert(hash); hashes.insert(hash);
} }
} }
@ -192,7 +192,7 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::getIn
if (functionsSeen.count(f->getName()) == 0 && f->isPartOfExternalInterface()) if (functionsSeen.count(f->getName()) == 0 && f->isPartOfExternalInterface())
{ {
functionsSeen.insert(f->getName()); functionsSeen.insert(f->getName());
FixedHash<4> hash(dev::sha3(f->externalTypes())); FixedHash<4> hash(dev::sha3(f->externalSignature()));
m_interfaceFunctionList->push_back(make_pair(hash, make_shared<FunctionType>(*f, false))); m_interfaceFunctionList->push_back(make_pair(hash, make_shared<FunctionType>(*f, false)));
} }
@ -202,7 +202,7 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::getIn
FunctionType ftype(*v); FunctionType ftype(*v);
solAssert(v->getType().get(), ""); solAssert(v->getType().get(), "");
functionsSeen.insert(v->getName()); functionsSeen.insert(v->getName());
FixedHash<4> hash(dev::sha3(ftype.externalTypes(v->getName()))); FixedHash<4> hash(dev::sha3(ftype.externalSignature(v->getName())));
m_interfaceFunctionList->push_back(make_pair(hash, make_shared<FunctionType>(*v))); m_interfaceFunctionList->push_back(make_pair(hash, make_shared<FunctionType>(*v)));
} }
} }
@ -320,9 +320,9 @@ void FunctionDefinition::checkTypeRequirements()
m_body->checkTypeRequirements(); m_body->checkTypeRequirements();
} }
string FunctionDefinition::externalTypes() const string FunctionDefinition::externalSignature() const
{ {
return FunctionType(*this).externalTypes(getName()); return FunctionType(*this).externalSignature(getName());
} }
bool VariableDeclaration::isLValue() const bool VariableDeclaration::isLValue() const
@ -430,7 +430,7 @@ void EventDefinition::checkTypeRequirements()
numIndexed++; numIndexed++;
if (!var->getType()->canLiveOutsideStorage()) if (!var->getType()->canLiveOutsideStorage())
BOOST_THROW_EXCEPTION(var->createTypeError("Type is required to live outside storage.")); BOOST_THROW_EXCEPTION(var->createTypeError("Type is required to live outside storage."));
if (!var->getType()->externalType() && getVisibility() >= Visibility::Public) if (!var->getType()->externalType())
BOOST_THROW_EXCEPTION(var->createTypeError("Internal type is not allowed for Events")); BOOST_THROW_EXCEPTION(var->createTypeError("Internal type is not allowed for Events"));
} }
if (numIndexed > 3) if (numIndexed > 3)

6
libsolidity/AST.h

@ -421,10 +421,10 @@ public:
/// Checks that all parameters have allowed types and calls checkTypeRequirements on the body. /// Checks that all parameters have allowed types and calls checkTypeRequirements on the body.
void checkTypeRequirements(); void checkTypeRequirements();
/// @returns the canonical signature of the function /// @returns the external signature of the function
/// That consists of the name of the function followed by the types of the /// That consists of the name of the function followed by the external types of the
/// arguments separated by commas all enclosed in parentheses without any spaces. /// arguments separated by commas all enclosed in parentheses without any spaces.
std::string externalTypes() const; std::string externalSignature() const;
private: private:
bool m_isConstructor; bool m_isConstructor;

2
libsolidity/ExpressionCompiler.cpp

@ -544,7 +544,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
} }
if (!event.isAnonymous()) if (!event.isAnonymous())
{ {
m_context << u256(h256::Arith(dev::sha3(function.externalTypes(event.getName())))); m_context << u256(h256::Arith(dev::sha3(function.externalSignature(event.getName()))));
++numIndexed; ++numIndexed;
} }
solAssert(numIndexed <= 4, "Too many indexed arguments."); solAssert(numIndexed <= 4, "Too many indexed arguments.");

4
libsolidity/InterfaceHandler.cpp

@ -129,7 +129,7 @@ std::unique_ptr<std::string> InterfaceHandler::getUserDocumentation(ContractDefi
if (!m_notice.empty()) if (!m_notice.empty())
{// since @notice is the only user tag if missing function should not appear {// since @notice is the only user tag if missing function should not appear
user["notice"] = Json::Value(m_notice); user["notice"] = Json::Value(m_notice);
methods[it.second->externalTypes()] = user; methods[it.second->externalSignature()] = user;
} }
} }
} }
@ -185,7 +185,7 @@ std::unique_ptr<std::string> InterfaceHandler::getDevDocumentation(ContractDefin
method["return"] = m_return; method["return"] = m_return;
if (!method.empty()) // add the function, only if we have any documentation to add if (!method.empty()) // add the function, only if we have any documentation to add
methods[it.second->externalTypes()] = method; methods[it.second->externalSignature()] = method;
} }
} }
doc["methods"] = methods; doc["methods"] = methods;

2
libsolidity/Types.cpp

@ -1127,7 +1127,7 @@ MemberList const& FunctionType::getMembers() const
} }
} }
string FunctionType::externalTypes(std::string const& _name) const string FunctionType::externalSignature(std::string const& _name) const
{ {
std::string funcName = _name; std::string funcName = _name;
if (_name == "") if (_name == "")

4
libsolidity/Types.h

@ -550,10 +550,10 @@ public:
virtual MemberList const& getMembers() const override; virtual MemberList const& getMembers() const override;
Location const& getLocation() const { return m_location; } Location const& getLocation() const { return m_location; }
/// @returns the external type of this function type given the function name /// @returns the external signature of this function type given the function name
/// If @a _name is not provided (empty string) then the @c m_declaration member of the /// If @a _name is not provided (empty string) then the @c m_declaration member of the
/// function type is used /// function type is used
std::string externalTypes(std::string const& _name = "") const; std::string externalSignature(std::string const& _name = "") const;
Declaration const& getDeclaration() const Declaration const& getDeclaration() const
{ {
solAssert(m_declaration, "Requested declaration from a FunctionType that has none"); solAssert(m_declaration, "Requested declaration from a FunctionType that has none");

2
mix/QFunctionDefinition.cpp

@ -28,7 +28,7 @@
using namespace dev::solidity; using namespace dev::solidity;
using namespace dev::mix; using namespace dev::mix;
QFunctionDefinition::QFunctionDefinition(QObject* _parent, dev::solidity::FunctionTypePointer const& _f): QBasicNodeDefinition(_parent, &_f->getDeclaration()), m_hash(dev::sha3(_f->externalTypes())) QFunctionDefinition::QFunctionDefinition(QObject* _parent, dev::solidity::FunctionTypePointer const& _f): QBasicNodeDefinition(_parent, &_f->getDeclaration()), m_hash(dev::sha3(_f->externalSignature()))
{ {
auto paramNames = _f->getParameterNames(); auto paramNames = _f->getParameterNames();
auto paramTypes = _f->getParameterTypes(); auto paramTypes = _f->getParameterTypes();

27
test/SolidityNameAndTypeResolution.cpp

@ -359,7 +359,7 @@ BOOST_AUTO_TEST_CASE(function_canonical_signature)
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
{ {
auto functions = contract->getDefinedFunctions(); auto functions = contract->getDefinedFunctions();
BOOST_CHECK_EQUAL("foo(uint256,uint64,bool)", functions[0]->externalTypes()); BOOST_CHECK_EQUAL("foo(uint256,uint64,bool)", functions[0]->externalSignature());
} }
} }
@ -376,7 +376,7 @@ BOOST_AUTO_TEST_CASE(function_canonical_signature_type_aliases)
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
{ {
auto functions = contract->getDefinedFunctions(); auto functions = contract->getDefinedFunctions();
BOOST_CHECK_EQUAL("boo(uint256,bytes32,address)", functions[0]->externalTypes()); BOOST_CHECK_EQUAL("boo(uint256,bytes32,address)", functions[0]->externalSignature());
} }
} }
@ -385,7 +385,7 @@ BOOST_AUTO_TEST_CASE(function_external_types)
ASTPointer<SourceUnit> sourceUnit; ASTPointer<SourceUnit> sourceUnit;
char const* text = R"( char const* text = R"(
contract Test { contract Test {
function boo(uint arg2, bool arg3, bytes8 arg4) returns (uint ret) { function boo(uint arg2, bool arg3, bytes8 arg4, bool[2] pairs) public returns (uint ret) {
ret = 5; ret = 5;
} }
})"; })";
@ -394,10 +394,28 @@ BOOST_AUTO_TEST_CASE(function_external_types)
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
{ {
auto functions = contract->getDefinedFunctions(); auto functions = contract->getDefinedFunctions();
BOOST_CHECK_EQUAL("boo(uint256,bool,bytes8)", functions[0]->externalTypes()); BOOST_CHECK_EQUAL("boo(uint256,bool,bytes8)", functions[0]->externalSignature());
} }
} }
//BOOST_AUTO_TEST_CASE(function_external_types_throw)
//{
// ASTPointer<SourceUnit> sourceUnit;
// char const* text = R"(
// contract ArrayContract {
// bool[2][] m_pairsOfFlags;
// function setAllFlagPairs(bool[2][] newPairs) {
// // assignment to array replaces the complete array
// m_pairsOfFlags = newPairs;
// }
// })";
// ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseTextAndResolveNames(text), "Parsing and name Resolving failed");
// for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes())
// if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
// {
// auto functions = contract->getDefinedFunctions();
// BOOST_CHECK_EQUAL("boo(uint256,bool,bytes8)", functions[0]->externalSigniture());
// }
//todo should check arrays and contract. also event //todo should check arrays and contract. also event
//BOOST_AUTO_TEST_CASE(function_external_types_throw) //BOOST_AUTO_TEST_CASE(function_external_types_throw)
//{ //{
@ -666,6 +684,7 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors)
"mapping(uint=>bytes4) public map;\n" "mapping(uint=>bytes4) public map;\n"
"mapping(uint=>mapping(uint=>bytes4)) public multiple_map;\n" "mapping(uint=>mapping(uint=>bytes4)) public multiple_map;\n"
"}\n"; "}\n";
ASTPointer<SourceUnit> source; ASTPointer<SourceUnit> source;
ContractDefinition const* contract; ContractDefinition const* contract;
ETH_TEST_CHECK_NO_THROW(source = parseTextAndResolveNames(text), "Parsing and Resolving names failed"); ETH_TEST_CHECK_NO_THROW(source = parseTextAndResolveNames(text), "Parsing and Resolving names failed");

1
test/SolidityTypes.cpp

@ -86,7 +86,6 @@ BOOST_AUTO_TEST_CASE(storage_layout_arrays)
BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared<FixedBytesType>(32), 9).getStorageSize() == 9); BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared<FixedBytesType>(32), 9).getStorageSize() == 9);
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
} }

Loading…
Cancel
Save