diff options
Diffstat (limited to 'lib/Frontend')
-rw-r--r-- | lib/Frontend/ASTConsumers.cpp | 26 | ||||
-rw-r--r-- | lib/Frontend/DocumentXML.cpp | 2 | ||||
-rw-r--r-- | lib/Frontend/RewriteBlocks.cpp | 20 | ||||
-rw-r--r-- | lib/Frontend/RewriteObjC.cpp | 22 |
4 files changed, 41 insertions, 29 deletions
diff --git a/lib/Frontend/ASTConsumers.cpp b/lib/Frontend/ASTConsumers.cpp index ba482b049a..c35f4c9e20 100644 --- a/lib/Frontend/ASTConsumers.cpp +++ b/lib/Frontend/ASTConsumers.cpp @@ -20,6 +20,7 @@ #include "clang/AST/AST.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/PrettyPrinter.h" #include "clang/CodeGen/ModuleBuilder.h" #include "llvm/Module.h" #include "llvm/Support/Streams.h" @@ -35,10 +36,13 @@ namespace { class DeclPrinter { public: llvm::raw_ostream& Out; + PrintingPolicy Policy; unsigned Indentation; - DeclPrinter(llvm::raw_ostream* out) : Out(out ? *out : llvm::errs()), - Indentation(0) {} + DeclPrinter(llvm::raw_ostream* out, + const PrintingPolicy &Policy = PrintingPolicy()) + : Out(out ? *out : llvm::errs()), Policy(Policy), + Indentation(0) {} DeclPrinter() : Out(llvm::errs()), Indentation(0) {} virtual ~DeclPrinter(); @@ -84,7 +88,7 @@ void DeclPrinter:: PrintDecl(Decl *D) { // FIXME: Pass a context here so we can use getBody() if (FD->getBodyIfAvailable()) { Out << ' '; - FD->getBodyIfAvailable()->printPretty(Out, 0, Indentation, true); + FD->getBodyIfAvailable()->printPretty(Out, 0, Policy); Out << '\n'; } } else if (isa<ObjCMethodDecl>(D)) { @@ -162,7 +166,7 @@ void DeclPrinter:: PrintDecl(Decl *D) { PrintLinkageSpec(LSD); } else if (FileScopeAsmDecl *AD = dyn_cast<FileScopeAsmDecl>(D)) { Out << "asm("; - AD->getAsmString()->printPretty(Out); + AD->getAsmString()->printPretty(Out, 0, Policy); Out << ")\n"; } else if (NamedDecl *ND = dyn_cast<NamedDecl>(D)) { Print(ND); @@ -193,12 +197,12 @@ void DeclPrinter::Print(NamedDecl *ND) { } std::string Name = ND->getNameAsString(); // This forms: "int a". - dyn_cast<ValueDecl>(ND)->getType().getAsStringInternal(Name); + dyn_cast<ValueDecl>(ND)->getType().getAsStringInternal(Name, Policy); Out << Name; if (VarDecl *Var = dyn_cast<VarDecl>(ND)) { if (Var->getInit()) { Out << " = "; - Var->getInit()->printPretty(Out); + Var->getInit()->printPretty(Out, 0, Policy); } } Out << ";\n"; @@ -252,7 +256,7 @@ void DeclPrinter::PrintFunctionDeclStart(FunctionDecl *FD) { std::string ParamStr; if (HasBody) ParamStr = FD->getParamDecl(i)->getNameAsString(); - FT->getArgType(i).getAsStringInternal(ParamStr); + FT->getArgType(i).getAsStringInternal(ParamStr, Policy); Proto += ParamStr; } @@ -266,7 +270,7 @@ void DeclPrinter::PrintFunctionDeclStart(FunctionDecl *FD) { Proto += "()"; } - AFT->getResultType().getAsStringInternal(Proto); + AFT->getResultType().getAsStringInternal(Proto, Policy); Out << Proto; if (!FD->getBodyIfAvailable()) @@ -276,7 +280,7 @@ void DeclPrinter::PrintFunctionDeclStart(FunctionDecl *FD) { void DeclPrinter::PrintTypeDefDecl(TypedefDecl *TD) { std::string S = TD->getNameAsString(); - TD->getUnderlyingType().getAsStringInternal(S); + TD->getUnderlyingType().getAsStringInternal(S, Policy); Out << "typedef " << S << ";\n"; } @@ -358,7 +362,7 @@ void DeclPrinter::PrintObjCImplementationDecl(ObjCImplementationDecl *OID) { PrintObjCMethodDecl(OMD); if (OMD->getBody()) { Out << ' '; - OMD->getBody()->printPretty(Out); + OMD->getBody()->printPretty(Out, 0, Policy); Out << '\n'; } } @@ -371,7 +375,7 @@ void DeclPrinter::PrintObjCImplementationDecl(ObjCImplementationDecl *OID) { PrintObjCMethodDecl(OMD); if (OMD->getBody()) { Out << ' '; - OMD->getBody()->printPretty(Out); + OMD->getBody()->printPretty(Out, 0, Policy); Out << '\n'; } } diff --git a/lib/Frontend/DocumentXML.cpp b/lib/Frontend/DocumentXML.cpp index 80060f5b73..ac1d7d2a8b 100644 --- a/lib/Frontend/DocumentXML.cpp +++ b/lib/Frontend/DocumentXML.cpp @@ -194,7 +194,7 @@ void DocumentXML::finalize() // don't use the get methods as they strip of typedef infos if (const BuiltinType *BT = dyn_cast<BuiltinType>(i->first)) { addSubNode("FundamentalType"); - addAttribute("name", BT->getName()); + addAttribute("name", BT->getName(Ctx->getLangOptions().CPlusPlus)); } else if (const PointerType *PT = dyn_cast<PointerType>(i->first)) { addSubNode("PointerType"); diff --git a/lib/Frontend/RewriteBlocks.cpp b/lib/Frontend/RewriteBlocks.cpp index 29f0578882..6d0f10def2 100644 --- a/lib/Frontend/RewriteBlocks.cpp +++ b/lib/Frontend/RewriteBlocks.cpp @@ -396,7 +396,7 @@ std::string RewriteBlocks::SynthesizeBlockFunc(BlockExpr *CE, int i, E = BD->param_end(); AI != E; ++AI) { if (AI != BD->param_begin()) S += ", "; ParamStr = (*AI)->getNameAsString(); - (*AI)->getType().getAsStringInternal(ParamStr); + (*AI)->getType().getAsStringInternal(ParamStr, Context->PrintingPolicy); S += ParamStr; } if (FT->isVariadic()) { @@ -413,7 +413,8 @@ std::string RewriteBlocks::SynthesizeBlockFunc(BlockExpr *CE, int i, E = BlockByRefDecls.end(); I != E; ++I) { S += " "; std::string Name = (*I)->getNameAsString(); - Context->getPointerType((*I)->getType()).getAsStringInternal(Name); + Context->getPointerType((*I)->getType()).getAsStringInternal(Name, + Context->PrintingPolicy); S += Name + " = __cself->" + (*I)->getNameAsString() + "; // bound by ref\n"; } // Next, emit a declaration for all "by copy" declarations. @@ -434,7 +435,7 @@ std::string RewriteBlocks::SynthesizeBlockFunc(BlockExpr *CE, int i, if (isBlockPointerType((*I)->getType())) S += "struct __block_impl *"; else - (*I)->getType().getAsStringInternal(Name); + (*I)->getType().getAsStringInternal(Name, Context->PrintingPolicy); S += Name + " = __cself->" + (*I)->getNameAsString() + "; // bound by copy\n"; } std::string RewrittenStr = RewrittenBlockExprs[CE]; @@ -515,8 +516,8 @@ std::string RewriteBlocks::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag, S += "struct __block_impl *"; Constructor += ", void *" + ArgName; } else { - (*I)->getType().getAsStringInternal(FieldName); - (*I)->getType().getAsStringInternal(ArgName); + (*I)->getType().getAsStringInternal(FieldName, Context->PrintingPolicy); + (*I)->getType().getAsStringInternal(ArgName, Context->PrintingPolicy); Constructor += ", " + ArgName; } S += FieldName + ";\n"; @@ -541,8 +542,10 @@ std::string RewriteBlocks::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag, S += "struct __block_impl *"; Constructor += ", void *" + ArgName; } else { - Context->getPointerType((*I)->getType()).getAsStringInternal(FieldName); - Context->getPointerType((*I)->getType()).getAsStringInternal(ArgName); + Context->getPointerType((*I)->getType()).getAsStringInternal(FieldName, + Context->PrintingPolicy); + Context->getPointerType((*I)->getType()).getAsStringInternal(ArgName, + Context->PrintingPolicy); Constructor += ", " + ArgName; } S += FieldName + "; // by ref\n"; @@ -947,7 +950,8 @@ std::string RewriteBlocks::SynthesizeBlockInitExpr(BlockExpr *Exp, VarDecl *VD) std::string FunkTypeStr; // Get a pointer to the function type so we can cast appropriately. - Context->getPointerType(QualType(Exp->getFunctionType(),0)).getAsStringInternal(FunkTypeStr); + Context->getPointerType(QualType(Exp->getFunctionType(),0)) + .getAsStringInternal(FunkTypeStr, Context->PrintingPolicy); // Rewrite the closure block with a compound literal. The first cast is // to prevent warnings from the C compiler. diff --git a/lib/Frontend/RewriteObjC.cpp b/lib/Frontend/RewriteObjC.cpp index 79ae08cee5..55f0b405a9 100644 --- a/lib/Frontend/RewriteObjC.cpp +++ b/lib/Frontend/RewriteObjC.cpp @@ -944,9 +944,10 @@ void RewriteObjC::RewriteObjCMethodDecl(ObjCMethodDecl *OMD, if (isTopLevelBlockPointerType(PDecl->getType())) { // Make sure we convert "t (^)(...)" to "t (*)(...)". const BlockPointerType *BPT = PDecl->getType()->getAsBlockPointerType(); - Context->getPointerType(BPT->getPointeeType()).getAsStringInternal(Name); + Context->getPointerType(BPT->getPointeeType()).getAsStringInternal(Name, + Context->PrintingPolicy); } else - PDecl->getType().getAsStringInternal(Name); + PDecl->getType().getAsStringInternal(Name, Context->PrintingPolicy); ResultStr += Name; } } @@ -3600,7 +3601,7 @@ std::string RewriteObjC::SynthesizeBlockFunc(BlockExpr *CE, int i, E = BD->param_end(); AI != E; ++AI) { if (AI != BD->param_begin()) S += ", "; ParamStr = (*AI)->getNameAsString(); - (*AI)->getType().getAsStringInternal(ParamStr); + (*AI)->getType().getAsStringInternal(ParamStr, Context->PrintingPolicy); S += ParamStr; } if (FT->isVariadic()) { @@ -3617,7 +3618,8 @@ std::string RewriteObjC::SynthesizeBlockFunc(BlockExpr *CE, int i, E = BlockByRefDecls.end(); I != E; ++I) { S += " "; std::string Name = (*I)->getNameAsString(); - Context->getPointerType((*I)->getType()).getAsStringInternal(Name); + Context->getPointerType((*I)->getType()).getAsStringInternal(Name, + Context->PrintingPolicy); S += Name + " = __cself->" + (*I)->getNameAsString() + "; // bound by ref\n"; } // Next, emit a declaration for all "by copy" declarations. @@ -3638,7 +3640,7 @@ std::string RewriteObjC::SynthesizeBlockFunc(BlockExpr *CE, int i, if (isTopLevelBlockPointerType((*I)->getType())) S += "struct __block_impl *"; else - (*I)->getType().getAsStringInternal(Name); + (*I)->getType().getAsStringInternal(Name, Context->PrintingPolicy); S += Name + " = __cself->" + (*I)->getNameAsString() + "; // bound by copy\n"; } std::string RewrittenStr = RewrittenBlockExprs[CE]; @@ -3719,8 +3721,8 @@ std::string RewriteObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag, S += "struct __block_impl *"; Constructor += ", void *" + ArgName; } else { - (*I)->getType().getAsStringInternal(FieldName); - (*I)->getType().getAsStringInternal(ArgName); + (*I)->getType().getAsStringInternal(FieldName, Context->PrintingPolicy); + (*I)->getType().getAsStringInternal(ArgName, Context->PrintingPolicy); Constructor += ", " + ArgName; } S += FieldName + ";\n"; @@ -3745,8 +3747,10 @@ std::string RewriteObjC::SynthesizeBlockImpl(BlockExpr *CE, std::string Tag, S += "struct __block_impl *"; Constructor += ", void *" + ArgName; } else { - Context->getPointerType((*I)->getType()).getAsStringInternal(FieldName); - Context->getPointerType((*I)->getType()).getAsStringInternal(ArgName); + Context->getPointerType((*I)->getType()).getAsStringInternal(FieldName, + Context->PrintingPolicy); + Context->getPointerType((*I)->getType()).getAsStringInternal(ArgName, + Context->PrintingPolicy); Constructor += ", " + ArgName; } S += FieldName + "; // by ref\n"; |