[PATCH] D155584: [clang][NFC] Simplify SourceLocExpr::EvaluateInContext
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 18 05:05:06 PDT 2023
tbaeder created this revision.
tbaeder added a reviewer: clang.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Use ASTContext::MakeIntValue and remove the std::tie+lambda weirdness.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D155584
Files:
clang/lib/AST/Expr.cpp
Index: clang/lib/AST/Expr.cpp
===================================================================
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -2301,14 +2301,17 @@
SourceLocation Loc;
const DeclContext *Context;
- std::tie(Loc,
- Context) = [&]() -> std::pair<SourceLocation, const DeclContext *> {
- if (auto *DIE = dyn_cast_or_null<CXXDefaultInitExpr>(DefaultExpr))
- return {DIE->getUsedLocation(), DIE->getUsedContext()};
- if (auto *DAE = dyn_cast_or_null<CXXDefaultArgExpr>(DefaultExpr))
- return {DAE->getUsedLocation(), DAE->getUsedContext()};
- return {this->getLocation(), this->getParentContext()};
- }();
+ if (const auto *DIE = dyn_cast_if_present<CXXDefaultInitExpr>(DefaultExpr)) {
+ Loc = DIE->getUsedLocation();
+ Context = DIE->getUsedContext();
+ } else if (const auto *DAE =
+ dyn_cast_if_present<CXXDefaultArgExpr>(DefaultExpr)) {
+ Loc = DAE->getUsedLocation();
+ Context = DAE->getUsedContext();
+ } else {
+ Loc = getLocation();
+ Context = getParentContext();
+ }
PresumedLoc PLoc = Ctx.getSourceManager().getPresumedLoc(
Ctx.getSourceManager().getExpansionRange(Loc).getEnd());
@@ -2346,13 +2349,9 @@
CurDecl ? PredefinedExpr::ComputeName(Kind, CurDecl) : std::string(""));
}
case SourceLocExpr::Line:
- case SourceLocExpr::Column: {
- llvm::APSInt IntVal(Ctx.getIntWidth(Ctx.UnsignedIntTy),
- /*isUnsigned=*/true);
- IntVal = getIdentKind() == SourceLocExpr::Line ? PLoc.getLine()
- : PLoc.getColumn();
- return APValue(IntVal);
- }
+ return APValue(Ctx.MakeIntValue(PLoc.getLine(), Ctx.UnsignedIntTy));
+ case SourceLocExpr::Column:
+ return APValue(Ctx.MakeIntValue(PLoc.getColumn(), Ctx.UnsignedIntTy));
case SourceLocExpr::SourceLocStruct: {
// Fill in a std::source_location::__impl structure, by creating an
// artificial file-scoped CompoundLiteralExpr, and returning a pointer to
@@ -2365,7 +2364,7 @@
// the ImplDecl type is as expected.
APValue Value(APValue::UninitStruct(), 0, 4);
- for (FieldDecl *F : ImplDecl->fields()) {
+ for (const FieldDecl *F : ImplDecl->fields()) {
StringRef Name = F->getName();
if (Name == "_M_file_name") {
SmallString<256> Path(PLoc.getFilename());
@@ -2382,16 +2381,10 @@
PredefinedExpr::PrettyFunction, CurDecl))
: "");
} else if (Name == "_M_line") {
- QualType Ty = F->getType();
- llvm::APSInt IntVal(Ctx.getIntWidth(Ty),
- Ty->hasUnsignedIntegerRepresentation());
- IntVal = PLoc.getLine();
+ llvm::APSInt IntVal = Ctx.MakeIntValue(PLoc.getLine(), F->getType());
Value.getStructField(F->getFieldIndex()) = APValue(IntVal);
} else if (Name == "_M_column") {
- QualType Ty = F->getType();
- llvm::APSInt IntVal(Ctx.getIntWidth(Ty),
- Ty->hasUnsignedIntegerRepresentation());
- IntVal = PLoc.getColumn();
+ llvm::APSInt IntVal = Ctx.MakeIntValue(PLoc.getColumn(), F->getType());
Value.getStructField(F->getFieldIndex()) = APValue(IntVal);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155584.541464.patch
Type: text/x-patch
Size: 3270 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230718/59db8af8/attachment.bin>
More information about the cfe-commits
mailing list