mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user