Re: Sage doubts

> Question 1: ----------- This is regarding the following
> member functions of SgStatement.  int hasSymbol(); 

> SgSymbol * symbol();

> the manual says the following about them: //returns TRUE
> if stmt has a symbol.

> // returns the symbol field. // used by loop headers to
> point to the loop variable symbol; Used by  // function and
> subroutine headers to point to function name.

> They seem to work fine for function statements. But
> symbol() returns NULL for a loop statement and does not
> return any loop variable symbol. 


> Given a for loop statement like " for(i=0; i<10; i++) " I
> assume that 'i' is the loop variable symbol. 


hasSymbol() returns non-zero only if there is a non-null
symbol pointer attached to the statement node in the .dep file.
If you look at the output of dumpdep for a C++ program, you will 

notice that the "sym" field for a FOR_NODE is not set, therefore  
hasSymbol returns zero. However, for a Fortran program this field is  
set, and hasSymbol() and symbol() work correctly. So, the manual  
should say that those methods are used for loop headers only in case  
of Fortran. In C++, you need to write your own function to extract  
the symbol from, for example,  the for statement. 

> Question 2: ----------- While traversing through a
> program using sage, I need to know when a given Symbol was
> assigned its current  value. (ie. its previous reference
> when it was probably in the lhs of an assignment
> statement). what is the best way to do that using sage. 


I would try using an SgAttribute attached to an SgSymbol to store the  
information (perhaps an SgStatement pointer?) about the most recent  
assignment. Then, when you encounter a particular symbol, you can  
retrieve this info.

> Question 3: ----------- this is about the
> SgBasicBlockStatement. I need to identify all the basic
> blocks within { } in the program. My simple test program
> segment to print it out is as below:

>      SgBasicBlockStmt *sbbs;           if(sbbs =
> isSgBasicBlockStmt(s))            {                 printf(" BASIC  
BLOCK is \n");                

> s->unparsestdout();                 printf("\n\n");           }

> this is done while traversing through each statement in
> the program. But I do not get anything in the output. Can
> you clarify exactly what type of basic blocks it will
> identify. 


SgBasicBlockStmt represents those compound statements in C++ that are  
not a part of: if, for, while, etc. statements. So, for example,  
there is one SgBasicBlockStmt in the following code fragment:

int i;
  int j;

but there are none in:
  for(i=0, i < 10, i++){

Hope this clarifies thing somewhat,  --Beata