scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit c1768b2e370906fc8418bc26cd69d88529c8c96b
parent a512be02d9c534110deafcce1e73f452a0fa9068
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 14 Apr 2014 10:21:52 +0200

Move ary2ptr to addr2ptr

The name of a function is a pointer of that function, so it
can appear in differnt places, and the action that we have
to take in that case is the same of arrays moved into
pointers, so we can abstract them and think we are
generating a pointer from and address.

Diffstat:
Mexpr.c | 17+++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/expr.c b/expr.c @@ -38,7 +38,7 @@ bitlogic(char op, Node *np1, Node *np2) } static Node * -ary2ptr(Node *np) +addr2ptr(Node *np) { Type *tp; @@ -71,7 +71,9 @@ convert(Node *np, Type *tp1) case PTR: switch (t2) { case ARY: case FTN: - /* TODO: take address of np */; + np = addr2ptr(np); + np->type = tp1; + return np; } } return NULL; @@ -120,7 +122,7 @@ arithmetic(char op, Node *np1, Node *np2) } break; case ARY: - np1 = ary2ptr(np1); + np1 = addr2ptr(np1); tp1 = np1->type; case PTR: pointer: @@ -188,11 +190,10 @@ compare(char op, Node *np1, Node *np2) defualt: goto incompatibles; } - case ARY: - np1 = ary2ptr(np1); + case ARY: case FTN: + np1 = addr2ptr(np1); + tp1 = UNQUAL(np1->type); break; - case FTN: - /* TODO: cover this cases */ case PTR: if (tp1 != tp2) goto incompatibles; @@ -353,7 +354,7 @@ cast(void) tp = typename(); expect(')'); np1 = cast(); - if ((np2 = convert(np2, tp)) == NULL) + if ((np2 = convert(np1, tp)) == NULL) error("bad type convertion requested"); np2->b.lvalue = np1->b.lvalue; return np1;