Browse Source

changed implementation according to notes from code review

cl-refactor
Liana Husikyan 10 years ago
parent
commit
e5ffefeab8
  1. 12
      libsolidity/AST.cpp
  2. 4
      libsolidity/AST.h
  3. 12
      libsolidity/CompilerStack.cpp
  4. 2
      libsolidity/CompilerStack.h
  5. 30
      libsolidity/InterfaceHandler.cpp
  6. 19
      libsolidity/InterfaceHandler.h
  7. 2
      mix/CodeModel.cpp

12
libsolidity/AST.cpp

@ -382,19 +382,19 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::getIn
return *m_interfaceFunctionList;
}
unique_ptr<string> ContractDefinition::devDocumentation() const
string const& ContractDefinition::devDocumentation() const
{
return unique_ptr<string>(new string(m_devDocumentation));
return m_devDocumentation;
}
void ContractDefinition::setDevDocumentation(string const& _devDocumentation)
string const& ContractDefinition::userDocumentation() const
{
m_devDocumentation = _devDocumentation;
return m_userDocumentation;
}
std::unique_ptr<string> ContractDefinition::userDocumentation() const
void ContractDefinition::setDevDocumentation(string const& _devDocumentation)
{
return unique_ptr<string>(new string(m_userDocumentation));
m_devDocumentation = _devDocumentation;
}
void ContractDefinition::setUserDocumentation(string const& _userDocumentation)

4
libsolidity/AST.h

@ -281,10 +281,10 @@ public:
/// Returns the fallback function or nullptr if no fallback function was specified.
FunctionDefinition const* getFallbackFunction() const;
std::unique_ptr<std::string> userDocumentation() const;
std::string const& userDocumentation() const;
void setUserDocumentation(std::string const& _userDocumentation);
std::unique_ptr<std::string> devDocumentation() const;
std::string const& devDocumentation() const;
void setDevDocumentation(std::string const& _devDocumentation);
private:

12
libsolidity/CompilerStack.cpp

@ -129,11 +129,12 @@ void CompilerStack::parse()
m_parseSuccessful = true;
}
void CompilerStack::parseNatspecDocumentation(ContractDefinition& _contract)
void CompilerStack::parseNatspecDocumentation(ContractDefinition const& _contract)
{
InterfaceHandler interfaceHandler;
interfaceHandler.generateDevDocumentation(_contract);
interfaceHandler.generateUserDocumentation(_contract);
string devDoc =_contract.devDocumentation();
devDoc = interfaceHandler.devDocumentation(_contract);
//interfaceHandler.generateUserDocumentation(_contract);
}
void CompilerStack::parse(string const& _sourceCode)
@ -256,8 +257,11 @@ string const& CompilerStack::getMetadata(string const& _contractName, Documentat
default:
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Illegal documentation type."));
}
auto resPtr = ((*doc) ? *(*doc) : contract.interfaceHandler->getDocumentation(*contract.contract, _type));
if (!*doc)
*doc = contract.interfaceHandler->getDocumentation(*contract.contract, _type);
*doc = (unique_ptr<string>(new string(contract.interfaceHandler->getDocumentation(*contract.contract, _type))));
return *(*doc);
}

2
libsolidity/CompilerStack.h

@ -149,7 +149,7 @@ public:
std::tuple<int, int, int, int> positionFromSourceLocation(SourceLocation const& _sourceLocation) const;
/// Parses Natspec documentations. Throws exceptions in case of wrong documented contract
void parseNatspecDocumentation(ContractDefinition& _contract);
void parseNatspecDocumentation(dev::solidity::ContractDefinition const& _contract);
private:
/**

30
libsolidity/InterfaceHandler.cpp

@ -16,7 +16,7 @@ InterfaceHandler::InterfaceHandler()
m_lastTag = DocTagType::None;
}
unique_ptr<string> InterfaceHandler::getDocumentation(
string InterfaceHandler::getDocumentation(
ContractDefinition const& _contractDef,
DocumentationType _type
)
@ -34,10 +34,10 @@ unique_ptr<string> InterfaceHandler::getDocumentation(
}
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown documentation type"));
return nullptr;
return "";
}
unique_ptr<string> InterfaceHandler::getABIInterface(ContractDefinition const& _contractDef)
string InterfaceHandler::getABIInterface(ContractDefinition const& _contractDef)
{
Json::Value abi(Json::arrayValue);
@ -103,10 +103,10 @@ unique_ptr<string> InterfaceHandler::getABIInterface(ContractDefinition const& _
event["inputs"] = params;
abi.append(event);
}
return unique_ptr<string>(new string(Json::FastWriter().write(abi)));
return Json::FastWriter().write(abi);
}
unique_ptr<string> InterfaceHandler::getABISolidityInterface(ContractDefinition const& _contractDef)
string InterfaceHandler::getABISolidityInterface(ContractDefinition const& _contractDef)
{
string ret = "contract " + _contractDef.getName() + "{";
@ -140,10 +140,10 @@ unique_ptr<string> InterfaceHandler::getABISolidityInterface(ContractDefinition
ret += ";";
}
return unique_ptr<string>(new string(ret + "}"));
return ret + "}";
}
void InterfaceHandler::generateUserDocumentation(ContractDefinition& _contractDef)
string InterfaceHandler::userDocumentation(ContractDefinition const& _contractDef)
{
Json::Value doc;
Json::Value methods(Json::objectValue);
@ -165,20 +165,10 @@ void InterfaceHandler::generateUserDocumentation(ContractDefinition& _contractDe
}
doc["methods"] = methods;
_contractDef.setUserDocumentation(Json::StyledWriter().write(doc));
return Json::StyledWriter().write(doc);
}
unique_ptr<string> InterfaceHandler::userDocumentation(ContractDefinition const& _contractDef)
{
return _contractDef.userDocumentation();
}
unique_ptr<string> InterfaceHandler::devDocumentation(ContractDefinition const& _contractDef)
{
return _contractDef.devDocumentation();
}
void InterfaceHandler::generateDevDocumentation(ContractDefinition& _contractDef)
string InterfaceHandler::devDocumentation(ContractDefinition const& _contractDef)
{
// LTODO: Somewhere in this function warnings for mismatch of param names
// should be thrown
@ -239,7 +229,7 @@ void InterfaceHandler::generateDevDocumentation(ContractDefinition& _contractDef
}
doc["methods"] = methods;
_contractDef.setDevDocumentation(Json::StyledWriter().write(doc));
return Json::StyledWriter().write(doc);
}
/* -- private -- */

19
libsolidity/InterfaceHandler.h

@ -65,9 +65,8 @@ public:
/// @param _contractDef The contract definition
/// @param _type The type of the documentation. Can be one of the
/// types provided by @c DocumentationType
/// @return A unique pointer contained string with the json
/// representation of provided type
std::unique_ptr<std::string> getDocumentation(
/// @return A string with the json representation of provided type
std::string getDocumentation(
ContractDefinition const& _contractDef,
DocumentationType _type
);
@ -75,24 +74,18 @@ public:
/// @param _contractDef The contract definition
/// @return A unique pointer contained string with the json
/// representation of the contract's ABI Interface
std::unique_ptr<std::string> getABIInterface(ContractDefinition const& _contractDef);
std::unique_ptr<std::string> getABISolidityInterface(ContractDefinition const& _contractDef);
/// Generate the User documentation of the contract
/// @param _contractDef The contract definition
void generateUserDocumentation(ContractDefinition& _contractDef);
std::string getABIInterface(ContractDefinition const& _contractDef);
std::string getABISolidityInterface(ContractDefinition const& _contractDef);
/// Get the User documentation of the contract
/// @param _contractDef The contract definition
/// @return A unique pointer contained string with the json
/// representation of the contract's user documentation
std::unique_ptr<std::string> userDocumentation(ContractDefinition const& _contractDef);
/// Genereates the Developer's documentation of the contract
/// @param _contractDef The contract definition
void generateDevDocumentation(ContractDefinition& _contractDef);
std::string userDocumentation(ContractDefinition const& _contractDef);
/// Genereates the Developer's documentation of the contract
/// @param _contractDef The contract definition
/// @return A unique pointer contained string with the json
/// representation of the contract's developer documentation
std::unique_ptr<std::string> devDocumentation(ContractDefinition const& _contractDef);
std::string devDocumentation(ContractDefinition const& _contractDef);
private:
void resetUser();

2
mix/CodeModel.cpp

@ -157,7 +157,7 @@ CompiledContract::CompiledContract(const dev::solidity::CompilerStack& _compiler
m_bytes = _compiler.getBytecode(_contractName.toStdString());
dev::solidity::InterfaceHandler interfaceHandler;
m_contractInterface = QString::fromStdString(*interfaceHandler.getABIInterface(contractDefinition));
m_contractInterface = QString::fromStdString(interfaceHandler.getABIInterface(contractDefinition));
if (m_contractInterface.isEmpty())
m_contractInterface = "[]";
if (contractDefinition.getLocation().sourceName.get())

Loading…
Cancel
Save