[llvm] r365191 - [FileCheck] Factor some parsing checks out
Thomas Preud'homme via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 5 05:01:07 PDT 2019
Author: thopre
Date: Fri Jul 5 05:01:06 2019
New Revision: 365191
URL: http://llvm.org/viewvc/llvm-project?rev=365191&view=rev
Log:
[FileCheck] Factor some parsing checks out
Summary:
Both callers of parseNumericVariableDefinition() perform the same extra
check that no character is found after the variable name. This patch
factors out this check into parseNumericVariableDefinition().
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/D64226
Modified:
llvm/trunk/lib/Support/FileCheck.cpp
llvm/trunk/test/FileCheck/numeric-defines-diagnostics.txt
Modified: llvm/trunk/lib/Support/FileCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/FileCheck.cpp?rev=365191&r1=365190&r2=365191&view=diff
==============================================================================
--- llvm/trunk/lib/Support/FileCheck.cpp (original)
+++ llvm/trunk/lib/Support/FileCheck.cpp Fri Jul 5 05:01:06 2019
@@ -130,6 +130,11 @@ Error FileCheckPattern::parseNumericVari
return FileCheckErrorDiagnostic::get(
SM, Name, "string variable with name '" + Name + "' already exists");
+ Expr = Expr.ltrim(SpaceChars);
+ if (!Expr.empty())
+ return FileCheckErrorDiagnostic::get(
+ SM, Expr, "unexpected characters after numeric variable name");
+
return Error::success();
}
@@ -229,27 +234,21 @@ Expected<FileCheckExpression *> FileChec
size_t DefEnd = Expr.find(':');
if (DefEnd != StringRef::npos) {
StringRef DefExpr = Expr.substr(0, DefEnd);
- StringRef UseExpr = Expr = Expr.substr(DefEnd + 1);
-
- DefExpr = DefExpr.ltrim(SpaceChars);
- StringRef Name;
- Error ErrorDiagnostic =
- parseNumericVariableDefinition(DefExpr, Name, Context, SM);
- if (ErrorDiagnostic)
- return std::move(ErrorDiagnostic);
-
- DefinedNumericVariable =
- Context->makeNumericVariable(this->LineNumber, Name);
+ StringRef UseExpr = Expr.substr(DefEnd + 1);
- DefExpr = DefExpr.ltrim(SpaceChars);
- if (!DefExpr.empty())
- return FileCheckErrorDiagnostic::get(
- SM, DefExpr, "invalid numeric variable definition");
UseExpr = UseExpr.ltrim(SpaceChars);
if (!UseExpr.empty())
return FileCheckErrorDiagnostic::get(
SM, UseExpr,
"unexpected string after variable definition: '" + UseExpr + "'");
+
+ DefExpr = DefExpr.ltrim(SpaceChars);
+ StringRef Name;
+ Error Err = parseNumericVariableDefinition(DefExpr, Name, Context, SM);
+ if (Err)
+ return std::move(Err);
+ DefinedNumericVariable = Context->makeNumericVariable(LineNumber, Name);
+
return Context->makeExpression(add, nullptr, 0);
}
@@ -1735,32 +1734,12 @@ Error FileCheckPatternContext::defineCmd
if (CmdlineDef[0] == '#') {
StringRef CmdlineName = CmdlineDef.substr(1, EqIdx - 1);
StringRef VarName;
- SMLoc CmdlineNameLoc = SMLoc::getFromPointer(CmdlineName.data());
Error ErrorDiagnostic = FileCheckPattern::parseNumericVariableDefinition(
CmdlineName, VarName, this, SM);
if (ErrorDiagnostic) {
Errs = joinErrors(std::move(Errs), std::move(ErrorDiagnostic));
continue;
}
- // Check that CmdlineName is only composed of the parsed numeric
- // variable. This catches cases like "FOO+2" in a "FOO+2=10" definition.
- if (!CmdlineName.empty()) {
- Errs = joinErrors(std::move(Errs),
- FileCheckErrorDiagnostic::get(
- SM, CmdlineNameLoc, "invalid variable name"));
- continue;
- }
-
- // Detect collisions between string and numeric variables when the latter
- // is created later than the former.
- if (DefinedVariableTable.find(VarName) != DefinedVariableTable.end()) {
- Errs = joinErrors(
- std::move(Errs),
- FileCheckErrorDiagnostic::get(SM, VarName,
- "string variable with name '" +
- VarName + "' already exists"));
- continue;
- }
StringRef CmdlineVal = CmdlineDef.substr(EqIdx + 1);
uint64_t Val;
Modified: llvm/trunk/test/FileCheck/numeric-defines-diagnostics.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/FileCheck/numeric-defines-diagnostics.txt?rev=365191&r1=365190&r2=365191&view=diff
==============================================================================
--- llvm/trunk/test/FileCheck/numeric-defines-diagnostics.txt (original)
+++ llvm/trunk/test/FileCheck/numeric-defines-diagnostics.txt Fri Jul 5 05:01:06 2019
@@ -20,9 +20,9 @@ NUMERRCLIPSEUDO-NEXT: {{^
RUN: not FileCheck -D#VALUE+2=10 --input-file %s %s 2>&1 \
RUN: | FileCheck %s --strict-whitespace --check-prefix NUMERRCLITRAIL
-NUMERRCLITRAIL: Global defines:1:20: error: invalid variable name
+NUMERRCLITRAIL: Global defines:1:25: error: unexpected characters after numeric variable name
NUMERRCLITRAIL-NEXT: Global define #1: #VALUE+2=10
-NUMERRCLITRAIL-NEXT: {{^ \^$}}
+NUMERRCLITRAIL-NEXT: {{^ \^$}}
; Invalid value: numeric expression instead of literal.
RUN: not FileCheck -D#VALUE1=3 -D#VALUE2='VALUE1 + 2' --input-file %s %s 2>&1 \
More information about the llvm-commits
mailing list