summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-10-03 16:01:44 (GMT)
committerBrad King <brad.king@kitware.com>2017-10-03 17:06:52 (GMT)
commitae62b1a29c8233c3dd40fc3e293ddcdbe0bdcccc (patch)
tree8e661286156f980fa6a7d299eafdd4bf98413f15 /src
parentb663caed7c6603a1b3c08d237174789424c00ed0 (diff)
downloadCastXML-ae62b1a29c8233c3dd40fc3e293ddcdbe0bdcccc.zip
CastXML-ae62b1a29c8233c3dd40fc3e293ddcdbe0bdcccc.tar.gz
CastXML-ae62b1a29c8233c3dd40fc3e293ddcdbe0bdcccc.tar.bz2
Output: Always print name= attribute for function-like elements
Anonymous struct and union types may have constructors and destructors that are also anonymous. Generate `name=""` in such cases because clients expect these function-like elements to have names as gccxml did. Issue: #89
Diffstat (limited to 'src')
-rw-r--r--src/Output.cxx42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/Output.cxx b/src/Output.cxx
index 1c2866d..1e72abb 100644
--- a/src/Output.cxx
+++ b/src/Output.cxx
@@ -34,6 +34,7 @@
#include "clang/Basic/TargetInfo.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/Preprocessor.h"
+#include "llvm/ADT/Optional.h"
#include "llvm/Support/raw_ostream.h"
#include <fstream>
@@ -472,9 +473,10 @@ class ASTVisitor : public ASTVisitorBase
/** Output a function element using the name and flags given by
the caller. This encompasses functionality common to all the
function declaration output methods. */
- void OutputFunctionHelper(clang::FunctionDecl const* d, DumpNode const* dn,
- const char* tag, std::string const& name,
- unsigned int flags);
+ void OutputFunctionHelper(
+ clang::FunctionDecl const* d, DumpNode const* dn, const char* tag,
+ unsigned int flags,
+ llvm::Optional<std::string> const& name = llvm::Optional<std::string>());
/** Output a function type element using the tag given by the caller.
This encompasses functionality common to all the function type
@@ -1519,13 +1521,13 @@ void ASTVisitor::PrintFloat128Type(DumpNode const* dn)
void ASTVisitor::OutputFunctionHelper(clang::FunctionDecl const* d,
DumpNode const* dn, const char* tag,
- std::string const& name,
- unsigned int flags)
+ unsigned int flags,
+ llvm::Optional<std::string> const& name)
{
this->OS << " <" << tag;
this->PrintIdAttribute(dn);
- if (!name.empty()) {
- this->PrintNameAttribute(name);
+ if (name) {
+ this->PrintNameAttribute(name.getValue());
}
if (flags & FH_Returns) {
this->PrintReturnsAttribute(d->getReturnType(), dn->Complete);
@@ -1951,10 +1953,10 @@ void ASTVisitor::OutputFunctionDecl(clang::FunctionDecl const* d,
}
if (d->isOverloadedOperator()) {
this->OutputFunctionHelper(
- d, dn, "OperatorFunction",
- clang::getOperatorSpelling(d->getOverloadedOperator()), flags);
+ d, dn, "OperatorFunction", flags,
+ std::string(clang::getOperatorSpelling(d->getOverloadedOperator())));
} else if (clang::IdentifierInfo const* ii = d->getIdentifier()) {
- this->OutputFunctionHelper(d, dn, "Function", ii->getName().str(), flags);
+ this->OutputFunctionHelper(d, dn, "Function", flags, ii->getName().str());
} else {
this->OutputUnimplementedDecl(d, dn);
}
@@ -1984,10 +1986,10 @@ void ASTVisitor::OutputCXXMethodDecl(clang::CXXMethodDecl const* d,
}
if (d->isOverloadedOperator()) {
this->OutputFunctionHelper(
- d, dn, "OperatorMethod",
- clang::getOperatorSpelling(d->getOverloadedOperator()), flags);
+ d, dn, "OperatorMethod", flags,
+ std::string(clang::getOperatorSpelling(d->getOverloadedOperator())));
} else if (clang::IdentifierInfo const* ii = d->getIdentifier()) {
- this->OutputFunctionHelper(d, dn, "Method", ii->getName().str(), flags);
+ this->OutputFunctionHelper(d, dn, "Method", flags, ii->getName().str());
} else {
this->OutputUnimplementedDecl(d, dn);
}
@@ -2012,7 +2014,7 @@ void ASTVisitor::OutputCXXConversionDecl(clang::CXXConversionDecl const* d,
if (d->isPure()) {
flags |= FH_Pure;
}
- this->OutputFunctionHelper(d, dn, "Converter", "", flags);
+ this->OutputFunctionHelper(d, dn, "Converter", flags);
}
void ASTVisitor::OutputCXXConstructorDecl(clang::CXXConstructorDecl const* d,
@@ -2028,8 +2030,8 @@ void ASTVisitor::OutputCXXConstructorDecl(clang::CXXConstructorDecl const* d,
if (d->isExplicit()) {
flags |= FH_Explicit;
}
- this->OutputFunctionHelper(d, dn, "Constructor", this->GetContextName(d),
- flags);
+ this->OutputFunctionHelper(d, dn, "Constructor", flags,
+ this->GetContextName(d));
}
void ASTVisitor::OutputCXXDestructorDecl(clang::CXXDestructorDecl const* d,
@@ -2048,8 +2050,8 @@ void ASTVisitor::OutputCXXDestructorDecl(clang::CXXDestructorDecl const* d,
if (d->isPure()) {
flags |= FH_Pure;
}
- this->OutputFunctionHelper(d, dn, "Destructor", this->GetContextName(d),
- flags);
+ this->OutputFunctionHelper(d, dn, "Destructor", flags,
+ this->GetContextName(d));
}
void ASTVisitor::OutputBuiltinType(clang::BuiltinType const* t,
@@ -2186,14 +2188,14 @@ void ASTVisitor::OutputStartXMLTags()
// Start dump with castxml-compatible format.
/* clang-format off */
this->OS <<
- "<CastXML format=\"" << Opts.CastXmlEpicFormatVersion << ".1.2\">\n"
+ "<CastXML format=\"" << Opts.CastXmlEpicFormatVersion << ".1.3\">\n"
;
/* clang-format on */
} else if (this->Opts.GccXml) {
// Start dump with gccxml-compatible format (legacy).
/* clang-format off */
this->OS <<
- "<GCC_XML version=\"0.9.0\" cvs_revision=\"1.142\">\n"
+ "<GCC_XML version=\"0.9.0\" cvs_revision=\"1.143\">\n"
;
/* clang-format on */
}