[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
Olaf,
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?
-Shyam
-----Original Message-----
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
Hi,
Sunder, Shyam (MSTG - NY) wrote:
> Hi,
>
> 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
a
> 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);
> project.scanFile("tests/A.h")->print(std::cout);
>
> CClassDatabase classdb(project);
>
> classdb.Dump(std::cout);
>
> DString d = classdb.ClassInfo(0)->AttributeInfo()->Name();
> std::cout << d.c_str() << std::endl;
>
> return 0;
> }
>
> However, The program crashes:
>
> #pragma once
>
> class A
> {
> public:
> int a;
>
> private:
> int b;
> assertion "index >= 0 && index < count" failed: file
>
"/home/matthias/Projekte/Cvsdir/Puma/gen/step1/inc/Puma/VoidPtrArray.h",
> 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 ()
returns 0.
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
CStructure.
I hope this helps,
Olaf
--------------------------------------------------------
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
mailing list