diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/chillASTs.cc | 709 | ||||
-rwxr-xr-x | src/ir_clang.cc | 479 | ||||
-rw-r--r-- | src/omegatools.cc | 4 |
3 files changed, 543 insertions, 649 deletions
diff --git a/src/chillASTs.cc b/src/chillASTs.cc index c73eb98..5b8e1e8 100644 --- a/src/chillASTs.cc +++ b/src/chillASTs.cc @@ -6,11 +6,11 @@ using namespace std; -int chillAST_node::chill_scalar_counter = 0; -int chillAST_node::chill_array_counter = 1; +int chillAST_Node::chill_scalar_counter = 0; +int chillAST_Node::chill_array_counter = 1; -const char *Chill_AST_Node_Names[] = { +const char *ChillAST_Node_Names[] = { "Unknown AST node type", "SourceFile", "TypedefDecl", @@ -54,24 +54,30 @@ const char *Chill_AST_Node_Names[] = { char *parseUnderlyingType(char *sometype) { int len = strlen(sometype); - //fprintf(stderr, "parseUnderlyingType( %s )\n", sometype); + CHILL_DEBUG_PRINT("parseUnderlyingType( %s )\n", sometype); char *underlying = strdup(sometype); char *p; char *start = underlying; // ugly. we want to turn "float *" into "float" but "struct abc *" into struct abc. - // there are probably many more cases. have an approved list? TODO - if (strstr(underlying, "struct ")) start += 7; // (length("struct ")) - //fprintf(stderr, "sometype '%s' start '%s'\n", sometype, start); - if (p = index(start, ' ')) *p = '\0'; // end at first space leak - if (p = index(start, '[')) *p = '\0'; // leak - if (p = index(start, '*')) *p = '\0'; // leak + // there are probably many more cases. have an approved list? + p = &underlying[len - 1]; + + while (p > underlying) + if (*p == ' ' || *p == '*') + --p; + else if (*p == ']') + // TODO This can be improved by using a stack + while (*p != '[') --p; + else break; + + *p = '\0'; return underlying; } void printSymbolTable(chillAST_SymbolTable *st) { - //printf("%d entries\n", st->size()); + CHILL_DEBUG_PRINT("%d entries\n", st->size()); if (!st) return; for (int i = 0; i < st->size(); i++) { printf("%d ", i); @@ -83,7 +89,7 @@ void printSymbolTable(chillAST_SymbolTable *st) { } void printSymbolTableMoreInfo(chillAST_SymbolTable *st) { - //printf("%d entries\n", st->size()); + CHILL_DEBUG_PRINT("%d entries\n", st->size()); if (!st) return; for (int i = 0; i < st->size(); i++) { printf("%d ", i); @@ -94,140 +100,104 @@ void printSymbolTableMoreInfo(chillAST_SymbolTable *st) { fflush(stdout); } +char *splitVariableName(char *name) { + char *cdot = strstr(name, "."); + char *carrow = strstr(name, "->"); // initial 'c' for const - can't change those -bool symbolTableHasVariableNamed(chillAST_SymbolTable *table, const char *name) { - if (!table) return false; // ?? - int numvars = table->size(); - for (int i = 0; i < numvars; i++) { - chillAST_VarDecl *vd = (*table)[i]; - if (!strcmp(name, vd->varname)) return true; // need to check type? + int pos = INT16_MAX, pend; + + if (cdot) pend = pos = (int) (cdot - name); + if (carrow) { + pos = min(pos, (int) (carrow - name)); + pend = pos + 1; } - return false; -} + if (pos == INT16_MAX) + return NULL; -chillAST_VarDecl *symbolTableFindVariableNamed(chillAST_SymbolTable *table, - const char *name) { // fwd decl TODO too many similar named functions - if (!table) return NULL; // ?? + name[pos] = '\0'; + return &name[pend + 1]; - // see if name has a dot or arrow (->) indicating that it is a structure/class - const char *cdot = strstr(name, "."); - const char *carrow = strstr(name, "->"); // initial 'c' for const - can't change those +} - char *varname; - char *subpart = NULL; +chillAST_VarDecl *symbolTableFindName(chillAST_SymbolTable *table, const char *name) { + if (!table) return NULL; + int numvars = table->size(); + for (int i = 0; i < numvars; i++) { + chillAST_VarDecl *vd = (*table)[i]; + if (!strcmp(name, vd->varname)) return vd; + } + return NULL; +} - if (cdot || carrow) { - fprintf(stderr, "symbolTableFindVariableNamed(), name '%s' looks like a struct\n", name); +chillAST_VarDecl *variableDeclFindSubpart(chillAST_VarDecl *decl, const char *name) { + char *varname = strdup(name), *subpart; - // so, look for the first part in the symbol table. - // warning, this could be looking for a->b.c.d->e.f->g - varname = strdup(name); + subpart = splitVariableName(varname); - char *dot = strstr(varname, "."); - char *arrow = strstr(varname, "->"); - if (dot != NULL && arrow != NULL) { // dot AND arrow, - fprintf(stderr, "chillast.cc symbolTableFindVariableNamed(), name '%s' has both dot and arrow? TODO\n"); - exit(-1); - } else if (dot != NULL && !arrow) { // just dot(s). dot points to the first one - //fprintf(stderr, "name '%s' has dot(s)\n", varname); - *dot = '\0'; // end string at the dot - subpart = &(dot[1]); - fprintf(stderr, "will now look for a struct/class named %s that has member %s\n", varname, subpart); - - } else if (arrow != NULL && !dot) { // just arrow(s) arrow points to the first one - //fprintf(stderr, "name '%s' has arrow(s)\n", varname); - *arrow = '\0'; // end string at the arrow - subpart = &(arrow[2]); - fprintf(stderr, "will now look for a struct/class named %s that has member %s\n", varname, subpart); - } else { // impossible - fprintf(stderr, - "chillast.cc symbolTableFindVariableNamed(), varname '%s', looks like a struct, but I can't figure it out\n", - varname); - exit(-1); + if (decl->isAStruct()) { + CHILL_DEBUG_PRINT("Finding %s in a struct of type %s\n", varname, decl->getTypeString()); + if (decl->isVarDecl()) { + chillAST_RecordDecl *rd = decl->getStructDef(); + if (rd) { + chillAST_VarDecl *sp = rd->findSubpart(varname); + if (sp) CHILL_DEBUG_PRINT("found a struct member named %s\n", varname); + else + CHILL_DEBUG_PRINT("DIDN'T FIND a struct member named %s\n", varname); + if (!subpart) + return sp; + return variableDeclFindSubpart(sp,subpart); // return the subpart?? + } else { + CHILL_ERROR("no recordDecl\n"); + exit(-1); + } + } else { + CHILL_ERROR("NOT a VarDecl???\n"); // impossible } } else { - varname = strdup(name); + fprintf(stderr, "false alarm. %s is a variable, but doesn't have subparts\n", varname); + return NULL; } +} - int numvars = table->size(); - for (int i = 0; i < numvars; i++) { - chillAST_VarDecl *vd = (*table)[i]; - if (!strcmp(varname, vd->varname)) { - fprintf(stderr, "found variable named %s\n", varname); - - if (!subpart) return vd; // need to check type? - - // OK, we have a variable, which looks like a struct/class, and a subpart that is some member names - //fprintf(stderr, "but I don't know how to check if it has member %s\n", subpart); - - char *dot = strstr(subpart, "."); - char *arrow = strstr(subpart, "->"); - - if (!dot && !arrow) { // whew, only one level of struct - //fprintf(stderr, "whew, only one level of struct\n"); - - // make sure this variable definition is a struct - if (vd->isAStruct()) { - //fprintf(stderr, "%s is a struct of type %s\n", varname, vd->getTypeString()); - if (vd->isVarDecl()) { - chillAST_RecordDecl *rd = vd->getStructDef(); - if (rd) { - //fprintf(stderr, "has a recordDecl\n"); - - chillAST_VarDecl *sp = rd->findSubpart(subpart); - if (sp) fprintf(stderr, "found a struct member named %s\n", subpart); - else fprintf(stderr, "DIDN'T FIND a struct member named %s\n", subpart); - return sp; // return the subpart?? - } else { - fprintf(stderr, "no recordDecl\n"); - exit(-1); - } - } else { - fprintf(stderr, "NOT a VarDecl???\n"); // impossible - } - } else { - fprintf(stderr, "false alarm. %s is a variable, but doesn't have subparts\n", varname); - return NULL; // false alarm. a variable of the correct name exists, but is not a struct - } - } +chillAST_VarDecl *symbolTableFindVariableNamed(chillAST_SymbolTable *table, + const char *name) { // fwd decl TODO too many similar named functions + if (!table) return NULL; // ?? - fprintf(stderr, - "chillast.cc symbolTableFindVariableNamed(), name '%s' can't figure out multiple levels of struct yet!\n"); + char *varname = strdup(name), *subpart; - exit(-1); - } - } - return NULL; -} + subpart = splitVariableName(varname); + chillAST_VarDecl *vd = symbolTableFindName(table, varname); -char *ulhack(char *brackets) // remove UL from numbers, MODIFIES the argument! + if (!subpart) + return vd; + return variableDeclFindSubpart(vd,subpart); +} + +//! remove UL from numbers, MODIFIES the argument! +char *ulhack(char *brackets) { - //fprintf(stderr, "ulhack( \"%s\" -> ", brackets); - // another hack. remove "UL" from integers + CHILL_DEBUG_PRINT("ulhack( \"%s\" -> ", brackets); int len = strlen(brackets); for (int i = 0; i < len - 2; i++) { if (isdigit(brackets[i])) { - if (brackets[i + 1] == 'U' && brackets[i + 2] == 'L') { - // remove + if (brackets[i + 1] == 'U' && brackets[i + 2] == 'L') { // remove for (int j = i + 3; j < len; j++) brackets[j - 2] = brackets[j]; len -= 2; brackets[len] = '\0'; } } } - //fprintf(stderr, "\"%s\" )\n", brackets); + CHILL_DEBUG_PRINT("%s", brackets); return brackets; } -char *restricthack(char *typeinfo) // remove __restrict__ , MODIFIES the argument! +//! remove __restrict__ , MODIFIES the argument! +char *restricthack(char *typeinfo) { - //if (!isRestrict( typeinfo )) return typeinfo; - - // there is a "__restrict__ " somewhere embedded. remove it. - // duplicate work + CHILL_DEBUG_PRINT("restricthack( \"%s\" -> ", typeinfo); std::string r("__restrict__"); std::string t(typeinfo); size_t index = t.find(r); @@ -238,16 +208,15 @@ char *restricthack(char *typeinfo) // remove __restrict__ , MODIFIES the argumen char *after = c + 12; if (*after == ' ') after++; - //fprintf(stderr, "after = '%s'\n", after); - while (*after != '\0') *c++ = *after++; *c = '\0'; + CHILL_DEBUG_PRINT("%s", typeinfo); return typeinfo; } - +// TODO DOC char *parseArrayParts(char *sometype) { int len = strlen(sometype); char *arraypart = (char *) calloc(1 + strlen(sometype), sizeof(char));// leak @@ -266,7 +235,7 @@ char *parseArrayParts(char *sometype) { ulhack(arraypart); restricthack(arraypart); - //fprintf(stderr, "parseArrayParts( %s ) => %s\n", sometype, arraypart); + CHILL_DEBUG_PRINT("parseArrayParts( %s ) => %s\n", sometype, arraypart); return arraypart; } @@ -305,7 +274,7 @@ bool streq(const char *a, const char *b) { return !strcmp(a, b); }; // slightly void chillindent(int howfar, FILE *fp) { for (int i = 0; i < howfar; i++) fprintf(fp, " "); } -chillAST_VarDecl *chillAST_node::findVariableNamed(const char *name) { // generic, recursive +chillAST_VarDecl *chillAST_Node::findVariableNamed(const char *name) { // generic, recursive fprintf(stderr, "nodetype %s findVariableNamed( %s )\n", getTypeString(), name); if (hasSymbolTable()) { // look in my symbol table if I have one fprintf(stderr, "%s has a symbol table\n", getTypeString()); @@ -327,7 +296,7 @@ chillAST_VarDecl *chillAST_node::findVariableNamed(const char *name) { // generi } -chillAST_RecordDecl *chillAST_node::findRecordDeclNamed(const char *name) { // recursive +chillAST_RecordDecl *chillAST_Node::findRecordDeclNamed(const char *name) { // recursive fprintf(stderr, "%s::findRecordDeclNamed( %s )\n", getTypeString(), name); // look in children int numchildren = children.size(); @@ -350,27 +319,27 @@ chillAST_RecordDecl *chillAST_node::findRecordDeclNamed(const char *name) { // r } -void chillAST_node::printPreprocBEFORE(int indent, FILE *fp) { +void chillAST_Node::printPreprocBEFORE(int indent, FILE *fp) { int numstmts = preprocessinginfo.size(); //if (0 != numstmts) { - // fprintf(fp, "chillAST_node::printPreprocBEFORE() %d statements\n", numstmts); + // fprintf(fp, "chillAST_Node::printPreprocBEFORE() %d statements\n", numstmts); //} for (int i = 0; i < numstmts; i++) { //fprintf(fp, "stmt %d %d\n", i, preprocessinginfo[i]->position); - if (preprocessinginfo[i]->position == CHILL_PREPROCESSING_LINEBEFORE || - preprocessinginfo[i]->position == CHILL_PREPROCESSING_IMMEDIATELYBEFORE) { + if (preprocessinginfo[i]->position == CHILLAST_PREPROCESSING_LINEBEFORE || + preprocessinginfo[i]->position == CHILLAST_PREPROCESSING_IMMEDIATELYBEFORE) { //fprintf(stderr, "before %d\n", preprocessinginfo[i]->position); preprocessinginfo[i]->print(indent, fp); } } } -void chillAST_node::printPreprocAFTER(int indent, FILE *fp) { +void chillAST_Node::printPreprocAFTER(int indent, FILE *fp) { for (int i = 0; i < preprocessinginfo.size(); i++) { - if (preprocessinginfo[i]->position == CHILL_PREPROCESSING_LINEAFTER || - preprocessinginfo[i]->position == CHILL_PREPROCESSING_TOTHERIGHT) { + if (preprocessinginfo[i]->position == CHILLAST_PREPROCESSING_LINEAFTER || + preprocessinginfo[i]->position == CHILLAST_PREPROCESSING_TOTHERIGHT) { //fprintf(stderr, "after %d\n", preprocessinginfo[i]->position); preprocessinginfo[i]->print(indent, fp); } @@ -378,9 +347,8 @@ void chillAST_node::printPreprocAFTER(int indent, FILE *fp) { } -chillAST_SourceFile::chillAST_SourceFile::chillAST_SourceFile() { +chillAST_SourceFile::chillAST_SourceFile() { SourceFileName = strdup("No Source File"); - asttype = CHILLAST_NODETYPE_SOURCEFILE; parent = NULL; // top node metacomment = NULL; global_symbol_table = NULL; @@ -393,7 +361,6 @@ chillAST_SourceFile::chillAST_SourceFile::chillAST_SourceFile() { chillAST_SourceFile::chillAST_SourceFile(const char *filename) { SourceFileName = strdup(filename); - asttype = CHILLAST_NODETYPE_SOURCEFILE; parent = NULL; // top node metacomment = NULL; global_symbol_table = NULL; @@ -539,9 +506,9 @@ chillAST_FunctionDecl *chillAST_SourceFile::findFunction(const char *name) { } -chillAST_node *chillAST_SourceFile::findCall(const char *name) { +chillAST_Node *chillAST_SourceFile::findCall(const char *name) { chillAST_MacroDefinition *macro = findMacro(name); - if (macro) return (chillAST_node *) macro; + if (macro) return (chillAST_Node *) macro; chillAST_FunctionDecl *func = findFunction(name); return func; } @@ -579,7 +546,6 @@ chillAST_VarDecl *chillAST_SourceFile::findVariableNamed(const char *name) { chillAST_TypedefDecl::chillAST_TypedefDecl() { underlyingtype = newtype = arraypart = NULL; - asttype = CHILLAST_NODETYPE_TYPEDEFDECL; parent = NULL; metacomment = NULL; isStruct = isUnion = false; @@ -590,12 +556,11 @@ chillAST_TypedefDecl::chillAST_TypedefDecl() { }; -chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, const char *nt, chillAST_node *par) { +chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, const char *nt, chillAST_Node *par) { //fprintf(stderr, "chillAST_TypedefDecl::chillAST_TypedefDecl( underlying type %s, newtype %s )\n", t, nt); underlyingtype = strdup(t); newtype = strdup(nt); arraypart = NULL; - asttype = CHILLAST_NODETYPE_TYPEDEFDECL; parent = NULL; metacomment = NULL; isStruct = isUnion = false; @@ -606,7 +571,7 @@ chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, const char *nt, chillAST_nod }; -chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, const char *a, char *p, chillAST_node *par) { +chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, const char *a, char *p, chillAST_Node *par) { underlyingtype = strdup(t); //fprintf(stderr, "chillAST_TypedefDecl::chillAST_TypedefDecl( underlying type %s )\n", underlyingtype); newtype = strdup(a); // the new named type ?? @@ -614,7 +579,6 @@ chillAST_TypedefDecl::chillAST_TypedefDecl(char *t, const char *a, char *p, chil arraypart = strdup(p); // array (p)art? // splitarraypart(); // TODO - asttype = CHILLAST_NODETYPE_TYPEDEFDECL; parent = par; metacomment = NULL; isStruct = isUnion = false; @@ -699,7 +663,6 @@ chillAST_RecordDecl *chillAST_TypedefDecl::getStructDef() { chillAST_RecordDecl::chillAST_RecordDecl() { - asttype = CHILLAST_NODETYPE_RECORDDECL; name = strdup("unknown"); // ?? originalname = NULL; // ?? isStruct = isUnion = false; @@ -708,9 +671,8 @@ chillAST_RecordDecl::chillAST_RecordDecl() { filename = NULL; } -chillAST_RecordDecl::chillAST_RecordDecl(const char *nam, chillAST_node *p) { +chillAST_RecordDecl::chillAST_RecordDecl(const char *nam, chillAST_Node *p) { //fprintf(stderr, "chillAST_RecordDecl::chillAST_RecordDecl()\n"); - asttype = CHILLAST_NODETYPE_RECORDDECL; parent = p; if (nam) name = strdup(nam); else name = strdup("unknown"); // ?? @@ -720,9 +682,8 @@ chillAST_RecordDecl::chillAST_RecordDecl(const char *nam, chillAST_node *p) { filename = NULL; } -chillAST_RecordDecl::chillAST_RecordDecl(const char *nam, const char *orig, chillAST_node *p) { +chillAST_RecordDecl::chillAST_RecordDecl(const char *nam, const char *orig, chillAST_Node *p) { fprintf(stderr, "chillAST_RecordDecl::chillAST_RecordDecl( %s, ( AKA %s ) )\n", nam, orig); - asttype = CHILLAST_NODETYPE_RECORDDECL; parent = p; if (p) p->addChild(this); @@ -833,7 +794,6 @@ void chillAST_RecordDecl::dump(int indent, FILE *fp) { chillAST_FunctionDecl::chillAST_FunctionDecl() { functionName = strdup("YouScrewedUp"); - asttype = CHILLAST_NODETYPE_FUNCTIONDECL; forwarddecl = externfunc = builtin = false; uniquePtr = (void *) NULL; this->setFunctionCPU(); @@ -847,14 +807,13 @@ chillAST_FunctionDecl::chillAST_FunctionDecl() { }; -chillAST_FunctionDecl::chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_node *par) { +chillAST_FunctionDecl::chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_Node *par) { returnType = strdup(rt); functionName = strdup(fname); this->setFunctionCPU(); //fprintf(stderr, "functionName %s\n", functionName); forwarddecl = externfunc = builtin = false; - asttype = CHILLAST_NODETYPE_FUNCTIONDECL; parent = par; metacomment = NULL; if (par) par->getSourceFile()->addFunc(this); @@ -866,7 +825,7 @@ chillAST_FunctionDecl::chillAST_FunctionDecl(const char *rt, const char *fname, }; -chillAST_FunctionDecl::chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_node *par, void *unique) { +chillAST_FunctionDecl::chillAST_FunctionDecl(const char *rt, const char *fname, chillAST_Node *par, void *unique) { CHILL_DEBUG_PRINT("chillAST_FunctionDecl::chillAST_FunctionDecl with unique %p\n", unique); returnType = strdup(rt); functionName = strdup(fname); @@ -875,7 +834,6 @@ chillAST_FunctionDecl::chillAST_FunctionDecl(const char *rt, const char *fname, forwarddecl = externfunc = builtin = false; body = new chillAST_CompoundStmt(); - asttype = CHILLAST_NODETYPE_FUNCTIONDECL; uniquePtr = unique; // a quick way to check equivalence. DO NOT ACCESS THROUGH THIS parent = par; metacomment = NULL; @@ -891,7 +849,7 @@ void chillAST_FunctionDecl::addParameter(chillAST_VarDecl *p) { CHILL_DEBUG_PRINT("%s chillAST_FunctionDecl::addParameter( 0x%x param %s) total of %d parameters\n", functionName, p, p->varname, 1 + parameters.size()); - if (symbolTableHasVariableNamed(¶meters, p->varname)) { // NOT recursive. just in FunctionDecl + if (symbolTableFindName(¶meters, p->varname)) { // NOT recursive. just in FunctionDecl CHILL_DEBUG_PRINT("chillAST_FunctionDecl::addParameter( %s ), parameter already exists?\n", p->varname); // exit(-1); // ?? return; // error? @@ -971,7 +929,7 @@ chillAST_VarDecl *chillAST_FunctionDecl::funcHasVariableNamed(const char *name) } -void chillAST_FunctionDecl::setBody(chillAST_node *bod) { +void chillAST_FunctionDecl::setBody(chillAST_Node *bod) { //fprintf(stderr, "%s chillAST_FunctionDecl::setBody( 0x%x ) total of %d children\n", functionName, bod, 1+children.size()); if (bod->isCompoundStmt()) body = (chillAST_CompoundStmt *) bod; else { @@ -984,7 +942,7 @@ void chillAST_FunctionDecl::setBody(chillAST_node *bod) { } -void chillAST_FunctionDecl::insertChild(int i, chillAST_node *node) { +void chillAST_FunctionDecl::insertChild(int i, chillAST_Node *node) { fprintf(stderr, "chillAST_FunctionDecl::insertChild() "); node->print(0, stderr); fprintf(stderr, "\n\n"); @@ -1004,7 +962,7 @@ void chillAST_FunctionDecl::insertChild(int i, chillAST_node *node) { } } -void chillAST_FunctionDecl::addChild(chillAST_node *node) { +void chillAST_FunctionDecl::addChild(chillAST_Node *node) { CHILL_DEBUG_BEGIN node->print(0, stderr); fprintf(stderr, "\n\n"); @@ -1045,7 +1003,7 @@ void chillAST_FunctionDecl::print(int indent, FILE *fp) { if (externfunc) fprintf(fp, "extern "); - if (function_type == CHILL_FUNCTION_GPU) fprintf(fp, "__global__ "); + if (function_type == CHILLAST_FUNCTION_GPU) fprintf(fp, "__global__ "); fprintf(fp, "%s %s", returnType, functionName); printParameterTypes(fp); @@ -1227,7 +1185,7 @@ void chillAST_FunctionDecl::cleanUpVarDecls() { //fprintf(stderr, "deleting %d vardecls\n", deletethese.size()); for (int i = 0; i < deletethese.size(); i++) { //fprintf(stderr, "deleting varDecl %s\n", deletethese[i]->varname); - chillAST_node *par = deletethese[i]->parent; + chillAST_Node *par = deletethese[i]->parent; par->removeChild(par->findChild(deletethese[i])); } @@ -1264,7 +1222,7 @@ bool chillAST_FunctionDecl::findLoopIndexesToReplace(chillAST_SymbolTable *symta } -chillAST_node *chillAST_FunctionDecl::constantFold() { +chillAST_Node *chillAST_FunctionDecl::constantFold() { //fprintf(stderr, "chillAST_FunctionDecl::constantFold()\n"); // parameters can't have constants? int numparameters = parameters.size(); @@ -1279,7 +1237,6 @@ chillAST_node *chillAST_FunctionDecl::constantFold() { chillAST_MacroDefinition::chillAST_MacroDefinition() { macroName = strdup("UNDEFINEDMACRO"); rhsString = NULL; - asttype = CHILLAST_NODETYPE_MACRODEFINITION; parent = NULL; metacomment = NULL; symbol_table = NULL; @@ -1289,10 +1246,9 @@ chillAST_MacroDefinition::chillAST_MacroDefinition() { }; -chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname, chillAST_node *par) { +chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname, chillAST_Node *par) { macroName = strdup(mname); rhsString = NULL; - asttype = CHILLAST_NODETYPE_MACRODEFINITION; parent = par; metacomment = NULL; symbol_table = NULL; @@ -1308,10 +1264,9 @@ chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname, chillAST_n }; -chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname, const char *rhs, chillAST_node *par) { +chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname, const char *rhs, chillAST_Node *par) { macroName = strdup(mname); rhsString = strdup(rhs); - asttype = CHILLAST_NODETYPE_MACRODEFINITION; parent = par; metacomment = NULL; symbol_table = NULL; @@ -1326,7 +1281,7 @@ chillAST_MacroDefinition::chillAST_MacroDefinition(const char *mname, const char }; -chillAST_node *chillAST_MacroDefinition::clone() { +chillAST_Node *chillAST_MacroDefinition::clone() { // TODO ?? cloning a macro makes no sense return this; @@ -1342,7 +1297,7 @@ chillAST_node *chillAST_MacroDefinition::clone() { } -void chillAST_MacroDefinition::setBody(chillAST_node *bod) { +void chillAST_MacroDefinition::setBody(chillAST_Node *bod) { fprintf(stderr, "%s chillAST_MacroDefinition::setBody( 0x%x )\n", macroName, bod); body = bod; fprintf(stderr, "body is:\n"); @@ -1373,11 +1328,11 @@ chillAST_VarDecl *chillAST_MacroDefinition::hasParameterNamed(const char *name) } -void chillAST_MacroDefinition::insertChild(int i, chillAST_node *node) { +void chillAST_MacroDefinition::insertChild(int i, chillAST_Node *node) { body->insertChild(i, node); } -void chillAST_MacroDefinition::addChild(chillAST_node *node) { +void chillAST_MacroDefinition::addChild(chillAST_Node *node) { body->addChild(node); node->parent = this; // this, or body?? } @@ -1425,7 +1380,6 @@ chillAST_ForStmt::chillAST_ForStmt() { init = cond = incr = NULL; body = new chillAST_CompoundStmt(); - asttype = CHILLAST_NODETYPE_LOOP; // breaking with tradition, this was CHILL_AST_FORSTMT conditionoperator = IR_COND_UNKNOWN; parent = NULL; metacomment = NULL; @@ -1435,8 +1389,8 @@ chillAST_ForStmt::chillAST_ForStmt() { } -chillAST_ForStmt::chillAST_ForStmt(chillAST_node *ini, chillAST_node *con, chillAST_node *inc, chillAST_node *bod, - chillAST_node *par) { +chillAST_ForStmt::chillAST_ForStmt(chillAST_Node *ini, chillAST_Node *con, chillAST_Node *inc, chillAST_Node *bod, + chillAST_Node *par) { parent = par; metacomment = NULL; init = ini; @@ -1451,8 +1405,6 @@ chillAST_ForStmt::chillAST_ForStmt(chillAST_node *ini, chillAST_node *con, chill if (body) body->setParent(this); // not sure this should be legal - asttype = CHILLAST_NODETYPE_LOOP; // breaking with tradition, this was CHILL_AST_FORSTMT - if (!cond->isBinaryOperator()) { fprintf(stderr, "ForStmt conditional is of type %s. Expecting a BinaryOperator\n", cond->getTypeString()); exit(-1); @@ -1583,10 +1535,10 @@ void chillAST_ForStmt::print(int indent, FILE *fp) { // A forstmt with compounds inside compounds ??? // this should probably all go away - chillAST_node *b = body; + chillAST_Node *b = body; //fprintf(fp, "b children %d\n", b->getNumChildren()); //fprintf(fp, "body child 0 of type %s\n", b->children[0]->getTypeString()); - //fprintf(stderr, "forstmt body type %s\n", Chill_AST_Node_Names[b->asttype] ); + //fprintf(stderr, "forstmt body type %s\n", Chill_AST_Node_Names[b->getType()] ); // deal with a tree of compound statements, in an ugly way. leave the ugliness while (1 == b->getNumChildren() && b->children[0]->isCompoundStmt()) { b = b->children[0]; @@ -1607,7 +1559,7 @@ void chillAST_ForStmt::print(int indent, FILE *fp) { b->print(indent + 1, fp); // I think this can't happen any more. body is always a compound statement - if (b->asttype == CHILLAST_NODETYPE_BINARYOPERATOR) { // a single assignment statement + if (b->getType() == CHILLAST_NODE_BINARYOPERATOR) { // a single assignment statement fprintf(fp, ";\n"); } @@ -1636,7 +1588,7 @@ void chillAST_ForStmt::dump(int indent, FILE *fp) { fprintf(fp, ")\n"); } -chillAST_node *chillAST_ForStmt::constantFold() { +chillAST_Node *chillAST_ForStmt::constantFold() { init = init->constantFold(); cond = cond->constantFold(); incr = incr->constantFold(); @@ -1645,7 +1597,7 @@ chillAST_node *chillAST_ForStmt::constantFold() { } -chillAST_node *chillAST_ForStmt::clone() { +chillAST_Node *chillAST_ForStmt::clone() { chillAST_ForStmt *fs = new chillAST_ForStmt(init->clone(), cond->clone(), incr->clone(), body->clone(), parent); fs->isFromSourceFile = isFromSourceFile; if (filename) fs->filename = strdup(filename); @@ -1708,7 +1660,7 @@ void chillAST_ForStmt::gatherVarUsage(vector<chillAST_VarDecl *> &decls) { body->gatherVarUsage(decls); } -void chillAST_ForStmt::gatherStatements(std::vector<chillAST_node *> &statements) { +void chillAST_ForStmt::gatherStatements(std::vector<chillAST_Node *> &statements) { // for completeness, should do all 4. Maybe someday //init->gatherStatements( statements ); @@ -1743,7 +1695,7 @@ void chillAST_ForStmt::addSyncs() { if (parent->isCompoundStmt()) { //fprintf(stderr, "ForStmt parent is CompoundStmt 0x%x\n", parent); - vector<chillAST_node *> chillin = parent->getChildren(); + vector<chillAST_Node *> chillin = parent->getChildren(); int numc = chillin.size(); //fprintf(stderr, "ForStmt parent is CompoundStmt 0x%x with %d children\n", parent, numc); for (int i = 0; i < numc; i++) { @@ -1869,7 +1821,7 @@ bool chillAST_ForStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bo // find parent of the ForStmt? // find parent^n of the ForStmt that is not a Forstmt? // find parent^n of the Forstmt that is a FunctionDecl? - chillAST_node *contain = findContainingNonLoop(); + chillAST_Node *contain = findContainingNonLoop(); if (contain == NULL) { fprintf(stderr, "nothing but loops all the way up?\n"); exit(0); @@ -1880,7 +1832,7 @@ bool chillAST_ForStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bo contain->insertChild(0, newguy); // ugly order TODO contain->addVariableToSymbolTable(newguy); // adds to first enclosing symbolTable - if (!symbolTableHasVariableNamed(contain->getSymbolTable(), vname)) { + if (!symbolTableFindName(contain->getSymbolTable(), vname)) { fprintf(stderr, "container doesn't have a var names %s afterwards???\n", vname); exit(-1); } @@ -1932,7 +1884,7 @@ bool chillAST_ForStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, bo return force; } -void chillAST_ForStmt::replaceChild(chillAST_node *old, chillAST_node *newchild) { +void chillAST_ForStmt::replaceChild(chillAST_Node *old, chillAST_Node *newchild) { //fprintf(stderr, "chillAST_ForStmt::replaceChild() REALLY CALLING BODY->ReplaceCHILD\n"); body->replaceChild(old, newchild); } @@ -2053,7 +2005,7 @@ void chillAST_ForStmt::loseLoopWithLoopVar(char *var) { fprintf(stderr, "chill_ast.cc multiple loop variables confuses me\n"); exit(-1); } - chillAST_node *newstmt = body; + chillAST_Node *newstmt = body; // ACTUALLY, if I am being replaced, and my loop conditional is a min (Ternary), then wrap my loop body in an if statement if (cond->isBinaryOperator()) { // what else could it be? @@ -2067,14 +2019,14 @@ void chillAST_ForStmt::loseLoopWithLoopVar(char *var) { C->print(); printf("\n"); fflush(stdout); - chillAST_node *l = C->lhs; + chillAST_Node *l = C->lhs; if (l->isParenExpr()) l = ((chillAST_ParenExpr *) l)->subexpr; - chillAST_node *r = C->rhs; + chillAST_Node *r = C->rhs; if (r->isParenExpr()) r = ((chillAST_ParenExpr *) r)->subexpr; //fprintf(stderr, "lhs is %s rhs is %s\n", l->getTypeString(), r->getTypeString()); - chillAST_node *ifcondrhs = NULL; + chillAST_Node *ifcondrhs = NULL; if (!(l->isConstant())) ifcondrhs = l; else if (!(r->isConstant())) ifcondrhs = r; else { @@ -2110,14 +2062,13 @@ chillAST_BinaryOperator::chillAST_BinaryOperator() { CHILL_DEBUG_PRINT("no parent\n"); lhs = rhs = NULL; op = NULL; - asttype = CHILLAST_NODETYPE_BINARYOPERATOR; isFromSourceFile = true; // default filename = NULL; } -chillAST_BinaryOperator::chillAST_BinaryOperator(chillAST_node *l, const char *oper, chillAST_node *r, - chillAST_node *par) { +chillAST_BinaryOperator::chillAST_BinaryOperator(chillAST_Node *l, const char *oper, chillAST_Node *r, + chillAST_Node *par) { //fprintf(stderr, "chillAST_BinaryOperator::chillAST_BinaryOperator( l %p %s r %p, parent %p) this %p\n", l, oper, r, par, this); CHILL_DEBUG_PRINT("( l %s r )\n", oper); @@ -2132,7 +2083,6 @@ chillAST_BinaryOperator::chillAST_BinaryOperator(chillAST_node *l, const char *o if (lhs) lhs->setParent(this); if (rhs) rhs->setParent(this); // may only have part of the lhs and rhs when binop is created op = strdup(oper); - asttype = CHILLAST_NODETYPE_BINARYOPERATOR; // if this writes to lhs and lhs type has an 'imwrittento' concept, set that up if (isAssignmentOp()) { @@ -2278,14 +2228,14 @@ void chillAST_BinaryOperator::printonly(int indent, FILE *fp) { } -class chillAST_node *chillAST_BinaryOperator::constantFold() { +class chillAST_Node *chillAST_BinaryOperator::constantFold() { //fprintf(stderr, "\nchillAST_BinaryOperator::constantFold() "); //print(0,stderr); fprintf(stderr, "\n"); lhs = lhs->constantFold(); rhs = rhs->constantFold(); - chillAST_node *returnval = this; + chillAST_Node *returnval = this; if (lhs->isConstant() && rhs->isConstant()) { //fprintf(stderr, "binop folding constants\n"); print(0,stderr); fprintf(stderr, "\n"); @@ -2340,11 +2290,11 @@ class chillAST_node *chillAST_BinaryOperator::constantFold() { } -class chillAST_node *chillAST_BinaryOperator::clone() { +class chillAST_Node *chillAST_BinaryOperator::clone() { //fprintf(stderr, "chillAST_BinaryOperator::clone() "); print(); printf("\n"); fflush(stdout); - chillAST_node *l = lhs->clone(); - chillAST_node *r = rhs->clone(); + chillAST_Node *l = lhs->clone(); + chillAST_Node *r = rhs->clone(); chillAST_BinaryOperator *bo = new chillAST_BinaryOperator(l, op, r, parent); l->setParent(bo); r->setParent(bo); @@ -2389,7 +2339,7 @@ void chillAST_BinaryOperator::gatherScalarRefs(std::vector<chillAST_DeclRefExpr } -void chillAST_BinaryOperator::replaceChild(chillAST_node *old, chillAST_node *newchild) { +void chillAST_BinaryOperator::replaceChild(chillAST_Node *old, chillAST_Node *newchild) { //fprintf(stderr, "\nbinop::replaceChild( old 0x%x, new ) lhs 0x%x rhd 0x%x\n", old, lhs, rhs); // will pointers match?? @@ -2443,7 +2393,7 @@ void chillAST_BinaryOperator::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> } -void chillAST_BinaryOperator::gatherStatements(std::vector<chillAST_node *> &statements) { +void chillAST_BinaryOperator::gatherStatements(std::vector<chillAST_Node *> &statements) { // what's legit? if (isAssignmentOp()) { @@ -2477,7 +2427,7 @@ void chillAST_BinaryOperator::replaceVarDecls(chillAST_VarDecl *olddecl, chillAS } -bool chillAST_BinaryOperator::isSameAs(chillAST_node *other) { +bool chillAST_BinaryOperator::isSameAs(chillAST_Node *other) { if (!other->isBinaryOperator()) return false; chillAST_BinaryOperator *o = (chillAST_BinaryOperator *) other; if (strcmp(op, o->op)) return false; // different operators @@ -2488,13 +2438,12 @@ bool chillAST_BinaryOperator::isSameAs(chillAST_node *other) { chillAST_TernaryOperator::chillAST_TernaryOperator() { op = strdup("?"); // the only one so far condition = lhs = rhs = NULL; - asttype = CHILLAST_NODETYPE_TERNARYOPERATOR; isFromSourceFile = true; // default filename = NULL; } -chillAST_TernaryOperator::chillAST_TernaryOperator(const char *oper, chillAST_node *c, chillAST_node *l, - chillAST_node *r, chillAST_node *par) { +chillAST_TernaryOperator::chillAST_TernaryOperator(const char *oper, chillAST_Node *c, chillAST_Node *l, + chillAST_Node *r, chillAST_Node *par) { op = strdup(oper); condition = c; @@ -2503,7 +2452,6 @@ chillAST_TernaryOperator::chillAST_TernaryOperator(const char *oper, chillAST_no lhs->setParent(this); rhs = r; rhs->setParent(this); - asttype = CHILLAST_NODETYPE_TERNARYOPERATOR; isFromSourceFile = true; // default filename = NULL; } @@ -2532,7 +2480,7 @@ void chillAST_TernaryOperator::print(int indent, FILE *fp) { fflush(fp); } -void chillAST_TernaryOperator::replaceChild(chillAST_node *old, chillAST_node *newchild) { +void chillAST_TernaryOperator::replaceChild(chillAST_Node *old, chillAST_Node *newchild) { //fprintf(stderr, "\nbinop::replaceChild( old 0x%x, new ) lhs 0x%x rhd 0x%x\n", old, lhs, rhs); // will pointers match?? @@ -2601,12 +2549,12 @@ void chillAST_TernaryOperator::printonly(int indent, FILE *fp) { } -class chillAST_node *chillAST_TernaryOperator::constantFold() { +class chillAST_Node *chillAST_TernaryOperator::constantFold() { condition = condition->constantFold(); lhs = lhs->constantFold(); rhs = rhs->constantFold(); - chillAST_node *returnval = this; + chillAST_Node *returnval = this; if (condition->isConstant()) { //fprintf(stderr, "ternop folding constants\n"); @@ -2660,10 +2608,10 @@ class chillAST_node *chillAST_TernaryOperator::constantFold() { return returnval; } -class chillAST_node *chillAST_TernaryOperator::clone() { - chillAST_node *c = condition->clone(); - chillAST_node *l = lhs->clone(); - chillAST_node *r = rhs->clone(); +class chillAST_Node *chillAST_TernaryOperator::clone() { + chillAST_Node *c = condition->clone(); + chillAST_Node *l = lhs->clone(); + chillAST_Node *r = rhs->clone(); chillAST_TernaryOperator *to = new chillAST_TernaryOperator(op, l, r, parent); c->setParent(to); l->setParent(to); @@ -2688,7 +2636,6 @@ void chillAST_TernaryOperator::gatherScalarRefs(std::vector<chillAST_DeclRefExpr chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() { //fprintf(stderr, "\n%p chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 0\n", this); - asttype = CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR; base = index = NULL; basedecl = NULL; //fprintf(stderr, "setting basedecl NULL for ASE %p\n", this); imwrittento = false; // ?? @@ -2702,12 +2649,11 @@ chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() { } -chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_node *bas, chillAST_node *indx, chillAST_node *par, +chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_Node *bas, chillAST_Node *indx, chillAST_Node *par, void *unique) { //fprintf(stderr, "\nchillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 1\n"); //fprintf(stderr, "ASE index %p ", indx); indx->print(0,stderr); fprintf(stderr, "\n"); - asttype = CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR; bas->setParent(this); if (bas->isImplicitCastExpr()) base = ((chillAST_ImplicitCastExpr *) bas)->subexpr; // probably wrong else base = bas; @@ -2733,12 +2679,11 @@ chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_node *bas, chi } -chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_node *bas, chillAST_node *indx, bool writtento, - chillAST_node *par, void *unique) { +chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_Node *bas, chillAST_Node *indx, bool writtento, + chillAST_Node *par, void *unique) { //fprintf(stderr, "\nchillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 2 parent %p\n", par ); //fprintf(stderr, "ASE %p index %p ", this, indx); indx->print(0,stderr); fprintf(stderr, "\n"); - asttype = CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR; bas->setParent(this); if (bas->isImplicitCastExpr()) base = ((chillAST_ImplicitCastExpr *) bas)->subexpr; // probably wrong else base = bas; @@ -2773,11 +2718,10 @@ chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_node *bas, chi } -chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_VarDecl *v, std::vector<chillAST_node *> indeces, - chillAST_node *par) { +chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_VarDecl *v, std::vector<chillAST_Node *> indeces, + chillAST_Node *par) { //fprintf(stderr, "\nchillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr() 4\n"); //fprintf(stderr,"chillAST_ArraySubscriptExpr( chillAST_VarDecl *v, std::vector<int> indeces)\n"); - asttype = CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR; parent = par; //if (parent == NULL) { // fprintf(stderr, "dammit. ASE %p has no parent\n", this); @@ -2807,7 +2751,7 @@ chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_VarDecl *v, st chillAST_ArraySubscriptExpr *rent = this; // parent for subnodes // these are on the top level ASE that we're creating here - base = (chillAST_node *) DRE; + base = (chillAST_Node *) DRE; index = indeces[numindeces - 1]; base->setParent(this); @@ -2830,9 +2774,9 @@ chillAST_ArraySubscriptExpr::chillAST_ArraySubscriptExpr(chillAST_VarDecl *v, st } -chillAST_node *chillAST_node::getEnclosingStatement(int level) { // TODO do for subclasses? +chillAST_Node *chillAST_Node::getEnclosingStatement(int level) { // TODO do for subclasses? - //fprintf(stderr, "chillAST_node::getEnclosingStatement( level %d ) node type %s\n", level, getTypeString()); + //fprintf(stderr, "chillAST_Node::getEnclosingStatement( level %d ) node type %s\n", level, getTypeString()); //print(); printf("\n"); fflush(stdout); // so far, user will ONLY call this directly on an array subscript expression @@ -2863,7 +2807,7 @@ chillAST_node *chillAST_node::getEnclosingStatement(int level) { // TODO do for } -void chillAST_ArraySubscriptExpr::gatherIndeces(std::vector<chillAST_node *> &ind) { +void chillAST_ArraySubscriptExpr::gatherIndeces(std::vector<chillAST_Node *> &ind) { if (base->isArraySubscriptExpr()) ((chillAST_ArraySubscriptExpr *) base)->gatherIndeces(ind); ind.push_back(index); } @@ -2950,7 +2894,7 @@ void chillAST_ArraySubscriptExpr::print(int indent, FILE *fp) const { chillAST_VarDecl *chillAST_ArraySubscriptExpr::multibase() { // return the VARDECL of the thing the subscript is an index into - //this should probably be a chillAST_node function instead of having all these ifs + //this should probably be a chillAST_Node function instead of having all these ifs //print(); printf("\n"); fflush(stdout); //base->print(); printf("\n"); fflush(stdout); //fprintf(stderr, "chillAST_ArraySubscriptExpr::multibase() base of type %s\n", base->getTypeString()); @@ -2960,21 +2904,21 @@ chillAST_VarDecl *chillAST_ArraySubscriptExpr::multibase() { // this will be used to SET basedecl //basedecl = NULL; // do this so we don't confuse ourselves looking at uninitialized basedecl - chillAST_node *b = base; + chillAST_Node *b = base; //fprintf(stderr, "base is of type %s\n", b->getTypeString()); if (!b) return NULL; // just in case ?? - if (base->asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR) { // bad coding + if (base->getType() == CHILLAST_NODE_IMPLICITCASTEXPR) { // bad coding b = ((chillAST_ImplicitCastExpr *) b)->subexpr; } - if (b->asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR) { // multidimensional array! + if (b->getType() == CHILLAST_NODE_ARRAYSUBSCRIPTEXPR) { // multidimensional array! // recurse return ((chillAST_ArraySubscriptExpr *) b)->multibase(); } - if (b->asttype == CHILLAST_NODETYPE_DECLREFEXPR) return (((chillAST_DeclRefExpr *) b)->getVarDecl()); + if (b->getType() == CHILLAST_NODE_DECLREFEXPR) return (((chillAST_DeclRefExpr *) b)->getVarDecl()); if (b->isBinaryOperator()) { @@ -2986,8 +2930,8 @@ chillAST_VarDecl *chillAST_ArraySubscriptExpr::multibase() { exit(-1); } - chillAST_node *l = BO->lhs; - chillAST_node *r = BO->rhs; + chillAST_Node *l = BO->lhs; + chillAST_Node *r = BO->rhs; printf("L %s\nR %s\n", l->getTypeString(), r->getTypeString()); exit(-1); @@ -3000,7 +2944,7 @@ chillAST_VarDecl *chillAST_ArraySubscriptExpr::multibase() { chillAST_MemberExpr *ME = (chillAST_MemberExpr *) b; //fprintf(stderr, "multibase() Member Expression "); ME->print(); printf("\n"); fflush(stdout); - chillAST_node *n = ME->base; // WRONG want the MEMBER + chillAST_Node *n = ME->base; // WRONG want the MEMBER //fprintf(stderr, "chillAST_ArraySubscriptExpr::multibase() Member Expression base of type %s\n", n->getTypeString()); //fprintf(stderr, "base is "); ME->base->dump(); @@ -3057,17 +3001,17 @@ chillAST_VarDecl *chillAST_ArraySubscriptExpr::multibase() { } -chillAST_node *chillAST_ArraySubscriptExpr::getIndex(int dim) { +chillAST_Node *chillAST_ArraySubscriptExpr::getIndex(int dim) { //fprintf(stderr, "chillAST_ArraySubscriptExpr::getIndex( %d )\n", dim); - chillAST_node *b = base; + chillAST_Node *b = base; int depth = 0; - std::vector<chillAST_node *> ind; - chillAST_node *curindex = index; + std::vector<chillAST_Node *> ind; + chillAST_Node *curindex = index; for (;;) { - if (b->asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR) b = ((chillAST_ImplicitCastExpr *) b)->subexpr; - else if (b->asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR) { + if (b->getType() == CHILLAST_NODE_IMPLICITCASTEXPR) b = ((chillAST_ImplicitCastExpr *) b)->subexpr; + else if (b->getType() == CHILLAST_NODE_ARRAYSUBSCRIPTEXPR) { //fprintf(stderr, "base "); b->print(); fprintf(stderr, "\n"); //fprintf(stderr, "index "); curindex->print(); fprintf(stderr, "\n"); ind.push_back(curindex); @@ -3090,16 +3034,16 @@ chillAST_node *chillAST_ArraySubscriptExpr::getIndex(int dim) { if (dim == 0) return index; // single dimension fprintf(stderr, "DIM NOT 0\n"); // multidimension - chillAST_node *b = base; - if (base->asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR) { // bad coding + chillAST_Node *b = base; + if (base->getType() == CHILLAST_NODE_IMPLICITCASTEXPR) { // bad coding b = ((chillAST_ImplicitCastExpr*)b)->subexpr; } - if (b->asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR) { // bad coding + if (b->getType() == CHILLAST_NODE_IMPLICITCASTEXPR) { // bad coding b = ((chillAST_ImplicitCastExpr*)b)->subexpr; } b->print(); printf("\n"); fflush(stdout); - if (b->asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR) { + if (b->getType() == CHILLAST_NODE_ARRAYSUBSCRIPTEXPR) { return ((chillAST_ArraySubscriptExpr *)b)->getIndex(dim-1); } @@ -3109,14 +3053,14 @@ chillAST_node *chillAST_ArraySubscriptExpr::getIndex(int dim) { } -class chillAST_node *chillAST_ArraySubscriptExpr::constantFold() { +class chillAST_Node *chillAST_ArraySubscriptExpr::constantFold() { //fprintf(stderr, "chillAST_ArraySubscriptExpr::constantFold()\n"); base = base->constantFold(); index = index->constantFold(); return this; } -class chillAST_node *chillAST_ArraySubscriptExpr::clone() { +class chillAST_Node *chillAST_ArraySubscriptExpr::clone() { //fprintf(stderr,"chillAST_ArraySubscriptExpr::clone() old imwrittento %d\n", imwrittento); //fprintf(stderr, "cloning ASE %p ", this); print(0,stderr); printf(" with parent %p\n", parent); fflush(stdout); //fprintf(stderr, "base %p base->parent %p index %p index->parent %p\n", base, base->parent, index, index->parent); @@ -3128,11 +3072,11 @@ class chillAST_node *chillAST_ArraySubscriptExpr::clone() { //fprintf(stderr, "old decl "); vd->print(); printf("\n");fflush(stdout); //fprintf(stderr, "old decl "); vd->dump(); printf("\n");fflush(stdout); } - chillAST_node *b = base->clone(); + chillAST_Node *b = base->clone(); //fprintf(stderr, "new base "); b->print(); printf("\n"); fflush(stdout); //fprintf(stderr, "new base "); b->dump(); printf("\n"); fflush(stdout); - chillAST_node *i = index->clone(); + chillAST_Node *i = index->clone(); //fprintf(stderr, "new index "); i->print(); printf("\n"); fflush(stdout); @@ -3223,7 +3167,7 @@ void chillAST_ArraySubscriptExpr::replaceVarDecls(chillAST_VarDecl *olddecl, chi } -void chillAST_ArraySubscriptExpr::replaceChild(chillAST_node *old, chillAST_node *newchild) { +void chillAST_ArraySubscriptExpr::replaceChild(chillAST_Node *old, chillAST_Node *newchild) { //fprintf(stderr,"chillAST_ArraySubscriptExpr::replaceChild()\n"); // arraysubscriptexpression doesn t really have children (should it?) @@ -3275,19 +3219,17 @@ bool chillAST_ArraySubscriptExpr::operator==(const chillAST_ArraySubscriptExpr & chillAST_MemberExpr::chillAST_MemberExpr() { - asttype = CHILLAST_NODETYPE_MEMBEREXPR; base = NULL; member = NULL; parent = NULL; metacomment = NULL; - exptype = CHILL_MEMBER_EXP_DOT; + exptype = CHILLAST_MEMBER_EXP_DOT; isFromSourceFile = true; // default filename = NULL; } -chillAST_MemberExpr::chillAST_MemberExpr(chillAST_node *bas, const char *mem, chillAST_node *p, void *unique, - CHILL_MEMBER_EXP_TYPE t) { - asttype = CHILLAST_NODETYPE_MEMBEREXPR; +chillAST_MemberExpr::chillAST_MemberExpr(chillAST_Node *bas, const char *mem, chillAST_Node *p, void *unique, + CHILLAST_MEMBER_EXP_TYPE t) { base = bas; if (base) base->setParent(this); if (mem) member = strdup(mem); @@ -3328,7 +3270,7 @@ void chillAST_MemberExpr::dump(int indent, FILE *fp) { base->dump(indent + 1, fp); chillindent(indent + 1, fp); - if (exptype == CHILL_MEMBER_EXP_ARROW) fprintf(fp, "->"); + if (exptype == CHILLAST_MEMBER_EXP_ARROW) fprintf(fp, "->"); else fprintf(fp, "."); fprintf(fp, "%s\n", member); @@ -3344,7 +3286,7 @@ void chillAST_MemberExpr::print(int indent, FILE *fp) { chillindent(indent, fp); fprintf(fp, "(NULL)"); } - if (exptype == CHILL_MEMBER_EXP_ARROW) fprintf(fp, "->"); + if (exptype == CHILLAST_MEMBER_EXP_ARROW) fprintf(fp, "->"); else fprintf(fp, "."); if (member) fprintf(fp, "%s", member); else fprintf(fp, "(NULL)"); @@ -3354,7 +3296,7 @@ void chillAST_MemberExpr::print(int indent, FILE *fp) { void chillAST_MemberExpr::printonly(int indent, FILE *fp) { base->print(indent, fp); - if (exptype == CHILL_MEMBER_EXP_ARROW) fprintf(fp, "->"); + if (exptype == CHILLAST_MEMBER_EXP_ARROW) fprintf(fp, "->"); else fprintf(fp, "."); fprintf(fp, "%s", member); fflush(fp); @@ -3365,7 +3307,7 @@ char *chillAST_MemberExpr::stringRep(int indent) { // char pointer to what we'd if (base->isDeclRefExpr()) { // chillAST_VarDecl *vd = (chillAST_VarDecl *) ((chillAST_DeclRefExpr *) base)->decl; char *leak = (char *) malloc(128); - if (exptype == CHILL_MEMBER_EXP_ARROW) sprintf(leak, "%s->%s", vd->varname, member); + if (exptype == CHILLAST_MEMBER_EXP_ARROW) sprintf(leak, "%s->%s", vd->varname, member); else sprintf(leak, "%s.%s", vd->varname, member); printstring = leak; return leak; @@ -3378,14 +3320,14 @@ char *chillAST_MemberExpr::stringRep(int indent) { // char pointer to what we'd } -class chillAST_node *chillAST_MemberExpr::constantFold() { +class chillAST_Node *chillAST_MemberExpr::constantFold() { base = base->constantFold(); //member = member->constantFold(); return this; } -class chillAST_node *chillAST_MemberExpr::clone() { - chillAST_node *b = base->clone(); +class chillAST_Node *chillAST_MemberExpr::clone() { + chillAST_Node *b = base->clone(); char *m = strdup(member); // ?? chillAST_MemberExpr *ME = new chillAST_MemberExpr(b, m, parent, uniquePtr /* ?? */ ); ME->isFromSourceFile = isFromSourceFile; @@ -3444,7 +3386,7 @@ bool chillAST_MemberExpr::operator==(const chillAST_MemberExpr &other) { } -void chillAST_MemberExpr::replaceChild(chillAST_node *old, chillAST_node *newchild) { +void chillAST_MemberExpr::replaceChild(chillAST_Node *old, chillAST_Node *newchild) { //printf("\nMemberExpr::replaceChild( )\n"); //printf("old: "); //old->print(); @@ -3461,7 +3403,7 @@ void chillAST_MemberExpr::replaceChild(chillAST_node *old, chillAST_node *newchi } } -chillAST_node *chillAST_MemberExpr::multibase2() { /*fprintf(stderr, "ME MB2\n" );*/ return (chillAST_node *) this; } +chillAST_Node *chillAST_MemberExpr::multibase2() { /*fprintf(stderr, "ME MB2\n" );*/ return (chillAST_Node *) this; } chillAST_VarDecl *chillAST_MemberExpr::getUnderlyingVarDecl() { fprintf(stderr, "chillAST_MemberExpr:getUnderlyingVarDecl()\n"); @@ -3521,7 +3463,6 @@ chillAST_VarDecl *chillAST_MemberExpr::multibase() { chillAST_DeclRefExpr::chillAST_DeclRefExpr() { - asttype = CHILLAST_NODETYPE_DECLREFEXPR; declarationType = strdup("UNKNOWN"); declarationName = strdup("NONE"); decl = NULL; @@ -3531,8 +3472,7 @@ chillAST_DeclRefExpr::chillAST_DeclRefExpr() { filename = NULL; } -chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *varname, chillAST_node *par) { - asttype = CHILLAST_NODETYPE_DECLREFEXPR; +chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *varname, chillAST_Node *par) { declarationType = strdup("UNKNOWN"); declarationName = strdup(varname); decl = NULL; @@ -3541,9 +3481,8 @@ chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *varname, chillAST_node *p filename = NULL; } -chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *vartype, const char *varname, chillAST_node *par) { +chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *vartype, const char *varname, chillAST_Node *par) { //fprintf(stderr, "DRE::DRE 0x%x %s %s\n", this, vartype, varname ); - asttype = CHILLAST_NODETYPE_DECLREFEXPR; declarationType = strdup(vartype); declarationName = strdup(varname); decl = NULL; @@ -3552,10 +3491,9 @@ chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *vartype, const char *varn filename = NULL; } -chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *vartype, const char *varname, chillAST_node *d, - chillAST_node *par) { +chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *vartype, const char *varname, chillAST_Node *d, + chillAST_Node *par) { //fprintf(stderr, "DRE::DRE2 0x%x %s %s 0x%x\n", this, vartype, varname, d ); - asttype = CHILLAST_NODETYPE_DECLREFEXPR; declarationType = strdup(vartype); declarationName = strdup(varname); decl = d; @@ -3564,10 +3502,9 @@ chillAST_DeclRefExpr::chillAST_DeclRefExpr(const char *vartype, const char *varn filename = NULL; } -chillAST_DeclRefExpr::chillAST_DeclRefExpr(chillAST_VarDecl *vd, chillAST_node *par) { // variable def +chillAST_DeclRefExpr::chillAST_DeclRefExpr(chillAST_VarDecl *vd, chillAST_Node *par) { // variable def //fprintf(stderr, "DRE::DRE3 (VD) 0x%x %s %s 0x%x\n", this, vd->vartype, vd->varname, vd ); - asttype = CHILLAST_NODETYPE_DECLREFEXPR; declarationType = strdup(vd->vartype); declarationName = strdup(vd->varname); decl = vd; @@ -3577,8 +3514,7 @@ chillAST_DeclRefExpr::chillAST_DeclRefExpr(chillAST_VarDecl *vd, chillAST_node * } -chillAST_DeclRefExpr::chillAST_DeclRefExpr(chillAST_FunctionDecl *fd, chillAST_node *par) { // function def - asttype = CHILLAST_NODETYPE_DECLREFEXPR; +chillAST_DeclRefExpr::chillAST_DeclRefExpr(chillAST_FunctionDecl *fd, chillAST_Node *par) { // function def declarationType = strdup(fd->returnType); declarationName = strdup(fd->functionName); decl = fd; @@ -3625,11 +3561,11 @@ void chillAST_DeclRefExpr::dump(int indent, FILE *fp) { fflush(fp); } -class chillAST_node *chillAST_DeclRefExpr::constantFold() { // can never do anything? +class chillAST_Node *chillAST_DeclRefExpr::constantFold() { // can never do anything? return this; } -class chillAST_node *chillAST_DeclRefExpr::clone() { +class chillAST_Node *chillAST_DeclRefExpr::clone() { //fprintf(stderr, "chillAST_DeclRefExpr::clone()\n"); chillAST_DeclRefExpr *DRE = new chillAST_DeclRefExpr(declarationType, declarationName, decl, parent); DRE->isFromSourceFile = isFromSourceFile; @@ -3780,9 +3716,9 @@ void chillAST_VarDecl::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) { } -chillAST_node *chillAST_VarDecl::constantFold() { return this; } +chillAST_Node *chillAST_VarDecl::constantFold() { return this; } -chillAST_node *chillAST_VarDecl::clone() { +chillAST_Node *chillAST_VarDecl::clone() { fprintf(stderr, "\nchillAST_VarDecl::clone() cloning vardecl for %s\n", varname); if (isAParameter) fprintf(stderr, "old vardecl IS a parameter\n"); //else fprintf(stderr, "old vardecl IS NOT a parameter\n"); @@ -3875,9 +3811,8 @@ void chillAST_VarDecl::splitarraypart() { } -chillAST_IntegerLiteral::chillAST_IntegerLiteral(int val, chillAST_node *par) { +chillAST_IntegerLiteral::chillAST_IntegerLiteral(int val, chillAST_Node *par) { value = val; - asttype = CHILLAST_NODETYPE_INTEGERLITERAL; parent = par; isFromSourceFile = true; // default filename = NULL; @@ -3896,10 +3831,10 @@ void chillAST_IntegerLiteral::dump(int indent, FILE *fp) { } -class chillAST_node *chillAST_IntegerLiteral::constantFold() { return this; } // can never do anything +class chillAST_Node *chillAST_IntegerLiteral::constantFold() { return this; } // can never do anything -class chillAST_node *chillAST_IntegerLiteral::clone() { +class chillAST_Node *chillAST_IntegerLiteral::clone() { chillAST_IntegerLiteral *IL = new chillAST_IntegerLiteral(value, parent); IL->isFromSourceFile = isFromSourceFile; @@ -3908,65 +3843,60 @@ class chillAST_node *chillAST_IntegerLiteral::clone() { } -chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, chillAST_node *par) { +chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, chillAST_Node *par) { value = val; precision = 1; float0double1 = 0; // which is live! allthedigits = NULL; - asttype = CHILLAST_NODETYPE_FLOATINGLITERAL; parent = par; isFromSourceFile = true; // default filename = NULL; } -chillAST_FloatingLiteral::chillAST_FloatingLiteral(double val, chillAST_node *par) { +chillAST_FloatingLiteral::chillAST_FloatingLiteral(double val, chillAST_Node *par) { doublevalue = val; precision = 2; float0double1 = 1; // which is live! allthedigits = NULL; - asttype = CHILLAST_NODETYPE_FLOATINGLITERAL; parent = par; isFromSourceFile = true; // default filename = NULL; } -chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, int precis, chillAST_node *par) { +chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, int precis, chillAST_Node *par) { value = val; precision = 1; float0double1 = 0; // which is live! precision = precis; // allthedigits = NULL; - asttype = CHILLAST_NODETYPE_FLOATINGLITERAL; parent = par; isFromSourceFile = true; // default filename = NULL; } -chillAST_FloatingLiteral::chillAST_FloatingLiteral(double val, int precis, chillAST_node *par) { +chillAST_FloatingLiteral::chillAST_FloatingLiteral(double val, int precis, chillAST_Node *par) { doublevalue = val; float0double1 = 1; // which is live! precision = precis; // allthedigits = NULL; - asttype = CHILLAST_NODETYPE_FLOATINGLITERAL; parent = par; isFromSourceFile = true; // default filename = NULL; } -chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, const char *printthis, chillAST_node *par) { +chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, const char *printthis, chillAST_Node *par) { value = val; float0double1 = 0; // which is live! precision = 1; allthedigits = NULL; if (printthis) allthedigits = strdup(printthis); //fprintf(stderr, "\nfloatingliteral allthedigits = '%s'\n", allthedigits); - asttype = CHILLAST_NODETYPE_FLOATINGLITERAL; parent = par; isFromSourceFile = true; // default filename = NULL; } -chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, int precis, const char *printthis, chillAST_node *par) { +chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, int precis, const char *printthis, chillAST_Node *par) { value = val; float0double1 = 0; // which is live! precision = precis; // but value is a float?? TODO @@ -3977,7 +3907,6 @@ chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, int precis, const allthedigits = strdup(printthis); } //fprintf(stderr, "\nfloatingliteral allthedigits = '%s'\n", allthedigits); - asttype = CHILLAST_NODETYPE_FLOATINGLITERAL; parent = par; isFromSourceFile = true; // default filename = NULL; @@ -3987,7 +3916,6 @@ chillAST_FloatingLiteral::chillAST_FloatingLiteral(float val, int precis, const chillAST_FloatingLiteral::chillAST_FloatingLiteral(chillAST_FloatingLiteral *old) { //fprintf(stderr, "chillAST_FloatingLiteral::chillAST_FloatingLiteral( old ) allthedigits %p\n", old->allthedigits); - asttype = CHILLAST_NODETYPE_FLOATINGLITERAL; value = old->value; doublevalue = old->doublevalue; float0double1 = old->float0double1; @@ -4050,9 +3978,9 @@ void chillAST_FloatingLiteral::dump(int indent, FILE *fp) { } -chillAST_node *chillAST_FloatingLiteral::constantFold() { return this; }; // NOOP +chillAST_Node *chillAST_FloatingLiteral::constantFold() { return this; }; // NOOP -chillAST_node *chillAST_FloatingLiteral::clone() { +chillAST_Node *chillAST_FloatingLiteral::clone() { //fprintf(stderr, "chillAST_FloatingLiteral::clone() "); //fprintf(stderr, "allthedigits %p \n", allthedigits); chillAST_FloatingLiteral *newone = new chillAST_FloatingLiteral(this); @@ -4063,7 +3991,7 @@ chillAST_node *chillAST_FloatingLiteral::clone() { return newone; } -bool chillAST_FloatingLiteral::isSameAs(chillAST_node *other) { +bool chillAST_FloatingLiteral::isSameAs(chillAST_Node *other) { if (!other->isFloatingLiteral()) return false; chillAST_FloatingLiteral *o = (chillAST_FloatingLiteral *) other; // should we care about single vs double precision? @@ -4075,12 +4003,11 @@ bool chillAST_FloatingLiteral::isSameAs(chillAST_node *other) { } -chillAST_UnaryOperator::chillAST_UnaryOperator(const char *oper, bool pre, chillAST_node *sub, chillAST_node *par) { +chillAST_UnaryOperator::chillAST_UnaryOperator(const char *oper, bool pre, chillAST_Node *sub, chillAST_Node *par) { op = strdup(oper); prefix = pre; subexpr = sub; subexpr->setParent(this); - asttype = CHILLAST_NODETYPE_UNARYOPERATOR; parent = par; isFromSourceFile = true; // default filename = NULL; @@ -4125,12 +4052,12 @@ void chillAST_UnaryOperator::gatherVarLHSUsage(vector<chillAST_VarDecl *> &decls } -chillAST_node *chillAST_UnaryOperator::constantFold() { +chillAST_Node *chillAST_UnaryOperator::constantFold() { //fprintf(stderr, "chillAST_UnaryOperator::constantFold() "); //print(); fprintf(stderr, "\n"); subexpr = subexpr->constantFold(); - chillAST_node *returnval = this; + chillAST_Node *returnval = this; if (subexpr->isConstant()) { //fprintf(stderr, "unary op folding constants\n"); //print(0,stderr); fprintf(stderr, "\n"); @@ -4160,7 +4087,7 @@ chillAST_node *chillAST_UnaryOperator::constantFold() { } -class chillAST_node *chillAST_UnaryOperator::clone() { +class chillAST_Node *chillAST_UnaryOperator::clone() { chillAST_UnaryOperator *UO = new chillAST_UnaryOperator(op, prefix, subexpr->clone(), parent); UO->isFromSourceFile = isFromSourceFile; if (filename) UO->filename = strdup(filename); @@ -4208,7 +4135,7 @@ int chillAST_UnaryOperator::evalAsInt() { } -bool chillAST_UnaryOperator::isSameAs(chillAST_node *other) { +bool chillAST_UnaryOperator::isSameAs(chillAST_Node *other) { if (!other->isUnaryOperator()) return false; chillAST_UnaryOperator *o = (chillAST_UnaryOperator *) other; if (strcmp(op, o->op)) return false; // different operators @@ -4216,10 +4143,9 @@ bool chillAST_UnaryOperator::isSameAs(chillAST_node *other) { } -chillAST_ImplicitCastExpr::chillAST_ImplicitCastExpr(chillAST_node *sub, chillAST_node *par) { +chillAST_ImplicitCastExpr::chillAST_ImplicitCastExpr(chillAST_Node *sub, chillAST_Node *par) { subexpr = sub; subexpr->setParent(this); - asttype = CHILLAST_NODETYPE_IMPLICITCASTEXPR; parent = par; //fprintf(stderr, "ImplicitCastExpr 0x%x has subexpr 0x%x", this, subexpr); //fprintf(stderr, " of type %s\n", subexpr->getTypeString()); @@ -4239,7 +4165,7 @@ void chillAST_ImplicitCastExpr::printonly(int indent, FILE *fp) { fflush(fp); }; -void chillAST_ImplicitCastExpr::replaceChild(chillAST_node *old, chillAST_node *newchild) { +void chillAST_ImplicitCastExpr::replaceChild(chillAST_Node *old, chillAST_Node *newchild) { if (subexpr == old) { // should be the case for this to get called subexpr = newchild; subexpr->setParent(this); @@ -4251,14 +4177,14 @@ void chillAST_ImplicitCastExpr::replaceChild(chillAST_node *old, chillAST_node * exit(-1); // ?? } -class chillAST_node *chillAST_ImplicitCastExpr::constantFold() { - chillAST_node *child = subexpr->constantFold(); +class chillAST_Node *chillAST_ImplicitCastExpr::constantFold() { + chillAST_Node *child = subexpr->constantFold(); child->setParent(parent); // remove myself !! probably a bad idea. TODO return child; } -class chillAST_node *chillAST_ImplicitCastExpr::clone() { +class chillAST_Node *chillAST_ImplicitCastExpr::clone() { chillAST_ImplicitCastExpr *ICE = new chillAST_ImplicitCastExpr(subexpr->clone(), parent); ICE->isFromSourceFile = isFromSourceFile; if (filename) ICE->filename = strdup(filename); @@ -4299,20 +4225,19 @@ void chillAST_ImplicitCastExpr::gatherVarUsage(vector<chillAST_VarDecl *> &decls } -chillAST_CStyleCastExpr::chillAST_CStyleCastExpr(const char *to, chillAST_node *sub, chillAST_node *par) { +chillAST_CStyleCastExpr::chillAST_CStyleCastExpr(const char *to, chillAST_Node *sub, chillAST_Node *par) { //fprintf(stderr, "chillAST_CStyleCastExpr::chillAST_CStyleCastExpr( %s, ...)\n", to); towhat = strdup(to); subexpr = sub; if (subexpr) subexpr->setParent(this); - asttype = CHILLAST_NODETYPE_CSTYLECASTEXPR; parent = par; //fprintf(stderr, "chillAST_CStyleCastExpr (%s) sub 0x%x\n", towhat, sub ); isFromSourceFile = true; // default filename = NULL; } -void chillAST_CStyleCastExpr::replaceChild(chillAST_node *old, chillAST_node *newchild) { +void chillAST_CStyleCastExpr::replaceChild(chillAST_Node *old, chillAST_Node *newchild) { if (subexpr == old) { // should be the case for this to get called subexpr = newchild; subexpr->setParent(this); @@ -4364,13 +4289,13 @@ void chillAST_CStyleCastExpr::dump(int indent, FILE *fp) { fflush(fp); } -class chillAST_node *chillAST_CStyleCastExpr::constantFold() { +class chillAST_Node *chillAST_CStyleCastExpr::constantFold() { subexpr = subexpr->constantFold(); return this; } -class chillAST_node *chillAST_CStyleCastExpr::clone() { +class chillAST_Node *chillAST_CStyleCastExpr::clone() { chillAST_CStyleCastExpr *CSCE = new chillAST_CStyleCastExpr(towhat, subexpr->clone(), parent); CSCE->isFromSourceFile = isFromSourceFile; if (filename) CSCE->filename = strdup(filename); @@ -4411,10 +4336,9 @@ void chillAST_CStyleCastExpr::gatherVarUsage(vector<chillAST_VarDecl *> &decls) } -chillAST_CStyleAddressOf::chillAST_CStyleAddressOf(chillAST_node *sub, chillAST_node *par) { +chillAST_CStyleAddressOf::chillAST_CStyleAddressOf(chillAST_Node *sub, chillAST_Node *par) { subexpr = sub; subexpr->setParent(this); - asttype = CHILLAST_NODETYPE_CSTYLEADDRESSOF; parent = par; //fprintf(stderr, "chillAST_CStyleCastExpr (%s) sub 0x%x\n", towhat, sub ); isFromSourceFile = true; // default @@ -4439,12 +4363,12 @@ void chillAST_CStyleAddressOf::dump(int indent, FILE *fp) { fflush(fp); } -class chillAST_node *chillAST_CStyleAddressOf::constantFold() { +class chillAST_Node *chillAST_CStyleAddressOf::constantFold() { subexpr = subexpr->constantFold(); return this; } -class chillAST_node *chillAST_CStyleAddressOf::clone() { +class chillAST_Node *chillAST_CStyleAddressOf::clone() { chillAST_CStyleAddressOf *CSAO = new chillAST_CStyleAddressOf(subexpr->clone(), parent); CSAO->isFromSourceFile = isFromSourceFile; if (filename) CSAO->filename = strdup(filename); @@ -4483,29 +4407,27 @@ void chillAST_CStyleAddressOf::gatherVarUsage(vector<chillAST_VarDecl *> &decls) } -chillAST_Malloc::chillAST_Malloc(chillAST_node *size, chillAST_node *p) { +chillAST_Malloc::chillAST_Malloc(chillAST_Node *size, chillAST_Node *p) { thing = NULL; sizeexpr = size; // probably a multiply like sizeof(int) * 1024 - asttype = CHILLAST_NODETYPE_MALLOC; parent = p; isFromSourceFile = true; // default filename = NULL; }; -chillAST_Malloc::chillAST_Malloc(char *thething, chillAST_node *numthings, chillAST_node *p) { +chillAST_Malloc::chillAST_Malloc(char *thething, chillAST_Node *numthings, chillAST_Node *p) { thing = strdup(thething); // "int" or "float" or "struct widget" sizeexpr = numthings; - asttype = CHILLAST_NODETYPE_MALLOC; parent = p; isFromSourceFile = true; // default filename = NULL; }; -chillAST_node *chillAST_Malloc::constantFold() { +chillAST_Node *chillAST_Malloc::constantFold() { sizeexpr->constantFold(); } -chillAST_node *chillAST_Malloc::clone() { +chillAST_Node *chillAST_Malloc::clone() { chillAST_Malloc *M = new chillAST_Malloc(thing, sizeexpr, parent); // the general version M->isFromSourceFile = isFromSourceFile; if (filename) M->filename = strdup(filename); @@ -4561,10 +4483,9 @@ void chillAST_Malloc::dump(int indent, FILE *fp) { }; -chillAST_CudaMalloc::chillAST_CudaMalloc(chillAST_node *devmemptr, chillAST_node *size, chillAST_node *p) { +chillAST_CudaMalloc::chillAST_CudaMalloc(chillAST_Node *devmemptr, chillAST_Node *size, chillAST_Node *p) { devPtr = devmemptr; sizeinbytes = size; // probably a multiply like sizeof(int) * 1024 - asttype = CHILLAST_NODETYPE_CUDAMALLOC; parent = p; isFromSourceFile = true; // default filename = NULL; @@ -4590,12 +4511,12 @@ void chillAST_CudaMalloc::dump(int indent, FILE *fp) { fflush(fp); }; -class chillAST_node *chillAST_CudaMalloc::constantFold() { +class chillAST_Node *chillAST_CudaMalloc::constantFold() { devPtr = devPtr->constantFold(); return this; } -class chillAST_node *chillAST_CudaMalloc::clone() { +class chillAST_Node *chillAST_CudaMalloc::clone() { chillAST_CudaMalloc *CM = new chillAST_CudaMalloc(devPtr->clone(), sizeinbytes->clone(), parent); CM->isFromSourceFile = isFromSourceFile; if (filename) CM->filename = strdup(filename); @@ -4636,10 +4557,9 @@ void chillAST_CudaMalloc::gatherVarUsage(vector<chillAST_VarDecl *> &decls) { } -chillAST_CudaFree::chillAST_CudaFree(chillAST_VarDecl *var, chillAST_node *p) { +chillAST_CudaFree::chillAST_CudaFree(chillAST_VarDecl *var, chillAST_Node *p) { variable = var; parent = p; - asttype = CHILLAST_NODETYPE_CUDAFREE; isFromSourceFile = true; // default filename = NULL; }; @@ -4656,11 +4576,11 @@ void chillAST_CudaFree::dump(int indent, FILE *fp) { fflush(fp); }; -class chillAST_node *chillAST_CudaFree::constantFold() { +class chillAST_Node *chillAST_CudaFree::constantFold() { return this; } -class chillAST_node *chillAST_CudaFree::clone() { +class chillAST_Node *chillAST_CudaFree::clone() { chillAST_CudaFree *CF = new chillAST_CudaFree(variable, parent); CF->isFromSourceFile = isFromSourceFile; if (filename) CF->filename = strdup(filename); @@ -4691,14 +4611,13 @@ void chillAST_CudaFree::gatherVarUsage(vector<chillAST_VarDecl *> &decls) { } -chillAST_CudaMemcpy::chillAST_CudaMemcpy(chillAST_VarDecl *d, chillAST_VarDecl *s, chillAST_node *siz, char *kind, - chillAST_node *par) { +chillAST_CudaMemcpy::chillAST_CudaMemcpy(chillAST_VarDecl *d, chillAST_VarDecl *s, chillAST_Node *siz, char *kind, + chillAST_Node *par) { dest = d; src = s; //fprintf(stderr, "chillAST_CudaMemcpy::chillAST_CudaMemcpy( dest %s, src %s, ...)\n", d->varname, s->varname ); size = siz; cudaMemcpyKind = kind; - asttype = CHILLAST_NODETYPE_CUDAMEMCPY; isFromSourceFile = true; // default filename = NULL; parent = par; @@ -4727,14 +4646,14 @@ void chillAST_CudaMemcpy::dump(int indent, FILE *fp) { fflush(fp); }; -class chillAST_node *chillAST_CudaMemcpy::constantFold() { +class chillAST_Node *chillAST_CudaMemcpy::constantFold() { dest = (chillAST_VarDecl *) dest->constantFold(); src = (chillAST_VarDecl *) src->constantFold(); size = size->constantFold(); return this; } -class chillAST_node *chillAST_CudaMemcpy::clone() { +class chillAST_Node *chillAST_CudaMemcpy::clone() { chillAST_CudaMemcpy *CMCPY = new chillAST_CudaMemcpy((chillAST_VarDecl *) (dest->clone()), (chillAST_VarDecl *) (src->clone()), size->clone(), strdup(cudaMemcpyKind), parent); @@ -4783,8 +4702,7 @@ void chillAST_CudaMemcpy::gatherVarUsage(vector<chillAST_VarDecl *> &decls) { } -chillAST_CudaSyncthreads::chillAST_CudaSyncthreads(chillAST_node *par) { - asttype = CHILLAST_NODETYPE_CUDASYNCTHREADS; +chillAST_CudaSyncthreads::chillAST_CudaSyncthreads(chillAST_Node *par) { parent = par; isFromSourceFile = true; // default filename = NULL; @@ -4803,8 +4721,7 @@ void chillAST_CudaSyncthreads::dump(int indent, FILE *fp) { } -chillAST_ReturnStmt::chillAST_ReturnStmt(chillAST_node *retval, chillAST_node *par) { - asttype = CHILLAST_NODETYPE_RETURNSTMT; +chillAST_ReturnStmt::chillAST_ReturnStmt(chillAST_Node *retval, chillAST_Node *par) { returnvalue = retval; if (returnvalue) returnvalue->setParent(this); parent = par; @@ -4839,14 +4756,14 @@ void chillAST_ReturnStmt::dump(int indent, FILE *fp) { } -class chillAST_node *chillAST_ReturnStmt::constantFold() { +class chillAST_Node *chillAST_ReturnStmt::constantFold() { if (returnvalue) returnvalue = returnvalue->constantFold(); return this; } -class chillAST_node *chillAST_ReturnStmt::clone() { - chillAST_node *val = NULL; +class chillAST_Node *chillAST_ReturnStmt::clone() { + chillAST_Node *val = NULL; if (returnvalue) val = returnvalue->clone(); chillAST_ReturnStmt *RS = new chillAST_ReturnStmt(val, parent); RS->isFromSourceFile = isFromSourceFile; @@ -4880,11 +4797,10 @@ void chillAST_ReturnStmt::gatherVarUsage(vector<chillAST_VarDecl *> &decls) { } -chillAST_CallExpr::chillAST_CallExpr(chillAST_node *c, - chillAST_node *par) { //, int numofargs, chillAST_node **theargs ) { +chillAST_CallExpr::chillAST_CallExpr(chillAST_Node *c, + chillAST_Node *par) { //, int numofargs, chillAST_Node **theargs ) { //fprintf(stderr, "chillAST_CallExpr::chillAST_CallExpr callee type %s\n", c->getTypeString()); - asttype = CHILLAST_NODETYPE_CALLEXPR; callee = c; //callee->setParent( this ); // ?? numargs = 0; @@ -4895,7 +4811,7 @@ chillAST_CallExpr::chillAST_CallExpr(chillAST_node *c, } -void chillAST_CallExpr::addArg(chillAST_node *a) { +void chillAST_CallExpr::addArg(chillAST_Node *a) { args.push_back(a); a->setParent(this); numargs += 1; @@ -5025,7 +4941,7 @@ void chillAST_CallExpr::gatherVarUsage(vector<chillAST_VarDecl *> &decls) { } -chillAST_node *chillAST_CallExpr::constantFold() { +chillAST_Node *chillAST_CallExpr::constantFold() { numargs = args.size(); // wrong place for this for (int i = 0; i < numargs; i++) { args[i] = args[i]->constantFold(); @@ -5033,7 +4949,7 @@ chillAST_node *chillAST_CallExpr::constantFold() { return this; } -chillAST_node *chillAST_CallExpr::clone() { +chillAST_Node *chillAST_CallExpr::clone() { //fprintf(stderr, "chillAST_CallExpr::clone()\n"); //print(0, stderr); fprintf(stderr, "\n"); @@ -5055,7 +4971,6 @@ chillAST_VarDecl::chillAST_VarDecl() { init = NULL; numdimensions = 0; arraysizes = NULL; - asttype = CHILLAST_NODETYPE_VARDECL; // parent = NULL; metacomment = NULL; @@ -5073,7 +4988,7 @@ chillAST_VarDecl::chillAST_VarDecl() { }; -chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, chillAST_node *par) { +chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, chillAST_Node *par) { //fprintf(stderr, "1chillAST_VarDecl::chillAST_VarDecl( type %s, name %s, arraypart %s, parent %p) %p\n", t, n, a, par, this); fprintf(stderr, "1chillAST_VarDecl::chillAST_VarDecl( type %s, name %s, arraypart %s)\n", t, n, a); vartype = strdup(t); @@ -5091,7 +5006,6 @@ chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, numdimensions = 0; arraysizes = NULL; uniquePtr = NULL; - asttype = CHILLAST_NODETYPE_VARDECL; parent = par; @@ -5125,7 +5039,7 @@ chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, chillAST_VarDecl::chillAST_VarDecl(chillAST_RecordDecl *astruct, const char *nam, const char *array, - chillAST_node *par) { + chillAST_Node *par) { // define a variable whose type is a struct! fprintf(stderr, "3chillAST_VarDecl::chillAST_VarDecl( %s %p struct ", nam, this); @@ -5152,7 +5066,6 @@ chillAST_VarDecl::chillAST_VarDecl(chillAST_RecordDecl *astruct, const char *nam numdimensions = 0; arraysizes = NULL; uniquePtr = NULL; - asttype = CHILLAST_NODETYPE_VARDECL; parent = par; knownArraySizes = false; @@ -5183,7 +5096,7 @@ chillAST_VarDecl::chillAST_VarDecl(chillAST_RecordDecl *astruct, const char *nam }; -chillAST_VarDecl::chillAST_VarDecl(chillAST_TypedefDecl *tdd, const char *n, const char *a, chillAST_node *par) { +chillAST_VarDecl::chillAST_VarDecl(chillAST_TypedefDecl *tdd, const char *n, const char *a, chillAST_Node *par) { fprintf(stderr, "4chillAST_VarDecl::chillAST_VarDecl( %s typedef ", n); const char *type = tdd->getStructName(); //fprintf (stderr, "%s, name %s, arraypart %s parent ) %p\n", type, n, a,this); // , par); @@ -5200,7 +5113,6 @@ chillAST_VarDecl::chillAST_VarDecl(chillAST_TypedefDecl *tdd, const char *n, con numdimensions = 0; arraysizes = NULL; uniquePtr = NULL; - asttype = CHILLAST_NODETYPE_VARDECL; parent = par; knownArraySizes = false; @@ -5230,7 +5142,7 @@ chillAST_VarDecl::chillAST_VarDecl(chillAST_TypedefDecl *tdd, const char *n, con }; -chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, void *ptr, chillAST_node *par) { +chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, void *ptr, chillAST_Node *par) { CHILL_DEBUG_PRINT("chillAST_VarDecl::chillAST_VarDecl( type %s, name %s, arraypart '%s' ) %p\n", t, n, a, this); @@ -5253,7 +5165,6 @@ chillAST_VarDecl::chillAST_VarDecl(const char *t, const char *n, const char *a, numdimensions = 0; arraysizes = NULL; uniquePtr = ptr; - asttype = CHILLAST_NODETYPE_VARDECL; parent = par; knownArraySizes = false; @@ -5544,7 +5455,6 @@ chillAST_RecordDecl *chillAST_VarDecl::getStructDef() { chillAST_CompoundStmt::chillAST_CompoundStmt() { //fprintf(stderr, "chillAST_CompoundStmt::chillAST_CompoundStmt() %p\n", this); - asttype = CHILLAST_NODETYPE_COMPOUNDSTMT; parent = NULL; symbol_table = new chillAST_SymbolTable; typedef_table = NULL; @@ -5559,10 +5469,10 @@ void chillAST_CompoundStmt::print(int indent, FILE *fp) { //fprintf(stderr, "NUMCHILDREN %d\n", numchildren); sleep(1); for (int i = 0; i < numchildren; i++) { children[i]->print(indent, fp); - if (children[i]->asttype != CHILLAST_NODETYPE_FORSTMT - && children[i]->asttype != CHILLAST_NODETYPE_IFSTMT - && children[i]->asttype != CHILLAST_NODETYPE_COMPOUNDSTMT - //&& children[i]->asttype != CHILLAST_NODETYPE_VARDECL // vardecl does its own ";\n" + if (children[i]->getType() != CHILLAST_NODE_FORSTMT + && children[i]->getType() != CHILLAST_NODE_IFSTMT + && children[i]->getType() != CHILLAST_NODE_COMPOUNDSTMT + //&& children[i]->getType() != CHILLAST_NODE_VARDECL // vardecl does its own ";\n" ) { fprintf(fp, ";\n"); // probably wrong } @@ -5570,9 +5480,9 @@ void chillAST_CompoundStmt::print(int indent, FILE *fp) { fflush(fp); } -void chillAST_CompoundStmt::replaceChild(chillAST_node *old, chillAST_node *newchild) { +void chillAST_CompoundStmt::replaceChild(chillAST_Node *old, chillAST_Node *newchild) { //fprintf(stderr, "chillAST_CompoundStmt::replaceChild( old %s, new %s)\n", old->getTypeString(), newchild->getTypeString() ); - vector<chillAST_node *> dupe = children; + vector<chillAST_Node *> dupe = children; int numdupe = dupe.size(); int any = 0; @@ -5619,7 +5529,7 @@ void chillAST_CompoundStmt::loseLoopWithLoopVar(char *var) { for (int j=0; j<children.size(); j++) { fprintf(stderr, "j %d/%d ", j, children.size()); fprintf(stderr, "subnode %d 0x%x ", j, children[j] ); - fprintf(stderr, "asttype %d ", children[j]->asttype); + fprintf(stderr, "asttype %d ", children[j]->getType()); fprintf(stderr, "%s ", children[j]->getTypeString()); if (children[j]->isForStmt()) { chillAST_ForStmt *FS = ((chillAST_ForStmt *) children[j]); @@ -5636,7 +5546,7 @@ void chillAST_CompoundStmt::loseLoopWithLoopVar(char *var) { #endif - vector<chillAST_node *> dupe = children; // simple enough? + vector<chillAST_Node *> dupe = children; // simple enough? for (int i = 0; i < dupe.size(); i++) { //for (int j=0; j<dupe.size(); j++) { // fprintf(stderr, "j %d/%d\n", j, dupe.size()); @@ -5681,14 +5591,14 @@ void chillAST_CompoundStmt::dump(int indent, FILE *fp) { }; -chillAST_node *chillAST_CompoundStmt::constantFold() { +chillAST_Node *chillAST_CompoundStmt::constantFold() { //fprintf(stderr, "chillAST_CompoundStmt::constantFold()\n"); for (int i = 0; i < children.size(); i++) children[i] = children[i]->constantFold(); return this; } -chillAST_node *chillAST_CompoundStmt::clone() { +chillAST_Node *chillAST_CompoundStmt::clone() { chillAST_CompoundStmt *cs = new chillAST_CompoundStmt(); for (int i = 0; i < children.size(); i++) cs->addChild(children[i]->clone()); cs->setParent(parent); @@ -5732,7 +5642,7 @@ void chillAST_CompoundStmt::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> for (int i = 0; i < children.size(); i++) children[i]->gatherScalarRefs(refs, 0); } -void chillAST_CompoundStmt::gatherStatements(std::vector<chillAST_node *> &statements) { +void chillAST_CompoundStmt::gatherStatements(std::vector<chillAST_Node *> &statements) { for (int i = 0; i < children.size(); i++) children[i]->gatherStatements(statements); } @@ -5768,7 +5678,7 @@ bool chillAST_CompoundStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symta return false; /* - vector<chillAST_node*> childrencopy; + vector<chillAST_Node*> childrencopy; for (int i=0; i<children.size(); i++) childrencopy.push_back( children[i] ); bool force = false; @@ -5798,10 +5708,9 @@ bool chillAST_CompoundStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symta } -chillAST_ParenExpr::chillAST_ParenExpr(chillAST_node *sub, chillAST_node *par) { +chillAST_ParenExpr::chillAST_ParenExpr(chillAST_Node *sub, chillAST_Node *par) { subexpr = sub; subexpr->setParent(this); - asttype = CHILLAST_NODETYPE_PARENEXPR; parent = par; isFromSourceFile = true; // default filename = NULL; @@ -5834,13 +5743,13 @@ void chillAST_ParenExpr::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &r } -chillAST_node *chillAST_ParenExpr::constantFold() { +chillAST_Node *chillAST_ParenExpr::constantFold() { subexpr = subexpr->constantFold(); return this; } -chillAST_node *chillAST_ParenExpr::clone() { +chillAST_Node *chillAST_ParenExpr::clone() { chillAST_ParenExpr *PE = new chillAST_ParenExpr(subexpr->clone(), NULL); PE->isFromSourceFile = isFromSourceFile; if (filename) PE->filename = strdup(filename); @@ -5875,7 +5784,7 @@ void chillAST_ParenExpr::gatherVarUsage(vector<chillAST_VarDecl *> &decls) { } -chillAST_Sizeof::chillAST_Sizeof(char *athing, chillAST_node *par) { +chillAST_Sizeof::chillAST_Sizeof(char *athing, chillAST_Node *par) { thing = strdup(athing); // memory leak parent = par; isFromSourceFile = true; // default @@ -5900,11 +5809,11 @@ void chillAST_Sizeof::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> void chillAST_Sizeof::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento) {} -chillAST_node *chillAST_Sizeof::constantFold() { +chillAST_Node *chillAST_Sizeof::constantFold() { return this; } -chillAST_node *chillAST_Sizeof::clone() { +chillAST_Node *chillAST_Sizeof::clone() { chillAST_Sizeof *SO = new chillAST_Sizeof(thing, NULL); SO->isFromSourceFile = isFromSourceFile; if (filename) SO->filename = strdup(filename); @@ -5944,8 +5853,8 @@ void insertNewDeclAtLocationOfOldIfNeeded(chillAST_VarDecl *newdecl, chillAST_Va newdecl->vartype = strdup(olddecl->vartype); - chillAST_node *newparent = newdecl->parent; - chillAST_node *oldparent = olddecl->parent; + chillAST_Node *newparent = newdecl->parent; + chillAST_Node *oldparent = olddecl->parent; //fprintf(stderr, "newparent 0x%x oldparent 0x%x\n", newparent, oldparent ); if (newparent == oldparent) return; @@ -5955,7 +5864,7 @@ void insertNewDeclAtLocationOfOldIfNeeded(chillAST_VarDecl *newdecl, chillAST_Va // find actual location of old decl and insert new one there //fprintf(stderr, "oldparent is of type %s\n", oldparent->getTypeString()); // better be compoundstmt ?? - vector<chillAST_node *> children = oldparent->getChildren(); + vector<chillAST_Node *> children = oldparent->getChildren(); int numchildren = children.size(); //fprintf(stderr, "oldparent has %d children\n", numchildren); @@ -5972,7 +5881,7 @@ void insertNewDeclAtLocationOfOldIfNeeded(chillAST_VarDecl *newdecl, chillAST_Va //fprintf(stderr, "olddecl is 0x%x\n", olddecl); //fprintf(stderr, "I know of %d variables\n", numchildren); for (int i = 0; i < numchildren; i++) { - chillAST_node *child = oldparent->getChild(i); + chillAST_Node *child = oldparent->getChild(i); //fprintf(stderr, "child %d @ 0x%x is of type %s\n", i, child, child->getTypeString()); if (children[i] == olddecl) { index = i; @@ -5994,26 +5903,26 @@ void insertNewDeclAtLocationOfOldIfNeeded(chillAST_VarDecl *newdecl, chillAST_Va } -void gatherVarDecls(vector<chillAST_node *> &code, vector<chillAST_VarDecl *> &decls) { +void gatherVarDecls(vector<chillAST_Node *> &code, vector<chillAST_VarDecl *> &decls) { //fprintf(stderr, "gatherVarDecls()\n"); int numcode = code.size(); //fprintf(stderr, "%d top level statements\n", numcode); for (int i = 0; i < numcode; i++) { - chillAST_node *statement = code[i]; + chillAST_Node *statement = code[i]; statement->gatherVarDecls(decls); } } -void gatherVarUsage(vector<chillAST_node *> &code, vector<chillAST_VarDecl *> &decls) { +void gatherVarUsage(vector<chillAST_Node *> &code, vector<chillAST_VarDecl *> &decls) { //fprintf(stderr, "gatherVarUsage()\n"); int numcode = code.size(); //fprintf(stderr, "%d top level statements\n", numcode); for (int i = 0; i < numcode; i++) { - chillAST_node *statement = code[i]; + chillAST_Node *statement = code[i]; statement->gatherVarUsage(decls); } @@ -6022,12 +5931,11 @@ void gatherVarUsage(vector<chillAST_node *> &code, vector<chillAST_VarDecl *> &d chillAST_IfStmt::chillAST_IfStmt() { cond = thenpart = elsepart = NULL; - asttype = CHILLAST_NODETYPE_IFSTMT; isFromSourceFile = true; // default filename = NULL; } -chillAST_IfStmt::chillAST_IfStmt(chillAST_node *c, chillAST_node *t, chillAST_node *e, chillAST_node *p) { +chillAST_IfStmt::chillAST_IfStmt(chillAST_Node *c, chillAST_Node *t, chillAST_Node *e, chillAST_Node *p) { cond = c; if (cond) cond->setParent(this); thenpart = t; @@ -6035,7 +5943,6 @@ chillAST_IfStmt::chillAST_IfStmt(chillAST_node *c, chillAST_node *t, chillAST_no elsepart = e; if (elsepart) elsepart->setParent(this); parent = p; - asttype = CHILLAST_NODETYPE_IFSTMT; isFromSourceFile = true; // default filename = NULL; } @@ -6088,14 +5995,14 @@ void chillAST_IfStmt::gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs } -chillAST_node *chillAST_IfStmt::constantFold() { +chillAST_Node *chillAST_IfStmt::constantFold() { if (cond) cond = cond->constantFold(); if (thenpart) thenpart = thenpart->constantFold(); if (elsepart) elsepart = elsepart->constantFold(); return this; } -void chillAST_IfStmt::gatherStatements(std::vector<chillAST_node *> &statements) { +void chillAST_IfStmt::gatherStatements(std::vector<chillAST_Node *> &statements) { //print(); printf("\n"); fflush(stdout); thenpart->gatherStatements(statements); @@ -6108,8 +6015,8 @@ void chillAST_IfStmt::gatherStatements(std::vector<chillAST_node *> &statements) } -chillAST_node *chillAST_IfStmt::clone() { - chillAST_node *c, *t, *e; +chillAST_Node *chillAST_IfStmt::clone() { + chillAST_Node *c, *t, *e; c = t = e = NULL; if (cond) c = cond->clone(); // has to be one, right? if (thenpart) t = thenpart->clone(); @@ -6205,7 +6112,7 @@ bool chillAST_IfStmt::findLoopIndexesToReplace(chillAST_SymbolTable *symtab, boo } -chillAST_node *lessthanmacro(chillAST_node *left, chillAST_node *right) { +chillAST_Node *lessthanmacro(chillAST_Node *left, chillAST_Node *right) { chillAST_ParenExpr *lp1 = new chillAST_ParenExpr(left); chillAST_ParenExpr *rp1 = new chillAST_ParenExpr(right); @@ -6221,7 +6128,7 @@ chillAST_node *lessthanmacro(chillAST_node *left, chillAST_node *right) { // look for function declaration with a given name, in the tree with root "node" -void findFunctionDeclRecursive(chillAST_node *node, const char *procname, vector<chillAST_FunctionDecl *> &funcs) { +void findFunctionDeclRecursive(chillAST_Node *node, const char *procname, vector<chillAST_FunctionDecl *> &funcs) { //fprintf(stderr, "findmanually() CHILL AST node of type %s\n", node->getTypeString()); if (node->isFunctionDecl()) { @@ -6263,7 +6170,7 @@ void findFunctionDeclRecursive(chillAST_node *node, const char *procname, vector } -chillAST_FunctionDecl *findFunctionDecl(chillAST_node *node, const char *procname) { +chillAST_FunctionDecl *findFunctionDecl(chillAST_Node *node, const char *procname) { vector<chillAST_FunctionDecl *> functions; findFunctionDeclRecursive(node, procname, functions); @@ -6337,7 +6244,7 @@ chillAST_TypedefTable *addTypedefToTable(chillAST_TypedefTable *tdt, chillAST_Ty } -chillAST_NoOp::chillAST_NoOp(chillAST_node *p) { +chillAST_NoOp::chillAST_NoOp(chillAST_Node *p) { parent = p; isFromSourceFile = true; // default filename = NULL; @@ -6345,14 +6252,14 @@ chillAST_NoOp::chillAST_NoOp(chillAST_node *p) { chillAST_Preprocessing::chillAST_Preprocessing() { - position = CHILL_PREPROCESSING_POSITIONUNKNOWN; - pptype = CHILL_PREPROCESSING_TYPEUNKNOWN; + position = CHILLAST_PREPROCESSING_POSITIONUNKNOWN; + pptype = CHILLAST_PREPROCESSING_TYPEUNKNOWN; blurb = strdup(""); // never use null. ignore the leak ?? } -chillAST_Preprocessing::chillAST_Preprocessing(CHILL_PREPROCESSING_POSITION pos, - CHILL_PREPROCESSING_TYPE t, +chillAST_Preprocessing::chillAST_Preprocessing(CHILLAST_PREPROCESSING_POSITION pos, + CHILLAST_PREPROCESSING_TYPE t, char *text) { position = pos; pptype = t; @@ -6360,28 +6267,28 @@ chillAST_Preprocessing::chillAST_Preprocessing(CHILL_PREPROCESSING_POSITION pos, } void chillAST_Preprocessing::print(int indent, FILE *fp) { // probably very wrong - if (position == CHILL_PREPROCESSING_LINEAFTER) { + if (position == CHILLAST_PREPROCESSING_LINEAFTER) { fprintf(fp, "\n"); chillindent(indent, fp); } - if (position == CHILL_PREPROCESSING_LINEBEFORE) { // ??? + if (position == CHILLAST_PREPROCESSING_LINEBEFORE) { // ??? //fprintf(fp, "\n"); chillindent(indent, fp); } fprintf(fp, "%s", blurb); - if (position == CHILL_PREPROCESSING_TOTHERIGHT) { + if (position == CHILLAST_PREPROCESSING_TOTHERIGHT) { fprintf(fp, "\n"); } - if (position == CHILL_PREPROCESSING_LINEBEFORE) { + if (position == CHILLAST_PREPROCESSING_LINEBEFORE) { //fprintf(fp, "\n"); // comment seems to have \n at the end already //chillindent(indent, fp); } - //if (pptype != CHILL_PREPROCESSING_IMMEDIATELYBEFORE && pptype != CHILL_PREPROCESSING_UNKNOWN) fprint(fp, "\n"); + //if (pptype != CHILLAST_PREPROCESSING_IMMEDIATELYBEFORE && pptype != CHILLAST_PREPROCESSING_UNKNOWN) fprint(fp, "\n"); } diff --git a/src/ir_clang.cc b/src/ir_clang.cc index c8a0c12..628e101 100755 --- a/src/ir_clang.cc +++ b/src/ir_clang.cc @@ -1,5 +1,3 @@ - - /***************************************************************************** Copyright (C) 2009-2010 University of Utah All Rights Reserved. @@ -21,8 +19,6 @@ History: #include "loop.hh" #include "chill_error.hh" -#define DUMPFUNC(x, y) std::cerr << "In function " << x << "\n"; y->dump(); - #include "clang/Frontend/FrontendActions.h" #include <clang/CodeGen/CodeGenAction.h> #include <clang/Frontend/CompilerInstance.h> @@ -45,50 +41,58 @@ History: #include "chillAST.h" +#define NL_RET(x) {chillAST_NodeList *ret = new chillAST_NodeList(); \ + ret->push_back(x); \ + return ret;} + // TODO move to ir_clang.hh -// fwd declarations -chillAST_node *ConvertVarDecl(clang::VarDecl *D, chillAST_node *); -chillAST_node *ConvertTypeDefDecl(clang::TypedefDecl *TDD, chillAST_node *); +chillAST_NodeList* ConvertTypeDefDecl(clang::TypedefDecl *TDD); -chillAST_node *ConvertRecordDecl(clang::RecordDecl *D, chillAST_node *); +chillAST_NodeList* ConvertRecordDecl(clang::RecordDecl *D); -chillAST_node *ConvertDeclStmt(clang::DeclStmt *clangDS, chillAST_node *); +chillAST_NodeList* ConvertDeclStmt(clang::DeclStmt *clangDS); -chillAST_node *ConvertCompoundStmt(clang::CompoundStmt *clangCS, chillAST_node *); +chillAST_NodeList* ConvertCompoundStmt(clang::CompoundStmt *clangCS); -chillAST_node *ConvertFunctionDecl(clang::FunctionDecl *D, chillAST_node *); +chillAST_NodeList* ConvertFunctionDecl(clang::FunctionDecl *D); -chillAST_node *ConvertForStmt(clang::ForStmt *clangFS, chillAST_node *); +chillAST_NodeList* ConvertForStmt(clang::ForStmt *clangFS); -chillAST_node *ConvertUnaryOperator(clang::UnaryOperator *clangU, chillAST_node *O); +chillAST_NodeList* ConvertUnaryOperator(clang::UnaryOperator *clangU); -chillAST_node *ConvertBinaryOperator(clang::BinaryOperator *clangBO, chillAST_node *B); +chillAST_NodeList* ConvertBinaryOperator(clang::BinaryOperator *clangBO); -chillAST_node *ConvertArraySubscriptExpr(clang::ArraySubscriptExpr *clangASE, chillAST_node *); +chillAST_NodeList* ConvertArraySubscriptExpr(clang::ArraySubscriptExpr *clangASE); -chillAST_node *ConvertDeclRefExpr(clang::DeclRefExpr *clangDRE, chillAST_node *); +chillAST_NodeList* ConvertDeclRefExpr(clang::DeclRefExpr *clangDRE); -chillAST_node *ConvertIntegerLiteral(clang::IntegerLiteral *clangIL, chillAST_node *); +chillAST_NodeList* ConvertIntegerLiteral(clang::IntegerLiteral *clangIL); -chillAST_node *ConvertFloatingLiteral(clang::FloatingLiteral *clangFL, chillAST_node *); +chillAST_NodeList* ConvertFloatingLiteral(clang::FloatingLiteral *clangFL); -chillAST_node *ConvertImplicitCastExpr(clang::ImplicitCastExpr *clangICE, chillAST_node *); +chillAST_NodeList* ConvertImplicitCastExpr(clang::ImplicitCastExpr *clangICE); -chillAST_node *ConvertCStyleCastExpr(clang::CStyleCastExpr *clangICE, chillAST_node *); +chillAST_NodeList* ConvertCStyleCastExpr(clang::CStyleCastExpr *clangICE); -chillAST_node *ConvertReturnStmt(clang::ReturnStmt *clangRS, chillAST_node *); +chillAST_NodeList* ConvertReturnStmt(clang::ReturnStmt *clangRS); -chillAST_node *ConvertCallExpr(clang::CallExpr *clangCE, chillAST_node *); +chillAST_NodeList* ConvertCallExpr(clang::CallExpr *clangCE); -chillAST_node *ConvertIfStmt(clang::IfStmt *clangIS, chillAST_node *); +chillAST_NodeList* ConvertIfStmt(clang::IfStmt *clangIS); -chillAST_node *ConvertMemberExpr(clang::MemberExpr *clangME, chillAST_node *); +chillAST_NodeList* ConvertMemberExpr(clang::MemberExpr *clangME); -chillAST_node *ConvertTranslationUnit(clang::TranslationUnitDecl *TUD, char *filename); +chillAST_NodeList* ConvertTranslationUnit(clang::TranslationUnitDecl *TUD, char *filename); -chillAST_node *ConvertGenericClangAST(clang::Stmt *s, chillAST_node *); +/*! + * \brief Convert fon Clang AST to CHiLL AST also append to parent node p if necessary + * + * @param s Clang statement + * @return A set of new statements + */ +chillAST_NodeList* ConvertGenericClangAST(clang::Stmt *s); std::vector<chillAST_VarDecl *> VariableDeclarations; @@ -170,6 +174,11 @@ void PrintTypeDefDecl(TypedefDecl *D, SourceManager *SRCMAN, int level); void PrintVarDecl(VarDecl *D, SourceManager *SRCMAN, int level); +chillAST_Node* unwrap(chillAST_NodeList* nl){ + chillAST_Node* n = (*nl)[0]; + delete nl; + return n; +} void printlines(SourceLocation &S, SourceLocation &E, SourceManager *SRCMAN) { unsigned int startlineno = SRCMAN->getPresumedLineNumber(S); @@ -382,28 +391,27 @@ void PrintCompoundStmt(Stmt *s, SourceManager *SRCMAN, int level) { //fprintf(stderr, "CompoundStmt has %d children\n", numchildren); -#ifdef DEBUGGING - BUH - for (Stmt::child_range I = cs->children(); I; ++I) { - const char *classname = I->getStmtClassName(); - if (!strcmp(classname, "BinaryOperator")) { - BinaryOperator *b = cast<BinaryOperator>(*I); - BinaryOperator::Opcode op = b->getOpcode(); - if (op == BO_Assign) { - fprintf(stderr, "compound statement has child of type ASSIGNMENT STATEMENT "); - SourceLocation S = I->getLocStart(); - SourceLocation E = I->getLocEnd(); - unsigned int startlineno = SRCMAN->getPresumedLineNumber( S ); - unsigned int endlineno = SRCMAN->getPresumedLineNumber( E ); - fprintf(stderr, "(%d-%d)\n", startlineno, endlineno ); - } - else - fprintf(stderr, "compound statement has child of type %s\n", I->getStmtClassName()); + CHILL_DEBUG_BEGIN + for (Stmt::child_iterator I = cs->child_begin(); I!=cs->child_end(); ++I) { + const char *classname = I->getStmtClassName(); + if (!strcmp(classname, "BinaryOperator")) { + BinaryOperator *b = cast<BinaryOperator>(*I); + BinaryOperator::Opcode op = b->getOpcode(); + if (op == BO_Assign) { + fprintf(stderr, "compound statement has child of type ASSIGNMENT STATEMENT "); + SourceLocation S = I->getLocStart(); + SourceLocation E = I->getLocEnd(); + unsigned int startlineno = SRCMAN->getPresumedLineNumber( S ); + unsigned int endlineno = SRCMAN->getPresumedLineNumber( E ); + fprintf(stderr, "(%d-%d)\n", startlineno, endlineno ); } else fprintf(stderr, "compound statement has child of type %s\n", I->getStmtClassName()); } -#endif // debugging + else + fprintf(stderr, "compound statement has child of type %s\n", I->getStmtClassName()); + } + CHILL_DEBUG_END for (auto I = cs->child_begin(); I != cs->child_end(); ++I) { @@ -615,7 +623,7 @@ void PrintVarDecl(VarDecl *D, SourceManager *SRCMAN, int level) { -chillAST_node *ConvertVarDecl(VarDecl *D, chillAST_node *p) { +chillAST_NodeList* ConvertVarDecl(VarDecl *D) { //fprintf(stderr, "\nConvertVarDecl()\n"); //fprintf(stderr, "Decl has type %s\n", D->getDeclKindName()); //PrintVarDecl( D, globalSRCMAN, 0 ); @@ -639,7 +647,7 @@ chillAST_node *ConvertVarDecl(VarDecl *D, chillAST_node *p) { char *varname = strdup(D->getName().str().c_str()); //fprintf(stderr, "VarDecl (clang 0x%x) for %s %s%s\n", D, vartype, varname, arraypart); - chillAST_VarDecl *chillVD = new chillAST_VarDecl(vartype, varname, arraypart, (void *) D, p /* , initializer */ ); + chillAST_VarDecl *chillVD = new chillAST_VarDecl(vartype, varname, arraypart, (void *) D, NULL); chillVD->isAParameter = isParm; //fprintf(stderr, "\nthis is the vardecl\n"); @@ -730,11 +738,12 @@ chillAST_node *ConvertVarDecl(VarDecl *D, chillAST_node *p) { // store this away for declrefexpr that references it! VariableDeclarations.push_back(chillVD); - return chillVD; + + NL_RET(chillVD); } -chillAST_node *ConvertRecordDecl(clang::RecordDecl *RD, chillAST_node *p) { // for structs and unions +chillAST_NodeList* ConvertRecordDecl(clang::RecordDecl *RD) { // for structs and unions //fprintf(stderr, "ConvertRecordDecl( )\n\nclang sees\n"); //RD->dump(); @@ -753,7 +762,7 @@ chillAST_node *ConvertRecordDecl(clang::RecordDecl *RD, chillAST_node *p) { // f sprintf(blurb, "struct %s", RD->getNameAsString().c_str()); fprintf(stderr, "blurb is '%s'\n", blurb); - chillAST_TypedefDecl *astruct = new chillAST_TypedefDecl(blurb, "", p); + chillAST_TypedefDecl *astruct = new chillAST_TypedefDecl(blurb, "", NULL); astruct->setStruct(true); astruct->setStructName(RD->getNameAsString().c_str()); @@ -779,11 +788,11 @@ chillAST_node *ConvertRecordDecl(clang::RecordDecl *RD, chillAST_node *p) { // f fprintf(stderr, "I just defined a struct\n"); astruct->print(0, stderr); - return astruct; + NL_RET(astruct); } -chillAST_node *ConvertTypeDefDecl(TypedefDecl *TDD, chillAST_node *p) { +chillAST_NodeList* ConvertTypeDefDecl(TypedefDecl *TDD) { //fprintf(stderr, "ConvertTypedefDecl( ) \n"); //fprintf(stderr, "TDD has type %s\n", TDD->getDeclKindName()); //TDD->dump(); fprintf(stderr, "\n"); @@ -796,23 +805,24 @@ chillAST_node *ConvertTypeDefDecl(TypedefDecl *TDD, chillAST_node *p) { char *alias = strdup(TDD->getName().str().c_str()); //fprintf(stderr, "underlying type %s arraypart '%s' name %s\n", under, arraypart, TDD->getName().str().c_str() ); - chillAST_TypedefDecl *CTDD = new chillAST_TypedefDecl(under, alias, arraypart, p); + chillAST_TypedefDecl *CTDD = new chillAST_TypedefDecl(under, alias, arraypart, NULL); free(under); free(arraypart); - return CTDD; + NL_RET(CTDD); } -chillAST_node *ConvertDeclStmt(DeclStmt *clangDS, chillAST_node *p) { +chillAST_NodeList* ConvertDeclStmt(DeclStmt *clangDS) { //fprintf(stderr, "ConvertDeclStmt()\n"); chillAST_VarDecl *chillvardecl; // the thing we'll return if this is a single declaration bool multiples = !clangDS->isSingleDecl(); if (multiples) { - //fprintf(stderr, "ir_clang.cc multiple declarations in a single CLANG DeclStmt not really handled! (??)\n"); + // TODO unhandled case + CHILL_ERROR("multiple declarations in a single CLANG DeclStmt not really handled! (??)\n"); // for now, try to make the multiple decls into a compoundstmt with them inside. // if we don't get scoping problems, this might work } @@ -840,15 +850,13 @@ chillAST_node *ConvertDeclStmt(DeclStmt *clangDS, chillAST_node *p) { //fprintf(stderr, "%s %s\n", td, varname); char *arraypart = splitTypeInfo(vartype); - chillvardecl = new chillAST_VarDecl(vartype, varname, arraypart, (void *) D, p); + chillvardecl = new chillAST_VarDecl(vartype, varname, arraypart, (void *) D, NULL); //fprintf(stderr, "DeclStmt (clang 0x%x) for %s %s%s\n", D, vartype, varname, arraypart); // store this away for declrefexpr that references it! VariableDeclarations.push_back(chillvardecl); - if (multiples) p->addChild(chillvardecl); - - // TODO + // TODO if (V->hasInit()) { CHILL_ERROR(" ConvertDeclStmt() UNHANDLED initialization\n"); exit(-1); @@ -856,35 +864,34 @@ chillAST_node *ConvertDeclStmt(DeclStmt *clangDS, chillAST_node *p) { } } // for each of possibly multiple decls - if (multiples) return NULL; // multiple decls added themselves already - return chillvardecl; // OR a single decl + NL_RET(chillvardecl); // OR a single decl } -chillAST_node *ConvertCompoundStmt(CompoundStmt *clangCS, chillAST_node *p) { +chillAST_NodeList* ConvertCompoundStmt(CompoundStmt *clangCS) { //fprintf(stderr, "ConvertCompoundStmt( )\n"); int numchildren = clangCS->size(); //fprintf(stderr, "clang CompoundStmt has %d children\n", numchildren); // make an empty CHILL compound statement chillAST_CompoundStmt *chillCS = new chillAST_CompoundStmt; - chillCS->setParent(p); // for each clang child for (auto I = clangCS->child_begin(); I != clangCS->child_end(); ++I) { // ?? loop looks WRONG // create the chill ast for each child Stmt *child = *I; - chillAST_node *n = ConvertGenericClangAST(child, chillCS); + chillAST_NodeList* nl = ConvertGenericClangAST(child); // usually n will be a statement. We just add it as a child. // SOME DeclStmts have multiple declarations. They will add themselves and return NULL - if (n) chillCS->addChild(n); + chillCS->addChildren(*nl); + delete nl; } - return chillCS; + NL_RET(chillCS); } -chillAST_node *ConvertFunctionDecl(FunctionDecl *D, chillAST_node *p) { +chillAST_NodeList* ConvertFunctionDecl(FunctionDecl *D) { //fprintf(stderr, "\nConvertFunctionDecl( )\n"); QualType QT = D->getReturnType(); string ReturnTypeStr = QT.getAsString(); @@ -895,7 +902,7 @@ chillAST_node *ConvertFunctionDecl(FunctionDecl *D, chillAST_node *p) { //fprintf(stderr, "function %s has type %s ", FuncName.c_str(), ReturnTypeStr.c_str()); //fprintf(stderr, "\n%s %s()\n", ReturnTypeStr.c_str(), FuncName.c_str()); - chillAST_FunctionDecl *chillFD = new chillAST_FunctionDecl(ReturnTypeStr.c_str(), FuncName.c_str(), p, D); + chillAST_FunctionDecl *chillFD = new chillAST_FunctionDecl(ReturnTypeStr.c_str(), FuncName.c_str(), NULL, D); int numparams = D->getNumParams(); @@ -907,14 +914,15 @@ chillAST_node *ConvertFunctionDecl(FunctionDecl *D, chillAST_node *p) { QualType T = pvd->getOriginalType(); CHILL_DEBUG_PRINT("OTYPE %s\n", T.getAsString().c_str()); - chillAST_VarDecl *chillPVD = (chillAST_VarDecl *) ConvertVarDecl(clangvardecl, chillFD); + chillAST_NodeList* nl = ConvertVarDecl(clangvardecl); + chillAST_VarDecl* decl = (chillAST_VarDecl*)unwrap(nl); //chillPVD->print(); fflush(stdout); //chillPVD->isAParameter = 1; - VariableDeclarations.push_back(chillPVD); + VariableDeclarations.push_back(decl); - chillFD->addParameter(chillPVD); - CHILL_DEBUG_PRINT("chillAST ParmVarDecl for %s from chill location 0x%x\n", chillPVD->varname, clangvardecl); + chillFD->addParameter(decl); + CHILL_DEBUG_PRINT("chillAST ParmVarDecl for %s from chill location 0x%x\n", decl->varname, clangvardecl); } // for each parameter @@ -929,76 +937,63 @@ chillAST_node *ConvertFunctionDecl(FunctionDecl *D, chillAST_node *p) { Stmt *clangbody = D->getBody(); if (clangbody) { // may just be fwd decl or external, without an actual body //fprintf(stderr, "body of type %s\n", clangbody->getStmtClassName()); - //chillAST_node *CB = ConvertCompoundStmt( dyn_cast<CompoundStmt>(clangbody) ); // always a compound statement? - chillAST_node *CB = ConvertGenericClangAST(clangbody, chillFD); + //chillAST_Node *CB = ConvertCompoundStmt( dyn_cast<CompoundStmt>(clangbody) ); // always a compound statement? + chillAST_NodeList* nl = ConvertGenericClangAST(clangbody); //fprintf(stderr, "FunctionDecl body = 0x%x of type %s\n", CB, CB->getTypeString()); - chillFD->setBody(CB); + chillFD->setBody(unwrap(nl)); } //fprintf(stderr, "adding function %s 0x%x to FunctionDeclarations\n", chillFD->functionName, chillFD); FunctionDeclarations.push_back(chillFD); - return chillFD; + NL_RET(chillFD); } -chillAST_node *ConvertForStmt(ForStmt *clangFS, chillAST_node *p) { - - Stmt *init = clangFS->getInit(); - Expr *cond = clangFS->getCond(); - Expr *incr = clangFS->getInc(); - Stmt *body = clangFS->getBody(); +chillAST_NodeList* ConvertForStmt(ForStmt *clangFS) { - chillAST_node *ini = ConvertGenericClangAST(init, NULL); - chillAST_node *con = ConvertGenericClangAST(cond, NULL); - chillAST_node *inc = ConvertGenericClangAST(incr, NULL); - chillAST_node *bod = ConvertGenericClangAST(body, NULL); - if (bod->asttype != CHILLAST_NODETYPE_COMPOUNDSTMT) { - //fprintf(stderr, "ForStmt body of type %s\n", bod->getTypeString()); + chillAST_Node *init = unwrap(ConvertGenericClangAST(clangFS->getInit())); + chillAST_Node *cond = unwrap(ConvertGenericClangAST(clangFS->getCond())); + chillAST_Node *incr = unwrap(ConvertGenericClangAST(clangFS->getInc())); + chillAST_Node *body = unwrap(ConvertGenericClangAST(clangFS->getBody())); + if (body->getType() != CHILLAST_NODE_COMPOUNDSTMT) { // make single statement loop bodies loop like other loops + CHILL_DEBUG_PRINT("ForStmt body of type %s\n", body->getTypeString()); chillAST_CompoundStmt *cs = new chillAST_CompoundStmt(); - cs->addChild(bod); - bod = cs; + cs->addChild(body); + body = cs; } - - - chillAST_ForStmt *chill_loop = new chillAST_ForStmt(ini, con, inc, bod, p); - ini->setParent(chill_loop); - con->setParent(chill_loop); - inc->setParent(chill_loop); - bod->setParent(chill_loop); - - return chill_loop; + chillAST_ForStmt *chill_loop = new chillAST_ForStmt(init, cond, incr, body, NULL); + NL_RET(chill_loop); } -chillAST_node *ConvertIfStmt(IfStmt *clangIS, chillAST_node *p) { +chillAST_NodeList* ConvertIfStmt(IfStmt *clangIS) { Expr *cond = clangIS->getCond(); Stmt *thenpart = clangIS->getThen(); Stmt *elsepart = clangIS->getElse(); - chillAST_node *con = ConvertGenericClangAST(cond, NULL); - chillAST_node *thn = NULL; - if (thenpart) thn = ConvertGenericClangAST(thenpart, NULL); - chillAST_node *els = NULL; - if (elsepart) els = ConvertGenericClangAST(elsepart, NULL); + chillAST_Node *con = unwrap(ConvertGenericClangAST(cond)); + chillAST_Node *thn = NULL; + if (thenpart) thn = unwrap(ConvertGenericClangAST(thenpart)); + chillAST_Node *els = NULL; + if (elsepart) els = unwrap(ConvertGenericClangAST(elsepart)); chillAST_IfStmt *ifstmt = new chillAST_IfStmt(con, thn, els, NULL); - return ifstmt; + NL_RET(ifstmt); } -chillAST_node *ConvertUnaryOperator(UnaryOperator *clangUO, chillAST_node *p) { +chillAST_NodeList* ConvertUnaryOperator(UnaryOperator *clangUO) { const char *op = unops[clangUO->getOpcode()].c_str(); bool pre = clangUO->isPrefix(); - chillAST_node *sub = ConvertGenericClangAST(clangUO->getSubExpr(), NULL); + chillAST_Node *sub = unwrap(ConvertGenericClangAST(clangUO->getSubExpr())); - chillAST_UnaryOperator *chillUO = new chillAST_UnaryOperator(op, pre, sub, p); - sub->setParent(chillUO); - return chillUO; + chillAST_UnaryOperator *chillUO = new chillAST_UnaryOperator(op, pre, sub, NULL); + NL_RET(chillUO); } -chillAST_node *ConvertBinaryOperator(BinaryOperator *clangBO, chillAST_node *p) { +chillAST_NodeList* ConvertBinaryOperator(BinaryOperator *clangBO) { // get the clang parts Expr *lhs = clangBO->getLHS(); @@ -1007,37 +1002,34 @@ chillAST_node *ConvertBinaryOperator(BinaryOperator *clangBO, chillAST_node *p) // convert to chill equivalents - chillAST_node *l = ConvertGenericClangAST(lhs, NULL); + chillAST_Node *l = unwrap(ConvertGenericClangAST(lhs)); const char *opstring = binops[op].c_str(); - chillAST_node *r = ConvertGenericClangAST(rhs, NULL); + chillAST_Node *r = unwrap(ConvertGenericClangAST(rhs)); // TODO chill equivalent for numeric op. // build up the chill Binary Op AST node - chillAST_BinaryOperator *binop = new chillAST_BinaryOperator(l, opstring, r, p); - l->setParent(binop); - r->setParent(binop); + chillAST_BinaryOperator *binop = new chillAST_BinaryOperator(l, opstring, r, NULL); - return binop; + NL_RET(binop); } -chillAST_node *ConvertArraySubscriptExpr(ArraySubscriptExpr *clangASE, chillAST_node *p) { +chillAST_NodeList* ConvertArraySubscriptExpr(ArraySubscriptExpr *clangASE) { Expr *clangbase = clangASE->getBase(); Expr *clangindex = clangASE->getIdx(); //fprintf(stderr, "clang base: "); clangbase->dump(); fprintf(stderr, "\n"); - chillAST_node *bas = ConvertGenericClangAST(clangbase, NULL); - chillAST_node *indx = ConvertGenericClangAST(clangindex, NULL); + chillAST_Node *bas = unwrap(ConvertGenericClangAST(clangbase)); + chillAST_Node *indx = unwrap(ConvertGenericClangAST(clangindex)); - chillAST_ArraySubscriptExpr *chillASE = new chillAST_ArraySubscriptExpr(bas, indx, p, clangASE); - bas->setParent(chillASE); - indx->setParent(chillASE); - return chillASE; + // TODO clangAST contamination + chillAST_ArraySubscriptExpr *chillASE = new chillAST_ArraySubscriptExpr(bas, indx, NULL, clangASE); + NL_RET(chillASE); } -chillAST_node *ConvertDeclRefExpr(DeclRefExpr *clangDRE, chillAST_node *p) { +chillAST_NodeList* ConvertDeclRefExpr(DeclRefExpr *clangDRE) { DeclarationNameInfo DNI = clangDRE->getNameInfo(); ValueDecl *vd = static_cast<ValueDecl *>(clangDRE->getDecl()); // ValueDecl ?? VarDecl ?? @@ -1049,7 +1041,7 @@ chillAST_node *ConvertDeclRefExpr(DeclRefExpr *clangDRE, chillAST_node *p) { DeclarationName DN = DNI.getName(); const char *varname = DN.getAsString().c_str(); - chillAST_DeclRefExpr *chillDRE = new chillAST_DeclRefExpr(TypeStr.c_str(), varname, p); + chillAST_DeclRefExpr *chillDRE = new chillAST_DeclRefExpr(TypeStr.c_str(), varname, NULL); //fprintf(stderr, "clang DeclRefExpr refers to declaration of %s @ 0x%x\n", varname, vd); //fprintf(stderr, "clang DeclRefExpr refers to declaration of %s of kind %s\n", varname, vd->getDeclKindName()); @@ -1082,7 +1074,7 @@ chillAST_node *ConvertDeclRefExpr(DeclRefExpr *clangDRE, chillAST_node *p) { exit(-1); } - chillDRE->decl = (chillAST_node *) chillvd; // start of spaghetti pointers ... + chillDRE->decl = (chillAST_Node *) chillvd; // start of spaghetti pointers ... } else if (!strcmp("Function", vd->getDeclKindName())) { //fprintf(stderr, "declrefexpr of type Function\n"); int numfuncs = FunctionDeclarations.size(); @@ -1098,7 +1090,7 @@ chillAST_node *ConvertDeclRefExpr(DeclRefExpr *clangDRE, chillAST_node *p) { exit(-1); } - chillDRE->decl = (chillAST_node *) chillfd; // start of spaghetti pointers ... + chillDRE->decl = (chillAST_Node *) chillfd; // start of spaghetti pointers ... } else { fprintf(stderr, "clang DeclRefExpr refers to declaration of %s of kind %s\n", varname, vd->getDeclKindName()); @@ -1106,23 +1098,23 @@ chillAST_node *ConvertDeclRefExpr(DeclRefExpr *clangDRE, chillAST_node *p) { exit(-1); } - //fprintf(stderr, "%s\n", DN.getAsString().c_str()); - return chillDRE; + //fprintf(stderr, "%s\n", DN.getAsString().c_str()); + NL_RET(chillDRE); } -chillAST_node *ConvertIntegerLiteral(IntegerLiteral *clangIL, chillAST_node *p) { +chillAST_NodeList* ConvertIntegerLiteral(IntegerLiteral *clangIL) { bool isSigned = clangIL->getType()->isSignedIntegerType(); //int val = clangIL->getIntValue(); const char *printable = clangIL->getValue().toString(10, isSigned).c_str(); int val = atoi(printable); //fprintf(stderr, "int value %s (%d)\n", printable, val); - chillAST_IntegerLiteral *chillIL = new chillAST_IntegerLiteral(val, p); - return chillIL; + chillAST_IntegerLiteral *chillIL = new chillAST_IntegerLiteral(val, NULL); + NL_RET(chillIL); } -chillAST_node *ConvertFloatingLiteral(FloatingLiteral *clangFL, chillAST_node *p) { +chillAST_NodeList* ConvertFloatingLiteral(FloatingLiteral *clangFL) { //fprintf(stderr, "\nConvertFloatingLiteral()\n"); float val = clangFL->getValueAsApproximateDouble(); // TODO approx is a bad idea! string WHAT; @@ -1186,30 +1178,29 @@ chillAST_node *ConvertFloatingLiteral(FloatingLiteral *clangFL, chillAST_node *p buf[len] = '\0'; //fprintf(stderr, "'%s'\n", buf); - chillAST_FloatingLiteral *chillFL = new chillAST_FloatingLiteral(val, buf, p); + chillAST_FloatingLiteral *chillFL = new chillAST_FloatingLiteral(val, buf, NULL); - //chillFL->print(); printf("\n"); fflush(stdout); - return chillFL; + //chillFL->print(); printf("\n"); fflush(stdout); + NL_RET(chillFL); } -chillAST_node *ConvertImplicitCastExpr(ImplicitCastExpr *clangICE, chillAST_node *p) { +chillAST_NodeList* ConvertImplicitCastExpr(ImplicitCastExpr *clangICE) { //fprintf(stderr, "ConvertImplicitCastExpr()\n"); CastExpr *CE = dyn_cast<ImplicitCastExpr>(clangICE); //fprintf(stderr, "implicit cast of type %s\n", CE->getCastKindName()); - chillAST_node *sub = ConvertGenericClangAST(clangICE->getSubExpr(), p); - chillAST_ImplicitCastExpr *chillICE = new chillAST_ImplicitCastExpr(sub, p); + chillAST_Node *sub = unwrap(ConvertGenericClangAST(clangICE->getSubExpr())); + chillAST_ImplicitCastExpr *chillICE = new chillAST_ImplicitCastExpr(sub, NULL); //sub->setParent( chillICE ); // these 2 lines work //return chillICE; - //sub->setParent(p); // ignore the ImplicitCastExpr !! TODO (probably a bad idea) - return sub; - + //sub->setParent(p); // ignore the ImplicitCastExpr !! TODO (probably a bad idea) + NL_RET(chillICE); } -chillAST_node *ConvertCStyleCastExpr(CStyleCastExpr *clangCSCE, chillAST_node *p) { +chillAST_NodeList* ConvertCStyleCastExpr(CStyleCastExpr *clangCSCE) { //fprintf(stderr, "ConvertCStyleCastExpr()\n"); //fprintf(stderr, "C Style cast of kind "); CastExpr *CE = dyn_cast<CastExpr>(clangCSCE); @@ -1219,58 +1210,54 @@ chillAST_node *ConvertCStyleCastExpr(CStyleCastExpr *clangCSCE, chillAST_node *p const char *towhat = strdup(clangCSCE->getTypeAsWritten().getAsString().c_str()); //fprintf(stderr, "before sub towhat (%s)\n", towhat); - chillAST_node *sub = ConvertGenericClangAST(clangCSCE->getSubExprAsWritten(), NULL); + chillAST_Node *sub = unwrap(ConvertGenericClangAST(clangCSCE->getSubExprAsWritten())); //fprintf(stderr, "after sub towhat (%s)\n", towhat); - chillAST_CStyleCastExpr *chillCSCE = new chillAST_CStyleCastExpr(towhat, sub, p); + chillAST_CStyleCastExpr *chillCSCE = new chillAST_CStyleCastExpr(towhat, sub, NULL); //fprintf(stderr, "after CSCE towhat (%s)\n", towhat); - sub->setParent(chillCSCE); - return chillCSCE; + NL_RET(chillCSCE); } -chillAST_node *ConvertReturnStmt(ReturnStmt *clangRS, chillAST_node *p) { - chillAST_node *retval = ConvertGenericClangAST(clangRS->getRetValue(), NULL); // NULL is handled +chillAST_NodeList* ConvertReturnStmt(ReturnStmt *clangRS) { + chillAST_Node *retval = unwrap(ConvertGenericClangAST(clangRS->getRetValue())); // NULL is handled //if (retval == NULL) fprintf(stderr, "return stmt returns nothing\n"); - chillAST_ReturnStmt *chillRS = new chillAST_ReturnStmt(retval, p); - if (retval) retval->setParent(chillRS); - return chillRS; + chillAST_ReturnStmt *chillRS = new chillAST_ReturnStmt(retval, NULL); + NL_RET(chillRS); } -chillAST_node *ConvertCallExpr(CallExpr *clangCE, chillAST_node *p) { +chillAST_NodeList* ConvertCallExpr(CallExpr *clangCE) { //fprintf(stderr, "ConvertCallExpr()\n"); - chillAST_node *callee = ConvertGenericClangAST(clangCE->getCallee(), NULL); + chillAST_Node *callee = unwrap(ConvertGenericClangAST(clangCE->getCallee())); //fprintf(stderr, "callee is of type %s\n", callee->getTypeString()); - //chillAST_node *next = ((chillAST_ImplicitCastExpr *)callee)->subexpr; + //chillAST_Node *next = ((chillAST_ImplicitCastExpr *)callee)->subexpr; //fprintf(stderr, "callee is of type %s\n", next->getTypeString()); - chillAST_CallExpr *chillCE = new chillAST_CallExpr(callee, p); - callee->setParent(chillCE); + chillAST_CallExpr *chillCE = new chillAST_CallExpr(callee, NULL); int numargs = clangCE->getNumArgs(); //fprintf(stderr, "CallExpr has %d args\n", numargs); Expr **clangargs = clangCE->getArgs(); for (int i = 0; i < numargs; i++) { - chillCE->addArg(ConvertGenericClangAST(clangargs[i], chillCE)); + chillCE->addArg(unwrap(ConvertGenericClangAST(clangargs[i]))); } - return chillCE; + NL_RET(chillCE); } -chillAST_node *ConvertParenExpr(ParenExpr *clangPE, chillAST_node *p) { - chillAST_node *sub = ConvertGenericClangAST(clangPE->getSubExpr(), NULL); - chillAST_ParenExpr *chillPE = new chillAST_ParenExpr(sub, p); - sub->setParent(chillPE); +chillAST_NodeList* ConvertParenExpr(ParenExpr *clangPE) { + chillAST_Node *sub = unwrap(ConvertGenericClangAST(clangPE->getSubExpr())); + chillAST_ParenExpr *chillPE = new chillAST_ParenExpr(sub, NULL); - return chillPE; + NL_RET(chillPE); } -chillAST_node *ConvertTranslationUnit(TranslationUnitDecl *TUD, char *filename) { +chillAST_NodeList* ConvertTranslationUnit(TranslationUnitDecl *TUD, char *filename) { //fprintf(stderr, "ConvertTranslationUnit( filename %s )\n\n", filename); // TUD derived from Decl and DeclContext static DeclContext *DC = TUD->castToDeclContext(TUD); @@ -1297,20 +1284,20 @@ chillAST_node *ConvertTranslationUnit(TranslationUnitDecl *TUD, char *filename) Decl *D = *DI; if (isa<FunctionDecl>(D)) { //fprintf(stderr, "\nTUD FunctionDecl\n"); - topnode->addChild(ConvertFunctionDecl(dyn_cast<FunctionDecl>(D), topnode)); + topnode->addChild(unwrap(ConvertFunctionDecl(dyn_cast<FunctionDecl>(D)))); } else if (isa<VarDecl>(D)) { //fprintf(stderr, "\nTUD VarDecl\n"); - topnode->addChild(ConvertVarDecl(dyn_cast<VarDecl>(D), topnode)); + topnode->addChild(unwrap(ConvertVarDecl(dyn_cast<VarDecl>(D)))); //fflush(stdout); fprintf(stderr, "\nTUD VarDecl DONE\n"); } else if (isa<TypedefDecl>(D)) { //fprintf(stderr, "\nTUD TypedefDecl\n"); - topnode->addChild(ConvertTypeDefDecl(dyn_cast<TypedefDecl>(D), topnode)); + topnode->addChild(unwrap(ConvertTypeDefDecl(dyn_cast<TypedefDecl>(D)))); } else if (isa<RecordDecl>(D)) { - fprintf(stderr, "\nTUD RecordDecl\n"); - topnode->addChild(ConvertRecordDecl(dyn_cast<RecordDecl>(D), topnode)); + CHILL_DEBUG_PRINT("\nTUD RecordDecl\n"); + topnode->addChild(unwrap(ConvertRecordDecl(dyn_cast<RecordDecl>(D)))); } else if (isa<TypeAliasDecl>(D)) { - fprintf(stderr, "TUD TypeAliasDecl TODO \n"); + CHILL_ERROR("TUD TypeAliasDecl TODO \n"); exit(-1); } else { - fprintf(stderr, "\nTUD a declaration of type %s (%d) which I can't handle\n", D->getDeclKindName(), D->getKind()); + CHILL_ERROR("\nTUD a declaration of type %s (%d) which I can't handle\n", D->getDeclKindName(), D->getKind()); exit(-1); } } @@ -1318,11 +1305,11 @@ chillAST_node *ConvertTranslationUnit(TranslationUnitDecl *TUD, char *filename) //fprintf(stderr, "in ConvertTranslationUnit(), dumping the file\n"); //topnode->dump(); - return (chillAST_node *) topnode; + NL_RET(topnode); } -chillAST_node *ConvertGenericClangAST(Stmt *s, chillAST_node *p) { +chillAST_NodeList* ConvertGenericClangAST(Stmt *s) { if (s == NULL) return NULL; //fprintf(stderr, "\nConvertGenericClangAST() Stmt of type %d (%s)\n", s->getStmtClass(),s->getStmtClassName()); @@ -1330,40 +1317,40 @@ chillAST_node *ConvertGenericClangAST(Stmt *s, chillAST_node *p) { //if (isa<Decl>(D)) fprintf(stderr, "Decl of kind %d (%s)\n", D->getKind(),D->getDeclKindName() ); - chillAST_node *ret = NULL; + chillAST_NodeList *ret = NULL; // find the SINGLE constant or data reference at this node or below if (isa<CompoundStmt>(s)) { - ret = ConvertCompoundStmt(dyn_cast<CompoundStmt>(s), p); + ret = ConvertCompoundStmt(dyn_cast<CompoundStmt>(s)); } else if (isa<DeclStmt>(s)) { - ret = ConvertDeclStmt(dyn_cast<DeclStmt>(s), p); + ret = ConvertDeclStmt(dyn_cast<DeclStmt>(s)); } else if (isa<ForStmt>(s)) { - ret = ConvertForStmt(dyn_cast<ForStmt>(s), p); + ret = ConvertForStmt(dyn_cast<ForStmt>(s)); } else if (isa<BinaryOperator>(s)) { - ret = ConvertBinaryOperator(dyn_cast<BinaryOperator>(s), p); + ret = ConvertBinaryOperator(dyn_cast<BinaryOperator>(s)); } else if (isa<ArraySubscriptExpr>(s)) { - ret = ConvertArraySubscriptExpr(dyn_cast<ArraySubscriptExpr>(s), p); + ret = ConvertArraySubscriptExpr(dyn_cast<ArraySubscriptExpr>(s)); } else if (isa<DeclRefExpr>(s)) { - ret = ConvertDeclRefExpr(dyn_cast<DeclRefExpr>(s), p); + ret = ConvertDeclRefExpr(dyn_cast<DeclRefExpr>(s)); } else if (isa<FloatingLiteral>(s)) { - ret = ConvertFloatingLiteral(dyn_cast<FloatingLiteral>(s), p); + ret = ConvertFloatingLiteral(dyn_cast<FloatingLiteral>(s)); } else if (isa<IntegerLiteral>(s)) { - ret = ConvertIntegerLiteral(dyn_cast<IntegerLiteral>(s), p); + ret = ConvertIntegerLiteral(dyn_cast<IntegerLiteral>(s)); } else if (isa<UnaryOperator>(s)) { - ret = ConvertUnaryOperator(dyn_cast<UnaryOperator>(s), p); + ret = ConvertUnaryOperator(dyn_cast<UnaryOperator>(s)); } else if (isa<ImplicitCastExpr>(s)) { - ret = ConvertImplicitCastExpr(dyn_cast<ImplicitCastExpr>(s), p); + ret = ConvertImplicitCastExpr(dyn_cast<ImplicitCastExpr>(s)); } else if (isa<CStyleCastExpr>(s)) { - ret = ConvertCStyleCastExpr(dyn_cast<CStyleCastExpr>(s), p); + ret = ConvertCStyleCastExpr(dyn_cast<CStyleCastExpr>(s)); } else if (isa<ReturnStmt>(s)) { - ret = ConvertReturnStmt(dyn_cast<ReturnStmt>(s), p); + ret = ConvertReturnStmt(dyn_cast<ReturnStmt>(s)); } else if (isa<CallExpr>(s)) { - ret = ConvertCallExpr(dyn_cast<CallExpr>(s), p); + ret = ConvertCallExpr(dyn_cast<CallExpr>(s)); } else if (isa<ParenExpr>(s)) { - ret = ConvertParenExpr(dyn_cast<ParenExpr>(s), p); + ret = ConvertParenExpr(dyn_cast<ParenExpr>(s)); } else if (isa<IfStmt>(s)) { - ret = ConvertIfStmt(dyn_cast<IfStmt>(s), p); + ret = ConvertIfStmt(dyn_cast<IfStmt>(s)); } else if (isa<MemberExpr>(s)) { - ret = ConvertMemberExpr(dyn_cast<MemberExpr>(s), p); + ret = ConvertMemberExpr(dyn_cast<MemberExpr>(s)); // these can only happen at the top level? @@ -1611,7 +1598,7 @@ IR_ArraySymbol *IR_chillArrayRef::symbol() const { //fprintf(stderr, "base: "); chillASE->base->print(); printf("\n"); fflush(stdout); - chillAST_node *mb = chillASE->multibase(); + chillAST_Node *mb = chillASE->multibase(); chillAST_VarDecl *vd = (chillAST_VarDecl *) mb; //fprintf(stderr, "symbol: '%s'\n", vd->varname); @@ -1621,22 +1608,22 @@ IR_ArraySymbol *IR_chillArrayRef::symbol() const { //fprintf(stderr, "ir_clang.cc returning IR_chillArraySymbol 0x%x\n", AS); return AS; /* - chillAST_node *b = chillASE->base; + chillAST_Node *b = chillASE->base; fprintf(stderr, "base of type %s\n", b->getTypeString()); //b->print(); printf("\n"); fflush(stdout); - if (b->asttype == CHILLAST_NODETYPE_IMPLICITCASTEXPR) { + if (b->getType() == CHILLAST_NODE_IMPLICITCASTEXPR) { b = ((chillAST_ImplicitCastExpr*)b)->subexpr; fprintf(stderr, "base of type %s\n", b->getTypeString()); } - if (b->asttype == CHILLAST_NODETYPE_DECLREFEXPR) { + if (b->getType() == CHILLAST_NODE_DECLREFEXPR) { if (NULL == ((chillAST_DeclRefExpr*)b)->decl) { fprintf(stderr, "IR_chillArrayRef::symbol() var decl = 0x%x\n", ((chillAST_DeclRefExpr*)b)->decl); exit(-1); } return new IR_chillArraySymbol(ir_, ((chillAST_DeclRefExpr*)b)->decl); // -> decl? } - if (b->asttype == CHILLAST_NODETYPE_ARRAYSUBSCRIPTEXPR) { // multidimensional array + if (b->getType() == CHILLAST_NODE_ARRAYSUBSCRIPTEXPR) { // multidimensional array return ( } fprintf(stderr, "IR_chillArrayRef::symbol() can't handle\n"); @@ -1726,25 +1713,25 @@ IR_chillLoop::IR_chillLoop(const IR_Code *ir, chillAST_ForStmt *achillforstmt) { chillupperbound = cond->getRHS(); conditionoperator = achillforstmt->conditionoperator; - chillAST_node *inc = chillforstmt->getInc(); + chillAST_Node *inc = chillforstmt->getInc(); // check the increment //fprintf(stderr, "increment is of type %s\n", inc->getTypeString()); //inc->print(); printf("\n"); fflush(stdout); - if (inc->asttype == CHILLAST_NODETYPE_UNARYOPERATOR) { + if (inc->getType() == CHILLAST_NODE_UNARYOPERATOR) { if (!strcmp(((chillAST_UnaryOperator *) inc)->op, "++")) step_size_ = 1; else step_size_ = -1; - } else if (inc->asttype == CHILLAST_NODETYPE_BINARYOPERATOR) { + } else if (inc->getType() == CHILLAST_NODE_BINARYOPERATOR) { int beets = false; // slang chillAST_BinaryOperator *bop = (chillAST_BinaryOperator *) inc; if (bop->isAssignmentOp()) { // I=I+1 or similar - chillAST_node *rhs = bop->getRHS(); // (I+1) + chillAST_Node *rhs = bop->getRHS(); // (I+1) // TODO looks like this will fail for I=1+I or I=J+1 etc. do more checking char *assop = bop->getOp(); //fprintf(stderr, "'%s' is an assignment op\n", bop->getOp()); if (streq(assop, "+=") || streq(assop, "-=")) { - chillAST_node *stride = rhs; + chillAST_Node *stride = rhs; //fprintf(stderr, "stride is of type %s\n", stride->getTypeString()); if (stride->isIntegerLiteral()) { int val = ((chillAST_IntegerLiteral *) stride)->value; @@ -1754,7 +1741,7 @@ IR_chillLoop::IR_chillLoop(const IR_Code *ir, chillAST_ForStmt *achillforstmt) { } else beets = true; // += or -= but not constant stride } else if (rhs->isBinaryOperator()) { chillAST_BinaryOperator *binoprhs = (chillAST_BinaryOperator *) rhs; - chillAST_node *intlit = binoprhs->getRHS(); + chillAST_Node *intlit = binoprhs->getRHS(); if (intlit->isIntegerLiteral()) { int val = ((chillAST_IntegerLiteral *) intlit)->value; if (!strcmp(binoprhs->getOp(), "+")) step_size_ = val; @@ -1881,13 +1868,13 @@ void IR_chillBlock::dump() const { } //StmtList -vector<chillAST_node *> IR_chillBlock::getStmtList() const { +vector<chillAST_Node *> IR_chillBlock::getStmtList() const { fprintf(stderr, "IR_xxxxBlock::getStmtList()\n"); return statements; // ?? } -void IR_chillBlock::addStatement(chillAST_node *s) { +void IR_chillBlock::addStatement(chillAST_Node *s) { statements.push_back(s); } @@ -1921,10 +1908,10 @@ class NULLASTConsumer : public ASTConsumer { }; -void findmanually(chillAST_node *node, char *procname, std::vector<chillAST_node *> &procs) { +void findmanually(chillAST_Node *node, char *procname, std::vector<chillAST_Node *> &procs) { //fprintf(stderr, "findmanually() CHILL AST node of type %s\n", node->getTypeString()); - if (node->asttype == CHILLAST_NODETYPE_FUNCTIONDECL) { + if (node->getType() == CHILLAST_NODE_FUNCTIONDECL) { char *name = ((chillAST_FunctionDecl *) node)->functionName; //fprintf(stderr, "node name 0x%x ", name); //fprintf(stderr, "%s procname ", name); @@ -2078,7 +2065,7 @@ aClangCompiler::aClangCompiler(char *filename) { // create another AST, very similar to the clang AST but not written by idiots CHILL_DEBUG_PRINT("converting entire clang AST into chill AST (ir_clang.cc)\n"); - chillAST_node *wholefile = ConvertTranslationUnit(TUD, filename); + chillAST_Node *wholefile = unwrap(ConvertTranslationUnit(TUD, filename)); fflush(stdout); //fprintf(stderr, "printing whole file\n"); @@ -2140,7 +2127,7 @@ chillAST_FunctionDecl *aClangCompiler::findprocedurebyname(char *procname) { //fprintf(stderr, "searching through files in the clang AST\n\n"); //fprintf(stderr, "astContext_ 0x%x\n", astContext_); - std::vector<chillAST_node *> procs; + std::vector<chillAST_Node *> procs; findmanually(entire_file_AST, procname, procs); //fprintf(stderr, "procs has %d members\n", procs.size()); @@ -2267,7 +2254,7 @@ IR_clangCode::IR_clangCode(const char *fname, const char *proc_name) : IR_Code() pInstance->setCurrentFunction(localFD); - chillAST_node *b = localFD->getBody(); // we do this just because it will get done next + chillAST_Node *b = localFD->getBody(); // we do this just because it will get done next CHILL_DEBUG_PRINT("calling new CG_chillBuilder() umwut?\n"); ocg_ = new omega::CG_chillBuilder(); // ocg == omega code gen @@ -2300,7 +2287,7 @@ IR_clangCode::~IR_clangCode() { // TODO should output the entire file, not just the function we're working on chillAST_SourceFile *src = chillfunc->getSourceFile(); - //chillAST_node *p = chillfunc->parent; // should be translationDeclUnit + //chillAST_Node *p = chillfunc->parent; // should be translationDeclUnit if (src) { //src->print(); // tmp if (src->isSourceFile()) src->printToFile(); @@ -2319,7 +2306,7 @@ IR_ScalarSymbol *IR_clangCode::CreateScalarSymbol(const IR_Symbol *sym, int i) { // do we have to check to see if it's already there? VariableDeclarations.push_back(vd); - chillAST_node *bod = chillfunc->getBody(); // always a compoundStmt ?? + chillAST_Node *bod = chillfunc->getBody(); // always a compoundStmt ?? bod->insertChild(0, vd); fprintf(stderr, "returning ... really\n"); return new IR_chillScalarSymbol(this, CSS->chillvd); // CSS->clone(); @@ -2392,7 +2379,7 @@ IR_clangCode::CreateArraySymbol(const IR_Symbol *sym, std::vector<omega::CG_outp exit(-1); } - chillAST_node *nodezero = CR->chillnodes[0]; + chillAST_Node *nodezero = CR->chillnodes[0]; if (!nodezero->isIntegerLiteral()) { fprintf(stderr, "IR_clangCode::CreateArraySymbol() array dimension %d not an IntegerLiteral\n", i); exit(-1); @@ -2410,7 +2397,7 @@ IR_clangCode::CreateArraySymbol(const IR_Symbol *sym, std::vector<omega::CG_outp // put decl in some symbol table VariableDeclarations.push_back(vd); // insert decl in the IR_code body - chillAST_node *bod = chillfunc->getBody(); // always a compoundStmt ?? + chillAST_Node *bod = chillfunc->getBody(); // always a compoundStmt ?? bod->insertChild(0, vd); return new IR_chillArraySymbol(this, vd); @@ -2449,7 +2436,7 @@ IR_ArrayRef *IR_clangCode::CreateArrayRef(const IR_ArraySymbol *sym, std::vector const IR_chillArraySymbol *c_sym = static_cast<const IR_chillArraySymbol *>(sym); chillAST_VarDecl *vd = c_sym->chillvd; - std::vector<chillAST_node *> inds; + std::vector<chillAST_Node *> inds; //fprintf(stderr, "%d array indeces\n", sym->n_dim()); for (int i = 0; i < index.size(); i++) { @@ -2466,7 +2453,7 @@ IR_ArrayRef *IR_clangCode::CreateArrayRef(const IR_ArraySymbol *sym, std::vector inds.push_back(CR->chillnodes[0]); /* - chillAST_node *nodezero = CR->chillnodes[0]; + chillAST_Node *nodezero = CR->chillnodes[0]; if (!nodezero->isIntegerLiteral()) { fprintf(stderr,"IR_clangCode::CreateArrayRef() array dimension %d not an IntegerLiteral\n",i); fprintf(stderr, "it is a %s\n", nodezero->getTypeString()); @@ -2495,7 +2482,7 @@ std::vector<IR_ArrayRef *> IR_clangCode::FindArrayRef(const omega::CG_outputRepr //fprintf(stderr, "FindArrayRef()\n"); std::vector<IR_ArrayRef *> arrays; const omega::CG_chillRepr *crepr = static_cast<const omega::CG_chillRepr *>(repr); - std::vector<chillAST_node *> chillstmts = crepr->getChillCode(); + std::vector<chillAST_Node *> chillstmts = crepr->getChillCode(); //fprintf(stderr, "there are %d chill statements in this repr\n", chillstmts.size()); @@ -2591,7 +2578,7 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl std::vector<IR_Control *> controls; - chillAST_node *blockast = NULL; + chillAST_Node *blockast = NULL; int numstmts = CB->statements.size(); CHILL_DEBUG_PRINT("%d statements\n", numstmts); @@ -2609,7 +2596,7 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl CHILL_DEBUG_END - //vector<chillAST_node *> funcchildren = chillfunc->getChildren(); + //vector<chillAST_Node *> funcchildren = chillfunc->getChildren(); //fprintf(stderr, "%d children of clangcode\n", funcchildren.size()); // includes parameters // build up a vector of "controls". @@ -2617,10 +2604,10 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl // bundled up into an IR_Block // ifs and loops will get their own entry - std::vector<chillAST_node *> children; + std::vector<chillAST_Node *> children; - if (blockast->asttype == CHILLAST_NODETYPE_FORSTMT) { + if (blockast->getType() == CHILLAST_NODE_FORSTMT) { CHILL_DEBUG_BEGIN fflush(stdout); fprintf(stderr, "found a top level For statement (Loop)\n"); @@ -2631,17 +2618,17 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl controls.push_back(new IR_chillLoop(this, (chillAST_ForStmt *) blockast)); } - //else if (blockast->asttype == CHILLAST_NODETYPE_IFSTMT) { + //else if (blockast->getType() == CHILLAST_NODE_IFSTMT) { // controls.push_back( new IR_clangIf( this, (chillAST_IfStmt *)blockast)); //} - else if (blockast->asttype == CHILLAST_NODETYPE_COMPOUNDSTMT || - blockast->asttype == CHILLAST_NODETYPE_FUNCTIONDECL) { + else if (blockast->getType() == CHILLAST_NODE_COMPOUNDSTMT || + blockast->getType() == CHILLAST_NODE_FUNCTIONDECL) { - if (blockast->asttype == CHILLAST_NODETYPE_FUNCTIONDECL) { - //fprintf(stderr, "ir_clanc.cc blockast->asttype == CHILLAST_NODETYPE_FUNCTIONDECL\n"); + if (blockast->getType() == CHILLAST_NODE_FUNCTIONDECL) { + //fprintf(stderr, "ir_clanc.cc blockast->getType() == CHILLAST_NODE_FUNCTIONDECL\n"); chillAST_FunctionDecl *FD = (chillAST_FunctionDecl *) blockast; - chillAST_node *bod = FD->getBody(); + chillAST_Node *bod = FD->getBody(); //fprintf(stderr, "bod 0x%x\n", bod); children = bod->getChildren(); @@ -2667,8 +2654,8 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl IR_chillBlock *basicblock = new IR_chillBlock(this); // no statements for (int i = 0; i < numchildren; i++) { //fprintf(stderr, "child %d is of type %s\n", i, children[i]->getTypeString()); - CHILL_ASTNODE_TYPE typ = children[i]->asttype; - if (typ == CHILLAST_NODETYPE_LOOP) { + CHILLAST_NODE_TYPE typ = children[i]->getType(); + if (typ == CHILLAST_NODE_LOOP) { if (numchildren == 1) { CHILL_DEBUG_PRINT("found a For statement (Loop)\n"); } else { @@ -2687,7 +2674,7 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl controls.push_back(new IR_chillLoop(this, (chillAST_ForStmt *) children[i])); } - //else if (typ == CHILLAST_NODETYPE_IFSTMT ) // TODO + //else if (typ == CHILLAST_NODE_IFSTMT ) // TODO else { // straight line code basicblock->addStatement(children[i]); CHILL_DEBUG_BEGIN @@ -2730,8 +2717,8 @@ IR_Block *IR_clangCode::MergeNeighboringControlStructures(const std::vector<IR_C IR_chillBlock *CBlock = new IR_chillBlock(controls[0]->ir_); // the thing we're building - std::vector<chillAST_node *> statements; - chillAST_node *parent = NULL; + std::vector<chillAST_Node *> statements; + chillAST_Node *parent = NULL; for (int i = 0; i < controls.size(); i++) { switch (controls[i]->type()) { case IR_CONTROL_LOOP: { @@ -2750,7 +2737,7 @@ IR_Block *IR_clangCode::MergeNeighboringControlStructures(const std::vector<IR_C case IR_CONTROL_BLOCK: { CHILL_DEBUG_PRINT("control %d is IR_CONTROL_BLOCK\n", i); IR_chillBlock *CB = static_cast<IR_chillBlock *>(controls[i]); - std::vector<chillAST_node *> blockstmts = CB->statements; + std::vector<chillAST_Node *> blockstmts = CB->statements; for (int j = 0; j < blockstmts.size(); j++) { if (parent == NULL) { parent = blockstmts[j]->parent; @@ -2778,7 +2765,7 @@ IR_Block *IR_clangCode::GetCode() const { // return IR_Block corresponding to //Stmt *s = func_->getBody(); // clang statement, and clang getBody //fprintf(stderr, "chillfunc 0x%x\n", chillfunc); - //chillAST_node *bod = chillfunc->getBody(); // chillAST + //chillAST_Node *bod = chillfunc->getBody(); // chillAST //fprintf(stderr, "printing the function getBody()\n"); //fprintf(stderr, "sourceManager 0x%x\n", sourceManager); //bod->print(); @@ -2792,7 +2779,7 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) { fprintf(stderr, "IR_xxxxCode::ReplaceCode( old, *repr)\n"); CG_chillRepr *chillrepr = (CG_chillRepr *) repr; - std::vector<chillAST_node *> newcode = chillrepr->getChillCode(); + std::vector<chillAST_Node *> newcode = chillrepr->getChillCode(); int numnew = newcode.size(); //fprintf(stderr, "new code (%d) is\n", numnew); @@ -2855,7 +2842,7 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) { } } - chillAST_node *par; + chillAST_Node *par; switch (old->type()) { case IR_CONTROL_LOOP: { //fprintf(stderr, "old is IR_CONTROL_LOOP\n"); @@ -2886,7 +2873,7 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) { fflush(stdout); fprintf(stderr, "\n}\n"); - std::vector<chillAST_node *> oldparentcode = par->getChildren(); // probably only works for compoundstmts + std::vector<chillAST_Node *> oldparentcode = par->getChildren(); // probably only works for compoundstmts //fprintf(stderr, "ir_clang.cc oldparentcode\n"); // find loop in the parent @@ -2940,7 +2927,7 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) { //fprintf(stderr, "\nafter inserting %d statements into the Clang IR,", numnew); CHILL_DEBUG_BEGIN fprintf(stderr, "new parent2 is\n\n{\n"); - std::vector<chillAST_node *> newparentcode = par->getChildren(); + std::vector<chillAST_Node *> newparentcode = par->getChildren(); for (int i = 0; i < newparentcode.size(); i++) { fflush(stdout); //fprintf(stderr, "%d ", i); @@ -2973,7 +2960,7 @@ void IR_clangCode::ReplaceExpression(IR_Ref *old, omega::CG_outputRepr *repr) { //exit(-1); } - chillAST_node *newthing = crepr->chillnodes[0]; + chillAST_Node *newthing = crepr->chillnodes[0]; fprintf(stderr, "with new "); newthing->print(); printf("\n\n"); @@ -3032,7 +3019,7 @@ IR_OPERATION_TYPE IR_clangCode::QueryExpOperation(const omega::CG_outputRepr *re //fprintf(stderr, "IR_clangCode::QueryExpOperation()\n"); CG_chillRepr *crepr = (CG_chillRepr *) repr; - chillAST_node *node = crepr->chillnodes[0]; + chillAST_Node *node = crepr->chillnodes[0]; //fprintf(stderr, "chillAST node type %s\n", node->getTypeString()); // really need to be more rigorous than this hack // TODO @@ -3104,7 +3091,7 @@ std::vector<omega::CG_outputRepr *> IR_clangCode::QueryExpOperand(const omega::C CG_chillRepr *crepr = (CG_chillRepr *) repr; //Expr *e = static_cast<const omega::CG_chillRepr *>(repr)->GetExpression(); wrong.. CLANG - chillAST_node *e = crepr->chillnodes[0]; // ?? + chillAST_Node *e = crepr->chillnodes[0]; // ?? //e->print(); printf("\n"); fflush(stdout); // really need to be more rigorous than this hack // TODO @@ -3200,7 +3187,7 @@ Expr *op1, *op2; IR_Ref *IR_clangCode::Repr2Ref(const omega::CG_outputRepr *repr) const { CG_chillRepr *crepr = (CG_chillRepr *) repr; - chillAST_node *node = crepr->chillnodes[0]; + chillAST_Node *node = crepr->chillnodes[0]; //Expr *e = static_cast<const omega::CG_chillRep *>(repr)->GetExpression(); @@ -3221,13 +3208,13 @@ IR_Ref *IR_clangCode::Repr2Ref(const omega::CG_outputRepr *repr) const { } } -chillAST_node *ConvertMemberExpr(clang::MemberExpr *clangME, chillAST_node *) { +chillAST_NodeList* ConvertMemberExpr(clang::MemberExpr *clangME) { fprintf(stderr, "ConvertMemberExpr()\n"); clang::Expr *E = clangME->getBase(); E->dump(); - chillAST_node *base = ConvertGenericClangAST(clangME->getBase(), NULL); + chillAST_Node *base = unwrap(ConvertGenericClangAST(clangME->getBase())); DeclarationNameInfo memnameinfo = clangME->getMemberNameInfo(); DeclarationName DN = memnameinfo.getName(); @@ -3240,6 +3227,6 @@ chillAST_node *ConvertMemberExpr(clang::MemberExpr *clangME, chillAST_node *) { ME->print(); fprintf(stderr, "\n"); - return ME; + NL_RET(ME); } diff --git a/src/omegatools.cc b/src/omegatools.cc index c7233c8..07b12f5 100644 --- a/src/omegatools.cc +++ b/src/omegatools.cc @@ -613,7 +613,7 @@ void exp2formula(IR_Code *ir, CG_chillRepr *CR = (CG_chillRepr *) v[0]; // cheat for now. we should not know this is a chillRepr //fprintf(stderr, "v "); CR->dump(); fflush(stdout); //fprintf(stderr, "v "); v[0]->dump(); /* printf("\n"); */ fflush(stdout); - chillAST_node *node = CR->GetCode(); + chillAST_Node *node = CR->GetCode(); //fprintf(stderr, "\n**** walking parents!\n"); @@ -695,7 +695,7 @@ void exp2formula(IR_Code *ir, // r is enclosing relation, we build another that will include Variable_ID e = find_index(r, s, side); // s is the array named "index" - std::vector<chillAST_node *> internals = ((CG_chillRepr *) v[0])->getChillCode(); + std::vector<chillAST_Node *> internals = ((CG_chillRepr *) v[0])->getChillCode(); int numnodes = internals.size(); // always 1? std::vector<chillAST_DeclRefExpr *> dres; std::vector<chillAST_VarDecl *> decls; |