[aspectc-user] Using puma to print out class member names

Olaf Spinczyk Olaf.Spinczyk at informatik.uni-erlangen.de
Thu Dec 30 10:49:24 CET 2004


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,


More information about the aspectc-user mailing list