diff options
author | Brad King <brad.king@kitware.com> | 2014-03-04 18:59:50 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2014-03-21 21:11:01 (GMT) |
commit | c722f17c03226b1101cdd732e169360b5f9a81a0 (patch) | |
tree | 498a5dacf6abf89b79f9961160e220d431ad04cd | |
parent | 32b50da7a2d85b1d0204ac05260e104a7094ca74 (diff) | |
download | CastXML-c722f17c03226b1101cdd732e169360b5f9a81a0.zip CastXML-c722f17c03226b1101cdd732e169360b5f9a81a0.tar.gz CastXML-c722f17c03226b1101cdd732e169360b5f9a81a0.tar.bz2 |
Output: Add init="" attribute to Variable elements
-rw-r--r-- | src/Output.cxx | 8 | ||||
-rw-r--r-- | test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/expect/gccxml.Variable-init-xml.txt | 12 | ||||
-rw-r--r-- | test/input/Variable-init.cxx | 4 |
4 files changed, 25 insertions, 0 deletions
diff --git a/src/Output.cxx b/src/Output.cxx index 9fc51ce..4643203 100644 --- a/src/Output.cxx +++ b/src/Output.cxx @@ -1075,6 +1075,14 @@ void ASTVisitor::OutputVarDecl(clang::VarDecl const* d, DumpNode const* dn) this->PrintIdAttribute(dn); this->PrintNameAttribute(d->getName().str()); this->PrintTypeAttribute(d->getType(), dn->Complete); + if(clang::Expr const* init = d->getInit()) { + this->OS << " init=\""; + std::string s; + llvm::raw_string_ostream rso(s); + init->printPretty(rso, 0, this->CTX.getPrintingPolicy()); + this->OS << encodeXML(rso.str()); + this->OS << "\""; + } this->PrintContextAttribute(d); this->PrintLocationAttribute(d); if(d->getStorageClass() == clang::SC_Static) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6bc17b7..1102aff 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -93,6 +93,7 @@ castxml_test_gccxml(Typedef-paren) castxml_test_gccxml(Typedef-to-Class-template) castxml_test_gccxml(Variable) castxml_test_gccxml(Variable-in-Class) +castxml_test_gccxml(Variable-init) castxml_test_gccxml(qualified-type-name) castxml_test_gccxml(using-declaration-ns) diff --git a/test/expect/gccxml.Variable-init-xml.txt b/test/expect/gccxml.Variable-init-xml.txt new file mode 100644 index 0000000..7eb4cf5 --- /dev/null +++ b/test/expect/gccxml.Variable-init-xml.txt @@ -0,0 +1,12 @@ +^<\?xml version="1.0"\?> +<GCC_XML[^>]*> + <Namespace id="_1" name="start" context="_2" members="_3 _4"/> + <Variable id="_3" name="var_int" type="_5" init="123" context="_1" location="f1:2" file="f1" line="2"/> + <Variable id="_4" name="var_str" type="_6" init=""abc"" context="_1" location="f1:3" file="f1" line="3"/> + <FundamentalType id="_5" name="int"/> + <PointerType id="_6" type="_8c"/> + <Namespace id="_2" name="::"/> + <FundamentalType id="_8" name="char"/> + <CvQualifiedType id="_8c" type="_8" const="1"/> + <File id="f1" name=".*/test/input/Variable-init.cxx"/> +</GCC_XML>$ diff --git a/test/input/Variable-init.cxx b/test/input/Variable-init.cxx new file mode 100644 index 0000000..79b05cf --- /dev/null +++ b/test/input/Variable-init.cxx @@ -0,0 +1,4 @@ +namespace start { + int var_int = 123; + const char* var_str = "abc"; +} |