 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
0.0% |
0 / 0 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
0.0% |
0 / 0 |
| |
|
Line Coverage: |
83.3% |
15 / 18 |
| |
 |
|
 |
1 : //===--- DocumentXML.cpp - XML document for ASTs --------------------------===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 : //
10 : // This file implements the XML document class, which provides the means to
11 : // dump out the AST in a XML form that exposes type details and other fields.
12 : //
13 : //===----------------------------------------------------------------------===//
14 :
15 : #include "clang/Frontend/DocumentXML.h"
16 : #include "clang/AST/TypeVisitor.h"
17 : #include "clang/AST/Type.h"
18 : #include "clang/AST/Decl.h"
19 :
20 : namespace clang {
21 : namespace XML {
22 : namespace {
23 :
24 : //---------------------------------------------------------
25 : class TypeWriter : public TypeVisitor<TypeWriter> {
26 : DocumentXML& Doc;
27 :
28 : public:
29 56: TypeWriter(DocumentXML& doc) : Doc(doc) {}
30 :
31 : #define NODE_XML( CLASS, NAME ) \
32 : void Visit##CLASS(CLASS* T) { \
33 : Doc.addSubNode(NAME);
34 :
35 : #define ID_ATTRIBUTE_XML // done by the Document class itself
36 : #define ATTRIBUTE_XML( FN, NAME ) Doc.addAttribute(NAME, T->FN);
37 : #define TYPE_ATTRIBUTE_XML( FN ) ATTRIBUTE_XML(FN, "type")
38 : #define CONTEXT_ATTRIBUTE_XML( FN ) ATTRIBUTE_XML(FN, "context")
39 : #define ATTRIBUTE_OPT_XML( FN, NAME ) Doc.addAttributeOptional(NAME, T->FN);
40 :
41 : #define ATTRIBUTE_ENUM_XML( FN, NAME ) \
42 : { \
43 : const char* pAttributeName = NAME; \
44 : const bool optional = false; \
45 : switch (T->FN) { \
46 : default: assert(0 && "unknown enum value");
47 :
48 : #define ATTRIBUTE_ENUM_OPT_XML( FN, NAME ) \
49 : { \
50 : const char* pAttributeName = NAME; \
51 : const bool optional = true; \
52 : switch (T->FN) { \
53 : default: assert(0 && "unknown enum value");
54 :
55 : #define ENUM_XML( VALUE, NAME ) case VALUE: if ((!optional) || NAME[0]) Doc.addAttribute(pAttributeName, NAME); break;
56 : #define END_ENUM_XML } }
57 : #define END_NODE_XML }
58 :
59 : #include "clang/Frontend/TypeXML.def"
60 :
61 : };
62 :
63 : //---------------------------------------------------------
64 : } // anon clang
65 : } // NS XML
66 :
67 : //---------------------------------------------------------
68 : class DocumentXML::TypeAdder : public TypeVisitor<DocumentXML::TypeAdder> {
69 : DocumentXML& Doc;
70 :
71 0: void addIfType(const Type* pType) {
72 0: Doc.addTypeRecursively(pType);
73 0: }
74 :
75 9: void addIfType(const QualType& pType) {
76 9: Doc.addTypeRecursively(pType);
77 9: }
78 :
79 19: template<class T> void addIfType(T) {}
80 :
81 : public:
82 54: TypeAdder(DocumentXML& doc) : Doc(doc) {}
83 :
84 : #define NODE_XML( CLASS, NAME ) \
85 : void Visit##CLASS(CLASS* T) \
86 : {
87 :
88 : #define ID_ATTRIBUTE_XML
89 : #define TYPE_ATTRIBUTE_XML( FN ) Doc.addTypeRecursively(T->FN);
90 : #define CONTEXT_ATTRIBUTE_XML( FN )
91 : #define ATTRIBUTE_XML( FN, NAME ) addIfType(T->FN);
92 : #define ATTRIBUTE_OPT_XML( FN, NAME )
93 : #define ATTRIBUTE_ENUM_XML( FN, NAME )
94 : #define ATTRIBUTE_ENUM_OPT_XML( FN, NAME )
95 : #define ENUM_XML( VALUE, NAME )
96 : #define END_ENUM_XML
97 : #define END_NODE_XML }
98 :
99 : #include "clang/Frontend/TypeXML.def"
100 : };
101 :
102 : //---------------------------------------------------------
103 54: void DocumentXML::addParentTypes(const Type* pType) {
104 54: TypeAdder(*this).Visit(const_cast<Type*>(pType));
105 54: }
106 :
107 : //---------------------------------------------------------
108 54: void DocumentXML::writeTypeToXML(const Type* pType) {
109 54: XML::TypeWriter(*this).Visit(const_cast<Type*>(pType));
110 54: }
111 :
112 : //---------------------------------------------------------
113 2: void DocumentXML::writeTypeToXML(const QualType& pType) {
114 2: XML::TypeWriter(*this).VisitQualType(const_cast<QualType*>(&pType));
115 2: }
116 :
117 : //---------------------------------------------------------
118 : } // NS clang
119 :
Generated: 2010-02-10 01:31 by zcov