From c7c836f667300470f12820fe9128e10afbbe2267 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 18 Aug 2015 13:10:10 -0400 Subject: Output: Refactor attributes="" printing to use a helper Add a PrintAttributesAttribute helper and use it anywhere we currently print the attributes="" attribute. --- src/Output.cxx | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/Output.cxx b/src/Output.cxx index affb4fb..b6d8115 100644 --- a/src/Output.cxx +++ b/src/Output.cxx @@ -340,9 +340,12 @@ 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 an attributes="..." attribute listing the given attributes. */ + void PrintAttributesAttribute(std::vector const& attrs); + + /** Get the attributes of the given function type. */ + void GetFunctionTypeAttributes(clang::FunctionProtoType const* t, + std::vector& attrs); /** Print a throw="..." attribute listing the XML IDREFs for the types that the given function prototype declares in @@ -1193,19 +1196,36 @@ void ASTVisitor::PrintBasesAttribute(clang::CXXRecordDecl const* dx) } //---------------------------------------------------------------------------- -void ASTVisitor::PrintFunctionTypeAttributes(clang::FunctionProtoType const* t) +void ASTVisitor::PrintAttributesAttribute( + std::vector const& attrs) +{ + if (attrs.empty()) { + return; + } + this->OS << " attributes=\""; + const char* sep = ""; + for (std::string const& a: attrs) { + this->OS << sep << encodeXML(a); + sep = " "; + } + this->OS << "\""; +} + +//---------------------------------------------------------------------------- +void ASTVisitor::GetFunctionTypeAttributes(clang::FunctionProtoType const* t, + std::vector& attrs) { switch (t->getExtInfo().getCC()) { case clang::CallingConv::CC_C: break; case clang::CallingConv::CC_X86StdCall: - this->OS << " attributes=\"__stdcall__\""; + attrs.push_back("__stdcall__"); break; case clang::CallingConv::CC_X86FastCall: - this->OS << " attributes=\"__fastcall__\""; + attrs.push_back("__fastcall__"); break; case clang::CallingConv::CC_X86ThisCall: - this->OS << " attributes=\"__thiscall__\""; + attrs.push_back("__thiscall__"); break; default: break; @@ -1302,6 +1322,8 @@ void ASTVisitor::OutputFunctionHelper(clang::FunctionDecl const* d, this->OS << " artificial=\"1\""; } + std::vector attributes; + if (clang::FunctionProtoType const* fpt = d->getType()->getAs()) { this->PrintThrowsAttribute(fpt, dn->Complete); @@ -1309,9 +1331,11 @@ void ASTVisitor::OutputFunctionHelper(clang::FunctionDecl const* d, !clang::isa(d)) { this->PrintMangledAttribute(d); } - this->PrintFunctionTypeAttributes(fpt); + this->GetFunctionTypeAttributes(fpt, attributes); } + this->PrintAttributesAttribute(attributes); + if(unsigned np = d->getNumParams()) { this->OS << ">\n"; for (unsigned i = 0; i < np; ++i) { @@ -1356,7 +1380,9 @@ void ASTVisitor::OutputFunctionTypeHelper(clang::FunctionProtoType const* t, if(t->isRestrict()) { this->OS << " restrict=\"1\""; } - this->PrintFunctionTypeAttributes(t); + std::vector attributes; + this->GetFunctionTypeAttributes(t, attributes); + this->PrintAttributesAttribute(attributes); if(t->param_type_begin() != t->param_type_end()) { this->OS << ">\n"; for (clang::FunctionProtoType::param_type_iterator -- cgit v0.12