static QualifiedType returnInfoArrayIndexValue(CallExpr* call) { Type* type = call->get(1)->typeInfo(); if (type->symbol->hasFlag(FLAG_WIDE_CLASS)) type = type->getField("addr")->type; if (!type->substitutions.n) INT_FATAL(call, "bad primitive"); // Is this conditional necessary? Can just assume condition is true? if (type->symbol->hasFlag(FLAG_DATA_CLASS)) { return QualifiedType(toTypeSymbol(getDataClassType(type->symbol))->type, QUAL_VAL); } else { return QualifiedType(toTypeSymbol(type->substitutions.v[0].value)->type, QUAL_VAL); } }
static void list_sym(Symbol* sym, bool type = true) { if (VarSymbol* var = toVarSymbol(sym)) { if (var->immediate) { if (var->immediate->const_kind == NUM_KIND_INT) { printf("%"PRId64" ", var->immediate->int_value()); return; } else if (var->immediate->const_kind == CONST_KIND_STRING) { printf("\"%s\" ", var->immediate->v_string); return; } } } if (toFnSymbol(sym)) { printf("fn "); } else if (toArgSymbol(sym)) { printf("arg "); } else if (toTypeSymbol(sym)) { printf("type "); } printf("%s", sym->name); printf("[%d]", sym->id); if (!type) { printf(" "); } else if (FnSymbol* fn = toFnSymbol(sym)) { printf(":%s", fn->retType->symbol->name); printf("[%d] ", fn->retType->symbol->id); } else if (sym->type && sym->type->symbol) { printf(":%s", sym->type->symbol->name); printf("[%d] ", sym->type->symbol->id); } else { printf(" "); } }
static void view_sym(Symbol* sym, bool number, int mark) { putchar('\''); if (sym->id == mark) printf("***"); if (toFnSymbol(sym)) { printf("fn "); } else if (toArgSymbol(sym)) { printf("arg "); } else if (toTypeSymbol(sym)) { printf("type "); } printf("%s", sym->name); if (number) printf("[%d]", sym->id); if (FnSymbol* fn = toFnSymbol(sym)) { printf(":%s", fn->retType->symbol->name); if (number) printf("[%d]", fn->retType->symbol->id); } else if (sym->type && sym->type->symbol) { printf(":%s", sym->type->symbol->name); if (number) printf("[%d]", sym->type->symbol->id); } if (sym->hasFlag(FLAG_GENERIC)) putchar('?'); putchar('\''); }
BlockStmt* BlockStmt::copyInner(SymbolMap* map) { BlockStmt* _this = new BlockStmt(); _this->blockTag = blockTag; _this->blockInfo = COPY_INT(blockInfo); _this->useList = COPY_INT(useList); _this->byrefVars = COPY_INT(byrefVars); for_alist(expr, body) { Expr* copy = COPY_INT(expr); _this->insertAtTail(copy); if (DefExpr* def = toDefExpr(copy)) { if (TypeSymbol* ts = toTypeSymbol(def->sym)) { if (EnumType* et = toEnumType(ts->type)) { // ensure we have the size, cast functions, etc. // Lydia NOTE: This relies on making no copies of enum types prior to // buildDefaultFunctions(). The creation must happen here because // otherwise the EnumType will not have the correct symbol, and the // symbol will not be in the tree. buildEnumFunctions(et); } } } }
GenRet BlockStmt::codegen() { GenInfo* info = gGenInfo; FILE* outfile = info->cfile; GenRet ret; codegenStmt(this); if( outfile ) { if (blockInfo) { if (blockInfo->isPrimitive(PRIM_BLOCK_WHILEDO_LOOP)) { std::string hdr = "while (" + codegenValue(blockInfo->get(1)).c + ") "; info->cStatements.push_back(hdr); } else if (blockInfo->isPrimitive(PRIM_BLOCK_DOWHILE_LOOP)) { info->cStatements.push_back("do "); } else if (blockInfo->isPrimitive(PRIM_BLOCK_FOR_LOOP)) { std::string hdr = "for (;" + codegenValue(blockInfo->get(1)).c + ";) "; info->cStatements.push_back(hdr); } else if (blockInfo->isPrimitive(PRIM_BLOCK_XMT_PRAGMA_FORALL_I_IN_N)) { std::string hdr = "_Pragma(\"mta for all streams "; hdr += codegenValue(blockInfo->get(1)).c; hdr += " of "; hdr += codegenValue(blockInfo->get(2)).c; hdr += "\")\n"; info->cStatements.push_back(hdr); } } if (this != getFunction()->body) info->cStatements.push_back("{\n"); if (!(fNoRepositionDefExpr)) { Vec<BaseAST*> asts; collect_top_asts(this, asts); forv_Vec(BaseAST, ast, asts) { if (DefExpr* def = toDefExpr(ast)) { if (def->parentExpr == this) { if (!toTypeSymbol(def->sym)) { if (fGenIDS && isVarSymbol(def->sym)) info->cStatements.push_back("/* " + numToString(def->sym->id) + " */ "); def->sym->codegenDef(); } } } } } body.codegen(""); if (blockInfo && blockInfo->isPrimitive(PRIM_BLOCK_DOWHILE_LOOP)) { std::string ftr = "} while (" + codegenValue(blockInfo->get(1)).c + ");\n"; info->cStatements.push_back(ftr); } else if (this != getFunction()->body) { std::string end = "}"; CondStmt* cond = toCondStmt(parentExpr); if (!cond || !(cond->thenStmt == this && cond->elseStmt)) end += "\n"; info->cStatements.push_back(end); } } else {
static Type* returnInfoArrayIndexValue(CallExpr* call) { SymExpr* sym = toSymExpr(call->get(1)); INT_ASSERT(sym); Type* type = sym->var->type; if (type->symbol->hasFlag(FLAG_WIDE_CLASS)) type = type->getField("addr")->type; if (!type->substitutions.n) INT_FATAL(call, "bad primitive"); // Is this conditional necessary? Can just assume condition is true? if (type->symbol->hasFlag(FLAG_DATA_CLASS)) { return toTypeSymbol(getDataClassType(type->symbol))->type; } else { return toTypeSymbol(type->substitutions.v[0].value)->type; } }
void IpeModuleRoot::init() { mState = kResolved; initialize(); for (int i = 1; i <= sHighWater; i++) { DefExpr* expr = toDefExpr(rootModule->block->body.get(i)); INT_ASSERT(expr); if (mEnv->findLocal(expr->sym->name) != NULL) { printf(" Attempt to redefine identifier %s\n", expr->sym->name); INT_ASSERT(false); } else if (TypeSymbol* sym = toTypeSymbol(expr->sym)) { int offset = mEnv->allocateValue(sym->type); VarSymbol* var = new VarSymbol(sym->name, gIpeTypeType); INT_ASSERT(expr->exprType == NULL); INT_ASSERT(expr->init == NULL); var->addFlag(FLAG_CONST); var->locationSet(0, offset); mEnv->varAdd(var); } else if (expr->sym->isImmediate() == true) { VarSymbol* var = toVarSymbol(expr->sym); int offset = mEnv->allocateValue(var->type); var->addFlag(FLAG_CONST); var->locationSet(0, offset); mEnv->varAdd(var); } else { AstDumpToNode logger(stdout, 3); printf("Unexpected expression while initializing RootModule\n"); printf(" "); expr->accept(&logger); printf("\n"); INT_ASSERT(false); } } moduleAdd(this); }
void viewFlags(BaseAST* ast) { if (!viewFlagsShort && !viewFlagsName && !viewFlagsComment) viewFlagsName = true; if (Symbol* sym = toSymbol(ast)) { for (int flagNum = FLAG_FIRST; flagNum <= FLAG_LAST; flagNum++) { if (sym->flags[flagNum]) { if (viewFlagsName) printf("%s ", flagNames[flagNum]); if (viewFlagsPragma) printf("%s", flagPragma[flagNum] ? "ypr " : "npr "); if (viewFlagsShort) printf("\"%s\" ", flagShortNames[flagNum]); if (viewFlagsComment) printf("// %s", *flagComments[flagNum] ? flagComments[flagNum] : "ncm"); printf("\n"); } } if (viewFlagsExtras) { if (VarSymbol* vs = toVarSymbol(sym)) { if (vs->immediate) { printf("immediate "); fprint_imm(stdout, *toVarSymbol(sym)->immediate, true); printf("\n"); } } else if (ArgSymbol* as = toArgSymbol(sym)) { printf("%s arg\n", as->intentDescrString()); } else if (toTypeSymbol(sym)) { printf("a TypeSymbol\n"); } else if (FnSymbol* fs = toFnSymbol(sym)) { printf("fn %s(%d args) %s\n", fs->_this ? intentDescrString(fs->thisTag) : "", fs->numFormals(), retTagDescrString(fs->retTag)); } else if (toEnumSymbol(sym)) { printf("an EnumSymbol\n"); } else if (ModuleSymbol* ms = toModuleSymbol(sym)) { printf("module %s\n", modTagDescrString(ms->modTag)); } else if (toLabelSymbol(sym)) { printf("a LabelSymbol\n"); } else { printf("unknown symbol kind\n"); } } } else { printf("[%d]: not a Symbol, has no flags\n", ast->id); } }
static void log_ast_symbol(FILE* file, Symbol* sym, bool def) { if (log_need_space) putc(' ', file); log_need_space = false; if (def) if (ArgSymbol* arg = toArgSymbol(sym)) { log_need_space = true; switch (arg->intent) { case INTENT_IN: fprintf(file, "in"); break; case INTENT_INOUT: fprintf(file, "inout"); break; case INTENT_OUT: fprintf(file, "out"); break; case INTENT_CONST: fprintf(file, "const"); break; case INTENT_CONST_IN: fprintf(file, "const in"); break; case INTENT_CONST_REF: fprintf(file, "const ref"); break; case INTENT_REF: fprintf(file, "ref"); break; case INTENT_PARAM: fprintf(file, "param"); break; case INTENT_TYPE: fprintf(file, "type"); break; default: log_need_space = false; break; } log_write(file, true, "arg", true); } log_write(file, true, sym->name, true); if (fLogIds) fprintf(file, "[%d]", sym->id); if (def && !toTypeSymbol(sym) && sym->type && sym->type->symbol && sym->type != dtUnknown) { log_write(file, false, ":", false); log_ast_symbol(file, sym->type->symbol, false); } if (sym->hasFlag(FLAG_GENERIC)) log_write(file, false, "?", false); log_need_space = true; }
void AstDumpToHtml::writeSymbol(Symbol* sym, bool def) { if (def) { fprintf(mFP, "<A NAME=\"SYM%d\">", sym->id); } else if (sym->defPoint && sym->defPoint->parentSymbol && sym->defPoint->getModule()) { INT_ASSERT(hasHref(sym)); fprintf(mFP, "<A HREF=\"%s#SYM%d\">", html_file_name(sPassIndex, sym->defPoint->getModule()->name), sym->id); } else { INT_ASSERT(!hasHref(sym)); fprintf(mFP, "<A>"); } if (isFnSymbol(sym)) { fprintf(mFP, "<FONT COLOR=\"blue\">"); } else if (isTypeSymbol(sym)) { fprintf(mFP, "<FONT COLOR=\"green\">"); } else { fprintf(mFP, "<FONT COLOR=\"red\">"); } fprintf(mFP, "%s", sym->name); fprintf(mFP, "</FONT>"); fprintf(mFP, "<FONT COLOR=\"grey\">[%d]</FONT>", sym->id); fprintf(mFP, "</A>"); if (def && !toTypeSymbol(sym) && sym->type && sym->type->symbol && sym->type != dtUnknown) { fprintf(mFP, ":"); writeSymbol(sym->type->symbol, false); } }
void buildDefaultFunctions() { build_chpl_entry_points(); SET_LINENO(rootModule); // todo - remove reset_ast_loc() calls below? std::vector<BaseAST*> asts; collect_asts(rootModule, asts); for_vector(BaseAST, ast, asts) { if (TypeSymbol* type = toTypeSymbol(ast)) { // Here we build default functions that are always generated (even when // the type symbol has FLAG_NO_DEFAULT_FUNCTIONS attached). if (AggregateType* ct = toAggregateType(type->type)) { buildFieldAccessorFunctions(ct); if (!ct->symbol->hasFlag(FLAG_REF)) buildDefaultDestructor(ct); // Classes should use the nil:<type> _defaultOf method unless they // do not inherit from object. For those types and records, call // we need a more complicated _defaultOf method generated by the // compiler if (!ct->isClass() || ct->symbol->hasFlag(FLAG_NO_OBJECT)) build_record_init_function(ct); } if (type->hasFlag(FLAG_NO_DEFAULT_FUNCTIONS)) continue; // Here we build default functions that respect the "no default // functions" pragma. if (AggregateType* ct = toAggregateType(type->type)) { buildDefaultReadWriteFunctions(ct); if (isRecord(ct)) { if (!isRecordWrappedType(ct)) { build_record_equality_function(ct); build_record_inequality_function(ct); } build_record_assignment_function(ct); build_record_cast_function(ct); build_record_copy_function(ct); build_record_hash_function(ct); } if (isUnion(ct)) build_union_assignment_function(ct); } else if (EnumType* et = toEnumType(type->type)) { //buildDefaultReadFunction(et); buildStringCastFunction(et); build_enum_cast_function(et); build_enum_assignment_function(et); build_enum_first_function(et); build_enum_enumerate_function(et); } else { // The type is a simple type. // Other simple types are handled explicitly in the module code. // But to avoid putting a catch-all case there to implement assignment // for extern types that are simple (as far as we can tell), we build // definitions for those assignments here. if (type->hasFlag(FLAG_EXTERN)) { build_extern_init_function(type->type); build_extern_assignment_function(type->type); } } } } }