[Prev][Next][Index]

No Subject





Hola Sage Gurus,

	I think I have a bug here, although I may be doing something
impolite in my code that I don't know about.  My code worked way back
in version 1.1, and now I am trying to make it fit the newest stuff.  

	I am using sage to look for the variable names of a var decl 
statement, if they exist.  After testing, I came up with what seemed 
to be the statement that caused the problem:

	char * d[1] = {"Proje"};

...where "Proje" is any string 5 or more characters long.  Note that:

	char * d[1] = {"Proj"};

...works fine.

	Here is a somewhat slimmed version of the code that generated the
bug.  I will insert comments in the topmost function, where the 
problem occurred (Note that I just linked with libSage++.a)...

/* ---------------------------------------------------------------*/

#include "stdio.h"
#include "sage++user.h"

// look at symbol, return it if same as fname, else return NULL
SgSymbol *newextractSymbIfSame(SgExpression *e, char *fname) {
  char *tmp;
  SgSymbol *symb;

  if (!e) return NULL;

/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */	
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */	
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */	

/* during the e->symbol() call, libSage++ enters an infinite loop 
   in a function called SetMappingInTableForSymb.  This happens 
   because it is trying to allocate a large enough table (via
   ReallocatesymbolTableClass() ) to accomodate the symbol ID, 
   which seems to be garbage, a number usually in the zillions.  
   So, it seems that by having more than 4 characters in the 
   initialization string, the symbol ID or a pointer or something
   is overwritten.  
*/
  if (symb = e->symbol()) {

/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */	
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */	
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */	

    tmp = symb->identifier();
    if (strcmp(tmp, fname) == 0) {
      return e->symbol();
    }
  } 
  return NULL;
}

SgSymbol *newfindVarRefInExpTree(char *fname, SgExpression *exp) {
  SgSymbol *s;
  if (!exp || (exp->variant() == INT_VAL)) {
    return NULL;
  }
  if (s = newextractSymbIfSame(exp, fname)) {
    return s; 
  } else if (s = newfindVarRefInExpTree(fname, exp->lhs())) {
    return s;
  } else if (s = newfindVarRefInExpTree(fname, exp->rhs())) {
    return s;
  }
  return NULL;
}

int main () {

  SgProject *p;
  SgFile *f;
  SgStatement *st;
  SgSymbol *symb;
  SgExpression *e;
  SgExpression *el;

  p = new SgProject("tst.proj");
  f = &(p->file(0));
  st = f->firstStatement();
  st = st->lexNext();

  el = st->expr(0);
  // get first value of expression list;
  if (symb = newfindVarRefInExpTree("testName", el)) {
    printf("YEEHAW!");
  }
  printf("Done!");
}

/* ---------------------------------------------------------------*/

(NOTE:  For testing, I inserted the example problem lines of code into 
a file tst.C, used pc++ to convert to a dep file "tst.dep", and put the 
dep file name ("tst.dep") into a file tst.proj.)



Let me know if there is a much more intelligent way of searching, or 
if I am doing something buggy in my code that is causing your
code problems.  

thanks a ton,

darryl



Follow-Up(s):