Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/Support/FileCheck.cpp
Show First 20 Lines • Show All 267 Lines • ▼ Show 20 Lines | return ErrorDiagnostic::get( | ||||
"' defined earlier in the same CHECK directive"); | "' defined earlier in the same CHECK directive"); | ||||
return std::make_unique<NumericVariableUse>(Name, NumericVariable); | return std::make_unique<NumericVariableUse>(Name, NumericVariable); | ||||
} | } | ||||
Expected<std::unique_ptr<ExpressionAST>> Pattern::parseNumericOperand( | Expected<std::unique_ptr<ExpressionAST>> Pattern::parseNumericOperand( | ||||
StringRef &Expr, AllowedOperand AO, Optional<size_t> LineNumber, | StringRef &Expr, AllowedOperand AO, Optional<size_t> LineNumber, | ||||
FileCheckPatternContext *Context, const SourceMgr &SM) { | FileCheckPatternContext *Context, const SourceMgr &SM) { | ||||
if (Expr.startswith("(")) { | |||||
if (AO != AllowedOperand::Any) | |||||
return ErrorDiagnostic::get( | |||||
SM, Expr, "parenthesized expression not permitted here"); | |||||
return parseParenExpr(Expr, LineNumber, Context, SM); | |||||
} | |||||
if (AO == AllowedOperand::LineVar || AO == AllowedOperand::Any) { | if (AO == AllowedOperand::LineVar || AO == AllowedOperand::Any) { | ||||
// Try to parse as a numeric variable use. | // Try to parse as a numeric variable use. | ||||
Expected<Pattern::VariableProperties> ParseVarResult = | Expected<Pattern::VariableProperties> ParseVarResult = | ||||
parseVariable(Expr, SM); | parseVariable(Expr, SM); | ||||
if (ParseVarResult) | if (ParseVarResult) | ||||
return parseNumericVariableUse(ParseVarResult->Name, | return parseNumericVariableUse(ParseVarResult->Name, | ||||
ParseVarResult->IsPseudo, LineNumber, | ParseVarResult->IsPseudo, LineNumber, | ||||
Context, SM); | Context, SM); | ||||
Show All 11 Lines | if (!Expr.consumeInteger((AO == AllowedOperand::LegacyLiteral) ? 10 : 0, | ||||
return std::make_unique<ExpressionLiteral>( | return std::make_unique<ExpressionLiteral>( | ||||
OperandExpr.drop_back(Expr.size()), LiteralValue); | OperandExpr.drop_back(Expr.size()), LiteralValue); | ||||
} | } | ||||
return ErrorDiagnostic::get(SM, Expr, | return ErrorDiagnostic::get(SM, Expr, | ||||
"invalid operand format '" + Expr + "'"); | "invalid operand format '" + Expr + "'"); | ||||
} | } | ||||
Expected<std::unique_ptr<ExpressionAST>> | |||||
Pattern::parseParenExpr(StringRef &Expr, Optional<size_t> LineNumber, | |||||
FileCheckPatternContext *Context, const SourceMgr &SM) { | |||||
Expr = Expr.ltrim(SpaceChars); | |||||
assert(Expr.startswith("(")); | |||||
// Parse right operand. | |||||
Expr.consume_front("("); | |||||
Expr = Expr.ltrim(SpaceChars); | |||||
if (Expr.empty()) | |||||
return ErrorDiagnostic::get(SM, Expr, "missing operand in expression"); | |||||
// Note: parseNumericOperand handles nested opening parentheses. | |||||
Expected<std::unique_ptr<ExpressionAST>> SubExprResult = | |||||
parseNumericOperand(Expr, AllowedOperand::Any, LineNumber, Context, SM); | |||||
Expr = Expr.ltrim(SpaceChars); | |||||
while (SubExprResult && !Expr.empty() && !Expr.startswith(")")) { | |||||
StringRef OrigExpr = Expr; | |||||
SubExprResult = parseBinop(OrigExpr, Expr, std::move(*SubExprResult), false, | |||||
LineNumber, Context, SM); | |||||
Expr = Expr.ltrim(SpaceChars); | |||||
} | |||||
if (!SubExprResult) | |||||
return SubExprResult; | |||||
if (!Expr.consume_front(")")) { | |||||
return ErrorDiagnostic::get(SM, Expr, | |||||
"missing ')' at end of nested expression"); | |||||
} | |||||
return SubExprResult; | |||||
} | |||||
static uint64_t add(uint64_t LeftOp, uint64_t RightOp) { | static uint64_t add(uint64_t LeftOp, uint64_t RightOp) { | ||||
return LeftOp + RightOp; | return LeftOp + RightOp; | ||||
} | } | ||||
static uint64_t sub(uint64_t LeftOp, uint64_t RightOp) { | static uint64_t sub(uint64_t LeftOp, uint64_t RightOp) { | ||||
return LeftOp - RightOp; | return LeftOp - RightOp; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,883 Lines • Show Last 20 Lines |