frame make_or_frame(frame f1, frame f2, int trsl) { if (trsl) { string final = "idTrue : _u1 || _u2 " QSM " idNull : idFalse"; string qsm = " " QSM " "; string du1 = make_decl(T_CBOOL, "_u" LVA "1 = 0"); string du2 = make_decl(T_CBOOL, "_u" LVA "2 = 0"); f1 = make_lknv_frame(f1, 1, 0, T_BOOL); f2 = make_lknv_frame(f2, 2, 0, T_BOOL); f1 = merge_frames(T_BOOL, T_UNKNOWN, f1, f2, f1->cl + f2->cl + 120, RET, "(", f1->code, qsm, "_v1 != idFalse : (_u1 = 1, 0)) ||" NST TABS "(", f2->code, qsm, "_v2 != idFalse : (_u2 = 1, 0))", qsm, NST, TABS, final, ""); f1->decls = cons(du1, f1->decls); f1->decls = cons(du2, f1->decls); f1->block = -1; return f1; } return make_log_frame(f1, f2, " || "); }
static frame make_lknv_frame(frame f, int n, int copy, rtype type) { char v[8]; string dv; if (copy) { frame cf = make_frame(f->type, NULL, f->cl, f->code, ""); f = cf; } if (f->type == T_SLOT) return make_knv_frame(f, n); sprintf(v, "_v%c%d", LVAC, n); dv = make_decl(type, v); dv[0] = type; if (f->block) { int b = f->block; f = deblock_frame(f, 1); if (b != -1) f = prepare_frame(f, type); } else if (f->type != type) f = coerce_frame(f, type); f->decls = cons(dv, f->decls); return merge_frames(T_CBOOL, T_UNKNOWN, f, NULL, f->cl + 18, "_lkn(" AMP, v, ", ", NORET(f->code), ")", ""); }
static frame make_knv_frame(frame f, int n) { frame fc = make_frame(f->type, copy_list(f->decls, 0), 6, "_knv(" AMP, ""); char v[8], buf[512]; int i, l; string dv, st, next; sprintf(v, "_v%c%d", LVAC, n); dv = make_decl(T_ATOM, v); for (i = 0, st = f->code; ; st = next + 1) { next = strchr(st, NSTC); l = next ? next - st : strlen(st); strncpy(buf + i, st, l); i += l; strcpy(buf + i, ", "); i += 2; if (!next) break; } strcpy(buf + i, "NULL)"); i += 5; fc->decls = cons(dv, fc->decls); return merge_frames(T_CBOOL, T_UNKNOWN, fc, NULL, fc->cl + i + 9, fc->code, v, ", ", buf, ""); }
static struct vector *decls(declfun_p * dcl) { struct vector *v = vec_new(); node_t *basety; int sclass, fspec; int level = SCOPE; int follow[] = {STATIC, INT, CONST, IF, '}', 0}; basety = specifiers(&sclass, &fspec); if (token->id == ID || token->id == '*' || token->id == '(') { struct token *id = NULL; node_t *ty = NULL; int params = 0; // for functioness // declarator if (level == GLOBAL) declarator(&ty, &id, ¶ms); else declarator(&ty, &id, NULL); attach_type(&ty, basety); if (level == GLOBAL && params) { if (first_funcdef(ty)) { vec_push(v, funcdef(id, ty, sclass, fspec)); return v; } else { exit_params(); } } for (;;) { if (id) { int kind; if (dcl == globaldecl) kind = GLOBAL; else if (dcl == paramdecl) kind = PARAM; else kind = LOCAL; node_t *decl = make_decl(id, ty, sclass, fspec, dcl); if (token->id == '=') decl_initializer(decl, sclass, kind); ensure_decl(decl, sclass, kind); vec_push(v, decl); } if (token->id != ',') break; expect(','); id = NULL; ty = NULL; // declarator declarator(&ty, &id, NULL); attach_type(&ty, basety); } } else if (isenum(basety) || isstruct(basety) || isunion(basety)) { // struct/union/enum int node_id; node_t *decl; if (isstruct(basety)) node_id = STRUCT_DECL; else if (isunion(basety)) node_id = UNION_DECL; else node_id = ENUM_DECL; decl = ast_decl(node_id); DECL_SYM(decl) = TYPE_TSYM(basety); vec_push(v, decl); } else { error("invalid token '%s' in declaration", token->name); } match(';', follow); return v; }