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//===----------------------------------------------------------------------===// --- 60 unchanged lines hidden (view full) --- 69 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); 70 void VisitObjCCategoryDecl(ObjCCategoryDecl *D); 71 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); 72 void VisitObjCPropertyDecl(ObjCPropertyDecl *D); 73 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); 74 }; 75} 76 |
77void Decl::print(llvm::raw_ostream &Out, unsigned Indentation) { 78 print(Out, getASTContext().PrintingPolicy, Indentation); |
79} 80 |
81void Decl::print(llvm::raw_ostream &Out, const PrintingPolicy &Policy, 82 unsigned Indentation) { 83 DeclPrinter Printer(Out, getASTContext(), Policy, Indentation); |
84 Printer.Visit(this); 85} 86 87static QualType GetBaseType(QualType T) { 88 // FIXME: This should be on the Type class! 89 QualType BaseType = T; 90 while (!BaseType->isSpecifierType()) { 91 if (isa<TypedefType>(BaseType)) 92 break; 93 else if (const PointerType* PTy = BaseType->getAsPointerType()) 94 BaseType = PTy->getPointeeType(); 95 else if (const ArrayType* ATy = dyn_cast<ArrayType>(BaseType)) 96 BaseType = ATy->getElementType(); 97 else if (const FunctionType* FTy = BaseType->getAsFunctionType()) 98 BaseType = FTy->getResultType(); |
99 else if (const VectorType *VTy = BaseType->getAsVectorType()) 100 BaseType = VTy->getElementType(); |
101 else 102 assert(0 && "Unknown declarator!"); 103 } 104 return BaseType; 105} 106 107static QualType getDeclType(Decl* D) { 108 if (TypedefDecl* TDD = dyn_cast<TypedefDecl>(D)) 109 return TDD->getUnderlyingType(); 110 if (ValueDecl* VD = dyn_cast<ValueDecl>(D)) 111 return VD->getType(); 112 return QualType(); 113} 114 115void Decl::printGroup(Decl** Begin, unsigned NumDecls, |
116 llvm::raw_ostream &Out, const PrintingPolicy &Policy, |
117 unsigned Indentation) { 118 if (NumDecls == 1) { |
119 (*Begin)->print(Out, Policy, Indentation); |
120 return; 121 } 122 123 Decl** End = Begin + NumDecls; 124 TagDecl* TD = dyn_cast<TagDecl>(*Begin); 125 if (TD) 126 ++Begin; 127 128 PrintingPolicy SubPolicy(Policy); 129 if (TD && TD->isDefinition()) { |
130 TD->print(Out, Policy, Indentation); |
131 Out << " "; 132 SubPolicy.SuppressTag = true; 133 } 134 135 bool isFirst = true; 136 for ( ; Begin != End; ++Begin) { 137 if (isFirst) { 138 SubPolicy.SuppressSpecifiers = false; 139 isFirst = false; 140 } else { 141 if (!isFirst) Out << ", "; 142 SubPolicy.SuppressSpecifiers = true; 143 } 144 |
145 (*Begin)->print(Out, SubPolicy, Indentation); |
146 } 147} 148 |
149void Decl::dump() { 150 print(llvm::errs()); |
151} 152 153llvm::raw_ostream& DeclPrinter::Indent() { 154 for (unsigned i = 0; i < Indentation; ++i) 155 Out << " "; 156 return Out; 157} 158 159void DeclPrinter::ProcessDeclGroup(llvm::SmallVectorImpl<Decl*>& Decls) { 160 this->Indent(); |
161 Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation); |
162 Out << ";\n"; 163 Decls.clear(); 164 165} 166 167//---------------------------------------------------------------------------- 168// Common C declarations 169//---------------------------------------------------------------------------- 170 171void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) { 172 if (Indent) 173 Indentation += Policy.Indentation; 174 175 llvm::SmallVector<Decl*, 2> Decls; |
176 for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end(); |
177 D != DEnd; ++D) { 178 if (!Policy.Dump) { 179 // Skip over implicit declarations in pretty-printing mode. 180 if (D->isImplicit()) continue; 181 // FIXME: Ugly hack so we don't pretty-print the builtin declaration 182 // of __builtin_va_list. There should be some other way to check that. 183 if (isa<NamedDecl>(*D) && cast<NamedDecl>(*D)->getNameAsString() == 184 "__builtin_va_list") --- 172 unchanged lines hidden (view full) --- 357 Indent(); 358 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i)); 359 Out << ";\n"; 360 } 361 Indentation -= Policy.Indentation; 362 } else 363 Out << ' '; 364 |
365 D->getBody()->printPretty(Out, Context, 0, SubPolicy, Indentation); |
366 Out << '\n'; 367 } 368} 369 370void DeclPrinter::VisitFieldDecl(FieldDecl *D) { 371 if (!Policy.SuppressSpecifiers && D->isMutable()) 372 Out << "mutable "; 373 --- 123 unchanged lines hidden (view full) --- 497 } 498 499 Out << "extern \"" << l << "\" "; 500 if (D->hasBraces()) { 501 Out << "{\n"; 502 VisitDeclContext(D); 503 Indent() << "}"; 504 } else |
505 Visit(*D->decls_begin()); |
506} 507 508void DeclPrinter::VisitTemplateDecl(TemplateDecl *D) { 509 Out << "template <"; 510 511 TemplateParameterList *Params = D->getTemplateParameters(); 512 for (unsigned i = 0, e = Params->size(); i != e; ++i) { 513 if (i != 0) --- 252 unchanged lines hidden --- |