From 73b947ec075e536535e9cc5bec84d1bed4d43d5b Mon Sep 17 00:00:00 2001 From: Michka Popoff Date: Mon, 25 May 2015 10:55:04 +0200 Subject: castxml: Teach --castxml-start to support a comma-separated list In gccxml one could input a comma-separated list for the starting declarations to parse. Add support for this with tests for cases were a comma-separated list is used, and for the case where --castxml-start is used multiple times. --- doc/manual/castxml.1.rst | 7 ++++--- src/castxml.cxx | 13 ++++++++++--- test/CMakeLists.txt | 9 +++++++++ test/expect/gccxml.any.Namespace-nested-1.xml.txt | 11 +++++++++++ test/expect/gccxml.any.Namespace-nested-2.xml.txt | 11 +++++++++++ 5 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 test/expect/gccxml.any.Namespace-nested-1.xml.txt create mode 100644 test/expect/gccxml.any.Namespace-nested-2.xml.txt diff --git a/doc/manual/castxml.1.rst b/doc/manual/castxml.1.rst index a1a0172..4bf31f9 100644 --- a/doc/manual/castxml.1.rst +++ b/doc/manual/castxml.1.rst @@ -55,9 +55,10 @@ Remaining options are given to the internal Clang compiler. move constructors or move assignment operators, and may contain ```` elements on non-c++98 constructs. -``--castxml-start `` - Start AST traversal at the declaration(s) with the given - qualified name. +``--castxml-start [,]...`` + Start AST traversal at declaration(s) with the given qualified name(s). + Multiple names may be specified as a comma-separated list or by repeating + the option. ``-help``, ``--help`` Print ``castxml`` and internal Clang compiler usage information. diff --git a/src/castxml.cxx b/src/castxml.cxx index cb0570b..12ab336 100644 --- a/src/castxml.cxx +++ b/src/castxml.cxx @@ -27,6 +27,7 @@ #include "llvm/Support/raw_ostream.h" #include +#include #include #include #include @@ -91,8 +92,10 @@ int main(int argc_in, const char** argv_in) " --castxml-gccxml\n" " Write gccxml-format output to .xml or file named by '-o'\n" "\n" - " --castxml-start \n" - " Start AST traversal at declaration with given (qualified) name\n" + " --castxml-start [,]...\n" + " Start AST traversal at declaration(s) with the given (qualified)\n" + " name(s). Multiple names may be specified as a comma-separated\n" + " list or by repeating the option.\n" "\n" " -help, --help\n" " Print castxml and internal Clang compiler usage information\n" @@ -124,7 +127,11 @@ int main(int argc_in, const char** argv_in) } } else if(strcmp(argv[i], "--castxml-start") == 0) { if((i+1) < argc) { - opts.StartNames.push_back(argv[++i]); + std::string item; + std::stringstream stream(argv[++i]); + while (std::getline(stream, item, ',')) { + opts.StartNames.push_back(item); + } } else { std::cerr << "error: argument to '--castxml-start' is missing " diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index afbbbaf..ae61ace 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -240,6 +240,15 @@ castxml_test_gccxml(Variable) castxml_test_gccxml(Variable-in-Class) castxml_test_gccxml(Variable-init) +# Test multiple start declarations. +set(castxml_test_gccxml_custom_input Namespace-nested) +set(castxml_test_gccxml_custom_start --castxml-start start::ns1,start::ns3) +castxml_test_gccxml(Namespace-nested-1) +set(castxml_test_gccxml_custom_start --castxml-start start::ns1 --castxml-start start::ns3) +castxml_test_gccxml(Namespace-nested-2) +unset(castxml_test_gccxml_custom_start) +unset(castxml_test_gccxml_custom_input) + castxml_test_gccxml(qualified-type-name) castxml_test_gccxml(using-declaration-class) castxml_test_gccxml(using-declaration-ns) diff --git a/test/expect/gccxml.any.Namespace-nested-1.xml.txt b/test/expect/gccxml.any.Namespace-nested-1.xml.txt new file mode 100644 index 0000000..49673f0 --- /dev/null +++ b/test/expect/gccxml.any.Namespace-nested-1.xml.txt @@ -0,0 +1,11 @@ +^<\?xml version="1.0"\?> +]*> + + + + + + + + +$ diff --git a/test/expect/gccxml.any.Namespace-nested-2.xml.txt b/test/expect/gccxml.any.Namespace-nested-2.xml.txt new file mode 100644 index 0000000..49673f0 --- /dev/null +++ b/test/expect/gccxml.any.Namespace-nested-2.xml.txt @@ -0,0 +1,11 @@ +^<\?xml version="1.0"\?> +]*> + + + + + + + + +$ -- cgit v0.12