ref: c1768b2e370906fc8418bc26cd69d88529c8c96b
parent: a512be02d9c534110deafcce1e73f452a0fa9068
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Apr 14 06:21:52 EDT 2014
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.
--- a/expr.c
+++ b/expr.c
@@ -38,7 +38,7 @@
}
static Node *
-ary2ptr(Node *np)
+addr2ptr(Node *np)
{
Type *tp;
@@ -71,7 +71,9 @@
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 @@
}
break;
case ARY:
- np1 = ary2ptr(np1);
+ np1 = addr2ptr(np1);
tp1 = np1->type;
case PTR:
pointer:
@@ -188,11 +190,10 @@
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 @@
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;