Skip to content

Commit

Permalink
Output: Add mangled="" attributes to function and variable decls
Browse files Browse the repository at this point in the history
The gccxml output format includes mangled="" attributes on almost all
elements.  Clang only defines mangling for function and variable
declarations.  Add mangled attributes to castxml output where possible.
  • Loading branch information
bradking committed May 12, 2015
1 parent 9a56b84 commit 0a10370
Show file tree
Hide file tree
Showing 52 changed files with 128 additions and 96 deletions.
33 changes: 32 additions & 1 deletion src/Output.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclOpenMP.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Mangle.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/Preprocessor.h"
Expand Down Expand Up @@ -300,6 +301,9 @@ class ASTVisitor: public ASTVisitorBase
/** Print a name="..." attribute. */
void PrintNameAttribute(std::string const& name);

/** Print a mangled="..." attribute. */
void PrintMangledAttribute(clang::NamedDecl const* d);

/** Print an offset="..." attribute. */
void PrintOffsetAttribute(unsigned int const& offset);

Expand Down Expand Up @@ -449,6 +453,9 @@ class ASTVisitor: public ASTVisitorBase
// Whether we are in the complete or incomplete output step.
bool RequireComplete;

// Mangling context for target ABI.
std::unique_ptr<clang::MangleContext> MangleContext;

// Map from clang AST declaration node to our dump status node.
typedef std::map<clang::Decl const*, DumpNode> DeclNodesMap;
DeclNodesMap DeclNodes;
Expand Down Expand Up @@ -480,7 +487,8 @@ class ASTVisitor: public ASTVisitorBase
Opts(opts),
NodeCount(0), FileCount(0),
FileBuiltin(false),
RequireComplete(true) {}
RequireComplete(true),
MangleContext(ctx.createMangleContext()) {}

/** Visit declarations in the given translation unit.
This is the main entry point. */
Expand Down Expand Up @@ -987,6 +995,24 @@ void ASTVisitor::PrintNameAttribute(std::string const& name)
this->OS << " name=\"" << encodeXML(name) << "\"";
}

//----------------------------------------------------------------------------
void ASTVisitor::PrintMangledAttribute(clang::NamedDecl const* d)
{
// Compute the mangled name.
std::string s;
{
llvm::raw_string_ostream rso(s);
this->MangleContext->mangleName(d, rso);
}

// Strip a leading 1 byte in MS mangling.
if (!s.empty() && s[0] == '\1') {
s = s.substr(1);
}

this->OS << " mangled=\"" << encodeXML(s) << "\"";
}

//----------------------------------------------------------------------------
void ASTVisitor::PrintOffsetAttribute(unsigned int const& offset)
{
Expand Down Expand Up @@ -1238,6 +1264,10 @@ void ASTVisitor::OutputFunctionHelper(clang::FunctionDecl const* d,
d->getType()->getAs<clang::FunctionProtoType>()) {
this->PrintFunctionTypeAttributes(fpt);
this->PrintThrowsAttribute(fpt, dn->Complete);
if (!clang::isa<clang::CXXConstructorDecl>(d) &&
!clang::isa<clang::CXXDestructorDecl>(d)) {
this->PrintMangledAttribute(d);
}
}

if(unsigned np = d->getNumParams()) {
Expand Down Expand Up @@ -1521,6 +1551,7 @@ void ASTVisitor::OutputVarDecl(clang::VarDecl const* d, DumpNode const* dn)
if(d->getStorageClass() == clang::SC_Extern) {
this->OS << " extern=\"1\"";
}
this->PrintMangledAttribute(d);

this->OS << "/>\n";
}
Expand Down
6 changes: 3 additions & 3 deletions test/expect/gccxml.any.Class-abstract.xml.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
^<\?xml version="1.0"\?>
<GCC_XML[^>]*>
<Class id="_1" name="start" context="_2" location="f1:1" file="f1" line="1" abstract="1" members="_3 _4 _5 _6 _7 _8" size="[0-9]+" align="[0-9]+"/>
<Method id="_3" name="method" returns="_9" context="_1" access="private" location="f1:2" file="f1" line="2" virtual="1" pure_virtual="1">
<Method id="_3" name="method" returns="_9" context="_1" access="private" location="f1:2" file="f1" line="2" virtual="1" pure_virtual="1" mangled="[^"]+">
<Argument type="_9" location="f1:2" file="f1" line="2"/>
</Method>
<Converter id="_4" returns="_9" context="_1" access="private" location="f1:3" file="f1" line="3" virtual="1" pure_virtual="1"/>
<Converter id="_4" returns="_9" context="_1" access="private" location="f1:3" file="f1" line="3" virtual="1" pure_virtual="1" mangled="[^"]+"/>
<Destructor id="_5" name="start" context="_1" access="private" location="f1:4" file="f1" line="4" virtual="1" pure_virtual="1"/>
<OperatorMethod id="_6" name="=" returns="_10" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")?>
<OperatorMethod id="_6" name="=" returns="_10" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")? mangled="[^"]+">
<Argument type="_11" location="f1:1" file="f1" line="1"/>
</OperatorMethod>
<Constructor id="_7" name="start" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")?/>
Expand Down
4 changes: 2 additions & 2 deletions test/expect/gccxml.any.Class-base-typedef.xml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Constructor id="_4" name="start" context="_1" access="public" location="f1:3" file="f1" line="3" inline="1" artificial="1"( throws="")?>
<Argument type="_8" location="f1:3" file="f1" line="3"/>
</Constructor>
<OperatorMethod id="_5" name="=" returns="_9" context="_1" access="public" location="f1:3" file="f1" line="3" inline="1" artificial="1"( throws="")?>
<OperatorMethod id="_5" name="=" returns="_9" context="_1" access="public" location="f1:3" file="f1" line="3" inline="1" artificial="1"( throws="")? mangled="[^"]+">
<Argument type="_8" location="f1:3" file="f1" line="3"/>
</OperatorMethod>
<Destructor id="_6" name="start" context="_1" access="public" location="f1:3" file="f1" line="3" inline="1" artificial="1"( throws="")?/>
Expand All @@ -19,7 +19,7 @@
<Constructor id="_11" name="base" context="_7" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")?>
<Argument type="_14" location="f1:1" file="f1" line="1"/>
</Constructor>
<OperatorMethod id="_12" name="=" returns="_15" context="_7" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")?>
<OperatorMethod id="_12" name="=" returns="_15" context="_7" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")? mangled="[^"]+">
<Argument type="_14" location="f1:1" file="f1" line="1"/>
</OperatorMethod>
<Destructor id="_13" name="base" context="_7" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")?/>
Expand Down
2 changes: 1 addition & 1 deletion test/expect/gccxml.any.Class-forward.xml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Constructor id="_4" name="start" context="_1" access="public" location="f1:5" file="f1" line="5">
<Argument type="_7" location="f1:5" file="f1" line="5"/>
</Constructor>
<OperatorMethod id="_5" name="=" returns="_8" context="_1" access="public" location="f1:6" file="f1" line="6">
<OperatorMethod id="_5" name="=" returns="_8" context="_1" access="public" location="f1:6" file="f1" line="6" mangled="[^"]+">
<Argument type="_7" location="f1:6" file="f1" line="6"/>
</OperatorMethod>
<Destructor id="_6" name="start" context="_1" access="public" location="f1:7" file="f1" line="7"/>
Expand Down
4 changes: 2 additions & 2 deletions test/expect/gccxml.any.Class-friends.xml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
<Constructor id="_4" name="start" context="_1" access="public" location="f1:3" file="f1" line="3" inline="1" artificial="1"( throws="")?>
<Argument type="_9" location="f1:3" file="f1" line="3"/>
</Constructor>
<OperatorMethod id="_5" name="=" returns="_10" context="_1" access="public" location="f1:3" file="f1" line="3" inline="1" artificial="1"( throws="")?>
<OperatorMethod id="_5" name="=" returns="_10" context="_1" access="public" location="f1:3" file="f1" line="3" inline="1" artificial="1"( throws="")? mangled="[^"]+">
<Argument type="_9" location="f1:3" file="f1" line="3"/>
</OperatorMethod>
<Destructor id="_6" name="start" context="_1" access="public" location="f1:3" file="f1" line="3" inline="1" artificial="1"( throws="")?/>
<ReferenceType id="_9" type="_1c"/>
<CvQualifiedType id="_1c" type="_1" const="1"/>
<ReferenceType id="_10" type="_1"/>
<Namespace id="_2" name="::"/>
<Function id="_7" name="f" returns="_11" context="_2" location="f1:2" file="f1" line="2"/>
<Function id="_7" name="f" returns="_11" context="_2" location="f1:2" file="f1" line="2" mangled="[^"]+"/>
<Class id="_8" name="A" context="_2" location="f1:1" file="f1" line="1" size="[0-9]+" align="[0-9]+"/>
<FundamentalType id="_11" name="void" size="[0-9]+" align="[0-9]+"/>
<File id="f1" name=".*/test/input/Class-friends.cxx"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Constructor id="_8" name="base" context="_5" access="private" location="f1:6" file="f1" line="6">
<Argument type="_11" location="f1:6" file="f1" line="6"/>
</Constructor>
<OperatorMethod id="_9" name="=" returns="_12" context="_5" access="private" location="f1:7" file="f1" line="7">
<OperatorMethod id="_9" name="=" returns="_12" context="_5" access="private" location="f1:7" file="f1" line="7" mangled="[^"]+">
<Argument type="_11" location="f1:7" file="f1" line="7"/>
</OperatorMethod>
<Field id="_10" name="data" type="_13" context="_5" access="private" location="f1:8" file="f1" line="8" offset="0" mutable="1"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Constructor id="_8" name="base" context="_5" access="private" location="f1:6" file="f1" line="6">
<Argument type="_10" location="f1:6" file="f1" line="6"/>
</Constructor>
<OperatorMethod id="_9" name="=" returns="_11" context="_5" access="private" location="f1:7" file="f1" line="7">
<OperatorMethod id="_9" name="=" returns="_11" context="_5" access="private" location="f1:7" file="f1" line="7" mangled="[^"]+">
<Argument type="_10" location="f1:7" file="f1" line="7"/>
</OperatorMethod>
<ReferenceType id="_10" type="_5c"/>
Expand Down
2 changes: 1 addition & 1 deletion test/expect/gccxml.any.Class-implicit-member-array.xml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Constructor id="_5" name="start" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")?>
<Argument type="_9" location="f1:1" file="f1" line="1"/>
</Constructor>
<OperatorMethod id="_6" name="=" returns="_10" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")?>
<OperatorMethod id="_6" name="=" returns="_10" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")? mangled="[^"]+">
<Argument type="_9" location="f1:1" file="f1" line="1"/>
</OperatorMethod>
<Destructor id="_7" name="start" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")?/>
Expand Down
4 changes: 2 additions & 2 deletions test/expect/gccxml.any.Class-implicit-members.xml.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
^<\?xml version="1.0"\?>
<GCC_XML[^>]*>
<Class id="_1" name="start" context="_2" location="f1:1" file="f1" line="1" members="_3 _4 _5 _6 _7" size="[0-9]+" align="[0-9]+"/>
<Method id="_3" name="method" returns="_1" context="_1" access="private" location="f1:2" file="f1" line="2" inline="1">
<Method id="_3" name="method" returns="_1" context="_1" access="private" location="f1:2" file="f1" line="2" inline="1" mangled="[^"]+">
<Argument name="x" type="_8" location="f1:2" file="f1" line="2"/>
</Method>
<Constructor id="_4" name="start" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")?/>
<Constructor id="_5" name="start" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")?>
<Argument type="_8" location="f1:1" file="f1" line="1"/>
</Constructor>
<OperatorMethod id="_6" name="=" returns="_9" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")?>
<OperatorMethod id="_6" name="=" returns="_9" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")? mangled="[^"]+">
<Argument type="_8" location="f1:1" file="f1" line="1"/>
</OperatorMethod>
<Destructor id="_7" name="start" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")?/>
Expand Down
4 changes: 2 additions & 2 deletions test/expect/gccxml.any.Class-member-template.xml.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
^<\?xml version="1.0"\?>
<GCC_XML[^>]*>
<Class id="_1" name="start" context="_2" location="f1:1" file="f1" line="1" members="_3 _4 _5 _6 _7" size="[0-9]+" align="[0-9]+"/>
<Method id="_3" name="method" returns="_8" context="_1" access="private" location="f1:2" file="f1" line="2" inline="1">
<Method id="_3" name="method" returns="_8" context="_1" access="private" location="f1:2" file="f1" line="2" inline="1" mangled="[^"]+">
<Argument name="v" type="_8" location="f1:2" file="f1" line="2"/>
</Method>
<Constructor id="_4" name="start" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")?/>
<Constructor id="_5" name="start" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")?>
<Argument type="_9" location="f1:1" file="f1" line="1"/>
</Constructor>
<OperatorMethod id="_6" name="=" returns="_10" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")?>
<OperatorMethod id="_6" name="=" returns="_10" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")? mangled="[^"]+">
<Argument type="_9" location="f1:1" file="f1" line="1"/>
</OperatorMethod>
<Destructor id="_7" name="start" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")?/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<GCC_XML[^>]*>
<Class id="_1" name="start&lt;int &amp;&gt;" context="_2" location="f1:7" file="f1" line="7" members="_3 _4 _5 _6 _7 _8" size="[0-9]+" align="[0-9]+"/>
<Typedef id="_3" name="Int" type="_9" context="_1" access="private" location="f1:3" file="f1" line="3"/>
<Method id="_4" name="method" returns="_9" context="_1" access="public" location="f1:5" file="f1" line="5">
<Method id="_4" name="method" returns="_9" context="_1" access="public" location="f1:5" file="f1" line="5" mangled="[^"]+">
<Argument type="_3" location="f1:5" file="f1" line="5"/>
</Method>
<Constructor id="_5" name="start" context="_1" access="public" location="f1:7" file="f1" line="7" inline="1" artificial="1"( throws="")?/>
<Constructor id="_6" name="start" context="_1" access="public" location="f1:7" file="f1" line="7" inline="1" artificial="1"( throws="")?>
<Argument type="_10" location="f1:7" file="f1" line="7"/>
</Constructor>
<OperatorMethod id="_7" name="=" returns="_11" context="_1" access="public" location="f1:7" file="f1" line="7" inline="1" artificial="1"( throws="")?>
<OperatorMethod id="_7" name="=" returns="_11" context="_1" access="public" location="f1:7" file="f1" line="7" inline="1" artificial="1"( throws="")? mangled="[^"]+">
<Argument type="_10" location="f1:7" file="f1" line="7"/>
</OperatorMethod>
<Destructor id="_8" name="start" context="_1" access="public" location="f1:7" file="f1" line="7" inline="1" artificial="1"( throws="")?/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
^<\?xml version="1.0"\?>
<GCC_XML[^>]*>
<Class id="_1" name="start&lt;const int&gt;" context="_2" location="f1:4" file="f1" line="4" members="_3 _4 _5 _6 _7" size="[0-9]+" align="[0-9]+"/>
<Method id="_3" name="method" returns="_8" context="_1" access="private" location="f1:2" file="f1" line="2">
<Method id="_3" name="method" returns="_8" context="_1" access="private" location="f1:2" file="f1" line="2" mangled="[^"]+">
<Argument type="_9" location="f1:2" file="f1" line="2"/>
</Method>
<Constructor id="_4" name="start" context="_1" access="public" location="f1:4" file="f1" line="4" inline="1" artificial="1"/>
<Constructor id="_4" name="start" context="_1" access="public" location="f1:4" file="f1" line="4" inline="1" artificial="1"( throws="")?/>
<Constructor id="_5" name="start" context="_1" access="public" location="f1:4" file="f1" line="4" inline="1" artificial="1"( throws="")?>
<Argument type="_10" location="f1:4" file="f1" line="4"/>
</Constructor>
<OperatorMethod id="_6" name="=" returns="_11" context="_1" access="public" location="f1:4" file="f1" line="4" inline="1" artificial="1"( throws="")?>
<OperatorMethod id="_6" name="=" returns="_11" context="_1" access="public" location="f1:4" file="f1" line="4" inline="1" artificial="1"( throws="")? mangled="[^"]+">
<Argument type="_10" location="f1:4" file="f1" line="4"/>
</OperatorMethod>
<Destructor id="_7" name="start" context="_1" access="public" location="f1:4" file="f1" line="4" inline="1" artificial="1"( throws="")?/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
^<\?xml version="1.0"\?>
<GCC_XML[^>]*>
<Class id="_1" name="start&lt;int&gt;" context="_2" location="f1:4" file="f1" line="4" members="_3 _4 _5 _6 _7" size="[0-9]+" align="[0-9]+"/>
<Method id="_3" name="method" returns="_8" context="_1" access="private" location="f1:2" file="f1" line="2">
<Method id="_3" name="method" returns="_8" context="_1" access="private" location="f1:2" file="f1" line="2" mangled="[^"]+">
<Argument type="_8" location="f1:2" file="f1" line="2" default="123"/>
</Method>
<Constructor id="_4" name="start" context="_1" access="public" location="f1:4" file="f1" line="4" inline="1" artificial="1"( throws="")?/>
<Constructor id="_5" name="start" context="_1" access="public" location="f1:4" file="f1" line="4" inline="1" artificial="1"( throws="")?>
<Argument type="_9" location="f1:4" file="f1" line="4"/>
</Constructor>
<OperatorMethod id="_6" name="=" returns="_10" context="_1" access="public" location="f1:4" file="f1" line="4" inline="1" artificial="1"( throws="")?>
<OperatorMethod id="_6" name="=" returns="_10" context="_1" access="public" location="f1:4" file="f1" line="4" inline="1" artificial="1"( throws="")? mangled="[^"]+">
<Argument type="_9" location="f1:4" file="f1" line="4"/>
</OperatorMethod>
<Destructor id="_7" name="start" context="_1" access="public" location="f1:4" file="f1" line="4" inline="1" artificial="1"( throws="")?/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
^<\?xml version="1.0"\?>
<GCC_XML[^>]*>
<Class id="_1" name="start&lt;const int&gt;" context="_2" location="f1:4" file="f1" line="4" members="_3 _4 _5 _6 _7" size="[0-9]+" align="[0-9]+"/>
<Method id="_3" name="method" returns="_8c" context="_1" access="private" location="f1:2" file="f1" line="2"/>
<Constructor id="_4" name="start" context="_1" access="public" location="f1:4" file="f1" line="4" inline="1" artificial="1"/>
<Method id="_3" name="method" returns="_8c" context="_1" access="private" location="f1:2" file="f1" line="2" mangled="[^"]+"/>
<Constructor id="_4" name="start" context="_1" access="public" location="f1:4" file="f1" line="4" inline="1" artificial="1"( throws="")?/>
<Constructor id="_5" name="start" context="_1" access="public" location="f1:4" file="f1" line="4" inline="1" artificial="1"( throws="")?>
<Argument type="_9" location="f1:4" file="f1" line="4"/>
</Constructor>
<OperatorMethod id="_6" name="=" returns="_10" context="_1" access="public" location="f1:4" file="f1" line="4" inline="1" artificial="1"( throws="")?>
<OperatorMethod id="_6" name="=" returns="_10" context="_1" access="public" location="f1:4" file="f1" line="4" inline="1" artificial="1"( throws="")? mangled="[^"]+">
<Argument type="_9" location="f1:4" file="f1" line="4"/>
</OperatorMethod>
<Destructor id="_7" name="start" context="_1" access="public" location="f1:4" file="f1" line="4" inline="1" artificial="1"( throws="")?/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Constructor id="_4" name="start" context="_1" access="public" location="f1:4" file="f1" line="4">
<Argument type="_8" location="f1:4" file="f1" line="4"/>
</Constructor>
<OperatorMethod id="_5" name="=" returns="_9" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")?>
<OperatorMethod id="_5" name="=" returns="_9" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")? mangled="[^"]+">
<Argument type="_7" location="f1:1" file="f1" line="1"/>
</OperatorMethod>
<Destructor id="_6" name="start" context="_1" access="public" location="f1:1" file="f1" line="1" inline="1" artificial="1"( throws="")?/>
Expand Down
Loading

0 comments on commit 0a10370

Please sign in to comment.