Deleted Added
full compact
DeclPrinter.cpp (194179) DeclPrinter.cpp (195341)
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
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, ASTContext &Context,
78 unsigned Indentation) {
79 print(Out, Context, Context.PrintingPolicy, Indentation);
77void Decl::print(llvm::raw_ostream &Out, unsigned Indentation) {
78 print(Out, getASTContext().PrintingPolicy, Indentation);
80}
81
79}
80
82void Decl::print(llvm::raw_ostream &Out, ASTContext &Context,
83 const PrintingPolicy &Policy, unsigned Indentation) {
84 DeclPrinter Printer(Out, Context, Policy, Indentation);
81void Decl::print(llvm::raw_ostream &Out, const PrintingPolicy &Policy,
82 unsigned Indentation) {
83 DeclPrinter Printer(Out, getASTContext(), Policy, Indentation);
85 Printer.Visit(this);
86}
87
88static QualType GetBaseType(QualType T) {
89 // FIXME: This should be on the Type class!
90 QualType BaseType = T;
91 while (!BaseType->isSpecifierType()) {
92 if (isa<TypedefType>(BaseType))
93 break;
94 else if (const PointerType* PTy = BaseType->getAsPointerType())
95 BaseType = PTy->getPointeeType();
96 else if (const ArrayType* ATy = dyn_cast<ArrayType>(BaseType))
97 BaseType = ATy->getElementType();
98 else if (const FunctionType* FTy = BaseType->getAsFunctionType())
99 BaseType = FTy->getResultType();
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();
100 else
101 assert(0 && "Unknown declarator!");
102 }
103 return BaseType;
104}
105
106static QualType getDeclType(Decl* D) {
107 if (TypedefDecl* TDD = dyn_cast<TypedefDecl>(D))
108 return TDD->getUnderlyingType();
109 if (ValueDecl* VD = dyn_cast<ValueDecl>(D))
110 return VD->getType();
111 return QualType();
112}
113
114void Decl::printGroup(Decl** Begin, unsigned NumDecls,
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,
115 llvm::raw_ostream &Out, ASTContext &Context,
116 const PrintingPolicy &Policy,
116 llvm::raw_ostream &Out, const PrintingPolicy &Policy,
117 unsigned Indentation) {
118 if (NumDecls == 1) {
117 unsigned Indentation) {
118 if (NumDecls == 1) {
119 (*Begin)->print(Out, Context, Policy, Indentation);
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()) {
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, Context, Policy, Indentation);
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
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, Context, SubPolicy, Indentation);
145 (*Begin)->print(Out, SubPolicy, Indentation);
146 }
147}
148
146 }
147}
148
149void Decl::dump(ASTContext &Context) {
150 print(llvm::errs(), Context);
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();
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, Context,
162 Policy, Indentation);
161 Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation);
163 Out << ";\n";
164 Decls.clear();
165
166}
167
168//----------------------------------------------------------------------------
169// Common C declarations
170//----------------------------------------------------------------------------
171
172void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
173 if (Indent)
174 Indentation += Policy.Indentation;
175
176 llvm::SmallVector<Decl*, 2> Decls;
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;
177 for (DeclContext::decl_iterator D = DC->decls_begin(Context),
178 DEnd = DC->decls_end(Context);
176 for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end();
179 D != DEnd; ++D) {
180 if (!Policy.Dump) {
181 // Skip over implicit declarations in pretty-printing mode.
182 if (D->isImplicit()) continue;
183 // FIXME: Ugly hack so we don't pretty-print the builtin declaration
184 // of __builtin_va_list. There should be some other way to check that.
185 if (isa<NamedDecl>(*D) && cast<NamedDecl>(*D)->getNameAsString() ==
186 "__builtin_va_list")

--- 172 unchanged lines hidden (view full) ---

359 Indent();
360 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
361 Out << ";\n";
362 }
363 Indentation -= Policy.Indentation;
364 } else
365 Out << ' ';
366
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
367 D->getBody(Context)->printPretty(Out, Context, 0, SubPolicy, Indentation);
365 D->getBody()->printPretty(Out, Context, 0, SubPolicy, Indentation);
368 Out << '\n';
369 }
370}
371
372void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
373 if (!Policy.SuppressSpecifiers && D->isMutable())
374 Out << "mutable ";
375

--- 123 unchanged lines hidden (view full) ---

499 }
500
501 Out << "extern \"" << l << "\" ";
502 if (D->hasBraces()) {
503 Out << "{\n";
504 VisitDeclContext(D);
505 Indent() << "}";
506 } else
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
507 Visit(*D->decls_begin(Context));
505 Visit(*D->decls_begin());
508}
509
510void DeclPrinter::VisitTemplateDecl(TemplateDecl *D) {
511 Out << "template <";
512
513 TemplateParameterList *Params = D->getTemplateParameters();
514 for (unsigned i = 0, e = Params->size(); i != e; ++i) {
515 if (i != 0)

--- 252 unchanged lines hidden ---
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 ---