summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-02-12 21:13:31 (GMT)
committerBrad King <brad.king@kitware.com>2014-03-21 18:38:52 (GMT)
commit2da34defdc88e70cda35cb08e5fa692466ab27ba (patch)
treee4122e35313e1357e04f1645a0618e4d76eafc97
parent5a5c1c8043ea4726546f003e47953d33975de54e (diff)
downloadCastXML-2da34defdc88e70cda35cb08e5fa692466ab27ba.zip
CastXML-2da34defdc88e70cda35cb08e5fa692466ab27ba.tar.gz
CastXML-2da34defdc88e70cda35cb08e5fa692466ab27ba.tar.bz2
Output: Generate Typedef elements
Implement the OutputTypedefDecl method to generate the Typedef element. Report the name="", type="", context="", and location="" of the declaration.
-rw-r--r--src/Output.cxx104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/Output.cxx b/src/Output.cxx
index 57c7c0c..038584b 100644
--- a/src/Output.cxx
+++ b/src/Output.cxx
@@ -165,12 +165,37 @@ class ASTVisitor: public ASTVisitorBase
declaration context (namespace, class, etc.). */
unsigned int GetContextIdRef(clang::DeclContext const* dc);
+ /** Get the XML IDREF for the element defining the given
+ (possibly cv-qualified) type. The qc,qv,qr booleans are
+ set to whether the IDREF should include the const,
+ volatile, or restrict qualifier, respectively. Also
+ queues the given type for later output. */
+ unsigned int GetTypeIdRef(clang::QualType t, bool complete,
+ bool& qc, bool& qv, bool& qr);
+
+ /** Print the XML IDREF value referencing the given type.
+ If the type has top-level cv-qualifiers, they are
+ appended to the numeric id as single characters (c=const,
+ v=volatile, r=restrict) to reference the XML ID of
+ a CvQualifiedType element describing the qualifiers
+ and referencing the unqualified type. */
+ void PrintTypeIdRef(clang::QualType t, bool complete);
+
/** Print an id="_<n>" XML unique ID attribute. */
void PrintIdAttribute(DumpNode const* dn);
/** Print a name="..." attribute. */
void PrintNameAttribute(std::string const& name);
+ /** Print a type="..." attribute with the XML IDREF for
+ the given (possibly cv-qualified) type. Also queues
+ the given type for later output. */
+ void PrintTypeAttribute(clang::QualType t, bool complete);
+
+ /** Print the XML attributes location="fid:line" file="fid" line="line"
+ for the given decl. */
+ void PrintLocationAttribute(clang::Decl const* d);
+
/** Print a members="..." attribute listing the XML IDREFs for
members of the given declaration context. Also queues the
context members for later output. */
@@ -186,6 +211,7 @@ class ASTVisitor: public ASTVisitorBase
void OutputTranslationUnitDecl(clang::TranslationUnitDecl const* d,
DumpNode const* dn);
void OutputNamespaceDecl(clang::NamespaceDecl const* d, DumpNode const* dn);
+ void OutputTypedefDecl(clang::TypedefDecl const* d, DumpNode const* dn);
/** Queue declarations matching given qualified name in given context. */
void LookupStart(clang::DeclContext const* dc, std::string const& name);
@@ -393,6 +419,43 @@ unsigned int ASTVisitor::GetContextIdRef(clang::DeclContext const* dc)
}
//----------------------------------------------------------------------------
+unsigned int ASTVisitor::GetTypeIdRef(clang::QualType t, bool complete,
+ bool& qc, bool& qv, bool& qr)
+{
+ // Add the type node.
+ unsigned int id = this->AddDumpNode(t, complete);
+
+ // Check for qualifiers.
+ qc = t.isLocalConstQualified();
+ qv = t.isLocalVolatileQualified();
+ qr = t.isLocalRestrictQualified();
+
+ // If the type has qualifiers, add the unqualified type and use its id.
+ if(t.hasLocalQualifiers()) {
+ id = this->AddDumpNode(t.getLocalUnqualifiedType(), complete);
+ }
+
+ // Return the dump node id of the unqualified type.
+ return id;
+}
+
+//----------------------------------------------------------------------------
+void ASTVisitor::PrintTypeIdRef(clang::QualType t, bool complete)
+{
+ // Add the type node.
+ bool qc, qv, qr;
+ unsigned int id = this->GetTypeIdRef(t, complete, qc, qv, qr);
+
+ // Check cv-qualificiation.
+ const char* c = qc? "c" : "";
+ const char* v = qv? "v" : "";
+ const char* r = qr? "r" : "";
+
+ // Print the reference.
+ this->OS << "_" << id << c << v << r;
+}
+
+//----------------------------------------------------------------------------
void ASTVisitor::PrintIdAttribute(DumpNode const* dn)
{
this->OS << " id=\"_" << dn->Index << "\"";
@@ -405,6 +468,33 @@ void ASTVisitor::PrintNameAttribute(std::string const& name)
}
//----------------------------------------------------------------------------
+void ASTVisitor::PrintTypeAttribute(clang::QualType t, bool complete)
+{
+ this->OS << " type=\"";
+ this->PrintTypeIdRef(t, complete);
+ this->OS << "\"";
+}
+
+//----------------------------------------------------------------------------
+void ASTVisitor::PrintLocationAttribute(clang::Decl const* d)
+{
+ clang::SourceLocation sl = d->getLocation();
+ if(!sl.isValid()) {
+ 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 << "\"";
+ }
+}
+
+//----------------------------------------------------------------------------
void ASTVisitor::PrintContextAttribute(clang::Decl const* d)
{
clang::DeclContext const* dc = d->getDeclContext();
@@ -490,6 +580,20 @@ void ASTVisitor::OutputNamespaceDecl(
}
//----------------------------------------------------------------------------
+void ASTVisitor::OutputTypedefDecl(clang::TypedefDecl const* d,
+ DumpNode const* dn)
+{
+ this->OS << " <Typedef";
+ this->PrintIdAttribute(dn);
+ this->PrintNameAttribute(d->getName().str());
+ this->PrintTypeAttribute(d->getTypeSourceInfo()->getType(), dn->Complete);
+ this->PrintContextAttribute(d);
+ this->PrintLocationAttribute(d);
+
+ this->OS << "/>\n";
+}
+
+//----------------------------------------------------------------------------
void ASTVisitor::LookupStart(clang::DeclContext const* dc,
std::string const& name)
{