From: Chris Lattner Date: Sat, 28 Mar 2009 05:44:17 +0000 (+0000) Subject: reduce indentation, no functionality change. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b23ff6b4ebefe9c0fd531d2247171500e5d0a5b7;p=clang reduce indentation, no functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67916 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/clang-cc/ASTConsumers.cpp b/tools/clang-cc/ASTConsumers.cpp index 5b4287a2bd..cb09659a58 100644 --- a/tools/clang-cc/ASTConsumers.cpp +++ b/tools/clang-cc/ASTConsumers.cpp @@ -543,7 +543,7 @@ namespace { PrintDecl(D); } }; -} +} // end anonymous namespace ASTConsumer *clang::CreateASTPrinter(llvm::raw_ostream* out) { return new ASTPrinter(out); @@ -561,53 +561,55 @@ namespace { void Initialize(ASTContext &Context) { SM = &Context.getSourceManager(); } + + virtual void HandleTopLevelDecl(Decl *D); + }; +} // end anonymous namespace + +void ASTDumper::HandleTopLevelDecl(Decl *D) { + if (FunctionDecl *FD = dyn_cast(D)) { + PrintFunctionDeclStart(FD); - virtual void HandleTopLevelDecl(Decl *D) { - if (FunctionDecl *FD = dyn_cast(D)) { - PrintFunctionDeclStart(FD); - - if (FD->getBody()) { - Out << '\n'; - // FIXME: convert dumper to use std::ostream? - FD->getBody()->dumpAll(*SM); - Out << '\n'; - } - } else if (TypedefDecl *TD = dyn_cast(D)) { - PrintTypeDefDecl(TD); - } else if (ObjCInterfaceDecl *OID = dyn_cast(D)) { - Out << "Read objc interface '" << OID->getNameAsString() << "'\n"; - } else if (ObjCProtocolDecl *OPD = dyn_cast(D)) { - Out << "Read objc protocol '" << OPD->getNameAsString() << "'\n"; - } else if (ObjCCategoryDecl *OCD = dyn_cast(D)) { - Out << "Read objc category '" << OCD->getNameAsString() << "'\n"; - } else if (isa(D)) { - Out << "Read objc fwd protocol decl\n"; - } else if (isa(D)) { - Out << "Read objc fwd class decl\n"; - } else if (isa(D)) { - Out << "Read file scope asm decl\n"; - } else if (ObjCMethodDecl* MD = dyn_cast(D)) { - Out << "Read objc method decl: '" << MD->getSelector().getAsString() - << "'\n"; - if (MD->getBody()) { - // FIXME: convert dumper to use std::ostream? - MD->getBody()->dumpAll(*SM); - Out << '\n'; - } - } else if (isa(D)) { - Out << "Read objc implementation decl\n"; - } else if (isa(D)) { - Out << "Read objc category implementation decl\n"; - } else if (isa(D)) { - Out << "Read linkage spec decl\n"; - } else if (NamedDecl *ND = dyn_cast(D)) { - Out << "Read top-level variable decl: '" << ND->getNameAsString() - << "'\n"; - } else { - assert(0 && "Unknown decl type!"); - } + if (FD->getBody()) { + Out << '\n'; + // FIXME: convert dumper to use std::ostream? + FD->getBody()->dumpAll(*SM); + Out << '\n'; } - }; + } else if (TypedefDecl *TD = dyn_cast(D)) { + PrintTypeDefDecl(TD); + } else if (ObjCInterfaceDecl *OID = dyn_cast(D)) { + Out << "Read objc interface '" << OID->getNameAsString() << "'\n"; + } else if (ObjCProtocolDecl *OPD = dyn_cast(D)) { + Out << "Read objc protocol '" << OPD->getNameAsString() << "'\n"; + } else if (ObjCCategoryDecl *OCD = dyn_cast(D)) { + Out << "Read objc category '" << OCD->getNameAsString() << "'\n"; + } else if (isa(D)) { + Out << "Read objc fwd protocol decl\n"; + } else if (isa(D)) { + Out << "Read objc fwd class decl\n"; + } else if (isa(D)) { + Out << "Read file scope asm decl\n"; + } else if (ObjCMethodDecl* MD = dyn_cast(D)) { + Out << "Read objc method decl: '" << MD->getSelector().getAsString() + << "'\n"; + if (MD->getBody()) { + // FIXME: convert dumper to use std::ostream? + MD->getBody()->dumpAll(*SM); + Out << '\n'; + } + } else if (isa(D)) { + Out << "Read objc implementation decl\n"; + } else if (isa(D)) { + Out << "Read objc category implementation decl\n"; + } else if (isa(D)) { + Out << "Read linkage spec decl\n"; + } else if (NamedDecl *ND = dyn_cast(D)) { + Out << "Read top-level variable decl: '" << ND->getNameAsString() + << "'\n"; + } else { + assert(0 && "Unknown decl type!"); + } } ASTConsumer *clang::CreateASTDumper() { return new ASTDumper(); } @@ -623,29 +625,34 @@ namespace { SM = &Context.getSourceManager(); } - virtual void HandleTopLevelDecl(Decl *D) { - if (FunctionDecl *FD = dyn_cast(D)) { - DeclPrinter().PrintFunctionDeclStart(FD); - - if (FD->getBody()) { - llvm::cerr << '\n'; - FD->getBody()->viewAST(); - llvm::cerr << '\n'; - } - } - else if (ObjCMethodDecl *MD = dyn_cast(D)) { - DeclPrinter().PrintObjCMethodDecl(MD); - - if (MD->getBody()) { - llvm::cerr << '\n'; - MD->getBody()->viewAST(); - llvm::cerr << '\n'; - } - } - } + virtual void HandleTopLevelDecl(Decl *D); }; } +void ASTViewer::HandleTopLevelDecl(Decl *D) { + if (FunctionDecl *FD = dyn_cast(D)) { + DeclPrinter().PrintFunctionDeclStart(FD); + + if (FD->getBody()) { + llvm::cerr << '\n'; + FD->getBody()->viewAST(); + llvm::cerr << '\n'; + } + return; + } + + if (ObjCMethodDecl *MD = dyn_cast(D)) { + DeclPrinter().PrintObjCMethodDecl(MD); + + if (MD->getBody()) { + llvm::cerr << '\n'; + MD->getBody()->viewAST(); + llvm::cerr << '\n'; + } + } +} + + ASTConsumer *clang::CreateASTViewer() { return new ASTViewer(); } //===----------------------------------------------------------------------===// @@ -664,6 +671,7 @@ public: void PrintDeclContext(const DeclContext* DC, unsigned Indentation); }; +} // end anonymous namespace void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, unsigned Indentation) { @@ -919,9 +927,6 @@ void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, } } } - -} - ASTConsumer *clang::CreateDeclContextPrinter() { return new DeclContextPrinter(); } @@ -997,56 +1002,57 @@ public: BuildSerializer(const llvm::sys::Path& dir, Diagnostic& diags) : ASTSerializer(diags), EmitDir(dir) {} - virtual void HandleTranslationUnit(ASTContext &Ctx) { - if (Diags.hasErrorOccurred()) - return; - - SourceManager& SourceMgr = Ctx.getSourceManager(); - FileID ID = SourceMgr.getMainFileID(); - assert(!ID.isInvalid() && "MainFileID not set!"); - const FileEntry* FE = SourceMgr.getFileEntryForID(ID); - assert(FE && "No FileEntry for main file."); - - // FIXME: This is not portable to Windows. - // FIXME: This logic should probably be moved elsewhere later. - - llvm::sys::Path FName(EmitDir); - - std::vector buf; - buf.reserve(strlen(FE->getName())+100); - - sprintf(&buf[0], "dev_%llx", (unsigned long long) FE->getDevice()); - FName.appendComponent(&buf[0]); - FName.createDirectoryOnDisk(true); - if (!FName.canWrite() || !FName.isDirectory()) { - assert (false && "Could not create 'device' serialization directory."); - return; - } - - sprintf(&buf[0], "%s-%llX.ast", FE->getName(), - (unsigned long long) FE->getInode()); - FName.appendComponent(&buf[0]); - - - // Reserve 256K for bitstream buffer. - std::vector Buffer; - Buffer.reserve(256*1024); - - Ctx.EmitASTBitcodeBuffer(Buffer); - - // Write the bits to disk. - if (FILE* fp = fopen(FName.c_str(),"wb")) { - fwrite((char*)&Buffer.front(), sizeof(char), Buffer.size(), fp); - fclose(fp); - } - - // Now emit the sources. - - } + virtual void HandleTranslationUnit(ASTContext &Ctx); }; +} // end anonymous namespace + + +void BuildSerializer::HandleTranslationUnit(ASTContext &Ctx) { + if (Diags.hasErrorOccurred()) + return; + SourceManager& SourceMgr = Ctx.getSourceManager(); + FileID ID = SourceMgr.getMainFileID(); + assert(!ID.isInvalid() && "MainFileID not set!"); + const FileEntry* FE = SourceMgr.getFileEntryForID(ID); + assert(FE && "No FileEntry for main file."); -} // end anonymous namespace + // FIXME: This is not portable to Windows. + // FIXME: This logic should probably be moved elsewhere later. + + llvm::sys::Path FName(EmitDir); + + std::vector buf; + buf.reserve(strlen(FE->getName())+100); + + sprintf(&buf[0], "dev_%llx", (unsigned long long) FE->getDevice()); + FName.appendComponent(&buf[0]); + FName.createDirectoryOnDisk(true); + if (!FName.canWrite() || !FName.isDirectory()) { + assert (false && "Could not create 'device' serialization directory."); + return; + } + + sprintf(&buf[0], "%s-%llX.ast", FE->getName(), + (unsigned long long) FE->getInode()); + FName.appendComponent(&buf[0]); + + + // Reserve 256K for bitstream buffer. + std::vector Buffer; + Buffer.reserve(256*1024); + + Ctx.EmitASTBitcodeBuffer(Buffer); + + // Write the bits to disk. + if (FILE* fp = fopen(FName.c_str(),"wb")) { + fwrite((char*)&Buffer.front(), sizeof(char), Buffer.size(), fp); + fclose(fp); + } + + // Now emit the sources. + +} ASTConsumer* clang::CreateASTSerializer(const std::string& InFile,