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:
Denis Vnukov
2016-01-25 14:29:55 -08:00
parent 3205d42144
commit 621e1173ce
2 changed files with 56 additions and 13 deletions

View File

@@ -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();