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