diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp index d3b061520f03a..e2cc6dc6763bb 100644 --- a/llvm/lib/FileCheck/FileCheck.cpp +++ b/llvm/lib/FileCheck/FileCheck.cpp @@ -363,7 +363,7 @@ Expected llvm::min(const ExpressionValue &LeftOperand, } Expected NumericVariableUse::eval() const { - std::optional Value = Variable->getValue(); + Optional Value = Variable->getValue(); if (Value) return *Value; @@ -480,7 +480,7 @@ char ErrorReported::ID = 0; Expected Pattern::parseNumericVariableDefinition( StringRef &Expr, FileCheckPatternContext *Context, - std::optional LineNumber, ExpressionFormat ImplicitFormat, + Optional LineNumber, ExpressionFormat ImplicitFormat, const SourceMgr &SM) { Expected ParseVarResult = parseVariable(Expr, SM); if (!ParseVarResult) @@ -518,7 +518,7 @@ Expected Pattern::parseNumericVariableDefinition( } Expected> Pattern::parseNumericVariableUse( - StringRef Name, bool IsPseudo, std::optional LineNumber, + StringRef Name, bool IsPseudo, Optional LineNumber, FileCheckPatternContext *Context, const SourceMgr &SM) { if (IsPseudo && !Name.equals("@LINE")) return ErrorDiagnostic::get( @@ -542,7 +542,7 @@ Expected> Pattern::parseNumericVariableUse( Context->GlobalNumericVariableTable[Name] = NumericVariable; } - std::optional DefLineNumber = NumericVariable->getDefLineNumber(); + Optional DefLineNumber = NumericVariable->getDefLineNumber(); if (DefLineNumber && LineNumber && *DefLineNumber == *LineNumber) return ErrorDiagnostic::get( SM, Name, @@ -554,7 +554,7 @@ Expected> Pattern::parseNumericVariableUse( Expected> Pattern::parseNumericOperand( StringRef &Expr, AllowedOperand AO, bool MaybeInvalidConstraint, - std::optional LineNumber, FileCheckPatternContext *Context, + Optional LineNumber, FileCheckPatternContext *Context, const SourceMgr &SM) { if (Expr.startswith("(")) { if (AO != AllowedOperand::Any) @@ -611,7 +611,7 @@ Expected> Pattern::parseNumericOperand( } Expected> -Pattern::parseParenExpr(StringRef &Expr, std::optional LineNumber, +Pattern::parseParenExpr(StringRef &Expr, Optional LineNumber, FileCheckPatternContext *Context, const SourceMgr &SM) { Expr = Expr.ltrim(SpaceChars); assert(Expr.startswith("(")); @@ -646,7 +646,7 @@ Pattern::parseParenExpr(StringRef &Expr, std::optional LineNumber, Expected> Pattern::parseBinop(StringRef Expr, StringRef &RemainingExpr, std::unique_ptr LeftOp, - bool IsLegacyLineExpr, std::optional LineNumber, + bool IsLegacyLineExpr, Optional LineNumber, FileCheckPatternContext *Context, const SourceMgr &SM) { RemainingExpr = RemainingExpr.ltrim(SpaceChars); if (RemainingExpr.empty()) @@ -690,12 +690,12 @@ Pattern::parseBinop(StringRef Expr, StringRef &RemainingExpr, Expected> Pattern::parseCallExpr(StringRef &Expr, StringRef FuncName, - std::optional LineNumber, + Optional LineNumber, FileCheckPatternContext *Context, const SourceMgr &SM) { Expr = Expr.ltrim(SpaceChars); assert(Expr.startswith("(")); - auto OptFunc = StringSwitch>(FuncName) + auto OptFunc = StringSwitch>(FuncName) .Case("add", operator+) .Case("div", operator/) .Case("max", max) @@ -765,8 +765,8 @@ Pattern::parseCallExpr(StringRef &Expr, StringRef FuncName, } Expected> Pattern::parseNumericSubstitutionBlock( - StringRef Expr, std::optional &DefinedNumericVariable, - bool IsLegacyLineExpr, std::optional LineNumber, + StringRef Expr, Optional &DefinedNumericVariable, + bool IsLegacyLineExpr, Optional LineNumber, FileCheckPatternContext *Context, const SourceMgr &SM) { std::unique_ptr ExpressionASTPointer = nullptr; StringRef DefExpr = StringRef(); @@ -1099,7 +1099,7 @@ bool Pattern::parsePattern(StringRef PatternStr, StringRef Prefix, // Parse numeric substitution block. std::unique_ptr ExpressionPointer; - std::optional DefinedNumericVariable; + Optional DefinedNumericVariable; if (IsNumBlock) { Expected> ParseResult = parseNumericSubstitutionBlock(MatchStr, DefinedNumericVariable, @@ -1412,7 +1412,7 @@ void Pattern::printVariableDefs(const SourceMgr &SM, for (const auto &VariableDef : NumericVariableDefs) { VarCapture VC; VC.Name = VariableDef.getKey(); - std::optional StrValue = + Optional StrValue = VariableDef.getValue().DefinedNumericVariable->getStringValue(); if (!StrValue) continue; @@ -2701,7 +2701,7 @@ Error FileCheckPatternContext::defineCmdlineVariables( // Now parse the definition both to check that the syntax is correct and // to create the necessary class instance. StringRef CmdlineDefExpr = CmdlineDef.substr(1); - std::optional DefinedNumericVariable; + Optional DefinedNumericVariable; Expected> ExpressionResult = Pattern::parseNumericSubstitutionBlock(CmdlineDefExpr, DefinedNumericVariable, false, diff --git a/llvm/lib/FileCheck/FileCheckImpl.h b/llvm/lib/FileCheck/FileCheckImpl.h index fd3568e7a5b06..556be6b8bb0f9 100644 --- a/llvm/lib/FileCheck/FileCheckImpl.h +++ b/llvm/lib/FileCheck/FileCheckImpl.h @@ -15,13 +15,13 @@ #ifndef LLVM_LIB_FILECHECK_FILECHECKIMPL_H #define LLVM_LIB_FILECHECK_FILECHECKIMPL_H +#include "llvm/ADT/Optional.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/FileCheck/FileCheck.h" #include "llvm/Support/Error.h" #include "llvm/Support/SourceMgr.h" #include -#include #include #include @@ -266,23 +266,23 @@ class NumericVariable { ExpressionFormat ImplicitFormat; /// Value of numeric variable, if defined, or std::nullopt otherwise. - std::optional Value; + Optional Value; /// The input buffer's string from which Value was parsed, or std::nullopt. /// See comments on getStringValue for a discussion of the None case. - std::optional StrValue; + Optional StrValue; /// Line number where this variable is defined, or std::nullopt if defined /// before input is parsed. Used to determine whether a variable is defined on /// the same line as a given use. - std::optional DefLineNumber; + Optional DefLineNumber; public: /// Constructor for a variable \p Name with implicit format \p ImplicitFormat /// defined at line \p DefLineNumber or defined before input is parsed if /// \p DefLineNumber is None. explicit NumericVariable(StringRef Name, ExpressionFormat ImplicitFormat, - std::optional DefLineNumber = std::nullopt) + Optional DefLineNumber = std::nullopt) : Name(Name), ImplicitFormat(ImplicitFormat), DefLineNumber(DefLineNumber) {} @@ -293,20 +293,20 @@ class NumericVariable { ExpressionFormat getImplicitFormat() const { return ImplicitFormat; } /// \returns this variable's value. - std::optional getValue() const { return Value; } + Optional getValue() const { return Value; } /// \returns the input buffer's string from which this variable's value was /// parsed, or std::nullopt if the value is not yet defined or was not parsed /// from the input buffer. For example, the value of @LINE is not parsed from /// the input buffer, and some numeric variables are parsed from the command /// line instead. - std::optional getStringValue() const { return StrValue; } + Optional getStringValue() const { return StrValue; } /// Sets value of this numeric variable to \p NewValue, and sets the input /// buffer string from which it was parsed to \p NewStrValue. See comments on /// getStringValue for a discussion of when the latter can be None. void setValue(ExpressionValue NewValue, - std::optional NewStrValue = std::nullopt) { + Optional NewStrValue = std::nullopt) { Value = NewValue; StrValue = NewStrValue; } @@ -320,7 +320,7 @@ class NumericVariable { /// \returns the line number where this variable is defined, if any, or /// std::nullopt if defined before input is parsed. - std::optional getDefLineNumber() const { return DefLineNumber; } + Optional getDefLineNumber() const { return DefLineNumber; } }; /// Class representing the use of a numeric variable in the AST of an @@ -675,14 +675,14 @@ class Pattern { /// Line number for this CHECK pattern or std::nullopt if it is an implicit /// pattern. Used to determine whether a variable definition is made on an /// earlier line to the one with this CHECK. - std::optional LineNumber; + Optional LineNumber; /// Ignore case while matching if set to true. bool IgnoreCase = false; public: Pattern(Check::FileCheckType Ty, FileCheckPatternContext *Context, - std::optional Line = std::nullopt) + Optional Line = std::nullopt) : Context(Context), CheckTy(Ty), LineNumber(Line) {} /// \returns the location in source code. @@ -719,8 +719,8 @@ class Pattern { /// representing the numeric variable defined in this numeric substitution /// block, or std::nullopt if this block does not define any variable. static Expected> parseNumericSubstitutionBlock( - StringRef Expr, std::optional &DefinedNumericVariable, - bool IsLegacyLineExpr, std::optional LineNumber, + StringRef Expr, Optional &DefinedNumericVariable, + bool IsLegacyLineExpr, Optional LineNumber, FileCheckPatternContext *Context, const SourceMgr &SM); /// Parses the pattern in \p PatternStr and initializes this Pattern instance /// accordingly. @@ -736,7 +736,7 @@ class Pattern { size_t Len; }; struct MatchResult { - std::optional TheMatch; + Optional TheMatch; Error TheError; MatchResult(size_t MatchPos, size_t MatchLen, Error E) : TheMatch(Match{MatchPos, MatchLen}), TheError(std::move(E)) {} @@ -794,7 +794,7 @@ class Pattern { /// should defining such a variable be invalid. static Expected parseNumericVariableDefinition( StringRef &Expr, FileCheckPatternContext *Context, - std::optional LineNumber, ExpressionFormat ImplicitFormat, + Optional LineNumber, ExpressionFormat ImplicitFormat, const SourceMgr &SM); /// Parses \p Name as a (pseudo if \p IsPseudo is true) numeric variable use /// at line \p LineNumber, or before input is parsed if \p LineNumber is @@ -803,7 +803,7 @@ class Pattern { /// representing that variable if successful, or an error holding a /// diagnostic against \p SM otherwise. static Expected> parseNumericVariableUse( - StringRef Name, bool IsPseudo, std::optional LineNumber, + StringRef Name, bool IsPseudo, Optional LineNumber, FileCheckPatternContext *Context, const SourceMgr &SM); enum class AllowedOperand { LineVar, LegacyLiteral, Any }; /// Parses \p Expr for use of a numeric operand at line \p LineNumber, or @@ -817,7 +817,7 @@ class Pattern { /// function will attempt to parse a parenthesized expression. static Expected> parseNumericOperand(StringRef &Expr, AllowedOperand AO, bool ConstraintParsed, - std::optional LineNumber, + Optional LineNumber, FileCheckPatternContext *Context, const SourceMgr &SM); /// Parses and updates \p RemainingExpr for a binary operation at line /// \p LineNumber, or before input is parsed if \p LineNumber is None. The @@ -831,7 +831,7 @@ class Pattern { static Expected> parseBinop(StringRef Expr, StringRef &RemainingExpr, std::unique_ptr LeftOp, bool IsLegacyLineExpr, - std::optional LineNumber, FileCheckPatternContext *Context, + Optional LineNumber, FileCheckPatternContext *Context, const SourceMgr &SM); /// Parses a parenthesized expression inside \p Expr at line \p LineNumber, or @@ -841,7 +841,7 @@ class Pattern { /// 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> - parseParenExpr(StringRef &Expr, std::optional LineNumber, + parseParenExpr(StringRef &Expr, Optional LineNumber, FileCheckPatternContext *Context, const SourceMgr &SM); /// Parses \p Expr for an argument list belonging to a call to function \p @@ -853,8 +853,8 @@ class Pattern { /// otherwise. static Expected> parseCallExpr(StringRef &Expr, StringRef FuncName, - std::optional LineNumber, - FileCheckPatternContext *Context, const SourceMgr &SM); + Optional LineNumber, FileCheckPatternContext *Context, + const SourceMgr &SM); }; //===----------------------------------------------------------------------===// diff --git a/llvm/unittests/FileCheck/FileCheckTest.cpp b/llvm/unittests/FileCheck/FileCheckTest.cpp index 8f7512844e8d7..c31c553470dd1 100644 --- a/llvm/unittests/FileCheck/FileCheckTest.cpp +++ b/llvm/unittests/FileCheck/FileCheckTest.cpp @@ -750,7 +750,7 @@ TEST_F(FileCheckTest, NumericVariable) { // Defined variable without string: only getValue and eval return value set. FooVar.setValue(ExpressionValue(42u)); - std::optional Value = FooVar.getValue(); + Optional Value = FooVar.getValue(); ASSERT_TRUE(Value); EXPECT_EQ(42, cantFail(Value->getSignedValue())); EXPECT_FALSE(FooVar.getStringValue()); @@ -1014,7 +1014,7 @@ class PatternTester { Expected> parseSubst(StringRef Expr, bool IsLegacyLineExpr = false) { StringRef ExprBufferRef = bufferize(SM, Expr); - std::optional DefinedNumericVariable; + Optional DefinedNumericVariable; return P.parseNumericSubstitutionBlock( ExprBufferRef, DefinedNumericVariable, IsLegacyLineExpr, LineNumber, &Context, SM); @@ -1665,7 +1665,7 @@ TEST_F(FileCheckTest, FileCheckContext) { StringRef UnknownVarStr = "UnknownVar"; Expected LocalVar = Cxt.getPatternVarValue(LocalVarStr); P = Pattern(Check::CheckPlain, &Cxt, ++LineNumber); - std::optional DefinedNumericVariable; + Optional DefinedNumericVariable; Expected> ExpressionPointer = P.parseNumericSubstitutionBlock(LocalNumVar1Ref, DefinedNumericVariable, /*IsLegacyLineExpr=*/false, LineNumber,