55 while (!strToProcess.
empty()) {
57 size_t regexIt = strToProcess.
find(
"{{");
63 strToProcess = strToProcess.
drop_front(regexIt + 2);
66 size_t regexEndIt = strToProcess.
find(
"}}");
68 return emitError(os, mgr,
"found start of regex with no end '}}'");
72 std::string regexError;
74 return emitError(os, mgr,
"invalid regex: " + regexError);
76 regexOS <<
'(' << regexBlock <<
')';
77 strToProcess = strToProcess.
drop_front(regexEndIt + 2);
93 unsigned lastNonDesignatorLine = 0;
101 for (
unsigned lineNo = 0, e = lines.
size(); lineNo < e; ++lineNo) {
103 if (!expected.match(lines[lineNo].rtrim(), &matches)) {
105 if (!designatorsForNextLine.
empty()) {
106 for (
unsigned diagIndex : designatorsForNextLine)
107 expectedDiags[diagIndex].lineNo = lineNo + 1;
108 designatorsForNextLine.clear();
110 lastNonDesignatorLine = lineNo;
118 if (matches[1] ==
"error")
120 else if (matches[1] ==
"warning")
122 else if (matches[1] ==
"remark")
125 assert(matches[1] ==
"note");
128 ExpectedDiag record(kind, lineNo + 1, expectedStart, matches[5]);
131 if (!matches[2].empty() && !record.
computeRegex(os, mgr)) {
137 if (!offsetMatch.
empty()) {
141 if (offsetMatch[0] ==
'+' || offsetMatch[0] ==
'-') {
145 if (offsetMatch.
front() ==
'+')
152 expectedUnknownLocDiags.emplace_back(std::move(record));
157 record.
lineNo = lastNonDesignatorLine + 1;
162 designatorsForNextLine.
push_back(expectedDiags.size());
171 return expectedDiags;
174std::optional<MutableArrayRef<SourceMgrDiagnosticVerifier::ExpectedDiag>>
176 auto expectedDiags = expectedDiagsPerFile.find(bufName);
177 if (expectedDiags != expectedDiagsPerFile.end())
186 StringRef message,
bool reportUnexpected) {
198 diags = expectedUnknownLocDiags;
206 for (
auto &e : diags) {
208 if (
hasLoc && e.lineNo != lineNo)
210 if (e.match(message)) {
211 if (e.kind == kind) {
222 if (!reportUnexpected)
231 "' diagnostic emitted when expecting a '" +
242 diag.emitError(os, mgr,
244 diag.substring +
"\" was not produced");
248 for (
auto &expectedDiagsPair : expectedDiagsPerFile)
249 for (
auto &diag : expectedDiagsPair.second)
250 checkExpectedDiags(diag);
251 for (
auto &diag : expectedUnknownLocDiags)
252 checkExpectedDiags(diag);
253 expectedDiagsPerFile.clear();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
bool hasLoc(const Instruction &I)
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
static StringRef getDiagKindStr(SourceMgr::DiagKind kind)
Given a diagnostic kind, return a human readable string for it.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
StringRef getBuffer() const
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
static LLVM_ABI std::string escape(StringRef String)
Turn String into a regex by escaping its special characters.
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
Represents a range in source code.
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
MatchResult
The result of matching a single actual diagnostic against the expected diagnostics recorded for its l...
@ Matched
The diagnostic matched an expected diagnostic (kind and text).
@ Unexpected
The diagnostic did not match any expected diagnostic.
@ Ignored
The diagnostic did not match, but reportUnexpected was false, so nothing was printed and nothing need...
@ NearMiss
The diagnostic's text matched an expected diagnostic, but its kind didn't; a message about this has a...
bool verify(raw_ostream &os, SourceMgr &mgr)
Reports (through mgr) any expected diagnostic that was never matched by a call to process.
MatchResult process(raw_ostream &os, SourceMgr &mgr, SourceMgr::DiagKind kind, bool hasLoc, const MemoryBuffer *buf, unsigned lineNo, StringRef message, bool reportUnexpected=true)
Matches a single actual diagnostic against the expected diagnostics recorded for buf / lineNo,...
MutableArrayRef< ExpectedDiag > computeExpectedDiags(raw_ostream &os, SourceMgr &mgr, const MemoryBuffer *buf)
Computes and caches the list of expected diagnostics for buf, if not already cached.
std::optional< MutableArrayRef< ExpectedDiag > > getExpectedDiags(StringRef bufName)
Returns the cached expected diagnostics for the buffer named bufName, or std::nullopt if computeExpec...
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
LLVM_ABI void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
static constexpr size_t npos
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
constexpr bool empty() const
Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
char front() const
Get the first character in the string.
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
bool consume_front(char Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
A single diagnostic expected via an 'expected-<kind>' comment.
std::optional< Regex > substringRegex
An optional regex matcher, if the expected diagnostic substring was a regex string.
StringRef substring
The substring that is expected to be within the diagnostic.
LLVM_ABI bool computeRegex(raw_ostream &os, SourceMgr &mgr)
Computes the regex matcher for a '-re' diagnostic's substring.
SourceMgr::DiagKind kind
The severity of the diagnostic expected.
SMLoc fileLoc
The location of the expected diagnostic within the input file.
LLVM_ABI bool match(StringRef str) const
Returns true if this diagnostic matches the given message.
unsigned lineNo
The line number the expected diagnostic should be on.
LLVM_ABI bool emitError(raw_ostream &os, SourceMgr &mgr, const Twine &msg) const
Prints msg at this diagnostic's location and returns false, for use as return emitError(....