13 namespace ast_matchers {
15 Diagnostics::ArgStream Diagnostics::pushContextFrame(ContextType Type,
17 ContextStack.emplace_back();
18 ContextFrame& data = ContextStack.back();
21 return ArgStream(&data.Args);
25 StringRef MatcherName,
32 StringRef MatcherName,
36 Error->pushContextFrame(
CT_MatcherArg, MatcherRange) << ArgNumber
43 : Error(Error), BeginIndex(Error->Errors.size()) {}
47 if (BeginIndex < Error->Errors.size()) {
49 for (
size_t i = BeginIndex + 1, e = Error->Errors.size(); i < e; ++i) {
50 Dest.
Messages.push_back(Error->Errors[i].Messages[0]);
52 Error->Errors.resize(BeginIndex + 1);
58 Error->Errors.resize(BeginIndex);
62 Out->push_back(Arg.str());
68 Errors.emplace_back();
80 return "Error building matcher $0.";
82 return "Error parsing argument $0 for matcher $1.";
84 llvm_unreachable(
"Unknown ContextType value.");
90 return "Matcher not found: $0";
92 return "Incorrect argument count. (Expected = $0) != (Actual = $1)";
94 return "Incorrect type for arg $0. (Expected = $1) != (Actual = $2)";
96 return "Matcher does not support binding.";
99 return "Ambiguous matcher overload.";
101 return "Value not found: $0";
104 return "Error parsing string token: <$0>";
106 return "Error parsing matcher. Found token <$0> while looking for '('.";
108 return "Error parsing matcher. Found end-of-code while looking for ')'.";
110 return "Error parsing matcher. Found token <$0> while looking for ','.";
112 return "End of code found while looking for token.";
114 return "Input value is not a matcher expression.";
116 return "Invalid token <$0> found when looking for a value.";
118 return "Malformed bind() expression.";
120 return "Expected end of code.";
122 return "Error parsing unsigned token: <$0>";
124 return "Input value has unresolved overloaded type: $0";
129 llvm_unreachable(
"Unknown ErrorType value.");
134 llvm::raw_ostream &OS) {
135 while (!FormatString.empty()) {
136 std::pair<StringRef, StringRef> Pieces = FormatString.split(
"$");
137 OS << Pieces.first.str();
138 if (Pieces.second.empty())
break;
140 const char Next = Pieces.second.front();
141 FormatString = Pieces.second.drop_front();
142 if (Next >=
'0' && Next <=
'9') {
143 const unsigned Index = Next -
'0';
144 if (Index < Args.size()) {
147 OS <<
"<Argument_Not_Provided>";
154 llvm::raw_ostream &OS) {
161 llvm::raw_ostream &OS) {
168 const Twine Prefix, llvm::raw_ostream &OS) {
175 llvm::raw_ostream &OS) {
179 for (
size_t i = 0, e = Content.
Messages.size(); i != e; ++i) {
180 if (i != 0) OS <<
"\n";
182 "Candidate " + Twine(i + 1) +
": ", OS);
188 for (
size_t i = 0, e = Errors.size(); i != e; ++i) {
189 if (i != 0) OS <<
"\n";
196 llvm::raw_string_ostream OS(S);
202 for (
size_t i = 0, e = Errors.size(); i != e; ++i) {
203 if (i != 0) OS <<
"\n";
205 for (
size_t i = 0, e = Error.
ContextStack.size(); i != e; ++i) {
215 llvm::raw_string_ostream OS(S);
static void printErrorContentToStream(const Diagnostics::ErrorContent &Content, llvm::raw_ostream &OS)
std::string toString() const
static void maybeAddLineAndColumn(SourceRange Range, llvm::raw_ostream &OS)
static StringRef contextTypeToFormatString(Diagnostics::ContextType Type)
std::vector< std::string > Args
MatcherArgEnum
About to recurse into parsing one argument for a matcher.
Context(ConstructMatcherEnum, Diagnostics *Error, StringRef MatcherName, SourceRange MatcherRange)
ContextType
Parser context types.
ConstructMatcherEnum
About to call the constructor for a matcher.
std::vector< Message > Messages
OverloadContext(Diagnostics *Error)
void revertErrors()
Revert all errors that happened within this context.
std::string toStringFull() const
Diagnostics class to manage error messages.
Helper class to manage error messages.
static void printContextFrameToStream(const Diagnostics::ContextFrame &Frame, llvm::raw_ostream &OS)
ArgStream addError(SourceRange Range, ErrorType Error)
Add an error to the diagnostics.
static void formatErrorString(StringRef FormatString, ArrayRef< std::string > Args, llvm::raw_ostream &OS)
ErrorType
All errors from the system.
void printToStream(llvm::raw_ostream &OS) const
Returns a simple string representation of each error.
ArgStream & operator<<(const T &Arg)
std::vector< ContextFrame > ContextStack
Information stored for each error found.
std::vector< std::string > Args
void printToStreamFull(llvm::raw_ostream &OS) const
Returns the full string representation of each error.
static void printMessageToStream(const Diagnostics::ErrorContent::Message &Message, const Twine Prefix, llvm::raw_ostream &OS)
static StringRef errorTypeToFormatString(Diagnostics::ErrorType Type)
Information stored for one frame of the context.