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 } // namespace 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).substr(2) << ' '; 959 } 960 } 961 962 Out << Ctx.getUnqualifiedObjCPointerType(T).getAsString(Policy); 963 Out << ')'; 964 } 965 966 void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) { 967 if (OMD->isInstanceMethod()) 968 Out << "- "; 969 else 970 Out << "+ "; 971 if (!OMD->getReturnType().isNull()) { 972 PrintObjCMethodType(OMD->getASTContext(), OMD->getObjCDeclQualifier(), 973 OMD->getReturnType()); 974 } 975 976 std::string name = OMD->getSelector().getAsString(); 977 std::string::size_type pos, lastPos = 0; 978 for (const auto *PI : OMD->params()) { 979 // FIXME: selector is missing here! 980 pos = name.find_first_of(':', lastPos); 981 Out << " " << name.substr(lastPos, pos - lastPos) << ':'; 982 PrintObjCMethodType(OMD->getASTContext(), 983 PI->getObjCDeclQualifier(), 984 PI->getType()); 985 Out << *PI; 986 lastPos = pos + 1; 987 } 988 989 if (OMD->param_begin() == OMD->param_end()) 990 Out << " " << name; 991 992 if (OMD->isVariadic()) 993 Out << ", ..."; 994 995 prettyPrintAttributes(OMD); 996 997 if (OMD->getBody() && !Policy.TerseOutput) { 998 Out << ' '; 999 OMD->getBody()->printPretty(Out, nullptr, Policy); 1000 } 1001 else if (Policy.PolishForDeclaration) 1002 Out << ';'; 1003 } 1004 1005 void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) { 1006 std::string I = OID->getNameAsString(); 1007 ObjCInterfaceDecl *SID = OID->getSuperClass(); 1008 1009 bool eolnOut = false; 1010 if (SID) 1011 Out << "@implementation " << I << " : " << *SID; 1012 else 1013 Out << "@implementation " << I; 1014 1015 if (OID->ivar_size() > 0) { 1016 Out << "{\n"; 1017 eolnOut = true; 1018 Indentation += Policy.Indentation; 1019 for (const auto *I : OID->ivars()) { 1020 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()). 1021 getAsString(Policy) << ' ' << *I << ";\n"; 1022 } 1023 Indentation -= Policy.Indentation; 1024 Out << "}\n"; 1025 } 1026 else if (SID || (OID->decls_begin() != OID->decls_end())) { 1027 Out << "\n"; 1028 eolnOut = true; 1029 } 1030 VisitDeclContext(OID, false); 1031 if (!eolnOut) 1032 Out << "\n"; 1033 Out << "@end"; 1034 } 1035 1036 void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) { 1037 std::string I = OID->getNameAsString(); 1038 ObjCInterfaceDecl *SID = OID->getSuperClass(); 1039 1040 if (!OID->isThisDeclarationADefinition()) { 1041 Out << "@class " << I << ";"; 1042 return; 1043 } 1044 bool eolnOut = false; 1045 if (SID) 1046 Out << "@interface " << I << " : " << *SID; 1047 else 1048 Out << "@interface " << I; 1049 1050 // Protocols? 1051 const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols(); 1052 if (!Protocols.empty()) { 1053 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), 1054 E = Protocols.end(); I != E; ++I) 1055 Out << (I == Protocols.begin() ? '<' : ',') << **I; 1056 Out << "> "; 1057 } 1058 1059 if (OID->ivar_size() > 0) { 1060 Out << "{\n"; 1061 eolnOut = true; 1062 Indentation += Policy.Indentation; 1063 for (const auto *I : OID->ivars()) { 1064 Indent() << I->getASTContext() 1065 .getUnqualifiedObjCPointerType(I->getType()) 1066 .getAsString(Policy) << ' ' << *I << ";\n"; 1067 } 1068 Indentation -= Policy.Indentation; 1069 Out << "}\n"; 1070 } 1071 else if (SID || (OID->decls_begin() != OID->decls_end())) { 1072 Out << "\n"; 1073 eolnOut = true; 1074 } 1075 1076 VisitDeclContext(OID, false); 1077 if (!eolnOut) 1078 Out << "\n"; 1079 Out << "@end"; 1080 // FIXME: implement the rest... 1081 } 1082 1083 void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) { 1084 if (!PID->isThisDeclarationADefinition()) { 1085 Out << "@protocol " << *PID << ";\n"; 1086 return; 1087 } 1088 // Protocols? 1089 const ObjCList<ObjCProtocolDecl> &Protocols = PID->getReferencedProtocols(); 1090 if (!Protocols.empty()) { 1091 Out << "@protocol " << *PID; 1092 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), 1093 E = Protocols.end(); I != E; ++I) 1094 Out << (I == Protocols.begin() ? '<' : ',') << **I; 1095 Out << ">\n"; 1096 } else 1097 Out << "@protocol " << *PID << '\n'; 1098 VisitDeclContext(PID, false); 1099 Out << "@end"; 1100 } 1101 1102 void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) { 1103 Out << "@implementation " << *PID->getClassInterface() << '(' << *PID <<")\n"; 1104 1105 VisitDeclContext(PID, false); 1106 Out << "@end"; 1107 // FIXME: implement the rest... 1108 } 1109 1110 void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) { 1111 Out << "@interface " << *PID->getClassInterface() << '(' << *PID << ")\n"; 1112 if (PID->ivar_size() > 0) { 1113 Out << "{\n"; 1114 Indentation += Policy.Indentation; 1115 for (const auto *I : PID->ivars()) 1116 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()). 1117 getAsString(Policy) << ' ' << *I << ";\n"; 1118 Indentation -= Policy.Indentation; 1119 Out << "}\n"; 1120 } 1121 1122 VisitDeclContext(PID, false); 1123 Out << "@end"; 1124 1125 // FIXME: implement the rest... 1126 } 1127 1128 void DeclPrinter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) { 1129 Out << "@compatibility_alias " << *AID 1130 << ' ' << *AID->getClassInterface() << ";\n"; 1131 } 1132 1133 /// PrintObjCPropertyDecl - print a property declaration. 1134 /// 1135 void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) { 1136 if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Required) 1137 Out << "@required\n"; 1138 else if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Optional) 1139 Out << "@optional\n"; 1140 1141 QualType T = PDecl->getType(); 1142 1143 Out << "@property"; 1144 if (PDecl->getPropertyAttributes() != ObjCPropertyDecl::OBJC_PR_noattr) { 1145 bool first = true; 1146 Out << " ("; 1147 if (PDecl->getPropertyAttributes() & 1148 ObjCPropertyDecl::OBJC_PR_readonly) { 1149 Out << (first ? ' ' : ',') << "readonly"; 1150 first = false; 1151 } 1152 1153 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) { 1154 Out << (first ? ' ' : ',') << "getter = "; 1155 PDecl->getGetterName().print(Out); 1156 first = false; 1157 } 1158 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) { 1159 Out << (first ? ' ' : ',') << "setter = "; 1160 PDecl->getSetterName().print(Out); 1161 first = false; 1162 } 1163 1164 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_assign) { 1165 Out << (first ? ' ' : ',') << "assign"; 1166 first = false; 1167 } 1168 1169 if (PDecl->getPropertyAttributes() & 1170 ObjCPropertyDecl::OBJC_PR_readwrite) { 1171 Out << (first ? ' ' : ',') << "readwrite"; 1172 first = false; 1173 } 1174 1175 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain) { 1176 Out << (first ? ' ' : ',') << "retain"; 1177 first = false; 1178 } 1179 1180 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_strong) { 1181 Out << (first ? ' ' : ',') << "strong"; 1182 first = false; 1183 } 1184 1185 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy) { 1186 Out << (first ? ' ' : ',') << "copy"; 1187 first = false; 1188 } 1189 1190 if (PDecl->getPropertyAttributes() & 1191 ObjCPropertyDecl::OBJC_PR_nonatomic) { 1192 Out << (first ? ' ' : ',') << "nonatomic"; 1193 first = false; 1194 } 1195 if (PDecl->getPropertyAttributes() & 1196 ObjCPropertyDecl::OBJC_PR_atomic) { 1197 Out << (first ? ' ' : ',') << "atomic"; 1198 first = false; 1199 } 1200 1201 if (PDecl->getPropertyAttributes() & 1202 ObjCPropertyDecl::OBJC_PR_nullability) { 1203 if (auto nullability = AttributedType::stripOuterNullability(T)) { 1204 if (*nullability == NullabilityKind::Unspecified && 1205 (PDecl->getPropertyAttributes() & 1206 ObjCPropertyDecl::OBJC_PR_null_resettable)) { 1207 Out << (first ? ' ' : ',') << "null_resettable"; 1208 } else { 1209 Out << (first ? ' ' : ',') 1210 << getNullabilitySpelling(*nullability).substr(2); 1211 } 1212 first = false; 1213 } 1214 } 1215 1216 (void) first; // Silence dead store warning due to idiomatic code. 1217 Out << " )"; 1218 } 1219 Out << ' ' << PDecl->getASTContext().getUnqualifiedObjCPointerType(T). 1220 getAsString(Policy) << ' ' << *PDecl; 1221 if (Policy.PolishForDeclaration) 1222 Out << ';'; 1223 } 1224 1225 void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) { 1226 if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) 1227 Out << "@synthesize "; 1228 else 1229 Out << "@dynamic "; 1230 Out << *PID->getPropertyDecl(); 1231 if (PID->getPropertyIvarDecl()) 1232 Out << '=' << *PID->getPropertyIvarDecl(); 1233 } 1234 1235 void DeclPrinter::VisitUsingDecl(UsingDecl *D) { 1236 if (!D->isAccessDeclaration()) 1237 Out << "using "; 1238 if (D->hasTypename()) 1239 Out << "typename "; 1240 D->getQualifier()->print(Out, Policy); 1241 Out << *D; 1242 } 1243 1244 void 1245 DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) { 1246 Out << "using typename "; 1247 D->getQualifier()->print(Out, Policy); 1248 Out << D->getDeclName(); 1249 } 1250 1251 void DeclPrinter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { 1252 if (!D->isAccessDeclaration()) 1253 Out << "using "; 1254 D->getQualifier()->print(Out, Policy); 1255 Out << D->getName(); 1256 } 1257 1258 void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) { 1259 // ignore 1260 } 1261 1262 void DeclPrinter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) { 1263 Out << "#pragma omp threadprivate"; 1264 if (!D->varlist_empty()) { 1265 for (OMPThreadPrivateDecl::varlist_iterator I = D->varlist_begin(), 1266 E = D->varlist_end(); 1267 I != E; ++I) { 1268 Out << (I == D->varlist_begin() ? '(' : ','); 1269 NamedDecl *ND = cast<NamedDecl>(cast<DeclRefExpr>(*I)->getDecl()); 1270 ND->printQualifiedName(Out); 1271 } 1272 Out << ")"; 1273 } 1274 } 1275 1276