[SourceKit] Add type tags for parameters and return types

When the type is not just a reference to a nominal type, we still need
to be able to delineate it.

rdar://problem/24292226
This commit is contained in:
Ben Langmuir
2016-02-25 08:48:22 -08:00
parent 394b731e01
commit 86bc29cfc6
5 changed files with 85 additions and 19 deletions

View File

@@ -103,11 +103,18 @@ private:
// MARK: The ASTPrinter callback interface.
void printDeclPre(const Decl *D) override {
DeclStack.emplace_back(D);
openTag(getTagForDecl(D, /*isRef=*/false));
}
void printDeclPost(const Decl *D) override {
assert(DeclStack.back() == D && "unmatched printDeclPre");
DeclStack.pop_back();
closeTag(getTagForDecl(D, /*isRef=*/false));
}
void avoidPrintDeclPost(const Decl *D) override {
assert(DeclStack.back() == D && "unmatched printDeclPre");
DeclStack.pop_back();
}
void printDeclLoc(const Decl *D) override {
openTag("decl.name");
@@ -116,6 +123,17 @@ private:
closeTag("decl.name");
}
void printTypePre(const TypeLoc &TL) override {
auto tag = getTypeTagForCurrentDecl();
if (!tag.empty())
openTag(tag);
}
void printTypePost(const TypeLoc &TL) override {
auto tag = getTypeTagForCurrentDecl();
if (!tag.empty())
closeTag(tag);
}
void printNamePre(PrintNameContext context) override {
auto tag = getTagForPrintNameContext(context);
if (!tag.empty())
@@ -140,6 +158,31 @@ private:
void openTag(StringRef tag) { OS << "<" << tag << ">"; }
void closeTag(StringRef tag) { OS << "</" << tag << ">"; }
// MARK: Misc.
StringRef getTypeTagForCurrentDecl() const {
if (const Decl *D = currentDecl()) {
switch (D->getKind()) {
case DeclKind::Param:
return "decl.var.parameter.type";
case DeclKind::Func:
return "decl.function.returntype";
default:
break;
}
}
return "";
}
const Decl *currentDecl() const {
return DeclStack.empty() ? nullptr : DeclStack.back();
}
private:
/// A stack of declarations being printed, used to determine the context for
/// other ASTPrinter callbacks.
llvm::SmallVector<const Decl *, 3> DeclStack;
};
static Type findBaseTypeForReplacingArchetype(const ValueDecl *VD, const Type Ty) {