commit 565ba0922428a7a04198f8d11216309f018d6d50
parent 7d7ee21e09b35138c6be3cace6c0d9778c90603c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 5 Aug 2014 18:03:19 +0200
Add eqtype()
This function compare two types and see if they are the same
type or not. This function is needed because the comparision
of pointers can be difficult, because if they pointed to a
function they are going to point to different structures,
because different functions with the same type have different
Type structure (this is done because is hard to generate a
hash in this case).
Diffstat:
3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/cc1/cc1.h b/cc1/cc1.h
@@ -85,6 +85,7 @@ struct symbol {
struct symbol *hash;
};
+extern bool eqtype(Type *tp1, Type *tp2);
extern Type *ctype(int8_t type, int8_t sign, int8_t size),
*mktype(Type *tp, uint8_t op, void *data);
diff --git a/cc1/expr.c b/cc1/expr.c
@@ -9,6 +9,8 @@ static Symbol *zero, *one;
Node *expr(void);
+/* TODO: Change np1 and np2 to left and right (or l, r) */
+
void
init_expr(void)
{
@@ -111,9 +113,8 @@ convert(Node *np, Type *tp, char iscast)
{
uint8_t t;
- if (np->type == tp)
+ if (eqtype(np->type, tp))
return np;
-
t = tp->op;
switch (np->typeop) {
case ENUM: case INT: case FLOAT:
diff --git a/cc1/types.c b/cc1/types.c
@@ -207,3 +207,27 @@ mktype(Type *tp, uint8_t op, void *data)
return *tbl = bp;
}
+bool
+eqtype(Type *tp1, Type *tp2)
+{
+ Funpar *fp1, *fp2;
+
+ if (tp1 == tp2)
+ return 1;
+ if (tp1->op != tp2->op || tp1->op != PTR)
+ return 0;
+ tp1 = tp1->type;
+ tp2 = tp2->type;
+ if (tp1->op != tp2->op || tp1->op != FTN || !eqtype(tp1->type, tp2->type))
+ return 0;
+ fp2 = tp2->u.pars;
+ fp1 = tp1->u.pars;
+ while (fp1 && fp2) {
+ if (!eqtype(fp1->type, fp2->type))
+ break;
+ fp1 = fp1->next;
+ fp2 = fp2->next;
+ }
+
+ return fp1 == fp2;
+}