Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit f351424

Browse files
committed
Add -cc1 -ast-dump-xml, an excessively detailed XML dump of the internals
of the ASTs. Only available in assertions builds. No stability guarantee. This is intended solely as a debugging tool. I'm not sure if the goals are sufficiently aligned with the XML printer to allow a common implementation. Currently just falls back on the StmtDumper to display statements, which means it doesn't produce valid XML in those cases. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120088 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 19b78d9 commit f351424

10 files changed

+51
-0
lines changed

include/clang/AST/DeclBase.h

+2
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,8 @@ class Decl {
622622
llvm::raw_ostream &Out, const PrintingPolicy &Policy,
623623
unsigned Indentation = 0);
624624
void dump() const;
625+
void dumpXML() const;
626+
void dumpXML(llvm::raw_ostream &OS) const;
625627

626628
private:
627629
const Attr *getAttrsImpl() const;

include/clang/Driver/CC1Options.td

+2
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ def ast_print_xml : Flag<"-ast-print-xml">,
330330
HelpText<"Build ASTs and then print them in XML format">;
331331
def ast_dump : Flag<"-ast-dump">,
332332
HelpText<"Build ASTs and then debug dump them">;
333+
def ast_dump_xml : Flag<"-ast-dump-xml">,
334+
HelpText<"Build ASTs and then debug dump them in a verbose XML format">;
333335
def ast_view : Flag<"-ast-view">,
334336
HelpText<"Build ASTs and view them with GraphViz">;
335337
def boostcon : Flag<"-boostcon">,

include/clang/Frontend/ASTConsumers.h

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ ASTConsumer *CreateASTPrinterXML(llvm::raw_ostream *OS);
4848
// intended for debugging.
4949
ASTConsumer *CreateASTDumper();
5050

51+
// AST XML-dumper: dumps out the AST to stderr in a very detailed XML
52+
// format; this is intended for particularly intense debugging.
53+
ASTConsumer *CreateASTDumperXML(llvm::raw_ostream &OS);
54+
5155
// Graphical AST viewer: for each function definition, creates a graph of
5256
// the AST and displays it with the graph viewer "dotty". Also outputs
5357
// function declarations to stderr.

include/clang/Frontend/FrontendActions.h

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ class ASTDumpAction : public ASTFrontendAction {
5454
llvm::StringRef InFile);
5555
};
5656

57+
class ASTDumpXMLAction : public ASTFrontendAction {
58+
protected:
59+
virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
60+
llvm::StringRef InFile);
61+
};
62+
5763
class ASTViewAction : public ASTFrontendAction {
5864
protected:
5965
virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,

include/clang/Frontend/FrontendOptions.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace clang {
2121
namespace frontend {
2222
enum ActionKind {
2323
ASTDump, ///< Parse ASTs and dump them.
24+
ASTDumpXML, ///< Parse ASTs and dump them in XML.
2425
ASTPrint, ///< Parse ASTs and print them.
2526
ASTPrintXML, ///< Parse ASTs and print them in XML.
2627
ASTView, ///< Parse ASTs and view them in Graphviz.

lib/AST/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ add_clang_library(clangAST
1919
DeclObjC.cpp
2020
DeclPrinter.cpp
2121
DeclTemplate.cpp
22+
DumpXML.cpp
2223
Expr.cpp
2324
ExprClassification.cpp
2425
ExprConstant.cpp

lib/Frontend/ASTConsumers.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,23 @@ class InheritanceViewer : public ASTConsumer {
449449
ASTConsumer *clang::CreateInheritanceViewer(const std::string& clsname) {
450450
return new InheritanceViewer(clsname);
451451
}
452+
453+
//===----------------------------------------------------------------------===//
454+
/// ASTDumperXML - In-depth XML dumping.
455+
456+
namespace {
457+
class ASTDumpXML : public ASTConsumer {
458+
llvm::raw_ostream &OS;
459+
460+
public:
461+
ASTDumpXML(llvm::raw_ostream &OS) : OS(OS) {}
462+
463+
void HandleTranslationUnit(ASTContext &C) {
464+
C.getTranslationUnitDecl()->dumpXML(OS);
465+
}
466+
};
467+
}
468+
469+
ASTConsumer *clang::CreateASTDumperXML(llvm::raw_ostream &OS) {
470+
return new ASTDumpXML(OS);
471+
}

lib/Frontend/CompilerInvocation.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ static const char *getActionName(frontend::ActionKind Kind) {
319319
llvm_unreachable("Invalid kind!");
320320

321321
case frontend::ASTDump: return "-ast-dump";
322+
case frontend::ASTDumpXML: return "-ast-dump-xml";
322323
case frontend::ASTPrint: return "-ast-print";
323324
case frontend::ASTPrintXML: return "-ast-print-xml";
324325
case frontend::ASTView: return "-ast-view";
@@ -1003,6 +1004,8 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
10031004
assert(0 && "Invalid option in group!");
10041005
case OPT_ast_dump:
10051006
Opts.ProgramAction = frontend::ASTDump; break;
1007+
case OPT_ast_dump_xml:
1008+
Opts.ProgramAction = frontend::ASTDumpXML; break;
10061009
case OPT_ast_print:
10071010
Opts.ProgramAction = frontend::ASTPrint; break;
10081011
case OPT_ast_print_xml:

lib/Frontend/FrontendActions.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ ASTConsumer *ASTDumpAction::CreateASTConsumer(CompilerInstance &CI,
5959
return CreateASTDumper();
6060
}
6161

62+
ASTConsumer *ASTDumpXMLAction::CreateASTConsumer(CompilerInstance &CI,
63+
llvm::StringRef InFile) {
64+
llvm::raw_ostream *OS;
65+
if (CI.getFrontendOpts().OutputFile.empty())
66+
OS = &llvm::outs();
67+
else
68+
OS = CI.createDefaultOutputFile(false, InFile);
69+
if (!OS) return 0;
70+
return CreateASTDumperXML(*OS);
71+
}
72+
6273
ASTConsumer *ASTViewAction::CreateASTConsumer(CompilerInstance &CI,
6374
llvm::StringRef InFile) {
6475
return CreateASTViewer();

lib/FrontendTool/ExecuteCompilerInvocation.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ static FrontendAction *CreateFrontendBaseAction(CompilerInstance &CI) {
3535
llvm_unreachable("Invalid program action!");
3636

3737
case ASTDump: return new ASTDumpAction();
38+
case ASTDumpXML: return new ASTDumpXMLAction();
3839
case ASTPrint: return new ASTPrintAction();
3940
case ASTPrintXML: return new ASTPrintXMLAction();
4041
case ASTView: return new ASTViewAction();

0 commit comments

Comments
 (0)