From 2bba2e9e8900666ca92a7abb848ee8e5756462d8 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 11 Apr 2014 14:49:22 -0400 Subject: Output: Generate location attributes for builtin declarations Report a file id "f0" named "" for declarations that are generated by the compiler and have no reference location in the source. Add a test case covering the MSVC builtin "size_t" typedef. --- src/Output.cxx | 35 +++++++++++++++++-------- test/CMakeLists.txt | 1 + test/expect/gccxml.any.implicit-decl-ms.xml.txt | 11 ++++++++ test/input/implicit-decl-ms.cxx | 1 + 4 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 test/expect/gccxml.any.implicit-decl-ms.xml.txt create mode 100644 test/input/implicit-decl-ms.cxx diff --git a/src/Output.cxx b/src/Output.cxx index 0a3c6f4..132345d 100644 --- a/src/Output.cxx +++ b/src/Output.cxx @@ -359,6 +359,9 @@ private: // Total number of source files to be referenced. unsigned int FileCount; + // Whether we need a File element for compiler builtins. + bool FileBuiltin; + // Whether we are in the complete or incomplete output step. bool RequireComplete; @@ -388,6 +391,7 @@ public: ASTVisitorBase(ci, ctx, os), Opts(opts), NodeCount(0), FileCount(0), + FileBuiltin(false), RequireComplete(true) {} /** Visit declarations in the given translation unit. @@ -713,6 +717,11 @@ void ASTVisitor::ProcessQueue() //---------------------------------------------------------------------------- void ASTVisitor::ProcessFileQueue() { + if(this->FileBuiltin) { + this->OS << + " ") << "\"/>\n" + ; + } while(!this->FileQueue.empty()) { clang::FileEntry const* f = this->FileQueue.front(); this->FileQueue.pop(); @@ -902,18 +911,22 @@ void ASTVisitor::PrintReturnsAttribute(clang::QualType t, bool complete) void ASTVisitor::PrintLocationAttribute(clang::Decl const* d) { clang::SourceLocation sl = d->getLocation(); - if(!sl.isValid()) { - return; + if(sl.isValid()) { + clang::FullSourceLoc fsl = this->CTX.getFullLoc(sl).getExpansionLoc(); + if (clang::FileEntry const* f = + this->CI.getSourceManager().getFileEntryForID(fsl.getFileID())) { + unsigned int id = this->AddDumpFile(f); + unsigned int line = fsl.getExpansionLineNumber(); + this->OS << + " location=\"f" << id << ":" << line << "\"" + " file=\"f" << id << "\"" + " line=\"" << line << "\""; + return; + } } - clang::FullSourceLoc fsl = this->CTX.getFullLoc(sl).getExpansionLoc(); - if (clang::FileEntry const* f = - this->CI.getSourceManager().getFileEntryForID(fsl.getFileID())) { - unsigned int id = this->AddDumpFile(f); - unsigned int line = fsl.getExpansionLineNumber(); - this->OS << - " location=\"f" << id << ":" << line << "\"" - " file=\"f" << id << "\"" - " line=\"" << line << "\""; + if(d->isImplicit()) { + this->FileBuiltin = true; + this->OS << " location=\"f0:0\" file=\"f0\" line=\"0\""; } } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 27b2972..22858aa 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -189,6 +189,7 @@ castxml_test_gccxml(using-directive-start) if(";${LLVM_TARGETS_TO_BUILD};" MATCHES ";X86;") set(castxml_test_gccxml_extra_arguments -target i386-pc-windows-msvc) + castxml_test_gccxml(implicit-decl-ms) castxml_test_gccxml(inline-asm-ms) unset(castxml_test_gccxml_extra_arguments) endif() diff --git a/test/expect/gccxml.any.implicit-decl-ms.xml.txt b/test/expect/gccxml.any.implicit-decl-ms.xml.txt new file mode 100644 index 0000000..d6ac862 --- /dev/null +++ b/test/expect/gccxml.any.implicit-decl-ms.xml.txt @@ -0,0 +1,11 @@ +^<\?xml version="1.0"\?> +]*> + + + + + + + + +$ diff --git a/test/input/implicit-decl-ms.cxx b/test/input/implicit-decl-ms.cxx new file mode 100644 index 0000000..47f16e8 --- /dev/null +++ b/test/input/implicit-decl-ms.cxx @@ -0,0 +1 @@ +size_t start(size_t); -- cgit v0.12