mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Preserving source range of PBD entry's original initialization.
After typechecking removes the initializer from the var there was no way to restore information about the original source range of the declaration.
This commit is contained in:
@@ -1018,6 +1018,17 @@ PatternBindingDecl::PatternBindingDecl(SourceLoc StaticLoc,
|
||||
static_cast<unsigned>(StaticSpelling);
|
||||
}
|
||||
|
||||
PatternBindingDecl *
|
||||
PatternBindingDecl::create(ASTContext &Ctx, SourceLoc StaticLoc,
|
||||
StaticSpellingKind StaticSpelling,
|
||||
SourceLoc VarLoc,
|
||||
Pattern *Pat, Expr *E,
|
||||
DeclContext *Parent) {
|
||||
return create(Ctx, StaticLoc, StaticSpelling, VarLoc,
|
||||
PatternBindingEntry(Pat, E),
|
||||
Parent);
|
||||
}
|
||||
|
||||
PatternBindingDecl *
|
||||
PatternBindingDecl::create(ASTContext &Ctx, SourceLoc StaticLoc,
|
||||
StaticSpellingKind StaticSpelling,
|
||||
@@ -1037,7 +1048,7 @@ PatternBindingDecl::create(ASTContext &Ctx, SourceLoc StaticLoc,
|
||||
for (auto pe : PatternList) {
|
||||
++elt;
|
||||
auto &newEntry = entries[elt];
|
||||
newEntry = { nullptr, pe.getInit() };
|
||||
newEntry = pe; // This should take care of initializer with flags
|
||||
PBD->setPattern(elt, pe.getPattern());
|
||||
}
|
||||
return PBD;
|
||||
@@ -1072,6 +1083,20 @@ unsigned PatternBindingDecl::getPatternEntryIndexForVarDecl(const VarDecl *VD) c
|
||||
return ~0U;
|
||||
}
|
||||
|
||||
SourceRange PatternBindingEntry::getOrigInitRange() const {
|
||||
auto Init = InitCheckedAndRemoved.getPointer();
|
||||
return Init ? Init->getSourceRange() : SourceRange();
|
||||
}
|
||||
|
||||
void PatternBindingEntry::setInit(Expr *E) {
|
||||
auto F = InitCheckedAndRemoved.getInt();
|
||||
if (E) {
|
||||
InitCheckedAndRemoved.setInt(F - Flags::Removed);
|
||||
InitCheckedAndRemoved.setPointer(E);
|
||||
} else {
|
||||
InitCheckedAndRemoved.setInt(F | Flags::Removed);
|
||||
}
|
||||
}
|
||||
|
||||
SourceRange PatternBindingDecl::getSourceRange() const {
|
||||
SourceLoc startLoc = getStartLoc();
|
||||
|
||||
Reference in New Issue
Block a user