[Prev][Next][Index]

Re: class symbols



> I am having a problem finding the filename of
> SgClassSymb's in sage++ files.  What I'm doing is reading
> through the symbols, checking if they are class symbols,
> and then retrieving their name and the file they are
> declared in.  To do this, I use the declaredInStmt()
> method, and then the fileName() method.  The problem is
> that some of the class symbols' declaredInStmt() are
> returning NULL.  If I use the scope() method, then I get a
> temp file that I am using instead of the actual file that
> the "class" declaration is in.   

> 

It appears that there might be something wrong with declaredInStmt  
method. But even if that method were OK, you really do not want to  
use it. The problem is with things like:

class A;
class A;
class A{int i;};

in which statement is A declared?

What you should try instead is using structureDecl method (as shown  
below). What this method returns is the statement where the class is  
_defined_ (i.e., third statement above) rather than just simply  
declared (these might be multiple statements in multiple files).

So if you have a file:

class C;

#include "myinc.h"

class A;

class B{int i;};

and myinc.h contains:

class C{ int j;};

the code below will give:

class name C
 declared in stmt 3  file myinc.h
class name A
class name B
 declared in stmt 6  file cl.c

(notice that A is not "declared" (i.e., defined) according to the  
rule that the structureDecl method uses).

                  --Beata


      SgStatement *class_stmt = NULL;
      SgClassType * clt = isSgClassType(s->type());
      if(clt) class_stmt = clt->structureDecl();

      char *class_name = s->identifier();
      cout << "class name " << class_name << endl; 

      char *file_name = NULL;

      if(class_stmt)  {
	file_name = class_stmt->fileName();
        cout << " declared in stmt " << class_stmt ->id() << " file "
            << file_name << endl;
      }