Browse Source

Introducing Docstring parsing error exception and style fixes

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
cfb8e74a75
  1. 1
      libsolidity/Exceptions.h
  2. 20
      libsolidity/InterfaceHandler.cpp

1
libsolidity/Exceptions.h

@ -36,6 +36,7 @@ struct TypeError: virtual Exception {};
struct DeclarationError: virtual Exception {}; struct DeclarationError: virtual Exception {};
struct CompilerError: virtual Exception {}; struct CompilerError: virtual Exception {};
struct InternalCompilerError: virtual Exception {}; struct InternalCompilerError: virtual Exception {};
struct DocstringParsingError: virtual Exception {};
typedef boost::error_info<struct tag_sourcePosition, int> errinfo_sourcePosition; typedef boost::error_info<struct tag_sourcePosition, int> errinfo_sourcePosition;
typedef boost::error_info<struct tag_sourceLocation, Location> errinfo_sourceLocation; typedef boost::error_info<struct tag_sourceLocation, Location> errinfo_sourceLocation;

20
libsolidity/InterfaceHandler.cpp

@ -28,7 +28,7 @@ std::unique_ptr<std::string> InterfaceHandler::getDocumentation(std::shared_ptr<
return getABIInterface(_contractDef); return getABIInterface(_contractDef);
} }
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Internal error")); BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown documentation type"));
return nullptr; return nullptr;
} }
@ -160,7 +160,7 @@ std::string::const_iterator InterfaceHandler::parseDocTagParam(std::string::cons
// find param name // find param name
auto currPos = std::find(_pos, _end, ' '); auto currPos = std::find(_pos, _end, ' ');
if (currPos == _end) if (currPos == _end)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("End of param name not found")); BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("End of param name not found" + std::string(_pos, _end)));
auto paramName = std::string(_pos, currPos); auto paramName = std::string(_pos, currPos);
@ -179,7 +179,7 @@ std::string::const_iterator InterfaceHandler::appendDocTagParam(std::string::con
{ {
// Should never be called with an empty vector // Should never be called with an empty vector
if (asserts(!m_params.empty())) if (asserts(!m_params.empty()))
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Internal: Tried to append to empty parameter")); BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Internal: Tried to append to empty parameter"));
auto pair = m_params.back(); auto pair = m_params.back();
pair.second += " "; pair.second += " ";
@ -210,7 +210,7 @@ std::string::const_iterator InterfaceHandler::parseDocTag(std::string::const_ite
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(CompilerError() << errinfo_comment("Unknown tag encountered")); BOOST_THROW_EXCEPTION(DocstringParsingError() << errinfo_comment("Unknown tag " + _tag + " encountered"));
} }
} }
else else
@ -234,7 +234,7 @@ std::string::const_iterator InterfaceHandler::appendDocTag(std::string::const_it
case DOCTAG_PARAM: case DOCTAG_PARAM:
return appendDocTagParam(_pos, _end); return appendDocTagParam(_pos, _end);
default: default:
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Internal: Illegal documentation tag")); BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Internal: Illegal documentation tag type"));
break; break;
} }
} }
@ -254,18 +254,16 @@ void InterfaceHandler::parseDocString(std::string const& _string)
// we found a tag // we found a tag
auto tagNameEndPos = std::find(tagPos, end, ' '); auto tagNameEndPos = std::find(tagPos, end, ' ');
if (tagNameEndPos == end) if (tagNameEndPos == end)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("End of tag not found")); BOOST_THROW_EXCEPTION(DocstringParsingError() <<
errinfo_comment("End of tag " + std::string(tagPos, tagNameEndPos) + "not found"));
currPos = parseDocTag(tagNameEndPos + 1, end, std::string(tagPos +1, tagNameEndPos)); currPos = parseDocTag(tagNameEndPos + 1, end, std::string(tagPos + 1, tagNameEndPos));
} }
else if (m_lastTag != DOCTAG_NONE) // continuation of the previous tag else if (m_lastTag != DOCTAG_NONE) // continuation of the previous tag
currPos = appendDocTag(currPos + 1, end); currPos = appendDocTag(currPos + 1, end);
else // skip the line if a newline was found else if (currPos != end) // skip the line if a newline was found
{
if (currPos != end)
currPos = nlPos + 1; currPos = nlPos + 1;
} }
}
} }
} //solidity NS } //solidity NS

Loading…
Cancel
Save