summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-04-11 18:49:22 (GMT)
committerBrad King <brad.king@kitware.com>2014-04-11 18:51:06 (GMT)
commit2bba2e9e8900666ca92a7abb848ee8e5756462d8 (patch)
tree359d4dd98514b54ccf2b71c1fb178fc21f8d3215
parent81475d7fc881a5cdaa2e2a1e61ad335a52549093 (diff)
downloadCastXML-2bba2e9e8900666ca92a7abb848ee8e5756462d8.zip
CastXML-2bba2e9e8900666ca92a7abb848ee8e5756462d8.tar.gz
CastXML-2bba2e9e8900666ca92a7abb848ee8e5756462d8.tar.bz2
Output: Generate location attributes for builtin declarations
Report a file id "f0" named "<builtin>" 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.
-rw-r--r--src/Output.cxx35
-rw-r--r--test/CMakeLists.txt1
-rw-r--r--test/expect/gccxml.any.implicit-decl-ms.xml.txt11
-rw-r--r--test/input/implicit-decl-ms.cxx1
4 files changed, 37 insertions, 11 deletions
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 <<
+ " <File id=\"f0\" name=\"" << encodeXML("<builtin>") << "\"/>\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"\?>
+<GCC_XML[^>]*>
+ <Function id="_1" name="start" returns="_2" context="_3" location="f1:1" file="f1" line="1">
+ <Argument type="_2" location="f1:1" file="f1" line="1"/>
+ </Function>
+ <Typedef id="_2" name="size_t" type="_4" context="_3" location="f0:0" file="f0" line="0"/>
+ <FundamentalType id="_4" name="unsigned int"/>
+ <Namespace id="_3" name="::"/>
+ <File id="f0" name="&lt;builtin&gt;"/>
+ <File id="f1" name=".*/test/input/implicit-decl-ms.cxx"/>
+</GCC_XML>$
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);