Rose2xaif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CPlusPlusCanon.cpp
Go to the documentation of this file.
1 
14 #include <algorithm>
15 #include "canon/SageCanon.hpp"
16 #include "util/Messages.hpp"
17 
18 namespace rose2xaif
19 {
20 
21  SgStatement *
23  {
24  SgFunctionDeclaration * fdecl = isSgFunctionDeclaration(stmt);
25 
26  UNPARSEANDPRINT_MACRO(1, fdecl, "Canonicalizing Function Declaration ");
28  UNPARSEANDPRINT_MACRO(1, fdecl, "Template specialized fn declaration ");
30  //SHK - TO DO C++ TEMPLATES - Have to add logic to check whether this specialization needs to be canonicalized or not. For now, simply return.
31  return stmt;
32  }
33  SgName fn = fdecl->get_name();
34  SgSymbol *func_name = rose2xaif::findSymbolFromStmt(fn, fdecl);
35  SgFunctionSymbol * func_namet = isSgFunctionSymbol(func_name);
36  SgVariableSymbol * retval = NULL;
37  int isfrwrd = fdecl->isForward();
38  if (func_name == NULL) {
39  //this can possibly be forward declaration so it has no SgSymbol attached fromt the SymbolsAndActiveAnalysis::handleSymbols pass
40  if (isfrwrd) {
41  //SgFunctionDefinition * fdef=fdecl->get_definition_ref();
42  SgName mang = fdecl->get_mangled_name();
43  //if(!fdef)
44  // fatal("no def for forward decl %s", mang.str());
45  //above does not work, need to try to find function def in the same scope that has the same mangled name
46  //this would be global scope
47  //SHK - sgFile->root is not longer supported.
48  //SgGlobal * sglobal=getSageFile()->get_root();
49  SgGlobal * sglobal = globalScope(getSageFile());
50  SgDeclarationStatementPtrList& gldecls = sglobal->get_declarations();
51  if (gldecls.size() == 0)
52  fatal("unable to match forward declaration of " << mang.str());
53 
54  for (SgDeclarationStatementPtrList::iterator iter = gldecls.begin(); iter
55  != gldecls.end(); iter++) {
56  SgDeclarationStatement *cdcl = *iter;
57  SgFunctionDeclaration * curf = isSgFunctionDeclaration(cdcl);
58  if (curf) {
59  SgName cmang = curf->get_mangled_name();
60  if ((cmang == mang) && (cdcl != fdecl)) {
61  func_name = rose2xaif::findSymbolFromStmt(fn, cdcl);
62  func_namet = isSgFunctionSymbol(func_name);
63  if (func_namet) {
64  debugMsg(3, "found symbol for forward decl of " << mang.str());
65  addSymbolToStmt(func_name, fdecl);
66  break;
67  }
68  }
69  }
70  }
71  if (!func_namet)
72  fatal("unable to match frwd decl of "<< mang.str());
73  } else {
74  fatal("cannot find symbol for function "<< fn.str());
75  }
76  }
78 
79  if (!isfrwrd) {
80  debugMsg(2, "canonicalizing function definition");
81  //need to get definition
82 
83  SgFunctionDefinition * fdef = fdecl->get_definition();
84 
85  if (!fdef)
86  fatal(
87  "in canonicalizeStmt: function declaration that is not forward but does not have function definition");
88  //DeclSpec& spec=convertDeclSpec(pstmt);
89  //spec.setType(funcdecl_stmt->get_orig_return_type());
90  //Declarator& decl = convertSingleDeclarator(pstmt);
91  //DeclarationList& members=convertDeclarationList(pstmt, NULL, bbb->get_body()->get_statements(),NULL); //this should be the body...
92  //pdecl = new FuncDefinition(spec, decl, members);
93  //this peice is from old Sage to ADIF conversion ...
94 
95  //this will most certainly need to be done somehow..
96  /*
97  if(func_name)
98  {
99  int sageFlags = getSageFlags(func_name);
100 
101  //is the symbol inactive?
102  if (sageFlags & SAGE_INACTIVE)
103  {
104  pdecl->setInactive();
105 
106  //should the inactive function have body?
107  if (state.isFlag(StateManager::NO_INACTIVE_FUNC_DEF_F) &&
108  !funcdecl_stmt->isStatic())
109  {
110  members.flush();
111  }
112  }
113 
114  //allow the conversion of a function into a procedure?
115  if (sageFlags & SAGE_NO_FUNC_TO_PROC)
116  {
117  ((FuncDefinition*)pdecl)->setNoConversion();
118  }
119  }
120  */
121  //in simplest case canon decl and then the body
122  //TO DO canon decl
123  //convert func to proc (unless it is a member func that dentoes overloaded operator (noConversion
124  //used to take care of that)
125  //pull out init expressions (in a definition?, this would be Ok in C++, but not C, ignore for now)
126  enterFunc(fdef);
127  SgBasicBlock * fbody = fdef->get_body();
128  SgStatementPtrList & fmembers = fbody->get_statements();
129  canonicalizeStmtList(&fmembers);
130 
131  //now need to insert all aux/tmp declaration and statements created during canonicaliztion
132  /*
133  SgStatementPtrList & newstmts=getStmts();
134  //we cannot put statements before declarations!!!
135  //find first stmt
136  SgStatementPtrList::iterator iterb;
137  for (iterb=fmembers.begin(); iterb!=fmembers.end(); iterb++)
138  {
139  if(!isSgDeclarationStatement(*iterb))
140  break;
141  }
142  //iterb should point to first non-decl
143  fmembers.splice(iterb, newstmts);
144  //for(SgStatementPtrList::iterator iters=newstmts.end();
145  // iters!=newstmts.begin(); iters--)
146  //{
147  // fmembers.insert(iterb,*iters);
148  //}
149  //now insert decls, before first stmt
150  SgStatementPtrList & newdecls=getDecls();
151  //find first stmt again
152  for (iterb=fmembers.begin(); iterb!=fmembers.end(); iterb++)
153  {
154  if(!isSgDeclarationStatement(*iterb))
155  break;
156  }
157  fmembers.splice(iterb, newdecls);
158  */
159  leaveFunc();
160  }
161  SgNode * parent = fdecl->get_parent();
162  if (parent == NULL) {
163 
164  fatal("Parent of function declaration is NULL");
165  } else {
166  if (isSgGlobal(parent))
167  UNPARSEANDPRINT_MACRO(3, parent, "Unparsed parent is Global ");
168  }
169  }
170 
171  SgStatement *
173  {
174  SgReturnStmt * retst = isSgReturnStmt(stmt);
175  const char * current_file = getFileName();
176 
177  UNPARSEANDPRINT_MACRO(1, retst, "canonicalizing return stmt in StmtCanon ");
178 
179  //SHK -> Replaced the following statement with the correct function call
180  //SgExpression * retexp=retst->get_return_expr();
181  SgExpression * retexp = retst->get_expression();
182  SgExpression * newretexp = canonicalizeExpr(retexp, PULL_EFFECT);
183  //not sure what to do if newretexp is NULL
184  if (!newretexp) {
185  fatal("Canonicalizing return stmt, new retrun expression is NULL.");
186  } else {
187  UNPARSEANDPRINT_MACRO(3, newretexp, "canonicalized return stmt is ");
188  }
189  SgFunctionDefinition* curfdef = getFuncScope();
190  if (curfdef) {
191  SgName fname = curfdef->get_declaration()->get_name();
192 
193  SgSymbol * fsymb = rose2xaif::findSymbolFromStmt(fname, curfdef);
194  if (!fsymb)
195  fatal("No function symbol found in return stmt canonicalization.");
196 
197  //need to create deref expression with fsymb, and then assignment with retexp
198  SgVariableSymbol*vsymb = getRetVal(isSgFunctionSymbol(fsymb));
199  //if there is no retnm, skip the rest
200  if (vsymb) {
201  debugMsg(3, "vsymb option");
203  retst->set_expression(newretexp);
204  } else {
205  retst->set_expression(newretexp);
206  }
207  } else {
208  fatal("return statement without function scope");
209  }
210  }
211 
212  SgStatement *
214  SgStatement * stmt)
215  {
216  SgMemberFunctionDeclaration * memfdecl =
217  isSgMemberFunctionDeclaration(stmt);
218  UNPARSEANDPRINT_MACRO(1, memfdecl, "canonicalizing member function declaration ");
219  if (memfdecl->isSpecialization())
220  debugMsg(1, "Template specialized member function ");
221 
222  SgSpecialFunctionModifier & modifier =
223  memfdecl->get_specialFunctionModifier();
224  SgName fn = memfdecl->get_name();
225  SgSymbol *func_name = rose2xaif::findSymbolFromStmt(fn, memfdecl);
226  SgFunctionSymbol * func_namet = isSgFunctionSymbol(func_name);
227 
228  //SHK -TO DO FOR C++: Set the names in the decl and the symbols to add the prefix "ad_"
229 
230  SgVariableSymbol * retval = NULL;
231  int isfrwrd = memfdecl->isForward();
232  if (func_name == NULL) {
233  //this can possibly be forward declaration so it has no SgSymbol attached fromt the SymbolsAndActiveAnalysis::handleSymbols pass
234  if (isfrwrd) {
235  //SgFunctionDefinition * fdef=memfdecl->get_definition_ref();
236  SgName mang = memfdecl->get_mangled_name();
237  //if(!fdef)
238  // fatal("no def for forward decl %s", mang.str());
239  //above does not work, need to try to find function def in the same scope that has the same mangled name
240  //this would be global scope
241  //SHK
242  //SgGlobal * sglobal=getSageFile()->get_root();
243  SgGlobal * sglobal = globalScope(getSageFile());
244  SgDeclarationStatementPtrList& gldecls = sglobal->get_declarations();
245  if (gldecls.size() == 0)
246  fatal("unable to match forward declaration of "<< mang.str());
247 
248  for (SgDeclarationStatementPtrList::iterator iter = gldecls.begin(); iter
249  != gldecls.end(); iter++) {
250  SgDeclarationStatement *cdcl = *iter;
251  SgFunctionDeclaration * curf = isSgFunctionDeclaration(cdcl);
252  if (curf) {
253  SgName cmang = curf->get_mangled_name();
254  if ((cmang == mang) && (cdcl != memfdecl)) {
255  func_name = rose2xaif::findSymbolFromStmt(fn, cdcl);
256  func_namet = isSgFunctionSymbol(func_name);
257  if (func_namet) {
258  debugMsg(3, "1 found symbol for forward decl of " <<
259  mang.str());
260  addSymbolToStmt(func_name, memfdecl);
261  break;
262  }
263  }
264  }
265  }
266  if (!func_namet) {
267  fatal("unable to match frwd decl of "<< mang.str());
268  }
269  } else {
270  fatal("cannot find symbol for function "<< fn.str());
271  }
272  }
273  if (!isfrwrd) {
274  debugMsg(3, "1 canonicalizing member function definition");
275  //need to get definition
276  SgFunctionDefinition * fdef = memfdecl->get_definition();
277  if (!fdef)
278  fatal(
279  "in canonicalizeStmt: member function declaration that is not forward but does not have function definition");
280  enterFunc(fdef);
281  SgBasicBlock * fbody = fdef->get_body();
282  SgStatementPtrList & fmembers = fbody->get_statements();
283  canonicalizeStmtList(&fmembers);
284  leaveFunc();
285 
286  //SHK If it is not forward then one should be able to change the function return type (if it is of the class) right here.
287  SgClassDefinition * classdef = memfdecl->get_class_scope();
288  if (!classdef)
289  fatal("Classdef is NULL");
290  SgClassDeclaration * classdecl = classdef->get_declaration();
291  if (!classdecl)
292  fatal("Classdef->get_declaration is NULL");
293  std::string name = classdecl->get_name();
294  debugMsg(3, "1 Class name : " << name);
295 
296  SgClassType * newclasstype = classdecl->get_type();
297  UNPARSEANDPRINT_MACRO(3, classdecl, "1 Class Decl : ");
298  UNPARSEANDPRINT_MACRO(3, memfdecl, "1 Old decl : ");
299  UNPARSEANDPRINT_MACRO(3, memfdecl->get_type(), "1 Old type : ");
300  memfdecl->get_type()->set_return_type(newclasstype);
301  UNPARSEANDPRINT_MACRO(3, memfdecl, "1 New decl : ");
302 
303  //SHK If the function is a parametrized constructor of a derived class that passes values to the base class constructor,
304  //The name of the base class must be canonicalized. This action is being performed here as the 'call' is conceptually linked to the definition of
305  //the constructor.
306  //SHK TO DO C++ .. this must be done only for those base classes that are 'active'
307  SgSpecialFunctionModifier & modifier
308  = memfdecl->get_specialFunctionModifier();
309  if (modifier.isConstructor()) {
310  SgCtorInitializerList * constructorList =
311  memfdecl->get_CtorInitializerList();
312  if (constructorList) {
313  VERIFYUNPARSE_MACRO(constructorList);
314  SgInitializedNamePtrList & ctorslist = constructorList-> get_ctors();
315  for (SgInitializedNamePtrList::iterator ctor = ctorslist.begin(); ctor
316  != ctorslist.end(); ++ctor) {
317  SgInitializedName * initializedName = (*ctor);
318  std::string name = initializedName->get_name();
319  if (TRUE) { //SHK This check should be to see if the class associated with this name is active.
320  std::string prefstr(g_rose2xaif_state->getPrefix());
321  name = prefstr + name;
322  initializedName->set_name(name);
323  }
324  debugMsg(3, "Constructor initializer list entry is : " << name);
325  }
326  }
327  }
328  } else {
329  ;
330  }
331  }
332 
333 
334  void
335  CanonStateCPlusPlus::convertReturnType(SgFunctionType * ft) //this is only for pointer types, others hopefully converted in canonicalization
336  //apparently others not not done during canonicalization will do here
337  {
338  SgType * oldt = ft->get_return_type();
339  SgPointerType * tptr = NULL;
340  if (tptr = isSgPointerType(oldt)) {
341  //debugMsg(2,"pointer");
342  SgPointerType * newtptr = new SgPointerType();
343  SgPointerType * newcur = newtptr;
344  SgPointerType * prevt = tptr;
345  SgType * currt = tptr->get_base_type();
346  while (tptr = isSgPointerType(currt)) {
347  prevt = isSgPointerType(prevt->get_base_type());
348  currt = tptr->get_base_type();
349  newcur->set_base_type(new SgPointerType());
350  newcur = isSgPointerType(newcur->get_base_type());
351  }
352  if (currt == NULL)
353  fatal(
354  "SageCanon.cpp: Null type argument encountered in convertReturnType(SgFunctionType *, CanonState&) Pos 1.");
355  if (isActiveFloatType(currt)) {
356  //Sg_File_Info * finfo = new Sg_File_Info(getFileName(), 1, 1);
357  Sg_File_Info * finfo = Sg_File_Info::generateFileInfoForTransformationNode(getFileName());
358  SgTypedefDeclaration * tdecl = new SgTypedefDeclaration(finfo,
359  "DERIV_TYPE", currt);
360 
361 #ifdef ROSE_0_8_6a_or_higher
362  //SHK - sgFile->root is not longer supported.
363  //tdecl->set_scope(&(getSageFile()->root()));
364  tdecl->set_scope(globalScope(getSageFile()));
365 #endif
366  //SHK - sgFile->root is not longer supported.
367  //tdecl->set_parent(&(getSageFile()->root()));
368  tdecl->set_parent(globalScope(getSageFile()));
369  SgType * newt = tdecl->get_type();
370  //prevt->set_base_type(newt);
372  newcur->set_base_type(currt);
373  ft->set_orig_return_type(newtptr);
374  ft->set_return_type(newtptr);
375  }
376  } else {
377  //need to convert to a procedure?
378  //debugMsg(3,"else oldt is %s", oldt->sage_class_name());
379  if (oldt == NULL)
380  fatal(
381  "SageCanon.cpp: Null type argument encountered in convertReturnType(SgFunctionType *, CanonState&) Pos 2.");
382  if (isActiveFloatType(oldt)) {
383  //debugMsg(3,"converting to void");
384  SgTypeVoid * vt = new SgTypeVoid();
385  ft->set_orig_return_type(vt);
386  ft->set_return_type(vt);
387  SgTypePtrList & tpl = ft->get_arguments();
388  SgTypePtrList::iterator iter = tpl.begin();
389  SgType * ptype = new SgPointerType(oldt);
390  ft->insert_argument(iter, ptype);
391  }
392 
393  }
394  }
395 
396 
397  void
399  {
400 #ifdef ROSE_0_8_9a_or_higher
401  const char * current_file = getFileName();
402 #else
403  char * current_file=getFileName();
404 #endif
406  for (SgTypePtrList::iterator argiter = tlist->begin(); argiter
407  != tlist->end(); ++argiter) {
408  SgType * tt = *argiter;
409  SgPointerType * tptr = NULL;
410  if (tt == NULL)
411  fatal(
412  "SageCanon.cpp: Null type argument encountered in convertTypeList(SgTypePtrList *tlist). pos 1");
413  if (isActiveFloatType(tt)) {
414  //Sg_File_Info * finfo = new Sg_File_Info(current_file, 1, 1);
415  Sg_File_Info * finfo = Sg_File_Info::generateFileInfoForTransformationNode(current_file);
416  SgTypedefDeclaration * tdecl = new SgTypedefDeclaration(finfo,
417  "DERIV_TYPE", tt);
418  //SHK - sgFile->root is not longer supported.
419  //tdecl->set_parent(&(getSageFile()->root()));
420  tdecl->set_parent(globalScope(getSageFile()));
421 #ifdef ROSE_0_8_6a_or_higher
422  //SHK - sgFile->root is not longer supported.
423  //tdecl->set_scope(&(getSageFile()->root()));
424  tdecl->set_scope(globalScope(getSageFile()));
425 #endif
426 
427  SgType * newt = tdecl->get_type();
428  SgReferenceType * rt = NULL;
429  SgArrayType * at = NULL;
430  if (rt = isSgReferenceType(tt)) {
431  SgReferenceType * rtcopy = new SgReferenceType();
432  rtcopy->set_base_type(tt);
433  *argiter = rtcopy;
434  } else if (at = isSgArrayType(tt)) {
435  SgArrayType * rtcopy = new SgArrayType();
436  rtcopy->set_base_type(tt);
437  rtcopy->set_index(at->get_index());
438  *argiter = rtcopy;
439  } else {
440  *argiter = tt;
441  }
442  } else if (tptr = isSgPointerType(tt)) {
443  SgPointerType * newtptr = new SgPointerType();
444  SgPointerType * newcur = newtptr;
445  SgPointerType * prevt = tptr;
446  SgType * currt = tptr->get_base_type();
447  while (tptr = isSgPointerType(currt)) {
448  prevt = isSgPointerType(prevt->get_base_type());
449  currt = tptr->get_base_type();
450  newcur->set_base_type(new SgPointerType());
451  newcur = isSgPointerType(newcur->get_base_type());
452  }
453  if (currt == NULL)
454  fatal(
455  "SageCanon.cpp: Null type argument encountered in convertTypeList(SgTypePtrList *tlist). pos 2");
456  if (isActiveFloatType(currt)) {
457  //Sg_File_Info * finfo = new Sg_File_Info(current_file, 1, 1);
458  Sg_File_Info * finfo = Sg_File_Info::generateFileInfoForTransformationNode(current_file);
459  SgTypedefDeclaration * tdecl = new SgTypedefDeclaration(finfo,
460  "DERIV_TYPE", currt);
461  //SHK - sgFile->root is not longer supported.
462  //tdecl->set_parent(&(getSageFile()->root()));
463  tdecl->set_parent(globalScope(getSageFile()));
464 #ifdef ROSE_0_8_6a_or_higher
465  //SHK - sgFile->root is not longer supported.
466  //tdecl->set_scope(&(getSageFile()->root()));
467  tdecl->set_scope(globalScope(getSageFile()));
468 #endif
469  SgType * newt = tdecl->get_type();
470  //prevt->set_base_type(newt);
471  newcur->set_base_type(currt);
472  *argiter = newtptr;
473  }
474  }
475  }
476  }
477 
478  void
480  {
481  //string st=iname->get_name().getString();
482  //debugMsg(2,"in convertInitializedName for %s", st.c_str());
483  SgType * oldt = iname->get_type();
484  SgPointerType * tptr = NULL;
486 #ifdef ROSE_0_8_9a_or_higher
487  const char * current_file = getFileName();
488 #else
489  char * current_file=getFileName();
490 #endif
491  if (oldt == NULL)
492  fatal(
493  "SageCanon.cpp: Null type argument encountered in convertInitializedName(SgInitializedName *, CanonState& ). pos 1");
494  if (isActiveFloatType(oldt)) {
495  debugMsg(1, "Its an active float type");
496  //Sg_File_Info * finfo = new Sg_File_Info(current_file, 1, 1);
497  Sg_File_Info * finfo = Sg_File_Info::generateFileInfoForTransformationNode(current_file);
498 #ifndef AD_FORTRAN_SPECIFIC
499  SgTypedefDeclaration * tdecl = new SgTypedefDeclaration(finfo,
500  "DERIV_TYPE", oldt);
501  //SHK - sgFile->root is not longer supported.
502  //tdecl->set_parent(&(getSageFile()->root()));
503  tdecl->set_parent(globalScope(getSageFile()));
504 #ifdef ROSE_0_8_6a_or_higher
505  //SHK - sgFile->root is not longer supported.
506  //tdecl->set_scope(&(getSageFile()->root()));
507  tdecl->set_scope(globalScope(getSageFile()));
508 #endif
509  SgType * newt = tdecl->get_type();
510 #else
511  SgType * newt = oldt;
512 #endif
513  SgReferenceType * rt = NULL;
514  SgArrayType * at = NULL;
515  if (rt = isSgReferenceType(oldt)) {
516  SgReferenceType * rtcopy = new SgReferenceType();
517  rtcopy->set_base_type(oldt);
518  iname->set_type(rtcopy);
519  } else if (at = isSgArrayType(oldt)) {
520  SgArrayType * rtcopy = new SgArrayType();
521  SgType * baset = at->get_base_type();
522  SgArrayType * newbaset = rtcopy;
523  SgArrayType * prevtype = rtcopy;
524  SgExpression * previndex = at->get_index();
525  prevtype->set_index(previndex);
526  while (isSgArrayType(baset)) {
527  newbaset = new SgArrayType();
528  prevtype->set_base_type(newbaset);
529  newbaset->set_index((isSgArrayType(baset))->get_index());
530  baset = (isSgArrayType(baset))->get_base_type();
531  prevtype = newbaset;
532  }
533  newbaset->set_base_type(oldt);
534  iname->set_type(rtcopy);
535  } else {
536  iname->set_type(oldt);
537  }
538  } else if (tptr = isSgPointerType(oldt)) {
539  debugMsg(1, "Its a pointer type");
540  SgPointerType * newtptr = new SgPointerType();
541  SgPointerType * newcur = newtptr;
542  SgPointerType * prevt = tptr;
543  SgType * currt = tptr->get_base_type();
544  while (tptr = isSgPointerType(currt)) {
545  prevt = isSgPointerType(prevt->get_base_type());
546  currt = tptr->get_base_type();
547  newcur->set_base_type(new SgPointerType());
548  newcur = isSgPointerType(newcur->get_base_type());
549  }
550  if (currt == NULL)
551  fatal(
552  "SageCanon.cpp: Null type argument encountered in convertInitializedName(SgInitializedName *, CanonState& ). pos 2");
553  if (isActiveFloatType(currt)) {
554  //Sg_File_Info * finfo = new Sg_File_Info(current_file, 1, 1);
555  Sg_File_Info * finfo = Sg_File_Info::generateFileInfoForTransformationNode(current_file);
556  SgTypedefDeclaration * tdecl = new SgTypedefDeclaration(finfo,
557  "DERIV_TYPE", currt);
558  //SHK - sgFile->root is not longer supported.
559  //tdecl->set_parent(&(getSageFile()->root()));
560  tdecl->set_parent(globalScope(getSageFile()));
561 #ifdef ROSE_0_8_6a_or_higher
562  //SHK - sgFile->root is not longer supported.
563  //tdecl->set_scope(&(getSageFile()->root()));
564  tdecl->set_scope(globalScope(getSageFile()));
565 #endif
566 
567  SgType * newt = tdecl->get_type();
568  //prevt->set_base_type(newt);
569  SgArrayType * at = NULL;
570  if (at = isSgArrayType(currt)) {
571  debugMsg(3, "pointer to an array");
572  SgArrayType * rtcopy = new SgArrayType();
573  SgType * baset = at->get_base_type();
574  SgArrayType * newbaset = rtcopy;
575  SgArrayType * prevtype = rtcopy;
576  SgExpression * previndex = at->get_index();
577  prevtype->set_index(previndex);
578  while (isSgArrayType(baset)) {
579  newbaset = new SgArrayType();
580  prevtype->set_base_type(newbaset);
581  newbaset->set_index((isSgArrayType(baset))->get_index());
582  baset = (isSgArrayType(baset))->get_base_type();
583  prevtype = newbaset;
584  }
585  newbaset->set_base_type(currt);
586  newcur->set_base_type(rtcopy);
587  iname->set_type(newtptr);
588  } else {
589  newcur->set_base_type(currt);
590  iname->set_type(newtptr);
591  }
592  }
593  }
594  }
595 
596  void
598  {
599  if (!node) {
600  debugMsg(3, "visited with 0-Node!");
601  return;
602  }
603  //debugMsg(2,"visiting node %s", node->sage_class_name());
604  SgVariableDeclaration * stmt = NULL;
605  SgFunctionDeclaration *fdecl = NULL;
606  SgGlobal * sg = NULL;
607  SgClassDefinition * sgcldf = NULL;
608  SgClassDeclaration * sgcldcl = NULL;
609  SgTypedefDeclaration * sgtpdfdcl = NULL;
610  SgVarRefExp * varrefexp = NULL;
611  if ((stmt = isSgVariableDeclaration(node))
612  && (!canon.isFromSysInclude(stmt))) {
613  //remove sizeof hack helper declarations
614  SgInitializedNamePtrList &allvars = stmt->get_variables();
615  SgInitializedName * tv = allvars.front();
616  SgName valname = tv->get_name();
617  std::string valstr = valname.getString();
618  std::string type_sizeof_prefix_string = TYPE_SIZEOF_PREFIX_STRING;
619  int sizeof_prefix_len = type_sizeof_prefix_string.size();
620  if (valstr.substr(0, sizeof_prefix_len) == type_sizeof_prefix_string) {
621  //remove this declaration
622  SgGlobal * sggl = NULL;
623  if (sggl = isSgGlobal(stmt->get_parent())) {
624  debugMsg(3, "removing decl of " << valname.str());
625  sggl->remove_statement(stmt);
626  }
627 
628  }
629 
630  bool extra_def =
631  stmt->get_variableDeclarationContainsBaseTypeDefiningDeclaration();
632  if (extra_def) {
633  debugMsg(3, "extra definition inside variable declaration");
634  //need to traverse the definition since ROSE does not automatically do that
635  SgType * vt = tv->get_type();
636  SgClassType * clt = isSgClassType(vt); //what about other named types?
637  if (clt) {
638  SgDeclarationStatement * decl = clt->get_declaration();
639  SgClassDeclaration * cldecl = isSgClassDeclaration(decl);
640  if (cldecl) {
641  SgClassDefinition * cldef = cldecl->get_definition();
642  //visit(cldef);
644  preorder);
645  }
646  }
647  }
648  SageStatementAttr * stattr = getStatementAttr(stmt);
649  if (stattr) {
650  std::list<SgSymbol*> symlist = stattr->symbols;
651  int dsize = symlist.size();
652  if (dsize > 1) {
653  fatal(
654  "ConvertDeclarationsPass::visit found var decl with more than one symbol");
655  } else {
656  SgSymbol * symdecl = symlist.front();
657  SgInitializedName * iname = stmt->get_decl_item(symdecl->get_name());
658  //check for function pointer
659  SgPointerType * pt = isSgPointerType(symdecl->get_type());
660  SgFunctionType *ft;
661  if (pt && (ft = isSgFunctionType(pt->get_base_type()))) {
663  iname->set_type(new SgPointerType(ft));
664  SgTypePtrList & tpl = ft->get_arguments();
665  canon.convertTypeList(&tpl);
666  }
667 
668  //do this only if symbol is active
669  else if (canon.isActiveSymbol(symdecl)) {
671  }
672  }
673  }
674  } else if ((fdecl = isSgFunctionDeclaration(node))
675  && (!canon.isFromSysInclude(fdecl))) {
676  UNPARSEANDPRINT_MACRO(3, fdecl, "unparsed defnition at ConvertDeclarationsPass::visit beginning ");
677  SgName fn = fdecl->get_name();
678  std::string funstr = fn.getString();
679  std::string expr_sizeof_prefix_string = EXPR_SIZEOF_PREFIX_STRING;
680  int sizeof_prefix_len = expr_sizeof_prefix_string.size();
681  if (funstr.substr(0, sizeof_prefix_len) == expr_sizeof_prefix_string) {
682  //remove this declaration
683  SgGlobal * sggl = NULL;
684  if (sggl = isSgGlobal(node->get_parent())) {
685  debugMsg(3, "removing decl of " << funstr.c_str());
686  sggl->remove_statement(fdecl);
687  }
688  } else {
690  //SHK DONE C++ -> For C++ function declarations, return types do not need to be changed to DERIV_TYPE etc.
691  SgSymbol *func_name = rose2xaif::findSymbolFromStmt(fn, fdecl);
692  if (func_name) {
693  SageSymbolAttr * attr = getSymbolAttr(func_name);
694  if (attr->flags & SAGE_PREPEND) {
695  //SHK - This is where we have to handle operators and destructors...
696  if (SgMemberFunctionDeclaration * memfdecl
697  = isSgMemberFunctionDeclaration(node)) {
698  SgSpecialFunctionModifier & modifier =
699  memfdecl->get_specialFunctionModifier();
700  if (modifier.isDestructor()) {
701  debugMsg(3,
702  " Changing the name of the member function declaration - Desctructor");
703  std::string newname;
704  std::string prefstr(canon.g_rose2xaif_state->getPrefix());
705  newname = "~" + prefstr;
706  std::string oldstr(fn.str());
707  oldstr = oldstr.substr(1, oldstr.length());
708  newname += oldstr;
709  SgName newsgname(newname.c_str());
710  fdecl->set_name(newsgname);
711  } else if (modifier.isOperator()) {
712  ;
713  } else {
714  debugMsg(3,
715  " Changing the name of the member function declaration");
716  std::string newname;
717  std::string prefstr(canon.g_rose2xaif_state->getPrefix());
718  newname = prefstr;
719  std::string oldstr(fn.str());
720  newname += oldstr;
721  SgName newsgname(newname.c_str());
722  fdecl->set_name(newsgname);
723  }
724  } else {
725  if (SgTemplateInstantiationFunctionDecl * tinstdecl
726  = isSgTemplateInstantiationFunctionDecl(fdecl)) {
727  SgTemplateFunctionDeclaration * tdecl =
728  tinstdecl->get_templateDeclaration();
729  debugMsg(
730  1,
731  "SHK TO DO C++ TEMPLATES Not Changing the name of the template function declaration");
732  if (tdecl) {
733  UNPARSEANDPRINT_MACRO(1, tdecl, "SHK TO DO C++ TEMPLATES : template declaration is : ");
734  }
736  debugMsg(1,
737  "SHK TO DO C++ TEMPLATES Furthermore, It is a specialization");
738  }
740  fdecl)) {
741  debugMsg(1, "SHK TO DO C++ TEMPLATES It is a specialization");
742  } else {
743  SgSpecialFunctionModifier & modifier =
744  fdecl->get_specialFunctionModifier();
745  std::string newname;
746  std::string prefstr(canon.g_rose2xaif_state->getPrefix());
747  newname = prefstr;
748  std::string oldstr(fn.str());
749  if (oldstr.compare("main") != 0 || modifier.isOperator()) {
750  newname += oldstr;
751  SgName newsgname(newname.c_str());
752  fdecl->set_name(newsgname);
753  }
754  }
755  }
756  }
757  }
758  //SHK DONE C++ - Removed the conversion of the return type to DERIV_TYPE.
759  //canon.convertReturnType(fdecl->get_type());
760  SgInitializedNamePtrList & arglist = fdecl->get_args();
761  for (SgInitializedNamePtrList::iterator argiter = arglist.begin(); argiter
762  != arglist.end(); ++argiter) {
763  //check for function pointers
764  SgInitializedName * iname = *argiter;
765  SgPointerType * pt = isSgPointerType(iname->get_type());
766  SgFunctionType *ft;
767  if (pt && (ft = isSgFunctionType(pt->get_base_type()))) {
768  //SHK DONE C++ - Removed the conversion of the return type to DERIV_TYPE.
769  //convert.convertReturnType(ft);
770  iname->set_type(new SgPointerType(ft));
771  SgTypePtrList & tpl = ft->get_arguments();
772  //SHK DONE C++ - Removed the conversion of the arguments to DERIV_TYPE.
773  //convert.convertTypeList(&tpl);
774  } else {
775  //SHK DONE C++ - Removed the conversion of the function name to DERIV_TYPE.
776  ;// canon.convertInitializedName(iname);
777  }
778  }
779  }
780  } else if (sgcldf = isSgClassDefinition(node)) {
781  debugMsg(3, "found class def");
782  } else if (sgcldcl = isSgClassDeclaration(node)) {
783  debugMsg(3, "found class decl");
784  } else if (sgtpdfdcl = isSgTypedefDeclaration(node)) {
785  SgType * tp1 = sgtpdfdcl->get_base_type();
786  if (tp1) {
787  debugMsg(3, "base type is " << tp1->sage_class_name());
788  SgClassType * cltp = isSgClassType(tp1);
789  if (cltp) {
790  SgName clnm = cltp->get_name();
791  const char * clnmstr = clnm.str();
792  if (clnmstr == NULL) {
793  debugMsg(3, "class name is empty, found anon. typdef");
794  SgDeclarationStatement * cldecl = cltp->get_declaration();
795  if (cldecl) {
796  SgClassDeclaration * clcldecl = isSgClassDeclaration(cldecl);
797  if (clcldecl) {
798  SgClassDefinition* cldef = clcldecl->get_definition();
799  if (cldef) {
800  SgDeclarationStatementPtrList dl = cldef->get_members();
801  for (SgDeclarationStatementPtrList::iterator iter =
802  dl.begin(); iter != dl.end(); iter++)
803  visit(*iter); //this might not be good enough, does not go inside compound nodes
804  }
805  }
806  }
807  }
808  }
809  }
810  }
811  /*
812  else if(isSgBasicBlock(node))
813  {
814  char * newcode="#include \"ddd.h\"";
815  char * loc="int i;";
816  char * glob="int j;";
817  bool bt=TRUE;
818  bool bf=FALSE;
819  node->insertSourceCode(*queryGlobalProject, newcode, loc, glob, bt, bt);
820  }
821  */
822  else if (varrefexp = isSgVarRefExp(node)) {
823  SgVariableSymbol * vs = varrefexp->get_symbol();
824  if (vs) {
825  SgName varname = vs->get_name();
826  std::string valstr = varname.getString();
827  std::string type_sizeof_prefix_string = TYPE_SIZEOF_PREFIX_STRING;
828  int sizeof_prefix_len = type_sizeof_prefix_string.size();
829  if (valstr.substr(0, sizeof_prefix_len) == type_sizeof_prefix_string) {
830  SgExpression * retexp = NULL;
831  //convert to a sizeof operator
832  Sg_File_Info * finfo = node->get_file_info();
833 
834 #ifdef ROSE_0_8_9a_or_higher
835  const char * filename1 = finfo->get_filename(); //this is the same filename as used in Boyana's script
836 #else
837  char * filename1=finfo->get_filename(); //this is the same filename as used in Boyana's script
838 #endif
839  //Sg_File_Info * finfo1 = new Sg_File_Info(filename1, 1, 1);
840  Sg_File_Info * finfo1 = Sg_File_Info::generateFileInfoForTransformationNode(filename1);
841  //char * filename2=finfo->getCurrentFilename(); //this is NULL
842  //debugMsg(3,"%s", filename1);
843  std::string filestr = filename1;
844  int filelen = filestr.size();
845  int count_len = 1;
846  std::string sizeof_type = valstr.substr(sizeof_prefix_len + filelen
847  - count_len, valstr.size() - sizeof_prefix_len - filelen
848  + count_len);
849  //debugMsg(3,"%s ", sizeof_type.c_str());
850  SgType * newt = NULL;
851  if (sizeof_type == "int") {
852  newt = new SgTypeInt();
853  retexp = new SgSizeOfOp(finfo1, NULL, newt, newt);
854  }
855  if (sizeof_type == "long_int") {
856  newt = SgTypeLong::createType();
857  retexp = new SgSizeOfOp(finfo1, NULL, newt, newt);
858  }
859  if (retexp) {
860  VERIFYUNPARSE_MACRO(retexp);
861  //debugMsg(3,"retexp is %s", unp.c_str());
862  SgNode * parent = node->get_parent();
863  SgAssignInitializer * ai = NULL;
864  SgExprListExp *el = NULL;
865  if (ai = isSgAssignInitializer(parent)) {
866  //bug in ROSE sizeof does not unparse correctly inside initializer
867  ai->set_operand(retexp);
868  retexp->set_parent(ai);
869  } else if (el = isSgExprListExp(parent)) {
870  SgExpressionPtrList & lst = el->get_expressions();
871  for (SgExpressionPtrList::iterator iter = lst.begin(); iter
872  != lst.end(); iter++) {
873  if (*iter == node) {
874  *iter = retexp;
875  retexp->set_parent(parent);
876  break;
877  }
878  }
879  } else {
880  debugMsg(3, "sizeof parent is " << parent->sage_class_name());
881  fatal("implement sizeof for specified parent");
882  }
883  //have retexp eliminate init if needed due to ROSE bug
884  /*
885  bool insideInit=false;
886  if(ai)
887  insideInit=TRUE;
888  if(el)
889  {
890  while(1)
891  {
892  parent=parent->get_parent();
893  if(isSgAssignInitializer(parent))
894  {
895  insideInit=TRUE;
896  break;
897  }
898  else if(isSgStatement(parent))
899  {
900  break;
901  }
902  }
903  }
904  if(insideInit)
905  {
906  if(!ai)
907  ai=isSgAssignInitializer(parent);
908  SgNode * aip=ai->get_parent();
909  debugMsg(3,"aip is %s", aip->sage_class_name());
910  fatal("need to eliminate initialization");
911  }
912  */
913  }
914  //fatal ("convert sizeof");
915  }
916  }
917  }
918  }
919 
920  SgExpression *
922  int mode)
923  {
925  SgExpression * retexp = NULL;
926  SgExpression *expr = fcall;
927  UNPARSEANDPRINT_MACRO(1, fcall, "canonicalizing Function call ");
928 
929  SgVarRefExp * adExp = NULL; //SHK - Used to hold the canonicalized function pointer.
930  SgName adName;
931 
932  SgExprListExp * args = fcall->get_args();
933  SgExprListExp *newargs = args;
934 
935  SgExpression * func = fcall->get_function();
936  SgFunctionRefExp * fref = isSgFunctionRefExp(func);
937  if (fref) {
938  debugMsg(1, "It is a function ref exp ");
939  } else {
940  debugMsg(1, "It is NOT a function ref exp ");
941  }
942  SgSymbol * fs = NULL;
943  SgPointerDerefExp * pd;
944 
945  if (!fref) {
946  if (pd = isSgPointerDerefExp(func)) {
947  SgVarRefExp * fvar = isSgVarRefExp(pd->get_operand());
948  if (fvar) {
949  fs = fvar->get_symbol();
950  // SHK -NEW CODE BEGINS
951  //Here an expression adExp is created with a prefix "ad_". So adExp is created for every funtion call that happens through a function pointer.
952  adName = "ad_" + fs->get_name();
953  SgInitializer * adInitializer = NULL;
954  SgInitializedName * adInitializedName = new SgInitializedName(adName,
955  fs->get_type(), adInitializer, NULL);
956  Sg_File_Info * finfo_ad1 =
957  Sg_File_Info::generateFileInfoForTransformationNode(
958  expr->get_file_info()->get_filenameString());
959  Sg_File_Info * finfo_ad2 =
960  Sg_File_Info::generateFileInfoForTransformationNode(
961  expr->get_file_info()->get_filenameString());
962  adInitializedName->set_file_info(finfo_ad1);
963  SgVariableSymbol * adSymbol = new SgVariableSymbol(adInitializedName);
964  adExp = new SgVarRefExp(finfo_ad2, adSymbol);
965  debugMsg(1, "It is a function DEREF exp " << fs->get_name().str());
966  // SHK -NEW CODE ENDS
967  }
968  } else if (SgBinaryOp * binaryOp = isSgBinaryOp(func)) {
969  SgExpression* functionExpression = binaryOp->get_rhs_operand_i();
970  //classify_SgNode(functionExpression);
971  SgMemberFunctionRefExp * memberFunctionRefExp =
972  isSgMemberFunctionRefExp(functionExpression);
973  if (!memberFunctionRefExp)
974  fatal(
975  "ExprCanon.cpp In CanonicalizeExpression functioncallexp case, memberFunctionRefExp is NULL");
976  SgFunctionSymbol *fs_binaryOp = memberFunctionRefExp->get_symbol();
977  SgFunctionDeclaration * fdecl = fs_binaryOp->get_declaration();
978  std::string fun_name = fdecl->get_name();
979  debugMsg(1, "Found a possible member function or fancy call: "
980  << fun_name);
981  retexp = canonicalizeMemberFunctionCallExpr(expr, mode);
982  UNPARSEANDPRINT_MACRO(1, retexp, "returning from canonicalize FnrefExpr :");
983  return retexp;
984  } else {
985  fatal(
986  "Unsupported function call exp.");
987  }
988  } else {
989  fs = fref->get_symbol();
990  }
991  if (!fs) {
992  fatal("function call without corresponding symbol");
993  }
994  //check for sizeof hack
995  SgName funname = fs->get_name();
996  std::string funstr = funname.getString();
997  std::string expr_sizeof_prefix_string = EXPR_SIZEOF_PREFIX_STRING;
998  int sizeof_prefix_len = expr_sizeof_prefix_string.size();
999  if (funstr.substr(0, sizeof_prefix_len) == expr_sizeof_prefix_string) {
1000  //convert to a sizeof operator
1001  //second arg is the expression to use in sizeof
1002  SgExpressionPtrList & explst = args->get_expressions();
1003  SgExpressionPtrList::iterator iter = explst.begin();
1004  iter++;
1005  SgExpression *szexp = canonicalizeExpr(*iter, mode | PULL_EFFECT);
1006  Sg_File_Info * finfo =
1007  Sg_File_Info::generateFileInfoForTransformationNode(
1008  expr->get_file_info()->get_filenameString());
1009  retexp = new SgSizeOfOp(finfo, szexp, NULL, NULL);
1010  } else {
1011  if (!g_rose2xaif_state->isIntrinsicName(fs->get_name().str())
1012  || !optimized_canon) {
1013  UNPARSEANDPRINT_MACRO(1, fcall, "canonicalizing arg list of ");
1014  UNPARSEANDPRINT_MACRO(3, args, "Arg list Before canonicalization ");
1015  newargs = canonicalizeExprList(args, mode | PULL_EFFECT);
1016  UNPARSEANDPRINT_MACRO(3, args, "Arg list After ");
1017 
1018  } else {
1019  UNPARSEANDPRINT_MACRO(1, fcall, "skipping canonicalization of ");
1020  return fcall;
1021  }
1022  //CallExpression::pullArgs needs to go here
1023  //this needs to convert newargs
1024  SgFunctionSymbol * ffs = isSgFunctionSymbol(fs);
1025  SgFunctionDeclaration * fdecl = NULL;
1026  if (ffs) {
1027  fdecl = ffs->get_declaration();
1028  }
1029  if (fdecl && !isFromSysInclude(fdecl)) {
1030  debugMsg(1, "Case : 1 fdecl && !isFromSysInclude(fdecl)");
1031  SgInitializedNamePtrList & param_lst = fdecl->get_args();
1032  if (!g_rose2xaif_state->isIntrinsicName(fs->get_name().str())
1033  || !optimized_canon) {
1034  std::vector<SgType *> param_types;
1035  for (SgInitializedNamePtrList::iterator argiter = param_lst.begin(); argiter
1036  != param_lst.end(); ++argiter) {
1037  SgType * pt = (*argiter)->get_type();
1038  param_types.push_back(pt);
1039  }
1040  }
1041  } else if (pd) //call via a pointer, assume it is not pointing to a function from system include and pullArgs
1042  //can't really tell at compile time where the pointer will point but not many system includes
1043  //with floats
1044  {
1045  debugMsg(1, "Case : 2 pd");
1046  SgPointerType * pt = isSgPointerType(fs->get_type());
1047  if (pt) {
1048  SgFunctionType * ft = isSgFunctionType(pt->get_base_type());
1049  if (ft) {
1050  SgTypePtrList & tpl = ft->get_arguments();
1051  std::vector<SgType *> param_types;
1052  for (SgTypePtrList::iterator argiter = tpl.begin(); argiter
1053  != tpl.end(); ++argiter) {
1054  SgType * tt = *argiter;
1055  param_types.push_back(tt);
1056  }
1057  }
1058  }
1059  }
1060  fcall->set_args(newargs);
1061  newargs->set_parent(fcall);
1062  VERIFYUNPARSE_MACRO(fcall);
1063 
1064  if (mode & PULL_EFFECT) {
1065  debugMsg(1, "Case :mode& PULL_EFFECT ");
1066  //return pull(canon, pret);
1067  //we do not convert the call to the procedure
1068  //crete a temporary that is not a return arg
1069  //add assign expr stmt for this new temporary
1070  //return the var ref to temporary
1071  //we need to deal with malloc here
1072  retexp = expr;
1073  } else {
1074  //just convert to procedure if needed
1075  //this mean adding an extra arg in front
1076  //but for intrinsic functions it is different
1077 
1078  //if there is no retnm, skip the rest
1079  retexp = expr;
1080  }
1081  }
1082  UNPARSEANDPRINT_MACRO(1, retexp, "returning from canonicalize FnrefExpr");
1083  SgNode * parent = expr->get_parent();
1084  while (isSgFunctionDefinition(parent) == NULL) {
1085  parent = parent->get_parent();
1086  }
1087  UNPARSEANDPRINT_MACRO(1, parent, "Parent ");
1088  return retexp;
1089  }
1090 
1091  SgExpression *
1093  {
1094  SgExpression * retexp = NULL;
1096  //just for now
1097  //this is not the genral case
1098  debugMsg(1, "canonicalizing assign op exp");
1099  SgExpression *newlhs = canonicalizeExpr(asop->get_lhs_operand(), mode
1100  | PULL_EFFECT);
1101  //if we have a call on rhs and both lhs and rhs are active
1102  SgFunctionCallExp * fcall = NULL;
1103  //SgVarRefExp * vref=isSgVarRefExp(asop->get_lhs_operand());
1104  //if below should only be done if the particular function is to be converted to procedure
1105  //newlhs has to be active
1106  //more general expression than vref is possible...
1107  if ((fcall = isSgFunctionCallExp(asop->get_rhs_operand())) != NULL
1108  && isActiveExpr(newlhs) && ShouldConvertToProc(fcall)) //more conditons needed here!!!
1109  {
1110  SgExpression *newrhs = canonicalizeExpr(asop->get_rhs_operand(), mode);
1111  //SHK TO DO C++ - Does this lead to a memory leak?
1112  asop->set_lhs_operand(newlhs);
1113  asop->set_rhs_operand(newrhs);
1114  retexp = asop;
1115  } else {
1116  SgExpression *newrhs = NULL;
1117  if (isSgFunctionCallExp(asop->get_rhs_operand()))
1118  newrhs = canonicalizeExpr(asop->get_rhs_operand(), mode);
1119  else
1120  newrhs = canonicalizeExpr(asop->get_rhs_operand(), mode | PULL_EFFECT);
1121 
1122  asop->set_lhs_operand(newlhs);
1123  asop->set_rhs_operand(newrhs);
1124  retexp = asop;
1125  if (mode & PULL_EFFECT)
1126  retexp = pullExpr(asop);
1127  }
1128  return retexp;
1129  }
1130 
1131  SgExpression *
1132  CanonStateCPlusPlus::canonicalizeVarRefExpr(SgVarRefExp * varrefexp, int mode)
1133  {
1134  SgExpression * retexp = NULL;
1136  debugMsg(1, "canonicalizing SgVarRefExp 1");
1137  SgVariableSymbol * vs = varrefexp->get_symbol();
1138  debugMsg(3, "canonicalizing SgVarRefExp 2 ");
1139  if (vs) {
1140  SgName varname = vs->get_name();
1141  std::string valstr = varname.getString();
1142  std::string type_sizeof_prefix_string = TYPE_SIZEOF_PREFIX_STRING;
1143  int sizeof_prefix_len = type_sizeof_prefix_string.size();
1144  debugMsg(3, "canonicalizing SgVarRefExp 3 ");
1145  if (valstr.substr(0, sizeof_prefix_len) == type_sizeof_prefix_string) {
1146  //convert to a sizeof operator
1147  Sg_File_Info * finfo = varrefexp->get_file_info();
1148 #ifdef ROSE_0_8_9a_or_higher
1149  const char * filename1 = finfo->get_filename(); //this is the same filenaem as used in Boyana's script
1150 #else
1151  char * filename1=finfo->get_filename(); //this is the same filenaem as used in Boyana's script
1152 #endif
1153 
1154  //char * filename1=finfo->get_filename(); //this is the same filenaem as used in Boyana's script
1155  //char * filename2=finfo->getCurrentFilename(); //this is NULL
1156  //debugMsg(3,"%s", filename1);
1157  std::string filestr = filename1;
1158  int filelen = filestr.size();
1159  int count_len = 1;
1160  std::string sizeof_type = valstr.substr(sizeof_prefix_len + filelen
1161  - count_len, valstr.size() - sizeof_prefix_len - filelen
1162  + count_len);
1163  //debugMsg(3,"%s ", sizeof_type.c_str());
1164  if (sizeof_type == "double") {
1165  Sg_File_Info * finfo =
1166  Sg_File_Info::generateFileInfoForTransformationNode(
1167  varrefexp->get_file_info()->get_filenameString());
1168  Sg_File_Info * finfo2 =
1169  Sg_File_Info::generateFileInfoForTransformationNode(
1170  varrefexp->get_file_info()->get_filenameString());
1171  SgTypedefDeclaration * tdecl = new SgTypedefDeclaration(finfo2,
1172  "DERIV_TYPE", new SgTypeDouble());
1173  //SHK - sgFile->root is not longer supported.
1174  //tdecl->set_parent(&(getSageFile()->root()));
1175  tdecl->set_parent(globalScope(getSageFile()));
1176 #ifdef ROSE_0_8_6a_or_higher
1177  //SHK - sgFile->root is not longer supported.
1178  //tdecl->set_scope(&(getSageFile()->root()));
1179  tdecl->set_scope(globalScope(getSageFile()));
1180 #endif
1181 
1182  SgType * newt = tdecl->get_type();
1183  //SHK - Added the unused variable finfo to the constructor call.
1184  //retexp=new SgSizeOfOp(NULL, NULL, newt);
1185  retexp = new SgSizeOfOp(finfo, NULL, NULL, newt);
1186  } else if (sizeof_type == "float") {
1187  Sg_File_Info * finfo =
1188  Sg_File_Info::generateFileInfoForTransformationNode(
1189  varrefexp->get_file_info()->get_filenameString());
1190  Sg_File_Info * finfo2 =
1191  Sg_File_Info::generateFileInfoForTransformationNode(
1192  varrefexp->get_file_info()->get_filenameString());
1193  SgTypedefDeclaration * tdecl = new SgTypedefDeclaration(finfo2,
1194  "DERIV_TYPE", new SgTypeFloat());
1195  //SHK - sgFile->root is not longer supported.
1196  //tdecl->set_parent(&(getSageFile()->root()));
1197  tdecl->set_parent(globalScope(getSageFile()));
1198 #ifdef ROSE_0_8_6a_or_higher
1199  //SHK - sgFile->root is not longer supported.
1200  //tdecl->set_scope(&(getSageFile()->root()));
1201  tdecl->set_scope(globalScope(getSageFile()));
1202 #endif
1203  SgType * newt = tdecl->get_type();
1204  //SHK - Added the unused variable finfo to the constructor call.
1205  //retexp=new SgSizeOfOp(NULL, NULL, newt);
1206  retexp = new SgSizeOfOp(finfo, NULL, NULL, newt);
1207  } else if (sizeof_type == "int") {
1208  Sg_File_Info * finfo =
1209  Sg_File_Info::generateFileInfoForTransformationNode(
1210  varrefexp->get_file_info()->get_filenameString());
1211  Sg_File_Info * finfo2 =
1212  Sg_File_Info::generateFileInfoForTransformationNode(
1213  varrefexp->get_file_info()->get_filenameString());
1214  SgType * newt = new SgTypeInt();
1215 
1216  //SHK - Added the unused variable finfo to the constructor call.
1217  //retexp=new SgSizeOfOp(NULL, NULL, newt);
1218  retexp = new SgSizeOfOp(finfo, NULL, NULL, newt);
1219  } else if (sizeof_type == "long_int") {
1220  Sg_File_Info * finfo =
1221  Sg_File_Info::generateFileInfoForTransformationNode(
1222  varrefexp->get_file_info()->get_filenameString());
1223  Sg_File_Info * finfo2 =
1224  Sg_File_Info::generateFileInfoForTransformationNode(
1225  varrefexp->get_file_info()->get_filenameString());
1226  SgType * newt = new SgTypeLong();
1227 
1228  //SHK - Added the unused variable finfo to the constructor call.
1229  //retexp=new SgSizeOfOp(NULL, NULL, newt);
1230  retexp = new SgSizeOfOp(finfo, NULL, NULL, newt);
1231  } else
1232  fatal("convert sizeof");
1233 
1234  } else {
1235  //classify_SgExpression(varrefexp);
1236  //classify_SgType(isSgType(varrefexp->get_type()));
1237  //SgVariableSymbol * variableSymbol = isSgVariableSymbol(varrefexp->get_symbol());
1238  debugMsg(3, "canonicalizing SgVarRefExp 4 ");
1239  SgVariableSymbol * variableSymbol = varrefexp->get_symbol();
1240  //SgInitializedName * initializedName = (variableSymbol->get_declaration())->get_declaration();
1241  SgDeclarationStatement * initializedName =
1242  (variableSymbol->get_declaration())->get_declaration();
1243  debugMsg(3, "canonicalizing SgVarRefExp 5 ");
1244  std::string unparsed_varRefExp;
1245  UNPARSETOSTRING_MACRO(varrefexp, unparsed_varRefExp);
1246  debugMsg(3, "canonicalizing SgVarRefExp 6 ");
1247  std::string unparsed_initializedName;
1248  UNPARSETOSTRING_MACRO(initializedName, unparsed_initializedName);
1249  std::string unparsed_variableSymbol;
1250  UNPARSETOSTRING_MACRO(variableSymbol, unparsed_variableSymbol);
1251  debugMsg(1, " varRefExp = " << unparsed_varRefExp << " variableSymbol = "
1252  << unparsed_variableSymbol << " initializedName = "
1253  << unparsed_initializedName);
1254  SgExpression * p_varRefExp = isSgExpression(varrefexp->get_parent());
1255  if (p_varRefExp) {
1256  UNPARSEANDPRINT_MACRO(3, p_varRefExp, "p_varRefExp : ");
1257  } else {
1258  debugMsg(3, "p_varRefExp : NULL");
1259  }
1260  retexp = varrefexp;
1261  }
1262  } else {
1263  debugMsg(1, " In SgVarRefExp No symbol exists.");
1264  retexp = varrefexp;
1265  }
1266  return retexp;
1267  }
1268 
1269 
1270  SgExpression *
1271  CanonStateCPlusPlus::canonicalizeExpr(SgExpression * expr, int mode)
1272  {
1273 
1274  SgExpression * retexp = NULL;
1275  SgFunctionCallExp * fcall = NULL;
1276  SgAssignOp * asop = NULL;
1277  SgUnaryOp * uop = NULL;
1278  SgBinaryOp * bop = NULL;
1279  SgConditionalExp * condexp = NULL;
1280  SgVarRefExp * varrefexp = NULL;
1281 #ifdef ROSE_0_8_9a_or_higher
1282  const char * current_file = getFileName();
1283 #else
1284  char * current_file=getFileName();
1285 #endif
1286  if (condexp = isSgConditionalExp(expr)) {
1287  retexp = canonicalizeConditionalExpr(condexp, mode);
1288  } else if (SgMemberFunctionRefExp * memfref
1289  = isSgMemberFunctionRefExp(expr)) {
1290  retexp = canonicalizeMemberFunctionRefExpr(memfref, mode);
1291  } else if (fcall = isSgFunctionCallExp(expr)) {
1292  retexp = canonicalizeFunctionCallExpr(fcall, mode);
1293  } else if (asop = isSgAssignOp(expr)) {
1294  retexp = canonicalizeAssignOpExpr(asop, mode);
1295  } else if (uop = isSgUnaryOp(expr)) {
1296  retexp = canonicalizeUnaryOpExpr(uop, mode);
1297  } else if (bop = isSgBinaryOp(expr)) { //order important don't want this to apply to assign!!!
1298  retexp = canonicalizeBinaryOpExpr(bop, mode);
1299  } else if (varrefexp = isSgVarRefExp(expr)) {
1300  retexp = canonicalizeVarRefExpr(varrefexp, mode);
1301  } else if (SgFunctionRefExp * fnRefExp = isSgFunctionRefExp(expr)) {
1302  retexp = canonicalizeFunctionRefExpr(fnRefExp, mode);
1303  } else if (SgValueExp * valueExp = isSgValueExp(expr)) {
1304  retexp = canonicalizeValueExp(valueExp, mode);
1305  } else if (SgConstructorInitializer * constructorInitializer
1306  = isSgConstructorInitializer(expr)) {
1307  retexp = canonicalizeConstructorInitializerExpr(constructorInitializer,
1308  mode);
1309  } else if (SgThisExp * thisExp = isSgThisExp(expr)) {
1310  retexp = canonicalizeThisExpr(thisExp, mode);
1311  } else if (SgNewExp * newExp = isSgNewExp(expr)) {
1312  retexp = canonicalizeNewExpr(newExp, mode);
1313  } else if (SgDeleteExp * deleteExp = isSgDeleteExp(expr)) {
1314  retexp = canonicalizeDeleteExpr(deleteExp, mode);
1315  } else {
1316  retexp = canonicalizeUnimplementedExpr(expr, mode);
1317  }
1318  if (!retexp) {
1319  debugMsg(3, "returning NULL from canonicalizeExpr");
1320  } else {
1321  //if retexp is active but parent is inactive and retexp is a simple variable reference need to put DERIV_val around it
1322  //if it is more complicated need to pull it out
1323  //if retexp is of pointer type then nothing needs to be done
1324  if (isActiveExpr(retexp)) {
1325  SgExpression * parent = NULL; //isSgExpression(retexp->get_parent());
1326  if (!parent) {
1327  parent = isSgExpression(expr->get_parent());
1328  }
1329  int foo = !(isSgPointerType(retexp->get_type()));
1330  //SHK - ptt is unused after this. So commenting it out to prevent segfaults due to parent being NULL
1331  //SgType * ptt=parent->get_type();
1332  if ((parent) && !isActiveExpr(parent) && !isSgExpressionRoot(parent)
1333  && !(isSgPointerType(retexp->get_type())) && !(isSgFunctionCallExp(
1334  retexp))) {
1335  std::string parentstr;
1336  UNPARSETOSTRING_MACRO(parent, parentstr);
1337  debugMsg(3, "**** found inactive parent " <<
1338  parent->sage_class_name() << parentstr);
1340  }
1341  }
1342  UNPARSEANDPRINT_MACRO(1, retexp, "returning from canonicalizeExpr ");
1343  }
1344  // TODO: FIX THIS
1345  //return expr;
1346  return retexp;
1347  }
1348 
1349  SgExpression *
1351  int mode)
1352  {
1353  SgExpression * retexp = NULL;
1354  SgFunctionCallExp * fcall = isSgFunctionCallExp(expr);
1355  UNPARSEANDPRINT_MACRO(1, fcall, "Member Function Call is ");
1356 
1357  SgExprListExp * args = fcall->get_args();
1358  SgExprListExp *newargs = args;
1359  SgFunctionSymbol *fs = NULL;
1360  SgExpression * func = fcall->get_function();
1361 
1362  UNPARSEANDPRINT_MACRO(3, func, "Member Function is ");
1363 
1364  SgFunctionRefExp * fref = isSgFunctionRefExp(func);
1365  if (fref) {
1366  fatal(
1367  "ExprCanon.cpp In canonicalizeMemberFunctionCallExpr. expr is a member function ref exp. Do we need to handle it differently? ");
1368  }
1369 
1370  if (fref) {
1371  fs = fref->get_symbol();
1372  } else {
1373  if (SgPointerDerefExp * pd = isSgPointerDerefExp(func)) {
1374  //classify_SgExpression(pd);
1375  debugMsg(3, "It is a pointer deref expression");
1376  SgMemberFunctionRefExp * fvar = isSgMemberFunctionRefExp(
1377  pd->get_operand());
1378  if (fvar) {
1379  fs = fvar->get_symbol();
1380  }
1381  } else if (SgBinaryOp * binaryOp = isSgBinaryOp(func)) {
1382  SgExpression* functionExpression = binaryOp->get_rhs_operand_i();
1383  //classify_SgNode(functionExpression);
1384  SgMemberFunctionRefExp * memberFunctionRefExp =
1385  isSgMemberFunctionRefExp(functionExpression);
1386  if (!memberFunctionRefExp)
1387  fatal(
1388  "ExprCanon.cpp In CanonicalizeExpression functioncallexp case, memberFunctionRefExp is NULL");
1389  fs = memberFunctionRefExp->get_symbol();
1390  } else {
1391  fatal(
1392  "Unsupported function call exp.");
1393  }
1394  }
1395 
1396  if (!fs) {
1397  fatal("Member Function call without a corresponding symbol ");
1398  }
1399 
1400  if (!g_rose2xaif_state->isIntrinsicName(fs->get_name().str())
1401  || !optimized_canon) {
1402  UNPARSEANDPRINT_MACRO(3, fcall, "canonicalizing arg list of ");
1403  UNPARSEANDPRINT_MACRO(3, args, "Arg list Before canonicalization ");
1404  newargs = canonicalizeExprList(args, mode);
1405  UNPARSEANDPRINT_MACRO(3, newargs, "Arg list After ");
1406  } else {
1407  UNPARSEANDPRINT_MACRO(3, fcall, "skipping canonicalization of ");
1408  }
1409 
1410  fcall->set_args(newargs);
1411  newargs->set_parent(fcall);
1412  VERIFYUNPARSE_MACRO(fcall);
1413 
1414  retexp = expr;
1415  UNPARSEANDPRINT_MACRO(1, retexp, "returning %s from canonicalize Member FnrefExpr");
1416  return retexp;
1417  }
1418 
1419  SgExpression *
1421  SgConstructorInitializer * constructorInitializer, int mode)
1422  {
1423 
1424  UNPARSEANDPRINT_MACRO(1, constructorInitializer,
1425  " SHK -TO DO FOR C++: Implement ConstructorInitializer case in Canonicalise Expression: ");
1426  return constructorInitializer;
1427  }
1428 
1429  SgExpression *
1430  CanonStateCPlusPlus::canonicalizeThisExpr(SgThisExp * thisExp, int mode)
1431  {
1432 
1433  UNPARSEANDPRINT_MACRO(1, thisExp,
1434  " SHK -TO DO FOR C++: Implement ThisExp case in Canonicalise Expression: ");
1435  return thisExp;
1436  }
1437 
1438  SgExpression *
1439  CanonStateCPlusPlus::canonicalizeNewExpr(SgNewExp * newExp, int mode)
1440  {
1441 
1442  UNPARSEANDPRINT_MACRO(1, newExp,
1443  " SHK -TO DO FOR C++: Implement NewExp case in Canonicalise Expression: ");
1444  return newExp;
1445  }
1446 
1447  SgExpression *
1448  CanonStateCPlusPlus::canonicalizeDeleteExpr(SgDeleteExp * deleteExp, int mode)
1449  {
1450 
1451  UNPARSEANDPRINT_MACRO(1, deleteExp,
1452  " SHK -TO DO FOR C++: Implement DeleteExp case in Canonicalise Expression: ");
1453  return deleteExp;
1454  }
1455 
1456  /*
1457  SHK TO DO C++ - Need to think more about what needs to be done here. I think I created to deal with member function pointers.
1458  */
1459  SgExpression *
1461  SgMemberFunctionRefExp * memfref, int mode)
1462  {
1463  SgExpression * retexp = NULL;
1464  UNPARSEANDPRINT_MACRO(1, memfref,
1465  " SHK -TO DO FOR C++: Implement ConstructorInitializer case in Canonicalise Expression: ");
1466 
1467  /*
1468  SgExprListExp * args=fcall->get_args();
1469  SgExprListExp *newargs=args;
1470 
1471  SgExpression * func=fcall->get_function();
1472  SgFunctionRefExp * fref=isSgFunctionRefExp(func);
1473  if(fref){
1474  debugMsg(1,"It is a function ref exp ");
1475  }else{
1476  debugMsg(1,"It is NOT a function ref exp ");
1477  }
1478  SgSymbol * fs=NULL;
1479  SgPointerDerefExp * pd;
1480 
1481  if(!fref){
1482  if(pd=isSgPointerDerefExp(func)){
1483  //classify_SgExpression(pd);
1484  SgVarRefExp * fvar=isSgVarRefExp(pd->get_operand());
1485  if(fvar){
1486  fs=fvar->get_symbol();
1487  }
1488  }
1489  else{
1490  classify_SgNode(func);
1491  fatal("Unsupported function call exp. The classification is given above");
1492  }
1493  }
1494  else{
1495  fs=fref->get_symbol();
1496  }
1497  if(!fs){
1498  fatal("function call without corresponding symbol");
1499  }
1500  if(!g_rose2xaif_state->isIntrinsicName(fs->get_name().str()) || !optimized_canon){
1501  debugMsg(1,"canonicalizing arg list of %s", unparsed.c_str());
1502  newargs=canonicalizeExprList(args,mode|PULL_EFFECT);
1503  }
1504  else{
1505  debugMsg(1,"skipping canonicalization of %s", unparsed.c_str());
1506  }
1507  //CallExpression::pullArgs needs to go here
1508  //this needs to convert newargs
1509  SgFunctionSymbol * ffs=isSgFunctionSymbol(fs);
1510  SgFunctionDeclaration * fdecl=NULL;
1511  if(ffs){
1512  fdecl=ffs->get_declaration();
1513  }
1514  if(fdecl && !isFromSysInclude(fdecl)){
1515  debugMsg(1,"Case : 1 fdecl && !isFromSysInclude(fdecl)");
1516  SgInitializedNamePtrList & param_lst=fdecl->get_args();
1517  if(!g_rose2xaif_state->isIntrinsicName(fs->get_name().str())|| !optimized_canon){
1518  vector<SgType *> param_types;
1519  for(SgInitializedNamePtrList::iterator argiter=param_lst.begin();argiter!=param_lst.end();++argiter){
1520  SgType * pt=(*argiter)->get_type();
1521  param_types.push_back(pt);
1522  }
1523  }
1524  }
1525  else if(pd) //call via a pointer, assume it is not pointing to a function from system include and pullArgs
1526  //can't really tell at compile time where the pointer will point but not many system includes
1527  //with floats
1528  {
1529  debugMsg(1,"Case : 2 pd");
1530  SgPointerType * pt=isSgPointerType(fs->get_type());
1531  if(pt){
1532  SgFunctionType * ft=isSgFunctionType(pt->get_base_type());
1533  if(ft){
1534  SgTypePtrList & tpl=ft->get_arguments();
1535  vector<SgType *> param_types;
1536  for(SgTypePtrList::iterator argiter=tpl.begin();argiter!=tpl.end();++argiter){
1537  SgType * tt=*argiter;
1538  param_types.push_back(tt);
1539  }
1540  }
1541  }
1542  }
1543  fcall->set_args(newargs);
1544  newargs->set_parent(fcall);
1545 
1546  if(mode&PULL_EFFECT){
1547  debugMsg(1,"Case :mode& PULL_EFFECT ");
1548  //return pull(canon, pret);
1549  }
1550  else{
1551  retexp=expr;
1552  }
1553 
1554  */
1555  return retexp;
1556  }
1557 
1558  /*
1559  SHK TO DO C++ TEMPLATES - Need to think more about what needs to be done here. This is called from CanonicalizeStmt
1560  */
1561  SgStatement *
1563  SgTemplateDeclaration * tdecl)
1564  {
1565  return tdecl;
1566  }
1567  /*
1568  SHK TO DO C++ TEMPLATES - Need to think more about what needs to be done here. This is called from CanonicalizeStmt
1569  */
1570  SgStatement *
1572  SgTemplateInstantiationMemberFunctionDecl * tempInstMemFdecl)
1573  {
1574  return tempInstMemFdecl;
1575  }
1576  /*
1577  SHK TO DO C++ TEMPLATES - Need to think more about what needs to be done here. This is called from CanonicalizeStmt
1578  */
1579  SgStatement *
1581  SgTemplateInstantiationFunctionDecl * tempInstFdecl)
1582  {
1583  return tempInstFdecl;
1584  }
1585 
1586  /*
1587  SHK TO DO C++ TEMPLATES - Stores all known templates onto a list for reference later.
1588  */
1589  void
1591  {
1592  SgDeclarationStatementPtrList & gldecls = global->get_declarations();
1593  for (SgDeclarationStatementPtrList::iterator iter = gldecls.begin(); iter
1594  != gldecls.end(); iter++) {
1595  SgDeclarationStatement *decl = *iter;
1596  if (SgTemplateDeclaration * tdecl = isSgTemplateDeclaration(decl)) {
1597  debugMsg(1, "Pushing back a template declaration");
1598  templateList.push_back(tdecl);
1599  }
1600  }
1601  }
1602 
1603  /*
1604  SHK TO DO C++ TEMPLATES - Stores known function specializations onto a list for reference later.
1605  */
1606  void
1608  SgFunctionDeclaration * fdecl)
1609  {
1610  templateSpecializationList.push_back(fdecl);
1611  }
1612 
1613  /*
1614  SHK TO DO C++ TEMPLATES - Simply checks if a function declaration is a specialization of a known template.
1615  This returns TRUE if the name is same. Obviously we need more checks. See next function below.
1616  */
1617  bool
1619  SgFunctionDeclaration * fdecl)
1620  {
1621  std::string tName, fName = fdecl->get_name();
1622  for (SgDeclarationStatementPtrList::iterator iter = templateList.begin(); iter
1623  != templateList.end(); iter++) {
1624  SgTemplateDeclaration * tdecl = isSgTemplateDeclaration(*iter);
1625  std::string tName = tdecl->get_name();
1626  if (fName.compare(tName) == 0) {
1627  return TRUE;
1628  }
1629  }
1630  return FALSE;
1631  }
1632 
1633  /*
1634  SHK TO DO C++ TEMPLATES - The idea behind this function is to check if a function declaration matches the template declaration.
1635  That is, if a function declaration is a specialization of a template. This is true if the name of the function and the
1636  template parameters etc match.
1637  This is an INCOMPLETE function! This is where SHK left off on 30 Aug 2007.
1638  The problem that is that tdecl->get_templateParameters() returns a NULL pointer which is strange.
1639  Note, Template Parameters seems to refer to the types used in the Template rather then the arguments of the function template.
1640  Further, it seems as if there is no real way to get to the arguments of the function template.
1641  It would seem as if the class SgTemplateDeclaration is under development anyway.So the best way to
1642  get all the details we want is to use the tdecl->get_string() statement which basically gives an unparsed declaration
1643  of the template declaration and then parse it back ourselves to get the required information.
1644  */
1645  /*
1646  bool CanonStateCPlusPlus::isFunctionTemplateSpecialization(SgFunctionDeclaration * fdecl)
1647  {
1648  std::string tName, fName = fdecl->get_name();
1649  for (SgDeclarationStatementPtrList::iterator iter = templateList.begin(); iter!=templateList.end(); iter++) {
1650 
1651  SgTemplateDeclaration * tdecl = isSgTemplateDeclaration(*iter);
1652  std::string tName = tdecl->get_name();
1653  if(fName.compare(tName)==0){ //If the function name is the same as the specialization..proceed
1654  debugMsg(1," Name is the same");
1655  if(!tdecl)
1656  fatal(" tdecl is NULL");
1657  SgTemplateParameterPtrListPtr tParameterPtrListPtr = tdecl->get_templateParameters();
1658  SgTemplateParameterPtrList * tParameterPtrList = tdecl->get_templateParameters();
1659  if(tParameterPtrListPtr==NULL)
1660  fatal(" tParamaterPtrListPtr is NULL");
1661  SgInitializedNamePtrList & fArgs =fdecl->get_args();
1662  if(tParameterPtrList->size()==fArgs.size()){ // if the number of arguments are the same continue
1663  debugMsg(1," Parameter List size is the same");
1664  SgInitializedNamePtrList::iterator fIter = fArgs.begin();
1665  for (SgTemplateParameterPtrList::iterator tIter = tParameterPtrList->begin(); tIter!=tParameterPtrList->end(); tIter++) {
1666  debugMsg(1," Iterating over parameters");
1667  //check if all argument types are the same
1668  SgTemplateParameter * tArg = (*tIter);
1669  SgTemplateParameter::template_parameter_enum tEnum = tArg->get_parameterType();
1670  if(tEnum==0){//type parameter
1671  debugMsg(1," Its a type parameter");
1672  }
1673  if(tEnum==1){//nontype parameter
1674  debugMsg(1," Its a nontype parameter");
1675  }
1676  if(tEnum==2){//template parameter
1677  debugMsg(1," Its a template parameter");
1678  }
1679  SgType * tType = tArg->get_type();
1680  SgType * fInitType = (*fIter)->get_typeptr();
1681  std::string tInitTypeStr;
1682  UNPARSETOSTRING_MACRO(fInitType, fInitTypeStr);
1683  std::string fInitTypeStr;
1684  UNPARSETOSTRING_MACRO(tInitType, tInitTypeStr);
1685  if(fInitTypeStr.compare(tInitTypeStr)!=0){
1686  debugMsg(1," Parameters don't match template: " +tInitTypeStr+ " fn: " + fInitTypeStr);
1687  return FALSE;
1688  }
1689  fIter++;
1690  }
1691  return TRUE; //All argument types are the same.
1692  }
1693  }
1694  }
1695  return FALSE;
1696  }*/
1697 
1698  /*
1699  SHK TO DO C++ TEMPLATES - This function compares a function declaration along with known function specializations.
1700  */
1701  bool
1703  SgFunctionDeclaration * fdecl)
1704  {
1705  std::string tName, fName = fdecl->get_name();
1706  if (!isSgTemplateInstantiationFunctionDecl(fdecl)) {
1707  return FALSE;
1708  }
1709  for (SgDeclarationStatementPtrList::iterator iter =
1710  templateSpecializationList.begin(); iter
1711  != templateSpecializationList.end(); iter++) {
1712  SgFunctionDeclaration * tdecl = isSgFunctionDeclaration(*iter);
1713  std::string tName = tdecl->get_name();
1714  if (fName.compare(tName) == 0) { //If the function name is the same as the specialization..proceed
1715  SgType * tReturnType = tdecl->get_type()->get_return_type();
1716  SgType * fReturnType = fdecl->get_type()->get_return_type();
1717  std::string tReturnTypeStr;
1718  UNPARSETOSTRING_MACRO(tReturnType, tReturnTypeStr);
1719  std::string fReturnTypeStr;
1720  UNPARSETOSTRING_MACRO(fReturnType, fReturnTypeStr);
1721  if (fReturnTypeStr.compare(tReturnTypeStr) == 0) { // if the return types are the same continue
1722  SgInitializedNamePtrList & tArgs = tdecl->get_args();
1723  SgInitializedNamePtrList & fArgs = fdecl->get_args();
1724  if (tArgs.size() == fArgs.size()) { // if the number of arguments are the same continue
1725  SgInitializedNamePtrList::iterator fIter = fArgs.begin();
1726  for (SgInitializedNamePtrList::iterator tIter = tArgs.begin(); tIter
1727  != tArgs.end(); tIter++) { //check if all argument types are the same
1728  SgType * tInitType = (*tIter)->get_typeptr();
1729  SgType * fInitType = (*fIter)->get_typeptr();
1730  std::string tInitTypeStr;
1731  UNPARSETOSTRING_MACRO(tInitType, tInitTypeStr);
1732  std::string fInitTypeStr;
1733  UNPARSETOSTRING_MACRO(fInitType, fInitTypeStr);
1734  if (fInitTypeStr.compare(tInitTypeStr) != 0) {
1735  return FALSE;
1736  }
1737  fIter++;
1738  }
1739  return TRUE; //All argument types are the same.
1740  }
1741  }
1742  }
1743  }
1744  return FALSE;
1745  }
1746 
1747 } // namespace rose2xaif