mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Styling in Natspec Enums
This commit is contained in:
		
							parent
							
								
									3ef75bae6b
								
							
						
					
					
						commit
						7c0ae1a82f
					
				@ -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:
 | 
				
			||||||
 | 
				
			|||||||
@ -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;
 | 
				
			||||||
 | 
				
			|||||||
@ -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
 | 
				
			||||||
 | 
				
			|||||||
@ -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
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user