[Prev][Next][Index]
No Subject
- From: Darryl Ivan Brown <darrylb@skinner.cs.uoregon.edu>
- Date: Tue, 22 Nov 1994 09:17:58 -0800
- To: sage-bugs@cica.indiana.edu
Dearest sage++ sages,
I am having some trouble adding member functions to
classes. I have a function I wrote some months ago
that seems accomplish it correctly. That is to say,
when I unaprse the SgClassStmt that I have added the
function decl to, it shows the added function without
any problems during the unparseing.
Unfortunately, now when I try to save the
dep file after making the modification, it goes into a
infinite loop. If you have any clues to any recent
changes in sage++ that might have affected the way I
make this member func addition, let me know. Perhaps
when this was working I was doing other code
manipulations that accidentally made up for errors in
this function and that was why it worked (right).
After the function code below, I have included (one of)
the test pc++ program(s) I used as input (note: I also
tried it on mgrid in the test suites).
Function code follows:
// This function adds a member function to a class.
// It requires the class declaration statement, the function
// type, the function name, and the status of the function
// (public, private, protected);
//
// (Note that it returns a pointer to the function expression it
// creates. This is so that this expression can be used to add
// parameters to the function via the addParamToFuncExp function
// above.)
//;
SgExpression *addFunctionToClass(SgClassStmt *cs,
SgType *funcType,
char *funcName,
int status) {
SgVarDeclStmt *vds;
SgMemberFuncSymb *fs;
SgExprListExp *funcList;
SgExpression *fexp;
SgType *ty;
PTR_SYMB psymb, newsymb;
#define COLL_STATUS_NUM (256)
// create function symbol;
fs = new SgMemberFuncSymb(funcName, *funcType,
*cs, status);
// create a function pointer expression;
fexp = new SgExpression(FUNCTION_REF);
fexp->setSymbol(*fs);
// put the func ptr exp in a list;
funcList = new SgExprListExp();
funcList->setValue(*fexp);
funcList->setType(*funcType);
// create var declaration statement;
vds = new SgVarDeclStmt(*funcList, *funcType);
cs->insertStmtAfter(*vds);
// now modify the class type statement;;
ty = (cs->name())->type();
// extract symbol pointer;
newsymb = fs->thesymb;
// set up member func specific items.;
newsymb->entry.member_func.base_name = cs->symbol()->thesymb;
// assign the old first in line to be the 2nd, after new symbol;
newsymb->next_symb = newsymb->thread = psymb = ty->thetype->entry.derived_class.first;
newsymb->entry.member_func.next = psymb;
// make first declaration the new function;
ty->thetype->entry.derived_class.first = newsymb;
// it looks to me like num_fields is not used, but....;
ty->thetype->entry.derived_class.num_fields += 1;
return fexp;
}
// pc++ test program...
class s_elem {
int start[3];
public:
int myproc; // used to display data distribution
};
Collection Gr {
public:
int n[3]; //sizes of the whole area (including surface)
};
processor_main () {
Gr <s_elem> a;
}