From e73fba54fd7347b94a6951903eac8479495654f2 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 18 Aug 2015 13:52:39 -0400 Subject: Output: Add annotate() to function declaration attributes="" While CastXML cannot support the `gccxml()` attribute because Clang does not define it, we can support the `annotate()` attribute that Clang provides for arbitrary string annotations. This should fill the same use case as the `gccxml()` attribute did for clients. GitHub-Issue: 25 --- src/Output.cxx | 14 ++++++++++++ test/CMakeLists.txt | 8 +++++++ .../expect/gccxml.any.Constructor-annotate.xml.txt | 17 ++++++++++++++ test/expect/gccxml.any.Converter-annotate.xml.txt | 19 ++++++++++++++++ test/expect/gccxml.any.Destructor-annotate.xml.txt | 17 ++++++++++++++ test/expect/gccxml.any.Function-annotate.xml.txt | 10 +++++++++ ...Function-calling-convention-ms-annotate.xml.txt | 26 ++++++++++++++++++++++ test/expect/gccxml.any.Method-annotate.xml.txt | 21 +++++++++++++++++ .../gccxml.any.OperatorFunction-annotate.xml.txt | 13 +++++++++++ .../gccxml.any.OperatorMethod-annotate.xml.txt | 21 +++++++++++++++++ test/input/Constructor-annotate.cxx | 3 +++ test/input/Converter-annotate.cxx | 3 +++ test/input/Destructor-annotate.cxx | 3 +++ test/input/Function-annotate.cxx | 1 + .../Function-calling-convention-ms-annotate.cxx | 4 ++++ test/input/Method-annotate.cxx | 3 +++ test/input/OperatorFunction-annotate.cxx | 4 ++++ test/input/OperatorMethod-annotate.cxx | 3 +++ test/run.cmake | 1 + 19 files changed, 191 insertions(+) create mode 100644 test/expect/gccxml.any.Constructor-annotate.xml.txt create mode 100644 test/expect/gccxml.any.Converter-annotate.xml.txt create mode 100644 test/expect/gccxml.any.Destructor-annotate.xml.txt create mode 100644 test/expect/gccxml.any.Function-annotate.xml.txt create mode 100644 test/expect/gccxml.any.Function-calling-convention-ms-annotate.xml.txt create mode 100644 test/expect/gccxml.any.Method-annotate.xml.txt create mode 100644 test/expect/gccxml.any.OperatorFunction-annotate.xml.txt create mode 100644 test/expect/gccxml.any.OperatorMethod-annotate.xml.txt create mode 100644 test/input/Constructor-annotate.cxx create mode 100644 test/input/Converter-annotate.cxx create mode 100644 test/input/Destructor-annotate.cxx create mode 100644 test/input/Function-annotate.cxx create mode 100644 test/input/Function-calling-convention-ms-annotate.cxx create mode 100644 test/input/Method-annotate.cxx create mode 100644 test/input/OperatorFunction-annotate.cxx create mode 100644 test/input/OperatorMethod-annotate.cxx diff --git a/src/Output.cxx b/src/Output.cxx index b6d8115..cc4f340 100644 --- a/src/Output.cxx +++ b/src/Output.cxx @@ -347,6 +347,10 @@ class ASTVisitor: public ASTVisitorBase void GetFunctionTypeAttributes(clang::FunctionProtoType const* t, std::vector& attrs); + /** Get the attributes of the given declaration. */ + void GetDeclAttributes(clang::Decl const* d, + std::vector& attrs); + /** Print a throw="..." attribute listing the XML IDREFs for the types that the given function prototype declares in the throw() specification. */ @@ -1233,6 +1237,15 @@ void ASTVisitor::GetFunctionTypeAttributes(clang::FunctionProtoType const* t, } //---------------------------------------------------------------------------- +void ASTVisitor::GetDeclAttributes(clang::Decl const* d, + std::vector& attrs) +{ + for (auto const* a: d->specific_attrs()) { + attrs.push_back("annotate(" + a->getAnnotation().str() + ")"); + } +} + +//---------------------------------------------------------------------------- void ASTVisitor::PrintThrowsAttribute(clang::FunctionProtoType const* fpt, bool complete) { @@ -1334,6 +1347,7 @@ void ASTVisitor::OutputFunctionHelper(clang::FunctionDecl const* d, this->GetFunctionTypeAttributes(fpt, attributes); } + this->GetDeclAttributes(d, attributes); this->PrintAttributesAttribute(attributes); if(unsigned np = d->getNumParams()) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 23e956d..4c21e8a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -192,13 +192,17 @@ castxml_test_gccxml(Class-template-member-Typedef) castxml_test_gccxml(Class-template-member-Typedef-const) castxml_test_gccxml(Class-template-member-template) castxml_test_gccxml(Constructor) +castxml_test_gccxml(Constructor-annotate) castxml_test_gccxml(Converter) +castxml_test_gccxml(Converter-annotate) castxml_test_gccxml(CvQualifiedType) castxml_test_gccxml(Destructor) +castxml_test_gccxml(Destructor-annotate) castxml_test_gccxml(Enumeration) castxml_test_gccxml(Enumeration-anonymous) castxml_test_gccxml(Field) castxml_test_gccxml(Function) +castxml_test_gccxml(Function-annotate) castxml_test_gccxml(Function-Argument-decay) castxml_test_gccxml(Function-Argument-default) castxml_test_gccxml(Function-rvalue-reference) @@ -210,6 +214,7 @@ castxml_test_gccxml(FunctionType-variadic) castxml_test_gccxml(FundamentalType) castxml_test_gccxml(FundamentalTypes) castxml_test_gccxml(Method) +castxml_test_gccxml(Method-annotate) castxml_test_gccxml(Method-rvalue-reference) castxml_test_gccxml(MethodType) castxml_test_gccxml(MethodType-cv) @@ -230,7 +235,9 @@ castxml_test_gccxml(Namespace-repeat-start) castxml_test_gccxml(OffsetType) castxml_test_gccxml(OffsetType-cv) castxml_test_gccxml(OperatorFunction) +castxml_test_gccxml(OperatorFunction-annotate) castxml_test_gccxml(OperatorMethod) +castxml_test_gccxml(OperatorMethod-annotate) castxml_test_gccxml(PointerType) castxml_test_gccxml(ReferenceType) castxml_test_gccxml(RValueReferenceType) @@ -263,6 +270,7 @@ castxml_test_gccxml(using-directive-start) if(";${LLVM_TARGETS_TO_BUILD};" MATCHES ";X86;") set(castxml_test_gccxml_extra_arguments -target i386-pc-windows-msvc) castxml_test_gccxml(Function-calling-convention-ms) + castxml_test_gccxml(Function-calling-convention-ms-annotate) castxml_test_gccxml(implicit-decl-ms) castxml_test_gccxml(inline-asm-ms) unset(castxml_test_gccxml_extra_arguments) diff --git a/test/expect/gccxml.any.Constructor-annotate.xml.txt b/test/expect/gccxml.any.Constructor-annotate.xml.txt new file mode 100644 index 0000000..90c7f02 --- /dev/null +++ b/test/expect/gccxml.any.Constructor-annotate.xml.txt @@ -0,0 +1,17 @@ +^<\?xml version="1.0"\?> +]*> + + + + + + + + + + + + + + +$ diff --git a/test/expect/gccxml.any.Converter-annotate.xml.txt b/test/expect/gccxml.any.Converter-annotate.xml.txt new file mode 100644 index 0000000..0642674 --- /dev/null +++ b/test/expect/gccxml.any.Converter-annotate.xml.txt @@ -0,0 +1,19 @@ +^<\?xml version="1.0"\?> +]*> + + + + + + + + + + + + + + + + +$ diff --git a/test/expect/gccxml.any.Destructor-annotate.xml.txt b/test/expect/gccxml.any.Destructor-annotate.xml.txt new file mode 100644 index 0000000..0660f79 --- /dev/null +++ b/test/expect/gccxml.any.Destructor-annotate.xml.txt @@ -0,0 +1,17 @@ +^<\?xml version="1.0"\?> +]*> + + + + + + + + + + + + + + +$ diff --git a/test/expect/gccxml.any.Function-annotate.xml.txt b/test/expect/gccxml.any.Function-annotate.xml.txt new file mode 100644 index 0000000..3f98887 --- /dev/null +++ b/test/expect/gccxml.any.Function-annotate.xml.txt @@ -0,0 +1,10 @@ +^<\?xml version="1.0"\?> +]*> + + + + + + + +$ diff --git a/test/expect/gccxml.any.Function-calling-convention-ms-annotate.xml.txt b/test/expect/gccxml.any.Function-calling-convention-ms-annotate.xml.txt new file mode 100644 index 0000000..ba7fb08 --- /dev/null +++ b/test/expect/gccxml.any.Function-calling-convention-ms-annotate.xml.txt @@ -0,0 +1,26 @@ +^<\?xml version="1.0"\?> +]*> + + + + + + + + + + + + + + + + + + + + + + + +$ diff --git a/test/expect/gccxml.any.Method-annotate.xml.txt b/test/expect/gccxml.any.Method-annotate.xml.txt new file mode 100644 index 0000000..3e4f2f3 --- /dev/null +++ b/test/expect/gccxml.any.Method-annotate.xml.txt @@ -0,0 +1,21 @@ +^<\?xml version="1.0"\?> +]*> + + + + + + + + + + + + + + + + + + +$ diff --git a/test/expect/gccxml.any.OperatorFunction-annotate.xml.txt b/test/expect/gccxml.any.OperatorFunction-annotate.xml.txt new file mode 100644 index 0000000..8393bd2 --- /dev/null +++ b/test/expect/gccxml.any.OperatorFunction-annotate.xml.txt @@ -0,0 +1,13 @@ +^<\?xml version="1.0"\?> +]*> + + + + + + + + + + +$ diff --git a/test/expect/gccxml.any.OperatorMethod-annotate.xml.txt b/test/expect/gccxml.any.OperatorMethod-annotate.xml.txt new file mode 100644 index 0000000..692cd5e --- /dev/null +++ b/test/expect/gccxml.any.OperatorMethod-annotate.xml.txt @@ -0,0 +1,21 @@ +^<\?xml version="1.0"\?> +]*> + + + + + + + + + + + + + + + + + + +$ diff --git a/test/input/Constructor-annotate.cxx b/test/input/Constructor-annotate.cxx new file mode 100644 index 0000000..94cf13e --- /dev/null +++ b/test/input/Constructor-annotate.cxx @@ -0,0 +1,3 @@ +class start { + __attribute__ ((annotate ("an annotation"))) start(); +}; diff --git a/test/input/Converter-annotate.cxx b/test/input/Converter-annotate.cxx new file mode 100644 index 0000000..2e4a915 --- /dev/null +++ b/test/input/Converter-annotate.cxx @@ -0,0 +1,3 @@ +class start { + __attribute__ ((annotate ("an annotation"))) operator int(); +}; diff --git a/test/input/Destructor-annotate.cxx b/test/input/Destructor-annotate.cxx new file mode 100644 index 0000000..f2c59f1 --- /dev/null +++ b/test/input/Destructor-annotate.cxx @@ -0,0 +1,3 @@ +class start { + __attribute__ ((annotate ("an annotation"))) ~start(); +}; diff --git a/test/input/Function-annotate.cxx b/test/input/Function-annotate.cxx new file mode 100644 index 0000000..d7aaf79 --- /dev/null +++ b/test/input/Function-annotate.cxx @@ -0,0 +1 @@ +__attribute__ ((annotate ("an annotation"))) void start(int); diff --git a/test/input/Function-calling-convention-ms-annotate.cxx b/test/input/Function-calling-convention-ms-annotate.cxx new file mode 100644 index 0000000..4803dd8 --- /dev/null +++ b/test/input/Function-calling-convention-ms-annotate.cxx @@ -0,0 +1,4 @@ +__attribute__ ((annotate ("an annotation"))) void __cdecl start(void (__cdecl *)()); +__attribute__ ((annotate ("an annotation"))) void __stdcall start(void (__stdcall *)()); +__attribute__ ((annotate ("an annotation"))) void __fastcall start(void (__fastcall *)()); +__attribute__ ((annotate ("an annotation"))) void __thiscall start(void (__thiscall *)()); diff --git a/test/input/Method-annotate.cxx b/test/input/Method-annotate.cxx new file mode 100644 index 0000000..cbd02cf --- /dev/null +++ b/test/input/Method-annotate.cxx @@ -0,0 +1,3 @@ +class start { + __attribute__ ((annotate ("an annotation"))) int method(int); +}; diff --git a/test/input/OperatorFunction-annotate.cxx b/test/input/OperatorFunction-annotate.cxx new file mode 100644 index 0000000..bbb3bf9 --- /dev/null +++ b/test/input/OperatorFunction-annotate.cxx @@ -0,0 +1,4 @@ +class A; +namespace start { + __attribute__ ((annotate ("an annotation"))) A& operator<<(A&, int); +} diff --git a/test/input/OperatorMethod-annotate.cxx b/test/input/OperatorMethod-annotate.cxx new file mode 100644 index 0000000..3384ece --- /dev/null +++ b/test/input/OperatorMethod-annotate.cxx @@ -0,0 +1,3 @@ +class start { + __attribute__ ((annotate ("an annotation"))) start& operator<<(int); +}; diff --git a/test/run.cmake b/test/run.cmake index 1b973b3..e9911a6 100644 --- a/test/run.cmake +++ b/test/run.cmake @@ -84,6 +84,7 @@ if(msg) set(update_xml "${actual_xml}") string(REGEX REPLACE "^<\\?xml version=\"1.0\"\\?>" "^<\\\\?xml version=\"1.0\"\\\\?>" update_xml "${update_xml}") string(REGEX REPLACE "]*>" "]*>" update_xml "${update_xml}") + string(REGEX REPLACE "([()])" "\\\\\\1" update_xml "${update_xml}") string(REGEX REPLACE "mangled=\"[^\"]*\"" "mangled=\"[^\"]+\"" update_xml "${update_xml}") string(REGEX REPLACE "artificial=\"1\"( throw=\"\")?" "artificial=\"1\"( throw=\"\")?" update_xml "${update_xml}") string(REGEX REPLACE "size=\"[0-9]+\" align=\"[0-9]+\"" "size=\"[0-9]+\" align=\"[0-9]+\"" update_xml "${update_xml}") -- cgit v0.12