aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/ASTConsumers.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-05-29 20:38:28 +0000
committerDouglas Gregor <dgregor@apple.com>2009-05-29 20:38:28 +0000
commitd249e1d1f1498b81314459ceda19d6ff25c278ad (patch)
tree64980c7c4974845750bbfefa695204a8feff0861 /lib/Frontend/ASTConsumers.cpp
parente540858b289b23653bcb23646f135729203635cb (diff)
Create a new PrintingPolicy class, which we pass down through the AST
printing logic to help customize the output. For now, we use this rather than a special flag to suppress the "struct" when printing "struct X" and to print the Boolean type as "bool" in C++ but "_Bool" in C. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72590 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/ASTConsumers.cpp')
-rw-r--r--lib/Frontend/ASTConsumers.cpp26
1 files changed, 15 insertions, 11 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';
}
}