summaryrefslogtreecommitdiffstats
path: root/src/Output.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-08-18 17:10:10 (GMT)
committerBrad King <brad.king@kitware.com>2015-08-18 19:12:18 (GMT)
commitc7c836f667300470f12820fe9128e10afbbe2267 (patch)
tree55f1777b35944510f698840ea6c177a05738e04a /src/Output.cxx
parent1932cf268d410f9b9f60374de0a5a65147ee0849 (diff)
downloadCastXML-c7c836f667300470f12820fe9128e10afbbe2267.zip
CastXML-c7c836f667300470f12820fe9128e10afbbe2267.tar.gz
CastXML-c7c836f667300470f12820fe9128e10afbbe2267.tar.bz2
Output: Refactor attributes="" printing to use a helper
Add a PrintAttributesAttribute helper and use it anywhere we currently print the attributes="" attribute.
Diffstat (limited to 'src/Output.cxx')
-rw-r--r--src/Output.cxx44
1 files 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<std::string> const& attrs);
+
+ /** Get the attributes of the given function type. */
+ void GetFunctionTypeAttributes(clang::FunctionProtoType const* t,
+ std::vector<std::string>& 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<std::string> 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<std::string>& 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<std::string> attributes;
+
if (clang::FunctionProtoType const* fpt =
d->getType()->getAs<clang::FunctionProtoType>()) {
this->PrintThrowsAttribute(fpt, dn->Complete);
@@ -1309,9 +1331,11 @@ void ASTVisitor::OutputFunctionHelper(clang::FunctionDecl const* d,
!clang::isa<clang::CXXDestructorDecl>(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<std::string> 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