Merge pull request #6628 from nkcsgexi/synthesized-target-check

This commit is contained in:
swift-ci
2017-01-06 17:28:11 -08:00
committed by GitHub
4 changed files with 469 additions and 296 deletions

View File

@@ -97,7 +97,9 @@ struct TextReference {
};
class AnnotatingPrinter : public StreamPrinter {
const NominalTypeDecl *SynthesizeTarget = nullptr;
std::pair<const ExtensionDecl *, const NominalTypeDecl *>
SynthesizedExtensionInfo = {nullptr, nullptr};
typedef llvm::SmallDenseMap<ValueDecl*, ValueDecl*> DefaultImplementMap;
llvm::SmallDenseMap<ProtocolDecl*, DefaultImplementMap> AllDefaultMaps;
@@ -170,19 +172,20 @@ public:
void printSynthesizedExtensionPre(const ExtensionDecl *ED,
const NominalTypeDecl *NTD,
Optional<BracketOptions> Bracket) override {
assert(!SynthesizeTarget);
SynthesizeTarget = NTD;
assert(!SynthesizedExtensionInfo.first);
SynthesizedExtensionInfo = {ED, NTD};
if (!shouldContinuePre(ED, Bracket))
return;
unsigned StartOffset = OS.tell();
EntitiesStack.emplace_back(ED, SynthesizeTarget, nullptr, StartOffset, true);
EntitiesStack.emplace_back(ED, SynthesizedExtensionInfo.second, nullptr,
StartOffset, true);
}
void printSynthesizedExtensionPost(const ExtensionDecl *ED,
const NominalTypeDecl *NTD,
Optional<BracketOptions> Bracket) override {
assert(SynthesizeTarget);
SynthesizeTarget = nullptr;
assert(SynthesizedExtensionInfo.first);
SynthesizedExtensionInfo = {nullptr, nullptr};
if (!shouldContinuePost(ED, Bracket))
return;
TextEntity Entity = std::move(EntitiesStack.back());
@@ -199,8 +202,12 @@ public:
return;
unsigned StartOffset = OS.tell();
initDefaultMapToUse(D);
EntitiesStack.emplace_back(D, SynthesizeTarget, getDefaultImplementation(D),
StartOffset, false);
const NominalTypeDecl *SynthesizedTarget = nullptr;
// If D is declared in the extension, then the synthesized target is valid.
if (D->getDeclContext() == SynthesizedExtensionInfo.first)
SynthesizedTarget = SynthesizedExtensionInfo.second;
EntitiesStack.emplace_back(D, SynthesizedTarget,
getDefaultImplementation(D), StartOffset, false);
}
void printDeclLoc(const Decl *D) override {