static int doglobal(char *pre, int dowhat) { Ordered *walk; Symbol *sp; int j, cnt = 0; for (j = 0; j < 8; j++) for (walk = all_names; walk; walk = walk->next) { sp = walk->entry; if (!sp->context && !sp->owner && sp->type == Types[j]) { if (Types[j] != MTYPE || !ismtype(sp->name)) switch (dowhat) { case LOGV: if (sp->type == CHAN && verbose == 0) break; if (sp->hidden&1) break; do_var(tc, dowhat, "", sp, pre, "\", now.", ");\n"); break; case INIV: checktype(sp, (char *) 0); cnt++; /* fall through */ case PUTV: do_var(tc, dowhat, (sp->hidden&1)?"":"now.", sp, "", " = ", ";\n"); break; } } } return cnt; }
void c_wrapper(FILE *fd) /* allow pan.c to print out global sv entries */ { Ordered *walk; ProcList *p; Symbol *sp; Lextok *n; extern Lextok *Mtype; int j; fprintf(fd, "void\nc_globals(void)\n{\t/* int i; */\n"); fprintf(fd, " printf(\"global vars:\\n\");\n"); for (walk = all_names; walk; walk = walk->next) { sp = walk->entry; if (sp->context || sp->owner || (sp->hidden&1) || (sp->type == MTYPE && ismtype(sp->name))) continue; c_var(fd, "now.", sp); } fprintf(fd, "}\n"); fprintf(fd, "void\nc_locals(int pid, int tp)\n{\t/* int i; */\n"); fprintf(fd, " switch(tp) {\n"); for (p = rdy; p; p = p->nxt) { fprintf(fd, " case %d:\n", p->tn); fprintf(fd, " \tprintf(\"local vars proc %%d (%s):\\n\", pid);\n", p->n->name); if (c_splurge_any(p)) { fprintf(fd, " \tprintf(\"local vars proc %%d (%s):\\n\", pid);\n", p->n->name); c_splurge(fd, p); } else { fprintf(fd, " \t/* none */\n"); } fprintf(fd, " \tbreak;\n"); } fprintf(fd, " }\n}\n"); fprintf(fd, "void\nprintm(int x)\n{\n"); fprintf(fd, " switch (x) {\n"); for (n = Mtype, j = 1; n && j; n = n->rgt, j++) fprintf(fd, "\tcase %d: Printf(\"%s\"); break;\n", j, n->lft->sym->name); fprintf(fd, " default: Printf(\"%%d\", x);\n"); fprintf(fd, " }\n"); fprintf(fd, "}\n"); }
int c_splurge_any(ProcList *p) { Ordered *walk; Symbol *sp; if (strcmp(p->n->name, ":never:") != 0 && strcmp(p->n->name, ":trace:") != 0 && strcmp(p->n->name, ":notrace:") != 0) for (walk = all_names; walk; walk = walk->next) { sp = walk->entry; if (!sp->context || sp->type == 0 || strcmp(sp->context->name, p->n->name) != 0 || sp->owner || (sp->hidden&1) || (sp->type == MTYPE && ismtype(sp->name))) continue; return 1; } return 0; }
void c_splurge(FILE *fd, ProcList *p) { Ordered *walk; Symbol *sp; char pref[64]; if (strcmp(p->n->name, ":never:") != 0 && strcmp(p->n->name, ":trace:") != 0 && strcmp(p->n->name, ":notrace:") != 0) for (walk = all_names; walk; walk = walk->next) { sp = walk->entry; if (!sp->context || sp->type == 0 || strcmp(sp->context->name, p->n->name) != 0 || sp->owner || (sp->hidden&1) || (sp->type == MTYPE && ismtype(sp->name))) continue; sprintf(pref, "((P%d *)pptr(pid))->", p->tn); c_var(fd, pref, sp); } }
static int check_name(char *s) { int i; yylval = nn(ZN, 0, ZN, ZN); if (ltl_mode) { for (i = 0; LTL_syms[i].s; i++) { if (strcmp(s, LTL_syms[i].s) == 0) { return LTL_syms[i].tok; } } } for (i = 0; Names[i].s; i++) { if (strcmp(s, Names[i].s) == 0) { yylval->val = Names[i].val; if (Names[i].sym) yylval->sym = lookup(Names[i].sym); if (Names[i].tok == IN && !in_for) { continue; } return Names[i].tok; } } if ((yylval->val = ismtype(s)) != 0) { yylval->ismtyp = 1; return CONST; } if (strcmp(s, "_last") == 0) has_last++; if (strcmp(s, "_priority") == 0) has_priority++; if (Inlining >= 0 && !ReDiRect) { Lextok *tt, *t = Inline_stub[Inlining]->params; for (i = 0; t; t = t->rgt, i++) /* formal pars */ if (!strcmp(s, t->lft->sym->name) /* varname matches formal */ && strcmp(s, Inline_stub[Inlining]->anms[i]) != 0) /* actual pars */ { #if 0 if (verbose&32) printf("\tline %d, replace %s in call of '%s' with %s\n", lineno, s, Inline_stub[Inlining]->nm->name, Inline_stub[Inlining]->anms[i]); #endif for (tt = Inline_stub[Inlining]->params; tt; tt = tt->rgt) if (!strcmp(Inline_stub[Inlining]->anms[i], tt->lft->sym->name)) { /* would be cyclic if not caught */ printf("spin: %s:%d replacement value: %s\n", oFname->name?oFname->name:"--", lineno, tt->lft->sym->name); fatal("formal par of %s contains replacement value", Inline_stub[Inlining]->nm->name); yylval->ntyp = tt->lft->ntyp; yylval->sym = lookup(tt->lft->sym->name); return NAME; } /* check for occurrence of param as field of struct */ { char *ptr = Inline_stub[Inlining]->anms[i]; while ((ptr = strstr(ptr, s)) != NULL) { if (*(ptr-1) == '.' || *(ptr+strlen(s)) == '.') { fatal("formal par of %s used in structure name", Inline_stub[Inlining]->nm->name); } ptr++; } } ReDiRect = Inline_stub[Inlining]->anms[i]; return 0; } } yylval->sym = lookup(s); /* symbol table */ if (isutype(s)) return UNAME; if (isproctype(s)) return PNAME; if (iseqname(s)) return INAME; return NAME; }