[aspectc-user] Using puma to print out class member names
Sunder, Shyam (MSTG - NY)
s_sunder at ml.com
Thu Dec 30 17:31:17 CET 2004
Thanks for all the help. Now that I have a way to parse a class, I need
print out all its base classes. Here is my loop:
int numClasses = classdb.ClassInfos();
for ( int i =0; i < numClasses; i++ )
CClassInfo* classInfo = classdb.ClassInfo(i);
std::cout << "Class Name: " << classInfo->Name();
int numBaseClasses = classInfo->BaseClasses();
for ( int j = 0; j < numBaseClasses; j++ )
CBaseClassInfo* baseClassInfo = classInfo->BaseClass(j);
std::cout << "[" << baseClassInfo->Name() << "] ";
std::cout << std::endl;
However, baseClassInfo->Name() returns a null. How do I get to the name
of the base classes? What if they are template parameters?
From: Olaf Spinczyk [mailto:Olaf.Spinczyk at informatik.uni-erlangen.de]
Sent: Thursday, December 30, 2004 4:49 AM
To: Sunder, Shyam (MSTG - NY)
Cc: aspectc-user at aspectc.org
Subject: Re: [aspectc-user] Using puma to print out class member names
Sunder, Shyam (MSTG - NY) wrote:
> I am not sure if this is the right mailing list for asking questions
> about the Puma parser. I'm going to try my luck...
Well, there is no better mailing list for this question yet. We'll make
one if the number of Puma question will increase.
> I am trying to print out the member names of a particular class. After
> fair amount of trial and error, I got to this stage:
> #include "Puma/ErrorStream.h"
> #include "Puma/CProject.h"
> #include "Puma/CClassDatabase.h"
> #include "Puma/PathIterator.h"
> #include "Puma/CFunctionInfo.h"
> #include "Puma/CTypeInfo.h"
> #include "Puma/CClassInfo.h"
> #include "Puma/CAttributeInfo.h"
> #include <iostream>
> using namespace Puma;
> int main(int argc, char** argv)
> ErrorStream err;
> CProject project(err);
> CClassDatabase classdb(project);
> DString d = classdb.ClassInfo(0)->AttributeInfo()->Name();
> std::cout << d.c_str() << std::endl;
> return 0;
> However, The program crashes:
> #pragma once
> class A
> int a;
> int b;
> assertion "index >= 0 && index < count" failed: file
> line 186
> };Aborted (core dumped)
> Any ideas?
Yes, there are two problems.
First of all, you didn't *parse* the input file. You only scanned it,
which means that Puma converted the characters in your input file into a
sequence of tokens. Look into Puma/examples/ccparser/ccparser.cc to find
out how to parse an input file and dump the results.
The second problem is that you call ClassInfo (0)->AttributeInfo ().
This is wrong, because AttributeInfo () checks if your class-db object
is an attribute and converts the object pointer into an CAttributeInfo*
pointer if it is an attribute. In this case the object is not an
attribute (it is the first class in the class-db) and AttributeInfo ()
What you probably want here is the list of attributes defined in a
class. This can be obtained with the Attributes() and
Attribute(unsigned) functions, which CClassInfo inherits from
I hope this helps,
If you are not an intended recipient of this e-mail, please notify the sender, delete it and do not read, act upon, print, disclose, copy, retain or redistribute it. Click here for important additional terms relating to this e-mail. http://www.ml.com/email_terms/
More information about the aspectc-user