summaryrefslogtreecommitdiffstats
path: root/llvm/utils/FileCheck/FileCheck.cpp
diff options
context:
space:
mode:
authorArtem Belevich <tra@google.com>2017-03-09 17:59:04 +0000
committerArtem Belevich <tra@google.com>2017-03-09 17:59:04 +0000
commitf55e72a5a0a2473c2851c2b2c172d2ed53d15b1c (patch)
tree6f85dc5d420bcc6e186fd9ca4c583a43c081eb19 /llvm/utils/FileCheck/FileCheck.cpp
parenta9520b94d56ba857284a3de9ba717116f884bb26 (diff)
downloadbcm5719-llvm-f55e72a5a0a2473c2851c2b2c172d2ed53d15b1c.tar.gz
bcm5719-llvm-f55e72a5a0a2473c2851c2b2c172d2ed53d15b1c.zip
[FileCheck] Added --enable-var-scope option to enable scope for regex variables.
If `--enable-var-scope` is in effect, variables with names that start with `$` are considered to be global. All other variables are local. All local variables get undefined at the beginning of each CHECK-LABEL block. Global variables are not affected by CHECK-LABEL. This makes it easier to ensure that individual tests are not affected by variables set in preceding tests. Differential Revision: https://reviews.llvm.org/D30749 llvm-svn: 297396
Diffstat (limited to 'llvm/utils/FileCheck/FileCheck.cpp')
-rw-r--r--llvm/utils/FileCheck/FileCheck.cpp41
1 files changed, 33 insertions, 8 deletions
diff --git a/llvm/utils/FileCheck/FileCheck.cpp b/llvm/utils/FileCheck/FileCheck.cpp
index 9e177574625..da1267f027d 100644
--- a/llvm/utils/FileCheck/FileCheck.cpp
+++ b/llvm/utils/FileCheck/FileCheck.cpp
@@ -73,6 +73,12 @@ static cl::opt<bool> MatchFullLines(
"Allows leading and trailing whitespace if --strict-whitespace\n"
"is not also passed."));
+static cl::opt<bool> EnableVarScope(
+ "enable-var-scope", cl::init(false),
+ cl::desc("Enables scope for regex variables. Variables with names that\n"
+ "do not start with '$' will be reset at the beginning of\n"
+ "each CHECK-LABEL block."));
+
typedef cl::list<std::string>::const_iterator prefix_iterator;
//===----------------------------------------------------------------------===//
@@ -263,15 +269,19 @@ bool Pattern::ParsePattern(StringRef PatternStr, StringRef Prefix,
// is relaxed, more strict check is performed in \c EvaluateExpression.
bool IsExpression = false;
for (unsigned i = 0, e = Name.size(); i != e; ++i) {
- if (i == 0 && Name[i] == '@') {
- if (NameEnd != StringRef::npos) {
- SM.PrintMessage(SMLoc::getFromPointer(Name.data()),
- SourceMgr::DK_Error,
- "invalid name in named regex definition");
- return true;
+ if (i == 0) {
+ if (Name[i] == '$') // Global vars start with '$'
+ continue;
+ if (Name[i] == '@') {
+ if (NameEnd != StringRef::npos) {
+ SM.PrintMessage(SMLoc::getFromPointer(Name.data()),
+ SourceMgr::DK_Error,
+ "invalid name in named regex definition");
+ return true;
+ }
+ IsExpression = true;
+ continue;
}
- IsExpression = true;
- continue;
}
if (Name[i] != '_' && !isalnum(Name[i]) &&
(!IsExpression || (Name[i] != '+' && Name[i] != '-'))) {
@@ -1262,6 +1272,18 @@ static void DumpCommandLine(int argc, char **argv) {
errs() << "\n";
}
+// Remove local variables from \p VariableTable. Global variables
+// (start with '$') are preserved.
+static void ClearLocalVars(StringMap<StringRef> &VariableTable) {
+ SmallVector<StringRef, 16> LocalVars;
+ for (const auto &Var : VariableTable)
+ if (Var.first()[0] != '$')
+ LocalVars.push_back(Var.first());
+
+ for (const auto &Var : LocalVars)
+ VariableTable.erase(Var);
+}
+
/// Check the input to FileCheck provided in the \p Buffer against the \p
/// CheckStrings read from the check file.
///
@@ -1298,6 +1320,9 @@ bool CheckInput(SourceMgr &SM, StringRef Buffer,
++j;
}
+ if (EnableVarScope)
+ ClearLocalVars(VariableTable);
+
for (; i != j; ++i) {
const CheckString &CheckStr = CheckStrings[i];
OpenPOWER on IntegriCloud