diff --git a/llvm/lib/Support/FileCheck.cpp b/llvm/lib/Support/FileCheck.cpp --- a/llvm/lib/Support/FileCheck.cpp +++ b/llvm/lib/Support/FileCheck.cpp @@ -25,15 +25,15 @@ using namespace llvm; -Expected FileCheckNumericVariableUse::eval() const { - Optional Value = NumericVariable->getValue(); +Expected NumericVariableUse::eval() const { + Optional Value = Variable->getValue(); if (Value) return *Value; - return make_error(Name); + return make_error(Name); } -Expected FileCheckASTBinop::eval() const { +Expected BinaryOperation::eval() const { Expected LeftOp = LeftOperand->eval(); Expected RightOp = RightOperand->eval(); @@ -51,14 +51,14 @@ return EvalBinop(*LeftOp, *RightOp); } -Expected FileCheckNumericSubstitution::getResult() const { - Expected EvaluatedValue = ExpressionAST->eval(); +Expected NumericSubstitution::getResult() const { + Expected EvaluatedValue = ExpressionASTPointer->eval(); if (!EvaluatedValue) return EvaluatedValue.takeError(); return utostr(*EvaluatedValue); } -Expected FileCheckStringSubstitution::getResult() const { +Expected StringSubstitution::getResult() const { // Look up the value and escape it so that we can put it into the regex. Expected VarVal = Context->getPatternVarValue(FromStr); if (!VarVal) @@ -66,14 +66,12 @@ return Regex::escape(*VarVal); } -bool FileCheckPattern::isValidVarNameStart(char C) { - return C == '_' || isalpha(C); -} +bool Pattern::isValidVarNameStart(char C) { return C == '_' || isalpha(C); } -Expected -FileCheckPattern::parseVariable(StringRef &Str, const SourceMgr &SM) { +Expected +Pattern::parseVariable(StringRef &Str, const SourceMgr &SM) { if (Str.empty()) - return FileCheckErrorDiagnostic::get(SM, Str, "empty variable name"); + return ErrorDiagnostic::get(SM, Str, "empty variable name"); bool ParsedOneChar = false; unsigned I = 0; @@ -85,7 +83,7 @@ for (unsigned E = Str.size(); I != E; ++I) { if (!ParsedOneChar && !isValidVarNameStart(Str[I])) - return FileCheckErrorDiagnostic::get(SM, Str, "invalid variable name"); + return ErrorDiagnostic::get(SM, Str, "invalid variable name"); // Variable names are composed of alphanumeric characters and underscores. if (Str[I] != '_' && !isalnum(Str[I])) @@ -109,12 +107,11 @@ return C; } -char FileCheckUndefVarError::ID = 0; -char FileCheckErrorDiagnostic::ID = 0; -char FileCheckNotFoundError::ID = 0; +char UndefVarError::ID = 0; +char ErrorDiagnostic::ID = 0; +char NotFoundError::ID = 0; -Expected -FileCheckPattern::parseNumericVariableDefinition( +Expected Pattern::parseNumericVariableDefinition( StringRef &Expr, FileCheckPatternContext *Context, Optional LineNumber, const SourceMgr &SM) { Expected ParseVarResult = parseVariable(Expr, SM); @@ -123,22 +120,22 @@ StringRef Name = ParseVarResult->Name; if (ParseVarResult->IsPseudo) - return FileCheckErrorDiagnostic::get( + return ErrorDiagnostic::get( SM, Name, "definition of pseudo numeric variable unsupported"); // Detect collisions between string and numeric variables when the latter // is created later than the former. if (Context->DefinedVariableTable.find(Name) != Context->DefinedVariableTable.end()) - return FileCheckErrorDiagnostic::get( + return ErrorDiagnostic::get( SM, Name, "string variable with name '" + Name + "' already exists"); Expr = Expr.ltrim(SpaceChars); if (!Expr.empty()) - return FileCheckErrorDiagnostic::get( + return ErrorDiagnostic::get( SM, Expr, "unexpected characters after numeric variable name"); - FileCheckNumericVariable *DefinedNumericVariable; + NumericVariable *DefinedNumericVariable; auto VarTableIter = Context->GlobalNumericVariableTable.find(Name); if (VarTableIter != Context->GlobalNumericVariableTable.end()) DefinedNumericVariable = VarTableIter->second; @@ -148,13 +145,11 @@ return DefinedNumericVariable; } -Expected> -FileCheckPattern::parseNumericVariableUse(StringRef Name, bool IsPseudo, - Optional LineNumber, - FileCheckPatternContext *Context, - const SourceMgr &SM) { +Expected> Pattern::parseNumericVariableUse( + StringRef Name, bool IsPseudo, Optional LineNumber, + FileCheckPatternContext *Context, const SourceMgr &SM) { if (IsPseudo && !Name.equals("@LINE")) - return FileCheckErrorDiagnostic::get( + return ErrorDiagnostic::get( SM, Name, "invalid pseudo numeric variable '" + Name + "'"); // Numeric variable definitions and uses are parsed in the order in which @@ -166,7 +161,7 @@ // uses of undefined variables, whether string or numeric, are then diagnosed // in printSubstitutions() after failing to match. auto VarTableIter = Context->GlobalNumericVariableTable.find(Name); - FileCheckNumericVariable *NumericVariable; + NumericVariable *NumericVariable; if (VarTableIter != Context->GlobalNumericVariableTable.end()) NumericVariable = VarTableIter->second; else { @@ -176,22 +171,20 @@ Optional DefLineNumber = NumericVariable->getDefLineNumber(); if (DefLineNumber && LineNumber && *DefLineNumber == *LineNumber) - return FileCheckErrorDiagnostic::get( + return ErrorDiagnostic::get( SM, Name, "numeric variable '" + Name + "' defined earlier in the same CHECK directive"); - return std::make_unique(Name, NumericVariable); + return std::make_unique(Name, NumericVariable); } -Expected> -FileCheckPattern::parseNumericOperand(StringRef &Expr, AllowedOperand AO, - Optional LineNumber, - FileCheckPatternContext *Context, - const SourceMgr &SM) { +Expected> Pattern::parseNumericOperand( + StringRef &Expr, AllowedOperand AO, Optional LineNumber, + FileCheckPatternContext *Context, const SourceMgr &SM) { if (AO == AllowedOperand::LineVar || AO == AllowedOperand::Any) { // Try to parse as a numeric variable use. - Expected ParseVarResult = + Expected ParseVarResult = parseVariable(Expr, SM); if (ParseVarResult) return parseNumericVariableUse(ParseVarResult->Name, @@ -206,10 +199,10 @@ // Otherwise, parse it as a literal. uint64_t LiteralValue; if (!Expr.consumeInteger(/*Radix=*/10, LiteralValue)) - return std::make_unique(LiteralValue); + return std::make_unique(LiteralValue); - return FileCheckErrorDiagnostic::get(SM, Expr, - "invalid operand format '" + Expr + "'"); + return ErrorDiagnostic::get(SM, Expr, + "invalid operand format '" + Expr + "'"); } static uint64_t add(uint64_t LeftOp, uint64_t RightOp) { @@ -220,10 +213,10 @@ return LeftOp - RightOp; } -Expected> FileCheckPattern::parseBinop( - StringRef &Expr, std::unique_ptr LeftOp, - bool IsLegacyLineExpr, Optional LineNumber, - FileCheckPatternContext *Context, const SourceMgr &SM) { +Expected> +Pattern::parseBinop(StringRef &Expr, std::unique_ptr LeftOp, + bool IsLegacyLineExpr, Optional LineNumber, + FileCheckPatternContext *Context, const SourceMgr &SM) { Expr = Expr.ltrim(SpaceChars); if (Expr.empty()) return std::move(LeftOp); @@ -241,35 +234,32 @@ EvalBinop = sub; break; default: - return FileCheckErrorDiagnostic::get( + return ErrorDiagnostic::get( SM, OpLoc, Twine("unsupported operation '") + Twine(Operator) + "'"); } // Parse right operand. Expr = Expr.ltrim(SpaceChars); if (Expr.empty()) - return FileCheckErrorDiagnostic::get(SM, Expr, - "missing operand in expression"); + return ErrorDiagnostic::get(SM, Expr, "missing operand in expression"); // The second operand in a legacy @LINE expression is always a literal. AllowedOperand AO = IsLegacyLineExpr ? AllowedOperand::Literal : AllowedOperand::Any; - Expected> RightOpResult = + Expected> RightOpResult = parseNumericOperand(Expr, AO, LineNumber, Context, SM); if (!RightOpResult) return RightOpResult; Expr = Expr.ltrim(SpaceChars); - return std::make_unique(EvalBinop, std::move(LeftOp), - std::move(*RightOpResult)); + return std::make_unique(EvalBinop, std::move(LeftOp), + std::move(*RightOpResult)); } -Expected> -FileCheckPattern::parseNumericSubstitutionBlock( - StringRef Expr, - Optional &DefinedNumericVariable, +Expected> Pattern::parseNumericSubstitutionBlock( + StringRef Expr, Optional &DefinedNumericVariable, bool IsLegacyLineExpr, Optional LineNumber, FileCheckPatternContext *Context, const SourceMgr &SM) { - std::unique_ptr ExpressionAST = nullptr; + std::unique_ptr ExpressionASTPointer = nullptr; StringRef DefExpr = StringRef(); DefinedNumericVariable = None; // Save variable definition expression if any. @@ -286,26 +276,26 @@ // pseudo variable. AllowedOperand AO = IsLegacyLineExpr ? AllowedOperand::LineVar : AllowedOperand::Any; - Expected> ParseResult = + Expected> ParseResult = parseNumericOperand(Expr, AO, LineNumber, Context, SM); while (ParseResult && !Expr.empty()) { ParseResult = parseBinop(Expr, std::move(*ParseResult), IsLegacyLineExpr, LineNumber, Context, SM); // Legacy @LINE expressions only allow 2 operands. if (ParseResult && IsLegacyLineExpr && !Expr.empty()) - return FileCheckErrorDiagnostic::get( + return ErrorDiagnostic::get( SM, Expr, "unexpected characters at end of expression '" + Expr + "'"); } if (!ParseResult) return ParseResult; - ExpressionAST = std::move(*ParseResult); + ExpressionASTPointer = std::move(*ParseResult); } // Parse the numeric variable definition. if (DefEnd != StringRef::npos) { DefExpr = DefExpr.ltrim(SpaceChars); - Expected ParseResult = + Expected ParseResult = parseNumericVariableDefinition(DefExpr, Context, LineNumber, SM); if (!ParseResult) @@ -313,12 +303,11 @@ DefinedNumericVariable = *ParseResult; } - return std::move(ExpressionAST); + return std::move(ExpressionASTPointer); } -bool FileCheckPattern::parsePattern(StringRef PatternStr, StringRef Prefix, - SourceMgr &SM, - const FileCheckRequest &Req) { +bool Pattern::parsePattern(StringRef PatternStr, StringRef Prefix, + SourceMgr &SM, const FileCheckRequest &Req) { bool MatchFullLinesHere = Req.MatchFullLines && CheckTy != Check::CheckNot; IgnoreCase = Req.IgnoreCase; @@ -447,7 +436,7 @@ // Get the name (e.g. "foo") and verify it is well formed. StringRef OrigMatchStr = MatchStr; - Expected ParseVarResult = + Expected ParseVarResult = parseVariable(MatchStr, SM); if (!ParseVarResult) { logAllUnhandledErrors(ParseVarResult.takeError(), errs()); @@ -487,10 +476,10 @@ } // Parse numeric substitution block. - std::unique_ptr ExpressionAST; - Optional DefinedNumericVariable; + std::unique_ptr ExpressionASTPointer; + Optional DefinedNumericVariable; if (IsNumBlock) { - Expected> ParseResult = + Expected> ParseResult = parseNumericSubstitutionBlock(MatchStr, DefinedNumericVariable, IsLegacyLineExpr, LineNumber, Context, SM); @@ -498,8 +487,8 @@ logAllUnhandledErrors(ParseResult.takeError(), errs()); return true; } - ExpressionAST = std::move(*ParseResult); - SubstNeeded = ExpressionAST != nullptr; + ExpressionASTPointer = std::move(*ParseResult); + SubstNeeded = ExpressionASTPointer != nullptr; if (DefinedNumericVariable) { IsDefinition = true; DefName = (*DefinedNumericVariable)->getName(); @@ -516,7 +505,7 @@ ++SubstInsertIdx; if (IsNumBlock) { - FileCheckNumericVariableMatch NumericVariableDefinition = { + NumericVariableMatch NumericVariableDefinition = { *DefinedNumericVariable, CurParen}; NumericVariableDefs[DefName] = NumericVariableDefinition; // This store is done here rather than in match() to allow @@ -562,10 +551,11 @@ } else { // Handle substitution of string variables ([[]]) defined in // previous CHECK patterns, and substitution of expressions. - FileCheckSubstitution *Substitution = + Substitution *Substitution = IsNumBlock ? Context->makeNumericSubstitution( - SubstStr, std::move(ExpressionAST), SubstInsertIdx) + SubstStr, std::move(ExpressionASTPointer), + SubstInsertIdx) : Context->makeStringSubstitution(SubstStr, SubstInsertIdx); Substitutions.push_back(Substitution); } @@ -589,7 +579,7 @@ return false; } -bool FileCheckPattern::AddRegExToRegEx(StringRef RS, unsigned &CurParen, SourceMgr &SM) { +bool Pattern::AddRegExToRegEx(StringRef RS, unsigned &CurParen, SourceMgr &SM) { Regex R(RS); std::string Error; if (!R.isValid(Error)) { @@ -603,14 +593,14 @@ return false; } -void FileCheckPattern::AddBackrefToRegEx(unsigned BackrefNum) { +void Pattern::AddBackrefToRegEx(unsigned BackrefNum) { assert(BackrefNum >= 1 && BackrefNum <= 9 && "Invalid backref number"); std::string Backref = std::string("\\") + std::string(1, '0' + BackrefNum); RegExStr += Backref; } -Expected FileCheckPattern::match(StringRef Buffer, size_t &MatchLen, - const SourceMgr &SM) const { +Expected Pattern::match(StringRef Buffer, size_t &MatchLen, + const SourceMgr &SM) const { // If this is the EOF pattern, match it immediately. if (CheckTy == Check::CheckEOF) { MatchLen = 0; @@ -620,10 +610,10 @@ // If this is a fixed string pattern, just match it now. if (!FixedStr.empty()) { MatchLen = FixedStr.size(); - size_t Pos = IgnoreCase ? Buffer.find_lower(FixedStr) - : Buffer.find(FixedStr); + size_t Pos = + IgnoreCase ? Buffer.find_lower(FixedStr) : Buffer.find(FixedStr); if (Pos == StringRef::npos) - return make_error(); + return make_error(); return Pos; } @@ -663,7 +653,7 @@ if (IgnoreCase) Flags |= Regex::IgnoreCase; if (!Regex(RegExToMatch, Flags).match(Buffer, &MatchInfo)) - return make_error(); + return make_error(); // Successful regex match. assert(!MatchInfo.empty() && "Didn't get any match"); @@ -678,18 +668,18 @@ // If this defines any numeric variables, remember their values. for (const auto &NumericVariableDef : NumericVariableDefs) { - const FileCheckNumericVariableMatch &NumericVariableMatch = + const NumericVariableMatch &NumericVariableMatch = NumericVariableDef.getValue(); unsigned CaptureParenGroup = NumericVariableMatch.CaptureParenGroup; assert(CaptureParenGroup < MatchInfo.size() && "Internal paren error"); - FileCheckNumericVariable *DefinedNumericVariable = + NumericVariable *DefinedNumericVariable = NumericVariableMatch.DefinedNumericVariable; StringRef MatchedValue = MatchInfo[CaptureParenGroup]; uint64_t Val; if (MatchedValue.getAsInteger(10, Val)) - return FileCheckErrorDiagnostic::get(SM, MatchedValue, - "Unable to represent numeric value"); + return ErrorDiagnostic::get(SM, MatchedValue, + "Unable to represent numeric value"); DefinedNumericVariable->setValue(Val); } @@ -701,7 +691,7 @@ return FullMatch.data() - Buffer.data() + MatchStartSkip; } -unsigned FileCheckPattern::computeMatchDistance(StringRef Buffer) const { +unsigned Pattern::computeMatchDistance(StringRef Buffer) const { // Just compute the number of matching characters. For regular expressions, we // just compare against the regex itself and hope for the best. // @@ -718,8 +708,8 @@ return BufferPrefix.edit_distance(ExampleString); } -void FileCheckPattern::printSubstitutions(const SourceMgr &SM, StringRef Buffer, - SMRange MatchRange) const { +void Pattern::printSubstitutions(const SourceMgr &SM, StringRef Buffer, + SMRange MatchRange) const { // Print what we know about substitutions. if (!Substitutions.empty()) { for (const auto &Substitution : Substitutions) { @@ -731,11 +721,10 @@ // variables it uses. if (!MatchedValue) { bool UndefSeen = false; - handleAllErrors(MatchedValue.takeError(), - [](const FileCheckNotFoundError &E) {}, + handleAllErrors(MatchedValue.takeError(), [](const NotFoundError &E) {}, // Handled in PrintNoMatch(). - [](const FileCheckErrorDiagnostic &E) {}, - [&](const FileCheckUndefVarError &E) { + [](const ErrorDiagnostic &E) {}, + [&](const UndefVarError &E) { if (!UndefSeen) { OS << "uses undefined variable(s):"; UndefSeen = true; @@ -778,9 +767,8 @@ return Range; } -void FileCheckPattern::printFuzzyMatch( - const SourceMgr &SM, StringRef Buffer, - std::vector *Diags) const { +void Pattern::printFuzzyMatch(const SourceMgr &SM, StringRef Buffer, + std::vector *Diags) const { // Attempt to find the closest/best fuzzy match. Usually an error happens // because some string in the output didn't exactly match. In these cases, we // would like to show the user a best guess at what "should have" matched, to @@ -829,36 +817,34 @@ FileCheckPatternContext::getPatternVarValue(StringRef VarName) { auto VarIter = GlobalVariableTable.find(VarName); if (VarIter == GlobalVariableTable.end()) - return make_error(VarName); + return make_error(VarName); return VarIter->second; } template -FileCheckNumericVariable * -FileCheckPatternContext::makeNumericVariable(Types... args) { - NumericVariables.push_back( - std::make_unique(args...)); +NumericVariable *FileCheckPatternContext::makeNumericVariable(Types... args) { + NumericVariables.push_back(std::make_unique(args...)); return NumericVariables.back().get(); } -FileCheckSubstitution * +Substitution * FileCheckPatternContext::makeStringSubstitution(StringRef VarName, size_t InsertIdx) { Substitutions.push_back( - std::make_unique(this, VarName, InsertIdx)); + std::make_unique(this, VarName, InsertIdx)); return Substitutions.back().get(); } -FileCheckSubstitution *FileCheckPatternContext::makeNumericSubstitution( +Substitution *FileCheckPatternContext::makeNumericSubstitution( StringRef ExpressionStr, - std::unique_ptr ExpressionAST, size_t InsertIdx) { - Substitutions.push_back(std::make_unique( - this, ExpressionStr, std::move(ExpressionAST), InsertIdx)); + std::unique_ptr ExpressionASTPointer, size_t InsertIdx) { + Substitutions.push_back(std::make_unique( + this, ExpressionStr, std::move(ExpressionASTPointer), InsertIdx)); return Substitutions.back().get(); } -size_t FileCheckPattern::FindRegexVarEnd(StringRef Str, SourceMgr &SM) { +size_t Pattern::FindRegexVarEnd(StringRef Str, SourceMgr &SM) { // Offset keeps track of the current offset within the input Str size_t Offset = 0; // [...] Nesting depth @@ -1139,7 +1125,7 @@ PatternContext->createLineVariable(); - std::vector ImplicitNegativeChecks; + std::vector ImplicitNegativeChecks; for (const auto &PatternString : Req.ImplicitCheckNot) { // Create a buffer with fake command line content in order to display the // command line option responsible for the specific implicit CHECK-NOT. @@ -1153,12 +1139,12 @@ SM.AddNewSourceBuffer(std::move(CmdLine), SMLoc()); ImplicitNegativeChecks.push_back( - FileCheckPattern(Check::CheckNot, PatternContext.get())); + Pattern(Check::CheckNot, PatternContext.get())); ImplicitNegativeChecks.back().parsePattern(PatternInBuffer, "IMPLICIT-CHECK", SM, Req); } - std::vector DagNotMatches = ImplicitNegativeChecks; + std::vector DagNotMatches = ImplicitNegativeChecks; // LineNumber keeps track of the line on which CheckPrefix instances are // found. @@ -1216,7 +1202,7 @@ SMLoc PatternLoc = SMLoc::getFromPointer(Buffer.data()); // Parse the pattern. - FileCheckPattern P(CheckTy, PatternContext.get(), LineNumber); + Pattern P(CheckTy, PatternContext.get(), LineNumber); if (P.parsePattern(Buffer.substr(0, EOL), UsedPrefix, SM, Req)) return true; @@ -1261,7 +1247,7 @@ // prefix as a filler for the error message. if (!DagNotMatches.empty()) { CheckStrings->emplace_back( - FileCheckPattern(Check::CheckEOF, PatternContext.get(), LineNumber + 1), + Pattern(Check::CheckEOF, PatternContext.get(), LineNumber + 1), *Req.CheckPrefixes.begin(), SMLoc::getFromPointer(Buffer.data())); std::swap(DagNotMatches, CheckStrings->back().DagNotStrings); } @@ -1286,7 +1272,7 @@ } static void PrintMatch(bool ExpectedMatch, const SourceMgr &SM, - StringRef Prefix, SMLoc Loc, const FileCheckPattern &Pat, + StringRef Prefix, SMLoc Loc, const Pattern &Pat, int MatchedCount, StringRef Buffer, size_t MatchPos, size_t MatchLen, const FileCheckRequest &Req, std::vector *Diags) { @@ -1332,10 +1318,10 @@ } static void PrintNoMatch(bool ExpectedMatch, const SourceMgr &SM, - StringRef Prefix, SMLoc Loc, - const FileCheckPattern &Pat, int MatchedCount, - StringRef Buffer, bool VerboseVerbose, - std::vector *Diags, Error MatchErrors) { + StringRef Prefix, SMLoc Loc, const Pattern &Pat, + int MatchedCount, StringRef Buffer, + bool VerboseVerbose, std::vector *Diags, + Error MatchErrors) { assert(MatchErrors && "Called on successful match"); bool PrintDiag = true; if (!ExpectedMatch) { @@ -1361,9 +1347,8 @@ return; } - MatchErrors = - handleErrors(std::move(MatchErrors), - [](const FileCheckErrorDiagnostic &E) { E.log(errs()); }); + MatchErrors = handleErrors(std::move(MatchErrors), + [](const ErrorDiagnostic &E) { E.log(errs()); }); // No problem matching the string per se. if (!MatchErrors) @@ -1427,7 +1412,7 @@ FileCheckRequest &Req, std::vector *Diags) const { size_t LastPos = 0; - std::vector NotStrings; + std::vector NotStrings; // IsLabelScanMode is true when we are scanning forward to find CHECK-LABEL // bounds; we have not processed variable definitions within the bounded block @@ -1565,11 +1550,11 @@ return false; } -bool FileCheckString::CheckNot( - const SourceMgr &SM, StringRef Buffer, - const std::vector &NotStrings, - const FileCheckRequest &Req, std::vector *Diags) const { - for (const FileCheckPattern *Pat : NotStrings) { +bool FileCheckString::CheckNot(const SourceMgr &SM, StringRef Buffer, + const std::vector &NotStrings, + const FileCheckRequest &Req, + std::vector *Diags) const { + for (const Pattern *Pat : NotStrings) { assert((Pat->getCheckTy() == Check::CheckNot) && "Expect CHECK-NOT!"); size_t MatchLen = 0; @@ -1591,11 +1576,10 @@ return false; } -size_t -FileCheckString::CheckDag(const SourceMgr &SM, StringRef Buffer, - std::vector &NotStrings, - const FileCheckRequest &Req, - std::vector *Diags) const { +size_t FileCheckString::CheckDag(const SourceMgr &SM, StringRef Buffer, + std::vector &NotStrings, + const FileCheckRequest &Req, + std::vector *Diags) const { if (DagNotStrings.empty()) return 0; @@ -1615,7 +1599,7 @@ // group, so we don't use a range-based for loop here. for (auto PatItr = DagNotStrings.begin(), PatEnd = DagNotStrings.end(); PatItr != PatEnd; ++PatItr) { - const FileCheckPattern &Pat = *PatItr; + const Pattern &Pat = *PatItr; assert((Pat.getCheckTy() == Check::CheckDAG || Pat.getCheckTy() == Check::CheckNot) && "Invalid CHECK-DAG or CHECK-NOT!"); @@ -1820,8 +1804,8 @@ if (CmdlineDef.empty()) { Errs = joinErrors( std::move(Errs), - FileCheckErrorDiagnostic::get( - SM, CmdlineDef, "missing equal sign in global definition")); + ErrorDiagnostic::get(SM, CmdlineDef, + "missing equal sign in global definition")); continue; } @@ -1830,21 +1814,21 @@ // Now parse the definition both to check that the syntax is correct and // to create the necessary class instance. StringRef CmdlineDefExpr = CmdlineDef.substr(1); - Optional DefinedNumericVariable; - Expected> ExpressionASTResult = - FileCheckPattern::parseNumericSubstitutionBlock( + Optional DefinedNumericVariable; + Expected> ExpressionASTResult = + Pattern::parseNumericSubstitutionBlock( CmdlineDefExpr, DefinedNumericVariable, false, None, this, SM); if (!ExpressionASTResult) { Errs = joinErrors(std::move(Errs), ExpressionASTResult.takeError()); continue; } - std::unique_ptr ExpressionAST = + std::unique_ptr ExpressionASTPointer = std::move(*ExpressionASTResult); // Now evaluate the expression whose value this variable should be set // to, since the expression of a command-line variable definition should // only use variables defined earlier on the command-line. If not, this // is an error and we report it. - Expected Value = ExpressionAST->eval(); + Expected Value = ExpressionASTPointer->eval(); if (!Value) { Errs = joinErrors(std::move(Errs), Value.takeError()); continue; @@ -1861,8 +1845,8 @@ std::pair CmdlineNameVal = CmdlineDef.split('='); StringRef CmdlineName = CmdlineNameVal.first; StringRef OrigCmdlineName = CmdlineName; - Expected ParseVarResult = - FileCheckPattern::parseVariable(CmdlineName, SM); + Expected ParseVarResult = + Pattern::parseVariable(CmdlineName, SM); if (!ParseVarResult) { Errs = joinErrors(std::move(Errs), ParseVarResult.takeError()); continue; @@ -1872,7 +1856,7 @@ // "FOO+2" in a "FOO+2=10" definition. if (ParseVarResult->IsPseudo || !CmdlineName.empty()) { Errs = joinErrors(std::move(Errs), - FileCheckErrorDiagnostic::get( + ErrorDiagnostic::get( SM, OrigCmdlineName, "invalid name in string variable definition '" + OrigCmdlineName + "'")); @@ -1884,8 +1868,8 @@ // is created later than the latter. if (GlobalNumericVariableTable.find(Name) != GlobalNumericVariableTable.end()) { - Errs = joinErrors(std::move(Errs), FileCheckErrorDiagnostic::get( - SM, Name, + Errs = joinErrors(std::move(Errs), + ErrorDiagnostic::get(SM, Name, "numeric variable with name '" + Name + "' already exists")); continue; diff --git a/llvm/lib/Support/FileCheckImpl.h b/llvm/lib/Support/FileCheckImpl.h --- a/llvm/lib/Support/FileCheckImpl.h +++ b/llvm/lib/Support/FileCheckImpl.h @@ -31,9 +31,9 @@ //===----------------------------------------------------------------------===// /// Base class representing the AST of a given expression. -class FileCheckExpressionAST { +class ExpressionAST { public: - virtual ~FileCheckExpressionAST() = default; + virtual ~ExpressionAST() = default; /// Evaluates and \returns the value of the expression represented by this /// AST or an error if evaluation fails. @@ -41,14 +41,14 @@ }; /// Class representing an unsigned literal in the AST of an expression. -class FileCheckExpressionLiteral : public FileCheckExpressionAST { +class ExpressionLiteral : public ExpressionAST { private: /// Actual value of the literal. uint64_t Value; public: /// Constructs a literal with the specified value. - FileCheckExpressionLiteral(uint64_t Val) : Value(Val) {} + ExpressionLiteral(uint64_t Val) : Value(Val) {} /// \returns the literal's value. Expected eval() const override { return Value; } @@ -56,14 +56,14 @@ /// Class to represent an undefined variable error, which quotes that /// variable's name when printed. -class FileCheckUndefVarError : public ErrorInfo { +class UndefVarError : public ErrorInfo { private: StringRef VarName; public: static char ID; - FileCheckUndefVarError(StringRef VarName) : VarName(VarName) {} + UndefVarError(StringRef VarName) : VarName(VarName) {} StringRef getVarName() const { return VarName; } @@ -79,7 +79,7 @@ }; /// Class representing a numeric variable and its associated current value. -class FileCheckNumericVariable { +class NumericVariable { private: /// Name of the numeric variable. StringRef Name; @@ -95,8 +95,8 @@ public: /// Constructor for a variable \p Name defined at line \p DefLineNumber or /// defined before input is parsed if \p DefLineNumber is None. - explicit FileCheckNumericVariable(StringRef Name, - Optional DefLineNumber = None) + explicit NumericVariable(StringRef Name, + Optional DefLineNumber = None) : Name(Name), DefLineNumber(DefLineNumber) {} /// \returns name of this numeric variable. @@ -119,18 +119,17 @@ /// Class representing the use of a numeric variable in the AST of an /// expression. -class FileCheckNumericVariableUse : public FileCheckExpressionAST { +class NumericVariableUse : public ExpressionAST { private: /// Name of the numeric variable. StringRef Name; /// Pointer to the class instance for the variable this use is about. - FileCheckNumericVariable *NumericVariable; + NumericVariable *Variable; public: - FileCheckNumericVariableUse(StringRef Name, - FileCheckNumericVariable *NumericVariable) - : Name(Name), NumericVariable(NumericVariable) {} + NumericVariableUse(StringRef Name, NumericVariable *Variable) + : Name(Name), Variable(Variable) {} /// \returns the value of the variable referenced by this instance. Expected eval() const override; @@ -140,21 +139,20 @@ using binop_eval_t = uint64_t (*)(uint64_t, uint64_t); /// Class representing a single binary operation in the AST of an expression. -class FileCheckASTBinop : public FileCheckExpressionAST { +class BinaryOperation : public ExpressionAST { private: /// Left operand. - std::unique_ptr LeftOperand; + std::unique_ptr LeftOperand; /// Right operand. - std::unique_ptr RightOperand; + std::unique_ptr RightOperand; /// Pointer to function that can evaluate this binary operation. binop_eval_t EvalBinop; public: - FileCheckASTBinop(binop_eval_t EvalBinop, - std::unique_ptr LeftOp, - std::unique_ptr RightOp) + BinaryOperation(binop_eval_t EvalBinop, std::unique_ptr LeftOp, + std::unique_ptr RightOp) : EvalBinop(EvalBinop) { LeftOperand = std::move(LeftOp); RightOperand = std::move(RightOp); @@ -170,7 +168,7 @@ class FileCheckPatternContext; /// Class representing a substitution to perform in the RegExStr string. -class FileCheckSubstitution { +class Substitution { protected: /// Pointer to a class instance holding, among other things, the table with /// the values of live string variables at the start of any given CHECK line. @@ -188,11 +186,11 @@ size_t InsertIdx; public: - FileCheckSubstitution(FileCheckPatternContext *Context, StringRef VarName, - size_t InsertIdx) + Substitution(FileCheckPatternContext *Context, StringRef VarName, + size_t InsertIdx) : Context(Context), FromStr(VarName), InsertIdx(InsertIdx) {} - virtual ~FileCheckSubstitution() = default; + virtual ~Substitution() = default; /// \returns the string to be substituted for something else. StringRef getFromString() const { return FromStr; } @@ -205,29 +203,28 @@ virtual Expected getResult() const = 0; }; -class FileCheckStringSubstitution : public FileCheckSubstitution { +class StringSubstitution : public Substitution { public: - FileCheckStringSubstitution(FileCheckPatternContext *Context, - StringRef VarName, size_t InsertIdx) - : FileCheckSubstitution(Context, VarName, InsertIdx) {} + StringSubstitution(FileCheckPatternContext *Context, StringRef VarName, + size_t InsertIdx) + : Substitution(Context, VarName, InsertIdx) {} /// \returns the text that the string variable in this substitution matched /// when defined, or an error if the variable is undefined. Expected getResult() const override; }; -class FileCheckNumericSubstitution : public FileCheckSubstitution { +class NumericSubstitution : public Substitution { private: /// Pointer to the class representing the expression whose value is to be /// substituted. - std::unique_ptr ExpressionAST; + std::unique_ptr ExpressionASTPointer; public: - FileCheckNumericSubstitution(FileCheckPatternContext *Context, StringRef Expr, - std::unique_ptr ExprAST, - size_t InsertIdx) - : FileCheckSubstitution(Context, Expr, InsertIdx) { - ExpressionAST = std::move(ExprAST); + NumericSubstitution(FileCheckPatternContext *Context, StringRef Expr, + std::unique_ptr ExprAST, size_t InsertIdx) + : Substitution(Context, Expr, InsertIdx) { + ExpressionASTPointer = std::move(ExprAST); } /// \returns a string containing the result of evaluating the expression in @@ -241,11 +238,11 @@ struct FileCheckDiag; -/// Class holding the FileCheckPattern global state, shared by all patterns: -/// tables holding values of variables and whether they are defined or not at -/// any given time in the matching process. +/// Class holding the Pattern global state, shared by all patterns: tables +/// holding values of variables and whether they are defined or not at any +/// given time in the matching process. class FileCheckPatternContext { - friend class FileCheckPattern; + friend class Pattern; private: /// When matching a given pattern, this holds the value of all the string @@ -262,21 +259,20 @@ /// When matching a given pattern, this holds the pointers to the classes /// representing the numeric variables defined in previous patterns. When /// matching a pattern all definitions for that pattern are recorded in the - /// NumericVariableDefs table in the FileCheckPattern instance of that - /// pattern. - StringMap GlobalNumericVariableTable; + /// NumericVariableDefs table in the Pattern instance of that pattern. + StringMap GlobalNumericVariableTable; /// Pointer to the class instance representing the @LINE pseudo variable for /// easily updating its value. - FileCheckNumericVariable *LineVariable = nullptr; + NumericVariable *LineVariable = nullptr; /// Vector holding pointers to all parsed numeric variables. Used to /// automatically free them once they are guaranteed to no longer be used. - std::vector> NumericVariables; + std::vector> NumericVariables; /// Vector holding pointers to all substitutions. Used to automatically free /// them once they are guaranteed to no longer be used. - std::vector> Substitutions; + std::vector> Substitutions; public: /// \returns the value of string variable \p VarName or an error if no such @@ -303,32 +299,30 @@ private: /// Makes a new numeric variable and registers it for destruction when the /// context is destroyed. - template - FileCheckNumericVariable *makeNumericVariable(Types... args); + template NumericVariable *makeNumericVariable(Types... args); /// Makes a new string substitution and registers it for destruction when the /// context is destroyed. - FileCheckSubstitution *makeStringSubstitution(StringRef VarName, - size_t InsertIdx); + Substitution *makeStringSubstitution(StringRef VarName, size_t InsertIdx); /// Makes a new numeric substitution and registers it for destruction when /// the context is destroyed. - FileCheckSubstitution * + Substitution * makeNumericSubstitution(StringRef ExpressionStr, - std::unique_ptr ExpressionAST, + std::unique_ptr ExpressionAST, size_t InsertIdx); }; /// Class to represent an error holding a diagnostic with location information /// used when printing it. -class FileCheckErrorDiagnostic : public ErrorInfo { +class ErrorDiagnostic : public ErrorInfo { private: SMDiagnostic Diagnostic; public: static char ID; - FileCheckErrorDiagnostic(SMDiagnostic &&Diag) : Diagnostic(Diag) {} + ErrorDiagnostic(SMDiagnostic &&Diag) : Diagnostic(Diag) {} std::error_code convertToErrorCode() const override { return inconvertibleErrorCode(); @@ -338,7 +332,7 @@ void log(raw_ostream &OS) const override { Diagnostic.print(nullptr, OS); } static Error get(const SourceMgr &SM, SMLoc Loc, const Twine &ErrMsg) { - return make_error( + return make_error( SM.GetMessage(Loc, SourceMgr::DK_Error, ErrMsg)); } @@ -347,7 +341,7 @@ } }; -class FileCheckNotFoundError : public ErrorInfo { +class NotFoundError : public ErrorInfo { public: static char ID; @@ -361,7 +355,7 @@ } }; -class FileCheckPattern { +class Pattern { SMLoc PatternLoc; /// A fixed string to match as the pattern or empty if this pattern requires @@ -378,7 +372,7 @@ /// RegExStr will contain "foobaz" and we'll get two entries in this vector /// that tells us to insert the value of string variable "bar" at offset 3 /// and the value of expression "N+1" at offset 6. - std::vector Substitutions; + std::vector Substitutions; /// Maps names of string variables defined in a pattern to the number of /// their parenthesis group in RegExStr capturing their last definition. @@ -397,10 +391,10 @@ /// It holds the pointer to the class representing the numeric variable whose /// value is being defined and the number of the parenthesis group in /// RegExStr to capture that value. - struct FileCheckNumericVariableMatch { + struct NumericVariableMatch { /// Pointer to class representing the numeric variable whose value is being /// defined. - FileCheckNumericVariable *DefinedNumericVariable; + NumericVariable *DefinedNumericVariable; /// Number of the parenthesis group in RegExStr that captures the value of /// this numeric variable definition. @@ -408,10 +402,9 @@ }; /// Holds the number of the parenthesis group in RegExStr and pointer to the - /// corresponding FileCheckNumericVariable class instance of all numeric - /// variable definitions. Used to set the matched value of all those - /// variables. - StringMap NumericVariableDefs; + /// corresponding NumericVariable class instance of all numeric variable + /// definitions. Used to set the matched value of all those variables. + StringMap NumericVariableDefs; /// Pointer to a class instance holding the global state shared by all /// patterns: @@ -432,8 +425,8 @@ bool IgnoreCase = false; public: - FileCheckPattern(Check::FileCheckType Ty, FileCheckPatternContext *Context, - Optional Line = None) + Pattern(Check::FileCheckType Ty, FileCheckPatternContext *Context, + Optional Line = None) : Context(Context), CheckTy(Ty), LineNumber(Line) {} /// \returns the location in source code. @@ -469,14 +462,12 @@ /// substitution was successful, sets \p DefinedNumericVariable to point to /// the class representing the numeric variable defined in this numeric /// substitution block, or None if this block does not define any variable. - static Expected> - parseNumericSubstitutionBlock( - StringRef Expr, - Optional &DefinedNumericVariable, + static Expected> parseNumericSubstitutionBlock( + StringRef Expr, Optional &DefinedNumericVariable, bool IsLegacyLineExpr, Optional LineNumber, FileCheckPatternContext *Context, const SourceMgr &SM); - /// Parses the pattern in \p PatternStr and initializes this FileCheckPattern - /// instance accordingly. + /// Parses the pattern in \p PatternStr and initializes this Pattern instance + /// accordingly. /// /// \p Prefix provides which prefix is being matched, \p Req describes the /// global options that influence the parsing such as whitespace @@ -491,8 +482,8 @@ /// matched string. /// /// The GlobalVariableTable StringMap in the FileCheckPatternContext class - /// instance provides the current values of FileCheck string variables and - /// is updated if this match defines new values. Likewise, the + /// instance provides the current values of FileCheck string variables and is + /// updated if this match defines new values. Likewise, the /// GlobalNumericVariableTable StringMap in the same class provides the /// current values of FileCheck numeric variables and is updated if this /// match defines new numeric values. @@ -533,7 +524,7 @@ /// \returns a pointer to the class instance representing that variable, /// creating it if needed, or an error holding a diagnostic against \p SM /// should defining such a variable be invalid. - static Expected parseNumericVariableDefinition( + static Expected parseNumericVariableDefinition( StringRef &Expr, FileCheckPatternContext *Context, Optional LineNumber, const SourceMgr &SM); /// Parses \p Name as a (pseudo if \p IsPseudo is true) numeric variable use @@ -542,11 +533,9 @@ /// string and numeric variables. \returns the pointer to the class instance /// representing that variable if successful, or an error holding a /// diagnostic against \p SM otherwise. - static Expected> - parseNumericVariableUse(StringRef Name, bool IsPseudo, - Optional LineNumber, - FileCheckPatternContext *Context, - const SourceMgr &SM); + static Expected> parseNumericVariableUse( + StringRef Name, bool IsPseudo, Optional LineNumber, + FileCheckPatternContext *Context, const SourceMgr &SM); enum class AllowedOperand { LineVar, Literal, Any }; /// Parses \p Expr for use of a numeric operand at line \p LineNumber, or /// before input is parsed if \p LineNumber is None. Accepts both literal @@ -555,7 +544,7 @@ /// numeric variables. \returns the class representing that operand in the /// AST of the expression or an error holding a diagnostic against \p SM /// otherwise. - static Expected> + static Expected> parseNumericOperand(StringRef &Expr, AllowedOperand AO, Optional LineNumber, FileCheckPatternContext *Context, const SourceMgr &SM); @@ -566,8 +555,8 @@ /// the class instance holding the live string and numeric variables. /// \returns the class representing the binary operation in the AST of the /// expression, or an error holding a diagnostic against \p SM otherwise. - static Expected> - parseBinop(StringRef &Expr, std::unique_ptr LeftOp, + static Expected> + parseBinop(StringRef &Expr, std::unique_ptr LeftOp, bool IsLegacyLineExpr, Optional LineNumber, FileCheckPatternContext *Context, const SourceMgr &SM); }; @@ -579,7 +568,7 @@ /// A check that we found in the input file. struct FileCheckString { /// The pattern to match. - FileCheckPattern Pat; + Pattern Pat; /// Which prefix name this check matched. StringRef Prefix; @@ -589,9 +578,9 @@ /// All of the strings that are disallowed from occurring between this match /// string and the previous one (or start of file). - std::vector DagNotStrings; + std::vector DagNotStrings; - FileCheckString(const FileCheckPattern &P, StringRef S, SMLoc L) + FileCheckString(const Pattern &P, StringRef S, SMLoc L) : Pat(P), Prefix(S), Loc(L) {} /// Matches check string and its "not strings" and/or "dag strings". @@ -609,12 +598,12 @@ /// \p Buffer. Errors are reported against \p SM and diagnostics recorded in /// \p Diags according to the verbosity level set in \p Req. bool CheckNot(const SourceMgr &SM, StringRef Buffer, - const std::vector &NotStrings, + const std::vector &NotStrings, const FileCheckRequest &Req, std::vector *Diags) const; /// Matches "dag strings" and their mixed "not strings". size_t CheckDag(const SourceMgr &SM, StringRef Buffer, - std::vector &NotStrings, + std::vector &NotStrings, const FileCheckRequest &Req, std::vector *Diags) const; }; diff --git a/llvm/unittests/Support/FileCheckTest.cpp b/llvm/unittests/Support/FileCheckTest.cpp --- a/llvm/unittests/Support/FileCheckTest.cpp +++ b/llvm/unittests/Support/FileCheckTest.cpp @@ -19,13 +19,13 @@ TEST_F(FileCheckTest, Literal) { // Eval returns the literal's value. - FileCheckExpressionLiteral Ten(10); + ExpressionLiteral Ten(10); Expected Value = Ten.eval(); ASSERT_TRUE(bool(Value)); EXPECT_EQ(10U, *Value); // Max value can be correctly represented. - FileCheckExpressionLiteral Max(std::numeric_limits::max()); + ExpressionLiteral Max(std::numeric_limits::max()); Value = Max.eval(); ASSERT_TRUE(bool(Value)); EXPECT_EQ(std::numeric_limits::max(), *Value); @@ -45,14 +45,14 @@ static void expectUndefErrors(std::unordered_set ExpectedUndefVarNames, Error Err) { - handleAllErrors(std::move(Err), [&](const FileCheckUndefVarError &E) { + handleAllErrors(std::move(Err), [&](const UndefVarError &E) { ExpectedUndefVarNames.erase(E.getVarName()); }); EXPECT_TRUE(ExpectedUndefVarNames.empty()) << toString(ExpectedUndefVarNames); } -// Return whether Err contains any FileCheckUndefVarError whose associated name -// is not ExpectedUndefVarName. +// Return whether Err contains any UndefVarError whose associated name is not +// ExpectedUndefVarName. static void expectUndefError(const Twine &ExpectedUndefVarName, Error Err) { expectUndefErrors({ExpectedUndefVarName.str()}, std::move(Err)); } @@ -62,9 +62,9 @@ TEST_F(FileCheckTest, NumericVariable) { // Undefined variable: getValue and eval fail, error returned by eval holds // the name of the undefined variable. - FileCheckNumericVariable FooVar("FOO", 1); + NumericVariable FooVar("FOO", 1); EXPECT_EQ("FOO", FooVar.getName()); - FileCheckNumericVariableUse FooVarUse("FOO", &FooVar); + NumericVariableUse FooVarUse("FOO", &FooVar); EXPECT_FALSE(FooVar.getValue()); Expected EvalResult = FooVarUse.eval(); ASSERT_FALSE(EvalResult); @@ -90,15 +90,15 @@ } TEST_F(FileCheckTest, Binop) { - FileCheckNumericVariable FooVar("FOO", 1); + NumericVariable FooVar("FOO", 1); FooVar.setValue(42); - std::unique_ptr FooVarUse = - std::make_unique("FOO", &FooVar); - FileCheckNumericVariable BarVar("BAR", 2); + std::unique_ptr FooVarUse = + std::make_unique("FOO", &FooVar); + NumericVariable BarVar("BAR", 2); BarVar.setValue(18); - std::unique_ptr BarVarUse = - std::make_unique("BAR", &BarVar); - FileCheckASTBinop Binop(doAdd, std::move(FooVarUse), std::move(BarVarUse)); + std::unique_ptr BarVarUse = + std::make_unique("BAR", &BarVar); + BinaryOperation Binop(doAdd, std::move(FooVarUse), std::move(BarVarUse)); // Defined variable: eval returns right value. Expected Value = Binop.eval(); @@ -121,15 +121,15 @@ } TEST_F(FileCheckTest, ValidVarNameStart) { - EXPECT_TRUE(FileCheckPattern::isValidVarNameStart('a')); - EXPECT_TRUE(FileCheckPattern::isValidVarNameStart('G')); - EXPECT_TRUE(FileCheckPattern::isValidVarNameStart('_')); - EXPECT_FALSE(FileCheckPattern::isValidVarNameStart('2')); - EXPECT_FALSE(FileCheckPattern::isValidVarNameStart('$')); - EXPECT_FALSE(FileCheckPattern::isValidVarNameStart('@')); - EXPECT_FALSE(FileCheckPattern::isValidVarNameStart('+')); - EXPECT_FALSE(FileCheckPattern::isValidVarNameStart('-')); - EXPECT_FALSE(FileCheckPattern::isValidVarNameStart(':')); + EXPECT_TRUE(Pattern::isValidVarNameStart('a')); + EXPECT_TRUE(Pattern::isValidVarNameStart('G')); + EXPECT_TRUE(Pattern::isValidVarNameStart('_')); + EXPECT_FALSE(Pattern::isValidVarNameStart('2')); + EXPECT_FALSE(Pattern::isValidVarNameStart('$')); + EXPECT_FALSE(Pattern::isValidVarNameStart('@')); + EXPECT_FALSE(Pattern::isValidVarNameStart('+')); + EXPECT_FALSE(Pattern::isValidVarNameStart('-')); + EXPECT_FALSE(Pattern::isValidVarNameStart(':')); } static StringRef bufferize(SourceMgr &SM, StringRef Str) { @@ -144,65 +144,65 @@ SourceMgr SM; StringRef OrigVarName = bufferize(SM, "GoodVar42"); StringRef VarName = OrigVarName; - Expected ParsedVarResult = - FileCheckPattern::parseVariable(VarName, SM); + Expected ParsedVarResult = + Pattern::parseVariable(VarName, SM); ASSERT_TRUE(bool(ParsedVarResult)); EXPECT_EQ(ParsedVarResult->Name, OrigVarName); EXPECT_TRUE(VarName.empty()); EXPECT_FALSE(ParsedVarResult->IsPseudo); VarName = OrigVarName = bufferize(SM, "$GoodGlobalVar"); - ParsedVarResult = FileCheckPattern::parseVariable(VarName, SM); + ParsedVarResult = Pattern::parseVariable(VarName, SM); ASSERT_TRUE(bool(ParsedVarResult)); EXPECT_EQ(ParsedVarResult->Name, OrigVarName); EXPECT_TRUE(VarName.empty()); EXPECT_FALSE(ParsedVarResult->IsPseudo); VarName = OrigVarName = bufferize(SM, "@GoodPseudoVar"); - ParsedVarResult = FileCheckPattern::parseVariable(VarName, SM); + ParsedVarResult = Pattern::parseVariable(VarName, SM); ASSERT_TRUE(bool(ParsedVarResult)); EXPECT_EQ(ParsedVarResult->Name, OrigVarName); EXPECT_TRUE(VarName.empty()); EXPECT_TRUE(ParsedVarResult->IsPseudo); VarName = bufferize(SM, "42BadVar"); - ParsedVarResult = FileCheckPattern::parseVariable(VarName, SM); + ParsedVarResult = Pattern::parseVariable(VarName, SM); EXPECT_TRUE(errorToBool(ParsedVarResult.takeError())); VarName = bufferize(SM, "$@"); - ParsedVarResult = FileCheckPattern::parseVariable(VarName, SM); + ParsedVarResult = Pattern::parseVariable(VarName, SM); EXPECT_TRUE(errorToBool(ParsedVarResult.takeError())); VarName = OrigVarName = bufferize(SM, "B@dVar"); - ParsedVarResult = FileCheckPattern::parseVariable(VarName, SM); + ParsedVarResult = Pattern::parseVariable(VarName, SM); ASSERT_TRUE(bool(ParsedVarResult)); EXPECT_EQ(VarName, OrigVarName.substr(1)); EXPECT_EQ(ParsedVarResult->Name, "B"); EXPECT_FALSE(ParsedVarResult->IsPseudo); VarName = OrigVarName = bufferize(SM, "B$dVar"); - ParsedVarResult = FileCheckPattern::parseVariable(VarName, SM); + ParsedVarResult = Pattern::parseVariable(VarName, SM); ASSERT_TRUE(bool(ParsedVarResult)); EXPECT_EQ(VarName, OrigVarName.substr(1)); EXPECT_EQ(ParsedVarResult->Name, "B"); EXPECT_FALSE(ParsedVarResult->IsPseudo); VarName = bufferize(SM, "BadVar+"); - ParsedVarResult = FileCheckPattern::parseVariable(VarName, SM); + ParsedVarResult = Pattern::parseVariable(VarName, SM); ASSERT_TRUE(bool(ParsedVarResult)); EXPECT_EQ(VarName, "+"); EXPECT_EQ(ParsedVarResult->Name, "BadVar"); EXPECT_FALSE(ParsedVarResult->IsPseudo); VarName = bufferize(SM, "BadVar-"); - ParsedVarResult = FileCheckPattern::parseVariable(VarName, SM); + ParsedVarResult = Pattern::parseVariable(VarName, SM); ASSERT_TRUE(bool(ParsedVarResult)); EXPECT_EQ(VarName, "-"); EXPECT_EQ(ParsedVarResult->Name, "BadVar"); EXPECT_FALSE(ParsedVarResult->IsPseudo); VarName = bufferize(SM, "BadVar:"); - ParsedVarResult = FileCheckPattern::parseVariable(VarName, SM); + ParsedVarResult = Pattern::parseVariable(VarName, SM); ASSERT_TRUE(bool(ParsedVarResult)); EXPECT_EQ(VarName, ":"); EXPECT_EQ(ParsedVarResult->Name, "BadVar"); @@ -215,7 +215,7 @@ SourceMgr SM; FileCheckRequest Req; FileCheckPatternContext Context; - FileCheckPattern P{Check::CheckPlain, &Context, LineNumber++}; + Pattern P{Check::CheckPlain, &Context, LineNumber++}; public: PatternTester() { @@ -236,12 +236,12 @@ } void initNextPattern() { - P = FileCheckPattern(Check::CheckPlain, &Context, LineNumber++); + P = Pattern(Check::CheckPlain, &Context, LineNumber++); } bool parseSubstExpect(StringRef Expr) { StringRef ExprBufferRef = bufferize(SM, Expr); - Optional DefinedNumericVariable; + Optional DefinedNumericVariable; return errorToBool( P.parseNumericSubstitutionBlock(ExprBufferRef, DefinedNumericVariable, false, LineNumber - 1, &Context, SM) @@ -406,24 +406,22 @@ // Substitution of an undefined string variable fails and error holds that // variable's name. - FileCheckStringSubstitution StringSubstitution(&Context, "VAR404", 42); + StringSubstitution StringSubstitution(&Context, "VAR404", 42); Expected SubstValue = StringSubstitution.getResult(); ASSERT_FALSE(bool(SubstValue)); expectUndefError("VAR404", SubstValue.takeError()); // Substitutions of defined pseudo and non-pseudo numeric variables return // the right value. - FileCheckNumericVariable LineVar("@LINE", 1); - FileCheckNumericVariable NVar("N", 1); + NumericVariable LineVar("@LINE", 1); + NumericVariable NVar("N", 1); LineVar.setValue(42); NVar.setValue(10); - auto LineVarUse = - std::make_unique("@LINE", &LineVar); - auto NVarUse = std::make_unique("N", &NVar); - FileCheckNumericSubstitution SubstitutionLine(&Context, "@LINE", - std::move(LineVarUse), 12); - FileCheckNumericSubstitution SubstitutionN(&Context, "N", std::move(NVarUse), - 30); + auto LineVarUse = std::make_unique("@LINE", &LineVar); + auto NVarUse = std::make_unique("N", &NVar); + NumericSubstitution SubstitutionLine(&Context, "@LINE", std::move(LineVarUse), + 12); + NumericSubstitution SubstitutionN(&Context, "N", std::move(NVarUse), 30); SubstValue = SubstitutionLine.getResult(); ASSERT_TRUE(bool(SubstValue)); EXPECT_EQ("42", *SubstValue); @@ -443,8 +441,8 @@ expectUndefError("N", SubstValue.takeError()); // Substitution of a defined string variable returns the right value. - FileCheckPattern P(Check::CheckPlain, &Context, 1); - StringSubstitution = FileCheckStringSubstitution(&Context, "FOO", 42); + Pattern P(Check::CheckPlain, &Context, 1); + StringSubstitution = llvm::StringSubstitution(&Context, "FOO", 42); SubstValue = StringSubstitution.getResult(); ASSERT_TRUE(bool(SubstValue)); EXPECT_EQ("BAR", *SubstValue); @@ -514,9 +512,9 @@ StringRef EmptyVarStr = "EmptyVar"; StringRef UnknownVarStr = "UnknownVar"; Expected LocalVar = Cxt.getPatternVarValue(LocalVarStr); - FileCheckPattern P(Check::CheckPlain, &Cxt, 1); - Optional DefinedNumericVariable; - Expected> ExpressionAST = + Pattern P(Check::CheckPlain, &Cxt, 1); + Optional DefinedNumericVariable; + Expected> ExpressionASTPointer = P.parseNumericSubstitutionBlock(LocalNumVar1Ref, DefinedNumericVariable, /*IsLegacyLineExpr=*/false, /*LineNumber=*/1, &Cxt, SM); @@ -524,16 +522,16 @@ EXPECT_EQ(*LocalVar, "FOO"); Expected EmptyVar = Cxt.getPatternVarValue(EmptyVarStr); Expected UnknownVar = Cxt.getPatternVarValue(UnknownVarStr); - ASSERT_TRUE(bool(ExpressionAST)); - Expected ExpressionVal = (*ExpressionAST)->eval(); + ASSERT_TRUE(bool(ExpressionASTPointer)); + Expected ExpressionVal = (*ExpressionASTPointer)->eval(); ASSERT_TRUE(bool(ExpressionVal)); EXPECT_EQ(*ExpressionVal, 18U); - ExpressionAST = + ExpressionASTPointer = P.parseNumericSubstitutionBlock(LocalNumVar2Ref, DefinedNumericVariable, /*IsLegacyLineExpr=*/false, /*LineNumber=*/1, &Cxt, SM); - ASSERT_TRUE(bool(ExpressionAST)); - ExpressionVal = (*ExpressionAST)->eval(); + ASSERT_TRUE(bool(ExpressionASTPointer)); + ExpressionVal = (*ExpressionASTPointer)->eval(); ASSERT_TRUE(bool(ExpressionVal)); EXPECT_EQ(*ExpressionVal, 20U); ASSERT_TRUE(bool(EmptyVar)); @@ -548,19 +546,19 @@ // local variables, if it was created before. This is important because local // variable clearing due to --enable-var-scope happens after numeric // expressions are linked to the numeric variables they use. - EXPECT_TRUE(errorToBool((*ExpressionAST)->eval().takeError())); - P = FileCheckPattern(Check::CheckPlain, &Cxt, 2); - ExpressionAST = P.parseNumericSubstitutionBlock( + EXPECT_TRUE(errorToBool((*ExpressionASTPointer)->eval().takeError())); + P = Pattern(Check::CheckPlain, &Cxt, 2); + ExpressionASTPointer = P.parseNumericSubstitutionBlock( LocalNumVar1Ref, DefinedNumericVariable, /*IsLegacyLineExpr=*/false, /*LineNumber=*/2, &Cxt, SM); - ASSERT_TRUE(bool(ExpressionAST)); - ExpressionVal = (*ExpressionAST)->eval(); + ASSERT_TRUE(bool(ExpressionASTPointer)); + ExpressionVal = (*ExpressionASTPointer)->eval(); EXPECT_TRUE(errorToBool(ExpressionVal.takeError())); - ExpressionAST = P.parseNumericSubstitutionBlock( + ExpressionASTPointer = P.parseNumericSubstitutionBlock( LocalNumVar2Ref, DefinedNumericVariable, /*IsLegacyLineExpr=*/false, /*LineNumber=*/2, &Cxt, SM); - ASSERT_TRUE(bool(ExpressionAST)); - ExpressionVal = (*ExpressionAST)->eval(); + ASSERT_TRUE(bool(ExpressionASTPointer)); + ExpressionVal = (*ExpressionASTPointer)->eval(); EXPECT_TRUE(errorToBool(ExpressionVal.takeError())); EmptyVar = Cxt.getPatternVarValue(EmptyVarStr); EXPECT_TRUE(errorToBool(EmptyVar.takeError())); @@ -577,24 +575,24 @@ Expected GlobalVar = Cxt.getPatternVarValue(GlobalVarStr); ASSERT_TRUE(bool(GlobalVar)); EXPECT_EQ(*GlobalVar, "BAR"); - P = FileCheckPattern(Check::CheckPlain, &Cxt, 3); - ExpressionAST = P.parseNumericSubstitutionBlock( + P = Pattern(Check::CheckPlain, &Cxt, 3); + ExpressionASTPointer = P.parseNumericSubstitutionBlock( GlobalNumVarRef, DefinedNumericVariable, /*IsLegacyLineExpr=*/false, /*LineNumber=*/3, &Cxt, SM); - ASSERT_TRUE(bool(ExpressionAST)); - ExpressionVal = (*ExpressionAST)->eval(); + ASSERT_TRUE(bool(ExpressionASTPointer)); + ExpressionVal = (*ExpressionASTPointer)->eval(); ASSERT_TRUE(bool(ExpressionVal)); EXPECT_EQ(*ExpressionVal, 36U); // Clear local variables and check global variables remain defined. Cxt.clearLocalVars(); EXPECT_FALSE(errorToBool(Cxt.getPatternVarValue(GlobalVarStr).takeError())); - P = FileCheckPattern(Check::CheckPlain, &Cxt, 4); - ExpressionAST = P.parseNumericSubstitutionBlock( + P = Pattern(Check::CheckPlain, &Cxt, 4); + ExpressionASTPointer = P.parseNumericSubstitutionBlock( GlobalNumVarRef, DefinedNumericVariable, /*IsLegacyLineExpr=*/false, /*LineNumber=*/4, &Cxt, SM); - ASSERT_TRUE(bool(ExpressionAST)); - ExpressionVal = (*ExpressionAST)->eval(); + ASSERT_TRUE(bool(ExpressionASTPointer)); + ExpressionVal = (*ExpressionASTPointer)->eval(); ASSERT_TRUE(bool(ExpressionVal)); EXPECT_EQ(*ExpressionVal, 36U); }