summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
diff options
context:
space:
mode:
authorThomas Preud'homme <thomasp@graphcore.ai>2019-07-15 19:04:56 +0000
committerThomas Preud'homme <thomasp@graphcore.ai>2019-07-15 19:04:56 +0000
commit99f2a108707ebf015571101b113fc03b30ad79b9 (patch)
treeb20ad4a7b50fb54212f52b90db32e869304579ba /llvm/lib/Support
parent42e90ed7717e09a1e0fb21027e8346707b60c896 (diff)
downloadbcm5719-llvm-99f2a108707ebf015571101b113fc03b30ad79b9.tar.gz
bcm5719-llvm-99f2a108707ebf015571101b113fc03b30ad79b9.zip
[FileCheck] Store line numbers as optional values
Summary: Processing of command-line definition of variable and logic around implicit not directives both reuse parsing code that expects a line number to be defined. So far, a special line number of 0 was used for those users of the parsing code where a line number does not make sense. This commit instead represents line numbers as Optional values so that they can be None for those cases. Reviewers: jhenderson, chandlerc, jdenny, probinson, grimar, arichardson, rnk Subscribers: JonChesterfield, rogfer01, hfinkel, kristina, rnk, tra, arichardson, grimar, dblaikie, probinson, llvm-commits, hiraditya Tags: #llvm Differential Revision: https://reviews.llvm.org/D64639 llvm-svn: 366109
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/FileCheck.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/llvm/lib/Support/FileCheck.cpp b/llvm/lib/Support/FileCheck.cpp
index 9fb4d798849..e0f17787bdf 100644
--- a/llvm/lib/Support/FileCheck.cpp
+++ b/llvm/lib/Support/FileCheck.cpp
@@ -124,8 +124,8 @@ char FileCheckNotFoundError::ID = 0;
Expected<FileCheckNumericVariable *>
FileCheckPattern::parseNumericVariableDefinition(
- StringRef &Expr, FileCheckPatternContext *Context, size_t LineNumber,
- const SourceMgr &SM) {
+ StringRef &Expr, FileCheckPatternContext *Context,
+ Optional<size_t> LineNumber, const SourceMgr &SM) {
Expected<VariableProperties> ParseVarResult = parseVariable(Expr, SM);
if (!ParseVarResult)
return ParseVarResult.takeError();
@@ -152,7 +152,7 @@ FileCheckPattern::parseNumericVariableDefinition(
if (VarTableIter != Context->GlobalNumericVariableTable.end())
DefinedNumericVariable = VarTableIter->second;
else
- DefinedNumericVariable = Context->makeNumericVariable(LineNumber, Name);
+ DefinedNumericVariable = Context->makeNumericVariable(Name, LineNumber);
return DefinedNumericVariable;
}
@@ -177,11 +177,12 @@ FileCheckPattern::parseNumericVariableUse(StringRef Name, bool IsPseudo,
if (VarTableIter != Context->GlobalNumericVariableTable.end())
NumericVariable = VarTableIter->second;
else {
- NumericVariable = Context->makeNumericVariable(0, Name);
+ NumericVariable = Context->makeNumericVariable(Name);
Context->GlobalNumericVariableTable[Name] = NumericVariable;
}
- if (!IsPseudo && NumericVariable->getDefLineNumber() == LineNumber)
+ Optional<size_t> DefLineNumber = NumericVariable->getDefLineNumber();
+ if (DefLineNumber && LineNumber && *DefLineNumber == *LineNumber)
return FileCheckErrorDiagnostic::get(
SM, Name,
"numeric variable '" + Name + "' defined on the same line as used");
@@ -620,7 +621,8 @@ Expected<size_t> FileCheckPattern::match(StringRef Buffer, size_t &MatchLen,
std::string TmpStr;
if (!Substitutions.empty()) {
TmpStr = RegExStr;
- Context->LineVariable->setValue(LineNumber);
+ if (LineNumber)
+ Context->LineVariable->setValue(*LineNumber);
size_t InsertOffset = 0;
// Substitute all string variables and expressions whose values are only
@@ -1102,7 +1104,7 @@ FindFirstMatchingPrefix(Regex &PrefixRE, StringRef &Buffer,
void FileCheckPatternContext::createLineVariable() {
assert(!LineVariable && "@LINE pseudo numeric variable already created");
StringRef LineName = "@LINE";
- LineVariable = makeNumericVariable(0, LineName);
+ LineVariable = makeNumericVariable(LineName);
GlobalNumericVariableTable[LineName] = LineVariable;
}
@@ -1131,7 +1133,7 @@ bool FileCheck::ReadCheckFile(SourceMgr &SM, StringRef Buffer, Regex &PrefixRE,
SM.AddNewSourceBuffer(std::move(CmdLine), SMLoc());
ImplicitNegativeChecks.push_back(
- FileCheckPattern(Check::CheckNot, &PatternContext, 0));
+ FileCheckPattern(Check::CheckNot, &PatternContext));
ImplicitNegativeChecks.back().parsePattern(PatternInBuffer,
"IMPLICIT-CHECK", SM, Req);
}
@@ -1790,8 +1792,8 @@ Error FileCheckPatternContext::defineCmdlineVariables(
if (CmdlineDef[0] == '#') {
StringRef CmdlineName = CmdlineDef.substr(1, EqIdx - 1);
Expected<FileCheckNumericVariable *> ParseResult =
- FileCheckPattern::parseNumericVariableDefinition(CmdlineName, this, 0,
- SM);
+ FileCheckPattern::parseNumericVariableDefinition(CmdlineName, this,
+ None, SM);
if (!ParseResult) {
Errs = joinErrors(std::move(Errs), ParseResult.takeError());
continue;
OpenPOWER on IntegriCloud