24 SgFunctionDeclaration * fdecl = isSgFunctionDeclaration(stmt);
33 SgName fn = fdecl->get_name();
35 SgFunctionSymbol * func_namet = isSgFunctionSymbol(func_name);
36 SgVariableSymbol * retval = NULL;
37 int isfrwrd = fdecl->isForward();
38 if (func_name == NULL) {
42 SgName mang = fdecl->get_mangled_name();
50 SgDeclarationStatementPtrList& gldecls = sglobal->get_declarations();
51 if (gldecls.size() == 0)
52 fatal(
"unable to match forward declaration of " << mang.str());
54 for (SgDeclarationStatementPtrList::iterator iter = gldecls.begin(); iter
55 != gldecls.end(); iter++) {
56 SgDeclarationStatement *cdcl = *iter;
57 SgFunctionDeclaration * curf = isSgFunctionDeclaration(cdcl);
59 SgName cmang = curf->get_mangled_name();
60 if ((cmang == mang) && (cdcl != fdecl)) {
62 func_namet = isSgFunctionSymbol(func_name);
64 debugMsg(3,
"found symbol for forward decl of " << mang.str());
72 fatal(
"unable to match frwd decl of "<< mang.str());
74 fatal(
"cannot find symbol for function "<< fn.str());
80 debugMsg(2,
"canonicalizing function definition");
83 SgFunctionDefinition * fdef = fdecl->get_definition();
87 "in canonicalizeStmt: function declaration that is not forward but does not have function definition");
127 SgBasicBlock * fbody = fdef->get_body();
128 SgStatementPtrList & fmembers = fbody->get_statements();
161 SgNode * parent = fdecl->get_parent();
162 if (parent == NULL) {
164 fatal(
"Parent of function declaration is NULL");
166 if (isSgGlobal(parent))
174 SgReturnStmt * retst = isSgReturnStmt(stmt);
181 SgExpression * retexp = retst->get_expression();
185 fatal(
"Canonicalizing return stmt, new retrun expression is NULL.");
191 SgName fname = curfdef->get_declaration()->get_name();
195 fatal(
"No function symbol found in return stmt canonicalization.");
198 SgVariableSymbol*vsymb =
getRetVal(isSgFunctionSymbol(fsymb));
203 retst->set_expression(newretexp);
205 retst->set_expression(newretexp);
208 fatal(
"return statement without function scope");
216 SgMemberFunctionDeclaration * memfdecl =
217 isSgMemberFunctionDeclaration(stmt);
219 if (memfdecl->isSpecialization())
220 debugMsg(1,
"Template specialized member function ");
222 SgSpecialFunctionModifier & modifier =
223 memfdecl->get_specialFunctionModifier();
224 SgName fn = memfdecl->get_name();
226 SgFunctionSymbol * func_namet = isSgFunctionSymbol(func_name);
230 SgVariableSymbol * retval = NULL;
231 int isfrwrd = memfdecl->isForward();
232 if (func_name == NULL) {
236 SgName mang = memfdecl->get_mangled_name();
244 SgDeclarationStatementPtrList& gldecls = sglobal->get_declarations();
245 if (gldecls.size() == 0)
246 fatal(
"unable to match forward declaration of "<< mang.str());
248 for (SgDeclarationStatementPtrList::iterator iter = gldecls.begin(); iter
249 != gldecls.end(); iter++) {
250 SgDeclarationStatement *cdcl = *iter;
251 SgFunctionDeclaration * curf = isSgFunctionDeclaration(cdcl);
253 SgName cmang = curf->get_mangled_name();
254 if ((cmang == mang) && (cdcl != memfdecl)) {
256 func_namet = isSgFunctionSymbol(func_name);
258 debugMsg(3,
"1 found symbol for forward decl of " <<
267 fatal(
"unable to match frwd decl of "<< mang.str());
270 fatal(
"cannot find symbol for function "<< fn.str());
274 debugMsg(3,
"1 canonicalizing member function definition");
276 SgFunctionDefinition * fdef = memfdecl->get_definition();
279 "in canonicalizeStmt: member function declaration that is not forward but does not have function definition");
281 SgBasicBlock * fbody = fdef->get_body();
282 SgStatementPtrList & fmembers = fbody->get_statements();
287 SgClassDefinition * classdef = memfdecl->get_class_scope();
289 fatal(
"Classdef is NULL");
290 SgClassDeclaration * classdecl = classdef->get_declaration();
292 fatal(
"Classdef->get_declaration is NULL");
293 std::string name = classdecl->get_name();
294 debugMsg(3,
"1 Class name : " << name);
296 SgClassType * newclasstype = classdecl->get_type();
300 memfdecl->get_type()->set_return_type(newclasstype);
307 SgSpecialFunctionModifier & modifier
308 = memfdecl->get_specialFunctionModifier();
309 if (modifier.isConstructor()) {
310 SgCtorInitializerList * constructorList =
311 memfdecl->get_CtorInitializerList();
312 if (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();
321 name = prefstr + name;
322 initializedName->set_name(name);
324 debugMsg(3,
"Constructor initializer list entry is : " << name);
338 SgType * oldt = ft->get_return_type();
339 SgPointerType * tptr = NULL;
340 if (tptr = isSgPointerType(oldt)) {
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());
354 "SageCanon.cpp: Null type argument encountered in convertReturnType(SgFunctionType *, CanonState&) Pos 1.");
357 Sg_File_Info * finfo = Sg_File_Info::generateFileInfoForTransformationNode(
getFileName());
358 SgTypedefDeclaration * tdecl =
new SgTypedefDeclaration(finfo,
359 "DERIV_TYPE", currt);
361 #ifdef ROSE_0_8_6a_or_higher
369 SgType * newt = tdecl->get_type();
372 newcur->set_base_type(currt);
373 ft->set_orig_return_type(newtptr);
374 ft->set_return_type(newtptr);
381 "SageCanon.cpp: Null type argument encountered in convertReturnType(SgFunctionType *, CanonState&) Pos 2.");
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);
400 #ifdef ROSE_0_8_9a_or_higher
406 for (SgTypePtrList::iterator argiter = tlist->begin(); argiter
407 != tlist->end(); ++argiter) {
408 SgType * tt = *argiter;
409 SgPointerType * tptr = NULL;
412 "SageCanon.cpp: Null type argument encountered in convertTypeList(SgTypePtrList *tlist). pos 1");
415 Sg_File_Info * finfo = Sg_File_Info::generateFileInfoForTransformationNode(current_file);
416 SgTypedefDeclaration * tdecl =
new SgTypedefDeclaration(finfo,
421 #ifdef ROSE_0_8_6a_or_higher
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);
434 }
else if (at = isSgArrayType(tt)) {
435 SgArrayType * rtcopy =
new SgArrayType();
436 rtcopy->set_base_type(tt);
437 rtcopy->set_index(at->get_index());
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());
455 "SageCanon.cpp: Null type argument encountered in convertTypeList(SgTypePtrList *tlist). pos 2");
458 Sg_File_Info * finfo = Sg_File_Info::generateFileInfoForTransformationNode(current_file);
459 SgTypedefDeclaration * tdecl =
new SgTypedefDeclaration(finfo,
460 "DERIV_TYPE", currt);
464 #ifdef ROSE_0_8_6a_or_higher
469 SgType * newt = tdecl->get_type();
471 newcur->set_base_type(currt);
483 SgType * oldt = iname->get_type();
484 SgPointerType * tptr = NULL;
486 #ifdef ROSE_0_8_9a_or_higher
493 "SageCanon.cpp: Null type argument encountered in convertInitializedName(SgInitializedName *, CanonState& ). pos 1");
495 debugMsg(1,
"Its an active float type");
497 Sg_File_Info * finfo = Sg_File_Info::generateFileInfoForTransformationNode(current_file);
498 #ifndef AD_FORTRAN_SPECIFIC
499 SgTypedefDeclaration * tdecl =
new SgTypedefDeclaration(finfo,
504 #ifdef ROSE_0_8_6a_or_higher
509 SgType * newt = tdecl->get_type();
511 SgType * newt = oldt;
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();
533 newbaset->set_base_type(oldt);
534 iname->set_type(rtcopy);
536 iname->set_type(oldt);
538 }
else if (tptr = isSgPointerType(oldt)) {
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());
552 "SageCanon.cpp: Null type argument encountered in convertInitializedName(SgInitializedName *, CanonState& ). pos 2");
555 Sg_File_Info * finfo = Sg_File_Info::generateFileInfoForTransformationNode(current_file);
556 SgTypedefDeclaration * tdecl =
new SgTypedefDeclaration(finfo,
557 "DERIV_TYPE", currt);
561 #ifdef ROSE_0_8_6a_or_higher
567 SgType * newt = tdecl->get_type();
569 SgArrayType * at = NULL;
570 if (at = isSgArrayType(currt)) {
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();
585 newbaset->set_base_type(currt);
586 newcur->set_base_type(rtcopy);
587 iname->set_type(newtptr);
589 newcur->set_base_type(currt);
590 iname->set_type(newtptr);
600 debugMsg(3,
"visited with 0-Node!");
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))
614 SgInitializedNamePtrList &allvars = stmt->get_variables();
615 SgInitializedName * tv = allvars.front();
616 SgName valname = tv->get_name();
617 std::string valstr = valname.getString();
619 int sizeof_prefix_len = type_sizeof_prefix_string.size();
620 if (valstr.substr(0, sizeof_prefix_len) == type_sizeof_prefix_string) {
622 SgGlobal * sggl = NULL;
623 if (sggl = isSgGlobal(stmt->get_parent())) {
624 debugMsg(3,
"removing decl of " << valname.str());
625 sggl->remove_statement(stmt);
631 stmt->get_variableDeclarationContainsBaseTypeDefiningDeclaration();
633 debugMsg(3,
"extra definition inside variable declaration");
635 SgType * vt = tv->get_type();
636 SgClassType * clt = isSgClassType(vt);
638 SgDeclarationStatement * decl = clt->get_declaration();
639 SgClassDeclaration * cldecl = isSgClassDeclaration(decl);
641 SgClassDefinition * cldef = cldecl->get_definition();
650 std::list<SgSymbol*> symlist = stattr->
symbols;
651 int dsize = symlist.size();
654 "ConvertDeclarationsPass::visit found var decl with more than one symbol");
656 SgSymbol * symdecl = symlist.front();
657 SgInitializedName * iname = stmt->get_decl_item(symdecl->get_name());
659 SgPointerType * pt = isSgPointerType(symdecl->get_type());
661 if (pt && (ft = isSgFunctionType(pt->get_base_type()))) {
663 iname->set_type(
new SgPointerType(ft));
664 SgTypePtrList & tpl = ft->get_arguments();
674 }
else if ((fdecl = isSgFunctionDeclaration(node))
677 SgName fn = fdecl->get_name();
678 std::string funstr = fn.getString();
680 int sizeof_prefix_len = expr_sizeof_prefix_string.size();
681 if (funstr.substr(0, sizeof_prefix_len) == expr_sizeof_prefix_string) {
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);
696 if (SgMemberFunctionDeclaration * memfdecl
697 = isSgMemberFunctionDeclaration(node)) {
698 SgSpecialFunctionModifier & modifier =
699 memfdecl->get_specialFunctionModifier();
700 if (modifier.isDestructor()) {
702 " Changing the name of the member function declaration - Desctructor");
705 newname =
"~" + prefstr;
706 std::string oldstr(fn.str());
707 oldstr = oldstr.substr(1, oldstr.length());
709 SgName newsgname(newname.c_str());
710 fdecl->set_name(newsgname);
711 }
else if (modifier.isOperator()) {
715 " Changing the name of the member function declaration");
719 std::string oldstr(fn.str());
721 SgName newsgname(newname.c_str());
722 fdecl->set_name(newsgname);
725 if (SgTemplateInstantiationFunctionDecl * tinstdecl
726 = isSgTemplateInstantiationFunctionDecl(fdecl)) {
727 SgTemplateFunctionDeclaration * tdecl =
728 tinstdecl->get_templateDeclaration();
731 "SHK TO DO C++ TEMPLATES Not Changing the name of the template function declaration");
737 "SHK TO DO C++ TEMPLATES Furthermore, It is a specialization");
741 debugMsg(1,
"SHK TO DO C++ TEMPLATES It is a specialization");
743 SgSpecialFunctionModifier & modifier =
744 fdecl->get_specialFunctionModifier();
748 std::string oldstr(fn.str());
749 if (oldstr.compare(
"main") != 0 || modifier.isOperator()) {
751 SgName newsgname(newname.c_str());
752 fdecl->set_name(newsgname);
760 SgInitializedNamePtrList & arglist = fdecl->get_args();
761 for (SgInitializedNamePtrList::iterator argiter = arglist.begin(); argiter
762 != arglist.end(); ++argiter) {
764 SgInitializedName * iname = *argiter;
765 SgPointerType * pt = isSgPointerType(iname->get_type());
767 if (pt && (ft = isSgFunctionType(pt->get_base_type()))) {
770 iname->set_type(
new SgPointerType(ft));
771 SgTypePtrList & tpl = ft->get_arguments();
780 }
else if (sgcldf = isSgClassDefinition(node)) {
782 }
else if (sgcldcl = isSgClassDeclaration(node)) {
784 }
else if (sgtpdfdcl = isSgTypedefDeclaration(node)) {
785 SgType * tp1 = sgtpdfdcl->get_base_type();
787 debugMsg(3,
"base type is " << tp1->sage_class_name());
788 SgClassType * cltp = isSgClassType(tp1);
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();
796 SgClassDeclaration * clcldecl = isSgClassDeclaration(cldecl);
798 SgClassDefinition* cldef = clcldecl->get_definition();
800 SgDeclarationStatementPtrList dl = cldef->get_members();
801 for (SgDeclarationStatementPtrList::iterator iter =
802 dl.begin(); iter != dl.end(); iter++)
822 else if (varrefexp = isSgVarRefExp(node)) {
823 SgVariableSymbol * vs = varrefexp->get_symbol();
825 SgName varname = vs->get_name();
826 std::string valstr = varname.getString();
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;
832 Sg_File_Info * finfo = node->get_file_info();
834 #ifdef ROSE_0_8_9a_or_higher
835 const char * filename1 = finfo->get_filename();
837 char * filename1=finfo->get_filename();
840 Sg_File_Info * finfo1 = Sg_File_Info::generateFileInfoForTransformationNode(filename1);
843 std::string filestr = filename1;
844 int filelen = filestr.size();
846 std::string sizeof_type = valstr.substr(sizeof_prefix_len + filelen
847 - count_len, valstr.size() - sizeof_prefix_len - filelen
850 SgType * newt = NULL;
851 if (sizeof_type ==
"int") {
852 newt =
new SgTypeInt();
853 retexp =
new SgSizeOfOp(finfo1, NULL, newt, newt);
855 if (sizeof_type ==
"long_int") {
856 newt = SgTypeLong::createType();
857 retexp =
new SgSizeOfOp(finfo1, NULL, newt, newt);
862 SgNode * parent = node->get_parent();
863 SgAssignInitializer * ai = NULL;
864 SgExprListExp *el = NULL;
865 if (ai = isSgAssignInitializer(parent)) {
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++) {
875 retexp->set_parent(parent);
880 debugMsg(3,
"sizeof parent is " << parent->sage_class_name());
881 fatal(
"implement sizeof for specified parent");
925 SgExpression * retexp = NULL;
926 SgExpression *expr = fcall;
929 SgVarRefExp * adExp = NULL;
932 SgExprListExp * args = fcall->get_args();
933 SgExprListExp *newargs = args;
935 SgExpression * func = fcall->get_function();
936 SgFunctionRefExp * fref = isSgFunctionRefExp(func);
938 debugMsg(1,
"It is a function ref exp ");
940 debugMsg(1,
"It is NOT a function ref exp ");
942 SgSymbol * fs = NULL;
943 SgPointerDerefExp * pd;
946 if (pd = isSgPointerDerefExp(func)) {
947 SgVarRefExp * fvar = isSgVarRefExp(pd->get_operand());
949 fs = fvar->get_symbol();
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());
968 }
else if (SgBinaryOp * binaryOp = isSgBinaryOp(func)) {
969 SgExpression* functionExpression = binaryOp->get_rhs_operand_i();
971 SgMemberFunctionRefExp * memberFunctionRefExp =
972 isSgMemberFunctionRefExp(functionExpression);
973 if (!memberFunctionRefExp)
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: "
986 "Unsupported function call exp.");
989 fs = fref->get_symbol();
992 fatal(
"function call without corresponding symbol");
995 SgName funname = fs->get_name();
996 std::string funstr = funname.getString();
998 int sizeof_prefix_len = expr_sizeof_prefix_string.size();
999 if (funstr.substr(0, sizeof_prefix_len) == expr_sizeof_prefix_string) {
1002 SgExpressionPtrList & explst = args->get_expressions();
1003 SgExpressionPtrList::iterator iter = explst.begin();
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);
1024 SgFunctionSymbol * ffs = isSgFunctionSymbol(fs);
1025 SgFunctionDeclaration * fdecl = NULL;
1027 fdecl = ffs->get_declaration();
1030 debugMsg(1,
"Case : 1 fdecl && !isFromSysInclude(fdecl)");
1031 SgInitializedNamePtrList & param_lst = fdecl->get_args();
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);
1046 SgPointerType * pt = isSgPointerType(fs->get_type());
1048 SgFunctionType * ft = isSgFunctionType(pt->get_base_type());
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);
1060 fcall->set_args(newargs);
1061 newargs->set_parent(fcall);
1065 debugMsg(1,
"Case :mode& PULL_EFFECT ");
1083 SgNode * parent = expr->get_parent();
1084 while (isSgFunctionDefinition(parent) == NULL) {
1085 parent = parent->get_parent();
1094 SgExpression * retexp = NULL;
1098 debugMsg(1,
"canonicalizing assign op exp");
1102 SgFunctionCallExp * fcall = NULL;
1107 if ((fcall = isSgFunctionCallExp(asop->get_rhs_operand())) != NULL
1112 asop->set_lhs_operand(newlhs);
1113 asop->set_rhs_operand(newrhs);
1116 SgExpression *newrhs = NULL;
1117 if (isSgFunctionCallExp(asop->get_rhs_operand()))
1122 asop->set_lhs_operand(newlhs);
1123 asop->set_rhs_operand(newrhs);
1134 SgExpression * retexp = NULL;
1136 debugMsg(1,
"canonicalizing SgVarRefExp 1");
1137 SgVariableSymbol * vs = varrefexp->get_symbol();
1138 debugMsg(3,
"canonicalizing SgVarRefExp 2 ");
1140 SgName varname = vs->get_name();
1141 std::string valstr = varname.getString();
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) {
1147 Sg_File_Info * finfo = varrefexp->get_file_info();
1148 #ifdef ROSE_0_8_9a_or_higher
1149 const char * filename1 = finfo->get_filename();
1151 char * filename1=finfo->get_filename();
1157 std::string filestr = filename1;
1158 int filelen = filestr.size();
1160 std::string sizeof_type = valstr.substr(sizeof_prefix_len + filelen
1161 - count_len, valstr.size() - sizeof_prefix_len - filelen
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());
1176 #ifdef ROSE_0_8_6a_or_higher
1182 SgType * newt = tdecl->get_type();
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());
1198 #ifdef ROSE_0_8_6a_or_higher
1203 SgType * newt = tdecl->get_type();
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();
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();
1230 retexp =
new SgSizeOfOp(finfo, NULL, NULL, newt);
1232 fatal(
"convert sizeof");
1238 debugMsg(3,
"canonicalizing SgVarRefExp 4 ");
1239 SgVariableSymbol * variableSymbol = varrefexp->get_symbol();
1241 SgDeclarationStatement * initializedName =
1242 (variableSymbol->get_declaration())->get_declaration();
1243 debugMsg(3,
"canonicalizing SgVarRefExp 5 ");
1244 std::string unparsed_varRefExp;
1246 debugMsg(3,
"canonicalizing SgVarRefExp 6 ");
1247 std::string unparsed_initializedName;
1249 std::string unparsed_variableSymbol;
1251 debugMsg(1,
" varRefExp = " << unparsed_varRefExp <<
" variableSymbol = "
1252 << unparsed_variableSymbol <<
" initializedName = "
1253 << unparsed_initializedName);
1254 SgExpression * p_varRefExp = isSgExpression(varrefexp->get_parent());
1263 debugMsg(1,
" In SgVarRefExp No symbol exists.");
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
1286 if (condexp = isSgConditionalExp(expr)) {
1288 }
else if (SgMemberFunctionRefExp * memfref
1289 = isSgMemberFunctionRefExp(expr)) {
1291 }
else if (fcall = isSgFunctionCallExp(expr)) {
1293 }
else if (asop = isSgAssignOp(expr)) {
1295 }
else if (uop = isSgUnaryOp(expr)) {
1297 }
else if (bop = isSgBinaryOp(expr)) {
1299 }
else if (varrefexp = isSgVarRefExp(expr)) {
1301 }
else if (SgFunctionRefExp * fnRefExp = isSgFunctionRefExp(expr)) {
1303 }
else if (SgValueExp * valueExp = isSgValueExp(expr)) {
1305 }
else if (SgConstructorInitializer * constructorInitializer
1306 = isSgConstructorInitializer(expr)) {
1309 }
else if (SgThisExp * thisExp = isSgThisExp(expr)) {
1311 }
else if (SgNewExp * newExp = isSgNewExp(expr)) {
1313 }
else if (SgDeleteExp * deleteExp = isSgDeleteExp(expr)) {
1319 debugMsg(3,
"returning NULL from canonicalizeExpr");
1325 SgExpression * parent = NULL;
1327 parent = isSgExpression(expr->get_parent());
1329 int foo = !(isSgPointerType(retexp->get_type()));
1332 if ((parent) && !
isActiveExpr(parent) && !isSgExpressionRoot(parent)
1333 && !(isSgPointerType(retexp->get_type())) && !(isSgFunctionCallExp(
1335 std::string parentstr;
1337 debugMsg(3,
"**** found inactive parent " <<
1338 parent->sage_class_name() << parentstr);
1353 SgExpression * retexp = NULL;
1354 SgFunctionCallExp * fcall = isSgFunctionCallExp(expr);
1357 SgExprListExp * args = fcall->get_args();
1358 SgExprListExp *newargs = args;
1359 SgFunctionSymbol *fs = NULL;
1360 SgExpression * func = fcall->get_function();
1364 SgFunctionRefExp * fref = isSgFunctionRefExp(func);
1367 "ExprCanon.cpp In canonicalizeMemberFunctionCallExpr. expr is a member function ref exp. Do we need to handle it differently? ");
1371 fs = fref->get_symbol();
1373 if (SgPointerDerefExp * pd = isSgPointerDerefExp(func)) {
1375 debugMsg(3,
"It is a pointer deref expression");
1376 SgMemberFunctionRefExp * fvar = isSgMemberFunctionRefExp(
1379 fs = fvar->get_symbol();
1381 }
else if (SgBinaryOp * binaryOp = isSgBinaryOp(func)) {
1382 SgExpression* functionExpression = binaryOp->get_rhs_operand_i();
1384 SgMemberFunctionRefExp * memberFunctionRefExp =
1385 isSgMemberFunctionRefExp(functionExpression);
1386 if (!memberFunctionRefExp)
1388 "ExprCanon.cpp In CanonicalizeExpression functioncallexp case, memberFunctionRefExp is NULL");
1389 fs = memberFunctionRefExp->get_symbol();
1392 "Unsupported function call exp.");
1397 fatal(
"Member Function call without a corresponding symbol ");
1410 fcall->set_args(newargs);
1411 newargs->set_parent(fcall);
1421 SgConstructorInitializer * constructorInitializer,
int mode)
1425 " SHK -TO DO FOR C++: Implement ConstructorInitializer case in Canonicalise Expression: ");
1426 return constructorInitializer;
1434 " SHK -TO DO FOR C++: Implement ThisExp case in Canonicalise Expression: ");
1443 " SHK -TO DO FOR C++: Implement NewExp case in Canonicalise Expression: ");
1452 " SHK -TO DO FOR C++: Implement DeleteExp case in Canonicalise Expression: ");
1461 SgMemberFunctionRefExp * memfref,
int mode)
1463 SgExpression * retexp = NULL;
1465 " SHK -TO DO FOR C++: Implement ConstructorInitializer case in Canonicalise Expression: ");
1563 SgTemplateDeclaration * tdecl)
1572 SgTemplateInstantiationMemberFunctionDecl * tempInstMemFdecl)
1574 return tempInstMemFdecl;
1581 SgTemplateInstantiationFunctionDecl * tempInstFdecl)
1583 return tempInstFdecl;
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");
1608 SgFunctionDeclaration * fdecl)
1619 SgFunctionDeclaration * fdecl)
1621 std::string tName, fName = fdecl->get_name();
1622 for (SgDeclarationStatementPtrList::iterator iter =
templateList.begin(); iter
1624 SgTemplateDeclaration * tdecl = isSgTemplateDeclaration(*iter);
1625 std::string tName = tdecl->get_name();
1626 if (fName.compare(tName) == 0) {
1703 SgFunctionDeclaration * fdecl)
1705 std::string tName, fName = fdecl->get_name();
1706 if (!isSgTemplateInstantiationFunctionDecl(fdecl)) {
1709 for (SgDeclarationStatementPtrList::iterator iter =
1712 SgFunctionDeclaration * tdecl = isSgFunctionDeclaration(*iter);
1713 std::string tName = tdecl->get_name();
1714 if (fName.compare(tName) == 0) {
1715 SgType * tReturnType = tdecl->get_type()->get_return_type();
1716 SgType * fReturnType = fdecl->get_type()->get_return_type();
1717 std::string tReturnTypeStr;
1719 std::string fReturnTypeStr;
1721 if (fReturnTypeStr.compare(tReturnTypeStr) == 0) {
1722 SgInitializedNamePtrList & tArgs = tdecl->get_args();
1723 SgInitializedNamePtrList & fArgs = fdecl->get_args();
1724 if (tArgs.size() == fArgs.size()) {
1725 SgInitializedNamePtrList::iterator fIter = fArgs.begin();
1726 for (SgInitializedNamePtrList::iterator tIter = tArgs.begin(); tIter
1727 != tArgs.end(); tIter++) {
1728 SgType * tInitType = (*tIter)->get_typeptr();
1729 SgType * fInitType = (*fIter)->get_typeptr();
1730 std::string tInitTypeStr;
1732 std::string fInitTypeStr;
1734 if (fInitTypeStr.compare(tInitTypeStr) != 0) {