?? soapcpp2.y
字號:
} | aexp ;obex : oexp { $$ = $1; } ;/* aexp : and-expression */aexp : abex AN rexp { $$.hasval = False; $$.typ = mkint(); } | rexp ;abex : aexp { $$ = $1; } ;/* rexp : relational expression */rexp : rexp '|' rexp { $$ = iop("|", $1, $3); } | rexp '^' rexp { $$ = iop("^", $1, $3); } | rexp '&' rexp { $$ = iop("&", $1, $3); } | rexp EQ rexp { $$ = relop("==", $1, $3); } | rexp NE rexp { $$ = relop("!=", $1, $3); } | rexp '<' rexp { $$ = relop("<", $1, $3); } | rexp LE rexp { $$ = relop("<=", $1, $3); } | rexp '>' rexp { $$ = relop(">", $1, $3); } | rexp GE rexp { $$ = relop(">=", $1, $3); } | rexp LS rexp { $$ = iop("<<", $1, $3); } | rexp RS rexp { $$ = iop(">>", $1, $3); } | rexp '+' rexp { $$ = op("+", $1, $3); } | rexp '-' rexp { $$ = op("-", $1, $3); } | rexp '*' rexp { $$ = op("*", $1, $3); } | rexp '/' rexp { $$ = op("/", $1, $3); } | rexp '%' rexp { $$ = iop("%", $1, $3); } | lexp ;/* lexp : lvalue kind of expression with optional prefix contructs */lexp : '!' lexp { if ($2.hasval) $$.val.i = !$2.val.i; $$.typ = $2.typ; $$.hasval = $2.hasval; } | '~' lexp { if ($2.hasval) $$.val.i = ~$2.val.i; $$.typ = $2.typ; $$.hasval = $2.hasval; } | '-' lexp { if ($2.hasval) { if (integer($2.typ)) $$.val.i = -$2.val.i; else if (real($2.typ)) $$.val.r = -$2.val.r; else typerror("string?"); } $$.typ = $2.typ; $$.hasval = $2.hasval; } | '+' lexp { $$ = $2; } | '*' lexp { if ($2.typ->type == Tpointer) { $$.typ = (Tnode*) $2.typ->ref; } else typerror("dereference of non-pointer type"); $$.sto = Snone; $$.hasval = False; } | '&' lexp { $$.typ = mkpointer($2.typ); $$.sto = Snone; $$.hasval = False; } | SIZEOF '(' texp ')' { $$.hasval = True; $$.typ = mkint(); $$.val.i = $3.typ->width; } | pexp ;/* pexp : primitive expression with optional postfix constructs */pexp : '(' expr ')' { $$ = $2; } | ID { if ((p = enumentry($1)) == (Entry*) 0) p = undefined($1); else $$.hasval = True; $$.typ = p->info.typ; $$.val = p->info.val; } | LNG { $$.typ = mkint(); $$.hasval = True; $$.val.i = $1; } | DBL { $$.typ = mkfloat(); $$.hasval = True; $$.val.r = $1; } | CHR { $$.typ = mkchar(); $$.hasval = True; $$.val.i = $1; } | STR { $$.typ = mkstring(); $$.hasval = True; $$.val.s = $1; } | CFALSE { $$.typ = mkbool(); $$.hasval = True; $$.val.i = 0; } | CTRUE { $$.typ = mkbool(); $$.hasval = True; $$.val.i = 1; } ;%%/* * ??? */intyywrap(){ return 1;}/******************************************************************************\ Support routines\******************************************************************************/static Nodeop(const char *op, Node p, Node q){ Node r; Tnode *typ; r.typ = p.typ; r.sto = Snone; if (p.hasval && q.hasval) { if (integer(p.typ) && integer(q.typ)) switch (op[0]) { case '|': r.val.i = p.val.i | q.val.i; break; case '^': r.val.i = p.val.i ^ q.val.i; break; case '&': r.val.i = p.val.i & q.val.i; break; case '<': r.val.i = p.val.i << q.val.i; break; case '>': r.val.i = p.val.i >> q.val.i; break; case '+': r.val.i = p.val.i + q.val.i; break; case '-': r.val.i = p.val.i - q.val.i; break; case '*': r.val.i = p.val.i * q.val.i; break; case '/': r.val.i = p.val.i / q.val.i; break; case '%': r.val.i = p.val.i % q.val.i; break; default: typerror(op); } else if (real(p.typ) && real(q.typ)) switch (op[0]) { case '+': r.val.r = p.val.r + q.val.r; break; case '-': r.val.r = p.val.r - q.val.r; break; case '*': r.val.r = p.val.r * q.val.r; break; case '/': r.val.r = p.val.r / q.val.r; break; default: typerror(op); } else semerror("illegal constant operation"); r.hasval = True; } else { typ = mgtype(p.typ, q.typ); r.hasval = False; } return r;}static Nodeiop(const char *iop, Node p, Node q){ if (integer(p.typ) && integer(q.typ)) return op(iop, p, q); typerror("integer operands only"); return p;}static Noderelop(const char *op, Node p, Node q){ Node r; Tnode *typ; r.typ = mkint(); r.sto = Snone; r.hasval = False; if (p.typ->type != Tpointer || p.typ != q.typ) typ = mgtype(p.typ, q.typ); return r;}/******************************************************************************\ Scope management\******************************************************************************//*mkscope - initialize scope stack with a new table and offset*/static voidmkscope(Table *table, int offset){ sp = stack-1; enterscope(table, offset);}/*enterscope - enter a new scope by pushing a new table and offset on the stack*/static voidenterscope(Table *table, int offset){ if (++sp == stack+MAXNEST) execerror("maximum scope depth exceeded"); sp->table = table; sp->val = 0; sp->offset = offset; sp->grow = True; /* by default, offset grows */ sp->mask = False;}/*exitscope - exit a scope by popping the table and offset from the stack*/static voidexitscope(){ check(sp-- != stack, "exitscope() has no matching enterscope()");}/******************************************************************************\ Undefined symbol\******************************************************************************/static Entry*undefined(Symbol *sym){ Entry *p; sprintf(errbuf, "undefined identifier `%s'", sym->name); semwarn(errbuf); p = enter(sp->table, sym); p->level = GLOBAL; p->info.typ = mkint(); p->info.sto = Sextern; p->info.hasval = False; return p;}/*mgtype - return most general type among two numerical types*/Tnode*mgtype(Tnode *typ1, Tnode *typ2){ if (numeric(typ1) && numeric(typ2)) { if (typ1->type < typ2->type) return typ2; } else typerror("non-numeric type"); return typ1;}/******************************************************************************\ Type checks\******************************************************************************/static intinteger(Tnode *typ){ switch (typ->type) { case Tchar: case Tshort: case Tint: case Tlong: return True; } return False;}static intreal(Tnode *typ){ switch (typ->type) { case Tfloat: case Tdouble: return True; } return False;}static intnumeric(Tnode *typ){ return integer(typ) || real(typ);}static intpointer(Tnode *typ){ return typ->type == Tpointer;}static voidadd_fault(Table *gt){ Table *t; Entry *p; Symbol *s = lookup("SOAP_ENV__Fault"); p = entry(classtable, s); if (!p) { t = mktable((Table*)0); p = enter(t, lookup("faultcode")); p->info.typ = mkstring(); p = enter(t, lookup("faultstring")); p->info.typ = mkstring(); p = enter(t, lookup("faultactor")); p->info.typ = mkstring(); p = enter(t, lookup("detail")); p->info.typ = mkstring(); p = enter(classtable, s); p->info.typ = mkstruct(t, 16); p->info.typ->id = s; custom_fault = 0; }}static voidadd_header(Table *gt){ Table *t; Entry *p; Symbol *s = lookup("SOAP_ENV__Header"); p = entry(classtable, s); if (!p) { t = mktable((Table*)0); p = enter(t, lookup("dummy")); p->info.typ = mkpointer(mkvoid()); p = enter(classtable, s); p->info.typ = mkstruct(t, 4); p->info.typ->id = s; custom_header = 0; }}static voidadd_response(Entry *fun, Entry *ret){ Table *t; Entry *p, *q; Symbol *s; int n = strlen(fun->sym->name); char *r = (char*)emalloc(n+9); strcpy(r, fun->sym->name); strcat(r, "Response"); if (!(s = lookup(r))) s = install(r, ID); free(r); t = mktable((Table*)0); q = enter(t, ret->sym); q->info = ret->info; if (q->info.typ->type == Treference) q->info.typ = (Tnode*)q->info.typ->ref; p = enter(classtable, s); p->info.typ = mkstruct(t, 4); p->info.typ->id = s; fun->info.typ->response = p;}/*dumptbl(Table *t){ Entry *p; fprintf(stderr, " (level %d) ", t->level); for (p = t->list; p; p = p->next) { switch (p->info.sto) { case Sregister: fprintf(stderr, "register "); break; case Sstatic: fprintf(stderr, "static "); break; case Sextern: fprintf(stderr, "extern "); break; case Stypedef: fprintf(stderr, "typedef "); } dumptyp(p->info.typ); fprintf(stderr, " %s=%d (%d)", p->sym->name, p->info.val.i, p->lineno); } if (t->prev) { fprintf(stderr, "##(linked to table:##\n"); dumptbl(t->prev); fprintf(stderr, ")"); }}*//*char *dumptyp(Tnode *p){ char *s; switch (p->type) { case Tvoid: return "void"); case Tchar: return "char"; case Tshort: return "short"; case Tint: return "int"; case Tlong: return "long"; case Tllong: return "LONG64"; case Tfloat: return "float"; case Tdouble: return "double"; case Tuchar: return "unsigned char"; case Tushort: return "unsigned short"; case Tuint: return "unsigned int"; case Tulong: return "unsigned long"; case Tullong: return "ULONG64"; case Tenum: s = (char*)emalloc(strlen(p->id->name)+6); strcpy(s, "enum "); return strcat(s, p->id->name); case Tclass: return p->id->name; break; case Tstruct: s = (char*)emalloc(strlen(p->id->name)+8); strcpy(s, "struct "); return strcat(s, p->id->name); case Tunion: s = (char*)emalloc(strlen(p->id->name)+8); strcpy(s, "union "); return strcat(s, p->id->name); case Tpointer: dumptyp(p->ref); fprintf(stderr, "*"); break; case Tarray: fprintf(stderr, "[%d]", p->width/((Tnode*)p->ref)->width); break; case Tfun: if (p->ref) { fprintf(stderr, "int("); dumptyp(p->ref); fprintf(stderr, ")"); } else fprintf(stderr, "int()"); break; }}*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -