diff options
author | Brad King <brad.king@kitware.com> | 2016-03-16 18:50:27 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-03-16 19:11:28 (GMT) |
commit | 86c6385eee64dcd3107a59b443e5a89f854d9da9 (patch) | |
tree | 8f632be6db6b0d0be2b1f2f38f2a3b5919174d45 /test | |
parent | d49f98f75a252b1ce0382fa2e9e0345710b96ffb (diff) | |
download | CastXML-86c6385eee64dcd3107a59b443e5a89f854d9da9.zip CastXML-86c6385eee64dcd3107a59b443e5a89f854d9da9.tar.gz CastXML-86c6385eee64dcd3107a59b443e5a89f854d9da9.tar.bz2 |
Output: Print canonical form of types named in default arguments
In code like
namespace ns {
typedef unsigned int UI;
void f(UI = (UI)0);
}
we previously generated `default="(UI)0"` for the default argument of
`f` because Clang prints the expression as it was written in the source.
GCC-XML would generate the canonical typed value `default="0u"`.
Ideally we should generate `default="(ns::UI)0"` but Clang does not
offer hooks into its type printing API. Instead we can produce a value
which is useful to tools reading the output by printing the cast with a
canonical type like `default="(unsigned int)0"`. In the case that the
type names a struct or class the canonical type will be printed as the
fully qualified name.
GitHub-Issue: CastXML/CastXML#51
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 2 | ||||
-rw-r--r-- | test/expect/gccxml.any.Function-Argument-default-cast.xml.txt | 48 | ||||
-rw-r--r-- | test/expect/gccxml.any.Method-Argument-default-cast.xml.txt | 27 | ||||
-rw-r--r-- | test/input/Function-Argument-default-cast.cxx | 13 | ||||
-rw-r--r-- | test/input/Method-Argument-default-cast.cxx | 8 |
5 files changed, 98 insertions, 0 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e184325..973264a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -298,6 +298,7 @@ castxml_test_gccxml(Function-annotate) castxml_test_gccxml(Function-Argument-annotate) castxml_test_gccxml(Function-Argument-decay) castxml_test_gccxml(Function-Argument-default) +castxml_test_gccxml(Function-Argument-default-cast) castxml_test_gccxml(Function-Argument-default-ns) castxml_test_gccxml(Function-rvalue-reference) castxml_test_gccxml(Function-template) @@ -310,6 +311,7 @@ castxml_test_gccxml(FundamentalTypes) castxml_test_gccxml(Method) castxml_test_gccxml(Method-annotate) castxml_test_gccxml(Method-Argument-default) +castxml_test_gccxml(Method-Argument-default-cast) castxml_test_gccxml(Method-overrides) castxml_test_gccxml(Method-rvalue-reference) castxml_test_gccxml(MethodType) diff --git a/test/expect/gccxml.any.Function-Argument-default-cast.xml.txt b/test/expect/gccxml.any.Function-Argument-default-cast.xml.txt new file mode 100644 index 0000000..577adb1 --- /dev/null +++ b/test/expect/gccxml.any.Function-Argument-default-cast.xml.txt @@ -0,0 +1,48 @@ +^<\?xml version="1.0"\?> +<GCC_XML[^>]*> + <Namespace id="_1" name="start" context="_2" members="_3 _4 _5 _6 _7 _8"/> + <Struct id="_3" name="Base" context="_1" location="f1:2" file="f1" line="2" members="_9 _10 _11 _12" size="[0-9]+" align="[0-9]+"/> + <Struct id="_4" name="Derived" context="_1" location="f1:3" file="f1" line="3" members="_13 _14 _15 _16" bases="_3" size="[0-9]+" align="[0-9]+"> + <Base type="_3" access="public" virtual="0" offset="0"/> + </Struct> + <Function id="_5" name="b" returns="_17" context="_1" location="f1:4" file="f1" line="4" mangled="[^"]+"/> + <Function id="_6" name="bc" returns="_18" context="_1" location="f1:5" file="f1" line="5" mangled="[^"]+"/> + <Typedef id="_7" name="Int" type="_19" context="_1" location="f1:6" file="f1" line="6"/> + <Function id="_8" name="f" returns="_20" context="_1" location="f1:7" file="f1" line="7" mangled="[^"]+"> + <Argument type="_7" location="f1:7" file="f1" line="7" default="\(int\)0"/> + <Argument type="_17" location="f1:8" file="f1" line="8" default="\(start::Base \*\)0"/> + <Argument type="_17" location="f1:9" file="f1" line="9" default="static_cast<start::Base \*>\(0\)"/> + <Argument type="_17" location="f1:10" file="f1" line="10" default="reinterpret_cast<start::Base \*>\(0\)"/> + <Argument type="_17" location="f1:11" file="f1" line="11" default="const_cast<start::Base \*>\(start::bc\(\)\)"/> + <Argument type="_21" location="f1:12" file="f1" line="12" default="dynamic_cast<start::Derived \*>\(start::b\(\)\)"/> + </Function> + <Constructor id="_9" name="Base" context="_3" access="public" location="f1:2" file="f1" line="2"/> + <Destructor id="_10" name="Base" context="_3" access="public" location="f1:2" file="f1" line="2" virtual="1"/> + <OperatorMethod id="_11" name="=" returns="_22" context="_3" access="public" location="f1:2" file="f1" line="2" inline="1" artificial="1"( throw="")? mangled="[^"]+"> + <Argument type="_23" location="f1:2" file="f1" line="2"/> + </OperatorMethod> + <Constructor id="_12" name="Base" context="_3" access="public" location="f1:2" file="f1" line="2" inline="1" artificial="1"( throw="")?> + <Argument type="_23" location="f1:2" file="f1" line="2"/> + </Constructor> + <OperatorMethod id="_13" name="=" returns="_24" context="_4" access="public" location="f1:3" file="f1" line="3" inline="1" artificial="1"( throw="")? mangled="[^"]+"> + <Argument type="_25" location="f1:3" file="f1" line="3"/> + </OperatorMethod> + <Destructor id="_14" name="Derived" context="_4" access="public" location="f1:3" file="f1" line="3" virtual="1" inline="1" artificial="1"( throw="")? overrides="_10"/> + <Constructor id="_15" name="Derived" context="_4" access="public" location="f1:3" file="f1" line="3" inline="1" artificial="1"( throw="")?/> + <Constructor id="_16" name="Derived" context="_4" access="public" location="f1:3" file="f1" line="3" inline="1" artificial="1"( throw="")?> + <Argument type="_25" location="f1:3" file="f1" line="3"/> + </Constructor> + <PointerType id="_17" type="_3"/> + <PointerType id="_18" type="_3c"/> + <CvQualifiedType id="_3c" type="_3" const="1"/> + <FundamentalType id="_19" name="int" size="[0-9]+" align="[0-9]+"/> + <FundamentalType id="_20" name="void" size="[0-9]+" align="[0-9]+"/> + <PointerType id="_21" type="_4"/> + <ReferenceType id="_22" type="_3"/> + <ReferenceType id="_23" type="_3c"/> + <ReferenceType id="_24" type="_4"/> + <ReferenceType id="_25" type="_4c"/> + <CvQualifiedType id="_4c" type="_4" const="1"/> + <Namespace id="_2" name="::"/> + <File id="f1" name=".*/test/input/Function-Argument-default-cast.cxx"/> +</GCC_XML>$ diff --git a/test/expect/gccxml.any.Method-Argument-default-cast.xml.txt b/test/expect/gccxml.any.Method-Argument-default-cast.xml.txt new file mode 100644 index 0000000..e7f93f2 --- /dev/null +++ b/test/expect/gccxml.any.Method-Argument-default-cast.xml.txt @@ -0,0 +1,27 @@ +^<\?xml version="1.0"\?> +<GCC_XML[^>]*> + <Class id="_1" name="start" context="_2" location="f1:1" file="f1" line="1" members="_3 _4 _5 _6 _7 _8 _9" size="[0-9]+" align="[0-9]+"/> + <Class id="_3" name="Class" context="_1" access="private" location="f1:2" file="f1" line="2" incomplete="1"/> + <Typedef id="_4" name="Int" type="_10" context="_1" access="private" location="f1:3" file="f1" line="3"/> + <Method id="_5" name="f" returns="_10" context="_1" access="private" location="f1:4" file="f1" line="4" mangled="[^"]+"> + <Argument type="_4" location="f1:4" file="f1" line="4" default="\(int\)0"/> + <Argument type="_11" location="f1:5" file="f1" line="5" default="\(start::Class \*\)0"/> + <Argument type="_11" location="f1:6" file="f1" line="6" default="static_cast<start::Class \*>\(0\)"/> + <Argument type="_11" location="f1:7" file="f1" line="7" default="reinterpret_cast<start::Class \*>\(0\)"/> + </Method> + <Constructor id="_6" name="start" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throw="")?/> + <Constructor id="_7" name="start" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throw="")?> + <Argument type="_12" location="f1:1" file="f1" line="1"/> + </Constructor> + <OperatorMethod id="_8" name="=" returns="_13" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throw="")? mangled="[^"]+"> + <Argument type="_12" location="f1:1" file="f1" line="1"/> + </OperatorMethod> + <Destructor id="_9" name="start" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throw="")?/> + <FundamentalType id="_10" name="int" size="[0-9]+" align="[0-9]+"/> + <PointerType id="_11" type="_3"/> + <ReferenceType id="_12" type="_1c"/> + <CvQualifiedType id="_1c" type="_1" const="1"/> + <ReferenceType id="_13" type="_1"/> + <Namespace id="_2" name="::"/> + <File id="f1" name=".*/test/input/Method-Argument-default-cast.cxx"/> +</GCC_XML>$ diff --git a/test/input/Function-Argument-default-cast.cxx b/test/input/Function-Argument-default-cast.cxx new file mode 100644 index 0000000..09ff46b --- /dev/null +++ b/test/input/Function-Argument-default-cast.cxx @@ -0,0 +1,13 @@ +namespace start { + struct Base { Base(); virtual ~Base(); }; + struct Derived: public Base {}; + Base* b(); + Base const* bc(); + typedef int Int; + void f(Int = (Int)0, + Base* = (Base*)0, + Base* = static_cast<Base*>(0), + Base* = reinterpret_cast<Base*>(0), + Base* = const_cast<Base*>(bc()), + Derived* = dynamic_cast<Derived*>(b())); +} diff --git a/test/input/Method-Argument-default-cast.cxx b/test/input/Method-Argument-default-cast.cxx new file mode 100644 index 0000000..903b622 --- /dev/null +++ b/test/input/Method-Argument-default-cast.cxx @@ -0,0 +1,8 @@ +class start { + class Class; + typedef int Int; + int f(Int = (Int)0, + Class* = (Class*)0, + Class* = static_cast<Class*>(0), + Class* = reinterpret_cast<Class*>(0)); +}; |