diff options
author | Brad King <brad.king@kitware.com> | 2014-04-14 17:36:39 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2014-04-14 17:37:53 (GMT) |
commit | 68009c611d9fbf5ad8391e12e4d40c5716aee43e (patch) | |
tree | 3f8e1f58046e8d3fc948d393479d4c6ea89be1ea | |
parent | 2bba2e9e8900666ca92a7abb848ee8e5756462d8 (diff) | |
download | CastXML-68009c611d9fbf5ad8391e12e4d40c5716aee43e.zip CastXML-68009c611d9fbf5ad8391e12e4d40c5716aee43e.tar.gz CastXML-68009c611d9fbf5ad8391e12e4d40c5716aee43e.tar.bz2 |
Output: Add function calling convention attributes
Add to Function-like and FunctionType elements an attributes=""
attribute for the calling convention as gccxml does.
-rw-r--r-- | src/Output.cxx | 30 | ||||
-rw-r--r-- | test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/expect/gccxml.any.Function-calling-convention-ms.xml.txt | 26 | ||||
-rw-r--r-- | test/input/Function-calling-convention-ms.cxx | 4 |
4 files changed, 61 insertions, 0 deletions
diff --git a/src/Output.cxx b/src/Output.cxx index 132345d..3b7065d 100644 --- a/src/Output.cxx +++ b/src/Output.cxx @@ -25,6 +25,7 @@ #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclOpenMP.h" #include "clang/AST/DeclTemplate.h" +#include "clang/Basic/Specifiers.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Lex/Preprocessor.h" #include "llvm/Support/raw_ostream.h" @@ -256,6 +257,10 @@ class ASTVisitor: public ASTVisitorBase for later output. */ void PrintBasesAttribute(clang::CXXRecordDecl const* dx); + /** Print an attributes="..." attribute listing the attributes + of the given function type. */ + void PrintFunctionTypeAttributes(clang::FunctionProtoType const* t); + /** Print a throws="..." attribute listing the XML IDREFs for the types that the given function prototype declares in the throw() specification. */ @@ -466,6 +471,9 @@ unsigned int ASTVisitor::AddDumpNode(DumpType dt, bool complete) { case clang::Type::Adjusted: return this->AddDumpNode(DumpType( t->getAs<clang::AdjustedType>()->getAdjustedType(), c), complete); + case clang::Type::Attributed: + return this->AddDumpNode(DumpType( + t->getAs<clang::AttributedType>()->getEquivalentType(), c), complete); case clang::Type::Decayed: return this->AddDumpNode(DumpType( t->getAs<clang::DecayedType>()->getDecayedType(), c), complete); @@ -993,6 +1001,26 @@ void ASTVisitor::PrintBasesAttribute(clang::CXXRecordDecl const* dx) } //---------------------------------------------------------------------------- +void ASTVisitor::PrintFunctionTypeAttributes(clang::FunctionProtoType const* t) +{ + switch (t->getExtInfo().getCC()) { + case clang::CallingConv::CC_C: + break; + case clang::CallingConv::CC_X86StdCall: + this->OS << " attributes=\"__stdcall__\""; + break; + case clang::CallingConv::CC_X86FastCall: + this->OS << " attributes=\"__fastcall__\""; + break; + case clang::CallingConv::CC_X86ThisCall: + this->OS << " attributes=\"__thiscall__\""; + break; + default: + break; + } +} + +//---------------------------------------------------------------------------- void ASTVisitor::PrintThrowsAttribute(clang::FunctionProtoType const* fpt, bool complete) { @@ -1083,6 +1111,7 @@ void ASTVisitor::OutputFunctionHelper(clang::FunctionDecl const* d, } clang::QualType ft = d->getType(); + this->PrintFunctionTypeAttributes(ft->getAs<clang::FunctionProtoType>()); this->PrintThrowsAttribute( ft->getAs<clang::FunctionProtoType>(), dn->Complete); @@ -1130,6 +1159,7 @@ void ASTVisitor::OutputFunctionTypeHelper(clang::FunctionProtoType const* t, if(t->isRestrict()) { this->OS << " restrict=\"1\""; } + this->PrintFunctionTypeAttributes(t); if(t->param_type_begin() != t->param_type_end()) { this->OS << ">\n"; for (clang::FunctionProtoType::param_type_iterator diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 22858aa..902f892 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -189,6 +189,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(implicit-decl-ms) castxml_test_gccxml(inline-asm-ms) unset(castxml_test_gccxml_extra_arguments) diff --git a/test/expect/gccxml.any.Function-calling-convention-ms.xml.txt b/test/expect/gccxml.any.Function-calling-convention-ms.xml.txt new file mode 100644 index 0000000..012f4df --- /dev/null +++ b/test/expect/gccxml.any.Function-calling-convention-ms.xml.txt @@ -0,0 +1,26 @@ +^<\?xml version="1.0"\?> +<GCC_XML[^>]*> + <Function id="_1" name="start" returns="_5" context="_6" location="f1:1" file="f1" line="1"> + <Argument type="_7" location="f1:1" file="f1" line="1"/> + </Function> + <Function id="_2" name="start" returns="_5" context="_6" location="f1:2" file="f1" line="2" attributes="__stdcall__"> + <Argument type="_8" location="f1:2" file="f1" line="2"/> + </Function> + <Function id="_3" name="start" returns="_5" context="_6" location="f1:3" file="f1" line="3" attributes="__fastcall__"> + <Argument type="_9" location="f1:3" file="f1" line="3"/> + </Function> + <Function id="_4" name="start" returns="_5" context="_6" location="f1:4" file="f1" line="4" attributes="__thiscall__"> + <Argument type="_10" location="f1:4" file="f1" line="4"/> + </Function> + <FundamentalType id="_5" name="void"/> + <PointerType id="_7" type="_11"/> + <PointerType id="_8" type="_12"/> + <PointerType id="_9" type="_13"/> + <PointerType id="_10" type="_14"/> + <Namespace id="_6" name="::"/> + <FunctionType id="_11" returns="_5"/> + <FunctionType id="_12" returns="_5" attributes="__stdcall__"/> + <FunctionType id="_13" returns="_5" attributes="__fastcall__"/> + <FunctionType id="_14" returns="_5" attributes="__thiscall__"/> + <File id="f1" name=".*/test/input/Function-calling-convention-ms.cxx"/> +</GCC_XML>$ diff --git a/test/input/Function-calling-convention-ms.cxx b/test/input/Function-calling-convention-ms.cxx new file mode 100644 index 0000000..fac3c42 --- /dev/null +++ b/test/input/Function-calling-convention-ms.cxx @@ -0,0 +1,4 @@ +void __cdecl start(void (__cdecl *)()); +void __stdcall start(void (__stdcall *)()); +void __fastcall start(void (__fastcall *)()); +void __thiscall start(void (__thiscall *)()); |