Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1 | //===--- DeclPrinter.cpp - Printing implementation for Decl ASTs ----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 10 | // This file implements the Decl::print method, which pretty prints the |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 11 | // AST back out to C/Objective-C/C++/Objective-C++ code. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | #include "clang/AST/ASTContext.h" |
Benjamin Kramer | ea70eb3 | 2012-12-01 15:09:41 +0000 | [diff] [blame] | 15 | #include "clang/AST/Attr.h" |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 16 | #include "clang/AST/Decl.h" |
| 17 | #include "clang/AST/DeclCXX.h" |
| 18 | #include "clang/AST/DeclObjC.h" |
Benjamin Kramer | ea70eb3 | 2012-12-01 15:09:41 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclVisitor.h" |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 20 | #include "clang/AST/Expr.h" |
Douglas Gregor | 7ae2d77 | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 21 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 22 | #include "clang/AST/PrettyPrinter.h" |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 23 | #include "clang/Basic/Module.h" |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 24 | #include "llvm/Support/raw_ostream.h" |
| 25 | using namespace clang; |
| 26 | |
| 27 | namespace { |
Benjamin Kramer | 26222b6 | 2009-11-28 19:03:38 +0000 | [diff] [blame] | 28 | class DeclPrinter : public DeclVisitor<DeclPrinter> { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 29 | raw_ostream &Out; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 30 | PrintingPolicy Policy; |
| 31 | unsigned Indentation; |
Richard Trieu | 82398f9 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 32 | bool PrintInstantiation; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 33 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 34 | raw_ostream& Indent() { return Indent(Indentation); } |
| 35 | raw_ostream& Indent(unsigned Indentation); |
| 36 | void ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 37 | |
Anders Carlsson | 601d6e4 | 2009-08-28 22:39:52 +0000 | [diff] [blame] | 38 | void Print(AccessSpecifier AS); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 39 | |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 40 | /// Print an Objective-C method type in parentheses. |
| 41 | /// |
| 42 | /// \param Quals The Objective-C declaration qualifiers. |
| 43 | /// \param T The type to print. |
| 44 | void PrintObjCMethodType(ASTContext &Ctx, Decl::ObjCDeclQualifier Quals, |
| 45 | QualType T); |
| 46 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 47 | void PrintObjCTypeParams(ObjCTypeParamList *Params); |
| 48 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 49 | public: |
Richard Smith | 235341b | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 50 | DeclPrinter(raw_ostream &Out, const PrintingPolicy &Policy, |
| 51 | unsigned Indentation = 0, bool PrintInstantiation = false) |
| 52 | : Out(Out), Policy(Policy), Indentation(Indentation), |
Richard Trieu | 82398f9 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 53 | PrintInstantiation(PrintInstantiation) { } |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 54 | |
| 55 | void VisitDeclContext(DeclContext *DC, bool Indent = true); |
| 56 | |
| 57 | void VisitTranslationUnitDecl(TranslationUnitDecl *D); |
| 58 | void VisitTypedefDecl(TypedefDecl *D); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 59 | void VisitTypeAliasDecl(TypeAliasDecl *D); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 60 | void VisitEnumDecl(EnumDecl *D); |
| 61 | void VisitRecordDecl(RecordDecl *D); |
| 62 | void VisitEnumConstantDecl(EnumConstantDecl *D); |
Michael Han | 8432435 | 2013-02-22 17:15:32 +0000 | [diff] [blame] | 63 | void VisitEmptyDecl(EmptyDecl *D); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 64 | void VisitFunctionDecl(FunctionDecl *D); |
Fariborz Jahanian | bfc3ef5 | 2012-12-05 00:38:44 +0000 | [diff] [blame] | 65 | void VisitFriendDecl(FriendDecl *D); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 66 | void VisitFieldDecl(FieldDecl *D); |
| 67 | void VisitVarDecl(VarDecl *D); |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 68 | void VisitLabelDecl(LabelDecl *D); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 69 | void VisitParmVarDecl(ParmVarDecl *D); |
| 70 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *D); |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 71 | void VisitImportDecl(ImportDecl *D); |
Peter Collingbourne | 7d8a0b5 | 2011-03-16 18:37:27 +0000 | [diff] [blame] | 72 | void VisitStaticAssertDecl(StaticAssertDecl *D); |
Douglas Gregor | 5f478b7 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 73 | void VisitNamespaceDecl(NamespaceDecl *D); |
Douglas Gregor | 3bc6e4c | 2009-05-30 06:31:56 +0000 | [diff] [blame] | 74 | void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
Douglas Gregor | 1823193 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 75 | void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Douglas Gregor | 5f478b7 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 76 | void VisitCXXRecordDecl(CXXRecordDecl *D); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 77 | void VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Richard Smith | 030f499 | 2011-04-15 13:38:57 +0000 | [diff] [blame] | 78 | void VisitTemplateDecl(const TemplateDecl *D); |
Richard Trieu | 82398f9 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 79 | void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
| 80 | void VisitClassTemplateDecl(ClassTemplateDecl *D); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 81 | void VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 82 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 83 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 84 | void VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 85 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 86 | void VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 87 | void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); |
| 88 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 89 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
John McCall | e61f2ba | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 90 | void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
| 91 | void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
Anders Carlsson | df5a1c8 | 2009-08-28 19:16:39 +0000 | [diff] [blame] | 92 | void VisitUsingDecl(UsingDecl *D); |
John McCall | 3f74682 | 2009-11-17 05:59:44 +0000 | [diff] [blame] | 93 | void VisitUsingShadowDecl(UsingShadowDecl *D); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 94 | void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D); |
Richard Trieu | 82398f9 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 95 | |
| 96 | void PrintTemplateParameters(const TemplateParameterList *Params, |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 97 | const TemplateArgumentList *Args = nullptr); |
Douglas Gregor | 49ccfaa | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 98 | void prettyPrintAttributes(Decl *D); |
Alexey Bataev | 6d45532 | 2015-10-12 06:59:48 +0000 | [diff] [blame] | 99 | void prettyPrintPragmas(Decl *D); |
Richard Smith | a4bb292 | 2014-07-23 03:17:06 +0000 | [diff] [blame] | 100 | void printDeclType(QualType T, StringRef DeclName, bool Pack = false); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 101 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 102 | } |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 103 | |
Richard Trieu | 82398f9 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 104 | void Decl::print(raw_ostream &Out, unsigned Indentation, |
| 105 | bool PrintInstantiation) const { |
Douglas Gregor | c0b0728 | 2011-09-27 22:38:19 +0000 | [diff] [blame] | 106 | print(Out, getASTContext().getPrintingPolicy(), Indentation, PrintInstantiation); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 109 | void Decl::print(raw_ostream &Out, const PrintingPolicy &Policy, |
Richard Trieu | 82398f9 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 110 | unsigned Indentation, bool PrintInstantiation) const { |
Richard Smith | 235341b | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 111 | DeclPrinter Printer(Out, Policy, Indentation, PrintInstantiation); |
Anders Carlsson | 46f87dc | 2009-09-26 21:58:53 +0000 | [diff] [blame] | 112 | Printer.Visit(const_cast<Decl*>(this)); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 115 | static QualType GetBaseType(QualType T) { |
| 116 | // FIXME: This should be on the Type class! |
| 117 | QualType BaseType = T; |
| 118 | while (!BaseType->isSpecifierType()) { |
| 119 | if (isa<TypedefType>(BaseType)) |
| 120 | break; |
Ted Kremenek | c23c7e6 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 121 | else if (const PointerType* PTy = BaseType->getAs<PointerType>()) |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 122 | BaseType = PTy->getPointeeType(); |
Ted Kremenek | fa0a0b6 | 2012-10-11 20:58:14 +0000 | [diff] [blame] | 123 | else if (const BlockPointerType *BPy = BaseType->getAs<BlockPointerType>()) |
| 124 | BaseType = BPy->getPointeeType(); |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 125 | else if (const ArrayType* ATy = dyn_cast<ArrayType>(BaseType)) |
| 126 | BaseType = ATy->getElementType(); |
John McCall | 9dd450b | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 127 | else if (const FunctionType* FTy = BaseType->getAs<FunctionType>()) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 128 | BaseType = FTy->getReturnType(); |
John McCall | 9dd450b | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 129 | else if (const VectorType *VTy = BaseType->getAs<VectorType>()) |
Douglas Gregor | 1554825 | 2009-07-01 23:58:14 +0000 | [diff] [blame] | 130 | BaseType = VTy->getElementType(); |
Eli Friedman | 70bc6e6 | 2012-08-08 03:47:15 +0000 | [diff] [blame] | 131 | else if (const ReferenceType *RTy = BaseType->getAs<ReferenceType>()) |
| 132 | BaseType = RTy->getPointeeType(); |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 133 | else |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 134 | llvm_unreachable("Unknown declarator!"); |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 135 | } |
| 136 | return BaseType; |
| 137 | } |
| 138 | |
| 139 | static QualType getDeclType(Decl* D) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 140 | if (TypedefNameDecl* TDD = dyn_cast<TypedefNameDecl>(D)) |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 141 | return TDD->getUnderlyingType(); |
| 142 | if (ValueDecl* VD = dyn_cast<ValueDecl>(D)) |
| 143 | return VD->getType(); |
| 144 | return QualType(); |
| 145 | } |
| 146 | |
| 147 | void Decl::printGroup(Decl** Begin, unsigned NumDecls, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 148 | raw_ostream &Out, const PrintingPolicy &Policy, |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 149 | unsigned Indentation) { |
| 150 | if (NumDecls == 1) { |
Argyrios Kyrtzidis | 8a803cc | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 151 | (*Begin)->print(Out, Policy, Indentation); |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 152 | return; |
| 153 | } |
| 154 | |
| 155 | Decl** End = Begin + NumDecls; |
| 156 | TagDecl* TD = dyn_cast<TagDecl>(*Begin); |
| 157 | if (TD) |
| 158 | ++Begin; |
| 159 | |
| 160 | PrintingPolicy SubPolicy(Policy); |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 161 | if (TD && TD->isCompleteDefinition()) { |
Argyrios Kyrtzidis | 8a803cc | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 162 | TD->print(Out, Policy, Indentation); |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 163 | Out << " "; |
| 164 | SubPolicy.SuppressTag = true; |
| 165 | } |
| 166 | |
| 167 | bool isFirst = true; |
| 168 | for ( ; Begin != End; ++Begin) { |
| 169 | if (isFirst) { |
| 170 | SubPolicy.SuppressSpecifiers = false; |
| 171 | isFirst = false; |
| 172 | } else { |
| 173 | if (!isFirst) Out << ", "; |
| 174 | SubPolicy.SuppressSpecifiers = true; |
| 175 | } |
| 176 | |
Argyrios Kyrtzidis | 8a803cc | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 177 | (*Begin)->print(Out, SubPolicy, Indentation); |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | |
Alp Toker | ef6b007 | 2014-01-04 13:47:14 +0000 | [diff] [blame] | 181 | LLVM_DUMP_METHOD void DeclContext::dumpDeclContext() const { |
Anders Carlsson | 538af09 | 2009-12-09 17:27:46 +0000 | [diff] [blame] | 182 | // Get the translation unit |
| 183 | const DeclContext *DC = this; |
| 184 | while (!DC->isTranslationUnit()) |
| 185 | DC = DC->getParent(); |
| 186 | |
| 187 | ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext(); |
Richard Smith | 235341b | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 188 | DeclPrinter Printer(llvm::errs(), Ctx.getPrintingPolicy(), 0); |
Anders Carlsson | 538af09 | 2009-12-09 17:27:46 +0000 | [diff] [blame] | 189 | Printer.VisitDeclContext(const_cast<DeclContext *>(this), /*Indent=*/false); |
| 190 | } |
| 191 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 192 | raw_ostream& DeclPrinter::Indent(unsigned Indentation) { |
Daniel Dunbar | 671f45e | 2009-11-21 09:12:06 +0000 | [diff] [blame] | 193 | for (unsigned i = 0; i != Indentation; ++i) |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 194 | Out << " "; |
| 195 | return Out; |
| 196 | } |
| 197 | |
Douglas Gregor | 49ccfaa | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 198 | void DeclPrinter::prettyPrintAttributes(Decl *D) { |
Fariborz Jahanian | 0389e52 | 2012-12-19 23:36:00 +0000 | [diff] [blame] | 199 | if (Policy.PolishForDeclaration) |
Fariborz Jahanian | a7d76d2 | 2012-10-17 21:58:03 +0000 | [diff] [blame] | 200 | return; |
Alexey Bataev | 6d45532 | 2015-10-12 06:59:48 +0000 | [diff] [blame] | 201 | |
Douglas Gregor | 49ccfaa | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 202 | if (D->hasAttrs()) { |
| 203 | AttrVec &Attrs = D->getAttrs(); |
Alexey Bataev | 6d45532 | 2015-10-12 06:59:48 +0000 | [diff] [blame] | 204 | for (auto *A : Attrs) { |
| 205 | switch (A->getKind()) { |
| 206 | #define ATTR(X) |
| 207 | #define PRAGMA_SPELLING_ATTR(X) case attr::X: |
| 208 | #include "clang/Basic/AttrList.inc" |
| 209 | break; |
| 210 | default: |
| 211 | A->printPretty(Out, Policy); |
| 212 | break; |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | void DeclPrinter::prettyPrintPragmas(Decl *D) { |
| 219 | if (Policy.PolishForDeclaration) |
| 220 | return; |
| 221 | |
| 222 | if (D->hasAttrs()) { |
| 223 | AttrVec &Attrs = D->getAttrs(); |
| 224 | for (auto *A : Attrs) { |
| 225 | switch (A->getKind()) { |
| 226 | #define ATTR(X) |
| 227 | #define PRAGMA_SPELLING_ATTR(X) case attr::X: |
| 228 | #include "clang/Basic/AttrList.inc" |
| 229 | A->printPretty(Out, Policy); |
| 230 | Indent(); |
| 231 | break; |
| 232 | default: |
| 233 | break; |
| 234 | } |
Douglas Gregor | 49ccfaa | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
Richard Smith | a4bb292 | 2014-07-23 03:17:06 +0000 | [diff] [blame] | 239 | void DeclPrinter::printDeclType(QualType T, StringRef DeclName, bool Pack) { |
| 240 | // Normally, a PackExpansionType is written as T[3]... (for instance, as a |
| 241 | // template argument), but if it is the type of a declaration, the ellipsis |
| 242 | // is placed before the name being declared. |
| 243 | if (auto *PET = T->getAs<PackExpansionType>()) { |
| 244 | Pack = true; |
| 245 | T = PET->getPattern(); |
| 246 | } |
| 247 | T.print(Out, Policy, (Pack ? "..." : "") + DeclName); |
| 248 | } |
| 249 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 250 | void DeclPrinter::ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls) { |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 251 | this->Indent(); |
Argyrios Kyrtzidis | 8a803cc | 2009-06-30 02:35:04 +0000 | [diff] [blame] | 252 | Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation); |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 253 | Out << ";\n"; |
| 254 | Decls.clear(); |
| 255 | |
| 256 | } |
| 257 | |
Anders Carlsson | 601d6e4 | 2009-08-28 22:39:52 +0000 | [diff] [blame] | 258 | void DeclPrinter::Print(AccessSpecifier AS) { |
| 259 | switch(AS) { |
David Blaikie | aa347f9 | 2011-09-23 20:26:49 +0000 | [diff] [blame] | 260 | case AS_none: llvm_unreachable("No access specifier!"); |
Anders Carlsson | 601d6e4 | 2009-08-28 22:39:52 +0000 | [diff] [blame] | 261 | case AS_public: Out << "public"; break; |
| 262 | case AS_protected: Out << "protected"; break; |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 263 | case AS_private: Out << "private"; break; |
Anders Carlsson | 601d6e4 | 2009-08-28 22:39:52 +0000 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 267 | //---------------------------------------------------------------------------- |
| 268 | // Common C declarations |
| 269 | //---------------------------------------------------------------------------- |
| 270 | |
| 271 | void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) { |
Dmitri Gribenko | a93a7e8 | 2012-08-21 17:36:32 +0000 | [diff] [blame] | 272 | if (Policy.TerseOutput) |
Dmitri Gribenko | 309856a | 2012-08-20 23:39:06 +0000 | [diff] [blame] | 273 | return; |
| 274 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 275 | if (Indent) |
| 276 | Indentation += Policy.Indentation; |
| 277 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 278 | SmallVector<Decl*, 2> Decls; |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 279 | for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end(); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 280 | D != DEnd; ++D) { |
Ted Kremenek | 28e1c91 | 2010-07-30 00:47:46 +0000 | [diff] [blame] | 281 | |
| 282 | // Don't print ObjCIvarDecls, as they are printed when visiting the |
| 283 | // containing ObjCInterfaceDecl. |
| 284 | if (isa<ObjCIvarDecl>(*D)) |
| 285 | continue; |
| 286 | |
Alexander Kornienko | 90ff607 | 2012-12-20 02:09:13 +0000 | [diff] [blame] | 287 | // Skip over implicit declarations in pretty-printing mode. |
| 288 | if (D->isImplicit()) |
| 289 | continue; |
| 290 | |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 291 | // The next bits of code handles stuff like "struct {int x;} a,b"; we're |
| 292 | // forced to merge the declarations because there's no other way to |
| 293 | // refer to the struct in question. This limited merging is safe without |
| 294 | // a bunch of other checks because it only merges declarations directly |
| 295 | // referring to the tag, not typedefs. |
| 296 | // |
| 297 | // Check whether the current declaration should be grouped with a previous |
| 298 | // unnamed struct. |
| 299 | QualType CurDeclType = getDeclType(*D); |
| 300 | if (!Decls.empty() && !CurDeclType.isNull()) { |
| 301 | QualType BaseType = GetBaseType(CurDeclType); |
Eli Friedman | 24b3fed | 2013-08-12 21:54:04 +0000 | [diff] [blame] | 302 | if (!BaseType.isNull() && isa<ElaboratedType>(BaseType)) |
| 303 | BaseType = cast<ElaboratedType>(BaseType)->getNamedType(); |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 304 | if (!BaseType.isNull() && isa<TagType>(BaseType) && |
| 305 | cast<TagType>(BaseType)->getDecl() == Decls[0]) { |
| 306 | Decls.push_back(*D); |
| 307 | continue; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | // If we have a merged group waiting to be handled, handle it now. |
| 312 | if (!Decls.empty()) |
| 313 | ProcessDeclGroup(Decls); |
| 314 | |
| 315 | // If the current declaration is an unnamed tag type, save it |
| 316 | // so we can merge it with the subsequent declaration(s) using it. |
| 317 | if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->getIdentifier()) { |
| 318 | Decls.push_back(*D); |
| 319 | continue; |
| 320 | } |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 321 | |
| 322 | if (isa<AccessSpecDecl>(*D)) { |
| 323 | Indentation -= Policy.Indentation; |
| 324 | this->Indent(); |
| 325 | Print(D->getAccess()); |
| 326 | Out << ":\n"; |
| 327 | Indentation += Policy.Indentation; |
| 328 | continue; |
| 329 | } |
| 330 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 331 | this->Indent(); |
| 332 | Visit(*D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 333 | |
| 334 | // FIXME: Need to be able to tell the DeclPrinter when |
Yaron Keren | 51db877 | 2014-05-07 09:53:02 +0000 | [diff] [blame] | 335 | const char *Terminator = nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 336 | if (isa<OMPThreadPrivateDecl>(*D)) |
Yaron Keren | 51db877 | 2014-05-07 09:53:02 +0000 | [diff] [blame] | 337 | Terminator = nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 338 | else if (isa<FunctionDecl>(*D) && |
| 339 | cast<FunctionDecl>(*D)->isThisDeclarationADefinition()) |
Yaron Keren | 51db877 | 2014-05-07 09:53:02 +0000 | [diff] [blame] | 340 | Terminator = nullptr; |
Douglas Gregor | 36098ff | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 341 | else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->getBody()) |
Yaron Keren | 51db877 | 2014-05-07 09:53:02 +0000 | [diff] [blame] | 342 | Terminator = nullptr; |
Douglas Gregor | 36098ff | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 343 | else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) || |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 344 | isa<ObjCImplementationDecl>(*D) || |
Douglas Gregor | 36098ff | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 345 | isa<ObjCInterfaceDecl>(*D) || |
| 346 | isa<ObjCProtocolDecl>(*D) || |
| 347 | isa<ObjCCategoryImplDecl>(*D) || |
| 348 | isa<ObjCCategoryDecl>(*D)) |
Yaron Keren | 51db877 | 2014-05-07 09:53:02 +0000 | [diff] [blame] | 349 | Terminator = nullptr; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 350 | else if (isa<EnumConstantDecl>(*D)) { |
| 351 | DeclContext::decl_iterator Next = D; |
| 352 | ++Next; |
| 353 | if (Next != DEnd) |
| 354 | Terminator = ","; |
| 355 | } else |
| 356 | Terminator = ";"; |
| 357 | |
| 358 | if (Terminator) |
| 359 | Out << Terminator; |
| 360 | Out << "\n"; |
| 361 | } |
| 362 | |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 363 | if (!Decls.empty()) |
| 364 | ProcessDeclGroup(Decls); |
| 365 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 366 | if (Indent) |
| 367 | Indentation -= Policy.Indentation; |
| 368 | } |
| 369 | |
| 370 | void DeclPrinter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 371 | VisitDeclContext(D, false); |
| 372 | } |
| 373 | |
| 374 | void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) { |
Douglas Gregor | 26701a4 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 375 | if (!Policy.SuppressSpecifiers) { |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 376 | Out << "typedef "; |
Douglas Gregor | 26701a4 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 377 | |
| 378 | if (D->isModulePrivate()) |
| 379 | Out << "__module_private__ "; |
| 380 | } |
Enea Zaffanella | a86d88c | 2013-06-20 12:46:19 +0000 | [diff] [blame] | 381 | D->getTypeSourceInfo()->getType().print(Out, Policy, D->getName()); |
Douglas Gregor | 49ccfaa | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 382 | prettyPrintAttributes(D); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 383 | } |
| 384 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 385 | void DeclPrinter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
Enea Zaffanella | a86d88c | 2013-06-20 12:46:19 +0000 | [diff] [blame] | 386 | Out << "using " << *D; |
| 387 | prettyPrintAttributes(D); |
| 388 | Out << " = " << D->getTypeSourceInfo()->getType().getAsString(Policy); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 389 | } |
| 390 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 391 | void DeclPrinter::VisitEnumDecl(EnumDecl *D) { |
Douglas Gregor | 26701a4 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 392 | if (!Policy.SuppressSpecifiers && D->isModulePrivate()) |
| 393 | Out << "__module_private__ "; |
Douglas Gregor | ec0e366 | 2010-12-01 16:01:08 +0000 | [diff] [blame] | 394 | Out << "enum "; |
Abramo Bagnara | 0e05e24 | 2010-12-03 18:54:17 +0000 | [diff] [blame] | 395 | if (D->isScoped()) { |
| 396 | if (D->isScopedUsingClassTag()) |
| 397 | Out << "class "; |
| 398 | else |
| 399 | Out << "struct "; |
| 400 | } |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 401 | Out << *D; |
Douglas Gregor | ec0e366 | 2010-12-01 16:01:08 +0000 | [diff] [blame] | 402 | |
Argyrios Kyrtzidis | a18347e | 2012-05-05 04:20:37 +0000 | [diff] [blame] | 403 | if (D->isFixed()) |
| 404 | Out << " : " << D->getIntegerType().stream(Policy); |
Douglas Gregor | ec0e366 | 2010-12-01 16:01:08 +0000 | [diff] [blame] | 405 | |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 406 | if (D->isCompleteDefinition()) { |
Douglas Gregor | ec0e366 | 2010-12-01 16:01:08 +0000 | [diff] [blame] | 407 | Out << " {\n"; |
| 408 | VisitDeclContext(D); |
| 409 | Indent() << "}"; |
| 410 | } |
Douglas Gregor | 49ccfaa | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 411 | prettyPrintAttributes(D); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | void DeclPrinter::VisitRecordDecl(RecordDecl *D) { |
Douglas Gregor | 26701a4 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 415 | if (!Policy.SuppressSpecifiers && D->isModulePrivate()) |
| 416 | Out << "__module_private__ "; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 417 | Out << D->getKindName(); |
Aaron Ballman | 5388538 | 2014-09-15 16:45:30 +0000 | [diff] [blame] | 418 | |
| 419 | prettyPrintAttributes(D); |
| 420 | |
Benjamin Kramer | b11416d | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 421 | if (D->getIdentifier()) |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 422 | Out << ' ' << *D; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 423 | |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 424 | if (D->isCompleteDefinition()) { |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 425 | Out << " {\n"; |
| 426 | VisitDeclContext(D); |
| 427 | Indent() << "}"; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 432 | Out << *D; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 433 | if (Expr *Init = D->getInitExpr()) { |
| 434 | Out << " = "; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 435 | Init->printPretty(Out, nullptr, Policy, Indentation); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 439 | void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { |
Alexey Bataev | 6d45532 | 2015-10-12 06:59:48 +0000 | [diff] [blame] | 440 | if (!D->getDescribedFunctionTemplate() && |
| 441 | !D->isFunctionTemplateSpecialization()) |
| 442 | prettyPrintPragmas(D); |
| 443 | |
Fariborz Jahanian | 69c403c | 2012-12-05 22:19:06 +0000 | [diff] [blame] | 444 | CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D); |
Benjamin Kramer | 00e8a19 | 2014-02-25 18:03:55 +0000 | [diff] [blame] | 445 | CXXConversionDecl *ConversionDecl = dyn_cast<CXXConversionDecl>(D); |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 446 | if (!Policy.SuppressSpecifiers) { |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 447 | switch (D->getStorageClass()) { |
John McCall | 8e7d656 | 2010-08-26 03:08:43 +0000 | [diff] [blame] | 448 | case SC_None: break; |
| 449 | case SC_Extern: Out << "extern "; break; |
| 450 | case SC_Static: Out << "static "; break; |
| 451 | case SC_PrivateExtern: Out << "__private_extern__ "; break; |
Anastasia Stulova | bcea696 | 2015-09-30 14:08:20 +0000 | [diff] [blame] | 452 | case SC_Auto: case SC_Register: |
Peter Collingbourne | 2dbb708 | 2011-09-19 21:14:35 +0000 | [diff] [blame] | 453 | llvm_unreachable("invalid for functions"); |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 454 | } |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 455 | |
Douglas Gregor | 26701a4 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 456 | if (D->isInlineSpecified()) Out << "inline "; |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 457 | if (D->isVirtualAsWritten()) Out << "virtual "; |
Douglas Gregor | 26701a4 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 458 | if (D->isModulePrivate()) Out << "__module_private__ "; |
Benjamin Kramer | 2907b08 | 2014-02-25 18:49:49 +0000 | [diff] [blame] | 459 | if (D->isConstexpr() && !D->isExplicitlyDefaulted()) Out << "constexpr "; |
Benjamin Kramer | 00e8a19 | 2014-02-25 18:03:55 +0000 | [diff] [blame] | 460 | if ((CDecl && CDecl->isExplicitSpecified()) || |
| 461 | (ConversionDecl && ConversionDecl->isExplicit())) |
Fariborz Jahanian | 69c403c | 2012-12-05 22:19:06 +0000 | [diff] [blame] | 462 | Out << "explicit "; |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 463 | } |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 464 | |
Douglas Gregor | 2d042f1 | 2009-05-30 05:39:39 +0000 | [diff] [blame] | 465 | PrintingPolicy SubPolicy(Policy); |
| 466 | SubPolicy.SuppressSpecifiers = false; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 467 | std::string Proto = D->getNameInfo().getAsString(); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 468 | |
Abramo Bagnara | 6d81063 | 2010-12-14 22:11:44 +0000 | [diff] [blame] | 469 | QualType Ty = D->getType(); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 470 | while (const ParenType *PT = dyn_cast<ParenType>(Ty)) { |
Abramo Bagnara | 6d81063 | 2010-12-14 22:11:44 +0000 | [diff] [blame] | 471 | Proto = '(' + Proto + ')'; |
| 472 | Ty = PT->getInnerType(); |
| 473 | } |
| 474 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 475 | if (const FunctionType *AFT = Ty->getAs<FunctionType>()) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 476 | const FunctionProtoType *FT = nullptr; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 477 | if (D->hasWrittenPrototype()) |
| 478 | FT = dyn_cast<FunctionProtoType>(AFT); |
| 479 | |
| 480 | Proto += "("; |
| 481 | if (FT) { |
| 482 | llvm::raw_string_ostream POut(Proto); |
Richard Smith | 235341b | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 483 | DeclPrinter ParamPrinter(POut, SubPolicy, Indentation); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 484 | for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) { |
| 485 | if (i) POut << ", "; |
| 486 | ParamPrinter.VisitParmVarDecl(D->getParamDecl(i)); |
| 487 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 488 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 489 | if (FT->isVariadic()) { |
| 490 | if (D->getNumParams()) POut << ", "; |
| 491 | POut << "..."; |
| 492 | } |
Alexis Hunt | 4a8ea10 | 2011-05-06 20:44:56 +0000 | [diff] [blame] | 493 | } else if (D->doesThisDeclarationHaveABody() && !D->hasPrototype()) { |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 494 | for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) { |
| 495 | if (i) |
| 496 | Proto += ", "; |
| 497 | Proto += D->getParamDecl(i)->getNameAsString(); |
| 498 | } |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | Proto += ")"; |
Douglas Gregor | 049bdca | 2009-12-08 17:45:32 +0000 | [diff] [blame] | 502 | |
David Blaikie | f5697e5 | 2012-08-10 00:55:35 +0000 | [diff] [blame] | 503 | if (FT) { |
| 504 | if (FT->isConst()) |
Douglas Gregor | 8fc96fc | 2010-11-19 18:44:34 +0000 | [diff] [blame] | 505 | Proto += " const"; |
David Blaikie | f5697e5 | 2012-08-10 00:55:35 +0000 | [diff] [blame] | 506 | if (FT->isVolatile()) |
Douglas Gregor | 8fc96fc | 2010-11-19 18:44:34 +0000 | [diff] [blame] | 507 | Proto += " volatile"; |
David Blaikie | f5697e5 | 2012-08-10 00:55:35 +0000 | [diff] [blame] | 508 | if (FT->isRestrict()) |
Douglas Gregor | 8fc96fc | 2010-11-19 18:44:34 +0000 | [diff] [blame] | 509 | Proto += " restrict"; |
Benjamin Kramer | 2907b08 | 2014-02-25 18:49:49 +0000 | [diff] [blame] | 510 | |
| 511 | switch (FT->getRefQualifier()) { |
| 512 | case RQ_None: |
| 513 | break; |
| 514 | case RQ_LValue: |
| 515 | Proto += " &"; |
| 516 | break; |
| 517 | case RQ_RValue: |
| 518 | Proto += " &&"; |
| 519 | break; |
| 520 | } |
Douglas Gregor | 8fc96fc | 2010-11-19 18:44:34 +0000 | [diff] [blame] | 521 | } |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 522 | |
| 523 | if (FT && FT->hasDynamicExceptionSpec()) { |
Douglas Gregor | 049bdca | 2009-12-08 17:45:32 +0000 | [diff] [blame] | 524 | Proto += " throw("; |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 525 | if (FT->getExceptionSpecType() == EST_MSAny) |
Douglas Gregor | 049bdca | 2009-12-08 17:45:32 +0000 | [diff] [blame] | 526 | Proto += "..."; |
| 527 | else |
| 528 | for (unsigned I = 0, N = FT->getNumExceptions(); I != N; ++I) { |
| 529 | if (I) |
| 530 | Proto += ", "; |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 531 | |
Dmitri Gribenko | 76bb5cabfa | 2012-09-10 21:20:09 +0000 | [diff] [blame] | 532 | Proto += FT->getExceptionType(I).getAsString(SubPolicy); |
Douglas Gregor | 049bdca | 2009-12-08 17:45:32 +0000 | [diff] [blame] | 533 | } |
| 534 | Proto += ")"; |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 535 | } else if (FT && isNoexceptExceptionSpec(FT->getExceptionSpecType())) { |
| 536 | Proto += " noexcept"; |
| 537 | if (FT->getExceptionSpecType() == EST_ComputedNoexcept) { |
| 538 | Proto += "("; |
| 539 | llvm::raw_string_ostream EOut(Proto); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 540 | FT->getNoexceptExpr()->printPretty(EOut, nullptr, SubPolicy, |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 541 | Indentation); |
| 542 | EOut.flush(); |
| 543 | Proto += EOut.str(); |
| 544 | Proto += ")"; |
| 545 | } |
Douglas Gregor | 049bdca | 2009-12-08 17:45:32 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Fariborz Jahanian | 69c403c | 2012-12-05 22:19:06 +0000 | [diff] [blame] | 548 | if (CDecl) { |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 549 | bool HasInitializerList = false; |
Aaron Ballman | 0ad7830 | 2014-03-13 17:34:31 +0000 | [diff] [blame] | 550 | for (const auto *BMInitializer : CDecl->inits()) { |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 551 | if (BMInitializer->isInClassMemberInitializer()) |
| 552 | continue; |
| 553 | |
| 554 | if (!HasInitializerList) { |
| 555 | Proto += " : "; |
| 556 | Out << Proto; |
| 557 | Proto.clear(); |
| 558 | HasInitializerList = true; |
| 559 | } else |
| 560 | Out << ", "; |
| 561 | |
| 562 | if (BMInitializer->isAnyMemberInitializer()) { |
| 563 | FieldDecl *FD = BMInitializer->getAnyMember(); |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 564 | Out << *FD; |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 565 | } else { |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 566 | Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | Out << "("; |
| 570 | if (!BMInitializer->getInit()) { |
| 571 | // Nothing to print |
| 572 | } else { |
| 573 | Expr *Init = BMInitializer->getInit(); |
| 574 | if (ExprWithCleanups *Tmp = dyn_cast<ExprWithCleanups>(Init)) |
| 575 | Init = Tmp->getSubExpr(); |
Douglas Gregor | 7ae2d77 | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 576 | |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 577 | Init = Init->IgnoreParens(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 578 | |
| 579 | Expr *SimpleInit = nullptr; |
| 580 | Expr **Args = nullptr; |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 581 | unsigned NumArgs = 0; |
| 582 | if (ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) { |
| 583 | Args = ParenList->getExprs(); |
| 584 | NumArgs = ParenList->getNumExprs(); |
| 585 | } else if (CXXConstructExpr *Construct |
| 586 | = dyn_cast<CXXConstructExpr>(Init)) { |
| 587 | Args = Construct->getArgs(); |
| 588 | NumArgs = Construct->getNumArgs(); |
| 589 | } else |
| 590 | SimpleInit = Init; |
| 591 | |
| 592 | if (SimpleInit) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 593 | SimpleInit->printPretty(Out, nullptr, Policy, Indentation); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 594 | else { |
| 595 | for (unsigned I = 0; I != NumArgs; ++I) { |
Richard Trieu | ddd01ce | 2014-06-09 22:53:25 +0000 | [diff] [blame] | 596 | assert(Args[I] != nullptr && "Expected non-null Expr"); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 597 | if (isa<CXXDefaultArgExpr>(Args[I])) |
| 598 | break; |
| 599 | |
| 600 | if (I) |
| 601 | Out << ", "; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 602 | Args[I]->printPretty(Out, nullptr, Policy, Indentation); |
Fariborz Jahanian | 494720b | 2009-07-13 20:18:13 +0000 | [diff] [blame] | 603 | } |
Douglas Gregor | 7ae2d77 | 2010-01-31 09:12:51 +0000 | [diff] [blame] | 604 | } |
Fariborz Jahanian | 494720b | 2009-07-13 20:18:13 +0000 | [diff] [blame] | 605 | } |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 606 | Out << ")"; |
Benjamin Kramer | 2907b08 | 2014-02-25 18:49:49 +0000 | [diff] [blame] | 607 | if (BMInitializer->isPackExpansion()) |
| 608 | Out << "..."; |
Fariborz Jahanian | 494720b | 2009-07-13 20:18:13 +0000 | [diff] [blame] | 609 | } |
Benjamin Kramer | 2907b08 | 2014-02-25 18:49:49 +0000 | [diff] [blame] | 610 | } else if (!ConversionDecl && !isa<CXXDestructorDecl>(D)) { |
Richard Smith | e656076 | 2013-02-22 05:54:51 +0000 | [diff] [blame] | 611 | if (FT && FT->hasTrailingReturn()) { |
| 612 | Out << "auto " << Proto << " -> "; |
| 613 | Proto.clear(); |
| 614 | } |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 615 | AFT->getReturnType().print(Out, Policy, Proto); |
Benjamin Kramer | 00e8a19 | 2014-02-25 18:03:55 +0000 | [diff] [blame] | 616 | Proto.clear(); |
Richard Smith | e656076 | 2013-02-22 05:54:51 +0000 | [diff] [blame] | 617 | } |
Benjamin Kramer | 00e8a19 | 2014-02-25 18:03:55 +0000 | [diff] [blame] | 618 | Out << Proto; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 619 | } else { |
Argyrios Kyrtzidis | a18347e | 2012-05-05 04:20:37 +0000 | [diff] [blame] | 620 | Ty.print(Out, Policy, Proto); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 621 | } |
| 622 | |
Douglas Gregor | 49ccfaa | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 623 | prettyPrintAttributes(D); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 624 | |
| 625 | if (D->isPure()) |
| 626 | Out << " = 0"; |
Alexis Hunt | 4a8ea10 | 2011-05-06 20:44:56 +0000 | [diff] [blame] | 627 | else if (D->isDeletedAsWritten()) |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 628 | Out << " = delete"; |
Fariborz Jahanian | de872af | 2012-12-05 22:53:06 +0000 | [diff] [blame] | 629 | else if (D->isExplicitlyDefaulted()) |
| 630 | Out << " = default"; |
Dmitri Gribenko | a9a2af7 | 2012-08-21 17:47:24 +0000 | [diff] [blame] | 631 | else if (D->doesThisDeclarationHaveABody() && !Policy.TerseOutput) { |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 632 | if (!D->hasPrototype() && D->getNumParams()) { |
| 633 | // This is a K&R function definition, so we need to print the |
| 634 | // parameters. |
| 635 | Out << '\n'; |
Richard Smith | 235341b | 2012-08-16 03:56:14 +0000 | [diff] [blame] | 636 | DeclPrinter ParamPrinter(Out, SubPolicy, Indentation); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 637 | Indentation += Policy.Indentation; |
| 638 | for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) { |
| 639 | Indent(); |
Douglas Gregor | 2d042f1 | 2009-05-30 05:39:39 +0000 | [diff] [blame] | 640 | ParamPrinter.VisitParmVarDecl(D->getParamDecl(i)); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 641 | Out << ";\n"; |
| 642 | } |
| 643 | Indentation -= Policy.Indentation; |
| 644 | } else |
| 645 | Out << ' '; |
| 646 | |
Richard Trieu | ddd01ce | 2014-06-09 22:53:25 +0000 | [diff] [blame] | 647 | if (D->getBody()) |
| 648 | D->getBody()->printPretty(Out, nullptr, SubPolicy, Indentation); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 649 | Out << '\n'; |
| 650 | } |
| 651 | } |
| 652 | |
Fariborz Jahanian | bfc3ef5 | 2012-12-05 00:38:44 +0000 | [diff] [blame] | 653 | void DeclPrinter::VisitFriendDecl(FriendDecl *D) { |
| 654 | if (TypeSourceInfo *TSI = D->getFriendType()) { |
Enea Zaffanella | eb22c87 | 2013-01-31 09:54:08 +0000 | [diff] [blame] | 655 | unsigned NumTPLists = D->getFriendTypeNumTemplateParameterLists(); |
| 656 | for (unsigned i = 0; i < NumTPLists; ++i) |
| 657 | PrintTemplateParameters(D->getFriendTypeTemplateParameterList(i)); |
Fariborz Jahanian | 7a16a02 | 2012-12-21 21:43:05 +0000 | [diff] [blame] | 658 | Out << "friend "; |
| 659 | Out << " " << TSI->getType().getAsString(Policy); |
Fariborz Jahanian | bfc3ef5 | 2012-12-05 00:38:44 +0000 | [diff] [blame] | 660 | } |
| 661 | else if (FunctionDecl *FD = |
| 662 | dyn_cast<FunctionDecl>(D->getFriendDecl())) { |
| 663 | Out << "friend "; |
| 664 | VisitFunctionDecl(FD); |
| 665 | } |
| 666 | else if (FunctionTemplateDecl *FTD = |
| 667 | dyn_cast<FunctionTemplateDecl>(D->getFriendDecl())) { |
| 668 | Out << "friend "; |
| 669 | VisitFunctionTemplateDecl(FTD); |
| 670 | } |
| 671 | else if (ClassTemplateDecl *CTD = |
| 672 | dyn_cast<ClassTemplateDecl>(D->getFriendDecl())) { |
| 673 | Out << "friend "; |
Fariborz Jahanian | 7a16a02 | 2012-12-21 21:43:05 +0000 | [diff] [blame] | 674 | VisitRedeclarableTemplateDecl(CTD); |
Fariborz Jahanian | bfc3ef5 | 2012-12-05 00:38:44 +0000 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 678 | void DeclPrinter::VisitFieldDecl(FieldDecl *D) { |
Alexey Bataev | 6d45532 | 2015-10-12 06:59:48 +0000 | [diff] [blame] | 679 | // FIXME: add printing of pragma attributes if required. |
Eli Friedman | 7963584 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 680 | if (!Policy.SuppressSpecifiers && D->isMutable()) |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 681 | Out << "mutable "; |
Douglas Gregor | 26701a4 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 682 | if (!Policy.SuppressSpecifiers && D->isModulePrivate()) |
| 683 | Out << "__module_private__ "; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 684 | |
Fariborz Jahanian | b5f3468 | 2013-05-01 20:53:21 +0000 | [diff] [blame] | 685 | Out << D->getASTContext().getUnqualifiedObjCPointerType(D->getType()). |
Fariborz Jahanian | 9e07584 | 2013-05-01 17:28:37 +0000 | [diff] [blame] | 686 | stream(Policy, D->getName()); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 687 | |
| 688 | if (D->isBitField()) { |
| 689 | Out << " : "; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 690 | D->getBitWidth()->printPretty(Out, nullptr, Policy, Indentation); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 691 | } |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 692 | |
| 693 | Expr *Init = D->getInClassInitializer(); |
| 694 | if (!Policy.SuppressInitializers && Init) { |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 695 | if (D->getInClassInitStyle() == ICIS_ListInit) |
| 696 | Out << " "; |
| 697 | else |
| 698 | Out << " = "; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 699 | Init->printPretty(Out, nullptr, Policy, Indentation); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 700 | } |
Douglas Gregor | 49ccfaa | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 701 | prettyPrintAttributes(D); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 702 | } |
| 703 | |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 704 | void DeclPrinter::VisitLabelDecl(LabelDecl *D) { |
Benjamin Kramer | db0fc51 | 2012-02-07 11:57:57 +0000 | [diff] [blame] | 705 | Out << *D << ":"; |
Chris Lattner | cab02a6 | 2011-02-17 20:34:02 +0000 | [diff] [blame] | 706 | } |
| 707 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 708 | void DeclPrinter::VisitVarDecl(VarDecl *D) { |
Alexey Bataev | 6d45532 | 2015-10-12 06:59:48 +0000 | [diff] [blame] | 709 | prettyPrintPragmas(D); |
Richard Smith | fd3834f | 2013-04-13 02:43:54 +0000 | [diff] [blame] | 710 | if (!Policy.SuppressSpecifiers) { |
| 711 | StorageClass SC = D->getStorageClass(); |
| 712 | if (SC != SC_None) |
| 713 | Out << VarDecl::getStorageClassSpecifierString(SC) << " "; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 714 | |
Enea Zaffanella | acb8ecd | 2013-05-04 08:27:07 +0000 | [diff] [blame] | 715 | switch (D->getTSCSpec()) { |
| 716 | case TSCS_unspecified: |
Richard Smith | fd3834f | 2013-04-13 02:43:54 +0000 | [diff] [blame] | 717 | break; |
Enea Zaffanella | acb8ecd | 2013-05-04 08:27:07 +0000 | [diff] [blame] | 718 | case TSCS___thread: |
| 719 | Out << "__thread "; |
| 720 | break; |
| 721 | case TSCS__Thread_local: |
Richard Smith | fd3834f | 2013-04-13 02:43:54 +0000 | [diff] [blame] | 722 | Out << "_Thread_local "; |
| 723 | break; |
Enea Zaffanella | acb8ecd | 2013-05-04 08:27:07 +0000 | [diff] [blame] | 724 | case TSCS_thread_local: |
Richard Smith | fd3834f | 2013-04-13 02:43:54 +0000 | [diff] [blame] | 725 | Out << "thread_local "; |
| 726 | break; |
| 727 | } |
| 728 | |
| 729 | if (D->isModulePrivate()) |
| 730 | Out << "__module_private__ "; |
| 731 | } |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 732 | |
Enea Zaffanella | a86d88c | 2013-06-20 12:46:19 +0000 | [diff] [blame] | 733 | QualType T = D->getTypeSourceInfo() |
| 734 | ? D->getTypeSourceInfo()->getType() |
| 735 | : D->getASTContext().getUnqualifiedObjCPointerType(D->getType()); |
Richard Smith | a4bb292 | 2014-07-23 03:17:06 +0000 | [diff] [blame] | 736 | printDeclType(T, D->getName()); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 737 | Expr *Init = D->getInit(); |
| 738 | if (!Policy.SuppressInitializers && Init) { |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 739 | bool ImplicitInit = false; |
Dmitri Gribenko | b614fab | 2013-02-03 23:02:47 +0000 | [diff] [blame] | 740 | if (CXXConstructExpr *Construct = |
| 741 | dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) { |
Dmitri Gribenko | 6835e37 | 2013-01-27 21:28:24 +0000 | [diff] [blame] | 742 | if (D->getInitStyle() == VarDecl::CallInit && |
| 743 | !Construct->isListInitialization()) { |
| 744 | ImplicitInit = Construct->getNumArgs() == 0 || |
| 745 | Construct->getArg(0)->isDefaultArgument(); |
| 746 | } |
| 747 | } |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 748 | if (!ImplicitInit) { |
Eli Friedman | 92125c4 | 2012-10-19 20:36:44 +0000 | [diff] [blame] | 749 | if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init)) |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 750 | Out << "("; |
| 751 | else if (D->getInitStyle() == VarDecl::CInit) { |
| 752 | Out << " = "; |
| 753 | } |
Benjamin Kramer | 54f81ed | 2016-01-25 10:34:06 +0000 | [diff] [blame^] | 754 | PrintingPolicy SubPolicy(Policy); |
| 755 | SubPolicy.SuppressSpecifiers = false; |
| 756 | SubPolicy.SuppressTag = false; |
| 757 | Init->printPretty(Out, nullptr, SubPolicy, Indentation); |
Eli Friedman | 92125c4 | 2012-10-19 20:36:44 +0000 | [diff] [blame] | 758 | if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init)) |
Sebastian Redl | a935179 | 2012-02-11 23:51:47 +0000 | [diff] [blame] | 759 | Out << ")"; |
Ted Kremenek | 3586938 | 2010-09-17 23:04:38 +0000 | [diff] [blame] | 760 | } |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 761 | } |
Douglas Gregor | 49ccfaa | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 762 | prettyPrintAttributes(D); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) { |
| 766 | VisitVarDecl(D); |
| 767 | } |
| 768 | |
| 769 | void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) { |
| 770 | Out << "__asm ("; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 771 | D->getAsmString()->printPretty(Out, nullptr, Policy, Indentation); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 772 | Out << ")"; |
| 773 | } |
| 774 | |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 775 | void DeclPrinter::VisitImportDecl(ImportDecl *D) { |
Douglas Gregor | c50d492 | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 776 | Out << "@import " << D->getImportedModule()->getFullModuleName() |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 777 | << ";\n"; |
| 778 | } |
| 779 | |
Peter Collingbourne | 7d8a0b5 | 2011-03-16 18:37:27 +0000 | [diff] [blame] | 780 | void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 781 | Out << "static_assert("; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 782 | D->getAssertExpr()->printPretty(Out, nullptr, Policy, Indentation); |
David Majnemer | cdffc36 | 2015-06-05 18:03:58 +0000 | [diff] [blame] | 783 | if (StringLiteral *SL = D->getMessage()) { |
| 784 | Out << ", "; |
| 785 | SL->printPretty(Out, nullptr, Policy, Indentation); |
| 786 | } |
Peter Collingbourne | 7d8a0b5 | 2011-03-16 18:37:27 +0000 | [diff] [blame] | 787 | Out << ")"; |
| 788 | } |
| 789 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 790 | //---------------------------------------------------------------------------- |
| 791 | // C++ declarations |
| 792 | //---------------------------------------------------------------------------- |
Douglas Gregor | 5f478b7 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 793 | void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) { |
Douglas Gregor | b526370 | 2012-05-01 01:43:38 +0000 | [diff] [blame] | 794 | if (D->isInline()) |
| 795 | Out << "inline "; |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 796 | Out << "namespace " << *D << " {\n"; |
Douglas Gregor | 5f478b7 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 797 | VisitDeclContext(D); |
| 798 | Indent() << "}"; |
| 799 | } |
| 800 | |
Douglas Gregor | 3bc6e4c | 2009-05-30 06:31:56 +0000 | [diff] [blame] | 801 | void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 802 | Out << "using namespace "; |
| 803 | if (D->getQualifier()) |
| 804 | D->getQualifier()->print(Out, Policy); |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 805 | Out << *D->getNominatedNamespaceAsWritten(); |
Douglas Gregor | 3bc6e4c | 2009-05-30 06:31:56 +0000 | [diff] [blame] | 806 | } |
| 807 | |
Douglas Gregor | 1823193 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 808 | void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 809 | Out << "namespace " << *D << " = "; |
Douglas Gregor | 1823193 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 810 | if (D->getQualifier()) |
| 811 | D->getQualifier()->print(Out, Policy); |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 812 | Out << *D->getAliasedNamespace(); |
Douglas Gregor | 1823193 | 2009-05-30 06:48:27 +0000 | [diff] [blame] | 813 | } |
| 814 | |
Michael Han | 8432435 | 2013-02-22 17:15:32 +0000 | [diff] [blame] | 815 | void DeclPrinter::VisitEmptyDecl(EmptyDecl *D) { |
| 816 | prettyPrintAttributes(D); |
Michael Han | 8432435 | 2013-02-22 17:15:32 +0000 | [diff] [blame] | 817 | } |
| 818 | |
Douglas Gregor | 5f478b7 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 819 | void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) { |
Alexey Bataev | 6d45532 | 2015-10-12 06:59:48 +0000 | [diff] [blame] | 820 | // FIXME: add printing of pragma attributes if required. |
Douglas Gregor | 26701a4 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 821 | if (!Policy.SuppressSpecifiers && D->isModulePrivate()) |
| 822 | Out << "__module_private__ "; |
Douglas Gregor | 5f478b7 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 823 | Out << D->getKindName(); |
Aaron Ballman | 5388538 | 2014-09-15 16:45:30 +0000 | [diff] [blame] | 824 | |
| 825 | prettyPrintAttributes(D); |
| 826 | |
Benjamin Kramer | b11416d | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 827 | if (D->getIdentifier()) |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 828 | Out << ' ' << *D; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 829 | |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 830 | if (D->isCompleteDefinition()) { |
Douglas Gregor | 5f478b7 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 831 | // Print the base classes |
| 832 | if (D->getNumBases()) { |
| 833 | Out << " : "; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 834 | for (CXXRecordDecl::base_class_iterator Base = D->bases_begin(), |
| 835 | BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) { |
Douglas Gregor | 5f478b7 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 836 | if (Base != D->bases_begin()) |
| 837 | Out << ", "; |
| 838 | |
| 839 | if (Base->isVirtual()) |
| 840 | Out << "virtual "; |
| 841 | |
Anders Carlsson | 6df9e07 | 2009-08-29 20:36:12 +0000 | [diff] [blame] | 842 | AccessSpecifier AS = Base->getAccessSpecifierAsWritten(); |
Richard Smith | a593419 | 2014-07-23 03:22:10 +0000 | [diff] [blame] | 843 | if (AS != AS_none) { |
Anders Carlsson | 6df9e07 | 2009-08-29 20:36:12 +0000 | [diff] [blame] | 844 | Print(AS); |
Richard Smith | a593419 | 2014-07-23 03:22:10 +0000 | [diff] [blame] | 845 | Out << " "; |
| 846 | } |
| 847 | Out << Base->getType().getAsString(Policy); |
Douglas Gregor | 5fc8c9e | 2011-04-27 17:07:55 +0000 | [diff] [blame] | 848 | |
| 849 | if (Base->isPackExpansion()) |
| 850 | Out << "..."; |
Douglas Gregor | 5f478b7 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 851 | } |
| 852 | } |
| 853 | |
| 854 | // Print the class definition |
Douglas Gregor | 7a1a7cb | 2009-05-31 07:13:39 +0000 | [diff] [blame] | 855 | // FIXME: Doesn't print access specifiers, e.g., "public:" |
Douglas Gregor | 5f478b7 | 2009-05-30 06:58:37 +0000 | [diff] [blame] | 856 | Out << " {\n"; |
| 857 | VisitDeclContext(D); |
| 858 | Indent() << "}"; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 859 | } |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 863 | const char *l; |
| 864 | if (D->getLanguage() == LinkageSpecDecl::lang_c) |
| 865 | l = "C"; |
| 866 | else { |
| 867 | assert(D->getLanguage() == LinkageSpecDecl::lang_cxx && |
| 868 | "unknown language in linkage specification"); |
| 869 | l = "C++"; |
| 870 | } |
| 871 | |
| 872 | Out << "extern \"" << l << "\" "; |
| 873 | if (D->hasBraces()) { |
| 874 | Out << "{\n"; |
| 875 | VisitDeclContext(D); |
| 876 | Indent() << "}"; |
| 877 | } else |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 878 | Visit(*D->decls_begin()); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 879 | } |
| 880 | |
Enea Zaffanella | eb22c87 | 2013-01-31 09:54:08 +0000 | [diff] [blame] | 881 | void DeclPrinter::PrintTemplateParameters(const TemplateParameterList *Params, |
| 882 | const TemplateArgumentList *Args) { |
Richard Trieu | 82398f9 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 883 | assert(Params); |
| 884 | assert(!Args || Params->size() == Args->size()); |
| 885 | |
Anders Carlsson | 40f8f8d | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 886 | Out << "template <"; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 887 | |
Anders Carlsson | 40f8f8d | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 888 | for (unsigned i = 0, e = Params->size(); i != e; ++i) { |
| 889 | if (i != 0) |
| 890 | Out << ", "; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 891 | |
Anders Carlsson | 40f8f8d | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 892 | const Decl *Param = Params->getParam(i); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 893 | if (const TemplateTypeParmDecl *TTP = |
Anders Carlsson | 40f8f8d | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 894 | dyn_cast<TemplateTypeParmDecl>(Param)) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 895 | |
Anders Carlsson | 40f8f8d | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 896 | if (TTP->wasDeclaredWithTypename()) |
| 897 | Out << "typename "; |
| 898 | else |
| 899 | Out << "class "; |
| 900 | |
Anders Carlsson | fb1d776 | 2009-06-12 22:23:22 +0000 | [diff] [blame] | 901 | if (TTP->isParameterPack()) |
Richard Smith | a4bb292 | 2014-07-23 03:17:06 +0000 | [diff] [blame] | 902 | Out << "..."; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 903 | |
Benjamin Kramer | db0fc51 | 2012-02-07 11:57:57 +0000 | [diff] [blame] | 904 | Out << *TTP; |
Anders Carlsson | 40f8f8d | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 905 | |
Richard Trieu | 82398f9 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 906 | if (Args) { |
| 907 | Out << " = "; |
| 908 | Args->get(i).print(Policy, Out); |
| 909 | } else if (TTP->hasDefaultArgument()) { |
Anders Carlsson | 40f8f8d | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 910 | Out << " = "; |
| 911 | Out << TTP->getDefaultArgument().getAsString(Policy); |
| 912 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 913 | } else if (const NonTypeTemplateParmDecl *NTTP = |
Anders Carlsson | 40f8f8d | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 914 | dyn_cast<NonTypeTemplateParmDecl>(Param)) { |
Richard Smith | a4bb292 | 2014-07-23 03:17:06 +0000 | [diff] [blame] | 915 | StringRef Name; |
| 916 | if (IdentifierInfo *II = NTTP->getIdentifier()) |
| 917 | Name = II->getName(); |
| 918 | printDeclType(NTTP->getType(), Name, NTTP->isParameterPack()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 919 | |
Richard Trieu | 82398f9 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 920 | if (Args) { |
| 921 | Out << " = "; |
| 922 | Args->get(i).print(Policy, Out); |
| 923 | } else if (NTTP->hasDefaultArgument()) { |
Anders Carlsson | 40f8f8d | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 924 | Out << " = "; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 925 | NTTP->getDefaultArgument()->printPretty(Out, nullptr, Policy, |
| 926 | Indentation); |
Anders Carlsson | 40f8f8d | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 927 | } |
Richard Smith | 030f499 | 2011-04-15 13:38:57 +0000 | [diff] [blame] | 928 | } else if (const TemplateTemplateParmDecl *TTPD = |
| 929 | dyn_cast<TemplateTemplateParmDecl>(Param)) { |
| 930 | VisitTemplateDecl(TTPD); |
| 931 | // FIXME: print the default argument, if present. |
Anders Carlsson | 40f8f8d | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 932 | } |
| 933 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 934 | |
Anders Carlsson | 40f8f8d | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 935 | Out << "> "; |
Richard Trieu | 82398f9 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) { |
| 939 | PrintTemplateParameters(D->getTemplateParameters()); |
Anders Carlsson | 40f8f8d | 2009-06-04 05:37:43 +0000 | [diff] [blame] | 940 | |
Richard Smith | 030f499 | 2011-04-15 13:38:57 +0000 | [diff] [blame] | 941 | if (const TemplateTemplateParmDecl *TTP = |
| 942 | dyn_cast<TemplateTemplateParmDecl>(D)) { |
Douglas Gregor | f550077 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 943 | Out << "class "; |
| 944 | if (TTP->isParameterPack()) |
| 945 | Out << "..."; |
| 946 | Out << D->getName(); |
Craig Silverstein | 4a5d086 | 2010-07-09 20:25:10 +0000 | [diff] [blame] | 947 | } else { |
| 948 | Visit(D->getTemplatedDecl()); |
| 949 | } |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 950 | } |
| 951 | |
Richard Trieu | 82398f9 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 952 | void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 953 | if (PrintInstantiation) { |
| 954 | TemplateParameterList *Params = D->getTemplateParameters(); |
Aaron Ballman | b8733c5 | 2014-03-14 16:05:56 +0000 | [diff] [blame] | 955 | for (auto *I : D->specializations()) { |
Alexey Bataev | 6d45532 | 2015-10-12 06:59:48 +0000 | [diff] [blame] | 956 | prettyPrintPragmas(I); |
Aaron Ballman | b8733c5 | 2014-03-14 16:05:56 +0000 | [diff] [blame] | 957 | PrintTemplateParameters(Params, I->getTemplateSpecializationArgs()); |
| 958 | Visit(I); |
Richard Trieu | 82398f9 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 959 | } |
| 960 | } |
| 961 | |
Alexey Bataev | 6d45532 | 2015-10-12 06:59:48 +0000 | [diff] [blame] | 962 | prettyPrintPragmas(D->getTemplatedDecl()); |
Richard Trieu | 82398f9 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 963 | return VisitRedeclarableTemplateDecl(D); |
| 964 | } |
| 965 | |
| 966 | void DeclPrinter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 967 | if (PrintInstantiation) { |
| 968 | TemplateParameterList *Params = D->getTemplateParameters(); |
Aaron Ballman | 702fa31 | 2014-03-14 16:13:33 +0000 | [diff] [blame] | 969 | for (auto *I : D->specializations()) { |
| 970 | PrintTemplateParameters(Params, &I->getTemplateArgs()); |
| 971 | Visit(I); |
Richard Trieu | 82398f9 | 2011-07-28 00:19:05 +0000 | [diff] [blame] | 972 | Out << '\n'; |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | return VisitRedeclarableTemplateDecl(D); |
| 977 | } |
| 978 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 979 | //---------------------------------------------------------------------------- |
| 980 | // Objective-C declarations |
| 981 | //---------------------------------------------------------------------------- |
| 982 | |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 983 | void DeclPrinter::PrintObjCMethodType(ASTContext &Ctx, |
| 984 | Decl::ObjCDeclQualifier Quals, |
| 985 | QualType T) { |
| 986 | Out << '('; |
| 987 | if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_In) |
| 988 | Out << "in "; |
| 989 | if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Inout) |
| 990 | Out << "inout "; |
| 991 | if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Out) |
| 992 | Out << "out "; |
| 993 | if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Bycopy) |
| 994 | Out << "bycopy "; |
| 995 | if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Byref) |
| 996 | Out << "byref "; |
| 997 | if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Oneway) |
| 998 | Out << "oneway "; |
| 999 | if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_CSNullability) { |
Douglas Gregor | aea7afd | 2015-06-24 22:02:08 +0000 | [diff] [blame] | 1000 | if (auto nullability = AttributedType::stripOuterNullability(T)) |
| 1001 | Out << getNullabilitySpelling(*nullability, true) << ' '; |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | Out << Ctx.getUnqualifiedObjCPointerType(T).getAsString(Policy); |
| 1005 | Out << ')'; |
| 1006 | } |
| 1007 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1008 | void DeclPrinter::PrintObjCTypeParams(ObjCTypeParamList *Params) { |
| 1009 | Out << "<"; |
| 1010 | unsigned First = true; |
| 1011 | for (auto *Param : *Params) { |
| 1012 | if (First) { |
| 1013 | First = false; |
| 1014 | } else { |
| 1015 | Out << ", "; |
| 1016 | } |
| 1017 | |
Douglas Gregor | 1ac1b63 | 2015-07-07 03:58:54 +0000 | [diff] [blame] | 1018 | switch (Param->getVariance()) { |
| 1019 | case ObjCTypeParamVariance::Invariant: |
| 1020 | break; |
| 1021 | |
| 1022 | case ObjCTypeParamVariance::Covariant: |
| 1023 | Out << "__covariant "; |
| 1024 | break; |
| 1025 | |
| 1026 | case ObjCTypeParamVariance::Contravariant: |
| 1027 | Out << "__contravariant "; |
| 1028 | break; |
| 1029 | } |
| 1030 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1031 | Out << Param->getDeclName().getAsString(); |
| 1032 | |
| 1033 | if (Param->hasExplicitBound()) { |
| 1034 | Out << " : " << Param->getUnderlyingType().getAsString(Policy); |
| 1035 | } |
| 1036 | } |
| 1037 | Out << ">"; |
| 1038 | } |
| 1039 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1040 | void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) { |
| 1041 | if (OMD->isInstanceMethod()) |
Douglas Gregor | 36098ff | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 1042 | Out << "- "; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1043 | else |
Douglas Gregor | 36098ff | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 1044 | Out << "+ "; |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 1045 | if (!OMD->getReturnType().isNull()) { |
| 1046 | PrintObjCMethodType(OMD->getASTContext(), OMD->getObjCDeclQualifier(), |
| 1047 | OMD->getReturnType()); |
| 1048 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1049 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1050 | std::string name = OMD->getSelector().getAsString(); |
| 1051 | std::string::size_type pos, lastPos = 0; |
Aaron Ballman | 43b68be | 2014-03-07 17:50:17 +0000 | [diff] [blame] | 1052 | for (const auto *PI : OMD->params()) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1053 | // FIXME: selector is missing here! |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 1054 | pos = name.find_first_of(':', lastPos); |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 1055 | Out << " " << name.substr(lastPos, pos - lastPos) << ':'; |
| 1056 | PrintObjCMethodType(OMD->getASTContext(), |
| 1057 | PI->getObjCDeclQualifier(), |
| 1058 | PI->getType()); |
| 1059 | Out << *PI; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1060 | lastPos = pos + 1; |
| 1061 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1062 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1063 | if (OMD->param_begin() == OMD->param_end()) |
| 1064 | Out << " " << name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1065 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1066 | if (OMD->isVariadic()) |
| 1067 | Out << ", ..."; |
Fariborz Jahanian | aae7fef | 2014-10-03 20:05:33 +0000 | [diff] [blame] | 1068 | |
| 1069 | prettyPrintAttributes(OMD); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1070 | |
Fariborz Jahanian | a7d76d2 | 2012-10-17 21:58:03 +0000 | [diff] [blame] | 1071 | if (OMD->getBody() && !Policy.TerseOutput) { |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1072 | Out << ' '; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1073 | OMD->getBody()->printPretty(Out, nullptr, Policy); |
Douglas Gregor | 36098ff | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 1074 | } |
Fariborz Jahanian | 0389e52 | 2012-12-19 23:36:00 +0000 | [diff] [blame] | 1075 | else if (Policy.PolishForDeclaration) |
Fariborz Jahanian | 9b7ab87 | 2012-12-18 23:02:59 +0000 | [diff] [blame] | 1076 | Out << ';'; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) { |
| 1080 | std::string I = OID->getNameAsString(); |
| 1081 | ObjCInterfaceDecl *SID = OID->getSuperClass(); |
| 1082 | |
Fariborz Jahanian | aae7fef | 2014-10-03 20:05:33 +0000 | [diff] [blame] | 1083 | bool eolnOut = false; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1084 | if (SID) |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 1085 | Out << "@implementation " << I << " : " << *SID; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1086 | else |
| 1087 | Out << "@implementation " << I; |
Fariborz Jahanian | 95759ff | 2012-12-04 00:47:33 +0000 | [diff] [blame] | 1088 | |
| 1089 | if (OID->ivar_size() > 0) { |
| 1090 | Out << "{\n"; |
Fariborz Jahanian | aae7fef | 2014-10-03 20:05:33 +0000 | [diff] [blame] | 1091 | eolnOut = true; |
Fariborz Jahanian | 95759ff | 2012-12-04 00:47:33 +0000 | [diff] [blame] | 1092 | Indentation += Policy.Indentation; |
Aaron Ballman | d6d25de | 2014-03-14 15:16:45 +0000 | [diff] [blame] | 1093 | for (const auto *I : OID->ivars()) { |
Fariborz Jahanian | b5f3468 | 2013-05-01 20:53:21 +0000 | [diff] [blame] | 1094 | Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()). |
Aaron Ballman | d6d25de | 2014-03-14 15:16:45 +0000 | [diff] [blame] | 1095 | getAsString(Policy) << ' ' << *I << ";\n"; |
Fariborz Jahanian | 95759ff | 2012-12-04 00:47:33 +0000 | [diff] [blame] | 1096 | } |
| 1097 | Indentation -= Policy.Indentation; |
| 1098 | Out << "}\n"; |
| 1099 | } |
Fariborz Jahanian | aae7fef | 2014-10-03 20:05:33 +0000 | [diff] [blame] | 1100 | else if (SID || (OID->decls_begin() != OID->decls_end())) { |
| 1101 | Out << "\n"; |
| 1102 | eolnOut = true; |
| 1103 | } |
Douglas Gregor | 36098ff | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 1104 | VisitDeclContext(OID, false); |
Fariborz Jahanian | aae7fef | 2014-10-03 20:05:33 +0000 | [diff] [blame] | 1105 | if (!eolnOut) |
| 1106 | Out << "\n"; |
Douglas Gregor | 36098ff | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 1107 | Out << "@end"; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) { |
| 1111 | std::string I = OID->getNameAsString(); |
| 1112 | ObjCInterfaceDecl *SID = OID->getSuperClass(); |
| 1113 | |
Douglas Gregor | dc9166c | 2011-12-15 20:29:51 +0000 | [diff] [blame] | 1114 | if (!OID->isThisDeclarationADefinition()) { |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1115 | Out << "@class " << I; |
| 1116 | |
| 1117 | if (auto TypeParams = OID->getTypeParamListAsWritten()) { |
| 1118 | PrintObjCTypeParams(TypeParams); |
| 1119 | } |
| 1120 | |
| 1121 | Out << ";"; |
Douglas Gregor | dc9166c | 2011-12-15 20:29:51 +0000 | [diff] [blame] | 1122 | return; |
| 1123 | } |
Fariborz Jahanian | 0389e52 | 2012-12-19 23:36:00 +0000 | [diff] [blame] | 1124 | bool eolnOut = false; |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1125 | Out << "@interface " << I; |
| 1126 | |
| 1127 | if (auto TypeParams = OID->getTypeParamListAsWritten()) { |
| 1128 | PrintObjCTypeParams(TypeParams); |
| 1129 | } |
| 1130 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1131 | if (SID) |
Bob Wilson | 1f24ea15 | 2015-10-01 00:53:13 +0000 | [diff] [blame] | 1132 | Out << " : " << QualType(OID->getSuperClassType(), 0).getAsString(Policy); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1133 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1134 | // Protocols? |
| 1135 | const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols(); |
| 1136 | if (!Protocols.empty()) { |
| 1137 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 1138 | E = Protocols.end(); I != E; ++I) |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 1139 | Out << (I == Protocols.begin() ? '<' : ',') << **I; |
Douglas Gregor | 36098ff | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 1140 | Out << "> "; |
Fariborz Jahanian | 0389e52 | 2012-12-19 23:36:00 +0000 | [diff] [blame] | 1141 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1142 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1143 | if (OID->ivar_size() > 0) { |
Douglas Gregor | 36098ff | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 1144 | Out << "{\n"; |
Fariborz Jahanian | 0389e52 | 2012-12-19 23:36:00 +0000 | [diff] [blame] | 1145 | eolnOut = true; |
Douglas Gregor | 36098ff | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 1146 | Indentation += Policy.Indentation; |
Aaron Ballman | 59abbd4 | 2014-03-13 21:09:43 +0000 | [diff] [blame] | 1147 | for (const auto *I : OID->ivars()) { |
| 1148 | Indent() << I->getASTContext() |
| 1149 | .getUnqualifiedObjCPointerType(I->getType()) |
| 1150 | .getAsString(Policy) << ' ' << *I << ";\n"; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1151 | } |
Douglas Gregor | 36098ff | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 1152 | Indentation -= Policy.Indentation; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1153 | Out << "}\n"; |
| 1154 | } |
Fariborz Jahanian | aae7fef | 2014-10-03 20:05:33 +0000 | [diff] [blame] | 1155 | else if (SID || (OID->decls_begin() != OID->decls_end())) { |
Fariborz Jahanian | 0389e52 | 2012-12-19 23:36:00 +0000 | [diff] [blame] | 1156 | Out << "\n"; |
| 1157 | eolnOut = true; |
| 1158 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1159 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1160 | VisitDeclContext(OID, false); |
Fariborz Jahanian | 0389e52 | 2012-12-19 23:36:00 +0000 | [diff] [blame] | 1161 | if (!eolnOut) |
Fariborz Jahanian | aae7fef | 2014-10-03 20:05:33 +0000 | [diff] [blame] | 1162 | Out << "\n"; |
Douglas Gregor | 36098ff | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 1163 | Out << "@end"; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1164 | // FIXME: implement the rest... |
| 1165 | } |
| 1166 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1167 | void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) { |
Douglas Gregor | f610267 | 2012-01-01 21:23:57 +0000 | [diff] [blame] | 1168 | if (!PID->isThisDeclarationADefinition()) { |
Fariborz Jahanian | 0389e52 | 2012-12-19 23:36:00 +0000 | [diff] [blame] | 1169 | Out << "@protocol " << *PID << ";\n"; |
Douglas Gregor | f610267 | 2012-01-01 21:23:57 +0000 | [diff] [blame] | 1170 | return; |
| 1171 | } |
Fariborz Jahanian | 0389e52 | 2012-12-19 23:36:00 +0000 | [diff] [blame] | 1172 | // Protocols? |
| 1173 | const ObjCList<ObjCProtocolDecl> &Protocols = PID->getReferencedProtocols(); |
| 1174 | if (!Protocols.empty()) { |
| 1175 | Out << "@protocol " << *PID; |
| 1176 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 1177 | E = Protocols.end(); I != E; ++I) |
| 1178 | Out << (I == Protocols.begin() ? '<' : ',') << **I; |
| 1179 | Out << ">\n"; |
| 1180 | } else |
| 1181 | Out << "@protocol " << *PID << '\n'; |
Douglas Gregor | 36098ff | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 1182 | VisitDeclContext(PID, false); |
| 1183 | Out << "@end"; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) { |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 1187 | Out << "@implementation " << *PID->getClassInterface() << '(' << *PID <<")\n"; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1188 | |
| 1189 | VisitDeclContext(PID, false); |
Douglas Gregor | 36098ff | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 1190 | Out << "@end"; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1191 | // FIXME: implement the rest... |
| 1192 | } |
| 1193 | |
| 1194 | void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) { |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1195 | Out << "@interface " << *PID->getClassInterface(); |
| 1196 | if (auto TypeParams = PID->getTypeParamList()) { |
| 1197 | PrintObjCTypeParams(TypeParams); |
| 1198 | } |
| 1199 | Out << "(" << *PID << ")\n"; |
Fariborz Jahanian | 4cf177e | 2012-12-04 17:20:57 +0000 | [diff] [blame] | 1200 | if (PID->ivar_size() > 0) { |
| 1201 | Out << "{\n"; |
| 1202 | Indentation += Policy.Indentation; |
Aaron Ballman | 865fbcd | 2014-03-14 13:13:27 +0000 | [diff] [blame] | 1203 | for (const auto *I : PID->ivars()) |
Fariborz Jahanian | b5f3468 | 2013-05-01 20:53:21 +0000 | [diff] [blame] | 1204 | Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()). |
Aaron Ballman | 865fbcd | 2014-03-14 13:13:27 +0000 | [diff] [blame] | 1205 | getAsString(Policy) << ' ' << *I << ";\n"; |
Fariborz Jahanian | 4cf177e | 2012-12-04 17:20:57 +0000 | [diff] [blame] | 1206 | Indentation -= Policy.Indentation; |
| 1207 | Out << "}\n"; |
| 1208 | } |
| 1209 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1210 | VisitDeclContext(PID, false); |
Douglas Gregor | 36098ff | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 1211 | Out << "@end"; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1212 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1213 | // FIXME: implement the rest... |
| 1214 | } |
| 1215 | |
| 1216 | void DeclPrinter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) { |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 1217 | Out << "@compatibility_alias " << *AID |
| 1218 | << ' ' << *AID->getClassInterface() << ";\n"; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | /// PrintObjCPropertyDecl - print a property declaration. |
| 1222 | /// |
| 1223 | void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) { |
| 1224 | if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Required) |
| 1225 | Out << "@required\n"; |
| 1226 | else if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Optional) |
| 1227 | Out << "@optional\n"; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1228 | |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 1229 | QualType T = PDecl->getType(); |
| 1230 | |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1231 | Out << "@property"; |
| 1232 | if (PDecl->getPropertyAttributes() != ObjCPropertyDecl::OBJC_PR_noattr) { |
| 1233 | bool first = true; |
| 1234 | Out << " ("; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1235 | if (PDecl->getPropertyAttributes() & |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1236 | ObjCPropertyDecl::OBJC_PR_readonly) { |
| 1237 | Out << (first ? ' ' : ',') << "readonly"; |
| 1238 | first = false; |
Ted Kremenek | 897af91 | 2011-08-17 21:09:35 +0000 | [diff] [blame] | 1239 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1240 | |
Ted Kremenek | 897af91 | 2011-08-17 21:09:35 +0000 | [diff] [blame] | 1241 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) { |
Aaron Ballman | b190f97 | 2014-01-03 17:59:55 +0000 | [diff] [blame] | 1242 | Out << (first ? ' ' : ',') << "getter = "; |
| 1243 | PDecl->getGetterName().print(Out); |
Ted Kremenek | 897af91 | 2011-08-17 21:09:35 +0000 | [diff] [blame] | 1244 | first = false; |
| 1245 | } |
| 1246 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) { |
Aaron Ballman | b190f97 | 2014-01-03 17:59:55 +0000 | [diff] [blame] | 1247 | Out << (first ? ' ' : ',') << "setter = "; |
| 1248 | PDecl->getSetterName().print(Out); |
Ted Kremenek | 897af91 | 2011-08-17 21:09:35 +0000 | [diff] [blame] | 1249 | first = false; |
| 1250 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1251 | |
Ted Kremenek | 897af91 | 2011-08-17 21:09:35 +0000 | [diff] [blame] | 1252 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_assign) { |
| 1253 | Out << (first ? ' ' : ',') << "assign"; |
| 1254 | first = false; |
| 1255 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1256 | |
Ted Kremenek | 897af91 | 2011-08-17 21:09:35 +0000 | [diff] [blame] | 1257 | if (PDecl->getPropertyAttributes() & |
| 1258 | ObjCPropertyDecl::OBJC_PR_readwrite) { |
| 1259 | Out << (first ? ' ' : ',') << "readwrite"; |
| 1260 | first = false; |
| 1261 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1262 | |
Ted Kremenek | 897af91 | 2011-08-17 21:09:35 +0000 | [diff] [blame] | 1263 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain) { |
| 1264 | Out << (first ? ' ' : ',') << "retain"; |
| 1265 | first = false; |
| 1266 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1267 | |
Ted Kremenek | 897af91 | 2011-08-17 21:09:35 +0000 | [diff] [blame] | 1268 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_strong) { |
| 1269 | Out << (first ? ' ' : ',') << "strong"; |
| 1270 | first = false; |
| 1271 | } |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1272 | |
Ted Kremenek | 897af91 | 2011-08-17 21:09:35 +0000 | [diff] [blame] | 1273 | if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy) { |
| 1274 | Out << (first ? ' ' : ',') << "copy"; |
| 1275 | first = false; |
| 1276 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1277 | |
Ted Kremenek | 897af91 | 2011-08-17 21:09:35 +0000 | [diff] [blame] | 1278 | if (PDecl->getPropertyAttributes() & |
| 1279 | ObjCPropertyDecl::OBJC_PR_nonatomic) { |
| 1280 | Out << (first ? ' ' : ',') << "nonatomic"; |
| 1281 | first = false; |
| 1282 | } |
| 1283 | if (PDecl->getPropertyAttributes() & |
| 1284 | ObjCPropertyDecl::OBJC_PR_atomic) { |
| 1285 | Out << (first ? ' ' : ',') << "atomic"; |
| 1286 | first = false; |
| 1287 | } |
| 1288 | |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 1289 | if (PDecl->getPropertyAttributes() & |
| 1290 | ObjCPropertyDecl::OBJC_PR_nullability) { |
Douglas Gregor | 86b4268 | 2015-06-19 18:27:52 +0000 | [diff] [blame] | 1291 | if (auto nullability = AttributedType::stripOuterNullability(T)) { |
Douglas Gregor | 849ebc2 | 2015-06-19 18:14:46 +0000 | [diff] [blame] | 1292 | if (*nullability == NullabilityKind::Unspecified && |
| 1293 | (PDecl->getPropertyAttributes() & |
| 1294 | ObjCPropertyDecl::OBJC_PR_null_resettable)) { |
| 1295 | Out << (first ? ' ' : ',') << "null_resettable"; |
| 1296 | } else { |
| 1297 | Out << (first ? ' ' : ',') |
Douglas Gregor | aea7afd | 2015-06-24 22:02:08 +0000 | [diff] [blame] | 1298 | << getNullabilitySpelling(*nullability, true); |
Douglas Gregor | 849ebc2 | 2015-06-19 18:14:46 +0000 | [diff] [blame] | 1299 | } |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 1300 | first = false; |
| 1301 | } |
| 1302 | } |
| 1303 | |
Ted Kremenek | 897af91 | 2011-08-17 21:09:35 +0000 | [diff] [blame] | 1304 | (void) first; // Silence dead store warning due to idiomatic code. |
| 1305 | Out << " )"; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1306 | } |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 1307 | Out << ' ' << PDecl->getASTContext().getUnqualifiedObjCPointerType(T). |
Fariborz Jahanian | 9e07584 | 2013-05-01 17:28:37 +0000 | [diff] [blame] | 1308 | getAsString(Policy) << ' ' << *PDecl; |
Fariborz Jahanian | 0389e52 | 2012-12-19 23:36:00 +0000 | [diff] [blame] | 1309 | if (Policy.PolishForDeclaration) |
| 1310 | Out << ';'; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) { |
| 1314 | if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) |
Douglas Gregor | 36098ff | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 1315 | Out << "@synthesize "; |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1316 | else |
Douglas Gregor | 36098ff | 2009-05-30 00:56:08 +0000 | [diff] [blame] | 1317 | Out << "@dynamic "; |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 1318 | Out << *PID->getPropertyDecl(); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1319 | if (PID->getPropertyIvarDecl()) |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 1320 | Out << '=' << *PID->getPropertyIvarDecl(); |
Douglas Gregor | 278f52e | 2009-05-30 00:08:05 +0000 | [diff] [blame] | 1321 | } |
Anders Carlsson | df5a1c8 | 2009-08-28 19:16:39 +0000 | [diff] [blame] | 1322 | |
| 1323 | void DeclPrinter::VisitUsingDecl(UsingDecl *D) { |
Enea Zaffanella | c70b251 | 2013-07-17 17:28:56 +0000 | [diff] [blame] | 1324 | if (!D->isAccessDeclaration()) |
| 1325 | Out << "using "; |
Enea Zaffanella | e05a3cf | 2013-07-22 10:54:09 +0000 | [diff] [blame] | 1326 | if (D->hasTypename()) |
Enea Zaffanella | c70b251 | 2013-07-17 17:28:56 +0000 | [diff] [blame] | 1327 | Out << "typename "; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1328 | D->getQualifier()->print(Out, Policy); |
Benjamin Kramer | b89514a | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 1329 | Out << *D; |
Anders Carlsson | df5a1c8 | 2009-08-28 19:16:39 +0000 | [diff] [blame] | 1330 | } |
| 1331 | |
John McCall | e61f2ba | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1332 | void |
| 1333 | DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) { |
| 1334 | Out << "using typename "; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1335 | D->getQualifier()->print(Out, Policy); |
Benjamin Kramer | b11416d | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 1336 | Out << D->getDeclName(); |
John McCall | e61f2ba | 2009-11-18 02:36:19 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | void DeclPrinter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { |
Enea Zaffanella | c70b251 | 2013-07-17 17:28:56 +0000 | [diff] [blame] | 1340 | if (!D->isAccessDeclaration()) |
| 1341 | Out << "using "; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 1342 | D->getQualifier()->print(Out, Policy); |
Benjamin Kramer | 36d514e | 2015-09-23 13:43:16 +0000 | [diff] [blame] | 1343 | Out << D->getDeclName(); |
Anders Carlsson | df5a1c8 | 2009-08-28 19:16:39 +0000 | [diff] [blame] | 1344 | } |
John McCall | 3f74682 | 2009-11-17 05:59:44 +0000 | [diff] [blame] | 1345 | |
| 1346 | void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| 1347 | // ignore |
| 1348 | } |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1349 | |
| 1350 | void DeclPrinter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) { |
| 1351 | Out << "#pragma omp threadprivate"; |
| 1352 | if (!D->varlist_empty()) { |
| 1353 | for (OMPThreadPrivateDecl::varlist_iterator I = D->varlist_begin(), |
| 1354 | E = D->varlist_end(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1355 | I != E; ++I) { |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1356 | Out << (I == D->varlist_begin() ? '(' : ','); |
| 1357 | NamedDecl *ND = cast<NamedDecl>(cast<DeclRefExpr>(*I)->getDecl()); |
| 1358 | ND->printQualifiedName(Out); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1359 | } |
| 1360 | Out << ")"; |
| 1361 | } |
| 1362 | } |
| 1363 | |