summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Detect.cxx92
-rw-r--r--src/Detect.h6
-rw-r--r--src/Options.h20
-rw-r--r--src/Output.cxx1087
-rw-r--r--src/Output.h12
-rw-r--r--src/RunClang.cxx301
-rw-r--r--src/RunClang.h3
-rw-r--r--src/Utils.cxx125
-rw-r--r--src/Utils.h5
-rw-r--r--src/castxml.cxx92
10 files changed, 941 insertions, 802 deletions
diff --git a/src/Detect.cxx b/src/Detect.cxx
index e1e7b79..21bfef2 100644
--- a/src/Detect.cxx
+++ b/src/Detect.cxx
@@ -34,20 +34,19 @@ static std::string getClangBuiltinIncludeDir()
return getClangResourceDir() + "/include";
}
-static bool failedCC(const char* id,
- std::vector<const char*> const& args,
- std::string const& out,
- std::string const& err,
+static bool failedCC(const char* id, std::vector<const char*> const& args,
+ std::string const& out, std::string const& err,
std::string const& msg)
{
std::cerr << "error: '--castxml-cc-" << id
<< "' compiler command failed:\n\n";
- for(std::vector<const char*>::const_iterator i = args.begin(),
- e = args.end(); i != e; ++i) {
+ for (std::vector<const char *>::const_iterator i = args.begin(),
+ e = args.end();
+ i != e; ++i) {
std::cerr << " '" << *i << "'";
}
std::cerr << "\n";
- if(!msg.empty()) {
+ if (!msg.empty()) {
std::cerr << msg << "\n";
} else {
std::cerr << out << "\n";
@@ -61,11 +60,10 @@ static void fixPredefines(Options& opts)
// Remove any detected conflicting definition of a Clang builtin macro.
std::string& pd = opts.Predefines;
std::string::size_type beg = 0;
- while ((beg = pd.find("#define __has", beg),
- beg != std::string::npos)) {
+ while ((beg = pd.find("#define __has", beg), beg != std::string::npos)) {
std::string::size_type end = pd.find('\n', beg);
if (end != std::string::npos) {
- pd.erase(beg, end+1 - beg);
+ pd.erase(beg, end + 1 - beg);
} else {
pd.erase(beg);
}
@@ -76,31 +74,28 @@ static void setTriple(Options& opts)
{
std::string const& pd = opts.Predefines;
llvm::Triple triple(llvm::sys::getDefaultTargetTriple());
- if(pd.find("#define __x86_64__ 1") != pd.npos ||
- pd.find("#define _M_X64 ") != pd.npos) {
+ if (pd.find("#define __x86_64__ 1") != pd.npos ||
+ pd.find("#define _M_X64 ") != pd.npos) {
triple.setArchName("x86_64");
- } else if(pd.find("#define __amd64__ 1") != pd.npos ||
- pd.find("#define _M_AMD64 ") != pd.npos) {
+ } else if (pd.find("#define __amd64__ 1") != pd.npos ||
+ pd.find("#define _M_AMD64 ") != pd.npos) {
triple.setArchName("amd64");
- } else if(pd.find("#define __i386__ 1") != pd.npos ||
- pd.find("#define _M_IX86 ") != pd.npos) {
+ } else if (pd.find("#define __i386__ 1") != pd.npos ||
+ pd.find("#define _M_IX86 ") != pd.npos) {
triple.setArchName("i386");
}
- if(pd.find("#define _WIN32 1") != pd.npos) {
+ if (pd.find("#define _WIN32 1") != pd.npos) {
triple.setVendorName("pc");
triple.setOSName("windows");
}
- if(pd.find("#define __MINGW32__ 1") != pd.npos) {
+ if (pd.find("#define __MINGW32__ 1") != pd.npos) {
triple.setEnvironmentName("gnu");
}
opts.Triple = triple.getTriple();
}
-static bool detectCC_GNU(const char* const* argBeg,
- const char* const* argEnd,
- Options& opts,
- const char* id,
- const char* ext)
+static bool detectCC_GNU(const char* const* argBeg, const char* const* argEnd,
+ Options& opts, const char* id, const char* ext)
{
std::string const fwExplicitSuffix = " (framework directory)";
std::string const fwImplicitSuffix = "/Frameworks";
@@ -114,33 +109,33 @@ static bool detectCC_GNU(const char* const* argBeg,
cc_args.push_back("-dM");
cc_args.push_back("-v");
cc_args.push_back(empty_cpp.c_str());
- if(runCommand(int(cc_args.size()), &cc_args[0], ret, out, err, msg) &&
- ret == 0) {
+ if (runCommand(int(cc_args.size()), &cc_args[0], ret, out, err, msg) &&
+ ret == 0) {
opts.Predefines = out;
const char* start_line = "#include <...> search starts here:";
- if(const char* c = strstr(err.c_str(), start_line)) {
- if((c = strchr(c, '\n'), c++)) {
- while(*c++ == ' ') {
- if(const char* e = strchr(c, '\n')) {
+ if (const char* c = strstr(err.c_str(), start_line)) {
+ if ((c = strchr(c, '\n'), c++)) {
+ while (*c++ == ' ') {
+ if (const char* e = strchr(c, '\n')) {
const char* s = c;
c = e + 1;
- if(*(e - 1) == '\r') {
+ if (*(e - 1) == '\r') {
--e;
}
- std::string inc(s, e-s);
+ std::string inc(s, e - s);
std::replace(inc.begin(), inc.end(), '\\', '/');
bool fw = ((inc.size() > fwExplicitSuffix.size()) &&
- (inc.substr(inc.size()-fwExplicitSuffix.size()) ==
+ (inc.substr(inc.size() - fwExplicitSuffix.size()) ==
fwExplicitSuffix));
- if(fw) {
- inc = inc.substr(0, inc.size()-fwExplicitSuffix.size());
+ if (fw) {
+ inc = inc.substr(0, inc.size() - fwExplicitSuffix.size());
} else {
fw = ((inc.size() > fwImplicitSuffix.size()) &&
- (inc.substr(inc.size()-fwImplicitSuffix.size()) ==
+ (inc.substr(inc.size() - fwImplicitSuffix.size()) ==
fwImplicitSuffix));
}
// Replace the compiler builtin include directory with ours.
- if (!fw && llvm::sys::fs::exists(inc+"/emmintrin.h")) {
+ if (!fw && llvm::sys::fs::exists(inc + "/emmintrin.h")) {
inc = getClangBuiltinIncludeDir();
}
opts.Includes.push_back(Options::Include(inc, fw));
@@ -156,11 +151,8 @@ static bool detectCC_GNU(const char* const* argBeg,
}
}
-static bool detectCC_MSVC(const char* const* argBeg,
- const char* const* argEnd,
- Options& opts,
- const char* id,
- const char* ext)
+static bool detectCC_MSVC(const char* const* argBeg, const char* const* argEnd,
+ Options& opts, const char* id, const char* ext)
{
std::vector<const char*> cc_args(argBeg, argEnd);
std::string detect_vs_cpp = getResourceDir() + "/detect_vs." + ext;
@@ -171,16 +163,16 @@ static bool detectCC_MSVC(const char* const* argBeg,
cc_args.push_back("-c");
cc_args.push_back("-FoNUL");
cc_args.push_back(detect_vs_cpp.c_str());
- if(runCommand(int(cc_args.size()), &cc_args[0], ret, out, err, msg) &&
- ret == 0) {
- if(const char* predefs = strstr(out.c_str(), "\n#define")) {
- opts.Predefines = predefs+1;
+ if (runCommand(int(cc_args.size()), &cc_args[0], ret, out, err, msg) &&
+ ret == 0) {
+ if (const char* predefs = strstr(out.c_str(), "\n#define")) {
+ opts.Predefines = predefs + 1;
}
- if(const char* includes_str = std::getenv("INCLUDE")) {
+ if (const char* includes_str = std::getenv("INCLUDE")) {
llvm::SmallVector<llvm::StringRef, 8> includes;
llvm::StringRef includes_ref(includes_str);
includes_ref.split(includes, ";", -1, false);
- for (llvm::StringRef i: includes) {
+ for (llvm::StringRef i : includes) {
if (!i.empty()) {
std::string inc = i;
std::replace(inc.begin(), inc.end(), '\\', '/');
@@ -196,10 +188,8 @@ static bool detectCC_MSVC(const char* const* argBeg,
}
}
-bool detectCC(const char* id,
- const char* const* argBeg,
- const char* const* argEnd,
- Options& opts)
+bool detectCC(const char* id, const char* const* argBeg,
+ const char* const* argEnd, Options& opts)
{
if (strcmp(id, "gnu") == 0) {
return detectCC_GNU(argBeg, argEnd, opts, id, "cpp");
diff --git a/src/Detect.h b/src/Detect.h
index 1877433..652d712 100644
--- a/src/Detect.h
+++ b/src/Detect.h
@@ -20,9 +20,7 @@ struct Options;
/// detectCC - Detect settings from given compiler command.
-bool detectCC(const char* id,
- const char* const* argBeg,
- const char* const* argEnd,
- Options& opts);
+bool detectCC(const char* id, const char* const* argBeg,
+ const char* const* argEnd, Options& opts);
#endif // CASTXML_DETECT_H
diff --git a/src/Options.h b/src/Options.h
index 34f5089..ab7f7ef 100644
--- a/src/Options.h
+++ b/src/Options.h
@@ -22,16 +22,26 @@
struct Options
{
- Options(): PPOnly(false), GccXml(false), HaveCC(false),
- HaveStd(false), HaveTarget(false) {}
+ Options()
+ : PPOnly(false)
+ , GccXml(false)
+ , HaveCC(false)
+ , HaveStd(false)
+ , HaveTarget(false)
+ {
+ }
bool PPOnly;
bool GccXml;
bool HaveCC;
bool HaveStd;
bool HaveTarget;
- struct Include {
- Include(std::string const& d, bool f = false):
- Directory(d), Framework(f) {}
+ struct Include
+ {
+ Include(std::string const& d, bool f = false)
+ : Directory(d)
+ , Framework(f)
+ {
+ }
std::string Directory;
bool Framework;
};
diff --git a/src/Output.cxx b/src/Output.cxx
index 32ce4b8..55e9ee5 100644
--- a/src/Output.cxx
+++ b/src/Output.cxx
@@ -49,12 +49,17 @@ protected:
clang::ASTContext const& CTX;
llvm::raw_ostream& OS;
- ASTVisitorBase(clang::CompilerInstance& ci,
- clang::ASTContext const& ctx,
- llvm::raw_ostream& os): CI(ci), CTX(ctx), OS(os) {}
+ ASTVisitorBase(clang::CompilerInstance& ci, clang::ASTContext const& ctx,
+ llvm::raw_ostream& os)
+ : CI(ci)
+ , CTX(ctx)
+ , OS(os)
+ {
+ }
// Represent cv qualifier state of one dump node.
- struct DumpQual {
+ struct DumpQual
+ {
private:
typedef void (DumpQual::*bool_type)() const;
void bool_true() const {}
@@ -62,12 +67,20 @@ protected:
bool IsConst;
bool IsVolatile;
bool IsRestrict;
- DumpQual(): IsConst(false), IsVolatile(false), IsRestrict(false) {}
- operator bool_type() const {
- return (this->IsConst || this->IsVolatile || this->IsRestrict)?
- &DumpQual::bool_true : nullptr;
+ DumpQual()
+ : IsConst(false)
+ , IsVolatile(false)
+ , IsRestrict(false)
+ {
}
- friend bool operator < (DumpQual const& l, DumpQual const& r) {
+ operator bool_type() const
+ {
+ return (this->IsConst || this->IsVolatile || this->IsRestrict)
+ ? &DumpQual::bool_true
+ : nullptr;
+ }
+ friend bool operator<(DumpQual const& l, DumpQual const& r)
+ {
if (!l.IsConst && r.IsConst) {
return true;
} else if (l.IsConst && !r.IsConst) {
@@ -84,28 +97,39 @@ protected:
return false;
}
}
- friend llvm::raw_ostream& operator << (llvm::raw_ostream& os,
- DumpQual const& dq) {
- return os << (dq.IsConst? "c":"")
- << (dq.IsVolatile? "v":"")
- << (dq.IsRestrict? "r":"");
+ friend llvm::raw_ostream& operator<<(llvm::raw_ostream& os,
+ DumpQual const& dq)
+ {
+ return os << (dq.IsConst ? "c" : "") << (dq.IsVolatile ? "v" : "")
+ << (dq.IsRestrict ? "r" : "");
}
};
// Represent id of one dump node.
- struct DumpId {
+ struct DumpId
+ {
private:
typedef void (DumpId::*bool_type)() const;
void bool_true() const {}
public:
unsigned int Id;
DumpQual Qual;
- DumpId(): Id(0), Qual() {}
- DumpId(unsigned int id, DumpQual dq): Id(id), Qual(dq) {}
- operator bool_type() const {
- return this->Id != 0? &DumpId::bool_true : nullptr;
+ DumpId()
+ : Id(0)
+ , Qual()
+ {
+ }
+ DumpId(unsigned int id, DumpQual dq)
+ : Id(id)
+ , Qual(dq)
+ {
}
- friend bool operator < (DumpId const& l, DumpId const& r) {
+ operator bool_type() const
+ {
+ return this->Id != 0 ? &DumpId::bool_true : nullptr;
+ }
+ friend bool operator<(DumpId const& l, DumpId const& r)
+ {
if (l.Id < r.Id) {
return true;
} else if (l.Id > r.Id) {
@@ -114,15 +138,21 @@ protected:
return l.Qual < r.Qual;
}
}
- friend llvm::raw_ostream& operator << (llvm::raw_ostream& os,
- DumpId const& id) {
+ friend llvm::raw_ostream& operator<<(llvm::raw_ostream& os,
+ DumpId const& id)
+ {
return os << id.Id << id.Qual;
}
};
// Record status of one AST node to be dumped.
- struct DumpNode {
- DumpNode(): Index(), Complete(false) {}
+ struct DumpNode
+ {
+ DumpNode()
+ : Index()
+ , Complete(false)
+ {
+ }
// Index in nodes ordered by first encounter.
DumpId Index;
@@ -131,30 +161,34 @@ protected:
bool Complete;
};
- // Report all decl nodes as unimplemented until overridden.
+// Report all decl nodes as unimplemented until overridden.
#define ABSTRACT_DECL(DECL)
-#define DECL(CLASS, BASE) \
- void Output##CLASS##Decl(clang::CLASS##Decl const* d, DumpNode const* dn) { \
- this->OutputUnimplementedDecl(d, dn); \
+#define DECL(CLASS, BASE) \
+ void Output##CLASS##Decl(clang::CLASS##Decl const* d, DumpNode const* dn) \
+ { \
+ this->OutputUnimplementedDecl(d, dn); \
}
#include "clang/AST/DeclNodes.inc"
- void OutputUnimplementedDecl(clang::Decl const* d, DumpNode const* dn) {
+ void OutputUnimplementedDecl(clang::Decl const* d, DumpNode const* dn)
+ {
/* clang-format off */
this->OS << " <Unimplemented id=\"_" << dn->Index
<< "\" kind=\"" << encodeXML(d->getDeclKindName()) << "\"/>\n";
/* clang-format on */
}
- // Report all type nodes as unimplemented until overridden.
+// Report all type nodes as unimplemented until overridden.
#define ABSTRACT_TYPE(CLASS, BASE)
-#define TYPE(CLASS, BASE) \
- void Output##CLASS##Type(clang::CLASS##Type const* t, DumpNode const* dn) { \
- this->OutputUnimplementedType(t, dn); \
- }
+#define TYPE(CLASS, BASE) \
+ void Output##CLASS##Type(clang::CLASS##Type const* t, DumpNode const* dn) \
+ { \
+ this->OutputUnimplementedType(t, dn); \
+ }
#include "clang/AST/TypeNodes.def"
- void OutputUnimplementedType(clang::Type const* t, DumpNode const* dn) {
+ void OutputUnimplementedType(clang::Type const* t, DumpNode const* dn)
+ {
/* clang-format off */
this->OS << " <Unimplemented id=\"_" << dn->Index
<< "\" type_class=\"" << encodeXML(t->getTypeClassName())
@@ -163,47 +197,74 @@ protected:
}
};
-class ASTVisitor: public ASTVisitorBase
+class ASTVisitor : public ASTVisitorBase
{
// Store a type to be visited, possibly as a record member.
- struct DumpType {
- DumpType(): Type(), Class(0) {}
- DumpType(clang::QualType t, clang::Type const* c = 0): Type(t), Class(c) {}
- friend bool operator < (DumpType const& l, DumpType const& r) {
+ struct DumpType
+ {
+ DumpType()
+ : Type()
+ , Class(0)
+ {
+ }
+ DumpType(clang::QualType t, clang::Type const* c = 0)
+ : Type(t)
+ , Class(c)
+ {
+ }
+ friend bool operator<(DumpType const& l, DumpType const& r)
+ {
// Order by pointer value without discarding low-order
// bits used to encode qualifiers.
void const* lpp = &l.Type;
void const* rpp = &r.Type;
void const* lpv = *static_cast<void const* const*>(lpp);
void const* rpv = *static_cast<void const* const*>(rpp);
- if(lpv < rpv) {
+ if (lpv < rpv) {
return true;
- } else if(lpv > rpv) {
+ } else if (lpv > rpv) {
return false;
} else {
return l.Class < r.Class;
}
}
- clang::QualType Type;
+ clang::QualType Type;
clang::Type const* Class;
};
// Store an entry in the node traversal queue.
- struct QueueEntry {
+ struct QueueEntry
+ {
// Available node kinds.
- enum Kinds {
+ enum Kinds
+ {
KindQual,
KindDecl,
KindType
};
- QueueEntry(DumpNode const* dn):
- Kind(KindQual), Decl(nullptr), Type(), DN(dn) {}
- QueueEntry(clang::Decl const* d, DumpNode const* dn):
- Kind(KindDecl), Decl(d), Type(), DN(dn) {}
- QueueEntry(DumpType t, DumpNode const* dn):
- Kind(KindType), Decl(nullptr), Type(t), DN(dn) {}
+ QueueEntry(DumpNode const* dn)
+ : Kind(KindQual)
+ , Decl(nullptr)
+ , Type()
+ , DN(dn)
+ {
+ }
+ QueueEntry(clang::Decl const* d, DumpNode const* dn)
+ : Kind(KindDecl)
+ , Decl(d)
+ , Type()
+ , DN(dn)
+ {
+ }
+ QueueEntry(DumpType t, DumpNode const* dn)
+ : Kind(KindType)
+ , Decl(nullptr)
+ , Type(t)
+ , DN(dn)
+ {
+ }
// Kind of node at this entry.
Kinds Kind;
@@ -217,32 +278,36 @@ class ASTVisitor: public ASTVisitorBase
// The dump status for this node.
DumpNode const* DN;
- friend bool operator < (QueueEntry const& l, QueueEntry const& r) {
+ friend bool operator<(QueueEntry const& l, QueueEntry const& r)
+ {
return l.DN->Index < r.DN->Index;
}
};
- class PrinterHelper: public clang::PrinterHelper {
+ class PrinterHelper : public clang::PrinterHelper
+ {
ASTVisitor& Visitor;
+
public:
- PrinterHelper(ASTVisitor& v): Visitor(v) {}
- bool handledStmt(clang::Stmt* s, llvm::raw_ostream& os) override {
+ PrinterHelper(ASTVisitor& v)
+ : Visitor(v)
+ {
+ }
+ bool handledStmt(clang::Stmt* s, llvm::raw_ostream& os) override
+ {
return this->Visitor.PrintHelpStmt(s, os);
}
};
/** Get the dump status node for a Clang declaration. */
- DumpNode* GetDumpNode(clang::Decl const* d) {
- return &this->DeclNodes[d];
- }
+ DumpNode* GetDumpNode(clang::Decl const* d) { return &this->DeclNodes[d]; }
/** Get the dump status node for a Clang type. */
- DumpNode* GetDumpNode(DumpType t) {
- return &this->TypeNodes[t];
- }
+ DumpNode* GetDumpNode(DumpType t) { return &this->TypeNodes[t]; }
/** Get the dump status node for a qualified DumpId. */
- DumpNode* GetDumpNode(DumpId id) {
+ DumpNode* GetDumpNode(DumpId id)
+ {
assert(id.Qual);
return &this->QualNodes[id];
}
@@ -260,7 +325,8 @@ class ASTVisitor: public ASTVisitorBase
DumpId AddQualDumpNode(DumpId id);
/** Helper common to AddDeclDumpNode and AddTypeDumpNode. */
- template <typename K> DumpId AddDumpNodeImpl(K k, bool complete);
+ template <typename K>
+ DumpId AddDumpNodeImpl(K k, bool complete);
/** Allocate a dump node for a source file entry. */
unsigned int AddDumpFile(clang::FileEntry const* f);
@@ -385,13 +451,14 @@ class ASTVisitor: public ASTVisitorBase
/** Flags used by function output methods to pass information
to the OutputFunctionHelper method. */
- enum FunctionHelperFlags {
- FH_Returns = (1<<0),
- FH_Static = (1<<1),
- FH_Explicit = (1<<2),
- FH_Const = (1<<3),
- FH_Virtual = (1<<4),
- FH_Pure = (1<<5),
+ enum FunctionHelperFlags
+ {
+ FH_Returns = (1 << 0),
+ FH_Static = (1 << 1),
+ FH_Explicit = (1 << 2),
+ FH_Const = (1 << 3),
+ FH_Virtual = (1 << 4),
+ FH_Pure = (1 << 5),
FH__Last
};
@@ -516,17 +583,17 @@ private:
std::queue<clang::FileEntry const*> FileQueue;
public:
- ASTVisitor(clang::CompilerInstance& ci,
- clang::ASTContext& ctx,
- llvm::raw_ostream& os,
- Options const& opts):
- ASTVisitorBase(ci, ctx, os),
- Opts(opts),
- NodeCount(0), FileCount(0),
- FileBuiltin(false),
- RequireComplete(true),
- MangleContext(ctx.createMangleContext()),
- PrintingPolicy(ctx.getPrintingPolicy()) {
+ ASTVisitor(clang::CompilerInstance& ci, clang::ASTContext& ctx,
+ llvm::raw_ostream& os, Options const& opts)
+ : ASTVisitorBase(ci, ctx, os)
+ , Opts(opts)
+ , NodeCount(0)
+ , FileCount(0)
+ , FileBuiltin(false)
+ , RequireComplete(true)
+ , MangleContext(ctx.createMangleContext())
+ , PrintingPolicy(ctx.getPrintingPolicy())
+ {
this->PrintingPolicy.SuppressUnwrittenScope = true;
}
@@ -536,29 +603,30 @@ public:
};
ASTVisitor::DumpId ASTVisitor::AddDeclDumpNode(clang::Decl const* d,
- bool complete, bool forType) {
+ bool complete, bool forType)
+{
// Select the definition or canonical declaration.
d = d->getCanonicalDecl();
- if(clang::RecordDecl const* rd = clang::dyn_cast<clang::RecordDecl>(d)) {
- if(clang::RecordDecl const* rdd = rd->getDefinition()) {
+ if (clang::RecordDecl const* rd = clang::dyn_cast<clang::RecordDecl>(d)) {
+ if (clang::RecordDecl const* rdd = rd->getDefinition()) {
d = rdd;
}
}
// Replace some decls with those they reference.
switch (d->getKind()) {
- case clang::Decl::UsingShadow:
- return this->AddDeclDumpNode(
- static_cast<clang::UsingShadowDecl const*>(d)->getTargetDecl(),
- complete, forType);
- case clang::Decl::LinkageSpec: {
- clang::DeclContext const* dc =
- static_cast<clang::LinkageSpecDecl const*>(d)->getDeclContext();
- return this->AddDeclDumpNode(clang::Decl::castFromDeclContext(dc),
- complete, forType);
- } break;
- default:
- break;
+ case clang::Decl::UsingShadow:
+ return this->AddDeclDumpNode(
+ static_cast<clang::UsingShadowDecl const*>(d)->getTargetDecl(),
+ complete, forType);
+ case clang::Decl::LinkageSpec: {
+ clang::DeclContext const* dc =
+ static_cast<clang::LinkageSpecDecl const*>(d)->getDeclContext();
+ return this->AddDeclDumpNode(clang::Decl::castFromDeclContext(dc),
+ complete, forType);
+ } break;
+ default:
+ break;
}
// Skip invalid declarations that are not needed for a type element.
@@ -569,7 +637,7 @@ ASTVisitor::DumpId ASTVisitor::AddDeclDumpNode(clang::Decl const* d,
// Skip C++11 declarations gccxml does not support.
if (this->Opts.GccXml) {
if (clang::FunctionDecl const* fd =
- clang::dyn_cast<clang::FunctionDecl>(d)) {
+ clang::dyn_cast<clang::FunctionDecl>(d)) {
if (fd->isDeleted()) {
return DumpId();
}
@@ -579,14 +647,15 @@ ASTVisitor::DumpId ASTVisitor::AddDeclDumpNode(clang::Decl const* d,
}
if (clang::FunctionProtoType const* fpt =
- fd->getType()->getAs<clang::FunctionProtoType>()) {
+ fd->getType()->getAs<clang::FunctionProtoType>()) {
if (fpt->getReturnType()->isRValueReferenceType()) {
return DumpId();
}
for (clang::FunctionProtoType::param_type_iterator
- i = fpt->param_type_begin(), e = fpt->param_type_end();
+ i = fpt->param_type_begin(),
+ e = fpt->param_type_end();
i != e; ++i) {
- if((*i)->isRValueReferenceType()) {
+ if ((*i)->isRValueReferenceType()) {
return DumpId();
}
}
@@ -602,7 +671,7 @@ ASTVisitor::DumpId ASTVisitor::AddDeclDumpNode(clang::Decl const* d,
}
if (clang::TypedefDecl const* td =
- clang::dyn_cast<clang::TypedefDecl>(d)) {
+ clang::dyn_cast<clang::TypedefDecl>(d)) {
if (td->getUnderlyingType()->isRValueReferenceType()) {
return DumpId();
}
@@ -614,7 +683,8 @@ ASTVisitor::DumpId ASTVisitor::AddDeclDumpNode(clang::Decl const* d,
ASTVisitor::DumpId ASTVisitor::AddDeclDumpNodeForType(clang::Decl const* d,
bool complete,
- DumpQual dq) {
+ DumpQual dq)
+{
// Get the id for the canonical decl.
DumpId id = this->AddDeclDumpNode(d, complete, true);
@@ -628,12 +698,13 @@ ASTVisitor::DumpId ASTVisitor::AddDeclDumpNodeForType(clang::Decl const* d,
}
ASTVisitor::DumpId ASTVisitor::AddTypeDumpNode(DumpType dt, bool complete,
- DumpQual dq) {
+ DumpQual dq)
+{
clang::QualType t = dt.Type;
clang::Type const* c = dt.Class;
// Extract local qualifiers and recurse with locally unqualified type.
- if(t.hasLocalQualifiers()) {
+ if (t.hasLocalQualifiers()) {
dq.IsConst = dq.IsConst || t.isLocalConstQualified();
dq.IsVolatile = dq.IsVolatile || t.isLocalVolatileQualified();
dq.IsRestrict = dq.IsRestrict || t.isLocalRestrictQualified();
@@ -643,72 +714,74 @@ ASTVisitor::DumpId ASTVisitor::AddTypeDumpNode(DumpType dt, bool complete,
// Replace some types with their decls.
switch (t->getTypeClass()) {
- case clang::Type::Adjusted:
- return this->AddTypeDumpNode(DumpType(
- t->getAs<clang::AdjustedType>()->getAdjustedType(), c),
- complete, dq);
- case clang::Type::Attributed:
- return this->AddTypeDumpNode(DumpType(
- t->getAs<clang::AttributedType>()->getEquivalentType(), c),
- complete, dq);
- case clang::Type::Decayed:
- return this->AddTypeDumpNode(DumpType(
- t->getAs<clang::DecayedType>()->getDecayedType(), c),
- complete, dq);
- case clang::Type::Elaborated:
- return this->AddTypeDumpNode(DumpType(
- t->getAs<clang::ElaboratedType>()->getNamedType(), c),
- complete, dq);
- case clang::Type::Enum:
- return this->AddDeclDumpNodeForType(
- t->getAs<clang::EnumType>()->getDecl(), complete, dq);
- case clang::Type::Paren:
- return this->AddTypeDumpNode(DumpType(
- t->getAs<clang::ParenType>()->getInnerType(), c),
- complete, dq);
- case clang::Type::Record:
- return this->AddDeclDumpNodeForType(
- t->getAs<clang::RecordType>()->getDecl(), complete, dq);
- case clang::Type::SubstTemplateTypeParm:
- return this->AddTypeDumpNode(DumpType(
- t->getAs<clang::SubstTemplateTypeParmType>()->getReplacementType(), c),
- complete, dq);
- case clang::Type::TemplateSpecialization: {
- clang::TemplateSpecializationType const* tst =
- t->getAs<clang::TemplateSpecializationType>();
- if(tst->isSugared()) {
- return this->AddTypeDumpNode(DumpType(tst->desugar(), c),
- complete, dq);
- }
- } break;
- case clang::Type::Typedef: {
- clang::TypedefType const* tdt = t->getAs<clang::TypedefType>();
- if(!tdt->isInstantiationDependentType() && tdt->isSugared()) {
- // Make sure all containing contexts are not templates.
- clang::Decl const* d = tdt->getDecl();
- while (clang::DeclContext const* tdc = d->getDeclContext()) {
- if (clang::CXXRecordDecl const* tdx =
- clang::dyn_cast<clang::CXXRecordDecl>(tdc)) {
- d = tdx;
- if (tdx->getDescribedClassTemplate() ||
- clang::isa<clang::ClassTemplatePartialSpecializationDecl>(tdx)
- ) {
- // This TypedefType refers to a non-dependent
- // TypedefDecl member of a class template. Since gccxml
- // format does not include uninstantiated templates we
- // must use the desugared type so that we do not end up
- // referencing a class template as context.
- return this->AddTypeDumpNode(tdt->desugar(), complete, dq);
+ case clang::Type::Adjusted:
+ return this->AddTypeDumpNode(
+ DumpType(t->getAs<clang::AdjustedType>()->getAdjustedType(), c),
+ complete, dq);
+ case clang::Type::Attributed:
+ return this->AddTypeDumpNode(
+ DumpType(t->getAs<clang::AttributedType>()->getEquivalentType(), c),
+ complete, dq);
+ case clang::Type::Decayed:
+ return this->AddTypeDumpNode(
+ DumpType(t->getAs<clang::DecayedType>()->getDecayedType(), c),
+ complete, dq);
+ case clang::Type::Elaborated:
+ return this->AddTypeDumpNode(
+ DumpType(t->getAs<clang::ElaboratedType>()->getNamedType(), c),
+ complete, dq);
+ case clang::Type::Enum:
+ return this->AddDeclDumpNodeForType(
+ t->getAs<clang::EnumType>()->getDecl(), complete, dq);
+ case clang::Type::Paren:
+ return this->AddTypeDumpNode(
+ DumpType(t->getAs<clang::ParenType>()->getInnerType(), c), complete,
+ dq);
+ case clang::Type::Record:
+ return this->AddDeclDumpNodeForType(
+ t->getAs<clang::RecordType>()->getDecl(), complete, dq);
+ case clang::Type::SubstTemplateTypeParm:
+ return this->AddTypeDumpNode(
+ DumpType(
+ t->getAs<clang::SubstTemplateTypeParmType>()->getReplacementType(),
+ c),
+ complete, dq);
+ case clang::Type::TemplateSpecialization: {
+ clang::TemplateSpecializationType const* tst =
+ t->getAs<clang::TemplateSpecializationType>();
+ if (tst->isSugared()) {
+ return this->AddTypeDumpNode(DumpType(tst->desugar(), c), complete,
+ dq);
+ }
+ } break;
+ case clang::Type::Typedef: {
+ clang::TypedefType const* tdt = t->getAs<clang::TypedefType>();
+ if (!tdt->isInstantiationDependentType() && tdt->isSugared()) {
+ // Make sure all containing contexts are not templates.
+ clang::Decl const* d = tdt->getDecl();
+ while (clang::DeclContext const* tdc = d->getDeclContext()) {
+ if (clang::CXXRecordDecl const* tdx =
+ clang::dyn_cast<clang::CXXRecordDecl>(tdc)) {
+ d = tdx;
+ if (tdx->getDescribedClassTemplate() ||
+ clang::isa<clang::ClassTemplatePartialSpecializationDecl>(
+ tdx)) {
+ // This TypedefType refers to a non-dependent
+ // TypedefDecl member of a class template. Since gccxml
+ // format does not include uninstantiated templates we
+ // must use the desugared type so that we do not end up
+ // referencing a class template as context.
+ return this->AddTypeDumpNode(tdt->desugar(), complete, dq);
+ }
+ } else {
+ break;
}
- } else {
- break;
}
}
- }
- return this->AddDeclDumpNodeForType(tdt->getDecl(), complete, dq);
- } break;
- default:
- break;
+ return this->AddDeclDumpNodeForType(tdt->getDecl(), complete, dq);
+ } break;
+ default:
+ break;
}
// Get the id for the fully desugared, unqualified type.
@@ -723,7 +796,8 @@ ASTVisitor::DumpId ASTVisitor::AddTypeDumpNode(DumpType dt, bool complete,
return id;
}
-ASTVisitor::DumpId ASTVisitor::AddQualDumpNode(DumpId id) {
+ASTVisitor::DumpId ASTVisitor::AddQualDumpNode(DumpId id)
+{
DumpNode* dn = this->GetDumpNode(id);
if (!dn->Index) {
dn->Index = id;
@@ -741,7 +815,7 @@ ASTVisitor::DumpId ASTVisitor::AddDumpNodeImpl(K k, bool complete)
DumpNode* dn = this->GetDumpNode(k);
if (dn->Index) {
// Node was already encountered. See if it is now complete.
- if(complete && !dn->Complete) {
+ if (complete && !dn->Complete) {
// Node is now complete, but wasn't before. Queue it.
dn->Complete = true;
this->Queue.insert(QueueEntry(k, dn));
@@ -750,7 +824,7 @@ ASTVisitor::DumpId ASTVisitor::AddDumpNodeImpl(K k, bool complete)
// This is a new node. Assign it an index.
dn->Index.Id = ++this->NodeCount;
dn->Complete = complete;
- if(complete || !this->RequireComplete) {
+ if (complete || !this->RequireComplete) {
// Node is complete. Queue it.
this->Queue.insert(QueueEntry(k, dn));
}
@@ -762,7 +836,7 @@ ASTVisitor::DumpId ASTVisitor::AddDumpNodeImpl(K k, bool complete)
unsigned int ASTVisitor::AddDumpFile(clang::FileEntry const* f)
{
unsigned int& index = this->FileNodes[f];
- if(index == 0) {
+ if (index == 0) {
index = ++this->FileCount;
this->FileQueue.push(f);
}
@@ -773,11 +847,12 @@ void ASTVisitor::AddClassTemplateDecl(clang::ClassTemplateDecl const* d,
std::set<DumpId>* emitted)
{
// Queue all the instantiations of this class template.
- for(clang::ClassTemplateDecl::spec_iterator i = d->spec_begin(),
- e = d->spec_end(); i != e; ++i) {
+ for (clang::ClassTemplateDecl::spec_iterator i = d->spec_begin(),
+ e = d->spec_end();
+ i != e; ++i) {
clang::CXXRecordDecl const* rd = *i;
DumpId id = this->AddDeclDumpNode(rd, true);
- if(id && emitted) {
+ if (id && emitted) {
emitted->insert(id);
}
}
@@ -787,11 +862,12 @@ void ASTVisitor::AddFunctionTemplateDecl(clang::FunctionTemplateDecl const* d,
std::set<DumpId>* emitted)
{
// Queue all the instantiations of this function template.
- for(clang::FunctionTemplateDecl::spec_iterator i = d->spec_begin(),
- e = d->spec_end(); i != e; ++i) {
+ for (clang::FunctionTemplateDecl::spec_iterator i = d->spec_begin(),
+ e = d->spec_end();
+ i != e; ++i) {
clang::FunctionDecl const* fd = *i;
DumpId id = this->AddDeclDumpNode(fd, true);
- if(id && emitted) {
+ if (id && emitted) {
emitted->insert(id);
}
}
@@ -802,12 +878,13 @@ void ASTVisitor::AddDeclContextMembers(clang::DeclContext const* dc,
{
bool const isTranslationUnit = clang::isa<clang::TranslationUnitDecl>(dc);
- for(clang::DeclContext::decl_iterator i = dc->decls_begin(),
- e = dc->decls_end(); i != e; ++i) {
+ for (clang::DeclContext::decl_iterator i = dc->decls_begin(),
+ e = dc->decls_end();
+ i != e; ++i) {
clang::Decl const* d = *i;
// Skip declarations that are not really members of this context.
- if(d->getDeclContext() != dc) {
+ if (d->getDeclContext() != dc) {
continue;
}
@@ -824,60 +901,60 @@ void ASTVisitor::AddDeclContextMembers(clang::DeclContext const* dc,
// Ignore certain members.
switch (d->getKind()) {
- case clang::Decl::CXXRecord: {
- clang::CXXRecordDecl const* rd =
- static_cast<clang::CXXRecordDecl const*>(d);
- if (rd->isInjectedClassName()) {
+ case clang::Decl::CXXRecord: {
+ clang::CXXRecordDecl const* rd =
+ static_cast<clang::CXXRecordDecl const*>(d);
+ if (rd->isInjectedClassName()) {
+ continue;
+ }
+ } break;
+ case clang::Decl::AccessSpec: {
continue;
- }
- } break;
- case clang::Decl::AccessSpec: {
- continue;
- } break;
- case clang::Decl::ClassTemplate: {
- this->AddClassTemplateDecl(
- static_cast<clang::ClassTemplateDecl const*>(d), &emitted);
- continue;
- } break;
- case clang::Decl::ClassTemplatePartialSpecialization: {
- continue;
- } break;
- case clang::Decl::Empty: {
- continue;
- } break;
- case clang::Decl::Friend: {
- continue;
- } break;
- case clang::Decl::FunctionTemplate: {
- this->AddFunctionTemplateDecl(
- static_cast<clang::FunctionTemplateDecl const*>(d), &emitted);
- continue;
- } break;
- case clang::Decl::LinkageSpec: {
- this->AddDeclContextMembers(
- static_cast<clang::LinkageSpecDecl const*>(d), emitted);
- continue;
- } break;
- case clang::Decl::Namespace: {
- clang::NamespaceDecl const* nd =
- static_cast<clang::NamespaceDecl const*>(d);
- if (nd->isInline()) {
- this->AddDeclContextMembers(nd, emitted);
+ } break;
+ case clang::Decl::ClassTemplate: {
+ this->AddClassTemplateDecl(
+ static_cast<clang::ClassTemplateDecl const*>(d), &emitted);
continue;
- }
- } break;
- case clang::Decl::Using: {
- continue;
- } break;
- case clang::Decl::UsingDirective: {
- continue;
- } break;
- default:
- break;
+ } break;
+ case clang::Decl::ClassTemplatePartialSpecialization: {
+ continue;
+ } break;
+ case clang::Decl::Empty: {
+ continue;
+ } break;
+ case clang::Decl::Friend: {
+ continue;
+ } break;
+ case clang::Decl::FunctionTemplate: {
+ this->AddFunctionTemplateDecl(
+ static_cast<clang::FunctionTemplateDecl const*>(d), &emitted);
+ continue;
+ } break;
+ case clang::Decl::LinkageSpec: {
+ this->AddDeclContextMembers(
+ static_cast<clang::LinkageSpecDecl const*>(d), emitted);
+ continue;
+ } break;
+ case clang::Decl::Namespace: {
+ clang::NamespaceDecl const* nd =
+ static_cast<clang::NamespaceDecl const*>(d);
+ if (nd->isInline()) {
+ this->AddDeclContextMembers(nd, emitted);
+ continue;
+ }
+ } break;
+ case clang::Decl::Using: {
+ continue;
+ } break;
+ case clang::Decl::UsingDirective: {
+ continue;
+ } break;
+ default:
+ break;
}
// Queue this decl and print its id.
- if(DumpId id = this->AddDeclDumpNode(d, true)) {
+ if (DumpId id = this->AddDeclDumpNode(d, true)) {
emitted.insert(id);
}
}
@@ -886,46 +963,49 @@ void ASTVisitor::AddDeclContextMembers(clang::DeclContext const* dc,
void ASTVisitor::AddStartDecl(clang::Decl const* d)
{
switch (d->getKind()) {
- case clang::Decl::ClassTemplate:
- this->AddClassTemplateDecl(
- static_cast<clang::ClassTemplateDecl const*>(d));
- break;
- case clang::Decl::FunctionTemplate:
- this->AddFunctionTemplateDecl(
- static_cast<clang::FunctionTemplateDecl const*>(d));
- break;
- case clang::Decl::Namespace: {
- if (!static_cast<clang::NamespaceDecl const*>(d)->isInline()) {
- this->AddDeclDumpNode(d, true);
- }
- } break;
- case clang::Decl::Using: {
+ case clang::Decl::ClassTemplate:
+ this->AddClassTemplateDecl(
+ static_cast<clang::ClassTemplateDecl const*>(d));
+ break;
+ case clang::Decl::FunctionTemplate:
+ this->AddFunctionTemplateDecl(
+ static_cast<clang::FunctionTemplateDecl const*>(d));
+ break;
+ case clang::Decl::Namespace: {
+ if (!static_cast<clang::NamespaceDecl const*>(d)->isInline()) {
+ this->AddDeclDumpNode(d, true);
+ }
+ } break;
+ case clang::Decl::Using: {
clang::UsingDecl const* ud = static_cast<clang::UsingDecl const*>(d);
- for(clang::UsingDecl::shadow_iterator i = ud->shadow_begin(),
- e = ud->shadow_end(); i != e; ++i) {
+ for (clang::UsingDecl::shadow_iterator i = ud->shadow_begin(),
+ e = ud->shadow_end();
+ i != e; ++i) {
this->AddDeclDumpNode(*i, true);
}
- } break;
- default:
- this->AddDeclDumpNode(d, true);
- break;
+ } break;
+ default:
+ this->AddDeclDumpNode(d, true);
+ break;
}
}
void ASTVisitor::QueueIncompleteDumpNodes()
{
// Queue declaration nodes that do not need complete output.
- for(DeclNodesMap::const_iterator i = this->DeclNodes.begin(),
- e = this->DeclNodes.end(); i != e; ++i) {
- if(!i->second.Complete) {
+ for (DeclNodesMap::const_iterator i = this->DeclNodes.begin(),
+ e = this->DeclNodes.end();
+ i != e; ++i) {
+ if (!i->second.Complete) {
this->Queue.insert(QueueEntry(i->first, &i->second));
}
}
// Queue type nodes that do not need complete output.
- for(TypeNodesMap::const_iterator i = this->TypeNodes.begin(),
- e = this->TypeNodes.end(); i != e; ++i) {
- if(!i->second.Complete) {
+ for (TypeNodesMap::const_iterator i = this->TypeNodes.begin(),
+ e = this->TypeNodes.end();
+ i != e; ++i) {
+ if (!i->second.Complete) {
this->Queue.insert(QueueEntry(i->first, &i->second));
}
}
@@ -934,33 +1014,33 @@ void ASTVisitor::QueueIncompleteDumpNodes()
void ASTVisitor::ProcessQueue()
{
// Dispatch each entry in the queue based on its node kind.
- while(!this->Queue.empty()) {
+ while (!this->Queue.empty()) {
QueueEntry qe = *this->Queue.begin();
this->Queue.erase(this->Queue.begin());
- switch(qe.Kind) {
- case QueueEntry::KindQual:
- this->OutputCvQualifiedType(qe.DN);
- break;
- case QueueEntry::KindDecl:
- this->OutputDecl(qe.Decl, qe.DN);
- break;
- case QueueEntry::KindType:
- this->OutputType(qe.Type, qe.DN);
- break;
+ switch (qe.Kind) {
+ case QueueEntry::KindQual:
+ this->OutputCvQualifiedType(qe.DN);
+ break;
+ case QueueEntry::KindDecl:
+ this->OutputDecl(qe.Decl, qe.DN);
+ break;
+ case QueueEntry::KindType:
+ this->OutputType(qe.Type, qe.DN);
+ break;
}
}
}
void ASTVisitor::ProcessFileQueue()
{
- if(this->FileBuiltin) {
+ if (this->FileBuiltin) {
/* clang-format off */
this->OS <<
" <File id=\"f0\" name=\"" << encodeXML("<builtin>") << "\"/>\n"
;
/* clang-format on */
}
- while(!this->FileQueue.empty()) {
+ while (!this->FileQueue.empty()) {
clang::FileEntry const* f = this->FileQueue.front();
this->FileQueue.pop();
/* clang-format off */
@@ -979,10 +1059,9 @@ void ASTVisitor::OutputDecl(clang::Decl const* d, DumpNode const* dn)
// Dispatch output of the declaration.
switch (d->getKind()) {
#define ABSTRACT_DECL(DECL)
-#define DECL(CLASS, BASE) \
- case clang::Decl::CLASS: \
- this->Output##CLASS##Decl( \
- static_cast<clang::CLASS##Decl const*>(d), dn); \
+#define DECL(CLASS, BASE) \
+ case clang::Decl::CLASS: \
+ this->Output##CLASS##Decl(static_cast<clang::CLASS##Decl const*>(d), dn); \
break;
#include "clang/AST/DeclNodes.inc"
}
@@ -993,18 +1072,18 @@ void ASTVisitor::OutputType(DumpType dt, DumpNode const* dn)
clang::QualType t = dt.Type;
clang::Type const* c = dt.Class;
- if(c) {
+ if (c) {
// Output the method type.
this->OutputMethodType(t->getAs<clang::FunctionProtoType>(), c, dn);
} else {
// Dispatch output of the unqualified type.
switch (t->getTypeClass()) {
#define ABSTRACT_TYPE(CLASS, BASE)
-#define TYPE(CLASS, BASE) \
- case clang::Type::CLASS: \
- this->Output##CLASS##Type( \
- static_cast<clang::CLASS##Type const*>(t.getTypePtr()), dn); \
- break;
+#define TYPE(CLASS, BASE) \
+ case clang::Type::CLASS: \
+ this->Output##CLASS##Type( \
+ static_cast<clang::CLASS##Type const*>(t.getTypePtr()), dn); \
+ break;
#include "clang/AST/TypeNodes.def"
}
}
@@ -1040,7 +1119,7 @@ ASTVisitor::DumpId ASTVisitor::GetContextIdRef(clang::DeclContext const* dc)
dc = dc->getParent();
}
- if(clang::Decl const* d = clang::dyn_cast<clang::Decl>(dc)) {
+ if (clang::Decl const* d = clang::dyn_cast<clang::Decl>(dc)) {
return this->AddDeclDumpNode(d, false);
} else {
return DumpId();
@@ -1050,7 +1129,7 @@ ASTVisitor::DumpId ASTVisitor::GetContextIdRef(clang::DeclContext const* dc)
std::string ASTVisitor::GetContextName(clang::CXXMethodDecl const* d)
{
clang::DeclContext const* dc = d->getDeclContext();
- if(clang::RecordDecl const* rd = clang::dyn_cast<clang::RecordDecl>(dc)) {
+ if (clang::RecordDecl const* rd = clang::dyn_cast<clang::RecordDecl>(dc)) {
return rd->getName().str();
}
return "";
@@ -1106,9 +1185,9 @@ void ASTVisitor::PrintOffsetAttribute(unsigned int const& offset)
void ASTVisitor::PrintABIAttributes(clang::TypeDecl const* d)
{
- if(clang::TypeDecl const* td = clang::dyn_cast<clang::TypeDecl>(d)) {
+ if (clang::TypeDecl const* td = clang::dyn_cast<clang::TypeDecl>(d)) {
clang::Type const* ty = td->getTypeForDecl();
- if(!ty->isIncompleteType()) {
+ if (!ty->isIncompleteType()) {
this->PrintABIAttributes(this->CTX.getTypeInfo(ty));
}
}
@@ -1144,10 +1223,10 @@ void ASTVisitor::PrintReturnsAttribute(clang::QualType t, bool complete)
void ASTVisitor::PrintLocationAttribute(clang::Decl const* d)
{
clang::SourceLocation sl = d->getLocation();
- if(sl.isValid()) {
+ if (sl.isValid()) {
clang::FullSourceLoc fsl = this->CTX.getFullLoc(sl).getExpansionLoc();
if (clang::FileEntry const* f =
- this->CI.getSourceManager().getFileEntryForID(fsl.getFileID())) {
+ this->CI.getSourceManager().getFileEntryForID(fsl.getFileID())) {
unsigned int id = this->AddDumpFile(f);
unsigned int line = fsl.getExpansionLineNumber();
/* clang-format off */
@@ -1159,7 +1238,7 @@ void ASTVisitor::PrintLocationAttribute(clang::Decl const* d)
return;
}
}
- if(d->isImplicit()) {
+ if (d->isImplicit()) {
this->FileBuiltin = true;
this->OS << " location=\"f0:0\" file=\"f0\" line=\"0\"";
}
@@ -1168,58 +1247,58 @@ void ASTVisitor::PrintLocationAttribute(clang::Decl const* d)
bool ASTVisitor::PrintHelpStmt(clang::Stmt const* s, llvm::raw_ostream& os)
{
switch (s->getStmtClass()) {
- case clang::Stmt::CStyleCastExprClass: {
- // Duplicate clang::StmtPrinter::VisitCStyleCastExpr
- // but with canonical type so we do not print an unqualified name.
- clang::CStyleCastExpr const* e =
- static_cast<clang::CStyleCastExpr const*>(s);
- os << "(";
- e->getTypeAsWritten().getCanonicalType().print(os, this->PrintingPolicy);
- os << ")";
- PrinterHelper ph(*this);
- e->getSubExpr()->printPretty(os, &ph, this->PrintingPolicy);
- return true;
- } break;
- case clang::Stmt::CXXConstCastExprClass: // fallthrough
- case clang::Stmt::CXXDynamicCastExprClass: // fallthrough
- case clang::Stmt::CXXReinterpretCastExprClass: // fallthrough
- case clang::Stmt::CXXStaticCastExprClass: {
- // Duplicate clang::StmtPrinter::VisitCXXNamedCastExpr
- // but with canonical type so we do not print an unqualified name.
- clang::CXXNamedCastExpr const* e =
- static_cast<clang::CXXNamedCastExpr const*>(s);
- os << e->getCastName() << '<';
- e->getTypeAsWritten().getCanonicalType().print(os, this->PrintingPolicy);
- os << ">(";
- PrinterHelper ph(*this);
- e->getSubExpr()->printPretty(os, &ph, this->PrintingPolicy);
- os << ")";
- return true;
- } break;
- case clang::Stmt::DeclRefExprClass: {
- // Print the fully qualified name of the referenced declaration.
- clang::DeclRefExpr const* e = static_cast<clang::DeclRefExpr const*>(s);
- if (clang::NamedDecl const* d =
- clang::dyn_cast<clang::NamedDecl>(e->getDecl())) {
- std::string s;
- {
- llvm::raw_string_ostream rso(s);
- d->printQualifiedName(rso, this->PrintingPolicy);
- rso.str();
- }
- if (clang::isa<clang::EnumConstantDecl>(d)) {
- // Clang does not exclude the "::" after an unnamed enum type.
- std::string::size_type pos = s.find("::::");
- if (pos != s.npos) {
- s.erase(pos, 2);
+ case clang::Stmt::CStyleCastExprClass: {
+ // Duplicate clang::StmtPrinter::VisitCStyleCastExpr
+ // but with canonical type so we do not print an unqualified name.
+ clang::CStyleCastExpr const* e =
+ static_cast<clang::CStyleCastExpr const*>(s);
+ os << "(";
+ e->getTypeAsWritten().getCanonicalType().print(os, this->PrintingPolicy);
+ os << ")";
+ PrinterHelper ph(*this);
+ e->getSubExpr()->printPretty(os, &ph, this->PrintingPolicy);
+ return true;
+ } break;
+ case clang::Stmt::CXXConstCastExprClass: // fallthrough
+ case clang::Stmt::CXXDynamicCastExprClass: // fallthrough
+ case clang::Stmt::CXXReinterpretCastExprClass: // fallthrough
+ case clang::Stmt::CXXStaticCastExprClass: {
+ // Duplicate clang::StmtPrinter::VisitCXXNamedCastExpr
+ // but with canonical type so we do not print an unqualified name.
+ clang::CXXNamedCastExpr const* e =
+ static_cast<clang::CXXNamedCastExpr const*>(s);
+ os << e->getCastName() << '<';
+ e->getTypeAsWritten().getCanonicalType().print(os, this->PrintingPolicy);
+ os << ">(";
+ PrinterHelper ph(*this);
+ e->getSubExpr()->printPretty(os, &ph, this->PrintingPolicy);
+ os << ")";
+ return true;
+ } break;
+ case clang::Stmt::DeclRefExprClass: {
+ // Print the fully qualified name of the referenced declaration.
+ clang::DeclRefExpr const* e = static_cast<clang::DeclRefExpr const*>(s);
+ if (clang::NamedDecl const* d =
+ clang::dyn_cast<clang::NamedDecl>(e->getDecl())) {
+ std::string s;
+ {
+ llvm::raw_string_ostream rso(s);
+ d->printQualifiedName(rso, this->PrintingPolicy);
+ rso.str();
+ }
+ if (clang::isa<clang::EnumConstantDecl>(d)) {
+ // Clang does not exclude the "::" after an unnamed enum type.
+ std::string::size_type pos = s.find("::::");
+ if (pos != s.npos) {
+ s.erase(pos, 2);
+ }
}
+ os << s;
+ return true;
}
- os << s;
- return true;
- }
- } break;
- default:
- break;
+ } break;
+ default:
+ break;
}
return false;
}
@@ -1227,17 +1306,17 @@ bool ASTVisitor::PrintHelpStmt(clang::Stmt const* s, llvm::raw_ostream& os)
void ASTVisitor::PrintAccessAttribute(clang::AccessSpecifier as)
{
switch (as) {
- case clang::AS_private:
- this->OS << " access=\"private\"";
- break;
- case clang::AS_protected:
- this->OS << " access=\"protected\"";
- break;
- case clang::AS_public:
- this->OS << " access=\"public\"";
- break;
- case clang::AS_none:
- break;
+ case clang::AS_private:
+ this->OS << " access=\"private\"";
+ break;
+ case clang::AS_protected:
+ this->OS << " access=\"protected\"";
+ break;
+ case clang::AS_public:
+ this->OS << " access=\"public\"";
+ break;
+ case clang::AS_none:
+ break;
}
}
@@ -1245,11 +1324,11 @@ void ASTVisitor::PrintContextAttribute(clang::Decl const* d,
clang::AccessSpecifier alt)
{
clang::DeclContext const* dc = d->getDeclContext();
- if(DumpId id = this->GetContextIdRef(dc)) {
+ if (DumpId id = this->GetContextIdRef(dc)) {
this->OS << " context=\"_" << id << "\"";
if (dc->isRecord()) {
clang::AccessSpecifier as = d->getAccess();
- this->PrintAccessAttribute(as != clang::AS_none? as : alt);
+ this->PrintAccessAttribute(as != clang::AS_none ? as : alt);
}
}
}
@@ -1263,11 +1342,12 @@ void ASTVisitor::PrintMembersAttribute(clang::DeclContext const* dc)
void ASTVisitor::PrintMembersAttribute(std::set<DumpId> const& emitted)
{
- if(!emitted.empty()) {
+ if (!emitted.empty()) {
this->OS << " members=\"";
const char* sep = "";
- for(std::set<DumpId>::const_iterator i = emitted.begin(),
- e = emitted.end(); i != e; ++i) {
+ for (std::set<DumpId>::const_iterator i = emitted.begin(),
+ e = emitted.end();
+ i != e; ++i) {
this->OS << sep << "_" << *i;
sep = " ";
}
@@ -1279,14 +1359,20 @@ void ASTVisitor::PrintBasesAttribute(clang::CXXRecordDecl const* dx)
{
this->OS << " bases=\"";
const char* sep = "";
- for(clang::CXXRecordDecl::base_class_const_iterator i = dx->bases_begin(),
- e = dx->bases_end(); i != e; ++i) {
+ for (clang::CXXRecordDecl::base_class_const_iterator i = dx->bases_begin(),
+ e = dx->bases_end();
+ i != e; ++i) {
this->OS << sep;
sep = " ";
switch (i->getAccessSpecifier()) {
- case clang::AS_private: this->OS << "private:"; break;
- case clang::AS_protected: this->OS << "protected:"; break;
- default: break;
+ case clang::AS_private:
+ this->OS << "private:";
+ break;
+ case clang::AS_protected:
+ this->OS << "protected:";
+ break;
+ default:
+ break;
}
this->PrintTypeIdRef(i->getType().getCanonicalType(), true);
}
@@ -1301,7 +1387,7 @@ void ASTVisitor::PrintAttributesAttribute(
}
this->OS << " attributes=\"";
const char* sep = "";
- for (std::string const& a: attrs) {
+ for (std::string const& a : attrs) {
this->OS << sep << encodeXML(a);
sep = " ";
}
@@ -1319,26 +1405,26 @@ 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:
- attrs.push_back("__stdcall__");
- break;
- case clang::CallingConv::CC_X86FastCall:
- attrs.push_back("__fastcall__");
- break;
- case clang::CallingConv::CC_X86ThisCall:
- attrs.push_back("__thiscall__");
- break;
- default:
- break;
+ case clang::CallingConv::CC_C:
+ break;
+ case clang::CallingConv::CC_X86StdCall:
+ attrs.push_back("__stdcall__");
+ break;
+ case clang::CallingConv::CC_X86FastCall:
+ attrs.push_back("__fastcall__");
+ break;
+ case clang::CallingConv::CC_X86ThisCall:
+ attrs.push_back("__thiscall__");
+ break;
+ default:
+ break;
}
}
void ASTVisitor::GetDeclAttributes(clang::Decl const* d,
std::vector<std::string>& attrs)
{
- for (auto const* a: d->specific_attrs<clang::AnnotateAttr>()) {
+ for (auto const* a : d->specific_attrs<clang::AnnotateAttr>()) {
attrs.push_back("annotate(" + a->getAnnotation().str() + ")");
}
}
@@ -1346,12 +1432,12 @@ void ASTVisitor::GetDeclAttributes(clang::Decl const* d,
void ASTVisitor::PrintThrowsAttribute(clang::FunctionProtoType const* fpt,
bool complete)
{
- if(fpt && fpt->hasDynamicExceptionSpec()) {
+ if (fpt && fpt->hasDynamicExceptionSpec()) {
clang::FunctionProtoType::exception_iterator i = fpt->exception_begin();
clang::FunctionProtoType::exception_iterator e = fpt->exception_end();
this->OS << " throw=\"";
const char* sep = "";
- for(;i != e; ++i) {
+ for (; i != e; ++i) {
this->OS << sep;
this->PrintTypeIdRef(*i, complete);
sep = " ";
@@ -1362,23 +1448,24 @@ void ASTVisitor::PrintThrowsAttribute(clang::FunctionProtoType const* fpt,
void ASTVisitor::PrintBefriendingAttribute(clang::CXXRecordDecl const* dx)
{
- if(dx && dx->hasFriends()) {
+ if (dx && dx->hasFriends()) {
this->OS << " befriending=\"";
const char* sep = "";
- for(clang::CXXRecordDecl::friend_iterator i = dx->friend_begin(),
- e = dx->friend_end(); i != e; ++i) {
+ for (clang::CXXRecordDecl::friend_iterator i = dx->friend_begin(),
+ e = dx->friend_end();
+ i != e; ++i) {
clang::FriendDecl const* fd = *i;
- if(clang::NamedDecl const* nd = fd->getFriendDecl()) {
- if(nd->isTemplateDecl()) {
+ if (clang::NamedDecl const* nd = fd->getFriendDecl()) {
+ if (nd->isTemplateDecl()) {
// gccxml output format does not have uninstantiated templates
continue;
}
- if(DumpId id = this->AddDeclDumpNode(nd, false)) {
+ if (DumpId id = this->AddDeclDumpNode(nd, false)) {
this->OS << sep << "_" << id;
sep = " ";
}
- } else if(clang::TypeSourceInfo const* tsi = fd->getFriendType()) {
+ } else if (clang::TypeSourceInfo const* tsi = fd->getFriendType()) {
this->OS << sep;
this->PrintTypeIdRef(tsi->getType(), false);
sep = " ";
@@ -1396,49 +1483,48 @@ void ASTVisitor::PrintFloat128Type(DumpNode const* dn)
}
void ASTVisitor::OutputFunctionHelper(clang::FunctionDecl const* d,
- DumpNode const* dn,
- const char* tag,
+ DumpNode const* dn, const char* tag,
std::string const& name,
unsigned int flags)
{
this->OS << " <" << tag;
this->PrintIdAttribute(dn);
- if(!name.empty()) {
+ if (!name.empty()) {
this->PrintNameAttribute(name);
}
- if(flags & FH_Returns) {
+ if (flags & FH_Returns) {
this->PrintReturnsAttribute(d->getReturnType(), dn->Complete);
}
this->PrintContextAttribute(d);
this->PrintLocationAttribute(d);
- if(flags & FH_Static) {
+ if (flags & FH_Static) {
this->OS << " static=\"1\"";
}
- if(flags & FH_Explicit) {
+ if (flags & FH_Explicit) {
this->OS << " explicit=\"1\"";
}
- if(flags & FH_Const) {
+ if (flags & FH_Const) {
this->OS << " const=\"1\"";
}
- if(flags & FH_Virtual) {
+ if (flags & FH_Virtual) {
this->OS << " virtual=\"1\"";
}
- if(flags & FH_Pure) {
+ if (flags & FH_Pure) {
this->OS << " pure_virtual=\"1\"";
}
- if(d->isInlined()) {
+ if (d->isInlined()) {
this->OS << " inline=\"1\"";
}
- if(d->getStorageClass() == clang::SC_Extern) {
+ if (d->getStorageClass() == clang::SC_Extern) {
this->OS << " extern=\"1\"";
}
- if(d->isImplicit()) {
+ if (d->isImplicit()) {
this->OS << " artificial=\"1\"";
}
if (clang::CXXMethodDecl const* md =
- clang::dyn_cast<clang::CXXMethodDecl>(d)) {
+ clang::dyn_cast<clang::CXXMethodDecl>(d)) {
if (md->size_overridden_methods() > 0) {
this->OS << " overrides=\"";
const char* sep = "";
@@ -1458,7 +1544,7 @@ void ASTVisitor::OutputFunctionHelper(clang::FunctionDecl const* d,
std::vector<std::string> attributes;
if (clang::FunctionProtoType const* fpt =
- d->getType()->getAs<clang::FunctionProtoType>()) {
+ d->getType()->getAs<clang::FunctionProtoType>()) {
this->PrintThrowsAttribute(fpt, dn->Complete);
if (!clang::isa<clang::CXXConstructorDecl>(d) &&
!clang::isa<clang::CXXDestructorDecl>(d)) {
@@ -1470,7 +1556,7 @@ void ASTVisitor::OutputFunctionHelper(clang::FunctionDecl const* d,
this->GetDeclAttributes(d, attributes);
this->PrintAttributesAttribute(attributes);
- if(unsigned np = d->getNumParams()) {
+ if (unsigned np = d->getNumParams()) {
this->OS << ">\n";
for (unsigned i = 0; i < np; ++i) {
// Use the default argument from the most recent declaration.
@@ -1478,14 +1564,14 @@ void ASTVisitor::OutputFunctionHelper(clang::FunctionDecl const* d,
// them all.
clang::ParmVarDecl const* pd = d->getMostRecentDecl()->getParamDecl(i);
clang::Expr const* def = pd->getInit();
- if(!def && pd->hasUninstantiatedDefaultArg()) {
+ if (!def && pd->hasUninstantiatedDefaultArg()) {
def = pd->getUninstantiatedDefaultArg();
}
// Use the parameter located in the canonical declaration.
this->OutputFunctionArgument(d->getParamDecl(i), dn->Complete, def);
}
- if(d->isVariadic()) {
+ if (d->isVariadic()) {
this->OS << " <Ellipsis/>\n";
}
this->OS << " </" << tag << ">\n";
@@ -1500,31 +1586,33 @@ void ASTVisitor::OutputFunctionTypeHelper(clang::FunctionProtoType const* t,
{
this->OS << " <" << tag;
this->PrintIdAttribute(dn);
- if(c) {
+ if (c) {
this->PrintBaseTypeAttribute(c, dn->Complete);
}
this->PrintReturnsAttribute(t->getReturnType(), dn->Complete);
- if(t->isConst()) {
+ if (t->isConst()) {
this->OS << " const=\"1\"";
}
- if(t->isVolatile()) {
+ if (t->isVolatile()) {
this->OS << " volatile=\"1\"";
}
- if(t->isRestrict()) {
+ if (t->isRestrict()) {
this->OS << " restrict=\"1\"";
}
std::vector<std::string> attributes;
this->GetFunctionTypeAttributes(t, attributes);
this->PrintAttributesAttribute(attributes);
- if(t->param_type_begin() != t->param_type_end()) {
+ if (t->param_type_begin() != t->param_type_end()) {
this->OS << ">\n";
for (clang::FunctionProtoType::param_type_iterator
- i = t->param_type_begin(), e = t->param_type_end(); i != e; ++i) {
+ i = t->param_type_begin(),
+ e = t->param_type_end();
+ i != e; ++i) {
this->OS << " <Argument";
this->PrintTypeAttribute(*i, dn->Complete);
this->OS << "/>\n";
}
- if(t->isVariadic()) {
+ if (t->isVariadic()) {
this->OS << " <Ellipsis/>\n";
}
this->OS << " </" << tag << ">\n";
@@ -1538,12 +1626,12 @@ void ASTVisitor::OutputFunctionArgument(clang::ParmVarDecl const* a,
{
this->OS << " <Argument";
std::string name = a->getName().str();
- if(!name.empty()) {
+ if (!name.empty()) {
this->PrintNameAttribute(name);
}
this->PrintTypeAttribute(a->getType(), complete);
this->PrintLocationAttribute(a);
- if(def) {
+ if (def) {
this->OS << " default=\"";
std::string s;
llvm::raw_string_ostream rso(s);
@@ -1556,20 +1644,20 @@ void ASTVisitor::OutputFunctionArgument(clang::ParmVarDecl const* a,
this->OS << "/>\n";
}
-void ASTVisitor::OutputTranslationUnitDecl(
- clang::TranslationUnitDecl const* d, DumpNode const* dn)
+void ASTVisitor::OutputTranslationUnitDecl(clang::TranslationUnitDecl const* d,
+ DumpNode const* dn)
{
this->OS << " <Namespace";
this->PrintIdAttribute(dn);
this->PrintNameAttribute("::");
- if(dn->Complete) {
+ if (dn->Complete) {
this->PrintMembersAttribute(d);
}
this->OS << "/>\n";
}
-void ASTVisitor::OutputNamespaceDecl(
- clang::NamespaceDecl const* d, DumpNode const* dn)
+void ASTVisitor::OutputNamespaceDecl(clang::NamespaceDecl const* d,
+ DumpNode const* dn)
{
this->OS << " <Namespace";
this->PrintIdAttribute(dn);
@@ -1578,9 +1666,9 @@ void ASTVisitor::OutputNamespaceDecl(
this->PrintNameAttribute(name);
}
this->PrintContextAttribute(d);
- if(dn->Complete) {
+ if (dn->Complete) {
std::set<DumpId> emitted;
- for (clang::NamespaceDecl const* r: d->redecls()) {
+ for (clang::NamespaceDecl const* r : d->redecls()) {
this->AddDeclContextMembers(r, emitted);
}
this->PrintMembersAttribute(emitted);
@@ -1593,18 +1681,26 @@ void ASTVisitor::OutputRecordDecl(clang::RecordDecl const* d,
{
const char* tag;
switch (d->getTagKind()) {
- case clang::TTK_Class: tag = "Class"; break;
- case clang::TTK_Union: tag = "Union"; break;
- case clang::TTK_Struct: tag = "Struct"; break;
- case clang::TTK_Interface: return;
- case clang::TTK_Enum: return;
+ case clang::TTK_Class:
+ tag = "Class";
+ break;
+ case clang::TTK_Union:
+ tag = "Union";
+ break;
+ case clang::TTK_Struct:
+ tag = "Struct";
+ break;
+ case clang::TTK_Interface:
+ return;
+ case clang::TTK_Enum:
+ return;
}
clang::CXXRecordDecl const* dx = clang::dyn_cast<clang::CXXRecordDecl>(d);
bool doBases = false;
this->OS << " <" << tag;
this->PrintIdAttribute(dn);
- if(!d->isAnonymousStructOrUnion()) {
+ if (!d->isAnonymousStructOrUnion()) {
std::string s;
llvm::raw_string_ostream rso(s);
d->getNameForDiagnostic(rso, this->PrintingPolicy, false);
@@ -1612,24 +1708,23 @@ void ASTVisitor::OutputRecordDecl(clang::RecordDecl const* d,
}
clang::AccessSpecifier access = clang::AS_none;
if (clang::ClassTemplateSpecializationDecl const* dxts =
- clang::dyn_cast<clang::ClassTemplateSpecializationDecl>(d)) {
+ clang::dyn_cast<clang::ClassTemplateSpecializationDecl>(d)) {
// This is a template instantiation so get the access of the original
// template. Access of the instantiation itself has no meaning.
- if (clang::ClassTemplateDecl const* dxt =
- dxts->getSpecializedTemplate()) {
+ if (clang::ClassTemplateDecl const* dxt = dxts->getSpecializedTemplate()) {
access = dxt->getAccess();
}
}
this->PrintContextAttribute(d, access);
this->PrintLocationAttribute(d);
- if(d->getDefinition()) {
- if(dx && dx->isAbstract()) {
+ if (d->getDefinition()) {
+ if (dx && dx->isAbstract()) {
this->OS << " abstract=\"1\"";
}
if (dn->Complete && !d->isInvalidDecl()) {
this->PrintMembersAttribute(d);
doBases = dx && dx->getNumBases();
- if(doBases) {
+ if (doBases) {
this->PrintBasesAttribute(dx);
}
this->PrintBefriendingAttribute(dx);
@@ -1639,21 +1734,22 @@ void ASTVisitor::OutputRecordDecl(clang::RecordDecl const* d,
}
this->PrintABIAttributes(d);
this->PrintAttributesAttribute(d);
- if(doBases) {
+ if (doBases) {
this->OS << ">\n";
clang::ASTRecordLayout const& layout = this->CTX.getASTRecordLayout(dx);
- for(clang::CXXRecordDecl::base_class_const_iterator i = dx->bases_begin(),
- e = dx->bases_end(); i != e; ++i) {
+ for (clang::CXXRecordDecl::base_class_const_iterator i = dx->bases_begin(),
+ e = dx->bases_end();
+ i != e; ++i) {
clang::QualType bt = i->getType().getCanonicalType();
clang::CXXRecordDecl const* bd = clang::dyn_cast<clang::CXXRecordDecl>(
bt->getAs<clang::RecordType>()->getDecl());
this->OS << " <Base";
this->PrintTypeAttribute(bt, true);
this->PrintAccessAttribute(i->getAccessSpecifier());
- this->OS << " virtual=\"" << (i->isVirtual()? 1 : 0) << "\"";
+ this->OS << " virtual=\"" << (i->isVirtual() ? 1 : 0) << "\"";
if (bd && !i->isVirtual()) {
- this->OS << " offset=\"" <<
- layout.getBaseClassOffset(bd).getQuantity() << "\"";
+ this->OS << " offset=\"" << layout.getBaseClassOffset(bd).getQuantity()
+ << "\"";
}
this->OS << "/>\n";
}
@@ -1666,7 +1762,7 @@ void ASTVisitor::OutputRecordDecl(clang::RecordDecl const* d,
void ASTVisitor::OutputCXXRecordDecl(clang::CXXRecordDecl const* d,
DumpNode const* dn)
{
- if(d->getDescribedClassTemplate()) {
+ if (d->getDescribedClassTemplate()) {
// We do not implement class template output yet.
this->ASTVisitorBase::OutputCXXRecordDecl(d, dn);
return;
@@ -1713,8 +1809,8 @@ void ASTVisitor::OutputEnumDecl(clang::EnumDecl const* d, DumpNode const* dn)
this->OS << " <Enumeration";
this->PrintIdAttribute(dn);
std::string name = d->getName().str();
- if(name.empty()) {
- if(clang::TypedefNameDecl const* td = d->getTypedefNameForAnonDecl()) {
+ if (name.empty()) {
+ if (clang::TypedefNameDecl const* td = d->getTypedefNameForAnonDecl()) {
name = td->getName().str();
}
}
@@ -1724,10 +1820,10 @@ void ASTVisitor::OutputEnumDecl(clang::EnumDecl const* d, DumpNode const* dn)
this->PrintAttributesAttribute(d);
clang::EnumDecl::enumerator_iterator enum_begin = d->enumerator_begin();
clang::EnumDecl::enumerator_iterator enum_end = d->enumerator_end();
- if(enum_begin != enum_end) {
+ if (enum_begin != enum_end) {
this->OS << ">\n";
- for(clang::EnumDecl::enumerator_iterator i = enum_begin;
- i != enum_end; ++i) {
+ for (clang::EnumDecl::enumerator_iterator i = enum_begin; i != enum_end;
+ ++i) {
clang::EnumConstantDecl const* ecd = *i;
this->OS << " <EnumValue";
this->PrintNameAttribute(ecd->getName());
@@ -1747,14 +1843,14 @@ void ASTVisitor::OutputFieldDecl(clang::FieldDecl const* d, DumpNode const* dn)
this->PrintIdAttribute(dn);
this->PrintNameAttribute(d->getName().str());
this->PrintTypeAttribute(d->getType(), dn->Complete);
- if(d->isBitField()) {
+ if (d->isBitField()) {
unsigned bits = d->getBitWidthValue(this->CTX);
this->OS << " bits=\"" << bits << "\"";
}
this->PrintContextAttribute(d);
this->PrintLocationAttribute(d);
this->PrintOffsetAttribute(this->CTX.getFieldOffset(d));
- if(d->isMutable()) {
+ if (d->isMutable()) {
this->OS << " mutable=\"1\"";
}
this->PrintAttributesAttribute(d);
@@ -1768,7 +1864,7 @@ void ASTVisitor::OutputVarDecl(clang::VarDecl const* d, DumpNode const* dn)
this->PrintIdAttribute(dn);
this->PrintNameAttribute(d->getName().str());
this->PrintTypeAttribute(d->getType(), dn->Complete);
- if(clang::Expr const* init = d->getInit()) {
+ if (clang::Expr const* init = d->getInit()) {
this->OS << " init=\"";
std::string s;
llvm::raw_string_ostream rso(s);
@@ -1779,10 +1875,10 @@ void ASTVisitor::OutputVarDecl(clang::VarDecl const* d, DumpNode const* dn)
}
this->PrintContextAttribute(d);
this->PrintLocationAttribute(d);
- if(d->getStorageClass() == clang::SC_Static) {
+ if (d->getStorageClass() == clang::SC_Static) {
this->OS << " static=\"1\"";
}
- if(d->getStorageClass() == clang::SC_Extern) {
+ if (d->getStorageClass() == clang::SC_Extern) {
this->OS << " extern=\"1\"";
}
this->PrintMangledAttribute(d);
@@ -1794,18 +1890,19 @@ void ASTVisitor::OutputVarDecl(clang::VarDecl const* d, DumpNode const* dn)
void ASTVisitor::OutputFunctionDecl(clang::FunctionDecl const* d,
DumpNode const* dn)
{
- if(d->getDescribedFunctionTemplate()) {
+ if (d->getDescribedFunctionTemplate()) {
// We do not implement function template output yet.
this->ASTVisitorBase::OutputFunctionDecl(d, dn);
return;
}
unsigned int flags = FH_Returns;
- if(d->getStorageClass() == clang::SC_Static) {
+ if (d->getStorageClass() == clang::SC_Static) {
flags |= FH_Static;
}
- if(d->isOverloadedOperator()) {
- this->OutputFunctionHelper(d, dn, "OperatorFunction",
+ if (d->isOverloadedOperator()) {
+ this->OutputFunctionHelper(
+ d, dn, "OperatorFunction",
clang::getOperatorSpelling(d->getOverloadedOperator()), flags);
} else if (clang::IdentifierInfo const* ii = d->getIdentifier()) {
this->OutputFunctionHelper(d, dn, "Function", ii->getName().str(), flags);
@@ -1817,27 +1914,28 @@ void ASTVisitor::OutputFunctionDecl(clang::FunctionDecl const* d,
void ASTVisitor::OutputCXXMethodDecl(clang::CXXMethodDecl const* d,
DumpNode const* dn)
{
- if(d->getDescribedFunctionTemplate()) {
+ if (d->getDescribedFunctionTemplate()) {
// We do not implement function template output yet.
this->ASTVisitorBase::OutputCXXMethodDecl(d, dn);
return;
}
unsigned int flags = FH_Returns;
- if(d->isStatic()) {
+ if (d->isStatic()) {
flags |= FH_Static;
}
- if(d->isConst()) {
+ if (d->isConst()) {
flags |= FH_Const;
}
- if(d->isVirtual()) {
+ if (d->isVirtual()) {
flags |= FH_Virtual;
}
- if(d->isPure()) {
+ if (d->isPure()) {
flags |= FH_Pure;
}
- if(d->isOverloadedOperator()) {
- this->OutputFunctionHelper(d, dn, "OperatorMethod",
+ if (d->isOverloadedOperator()) {
+ this->OutputFunctionHelper(
+ d, dn, "OperatorMethod",
clang::getOperatorSpelling(d->getOverloadedOperator()), flags);
} else if (clang::IdentifierInfo const* ii = d->getIdentifier()) {
this->OutputFunctionHelper(d, dn, "Method", ii->getName().str(), flags);
@@ -1849,20 +1947,20 @@ void ASTVisitor::OutputCXXMethodDecl(clang::CXXMethodDecl const* d,
void ASTVisitor::OutputCXXConversionDecl(clang::CXXConversionDecl const* d,
DumpNode const* dn)
{
- if(d->getDescribedFunctionTemplate()) {
+ if (d->getDescribedFunctionTemplate()) {
// We do not implement function template output yet.
this->ASTVisitorBase::OutputCXXConversionDecl(d, dn);
return;
}
unsigned int flags = FH_Returns;
- if(d->isConst()) {
+ if (d->isConst()) {
flags |= FH_Const;
}
- if(d->isVirtual()) {
+ if (d->isVirtual()) {
flags |= FH_Virtual;
}
- if(d->isPure()) {
+ if (d->isPure()) {
flags |= FH_Pure;
}
this->OutputFunctionHelper(d, dn, "Converter", "", flags);
@@ -1871,38 +1969,38 @@ void ASTVisitor::OutputCXXConversionDecl(clang::CXXConversionDecl const* d,
void ASTVisitor::OutputCXXConstructorDecl(clang::CXXConstructorDecl const* d,
DumpNode const* dn)
{
- if(d->getDescribedFunctionTemplate()) {
+ if (d->getDescribedFunctionTemplate()) {
// We do not implement function template output yet.
this->ASTVisitorBase::OutputCXXConstructorDecl(d, dn);
return;
}
unsigned int flags = 0;
- if(d->isExplicit()) {
+ if (d->isExplicit()) {
flags |= FH_Explicit;
}
- this->OutputFunctionHelper(d, dn, "Constructor",
- this->GetContextName(d), flags);
+ this->OutputFunctionHelper(d, dn, "Constructor", this->GetContextName(d),
+ flags);
}
void ASTVisitor::OutputCXXDestructorDecl(clang::CXXDestructorDecl const* d,
DumpNode const* dn)
{
- if(d->getDescribedFunctionTemplate()) {
+ if (d->getDescribedFunctionTemplate()) {
// We do not implement function template output yet.
this->ASTVisitorBase::OutputCXXDestructorDecl(d, dn);
return;
}
unsigned int flags = 0;
- if(d->isVirtual()) {
+ if (d->isVirtual()) {
flags |= FH_Virtual;
}
- if(d->isPure()) {
+ if (d->isPure()) {
flags |= FH_Pure;
}
- this->OutputFunctionHelper(d, dn, "Destructor",
- this->GetContextName(d), flags);
+ this->OutputFunctionHelper(d, dn, "Destructor", this->GetContextName(d),
+ flags);
}
void ASTVisitor::OutputBuiltinType(clang::BuiltinType const* t,
@@ -1914,13 +2012,27 @@ void ASTVisitor::OutputBuiltinType(clang::BuiltinType const* t,
// gccxml used different name variants than Clang for some types
std::string name;
switch (t->getKind()) {
- case clang::BuiltinType::Short: name = "short int"; break;
- case clang::BuiltinType::UShort: name = "short unsigned int"; break;
- case clang::BuiltinType::Long: name = "long int"; break;
- case clang::BuiltinType::ULong: name = "long unsigned int"; break;
- case clang::BuiltinType::LongLong: name = "long long int"; break;
- case clang::BuiltinType::ULongLong: name = "long long unsigned int"; break;
- default: name = t->getName(this->PrintingPolicy).str(); break;
+ case clang::BuiltinType::Short:
+ name = "short int";
+ break;
+ case clang::BuiltinType::UShort:
+ name = "short unsigned int";
+ break;
+ case clang::BuiltinType::Long:
+ name = "long int";
+ break;
+ case clang::BuiltinType::ULong:
+ name = "long unsigned int";
+ break;
+ case clang::BuiltinType::LongLong:
+ name = "long long int";
+ break;
+ case clang::BuiltinType::ULongLong:
+ name = "long long unsigned int";
+ break;
+ default:
+ name = t->getName(this->PrintingPolicy).str();
+ break;
};
this->PrintNameAttribute(name);
this->PrintABIAttributes(this->CTX.getTypeInfo(t));
@@ -1933,7 +2045,7 @@ void ASTVisitor::OutputConstantArrayType(clang::ConstantArrayType const* t,
{
this->OS << " <ArrayType";
this->PrintIdAttribute(dn);
- this->OS << " min=\"0\" max=\"" << (t->getSize()-1) << "\"";
+ this->OS << " min=\"0\" max=\"" << (t->getSize() - 1) << "\"";
this->PrintTypeAttribute(t->getElementType(), dn->Complete);
this->OS << "/>\n";
}
@@ -1966,7 +2078,7 @@ void ASTVisitor::OutputLValueReferenceType(clang::LValueReferenceType const* t,
void ASTVisitor::OutputMemberPointerType(clang::MemberPointerType const* t,
DumpNode const* dn)
{
- if(t->isMemberDataPointerType()) {
+ if (t->isMemberDataPointerType()) {
this->OutputOffsetType(t->getPointeeType(), t->getClass(), dn);
} else {
this->OS << " <PointerType";
@@ -2011,15 +2123,15 @@ void ASTVisitor::LookupStart(clang::DeclContext const* dc,
clang::IdentifierTable& ids = CI.getPreprocessor().getIdentifierTable();
auto const& result = dc->lookup(clang::DeclarationName(&ids.get(cur)));
- if(pos == name.npos) {
- for (clang::NamedDecl const* n: result) {
+ if (pos == name.npos) {
+ for (clang::NamedDecl const* n : result) {
this->AddStartDecl(n);
}
} else {
- std::string rest = name.substr(pos+2);
- for (clang::NamedDecl const* n: result) {
+ std::string rest = name.substr(pos + 2);
+ for (clang::NamedDecl const* n : result) {
if (clang::DeclContext const* idc =
- clang::dyn_cast<clang::DeclContext const>(n)) {
+ clang::dyn_cast<clang::DeclContext const>(n)) {
this->LookupStart(idc, rest);
}
}
@@ -2033,11 +2145,12 @@ void ASTVisitor::LookupStart(clang::DeclContext const* dc,
void ASTVisitor::HandleTranslationUnit(clang::TranslationUnitDecl const* tu)
{
// Add the starting nodes for the dump.
- if(!this->Opts.StartNames.empty()) {
+ if (!this->Opts.StartNames.empty()) {
// Use the specified starting locations.
- for(std::vector<std::string>::const_iterator
- i = this->Opts.StartNames.begin(), e = this->Opts.StartNames.end();
- i != e; ++i) {
+ for (std::vector<std::string>::const_iterator
+ i = this->Opts.StartNames.begin(),
+ e = this->Opts.StartNames.end();
+ i != e; ++i) {
this->LookupStart(tu, *i);
}
} else {
@@ -2074,10 +2187,8 @@ void ASTVisitor::HandleTranslationUnit(clang::TranslationUnitDecl const* tu)
/* clang-format on */
}
-void outputXML(clang::CompilerInstance& ci,
- clang::ASTContext& ctx,
- llvm::raw_ostream& os,
- Options const& opts)
+void outputXML(clang::CompilerInstance& ci, clang::ASTContext& ctx,
+ llvm::raw_ostream& os, Options const& opts)
{
ASTVisitor v(ci, ctx, os, opts);
v.HandleTranslationUnit(ctx.getTranslationUnitDecl());
diff --git a/src/Output.h b/src/Output.h
index 9df6391..db1982b 100644
--- a/src/Output.h
+++ b/src/Output.h
@@ -19,20 +19,18 @@
#include <cxsys/Configure.h>
namespace llvm {
- class raw_ostream;
+class raw_ostream;
}
namespace clang {
- class CompilerInstance;
- class ASTContext;
+class CompilerInstance;
+class ASTContext;
}
struct Options;
/// outputXML - Print a gccxml-compatible AST dump.
-void outputXML(clang::CompilerInstance& ci,
- clang::ASTContext& ctx,
- llvm::raw_ostream& os,
- Options const& opts);
+void outputXML(clang::CompilerInstance& ci, clang::ASTContext& ctx,
+ llvm::raw_ostream& os, Options const& opts);
#endif // CASTXML_OUTPUT_H
diff --git a/src/RunClang.cxx b/src/RunClang.cxx
index 1bc62dd..a1d67cf 100644
--- a/src/RunClang.cxx
+++ b/src/RunClang.cxx
@@ -50,12 +50,12 @@
#include <memory>
#include <queue>
-#if LLVM_VERSION_MAJOR > 3 \
- || LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
-# define CASTXML_OWNS_OSTREAM
+#if LLVM_VERSION_MAJOR > 3 || \
+ LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9
+#define CASTXML_OWNS_OSTREAM
#endif
-class ASTConsumer: public clang::ASTConsumer
+class ASTConsumer : public clang::ASTConsumer
{
clang::CompilerInstance& CI;
#ifdef CASTXML_OWNS_OSTREAM
@@ -63,47 +63,63 @@ class ASTConsumer: public clang::ASTConsumer
#endif
llvm::raw_ostream& OS;
Options const& Opts;
- struct Class {
+ struct Class
+ {
clang::CXXRecordDecl* RD;
int Depth;
- Class(clang::CXXRecordDecl* rd, int depth): RD(rd), Depth(depth) {}
+ Class(clang::CXXRecordDecl* rd, int depth)
+ : RD(rd)
+ , Depth(depth)
+ {
+ }
};
std::queue<Class> Classes;
int ClassImplicitMemberDepth = 0;
+
public:
#ifdef CASTXML_OWNS_OSTREAM
ASTConsumer(clang::CompilerInstance& ci,
- std::unique_ptr<llvm::raw_ostream> os, Options const& opts):
- CI(ci), OwnOS(std::move(os)), OS(*OwnOS), Opts(opts) {}
+ std::unique_ptr<llvm::raw_ostream> os, Options const& opts)
+ : CI(ci)
+ , OwnOS(std::move(os))
+ , OS(*OwnOS)
+ , Opts(opts)
+ {
+ }
#else
ASTConsumer(clang::CompilerInstance& ci, llvm::raw_ostream& os,
- Options const& opts):
- CI(ci), OS(os), Opts(opts) {}
+ Options const& opts)
+ : CI(ci)
+ , OS(os)
+ , Opts(opts)
+ {
+ }
#endif
- void AddImplicitMembers(Class const& c) {
+ void AddImplicitMembers(Class const& c)
+ {
clang::CXXRecordDecl* rd = c.RD;
this->ClassImplicitMemberDepth = c.Depth + 1;
clang::Sema& sema = this->CI.getSema();
sema.ForceDeclarationOfImplicitMembers(rd);
- for(clang::DeclContext::decl_iterator i = rd->decls_begin(),
- e = rd->decls_end(); i != e; ++i) {
+ for (clang::DeclContext::decl_iterator i = rd->decls_begin(),
+ e = rd->decls_end();
+ i != e; ++i) {
clang::CXXMethodDecl* m = clang::dyn_cast<clang::CXXMethodDecl>(*i);
- if(m && !m->isDeleted() && !m->isInvalidDecl()) {
+ if (m && !m->isDeleted() && !m->isInvalidDecl()) {
bool mark = false;
clang::CXXConstructorDecl* c =
- clang::dyn_cast<clang::CXXConstructorDecl>(m);
+ clang::dyn_cast<clang::CXXConstructorDecl>(m);
if (c) {
- mark = (c->isDefaultConstructor() ||
- c->isCopyConstructor() ||
+ mark = (c->isDefaultConstructor() || c->isCopyConstructor() ||
c->isMoveConstructor());
} else if (clang::dyn_cast<clang::CXXDestructorDecl>(m)) {
mark = true;
} else {
- mark = (m->isCopyAssignmentOperator() ||
- m->isMoveAssignmentOperator());
+ mark =
+ (m->isCopyAssignmentOperator() || m->isMoveAssignmentOperator());
}
if (mark) {
/* Ensure the member is defined. */
@@ -122,9 +138,10 @@ public:
}
}
- void HandleTagDeclDefinition(clang::TagDecl* d) {
- if(clang::CXXRecordDecl* rd = clang::dyn_cast<clang::CXXRecordDecl>(d)) {
- if(!rd->isDependentContext()) {
+ void HandleTagDeclDefinition(clang::TagDecl* d)
+ {
+ if (clang::CXXRecordDecl* rd = clang::dyn_cast<clang::CXXRecordDecl>(d)) {
+ if (!rd->isDependentContext()) {
if (this->ClassImplicitMemberDepth < 16) {
this->Classes.push(Class(rd, this->ClassImplicitMemberDepth));
}
@@ -132,7 +149,8 @@ public:
}
}
- void HandleTranslationUnit(clang::ASTContext& ctx) {
+ void HandleTranslationUnit(clang::ASTContext& ctx)
+ {
clang::Sema& sema = this->CI.getSema();
// Perform instantiations needed by the original translation unit.
@@ -159,13 +177,17 @@ public:
};
template <class T>
-class CastXMLPredefines: public T
+class CastXMLPredefines : public T
{
protected:
Options const& Opts;
- CastXMLPredefines(Options const& opts): Opts(opts) {}
- std::string UpdatePredefines(clang::CompilerInstance const& CI) {
+ CastXMLPredefines(Options const& opts)
+ : Opts(opts)
+ {
+ }
+ std::string UpdatePredefines(clang::CompilerInstance const& CI)
+ {
std::string const& predefines = CI.getPreprocessor().getPredefines();
// Identify the portion of the predefines string corresponding to
@@ -175,7 +197,7 @@ protected:
std::string::size_type start = predefines.find(predef_start);
std::string::size_type end = std::string::npos;
if (start != std::string::npos) {
- start += sizeof(predef_start)-1;
+ start += sizeof(predef_start) - 1;
end = predefines.find(predef_end, start);
if (end == std::string::npos) {
end = predefines.size();
@@ -193,15 +215,19 @@ protected:
builtins +=
#define STR(x) STR_(x)
#define STR_(x) #x
- "#define __castxml_clang_major__ " STR(CLANG_VERSION_MAJOR) "\n"
- "#define __castxml_clang_minor__ " STR(CLANG_VERSION_MINOR) "\n"
- "#define __castxml_clang_patchlevel__ "
+ "#define __castxml_clang_major__ " STR(
+ CLANG_VERSION_MAJOR) "\n"
+ "#define __castxml_clang_minor__ " STR(
+ CLANG_VERSION_MINOR) "\n"
+ "#define "
+ "__castxml_clang_"
+ "patchlevel__ "
#ifdef CLANG_VERSION_PATCHLEVEL
STR(CLANG_VERSION_PATCHLEVEL)
#else
- "0"
+ "0"
#endif
- "\n"
+ "\n"
#undef STR
#undef STR_
;
@@ -215,9 +241,8 @@ protected:
// Clang does not support this builtin, so fake it to tolerate
// uses in function bodies while parsing.
builtins += "\n"
- "#define __builtin_va_arg_pack() 0\n"
- "#define __builtin_va_arg_pack_len() 1\n"
- ;
+ "#define __builtin_va_arg_pack() 0\n"
+ "#define __builtin_va_arg_pack_len() 1\n";
}
// Provide __float128 if simulating the actual GNU compiler.
@@ -226,11 +251,10 @@ protected:
// diagnostics when it is used in some contexts. Provide our own
// approximation of the builtin instead.
builtins += "\n"
- "typedef struct __castxml__float128_s { "
- " char x[16] __attribute__((aligned(16))); "
- "} __castxml__float128;\n"
- "#define __float128 __castxml__float128\n"
- ;
+ "typedef struct __castxml__float128_s { "
+ " char x[16] __attribute__((aligned(16))); "
+ "} __castxml__float128;\n"
+ "#define __float128 __castxml__float128\n";
}
// Provide __is_assignable builtin if simulating MSVC.
@@ -238,7 +262,8 @@ protected:
// we can skip this when built against such a Clang.
if (CI.getLangOpts().MSCompatibilityVersion >= 190000000 &&
CI.getLangOpts().CPlusPlus11) {
- builtins += "\n"
+ builtins +=
+ "\n"
"template <typename T> T&& __castxml__declval() noexcept;\n"
"template <typename To, typename Fr, typename =\n"
" decltype(__castxml__declval<To>() = __castxml__declval<Fr>())>\n"
@@ -247,16 +272,15 @@ protected:
" static char (&__castxml__is_assignable_check(...))[2];\n"
"#define __is_assignable(_To,_Fr) \\\n"
" (sizeof(__castxml__is_assignable_check<_To,_Fr>(0)) == \\\n"
- " sizeof(char(&)[1]))\n"
- ;
+ " sizeof(char(&)[1]))\n";
}
-#if LLVM_VERSION_MAJOR < 3 \
- || LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 8
+#if LLVM_VERSION_MAJOR < 3 || LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 8
// Clang 3.8 and above provide a __make_integer_seq builtin needed
// in C++14 mode. Provide it ourselves for older Clang versions.
if (CI.getLangOpts().CPlusPlus14) {
- builtins += "\n"
+ builtins +=
+ "\n"
"template <typename _T, _T> struct __castxml__integral_constant;\n"
"template <template<typename _U, _U...> class _S,\n"
" typename, typename, bool>\n"
@@ -282,25 +306,24 @@ protected:
" __castxml__make_integer_seq_impl<_S,\n"
" __castxml__integral_constant<_T, _Sz>,\n"
" _S<_T>, (_Sz>=0)>::type;\n"
- "#define __make_integer_seq __castxml__make_integer_seq\n"
- ;
+ "#define __make_integer_seq __castxml__make_integer_seq\n";
}
#endif
// Prevent glibc use of a GNU extension not implemented by Clang.
if (this->NeedNoMathInlines(this->Opts.Predefines)) {
builtins += "\n"
- "#define __NO_MATH_INLINES 1\n"
- ;
+ "#define __NO_MATH_INLINES 1\n";
}
} else {
- builtins += predefines.substr(start, end-start);
+ builtins += predefines.substr(start, end - start);
}
return predefines.substr(0, start) + builtins + predefines.substr(end);
}
- bool IsActualGNU(std::string const& pd) const {
+ bool IsActualGNU(std::string const& pd) const
+ {
return (pd.find("#define __GNUC__ ") != pd.npos &&
pd.find("#define __clang__ ") == pd.npos &&
pd.find("#define __INTEL_COMPILER ") == pd.npos &&
@@ -308,18 +331,21 @@ protected:
pd.find("#define __PGI ") == pd.npos);
}
- bool NeedBuiltinVarArgPack(std::string const& pd) {
+ bool NeedBuiltinVarArgPack(std::string const& pd)
+ {
return this->IsActualGNU(pd);
}
- bool NeedFloat128(std::string const& pd) const {
+ bool NeedFloat128(std::string const& pd) const
+ {
return (this->IsActualGNU(pd) &&
(pd.find("#define __i386__ ") != pd.npos ||
pd.find("#define __x86_64__ ") != pd.npos ||
pd.find("#define __ia64__ ") != pd.npos));
}
- bool NeedNoMathInlines(std::string const& pd) const {
+ bool NeedNoMathInlines(std::string const& pd) const
+ {
return (this->IsActualGNU(pd) &&
(pd.find("#define __i386__ ") != pd.npos &&
pd.find("#define __OPTIMIZE__ ") != pd.npos &&
@@ -327,7 +353,8 @@ protected:
}
bool BeginSourceFileAction(clang::CompilerInstance& CI,
- llvm::StringRef /*Filename*/) {
+ llvm::StringRef /*Filename*/)
+ {
CI.getPreprocessor().setPredefines(this->UpdatePredefines(CI));
// Tell Clang not to tear down the parser at EOF.
@@ -337,54 +364,59 @@ protected:
}
};
-class CastXMLPrintPreprocessedAction:
- public CastXMLPredefines<clang::PrintPreprocessedAction>
+class CastXMLPrintPreprocessedAction
+ : public CastXMLPredefines<clang::PrintPreprocessedAction>
{
public:
- CastXMLPrintPreprocessedAction(Options const& opts):
- CastXMLPredefines(opts) {}
+ CastXMLPrintPreprocessedAction(Options const& opts)
+ : CastXMLPredefines(opts)
+ {
+ }
};
-class CastXMLSyntaxOnlyAction:
- public CastXMLPredefines<clang::SyntaxOnlyAction>
+class CastXMLSyntaxOnlyAction
+ : public CastXMLPredefines<clang::SyntaxOnlyAction>
{
- std::unique_ptr<clang::ASTConsumer>
- CreateASTConsumer(clang::CompilerInstance &CI,
- llvm::StringRef InFile) override {
+ std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(
+ clang::CompilerInstance& CI, llvm::StringRef InFile) override
+ {
using llvm::sys::path::filename;
- if(!this->Opts.GccXml) {
+ if (!this->Opts.GccXml) {
return clang::SyntaxOnlyAction::CreateASTConsumer(CI, InFile);
#ifdef CASTXML_OWNS_OSTREAM
- } else if(std::unique_ptr<llvm::raw_ostream> OS =
- CI.createDefaultOutputFile(false, filename(InFile), "xml")) {
+ } else if (std::unique_ptr<llvm::raw_ostream> OS =
+ CI.createDefaultOutputFile(false, filename(InFile), "xml")) {
return llvm::make_unique<ASTConsumer>(CI, std::move(OS), this->Opts);
#else
- } else if(llvm::raw_ostream* OS =
- CI.createDefaultOutputFile(false, filename(InFile), "xml")) {
+ } else if (llvm::raw_ostream* OS =
+ CI.createDefaultOutputFile(false, filename(InFile), "xml")) {
return llvm::make_unique<ASTConsumer>(CI, *OS, this->Opts);
#endif
} else {
return nullptr;
}
}
+
public:
- CastXMLSyntaxOnlyAction(Options const& opts):
- CastXMLPredefines(opts) {}
+ CastXMLSyntaxOnlyAction(Options const& opts)
+ : CastXMLPredefines(opts)
+ {
+ }
};
-static clang::FrontendAction*
-CreateFrontendAction(clang::CompilerInstance* CI, Options const& opts)
+static clang::FrontendAction* CreateFrontendAction(clang::CompilerInstance* CI,
+ Options const& opts)
{
clang::frontend::ActionKind action =
CI->getInvocation().getFrontendOpts().ProgramAction;
- switch(action) {
- case clang::frontend::PrintPreprocessedInput:
- return new CastXMLPrintPreprocessedAction(opts);
- case clang::frontend::ParseSyntaxOnly:
- return new CastXMLSyntaxOnlyAction(opts);
- default:
- std::cerr << "error: unsupported action: " << int(action) << "\n";
- return nullptr;
+ switch (action) {
+ case clang::frontend::PrintPreprocessedInput:
+ return new CastXMLPrintPreprocessedAction(opts);
+ case clang::frontend::ParseSyntaxOnly:
+ return new CastXMLSyntaxOnlyAction(opts);
+ default:
+ std::cerr << "error: unsupported action: " << int(action) << "\n";
+ return nullptr;
}
}
@@ -392,28 +424,28 @@ static bool runClangCI(clang::CompilerInstance* CI, Options const& opts)
{
// Create a diagnostics engine for this compiler instance.
CI->createDiagnostics();
- if(!CI->hasDiagnostics()) {
+ if (!CI->hasDiagnostics()) {
return false;
}
// Set frontend options we captured directly.
CI->getFrontendOpts().OutputFile = opts.OutputFile;
- if(opts.GccXml) {
-# define MSG(x) "error: '--castxml-gccxml' does not work with " x "\n"
- if(CI->getLangOpts().ObjC1 || CI->getLangOpts().ObjC2) {
+ if (opts.GccXml) {
+#define MSG(x) "error: '--castxml-gccxml' does not work with " x "\n"
+ if (CI->getLangOpts().ObjC1 || CI->getLangOpts().ObjC2) {
std::cerr << MSG("Objective C");
return false;
}
-# undef MSG
+#undef MSG
}
// Construct our Clang front-end action. This dispatches
// handling of each input file with an action based on the
// flags provided (e.g. -E to preprocess-only).
- std::unique_ptr<clang::FrontendAction>
- action(CreateFrontendAction(CI, opts));
- if(action) {
+ std::unique_ptr<clang::FrontendAction> action(
+ CreateFrontendAction(CI, opts));
+ if (action) {
return CI->ExecuteAction(*action);
} else {
return false;
@@ -423,34 +455,32 @@ static bool runClangCI(clang::CompilerInstance* CI, Options const& opts)
static llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine>
runClangCreateDiagnostics(const char* const* argBeg, const char* const* argEnd)
{
- llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions>
- diagOpts(new clang::DiagnosticOptions);
- llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs>
- diagID(new clang::DiagnosticIDs());
- std::unique_ptr<llvm::opt::OptTable>
- opts(clang::driver::createDriverOptTable());
+ llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diagOpts(
+ new clang::DiagnosticOptions);
+ llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagID(
+ new clang::DiagnosticIDs());
+ std::unique_ptr<llvm::opt::OptTable> opts(
+ clang::driver::createDriverOptTable());
unsigned missingArgIndex, missingArgCount;
-#if LLVM_VERSION_MAJOR > 3 \
- || LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
- llvm::opt::InputArgList
- args(opts->ParseArgs(llvm::makeArrayRef(argBeg, argEnd),
- missingArgIndex, missingArgCount));
+#if LLVM_VERSION_MAJOR > 3 || \
+ LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
+ llvm::opt::InputArgList args(opts->ParseArgs(
+ llvm::makeArrayRef(argBeg, argEnd), missingArgIndex, missingArgCount));
clang::ParseDiagnosticArgs(*diagOpts, args);
#else
- std::unique_ptr<llvm::opt::InputArgList>
- args(opts->ParseArgs(argBeg, argEnd, missingArgIndex, missingArgCount));
+ std::unique_ptr<llvm::opt::InputArgList> args(
+ opts->ParseArgs(argBeg, argEnd, missingArgIndex, missingArgCount));
clang::ParseDiagnosticArgs(*diagOpts, *args);
#endif
clang::TextDiagnosticPrinter* diagClient =
new clang::TextDiagnosticPrinter(llvm::errs(), &*diagOpts);
- llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine>
- diags(new clang::DiagnosticsEngine(diagID, &*diagOpts, diagClient));
+ llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine> diags(
+ new clang::DiagnosticsEngine(diagID, &*diagOpts, diagClient));
clang::ProcessWarningOptions(*diags, *diagOpts, /*ReportDiags=*/false);
return diags;
}
-static int runClangImpl(const char* const* argBeg,
- const char* const* argEnd,
+static int runClangImpl(const char* const* argBeg, const char* const* argEnd,
Options const& opts)
{
// Construct a diagnostics engine for use while processing driver options.
@@ -465,12 +495,12 @@ static int runClangImpl(const char* const* argBeg,
!llvm::sys::fs::is_directory(d.ResourceDir)) {
d.ResourceDir = getClangResourceDir();
}
- llvm::SmallVector<const char *, 16> cArgs;
+ llvm::SmallVector<const char*, 16> cArgs;
cArgs.push_back("<clang>");
cArgs.insert(cArgs.end(), argBeg, argEnd);
// Tell the driver not to generate any commands past syntax parsing.
- if(opts.PPOnly) {
+ if (opts.PPOnly) {
cArgs.push_back("-E");
} else {
cArgs.push_back("-fsyntax-only");
@@ -483,13 +513,13 @@ static int runClangImpl(const char* const* argBeg,
}
// For '-###' just print the jobs and exit early.
- if(c->getArgs().hasArg(clang::driver::options::OPT__HASH_HASH_HASH)) {
+ if (c->getArgs().hasArg(clang::driver::options::OPT__HASH_HASH_HASH)) {
c->getJobs().Print(llvm::errs(), "\n", true);
return 0;
}
// Reject '-o' with multiple inputs.
- if(!opts.OutputFile.empty() && c->getJobs().size() > 1) {
+ if (!opts.OutputFile.empty() && c->getJobs().size() > 1) {
diags->Report(clang::diag::err_drv_output_argument_with_multiple_files);
return 1;
}
@@ -497,17 +527,17 @@ static int runClangImpl(const char* const* argBeg,
// Run Clang for each compilation computed by the driver.
// This should be once per input source file.
bool result = true;
- for(auto const& job : c->getJobs()) {
+ for (auto const& job : c->getJobs()) {
clang::driver::Command const* cmd =
llvm::dyn_cast<clang::driver::Command>(&job);
- if(cmd && strcmp(cmd->getCreator().getName(), "clang") == 0) {
+ if (cmd && strcmp(cmd->getCreator().getName(), "clang") == 0) {
// Invoke Clang with this set of arguments.
- std::unique_ptr<clang::CompilerInstance>
- CI(new clang::CompilerInstance());
+ std::unique_ptr<clang::CompilerInstance> CI(
+ new clang::CompilerInstance());
const char* const* cmdArgBeg = cmd->getArguments().data();
const char* const* cmdArgEnd = cmdArgBeg + cmd->getArguments().size();
- if (clang::CompilerInvocation::CreateFromArgs
- (CI->getInvocation(), cmdArgBeg, cmdArgEnd, *diags)) {
+ if (clang::CompilerInvocation::CreateFromArgs(
+ CI->getInvocation(), cmdArgBeg, cmdArgEnd, *diags)) {
if (diags->hasErrorOccurred()) {
return 1;
}
@@ -521,25 +551,23 @@ static int runClangImpl(const char* const* argBeg,
llvm::raw_svector_ostream msg(buf);
job.Print(msg, "\n", true);
diags->Report(clang::diag::err_fe_expected_clang_command);
- diags->Report(clang::diag::err_fe_expected_compiler_job)
- << msg.str();
+ diags->Report(clang::diag::err_fe_expected_compiler_job) << msg.str();
result = false;
}
}
- return result? 0:1;
+ return result ? 0 : 1;
}
-int runClang(const char* const* argBeg,
- const char* const* argEnd,
+int runClang(const char* const* argBeg, const char* const* argEnd,
Options const& opts)
{
llvm::SmallVector<const char*, 32> args(argBeg, argEnd);
std::string fmsc_version = "-fmsc-version=";
std::string std_flag = "-std=";
- if(opts.HaveCC) {
+ if (opts.HaveCC) {
// Configure target to match that of given compiler.
- if(!opts.HaveTarget && !opts.Triple.empty()) {
+ if (!opts.HaveTarget && !opts.Triple.empty()) {
args.push_back("-target");
args.push_back(opts.Triple.c_str());
}
@@ -549,10 +577,11 @@ int runClang(const char* const* argBeg,
args.push_back("-nostdlibinc");
// Add header search paths detected from given compiler.
- for(std::vector<Options::Include>::const_iterator
- i = opts.Includes.begin(), e = opts.Includes.end();
- i != e; ++i) {
- if(i->Framework) {
+ for (std::vector<Options::Include>::const_iterator
+ i = opts.Includes.begin(),
+ e = opts.Includes.end();
+ i != e; ++i) {
+ if (i->Framework) {
args.push_back("-iframework");
} else {
args.push_back("-isystem");
@@ -565,18 +594,18 @@ int runClang(const char* const* argBeg,
// Configure language options to match given compiler.
std::string const& pd = opts.Predefines;
- if(pd.find("#define _MSC_EXTENSIONS ") != pd.npos) {
+ if (pd.find("#define _MSC_EXTENSIONS ") != pd.npos) {
args.push_back("-fms-extensions");
}
- if(const char* d = strstr(pd.c_str(), "#define _MSC_VER ")) {
+ if (const char* d = strstr(pd.c_str(), "#define _MSC_VER ")) {
args.push_back("-fms-compatibility");
// Extract the _MSC_VER value to give to -fmsc-version=.
d += 17;
- if(const char* e = strchr(d, '\n')) {
- if(*(e - 1) == '\r') {
+ if (const char* e = strchr(d, '\n')) {
+ if (*(e - 1) == '\r') {
--e;
}
- std::string const msc_ver_str(d, e-d);
+ std::string const msc_ver_str(d, e - d);
fmsc_version += msc_ver_str;
args.push_back(fmsc_version.c_str());
@@ -621,7 +650,7 @@ int runClang(const char* const* argBeg,
}
// Add the standard year.
- std::string const std_date_str(d, e-d);
+ std::string const std_date_str(d, e - d);
errno = 0;
long std_date = std::strtol(std_date_str.c_str(), nullptr, 10);
if (errno != 0) {
@@ -640,14 +669,14 @@ int runClang(const char* const* argBeg,
args.push_back(std_flag.c_str());
}
} else if (const char* d =
- strstr(pd.c_str(), "#define __STDC_VERSION__ ")) {
+ strstr(pd.c_str(), "#define __STDC_VERSION__ ")) {
// Extract the C standard level.
d += 25;
if (const char* e = strchr(d, '\n')) {
if (*(e - 1) == '\r') {
--e;
}
- std::string const std_date_str(d, e-d);
+ std::string const std_date_str(d, e - d);
errno = 0;
long std_date = std::strtol(std_date_str.c_str(), nullptr, 10);
if (errno != 0) {
diff --git a/src/RunClang.h b/src/RunClang.h
index 4918137..5fc6350 100644
--- a/src/RunClang.h
+++ b/src/RunClang.h
@@ -19,8 +19,7 @@
struct Options;
/// runClang - Run Clang with given user arguments and detected options.
-int runClang(const char* const* argBeg,
- const char* const* argEnd,
+int runClang(const char* const* argBeg, const char* const* argEnd,
Options const& opts);
#endif // CASTXML_RUNCLANG_H
diff --git a/src/Utils.cxx b/src/Utils.cxx
index 4977489..160e13c 100644
--- a/src/Utils.cxx
+++ b/src/Utils.cxx
@@ -18,10 +18,10 @@
#include "Version.h"
#include <cxsys/Process.h>
+#include <fstream>
#include <llvm/ADT/SmallString.h>
#include <llvm/Support/FileSystem.h>
#include <llvm/Support/Path.h>
-#include <fstream>
#include <vector>
static std::string castxmlResourceDir;
@@ -29,8 +29,8 @@ static std::string castxmlClangResourceDir;
static std::string GetMainExecutable(const char* argv0)
{
- return llvm::sys::fs::getMainExecutable
- (argv0, (void*)(intptr_t)GetMainExecutable);
+ return llvm::sys::fs::getMainExecutable(argv0,
+ (void*)(intptr_t)GetMainExecutable);
}
static bool tryBuildDir(std::string const& dir)
@@ -44,10 +44,8 @@ static bool tryBuildDir(std::string const& dir)
std::ifstream cl_fin(cl_dir_txt.c_str());
std::string src_dir;
std::string cl_dir;
- if (std::getline(src_fin, src_dir) &&
- llvm::sys::fs::is_directory(src_dir) &&
- std::getline(cl_fin, cl_dir) &&
- llvm::sys::fs::is_directory(cl_dir)) {
+ if (std::getline(src_fin, src_dir) && llvm::sys::fs::is_directory(src_dir) &&
+ std::getline(cl_fin, cl_dir) && llvm::sys::fs::is_directory(cl_dir)) {
castxmlResourceDir = src_dir + "/share/castxml";
castxmlClangResourceDir = cl_dir;
return true;
@@ -78,8 +76,7 @@ bool findResourceDir(const char* argv0, std::ostream& error)
llvm::sys::path::remove_filename(dir2);
// Build tree has
// <build>/bin[/<config>]/castxml
- if (!tryBuildDir(dir.str()) &&
- !tryBuildDir(dir2.str())) {
+ if (!tryBuildDir(dir.str()) && !tryBuildDir(dir2.str())) {
error << "Unable to locate resources for " << exe << "\n";
return false;
}
@@ -105,14 +102,12 @@ std::string getVersionString()
unsigned int getVersionValue()
{
- return (CASTXML_VERSION_MAJOR * 1000000 +
- CASTXML_VERSION_MINOR * 1000 +
- CASTXML_VERSION_PATCH * 1);
+ return (CASTXML_VERSION_MAJOR * 1000000 + CASTXML_VERSION_MINOR * 1000 +
+ CASTXML_VERSION_PATCH * 1);
}
-bool runCommand(int argc, const char* const* argv,
- int& ret, std::string& out, std::string& err,
- std::string& msg)
+bool runCommand(int argc, const char* const* argv, int& ret, std::string& out,
+ std::string& err, std::string& msg)
{
std::vector<const char*> cmd(argv, argv + argc);
cmd.push_back(0);
@@ -135,39 +130,39 @@ bool runCommand(int argc, const char* const* argv,
char* data;
int length;
int pipe;
- while((pipe = cxsysProcess_WaitForData(cp, &data, &length, 0)) > 0) {
- if(pipe == cxsysProcess_Pipe_STDOUT) {
- outBuf.insert(outBuf.end(), data, data+length);
- } else if(pipe == cxsysProcess_Pipe_STDERR) {
- errBuf.insert(errBuf.end(), data, data+length);
+ while ((pipe = cxsysProcess_WaitForData(cp, &data, &length, 0)) > 0) {
+ if (pipe == cxsysProcess_Pipe_STDOUT) {
+ outBuf.insert(outBuf.end(), data, data + length);
+ } else if (pipe == cxsysProcess_Pipe_STDERR) {
+ errBuf.insert(errBuf.end(), data, data + length);
}
}
cxsysProcess_WaitForExit(cp, 0);
- if(!outBuf.empty()) {
+ if (!outBuf.empty()) {
out.append(&*outBuf.begin(), outBuf.size());
}
- if(!errBuf.empty()) {
+ if (!errBuf.empty()) {
err.append(&*errBuf.begin(), errBuf.size());
}
bool result = true;
- switch(cxsysProcess_GetState(cp)) {
- case cxsysProcess_State_Exited:
- ret = cxsysProcess_GetExitValue(cp);
- break;
- case cxsysProcess_State_Exception:
- msg = cxsysProcess_GetExceptionString(cp);
- result = false;
- break;
- case cxsysProcess_State_Error:
- msg = cxsysProcess_GetErrorString(cp);
- result = false;
- break;
- default:
- msg = "Process terminated in unexpected state.\n";
- result = false;
- break;
+ switch (cxsysProcess_GetState(cp)) {
+ case cxsysProcess_State_Exited:
+ ret = cxsysProcess_GetExitValue(cp);
+ break;
+ case cxsysProcess_State_Exception:
+ msg = cxsysProcess_GetExceptionString(cp);
+ result = false;
+ break;
+ case cxsysProcess_State_Error:
+ msg = cxsysProcess_GetErrorString(cp);
+ result = false;
+ break;
+ default:
+ msg = "Process terminated in unexpected state.\n";
+ result = false;
+ break;
}
cxsysProcess_Delete(cp);
@@ -178,27 +173,34 @@ std::string encodeXML(std::string const& in, bool cdata)
{
std::string xml;
const char* last = in.c_str();
- for(const char* c = last; *c; ++c) {
- switch(*c) {
-# define XML(OUT) \
- xml.append(last, c - last); \
- last = c + 1; \
- xml.append(OUT)
- case '&': XML("&amp;"); break;
- case '<': XML("&lt;"); break;
- case '>': XML("&gt;"); break;
- case '\'':
- if(!cdata) {
- XML("&apos;");
- }
- break;
- case '"':
- if(!cdata) {
- XML("&quot;");
- }
- break;
- default: break;
-# undef XML
+ for (const char* c = last; *c; ++c) {
+ switch (*c) {
+#define XML(OUT) \
+ xml.append(last, c - last); \
+ last = c + 1; \
+ xml.append(OUT)
+ case '&':
+ XML("&amp;");
+ break;
+ case '<':
+ XML("&lt;");
+ break;
+ case '>':
+ XML("&gt;");
+ break;
+ case '\'':
+ if (!cdata) {
+ XML("&apos;");
+ }
+ break;
+ case '"':
+ if (!cdata) {
+ XML("&quot;");
+ }
+ break;
+ default:
+ break;
+#undef XML
}
}
xml.append(last);
@@ -206,7 +208,8 @@ std::string encodeXML(std::string const& in, bool cdata)
}
std::string stringReplace(std::string str, std::string const& in,
- std::string const& out) {
+ std::string const& out)
+{
std::string::size_type p = 0;
while ((p = str.find(in, p)) != std::string::npos) {
str.replace(p, in.size(), out);
@@ -216,7 +219,7 @@ std::string stringReplace(std::string str, std::string const& in,
}
#if defined(_WIN32)
-# include <windows.h>
+#include <windows.h>
#endif
void suppressInteractiveErrors()
diff --git a/src/Utils.h b/src/Utils.h
index 7103fa7..a29e96f 100644
--- a/src/Utils.h
+++ b/src/Utils.h
@@ -37,9 +37,8 @@ std::string getVersionString();
unsigned int getVersionValue();
/// runCommand - Run a given command line and capture the output.
-bool runCommand(int argc, const char* const* argv,
- int& ret, std::string& out, std::string& err,
- std::string& msg);
+bool runCommand(int argc, const char* const* argv, int& ret, std::string& out,
+ std::string& err, std::string& msg);
/// suppressInteractiveErrors - Disable Windows error dialog popups
void suppressInteractiveErrors();
diff --git a/src/castxml.cxx b/src/castxml.cxx
index 79232e1..485d939 100644
--- a/src/castxml.cxx
+++ b/src/castxml.cxx
@@ -29,20 +29,23 @@
#include "llvm/Support/raw_ostream.h"
#include <iostream>
-#include <sstream>
#include <set>
+#include <sstream>
+#include <string.h>
#include <system_error>
#include <vector>
-#include <string.h>
-#if LLVM_VERSION_MAJOR > 3 \
- || LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
-# include "llvm/Support/StringSaver.h"
+#if LLVM_VERSION_MAJOR > 3 || \
+ LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
+#include "llvm/Support/StringSaver.h"
#else
-class StringSaver: public llvm::cl::StringSaver {
+class StringSaver : public llvm::cl::StringSaver
+{
std::set<std::string> Strings;
+
public:
- const char* SaveString(const char* s) {
+ const char* SaveString(const char* s)
+ {
return this->Strings.insert(s).first->c_str();
}
};
@@ -59,18 +62,17 @@ int main(int argc_in, const char** argv_in)
llvm::SmallVector<const char*, 64> argv;
llvm::SpecificBumpPtrAllocator<char> argAlloc;
- if(std::error_code e =
- llvm::sys::Process::GetArgumentVector(
- argv, llvm::ArrayRef<const char*>(argv_in, argc_in), argAlloc)) {
+ if (std::error_code e = llvm::sys::Process::GetArgumentVector(
+ argv, llvm::ArrayRef<const char*>(argv_in, argc_in), argAlloc)) {
llvm::errs() << "error: could not get arguments: " << e.message() << "\n";
return 1;
- } else if(argv.empty()) {
+ } else if (argv.empty()) {
llvm::errs() << "error: no argv[0]?!\n";
return 1;
}
-#if LLVM_VERSION_MAJOR > 3 \
- || LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8
+#if LLVM_VERSION_MAJOR > 3 || \
+ LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8
llvm::BumpPtrAllocator argSaverAlloc;
llvm::StringSaver argSaver(argSaverAlloc);
#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 7
@@ -79,12 +81,12 @@ int main(int argc_in, const char** argv_in)
#else
StringSaver argSaver;
#endif
- llvm::cl::ExpandResponseFiles(
- argSaver, llvm::cl::TokenizeGNUCommandLine, argv);
+ llvm::cl::ExpandResponseFiles(argSaver, llvm::cl::TokenizeGNUCommandLine,
+ argv);
size_t const argc = argv.size();
- if(!findResourceDir(argv[0], std::cerr)) {
+ if (!findResourceDir(argv[0], std::cerr)) {
return 1;
}
@@ -126,13 +128,13 @@ int main(int argc_in, const char** argv_in)
/* clang-format on */
Options opts;
- llvm::SmallVector<const char *, 16> clang_args;
- llvm::SmallVector<const char *, 16> cc_args;
+ llvm::SmallVector<const char*, 16> clang_args;
+ llvm::SmallVector<const char*, 16> cc_args;
const char* cc_id = 0;
- for(size_t i=1; i < argc; ++i) {
- if(strcmp(argv[i], "--castxml-gccxml") == 0) {
- if(!opts.GccXml) {
+ for (size_t i = 1; i < argc; ++i) {
+ if (strcmp(argv[i], "--castxml-gccxml") == 0) {
+ if (!opts.GccXml) {
opts.GccXml = true;
} else {
/* clang-format off */
@@ -144,8 +146,8 @@ int main(int argc_in, const char** argv_in)
/* clang-format on */
return 1;
}
- } else if(strcmp(argv[i], "--castxml-start") == 0) {
- if((i+1) < argc) {
+ } else if (strcmp(argv[i], "--castxml-start") == 0) {
+ if ((i + 1) < argc) {
std::string item;
std::stringstream stream(argv[++i]);
while (std::getline(stream, item, ',')) {
@@ -162,14 +164,14 @@ int main(int argc_in, const char** argv_in)
/* clang-format on */
return 1;
}
- } else if(strncmp(argv[i], "--castxml-cc-", 13) == 0) {
- if(!cc_id) {
+ } else if (strncmp(argv[i], "--castxml-cc-", 13) == 0) {
+ if (!cc_id) {
cc_id = argv[i] + 13;
- if((i+1) >= argc) {
+ if ((i + 1) >= argc) {
continue;
}
++i;
- if(strncmp(argv[i], "-", 1) == 0) {
+ if (strncmp(argv[i], "-", 1) == 0) {
/* clang-format off */
std::cerr <<
"error: argument to '--castxml-cc-" << cc_id <<
@@ -180,10 +182,10 @@ int main(int argc_in, const char** argv_in)
/* clang-format on */
return 1;
}
- if(strcmp(argv[i], "(") == 0) {
+ if (strcmp(argv[i], "(") == 0) {
unsigned int depth = 1;
- for(++i; i < argc && depth > 0; ++i) {
- if(strncmp(argv[i], "--castxml-", 10) == 0) {
+ for (++i; i < argc && depth > 0; ++i) {
+ if (strncmp(argv[i], "--castxml-", 10) == 0) {
/* clang-format off */
std::cerr <<
"error: arguments to '--castxml-cc-" << cc_id <<
@@ -193,18 +195,18 @@ int main(int argc_in, const char** argv_in)
;
/* clang-format on */
return 1;
- } else if(strcmp(argv[i], "(") == 0) {
+ } else if (strcmp(argv[i], "(") == 0) {
++depth;
cc_args.push_back(argv[i]);
- } else if(strcmp(argv[i], ")") == 0) {
- if(--depth) {
+ } else if (strcmp(argv[i], ")") == 0) {
+ if (--depth) {
cc_args.push_back(argv[i]);
}
} else {
cc_args.push_back(argv[i]);
}
}
- if(depth) {
+ if (depth) {
/* clang-format off */
std::cerr <<
"error: unbalanced parentheses after '--castxml-cc-" <<
@@ -229,10 +231,10 @@ int main(int argc_in, const char** argv_in)
/* clang-format on */
return 1;
}
- } else if(strcmp(argv[i], "-E") == 0) {
+ } else if (strcmp(argv[i], "-E") == 0) {
opts.PPOnly = true;
- } else if(strcmp(argv[i], "-o") == 0) {
- if((i+1) < argc) {
+ } else if (strcmp(argv[i], "-o") == 0) {
+ if ((i + 1) < argc) {
opts.OutputFile = argv[++i];
} else {
/* clang-format off */
@@ -244,8 +246,8 @@ int main(int argc_in, const char** argv_in)
/* clang-format on */
return 1;
}
- } else if(strcmp(argv[i], "-help") == 0 ||
- strcmp(argv[i], "--help") == 0) {
+ } else if (strcmp(argv[i], "-help") == 0 ||
+ strcmp(argv[i], "--help") == 0) {
/* clang-format off */
std::cout <<
usage <<
@@ -258,7 +260,7 @@ int main(int argc_in, const char** argv_in)
/* clang-format on */
// Also print Clang help.
clang_args.push_back(argv[i]);
- } else if(strcmp(argv[i], "--version") == 0) {
+ } else if (strcmp(argv[i], "--version") == 0) {
/* clang-format off */
std::cout <<
"castxml version " << getVersionString() << "\n"
@@ -282,9 +284,9 @@ int main(int argc_in, const char** argv_in)
}
}
- if(cc_id) {
+ if (cc_id) {
opts.HaveCC = true;
- if(cc_args.empty()) {
+ if (cc_args.empty()) {
/* clang-format off */
std::cerr <<
"error: '--castxml-cc-" << cc_id <<
@@ -295,13 +297,13 @@ int main(int argc_in, const char** argv_in)
/* clang-format on */
return 1;
}
- if(!detectCC(cc_id, cc_args.data(), cc_args.data() + cc_args.size(),
- opts)) {
+ if (!detectCC(cc_id, cc_args.data(), cc_args.data() + cc_args.size(),
+ opts)) {
return 1;
}
}
- if(clang_args.empty()) {
+ if (clang_args.empty()) {
return 0;
}