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