From 68009c611d9fbf5ad8391e12e4d40c5716aee43e Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 14 Apr 2014 13:36:39 -0400 Subject: Output: Add function calling convention attributes Add to Function-like and FunctionType elements an attributes="" attribute for the calling convention as gccxml does. --- src/Output.cxx | 30 ++++++++++++++++++++++ test/CMakeLists.txt | 1 + ...cxml.any.Function-calling-convention-ms.xml.txt | 26 +++++++++++++++++++ test/input/Function-calling-convention-ms.cxx | 4 +++ 4 files changed, 61 insertions(+) create mode 100644 test/expect/gccxml.any.Function-calling-convention-ms.xml.txt create mode 100644 test/input/Function-calling-convention-ms.cxx 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()->getAdjustedType(), c), complete); + case clang::Type::Attributed: + return this->AddDumpNode(DumpType( + t->getAs()->getEquivalentType(), c), complete); case clang::Type::Decayed: return this->AddDumpNode(DumpType( t->getAs()->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()); this->PrintThrowsAttribute( ft->getAs(), 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"\?> +]*> + + + + + + + + + + + + + + + + + + + + + + + +$ 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 *)()); -- cgit v0.12