Skip to content

Commit 8dbbfab

Browse files
committed
AST: add debug locations for generated IntegerLiteralExprs
1 parent fbe83d5 commit 8dbbfab

11 files changed

+25
-25
lines changed

include/swift/AST/Expr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ class IntegerLiteralExpr : public NumberLiteralExpr {
741741
/// \p value The integer value.
742742
/// \return An implicit integer literal expression which evaluates to the value.
743743
static IntegerLiteralExpr *
744-
createFromUnsigned(ASTContext &C, unsigned value);
744+
createFromUnsigned(ASTContext &C, unsigned value, SourceLoc loc);
745745

746746
/// Returns the value of the literal, appropriately constructed in the
747747
/// target type.

lib/AST/Expr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,11 +1036,11 @@ StringRef LiteralExpr::getLiteralKindDescription() const {
10361036
llvm_unreachable("Unhandled literal");
10371037
}
10381038

1039-
IntegerLiteralExpr * IntegerLiteralExpr::createFromUnsigned(ASTContext &C, unsigned value) {
1039+
IntegerLiteralExpr * IntegerLiteralExpr::createFromUnsigned(ASTContext &C, unsigned value, SourceLoc loc) {
10401040
llvm::SmallString<8> Scratch;
10411041
llvm::APInt(sizeof(unsigned)*8, value).toString(Scratch, 10, /*signed*/ false);
10421042
auto Text = C.AllocateCopy(StringRef(Scratch));
1043-
return new (C) IntegerLiteralExpr(Text, SourceLoc(), /*implicit*/ true);
1043+
return new (C) IntegerLiteralExpr(Text, loc, /*implicit*/ true);
10441044
}
10451045

10461046
APInt IntegerLiteralExpr::getRawValue() const {

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2939,7 +2939,7 @@ namespace {
29392939

29402940
// Make the integer literals for the parameters.
29412941
auto buildExprFromUnsigned = [&](unsigned value) {
2942-
LiteralExpr *expr = IntegerLiteralExpr::createFromUnsigned(ctx, value);
2942+
LiteralExpr *expr = IntegerLiteralExpr::createFromUnsigned(ctx, value, loc);
29432943
cs.setType(expr, ctx.getIntType());
29442944
return handleIntegerLiteralExpr(expr);
29452945
};

lib/Sema/DerivedConformanceEquatableHashable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ deriveBodyHashable_enum_hasAssociatedValues_hashInto(
716716

717717
{
718718
// Generate: hasher.combine(<ordinal>)
719-
auto ordinalExpr = IntegerLiteralExpr::createFromUnsigned(C, index++);
719+
auto ordinalExpr = IntegerLiteralExpr::createFromUnsigned(C, index++, SourceLoc());
720720
auto combineExpr = createHasherCombineCall(C, hasherParam, ordinalExpr);
721721
statements.emplace_back(ASTNode(combineExpr));
722722
}

lib/Sema/DerivedConformanceRawRepresentable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ deriveBodyRawRepresentable_init(AbstractFunctionDecl *initDecl, void *) {
321321
// In case of a string enum we are calling the _findStringSwitchCase
322322
// function from the library and switching on the returned Int value.
323323
stringExprs.push_back(litExpr);
324-
litExpr = IntegerLiteralExpr::createFromUnsigned(C, Idx);
324+
litExpr = IntegerLiteralExpr::createFromUnsigned(C, Idx, SourceLoc());
325325
}
326326
auto litPat = new (C) ExprPattern(litExpr, /*isResolved*/ true,
327327
nullptr, nullptr);

lib/Sema/DerivedConformances.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ GuardStmt *DerivedConformance::returnComparisonIfNotEqualGuard(ASTContext &C,
692692
static IntegerLiteralExpr *buildIntegerLiteral(ASTContext &C, unsigned index) {
693693
Type intType = C.getIntType();
694694

695-
auto literal = IntegerLiteralExpr::createFromUnsigned(C, index);
695+
auto literal = IntegerLiteralExpr::createFromUnsigned(C, index, SourceLoc());
696696
literal->setType(intType);
697697
literal->setBuiltinInitializer(C.getIntBuiltinInitDecl(C.getIntDecl()));
698698

lib/Sema/InstrumenterSupport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ bool InstrumenterBase::doTypeCheckImpl(ASTContext &Ctx, DeclContext *DC,
132132
Expr *InstrumenterBase::buildIDArgumentExpr(Optional<DeclNameRef> name,
133133
SourceRange SR) {
134134
if (!name)
135-
return IntegerLiteralExpr::createFromUnsigned(Context, 0);
135+
return IntegerLiteralExpr::createFromUnsigned(Context, 0, SR.End);
136136

137137
return new (Context) UnresolvedDeclRefExpr(*name, DeclRefKind::Ordinary,
138138
DeclNameLoc(SR.End));

lib/Sema/PCMacro.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -552,10 +552,10 @@ class Instrumenter : InstrumenterBase {
552552
Context.SourceMgr.getPresumedLineAndColumnForLoc(
553553
Lexer::getLocForEndOfToken(Context.SourceMgr, SR.End));
554554

555-
Expr *StartLine = IntegerLiteralExpr::createFromUnsigned(Context, StartLC.first);
556-
Expr *EndLine = IntegerLiteralExpr::createFromUnsigned(Context, EndLC.first);
557-
Expr *StartColumn = IntegerLiteralExpr::createFromUnsigned(Context, StartLC.second);
558-
Expr *EndColumn = IntegerLiteralExpr::createFromUnsigned(Context, EndLC.second);
555+
Expr *StartLine = IntegerLiteralExpr::createFromUnsigned(Context, StartLC.first, SR.Start);
556+
Expr *EndLine = IntegerLiteralExpr::createFromUnsigned(Context, EndLC.first, SR.End);
557+
Expr *StartColumn = IntegerLiteralExpr::createFromUnsigned(Context, StartLC.second, SR.Start);
558+
Expr *EndColumn = IntegerLiteralExpr::createFromUnsigned(Context, EndLC.second, SR.End);
559559

560560
Expr *ModuleExpr = buildIDArgumentExpr(ModuleIdentifier, SR);
561561
Expr *FileExpr = buildIDArgumentExpr(FileIdentifier, SR);
@@ -623,10 +623,10 @@ class Instrumenter : InstrumenterBase {
623623
Context.SourceMgr.getPresumedLineAndColumnForLoc(
624624
Lexer::getLocForEndOfToken(Context.SourceMgr, SR.End));
625625

626-
Expr *StartLine = IntegerLiteralExpr::createFromUnsigned(Context, StartLC.first);
627-
Expr *EndLine = IntegerLiteralExpr::createFromUnsigned(Context, EndLC.first);
628-
Expr *StartColumn = IntegerLiteralExpr::createFromUnsigned(Context, StartLC.second);
629-
Expr *EndColumn = IntegerLiteralExpr::createFromUnsigned(Context, EndLC.second);
626+
Expr *StartLine = IntegerLiteralExpr::createFromUnsigned(Context, StartLC.first, SR.Start);
627+
Expr *EndLine = IntegerLiteralExpr::createFromUnsigned(Context, EndLC.first, SR.End);
628+
Expr *StartColumn = IntegerLiteralExpr::createFromUnsigned(Context, StartLC.second, SR.Start);
629+
Expr *EndColumn = IntegerLiteralExpr::createFromUnsigned(Context, EndLC.second, SR.End);
630630

631631
Expr *ModuleExpr = buildIDArgumentExpr(ModuleIdentifier, SR);
632632
Expr *FileExpr = buildIDArgumentExpr(FileIdentifier, SR);

lib/Sema/PlaygroundTransform.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ class Instrumenter : InstrumenterBase {
750750

751751
std::uniform_int_distribution<unsigned> Distribution(0, 0x7fffffffu);
752752
const unsigned id_num = Distribution(RNG);
753-
Expr *IDExpr = IntegerLiteralExpr::createFromUnsigned(Context, id_num);
753+
Expr *IDExpr = IntegerLiteralExpr::createFromUnsigned(Context, id_num, SourceLoc());
754754

755755
return buildLoggerCallWithArgs(LogWithIDName, { *E, NameExpr, IDExpr }, SR);
756756
}
@@ -779,10 +779,10 @@ class Instrumenter : InstrumenterBase {
779779
Context.SourceMgr.getPresumedLineAndColumnForLoc(
780780
Lexer::getLocForEndOfToken(Context.SourceMgr, SR.End));
781781

782-
Expr *StartLine = IntegerLiteralExpr::createFromUnsigned(Context, StartLC.first);
783-
Expr *EndLine = IntegerLiteralExpr::createFromUnsigned(Context, EndLC.first);
784-
Expr *StartColumn = IntegerLiteralExpr::createFromUnsigned(Context, StartLC.second);
785-
Expr *EndColumn = IntegerLiteralExpr::createFromUnsigned(Context, EndLC.second);
782+
Expr *StartLine = IntegerLiteralExpr::createFromUnsigned(Context, StartLC.first, SR.Start);
783+
Expr *EndLine = IntegerLiteralExpr::createFromUnsigned(Context, EndLC.first, SR.End);
784+
Expr *StartColumn = IntegerLiteralExpr::createFromUnsigned(Context, StartLC.second, SR.Start);
785+
Expr *EndColumn = IntegerLiteralExpr::createFromUnsigned(Context, EndLC.second, SR.End);
786786

787787
Expr *ModuleExpr = buildIDArgumentExpr(ModuleIdentifier, SR);
788788
Expr *FileExpr = buildIDArgumentExpr(FileIdentifier, SR);

unittests/Sema/BindingInferenceTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ TEST_F(SemaTest, TestIntLiteralBindingInference) {
2727

2828
ConstraintSystem cs(DC, options);
2929

30-
auto *intLiteral = IntegerLiteralExpr::createFromUnsigned(Context, 42);
30+
auto *intLiteral = IntegerLiteralExpr::createFromUnsigned(Context, 42, SourceLoc());
3131

3232
auto *literalTy = cs.createTypeVariable(cs.getConstraintLocator(intLiteral),
3333
/*options=*/0);

unittests/Sema/ConstraintGenerationTests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static Type getTypeOfCoercedExpr(ExplicitCastExpr *castExpr) {
3333
TEST_F(SemaTest, TestImplicitForceCastConstraintGeneration) {
3434
ConstraintSystem cs(DC, ConstraintSystemOptions());
3535

36-
auto *literal = IntegerLiteralExpr::createFromUnsigned(Context, 42);
36+
auto *literal = IntegerLiteralExpr::createFromUnsigned(Context, 42, SourceLoc());
3737

3838
auto *castExpr = ForcedCheckedCastExpr::createImplicit(Context, literal,
3939
Context.TheAnyType);
@@ -61,7 +61,7 @@ TEST_F(SemaTest, TestImplicitForceCastConstraintGeneration) {
6161
TEST_F(SemaTest, TestImplicitCoercionConstraintGeneration) {
6262
ConstraintSystem cs(DC, ConstraintSystemOptions());
6363

64-
auto *literal = IntegerLiteralExpr::createFromUnsigned(Context, 42);
64+
auto *literal = IntegerLiteralExpr::createFromUnsigned(Context, 42, SourceLoc());
6565

6666
auto *castExpr = CoerceExpr::createImplicit(Context, literal,
6767
getStdlibType("Double"));
@@ -90,7 +90,7 @@ TEST_F(SemaTest, TestImplicitCoercionConstraintGeneration) {
9090
TEST_F(SemaTest, TestImplicitConditionalCastConstraintGeneration) {
9191
ConstraintSystem cs(DC, ConstraintSystemOptions());
9292

93-
auto *literal = IntegerLiteralExpr::createFromUnsigned(Context, 42);
93+
auto *literal = IntegerLiteralExpr::createFromUnsigned(Context, 42, SourceLoc());
9494

9595
auto *castExpr = ConditionalCheckedCastExpr::createImplicit(
9696
Context, literal, getStdlibType("Double"));

0 commit comments

Comments
 (0)