Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 34 additions & 23 deletions interpreter/cling/lib/Interpreter/ForwardDeclPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ namespace cling {
}
}

void ForwardDeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
void ForwardDeclPrinter::printTypedefOrAliasDecl(TypedefNameDecl *D) {
QualType q = D->getTypeSourceInfo()->getType();
Visit(q);
if (m_SkipFlag) {
Expand All @@ -308,34 +308,45 @@ namespace cling {

std::string closeBraces = PrintEnclosingDeclContexts(Out(),
D->getDeclContext());
if (!m_Policy.SuppressSpecifiers)
Out() << "typedef ";
if (D->isModulePrivate())
Out() << "__module_private__ ";
auto printUnderying = [&]() {
QualType qNoRestrict = q;
if (qNoRestrict.isRestrictQualified())
qNoRestrict.removeLocalRestrict();
qNoRestrict.print(Out(), m_Policy);
};
auto printDeclName = [&]() {
if (D->isModulePrivate())
Out() << "__module_private__ ";

if (q.isRestrictQualified()){
q.removeLocalRestrict();
q.print(Out(), m_Policy, "");
Out() << " __restrict " << D->getName(); //TODO: Find some policy that does this automatically
}
else {
q.print(Out(), m_Policy, D->getName());
if (q.isRestrictQualified()) {
Out() << " __restrict "; // TODO: Find some policy that does this automatically
}
Out() << D->getName();
prettyPrintAttributes(D);
};

if (llvm::isa<TypedefDecl>(D)) {
Out() << "typedef ";
printUnderying();
Out() << " ";
printDeclName();
} else if (llvm::isa<TypeAliasDecl>(D)) {
Out() << "using ";
printDeclName();
Out() << " = ";
printUnderying();
} else {
skipDecl(D, "Neither a typedef nor a type alias!");
}
prettyPrintAttributes(D);
Out() << ';' << closeBraces << '\n';
}

void ForwardDeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
printTypedefOrAliasDecl(D);
}

void ForwardDeclPrinter::VisitTypeAliasDecl(TypeAliasDecl *D) {
/*FIXME: Ugly Hack*/
// if(!D->getLexicalDeclContext()->isNamespace()
// && !D->getLexicalDeclContext()->isFileContext())
// return;
std::string closeBraces = PrintEnclosingDeclContexts(Out(),
D->getDeclContext());
Out() << "using " << *D;
prettyPrintAttributes(D);
Out() << " = " << D->getTypeSourceInfo()->getType().getAsString(m_Policy)
<< ';' << closeBraces << '\n';
printTypedefOrAliasDecl(D);
}

void ForwardDeclPrinter::VisitEnumDecl(EnumDecl *D) {
Expand Down
3 changes: 3 additions & 0 deletions interpreter/cling/lib/Interpreter/ForwardDeclPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ namespace clang {
class TranslationUnitDecl;
class TypeAliasDecl;
class TypedefDecl;
class TypedefNameDecl;
class VarDecl;
class UsingDirectiveDecl;
}
Expand Down Expand Up @@ -109,6 +110,8 @@ namespace cling {
std::set<const char*> m_BuiltinNames;
IgnoreFilesFunc_t m_IgnoreFile; // Call back to ignore some top level files.

void printTypedefOrAliasDecl(clang::TypedefNameDecl* D);

public:
ForwardDeclPrinter(llvm::raw_ostream& OutS,
llvm::raw_ostream& LogS,
Expand Down