diff options
Diffstat (limited to 'lib/Frontend/ASTConsumers.cpp')
-rw-r--r-- | lib/Frontend/ASTConsumers.cpp | 191 |
1 files changed, 23 insertions, 168 deletions
diff --git a/lib/Frontend/ASTConsumers.cpp b/lib/Frontend/ASTConsumers.cpp index ebbd720ceb637..7b8ebf92032e1 100644 --- a/lib/Frontend/ASTConsumers.cpp +++ b/lib/Frontend/ASTConsumers.cpp @@ -24,7 +24,6 @@ #include "clang/AST/PrettyPrinter.h" #include "clang/CodeGen/ModuleBuilder.h" #include "llvm/Module.h" -#include "llvm/Support/Format.h" #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" #include "llvm/System/Path.h" @@ -165,7 +164,7 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, case Decl::Namespace: { Out << "[namespace] "; const NamespaceDecl* ND = cast<NamespaceDecl>(DC); - Out << ND->getNameAsString(); + Out << ND; break; } case Decl::Enum: { @@ -174,7 +173,7 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, Out << "[enum] "; else Out << "<enum> "; - Out << ED->getNameAsString(); + Out << ED; break; } case Decl::Record: { @@ -183,7 +182,7 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, Out << "[struct] "; else Out << "<struct> "; - Out << RD->getNameAsString(); + Out << RD; break; } case Decl::CXXRecord: { @@ -192,7 +191,7 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, Out << "[class] "; else Out << "<class> "; - Out << RD->getNameAsString() << " " << DC; + Out << RD << ' ' << DC; break; } case Decl::ObjCMethod: @@ -225,7 +224,7 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, Out << "[function] "; else Out << "<function> "; - Out << FD->getNameAsString(); + Out << FD; // Print the parameters. Out << "("; bool PrintComma = false; @@ -235,7 +234,7 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, Out << ", "; else PrintComma = true; - Out << (*I)->getNameAsString(); + Out << *I; } Out << ")"; break; @@ -248,7 +247,7 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, Out << "(c++ method) "; else Out << "<c++ method> "; - Out << D->getNameAsString(); + Out << D; // Print the parameters. Out << "("; bool PrintComma = false; @@ -258,7 +257,7 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, Out << ", "; else PrintComma = true; - Out << (*I)->getNameAsString(); + Out << *I; } Out << ")"; @@ -278,7 +277,7 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, Out << "(c++ ctor) "; else Out << "<c++ ctor> "; - Out << D->getNameAsString(); + Out << D; // Print the parameters. Out << "("; bool PrintComma = false; @@ -288,7 +287,7 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, Out << ", "; else PrintComma = true; - Out << (*I)->getNameAsString(); + Out << *I; } Out << ")"; @@ -307,7 +306,7 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, Out << "(c++ dtor) "; else Out << "<c++ dtor> "; - Out << D->getNameAsString(); + Out << D; // Check the semantic DC. const DeclContext* SemaDC = D->getDeclContext(); const DeclContext* LexicalDC = D->getLexicalDeclContext(); @@ -323,7 +322,7 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, Out << "(c++ conversion) "; else Out << "<c++ conversion> "; - Out << D->getNameAsString(); + Out << D; // Check the semantic DC. const DeclContext* SemaDC = D->getDeclContext(); const DeclContext* LexicalDC = D->getLexicalDeclContext(); @@ -370,42 +369,42 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, } case Decl::Field: { FieldDecl* FD = cast<FieldDecl>(*I); - Out << "<field> " << FD->getNameAsString() << "\n"; + Out << "<field> " << FD << '\n'; break; } case Decl::Typedef: { TypedefDecl* TD = cast<TypedefDecl>(*I); - Out << "<typedef> " << TD->getNameAsString() << "\n"; + Out << "<typedef> " << TD << '\n'; break; } case Decl::EnumConstant: { EnumConstantDecl* ECD = cast<EnumConstantDecl>(*I); - Out << "<enum constant> " << ECD->getNameAsString() << "\n"; + Out << "<enum constant> " << ECD << '\n'; break; } case Decl::Var: { VarDecl* VD = cast<VarDecl>(*I); - Out << "<var> " << VD->getNameAsString() << "\n"; + Out << "<var> " << VD << '\n'; break; } case Decl::ImplicitParam: { ImplicitParamDecl* IPD = cast<ImplicitParamDecl>(*I); - Out << "<implicit parameter> " << IPD->getNameAsString() << "\n"; + Out << "<implicit parameter> " << IPD << '\n'; break; } case Decl::ParmVar: { ParmVarDecl* PVD = cast<ParmVarDecl>(*I); - Out << "<parameter> " << PVD->getNameAsString() << "\n"; + Out << "<parameter> " << PVD << '\n'; break; } case Decl::ObjCProperty: { ObjCPropertyDecl* OPD = cast<ObjCPropertyDecl>(*I); - Out << "<objc property> " << OPD->getNameAsString() << "\n"; + Out << "<objc property> " << OPD << '\n'; break; } case Decl::FunctionTemplate: { FunctionTemplateDecl* FTD = cast<FunctionTemplateDecl>(*I); - Out << "<function template> " << FTD->getNameAsString() << "\n"; + Out << "<function template> " << FTD << '\n'; break; } case Decl::FileScopeAsm: { @@ -418,16 +417,16 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, } case Decl::NamespaceAlias: { NamespaceAliasDecl* NAD = cast<NamespaceAliasDecl>(*I); - Out << "<namespace alias> " << NAD->getNameAsString() << "\n"; + Out << "<namespace alias> " << NAD << '\n'; break; } case Decl::ClassTemplate: { ClassTemplateDecl *CTD = cast<ClassTemplateDecl>(*I); - Out << "<class template> " << CTD->getNameAsString() << '\n'; + Out << "<class template> " << CTD << '\n'; break; } default: - Out << "DeclKind: " << DK << '"' << I->getDeclKindName() << "\"\n"; + Out << "DeclKind: " << DK << '"' << *I << "\"\n"; assert(0 && "decl unhandled"); } } @@ -437,150 +436,6 @@ ASTConsumer *clang::CreateDeclContextPrinter() { } //===----------------------------------------------------------------------===// -/// RecordLayoutDumper - C++ Record Layout Dumping. -namespace { -class RecordLayoutDumper : public ASTConsumer { - llvm::raw_ostream& Out; - - void PrintOffset(uint64_t Offset, unsigned IndentLevel) { - Out << llvm::format("%4d | ", Offset); - for (unsigned I = 0; I < IndentLevel * 2; ++I) Out << ' '; - } - - void DumpRecordLayoutOffsets(const CXXRecordDecl *RD, ASTContext &C, - uint64_t Offset, - unsigned IndentLevel, const char* Description, - bool IncludeVirtualBases) { - const ASTRecordLayout &Info = C.getASTRecordLayout(RD); - - PrintOffset(Offset, IndentLevel); - Out << C.getTypeDeclType((CXXRecordDecl *)RD).getAsString(); - if (Description) - Out << ' ' << Description; - if (RD->isEmpty()) - Out << " (empty)"; - Out << '\n'; - - IndentLevel++; - - const CXXRecordDecl *PrimaryBase = Info.getPrimaryBase(); - - // Vtable pointer. - if (RD->isDynamicClass() && !PrimaryBase) { - PrintOffset(Offset, IndentLevel); - Out << '(' << RD->getNameAsString() << " vtable pointer)\n"; - } - // Dump (non-virtual) bases - for (CXXRecordDecl::base_class_const_iterator I = RD->bases_begin(), - E = RD->bases_end(); I != E; ++I) { - assert(!I->getType()->isDependentType() && - "Cannot layout class with dependent bases."); - if (I->isVirtual()) - continue; - - const CXXRecordDecl *Base = - cast<CXXRecordDecl>(I->getType()->getAs<RecordType>()->getDecl()); - - uint64_t BaseOffset = Offset + Info.getBaseClassOffset(Base) / 8; - - DumpRecordLayoutOffsets(Base, C, BaseOffset, IndentLevel, - Base == PrimaryBase ? "(primary base)" : "(base)", - /*IncludeVirtualBases=*/false); - } - - // Dump fields. - uint64_t FieldNo = 0; - for (CXXRecordDecl::field_iterator I = RD->field_begin(), - E = RD->field_end(); I != E; ++I, ++FieldNo) { - const FieldDecl *Field = *I; - uint64_t FieldOffset = Offset + Info.getFieldOffset(FieldNo) / 8; - - if (const RecordType *RT = Field->getType()->getAs<RecordType>()) { - if (const CXXRecordDecl *D = dyn_cast<CXXRecordDecl>(RT->getDecl())) { - DumpRecordLayoutOffsets(D, C, FieldOffset, IndentLevel, - Field->getNameAsCString(), - /*IncludeVirtualBases=*/true); - continue; - } - } - - PrintOffset(FieldOffset, IndentLevel); - Out << Field->getType().getAsString() << ' '; - Out << Field->getNameAsString() << '\n'; - } - - if (!IncludeVirtualBases) - return; - - // Dump virtual bases. - for (CXXRecordDecl::base_class_const_iterator I = RD->vbases_begin(), - E = RD->vbases_end(); I != E; ++I) { - assert(I->isVirtual() && "Found non-virtual class!"); - const CXXRecordDecl *VBase = - cast<CXXRecordDecl>(I->getType()->getAs<RecordType>()->getDecl()); - - uint64_t VBaseOffset = Offset + Info.getVBaseClassOffset(VBase) / 8; - DumpRecordLayoutOffsets(VBase, C, VBaseOffset, IndentLevel, - VBase == PrimaryBase ? - "(primary virtual base)" : "(virtual base)", - /*IncludeVirtualBases=*/false); - } - } - - // FIXME: Maybe this could be useful in ASTContext.cpp. - void DumpRecordLayout(const CXXRecordDecl *RD, ASTContext &C) { - const ASTRecordLayout &Info = C.getASTRecordLayout(RD); - - DumpRecordLayoutOffsets(RD, C, 0, 0, 0, - /*IncludeVirtualBases=*/true); - Out << " sizeof=" << Info.getSize() / 8; - Out << ", dsize=" << Info.getDataSize() / 8; - Out << ", align=" << Info.getAlignment() / 8 << '\n'; - Out << " nvsize=" << Info.getNonVirtualSize() / 8; - Out << ", nvalign=" << Info.getNonVirtualAlign() / 8 << '\n'; - Out << '\n'; - } - -public: - RecordLayoutDumper() : Out(llvm::errs()) {} - - void HandleTranslationUnit(ASTContext &C) { - for (ASTContext::type_iterator I = C.types_begin(), E = C.types_end(); - I != E; ++I) { - const RecordType *RT = dyn_cast<RecordType>(*I); - if (!RT) - continue; - - const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl()); - if (!RD) - continue; - - if (RD->isImplicit()) - continue; - - if (RD->isDependentType()) - continue; - - if (RD->isInvalidDecl()) - continue; - - if (!RD->getDefinition()) - continue; - - // FIXME: Do we really need to hard code this? - if (RD->getQualifiedNameAsString() == "__va_list_tag") - continue; - - DumpRecordLayout(RD, C); - } - } -}; -} // end anonymous namespace -ASTConsumer *clang::CreateRecordLayoutDumper() { - return new RecordLayoutDumper(); -} - -//===----------------------------------------------------------------------===// /// InheritanceViewer - C++ Inheritance Visualization namespace { |