#include "c.h"
#include "token.h"
Include dependency graph for expr.c:

Go to the source code of this file.
Defines | |
| #define | xx(t) if (xty == t || yty == t) return t |
| #define | xx(a, b, c, d, e, f, g) d, |
| #define | xx(a, b, c, d, e, f, g) c, |
| #define | yy(a, b, c, d, e, f, g) d, |
| #define | yy(a, b, c, d, e, f, g) c, |
Functions | |
| Type | binary (Type xty, Type yty) |
| Tree | cast (Tree p, Type type) |
| Tree | cond (Tree p) |
| Tree | expr (int tok) |
| Tree | expr0 (int tok) |
| Tree | expr1 (int tok) |
| Tree | expr2 (void) |
| Tree | expr3 (int) |
| Tree | field (Tree p, const char *name) |
| char * | funcname (Tree f) |
| int | hascall (Tree p) |
| Tree | idtree (Symbol p) |
| Tree | incr (int op, Tree v, Tree e) |
| Tree | lvalue (Tree p) |
| Tree | nullcall (Type pty, Symbol f, Tree p, Tree e) |
| Tree | nullcheck (Tree) |
| Tree | pointer (Tree p) |
| Tree | postfix (Tree) |
| Tree | primary (void) |
| Tree | retype (Tree p, Type ty) |
| Tree | rightkid (Tree p) |
| Tree | rvalue (Tree p) |
| Type | super (Type ty) |
| Tree | unary (void) |
| Tree | value (Tree p) |
Variables | |
| int | oper [] |
| char | prec [] |
| float | refinc = 1.0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||||||||
|
|
|
||||||||||||
|
Definition at line 797 of file expr.c. Referenced by calltree(), cmp(), condtree(), initializer(), initvalue(), intexpr(), listnodes(), retcode(), simplify(), statement(), swcode(), swstmt(), and tracevalue(). |
|
|
Definition at line 787 of file expr.c. Referenced by addd(), addi(), conditional(), divd(), divi(), lookup(), muld(), muli(), and simplify(). |
|
|
Definition at line 306 of file expr.c. Referenced by conditional(), statement(), and swstmt(). 00307 : t = gettok(); 00308 if (t == ID) { 00309 if (isstruct(p->type)) { 00310 Tree q = addrof(p); 00311 p = field(q, token); 00312 q = rightkid(q); 00313 if (isaddrop(q->op) && q->u.sym->temporary) 00314 p = tree(RIGHT, p->type, p, NULL); 00315 } else 00316 error("left operand of . has incompatible type `%t'\n", 00317 p->type); 00318 t = gettok(); 00319 } else
|
|
|
Definition at line 320 of file expr.c. Referenced by forstmt(), and statement().
|
|
|
Definition at line 323 of file expr.c. References error(), field(), gettok(), isptr, isstruct, nullcheck(), p, t, type::type, and tree::type. Referenced by constexpr(), dcllocal(), dclparam(), initializer(), and initvalue(). 00323 {
00324 if (isptr(p->type) && isstruct(p->type->type)) {
00325 if (YYnull)
00326 p = nullcheck(p);
00327 p = field(p, token);
00328 } else
00329 error("left operand of -> has incompatible type `%t'\n", p->type);
00330
00331 t = gettok();
00332 } else
00333 error("field name expected\n"); break;
00334 default:
00335 return p;
00336 }
00337 }
00338 static Tree primary(void) {
00339 Tree p;
00340
00341 assert(t != '(');
00342 switch (t) {
00343 case ICON:
|
Here is the call graph for this function:

|
|
Definition at line 347 of file expr.c. References Aflag, ID, p, q, SCON, Symbol, and tsym. 00347 : if (ischar(tsym->type->type)) 00348 tsym->u.c.v.p = stringn(tsym->u.c.v.p, tsym->type->size); 00349 else 00350 tsym->u.c.v.p = memcpy(allocate(tsym->type->size, PERM), tsym->u.c.v.p, tsym->type->size); 00351 tsym = constant(tsym->type, tsym->u.c.v); 00352 if (tsym->u.c.loc == NULL) 00353 tsym->u.c.loc = genident(STATIC, tsym->type, GLOBAL); 00354 p = idtree(tsym->u.c.loc); break; 00355 case ID: if (tsym == NULL) 00356 { 00357 Symbol p = install(token, &identifiers, level, FUNC); 00358 p->src = src; 00359 if (getchr() == '(') { 00360 Symbol q = lookup(token, externals); 00361 p->type = func(inttype, NULL, 1); 00362 p->sclass = EXTERN; 00363 if (Aflag >= 1) 00364 warning("missing prototype\n"); 00365 if (q && !eqtype(q->type, p->type, 1)) 00366 warning("implicit declaration of `%s' does not match previous declaration at %w\n", q->name, &q->src); 00367 00368 if (q == NULL) { 00369 q = install(p->name, &externals, GLOBAL, PERM); 00370 q->type = p->type;
|
|
|
Definition at line 381 of file expr.c. References IR. 00394 {
00395 if (tsym->sclass == TYPEDEF)
00396 error("illegal use of type name `%s'\n", tsym->name);
00397 p = idtree(tsym);
00398 } break;
00399 case FIRSTARG:
00400 if (level > PARAM && cfunc && cfunc->u.f.callee[0])
00401 p = idtree(cfunc->u.f.callee[0]);
00402 else {
|
|
||||||||||||
|
Definition at line 901 of file expr.c. Referenced by expr1(), MSG_ReadDeltaEntity(), MSG_ReadDeltaPlayerstate(), MSG_WriteDeltaEntity(), MSG_WriteDeltaPlayerstate(), tracevalue(), and uid2type(). |
|
|
Definition at line 943 of file expr.c. Referenced by conditional(), NameToAFunc(), and NameToGenFunc(). |
|
|
|
|
|
Definition at line 682 of file expr.c. References cnsttree(), p, Symbol, and YYnull. Referenced by bbcall(), bbentry(), bbexit(), bbincr(), cmp(), cvtconst(), dcllocal(), gencode(), listnodes(), retcode(), swcode(), tracecall(), tracefinis(), tracereturn(), and tracevalue(). 00683 {
00684 Symbol t1 = temporary(REGISTER, voidptype);
00685 p = tree(RIGHT, p->type,
00686 tree(OR, voidtype,
00687 cond(asgn(t1, cast(p, voidptype))),
00688 vcall(YYnull, voidtype, (file && *file ? pointer(idtree(mkstr(file)->u.c.loc)) : cnsttree(voidptype, NULL)), cnsttree(inttype, (long)lineno) , NULL)),
00689 idtree(t1));
00690 }
00691
00692 else
00693 p = nullcall(p->type, YYnull, p, cnsttree(inttype, 0L));
00694
00695 }
00696 return p;
00697 }
00698 Tree nullcall(Type pty, Symbol f, Tree p, Tree e) {
00699 Type ty;
00700
00701 if (isarray(pty))
00702 return retype(nullcall(atop(pty), f, p, e), pty);
00703 ty = unqual(unqual(p->type)->type);
00704 return vcall(f, pty,
00705 p, e,
00706 cnsttree(inttype, (long)ty->size),
00707 cnsttree(inttype, (long)ty->align),
00708 (file && *file ? pointer(idtree(mkstr(file)->u.c.loc)) : cnsttree(voidptype, NULL)), cnsttree(inttype, (long)lineno) , NULL);
00709 }
00710 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 344 of file expr.c. Referenced by bbincr(), and tracecall(). 00344 : p = tree(mkop(CNST,tsym->type), tsym->type, NULL, NULL); 00345 p->u.v = tsym->u.c.v; 00346 break;
|
|
|
Definition at line 722 of file expr.c. Referenced by listnodes(). |
|
||||||||||||||||||||
|
|
|
|
Definition at line 948 of file expr.c. Referenced by expr1(). |
|
|
Definition at line 779 of file expr.c. Referenced by bbentry(), bbexit(), bbincr(), initializer(), retcode(), swcode(), tracefinis(), and tracevalue(). |
|
|
Definition at line 530 of file expr.c. References ENUM, FLOAT, INT, inttype, p, POINTER, src, Type, UNSIGNED, and unsignedtype. 00537 {
00538 switch (src->op) {
00539 case INT:
00540 if (src->size < inttype->size)
00541 p = simplify(CVI, inttype, p, NULL);
00542 break;
00543 case UNSIGNED:
00544 if (src->size < inttype->size)
00545 p = simplify(CVU, inttype, p, NULL);
00546 else if (src->size < unsignedtype->size)
00547 p = simplify(CVU, unsignedtype, p, NULL);
00548 break;
00549 case ENUM:
00550 p = retype(p, inttype);
00551 break;
00552 case POINTER:
00553 if (isint(dst) && src->size > dst->size)
00554 warning("conversion from `%t' to `%t' is undefined\n", p->type, type);
00555 p = simplify(CVP, super(src), p, NULL);
00556 break;
00557 case FLOAT:
00558 break;
00559 default: assert(0);
00560 }
00561 {
00562 src = unqual(p->type);
00563 dst = super(dst);
00564 if (src->op != dst->op)
00565 switch (src->op) {
00566 case INT:
00567 p = simplify(CVI, dst, p, NULL);
00568 break;
00569 case UNSIGNED:
00570 if (isfloat(dst)) {
00571 Type ssrc = signedint(src);
00572 Tree two = cnsttree(longdouble, (long double)2.0);
00573 p = (*optree['+'])(ADD,
00574 (*optree['*'])(MUL,
00575 two,
00576 simplify(CVU, ssrc,
00577 simplify(RSH, src,
00578 p, consttree(1, inttype)), NULL)),
00579 simplify(CVU, ssrc,
00580 simplify(BAND, src,
00581 p, consttree(1, unsignedtype)), NULL));
00582 } else
00583 p = simplify(CVU, dst, p, NULL);
00584 break;
00585 case FLOAT:
00586 if (isunsigned(dst)) {
00587 Type sdst = signedint(dst);
00588 Tree c = cast(cnsttree(longdouble, (long double)sdst->u.sym->u.limits.max.i + 1), src);
00589 p = condtree(
00590 simplify(GE, src, p, c),
00591 (*optree['+'])(ADD,
00592 cast(cast(simplify(SUB, src, p, c), sdst), dst),
00593 cast(cnsttree(unsignedlong, (unsigned long)sdst->u.sym->u.limits.max.i + 1), dst)),
00594 simplify(CVF, sdst, p, NULL));
00595 } else
00596 p = simplify(CVF, dst, p, NULL);
00597 break;
00598 default: assert(0);
00599 }
00600 dst = unqual(type);
00601 }
00602 }
00603 src = unqual(p->type);
00604 switch (src->op) {
00605 case INT:
|
|
|
Definition at line 606 of file expr.c. References FLOAT, p, POINTER, src, and UNSIGNED. 00609 : 00610 if (src->op != dst->op || src->size != dst->size) 00611 p = simplify(CVU, dst, p, NULL); 00612 break; 00613 case FLOAT: 00614 if (src->op != dst->op || src->size != dst->size) 00615 p = simplify(CVF, dst, p, NULL); 00616 break; 00617 case POINTER: 00618 if (src->op != dst->op) 00619 p = simplify(CVP, dst, p, NULL); 00620 else { 00621 if (isfunc(src->type) && !isfunc(dst->type) 00622 || !isfunc(src->type) && isfunc(dst->type)) 00623 warning("conversion from `%t' to `%t' is compiler dependent\n", p->type, type); 00624 00625 if (src->size != dst->size) 00626 p = simplify(CVP, dst, p, NULL); 00627 } 00628 break; 00629 default: assert(0); 00630 } 00631 return retype(p, type); 00632 } 00633 Tree field(Tree p, const char *name) { 00634 Field q; 00635 Type ty1, ty = p->type; 00636 00637 if (isptr(ty)) 00638 ty = deref(ty); 00639 ty1 = ty; 00640 ty = unqual(ty); 00641 if ((q = fieldref(name, ty)) != NULL) { 00642 if (isarray(q->type)) { 00643 ty = q->type->type; 00644 if (isconst(ty1) && !isconst(ty)) 00645 ty = qual(CONST, ty); 00646 if (isvolatile(ty1) && !isvolatile(ty)) 00647 ty = qual(VOLATILE, ty); 00648 ty = array(ty, q->type->size/ty->size, q->type->align); 00649 } else { 00650 ty = q->type; 00651 if (isconst(ty1) && !isconst(ty)) 00652 ty = qual(CONST, ty); 00653 if (isvolatile(ty1) && !isvolatile(ty)) 00654 ty = qual(VOLATILE, ty); 00655 ty = ptr(ty); 00656 } 00657 if (YYcheck && !isaddrop(p->op) && q->offset > 0) /* omit */ 00658 p = nullcall(ty, YYcheck, p, consttree(q->offset, inttype)); /* omit */ 00659 else /* omit */ 00660 p = simplify(ADD+P, ty, p, consttree(q->offset, inttype)); 00661 00662 if (q->lsb) { 00663 p = tree(FIELD, ty->type, rvalue(p), NULL); 00664 p->u.field = q; 00665 } else if (!isarray(q->type)) 00666 p = rvalue(p); 00667 00668 } else { 00669 error("unknown field `%s' of `%t'\n", name, ty); 00670 p = rvalue(retype(p, ptr(inttype))); 00671 } 00672 return p; 00673 } 00674 /* funcname - return name of function f or a function' */ 00675 char *funcname(Tree f) { 00676 if (isaddrop(f->op)) 00677 return stringf("`%s'", f->u.sym->name); 00678 return "a function"; 00679 } 00680 static Tree nullcheck(Tree p) { 00681 if (!needconst && YYnull && isptr(p->type)) { p = value(p);
|
|
||||||||||||
|
Definition at line 730 of file expr.c. Referenced by initvalue(), simplify(), swstmt(), and tracevalue(). |
|
|
|
|
|
Definition at line 716 of file expr.c. Referenced by bbincr(), listnodes(), retcode(), swcode(), and tracevalue(). |
|
|
Definition at line 291 of file expr.c. 00292 : {
00293 Type ty;
00294 Coordinate pt;
00295 p = pointer(p);
00296 if (isptr(p->type) && isfunc(p->type->type))
00297 ty = p->type->type;
00298 else {
00299 error("found `%t' expected a function\n", p->type);
00300 ty = func(voidtype, NULL, 1);
00301 p = retype(p, ptr(ty));
00302 }
00303 pt = src;
00304 t = gettok();
00305 p = call(p, ty, pt);
|
|
|
Definition at line 403 of file expr.c. References p. 00407 : 00408 error("illegal expression\n"); 00409 p = cnsttree(inttype, 0L); 00410 } 00411 t = gettok(); 00412 return p; 00413 } 00414 Tree idtree(Symbol p) { 00415 int op; 00416 Tree e; 00417 Type ty = p->type ? unqual(p->type) : voidptype; 00418 00419 if (p->scope == GLOBAL || p->sclass == STATIC) 00420 op = ADDRG; 00421 else if (p->scope == PARAM) { 00422 op = ADDRF; 00423 if (isstruct(p->type) && !IR->wants_argb) 00424 { 00425 e = tree(mkop(op,voidptype), ptr(ptr(p->type)), NULL, NULL); 00426 e->u.sym = p; 00427 return rvalue(rvalue(e)); 00428 } 00429 } else if (p->sclass == EXTERN) { 00430 assert(p->u.alias); 00431 p = p->u.alias; 00432 op = ADDRG; 00433 } else 00434 op = ADDRL; 00435 p->ref += refinc; 00436 if (isarray(ty)) 00437 e = tree(mkop(op,voidptype), p->type, NULL, NULL); 00438 else if (isfunc(ty)) 00439 e = tree(mkop(op,funcptype), p->type, NULL, NULL); 00440 else 00441 e = tree(mkop(op,voidptype), ptr(p->type), NULL, NULL); 00442 e->u.sym = p; 00443 if (isptr(e->type)) 00444 e = rvalue(e); 00445 return e; 00446 } 00447 00448 Tree rvalue(Tree p) { 00449 Type ty = deref(p->type); 00450 00451 ty = unqual(ty); 00452 return tree(mkop(INDIR,ty), ty, p, NULL); 00453 } 00454 Tree lvalue(Tree p) { 00455 if (generic(p->op) != INDIR) { 00456 error("lvalue required\n"); 00457 return value(p); 00458 } else if (unqual(p->type) == voidtype) 00459 warning("`%t' used as an lvalue\n", p->type); 00460 return p->kids[0]; 00461 } 00462 Tree retype(Tree p, Type ty) { 00463 Tree q; 00464 00465 if (p->type == ty) 00466 return p; 00467 q = tree(p->op, ty, p->kids[0], p->kids[1]); 00468 q->node = p->node; 00469 q->u = p->u; 00470 return q; 00471 } 00472 Tree rightkid(Tree p) { 00473 while (p && p->op == RIGHT) 00474 if (p->kids[1]) 00475 p = p->kids[1]; 00476 else if (p->kids[0]) 00477 p = p->kids[0]; 00478 else 00479 assert(0); 00480 assert(p); 00481 return p; 00482 } 00483 int hascall(Tree p) { 00484 if (p == 0) 00485 return 0; 00486 if (generic(p->op) == CALL || (IR->mulops_calls && 00487 (p->op == DIV+I || p->op == MOD+I || p->op == MUL+I 00488 || p->op == DIV+U || p->op == MOD+U || p->op == MUL+U))) 00489 return 1; 00490 return hascall(p->kids[0]) || hascall(p->kids[1]); 00491 } 00492 Type binary(Type xty, Type yty) { 00493 #define xx(t) if (xty == t || yty == t) return t 00494 xx(longdouble); 00495 xx(doubletype); 00496 xx(floattype); 00497 xx(unsignedlonglong); 00498 xx(longlong); 00499 xx(unsignedlong); 00500 if (xty == longtype && yty == unsignedtype 00501 || xty == unsignedtype && yty == longtype) 00502 if (longtype->size > unsignedtype->size) 00503 return longtype; 00504 else 00505 return unsignedlong; 00506 xx(longtype); 00507 xx(unsignedtype); 00508 return inttype; 00509 #undef xx 00510 } 00511 Tree pointer(Tree p) { 00512 if (isarray(p->type)) 00513 /* assert(p->op != RIGHT || p->u.sym == NULL), */ 00514 p = retype(p, atop(p->type)); 00515 else if (isfunc(p->type)) 00516 p = retype(p, ptr(p->type)); 00517 return p; 00518 } 00519 Tree cond(Tree p) { 00520 int op = generic(rightkid(p)->op); 00521 00522 if (op == AND || op == OR || op == NOT 00523 || op == EQ || op == NE 00524 || op == LE || op == LT || op == GE || op == GT) 00525 return p; 00526 p = pointer(p); 00527 return (*optree[NEQ])(NE, p, consttree(0, inttype)); 00528 } Tree cast(Tree p, Type type) {
|
|
|
Definition at line 371 of file expr.c. 00376 {
00377 error("undeclared identifier `%s'\n", p->name);
00378 p->sclass = AUTO;
00379 p->type = inttype;
00380 if (p->scope == GLOBAL)
|
|
|
|
|
|
|
|
|
Definition at line 282 of file expr.c. Referenced by definept(), dostmt(), forstmt(), funcdefn(), ifstmt(), statement(), swstmt(), and whilestmt(). |
1.3.9.1