Skip to content

Commit 5522e31

Browse files
committed
[clang][NFC] Simplify SourceLocExpr::EvaluateInContext
Use ASTContext::MakeIntValue and remove the std::tie+lambda weirdness. Differential Revision: https://reviews.llvm.org/D155584
1 parent ed7ade9 commit 5522e31

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

clang/lib/AST/Expr.cpp

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,14 +2288,17 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx,
22882288
SourceLocation Loc;
22892289
const DeclContext *Context;
22902290

2291-
std::tie(Loc,
2292-
Context) = [&]() -> std::pair<SourceLocation, const DeclContext *> {
2293-
if (auto *DIE = dyn_cast_or_null<CXXDefaultInitExpr>(DefaultExpr))
2294-
return {DIE->getUsedLocation(), DIE->getUsedContext()};
2295-
if (auto *DAE = dyn_cast_or_null<CXXDefaultArgExpr>(DefaultExpr))
2296-
return {DAE->getUsedLocation(), DAE->getUsedContext()};
2297-
return {this->getLocation(), this->getParentContext()};
2298-
}();
2291+
if (const auto *DIE = dyn_cast_if_present<CXXDefaultInitExpr>(DefaultExpr)) {
2292+
Loc = DIE->getUsedLocation();
2293+
Context = DIE->getUsedContext();
2294+
} else if (const auto *DAE =
2295+
dyn_cast_if_present<CXXDefaultArgExpr>(DefaultExpr)) {
2296+
Loc = DAE->getUsedLocation();
2297+
Context = DAE->getUsedContext();
2298+
} else {
2299+
Loc = getLocation();
2300+
Context = getParentContext();
2301+
}
22992302

23002303
PresumedLoc PLoc = Ctx.getSourceManager().getPresumedLoc(
23012304
Ctx.getSourceManager().getExpansionRange(Loc).getEnd());
@@ -2333,13 +2336,9 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx,
23332336
CurDecl ? PredefinedExpr::ComputeName(Kind, CurDecl) : std::string(""));
23342337
}
23352338
case SourceLocExpr::Line:
2336-
case SourceLocExpr::Column: {
2337-
llvm::APSInt IntVal(Ctx.getIntWidth(Ctx.UnsignedIntTy),
2338-
/*isUnsigned=*/true);
2339-
IntVal = getIdentKind() == SourceLocExpr::Line ? PLoc.getLine()
2340-
: PLoc.getColumn();
2341-
return APValue(IntVal);
2342-
}
2339+
return APValue(Ctx.MakeIntValue(PLoc.getLine(), Ctx.UnsignedIntTy));
2340+
case SourceLocExpr::Column:
2341+
return APValue(Ctx.MakeIntValue(PLoc.getColumn(), Ctx.UnsignedIntTy));
23432342
case SourceLocExpr::SourceLocStruct: {
23442343
// Fill in a std::source_location::__impl structure, by creating an
23452344
// artificial file-scoped CompoundLiteralExpr, and returning a pointer to
@@ -2352,7 +2351,7 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx,
23522351
// the ImplDecl type is as expected.
23532352

23542353
APValue Value(APValue::UninitStruct(), 0, 4);
2355-
for (FieldDecl *F : ImplDecl->fields()) {
2354+
for (const FieldDecl *F : ImplDecl->fields()) {
23562355
StringRef Name = F->getName();
23572356
if (Name == "_M_file_name") {
23582357
SmallString<256> Path(PLoc.getFilename());
@@ -2369,16 +2368,10 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx,
23692368
PredefinedExpr::PrettyFunction, CurDecl))
23702369
: "");
23712370
} else if (Name == "_M_line") {
2372-
QualType Ty = F->getType();
2373-
llvm::APSInt IntVal(Ctx.getIntWidth(Ty),
2374-
Ty->hasUnsignedIntegerRepresentation());
2375-
IntVal = PLoc.getLine();
2371+
llvm::APSInt IntVal = Ctx.MakeIntValue(PLoc.getLine(), F->getType());
23762372
Value.getStructField(F->getFieldIndex()) = APValue(IntVal);
23772373
} else if (Name == "_M_column") {
2378-
QualType Ty = F->getType();
2379-
llvm::APSInt IntVal(Ctx.getIntWidth(Ty),
2380-
Ty->hasUnsignedIntegerRepresentation());
2381-
IntVal = PLoc.getColumn();
2374+
llvm::APSInt IntVal = Ctx.MakeIntValue(PLoc.getColumn(), F->getType());
23822375
Value.getStructField(F->getFieldIndex()) = APValue(IntVal);
23832376
}
23842377
}

0 commit comments

Comments
 (0)