diff options
| author | Michka Popoff <michkapopoff@gmail.com> | 2016-11-18 23:00:41 (GMT) |
|---|---|---|
| committer | Brad King <brad.king@kitware.com> | 2016-12-09 16:35:51 (GMT) |
| commit | 5e13767fcccee40991f7a31af71a877cc5163957 (patch) | |
| tree | b7d557175631a3718dc85cb8b43b5947dc08383c /src | |
| parent | 242cc739acd637bd713e05557fd6dadb7eefc5d5 (diff) | |
| download | CastXML-5e13767fcccee40991f7a31af71a877cc5163957.zip CastXML-5e13767fcccee40991f7a31af71a877cc5163957.tar.gz CastXML-5e13767fcccee40991f7a31af71a877cc5163957.tar.bz2 | |
castxml: Add flag --castxml-output=<v> to activate a new output format
This will allow us to move the format forward away from gccxml
compatibility in order to add information about new C++ structures.
The new format will work with all C and C++ language modes but
still not for Objective C/C++.
Retain the `--castxml-gccxml` flag to produce XML files as similar as
possible as the ones produced by gccxml, but do not allow both formats
to be specified at the same time. For now use the same output for both
formats except for the name of the root element. Later the new format
can be adapted to add new features.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Options.h | 4 | ||||
| -rw-r--r-- | src/Output.cxx | 37 | ||||
| -rw-r--r-- | src/RunClang.cxx | 11 | ||||
| -rw-r--r-- | src/castxml.cxx | 42 |
4 files changed, 85 insertions, 9 deletions
diff --git a/src/Options.h b/src/Options.h index ab7f7ef..0c7ffd9 100644 --- a/src/Options.h +++ b/src/Options.h @@ -25,16 +25,20 @@ struct Options Options() : PPOnly(false) , GccXml(false) + , CastXml(false) , HaveCC(false) , HaveStd(false) , HaveTarget(false) + , CastXmlEpicFormatVersion(1) { } bool PPOnly; bool GccXml; + bool CastXml; bool HaveCC; bool HaveStd; bool HaveTarget; + unsigned int CastXmlEpicFormatVersion; struct Include { Include(std::string const& d, bool f = false) diff --git a/src/Output.cxx b/src/Output.cxx index a1c103f..fe70d17 100644 --- a/src/Output.cxx +++ b/src/Output.cxx @@ -641,7 +641,7 @@ ASTVisitor::DumpId ASTVisitor::AddDeclDumpNode(clang::Decl const* d, } // Skip C++11 declarations gccxml does not support. - if (this->Opts.GccXml) { + if (this->Opts.GccXml || this->Opts.CastXml) { if (clang::FunctionDecl const* fd = clang::dyn_cast<clang::FunctionDecl>(d)) { if (fd->isDeleted()) { @@ -2123,23 +2123,44 @@ void ASTVisitor::OutputPointerType(clang::PointerType const* t, void ASTVisitor::OutputStartXMLTags() { - // Start dump with gccxml-compatible format. /* clang-format off */ this->OS << "<?xml version=\"1.0\"?>\n" - "<GCC_XML version=\"0.9.0\" cvs_revision=\"1.139\">\n" ; /* clang-format on */ + if (this->Opts.CastXml) { + // Start dump with castxml-compatible format. + /* clang-format off */ + this->OS << + "<CastXML format=\"" << Opts.CastXmlEpicFormatVersion << ".0.0\">\n" + ; + /* clang-format on */ + } else if (this->Opts.GccXml) { + // Start dump with gccxml-compatible format (legacy). + /* clang-format off */ + this->OS << + "<GCC_XML version=\"0.9.0\" cvs_revision=\"1.139\">\n" + ; + /* clang-format on */ + } } void ASTVisitor::OutputEndXMLTags() { // Finish dump. - /* clang-format off */ - this->OS << - "</GCC_XML>\n" - ; - /* clang-format on */ + if (this->Opts.CastXml) { + /* clang-format off */ + this->OS << + "</CastXML>\n" + ; + /* clang-format on */ + } else if (this->Opts.GccXml) { + /* clang-format off */ + this->OS << + "</GCC_XML>\n" + ; + /* clang-format on */ + } } void ASTVisitor::LookupStart(clang::DeclContext const* dc, diff --git a/src/RunClang.cxx b/src/RunClang.cxx index a1d67cf..37e8ac7 100644 --- a/src/RunClang.cxx +++ b/src/RunClang.cxx @@ -381,7 +381,7 @@ class CastXMLSyntaxOnlyAction clang::CompilerInstance& CI, llvm::StringRef InFile) override { using llvm::sys::path::filename; - if (!this->Opts.GccXml) { + if (!this->Opts.GccXml && !this->Opts.CastXml) { return clang::SyntaxOnlyAction::CreateASTConsumer(CI, InFile); #ifdef CASTXML_OWNS_OSTREAM } else if (std::unique_ptr<llvm::raw_ostream> OS = @@ -440,6 +440,15 @@ static bool runClangCI(clang::CompilerInstance* CI, Options const& opts) #undef MSG } + if (opts.CastXml) { +#define MSG(x) "error: '--castxml-output=<v>' does not work with " x "\n" + if (CI->getLangOpts().ObjC1 || CI->getLangOpts().ObjC2) { + std::cerr << MSG("Objective C"); + return false; + } +#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). diff --git a/src/castxml.cxx b/src/castxml.cxx index 485d939..7c39e78 100644 --- a/src/castxml.cxx +++ b/src/castxml.cxx @@ -107,8 +107,15 @@ int main(int argc_in, const char** argv_in) " <cc> names a compiler (e.g. \"gcc\") and <cc-opt>... specifies\n" " options that may affect its target (e.g. \"-m32\").\n" "\n" + " --castxml-output=<v>\n" + " Write castxml-format output to <src>.xml or file named by '-o'\n" + " The <v> specifies the \"epic\" format version number to generate,\n" + " and must be '1'.\n" + "\n" " --castxml-gccxml\n" " Write gccxml-format output to <src>.xml or file named by '-o'\n" + " Use this option if you need an output similar to the one generated\n" + " by the legacy gccxml tool.\n" "\n" " --castxml-start <name>[,<name>]...\n" " Start AST traversal at declaration(s) with the given (qualified)\n" @@ -146,6 +153,29 @@ int main(int argc_in, const char** argv_in) /* clang-format on */ return 1; } + } else if (strncmp(argv[i], "--castxml-output=", 17) == 0) { + if (!opts.CastXml) { + opts.CastXml = true; + opts.CastXmlEpicFormatVersion = atoi(argv[i] + 17); + if (opts.CastXmlEpicFormatVersion != 1) { + /* clang-format off */ + std::cerr << + "error: '--castxml-output=<v>' accepts only '1' as '<v>'!\n" + "\n" << + usage + ; + /* clang-format on */ + } + } else { + /* clang-format off */ + std::cerr << + "error: '--castxml-output=<v>' may be given at most once!\n" + "\n" << + usage + ; + /* clang-format on */ + return 1; + } } else if (strcmp(argv[i], "--castxml-start") == 0) { if ((i + 1) < argc) { std::string item; @@ -303,6 +333,18 @@ int main(int argc_in, const char** argv_in) } } + if (opts.GccXml && opts.CastXml) { + /* clang-format off */ + std::cerr << + "error: '--castxml-gccxml' and '--castxml-output=<v>'" + " may not be not be used together!\n" + "\n" << + usage + ; + /* clang-format on */ + return 1; + } + if (clang_args.empty()) { return 0; } |
