Browse Source

Styling in Natspec Enums

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
d53dcd3183
  1. 2
      alethzero/MainWin.cpp
  2. 12
      libsolidity/CompilerStack.cpp
  3. 8
      libsolidity/CompilerStack.h
  4. 72
      libsolidity/InterfaceHandler.cpp
  5. 18
      libsolidity/InterfaceHandler.h
  6. 16
      solc/CommandLineInterface.cpp
  7. 2
      test/SolidityABIJSON.cpp
  8. 2
      test/SolidityInterface.cpp
  9. 4
      test/SolidityNatspecJSON.cpp

2
alethzero/MainWin.cpp

@ -1940,7 +1940,7 @@ void Main::on_send_clicked()
{ {
h256 contractHash = compiler.getContractCodeHash(s); h256 contractHash = compiler.getContractCodeHash(s);
m_natspecDB.add(contractHash, m_natspecDB.add(contractHash,
compiler.getMetadata(s, dev::solidity::DocumentationType::NATSPEC_USER)); compiler.getMetadata(s, dev::solidity::DocumentationType::NatspecUser));
} }
} }
catch (...) catch (...)

12
libsolidity/CompilerStack.cpp

@ -227,12 +227,12 @@ void CompilerStack::streamAssembly(ostream& _outStream, string const& _contractN
string const& CompilerStack::getInterface(string const& _contractName) const string const& CompilerStack::getInterface(string const& _contractName) const
{ {
return getMetadata(_contractName, DocumentationType::ABI_INTERFACE); return getMetadata(_contractName, DocumentationType::ABIInterface);
} }
string const& CompilerStack::getSolidityInterface(string const& _contractName) const string const& CompilerStack::getSolidityInterface(string const& _contractName) const
{ {
return getMetadata(_contractName, DocumentationType::ABI_SOLIDITY_INTERFACE); return getMetadata(_contractName, DocumentationType::ABISolidityInterface);
} }
string const& CompilerStack::getMetadata(string const& _contractName, DocumentationType _type) const string const& CompilerStack::getMetadata(string const& _contractName, DocumentationType _type) const
@ -245,16 +245,16 @@ string const& CompilerStack::getMetadata(string const& _contractName, Documentat
std::unique_ptr<string const>* doc; std::unique_ptr<string const>* doc;
switch (_type) switch (_type)
{ {
case DocumentationType::NATSPEC_USER: case DocumentationType::NatspecUser:
doc = &contract.userDocumentation; doc = &contract.userDocumentation;
break; break;
case DocumentationType::NATSPEC_DEV: case DocumentationType::NatspecDev:
doc = &contract.devDocumentation; doc = &contract.devDocumentation;
break; break;
case DocumentationType::ABI_INTERFACE: case DocumentationType::ABIInterface:
doc = &contract.interface; doc = &contract.interface;
break; break;
case DocumentationType::ABI_SOLIDITY_INTERFACE: case DocumentationType::ABISolidityInterface:
doc = &contract.solidityInterface; doc = &contract.solidityInterface;
break; break;
default: default:

8
libsolidity/CompilerStack.h

@ -43,10 +43,10 @@ class InterfaceHandler;
enum class DocumentationType: uint8_t enum class DocumentationType: uint8_t
{ {
NATSPEC_USER = 1, NatspecUser = 1,
NATSPEC_DEV, NatspecDev,
ABI_INTERFACE, ABIInterface,
ABI_SOLIDITY_INTERFACE ABISolidityInterface
}; };
extern const std::map<std::string, std::string> StandardSources; extern const std::map<std::string, std::string> StandardSources;

72
libsolidity/InterfaceHandler.cpp

@ -13,7 +13,7 @@ namespace solidity
InterfaceHandler::InterfaceHandler() InterfaceHandler::InterfaceHandler()
{ {
m_lastTag = DocTagType::NONE; m_lastTag = DocTagType::None;
} }
std::unique_ptr<std::string> InterfaceHandler::getDocumentation(ContractDefinition const& _contractDef, std::unique_ptr<std::string> InterfaceHandler::getDocumentation(ContractDefinition const& _contractDef,
@ -21,13 +21,13 @@ std::unique_ptr<std::string> InterfaceHandler::getDocumentation(ContractDefiniti
{ {
switch(_type) switch(_type)
{ {
case DocumentationType::NATSPEC_USER: case DocumentationType::NatspecUser:
return getUserDocumentation(_contractDef); return getUserDocumentation(_contractDef);
case DocumentationType::NATSPEC_DEV: case DocumentationType::NatspecDev:
return getDevDocumentation(_contractDef); return getDevDocumentation(_contractDef);
case DocumentationType::ABI_INTERFACE: case DocumentationType::ABIInterface:
return getABIInterface(_contractDef); return getABIInterface(_contractDef);
case DocumentationType::ABI_SOLIDITY_INTERFACE: case DocumentationType::ABISolidityInterface:
return getABISolidityInterface(_contractDef); return getABISolidityInterface(_contractDef);
} }
@ -133,7 +133,7 @@ std::unique_ptr<std::string> InterfaceHandler::getUserDocumentation(ContractDefi
if (strPtr) if (strPtr)
{ {
resetUser(); resetUser();
parseDocString(*strPtr, CommentOwner::FUNCTION); parseDocString(*strPtr, CommentOwner::Function);
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);
@ -158,7 +158,7 @@ std::unique_ptr<std::string> InterfaceHandler::getDevDocumentation(ContractDefin
{ {
m_contractAuthor.clear(); m_contractAuthor.clear();
m_title.clear(); m_title.clear();
parseDocString(*contractDoc, CommentOwner::CONTRACT); parseDocString(*contractDoc, CommentOwner::Contract);
if (!m_contractAuthor.empty()) if (!m_contractAuthor.empty())
doc["author"] = m_contractAuthor; doc["author"] = m_contractAuthor;
@ -174,7 +174,7 @@ std::unique_ptr<std::string> InterfaceHandler::getDevDocumentation(ContractDefin
if (strPtr) if (strPtr)
{ {
resetDev(); resetDev();
parseDocString(*strPtr, CommentOwner::FUNCTION); parseDocString(*strPtr, CommentOwner::Function);
if (!m_dev.empty()) if (!m_dev.empty())
method["details"] = Json::Value(m_dev); method["details"] = Json::Value(m_dev);
@ -251,7 +251,7 @@ std::string::const_iterator InterfaceHandler::parseDocTagParam(std::string::cons
auto paramDesc = std::string(currPos, nlPos); auto paramDesc = std::string(currPos, nlPos);
m_params.push_back(std::make_pair(paramName, paramDesc)); m_params.push_back(std::make_pair(paramName, paramDesc));
m_lastTag = DocTagType::PARAM; m_lastTag = DocTagType::Param;
return skipLineOrEOS(nlPos, _end); return skipLineOrEOS(nlPos, _end);
} }
@ -280,28 +280,28 @@ std::string::const_iterator InterfaceHandler::parseDocTag(std::string::const_ite
// LTODO: need to check for @(start of a tag) between here and the end of line // LTODO: need to check for @(start of a tag) between here and the end of line
// for all cases. Also somehow automate list of acceptable tags for each // for all cases. Also somehow automate list of acceptable tags for each
// language construct since current way does not scale well. // language construct since current way does not scale well.
if (m_lastTag == DocTagType::NONE || _tag != "") if (m_lastTag == DocTagType::None || _tag != "")
{ {
if (_tag == "dev") if (_tag == "dev")
return parseDocTagLine(_pos, _end, m_dev, DocTagType::DEV, false); return parseDocTagLine(_pos, _end, m_dev, DocTagType::Dev, false);
else if (_tag == "notice") else if (_tag == "notice")
return parseDocTagLine(_pos, _end, m_notice, DocTagType::NOTICE, false); return parseDocTagLine(_pos, _end, m_notice, DocTagType::Notice, false);
else if (_tag == "return") else if (_tag == "return")
return parseDocTagLine(_pos, _end, m_return, DocTagType::RETURN, false); return parseDocTagLine(_pos, _end, m_return, DocTagType::Return, false);
else if (_tag == "author") else if (_tag == "author")
{ {
if (_owner == CommentOwner::CONTRACT) if (_owner == CommentOwner::Contract)
return parseDocTagLine(_pos, _end, m_contractAuthor, DocTagType::AUTHOR, false); return parseDocTagLine(_pos, _end, m_contractAuthor, DocTagType::Author, false);
else if (_owner == CommentOwner::FUNCTION) else if (_owner == CommentOwner::Function)
return parseDocTagLine(_pos, _end, m_author, DocTagType::AUTHOR, false); return parseDocTagLine(_pos, _end, m_author, DocTagType::Author, false);
else else
// LTODO: for now this else makes no sense but later comments will go to more language constructs // LTODO: for now this else makes no sense but later comments will go to more language constructs
BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("@author tag is legal only for contracts")); BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("@author tag is legal only for contracts"));
} }
else if (_tag == "title") else if (_tag == "title")
{ {
if (_owner == CommentOwner::CONTRACT) if (_owner == CommentOwner::Contract)
return parseDocTagLine(_pos, _end, m_title, DocTagType::TITLE, false); return parseDocTagLine(_pos, _end, m_title, DocTagType::Title, false);
else else
// LTODO: Unknown tag, throw some form of warning and not just an exception // LTODO: Unknown tag, throw some form of warning and not just an exception
BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("@title tag is legal only for contracts")); BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("@title tag is legal only for contracts"));
@ -322,27 +322,27 @@ std::string::const_iterator InterfaceHandler::appendDocTag(std::string::const_it
{ {
switch (m_lastTag) switch (m_lastTag)
{ {
case DocTagType::DEV: case DocTagType::Dev:
return parseDocTagLine(_pos, _end, m_dev, DocTagType::DEV, true); return parseDocTagLine(_pos, _end, m_dev, DocTagType::Dev, true);
case DocTagType::NOTICE: case DocTagType::Notice:
return parseDocTagLine(_pos, _end, m_notice, DocTagType::NOTICE, true); return parseDocTagLine(_pos, _end, m_notice, DocTagType::Notice, true);
case DocTagType::RETURN: case DocTagType::Return:
return parseDocTagLine(_pos, _end, m_return, DocTagType::RETURN, true); return parseDocTagLine(_pos, _end, m_return, DocTagType::Return, true);
case DocTagType::AUTHOR: case DocTagType::Author:
if (_owner == CommentOwner::CONTRACT) if (_owner == CommentOwner::Contract)
return parseDocTagLine(_pos, _end, m_contractAuthor, DocTagType::AUTHOR, true); return parseDocTagLine(_pos, _end, m_contractAuthor, DocTagType::Author, true);
else if (_owner == CommentOwner::FUNCTION) else if (_owner == CommentOwner::Function)
return parseDocTagLine(_pos, _end, m_author, DocTagType::AUTHOR, true); return parseDocTagLine(_pos, _end, m_author, DocTagType::Author, true);
else else
// LTODO: Unknown tag, throw some form of warning and not just an exception // LTODO: Unknown tag, throw some form of warning and not just an exception
BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("@author tag in illegal comment")); BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("@author tag in illegal comment"));
case DocTagType::TITLE: case DocTagType::Title:
if (_owner == CommentOwner::CONTRACT) if (_owner == CommentOwner::Contract)
return parseDocTagLine(_pos, _end, m_title, DocTagType::TITLE, true); return parseDocTagLine(_pos, _end, m_title, DocTagType::Title, true);
else else
// LTODO: Unknown tag, throw some form of warning and not just an exception // LTODO: Unknown tag, throw some form of warning and not just an exception
BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("@title tag in illegal comment")); BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("@title tag in illegal comment"));
case DocTagType::PARAM: case DocTagType::Param:
return appendDocTagParam(_pos, _end); return appendDocTagParam(_pos, _end);
default: default:
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Internal: Illegal documentation tag type")); BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Internal: Illegal documentation tag type"));
@ -378,14 +378,14 @@ void InterfaceHandler::parseDocString(std::string const& _string, CommentOwner _
currPos = parseDocTag(tagNameEndPos + 1, end, std::string(tagPos + 1, tagNameEndPos), _owner); currPos = parseDocTag(tagNameEndPos + 1, end, std::string(tagPos + 1, tagNameEndPos), _owner);
} }
else if (m_lastTag != DocTagType::NONE) // continuation of the previous tag else if (m_lastTag != DocTagType::None) // continuation of the previous tag
currPos = appendDocTag(currPos, end, _owner); currPos = appendDocTag(currPos, end, _owner);
else if (currPos != end) else if (currPos != end)
{ {
// if it begins without a tag then consider it as @notice // if it begins without a tag then consider it as @notice
if (currPos == _string.begin()) if (currPos == _string.begin())
{ {
currPos = parseDocTag(currPos, end, "notice", CommentOwner::FUNCTION); currPos = parseDocTag(currPos, end, "notice", CommentOwner::Function);
continue; continue;
} }
else if (nlPos == end) //end of text else if (nlPos == end) //end of text

18
libsolidity/InterfaceHandler.h

@ -41,19 +41,19 @@ enum class DocumentationType: uint8_t;
enum class DocTagType: uint8_t enum class DocTagType: uint8_t
{ {
NONE = 0, None = 0,
DEV, Dev,
NOTICE, Notice,
PARAM, Param,
RETURN, Return,
AUTHOR, Author,
TITLE Title
}; };
enum class CommentOwner enum class CommentOwner
{ {
CONTRACT, Contract,
FUNCTION Function
}; };
class InterfaceHandler class InterfaceHandler

16
solc/CommandLineInterface.cpp

@ -161,22 +161,22 @@ void CommandLineInterface::handleMeta(DocumentationType _type, string const& _co
std::string title; std::string title;
switch(_type) switch(_type)
{ {
case DocumentationType::ABI_INTERFACE: case DocumentationType::ABIInterface:
argName = g_argAbiStr; argName = g_argAbiStr;
suffix = ".abi"; suffix = ".abi";
title = "Contract JSON ABI"; title = "Contract JSON ABI";
break; break;
case DocumentationType::ABI_SOLIDITY_INTERFACE: case DocumentationType::ABISolidityInterface:
argName = g_argSolAbiStr; argName = g_argSolAbiStr;
suffix = ".sol"; suffix = ".sol";
title = "Contract Solidity ABI"; title = "Contract Solidity ABI";
break; break;
case DocumentationType::NATSPEC_USER: case DocumentationType::NatspecUser:
argName = g_argNatspecUserStr; argName = g_argNatspecUserStr;
suffix = ".docuser"; suffix = ".docuser";
title = "User Documentation"; title = "User Documentation";
break; break;
case DocumentationType::NATSPEC_DEV: case DocumentationType::NatspecDev:
argName = g_argNatspecDevStr; argName = g_argNatspecDevStr;
suffix = ".docdev"; suffix = ".docdev";
title = "Developer Documentation"; title = "Developer Documentation";
@ -436,10 +436,10 @@ void CommandLineInterface::actOnInput()
} }
handleBytecode(contract); handleBytecode(contract);
handleMeta(DocumentationType::ABI_INTERFACE, contract); handleMeta(DocumentationType::ABIInterface, contract);
handleMeta(DocumentationType::ABI_SOLIDITY_INTERFACE, contract); handleMeta(DocumentationType::ABISolidityInterface, contract);
handleMeta(DocumentationType::NATSPEC_DEV, contract); handleMeta(DocumentationType::NatspecDev, contract);
handleMeta(DocumentationType::NATSPEC_USER, contract); handleMeta(DocumentationType::NatspecUser, contract);
} // end of contracts iteration } // end of contracts iteration
} }

2
test/SolidityABIJSON.cpp

@ -48,7 +48,7 @@ public:
auto msg = std::string("Parsing contract failed with: ") + boost::diagnostic_information(_e); auto msg = std::string("Parsing contract failed with: ") + boost::diagnostic_information(_e);
BOOST_FAIL(msg); BOOST_FAIL(msg);
} }
std::string generatedInterfaceString = m_compilerStack.getMetadata("", DocumentationType::ABI_INTERFACE); std::string generatedInterfaceString = m_compilerStack.getMetadata("", DocumentationType::ABIInterface);
Json::Value generatedInterface; Json::Value generatedInterface;
m_reader.parse(generatedInterfaceString, generatedInterface); m_reader.parse(generatedInterfaceString, generatedInterface);
Json::Value expectedInterface; Json::Value expectedInterface;

2
test/SolidityInterface.cpp

@ -43,7 +43,7 @@ public:
{ {
m_code = _code; m_code = _code;
BOOST_REQUIRE_NO_THROW(m_compilerStack.parse(_code)); BOOST_REQUIRE_NO_THROW(m_compilerStack.parse(_code));
m_interface = m_compilerStack.getMetadata("", DocumentationType::ABI_SOLIDITY_INTERFACE); m_interface = m_compilerStack.getMetadata("", DocumentationType::ABISolidityInterface);
BOOST_REQUIRE_NO_THROW(m_reCompiler.parse(m_interface)); BOOST_REQUIRE_NO_THROW(m_reCompiler.parse(m_interface));
return m_reCompiler.getContractDefinition(_contractName); return m_reCompiler.getContractDefinition(_contractName);
} }

4
test/SolidityNatspecJSON.cpp

@ -54,9 +54,9 @@ public:
} }
if (_userDocumentation) if (_userDocumentation)
generatedDocumentationString = m_compilerStack.getMetadata("", DocumentationType::NATSPEC_USER); generatedDocumentationString = m_compilerStack.getMetadata("", DocumentationType::NatspecUser);
else else
generatedDocumentationString = m_compilerStack.getMetadata("", DocumentationType::NATSPEC_DEV); generatedDocumentationString = m_compilerStack.getMetadata("", DocumentationType::NatspecDev);
Json::Value generatedDocumentation; Json::Value generatedDocumentation;
m_reader.parse(generatedDocumentationString, generatedDocumentation); m_reader.parse(generatedDocumentationString, generatedDocumentation);
Json::Value expectedDocumentation; Json::Value expectedDocumentation;

Loading…
Cancel
Save