[hackers] [scc] [cc1] Add equiv parameter to eqtype() || Roberto E. Vargas Caballero
commit 7090df164ce7ae97854a3b991427160d2d79dac6
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Aug 9 13:36:20 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Aug 9 13:36:20 2016 +0200
[cc1] Add equiv parameter to eqtype()
Eqtype() compare two types, but it was checking always that
the types were exactly the same, and in some situations is
needed to check that two types are equivalent. Both
situations shared almost all the code, so the best option
is to add a new parameter to control what behaviour
the caller expects.
diff --git a/cc1/cc1.h b/cc1/cc1.h
index b9cbfb4..3d9634d 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -349,7 +349,7 @@ extern void errorp(char *fmt, ...);
extern void cpperror(char *fmt, ...);
/* types.c */
-extern int eqtype(Type *tp1, Type *tp2);
+extern int eqtype(Type *tp1, Type *tp2, int eqflag);
extern Type *ctype(unsigned type, unsigned sign, unsigned size);
extern Type *mktype(Type *tp, int op, TINT nelem, Type *data[]);
extern Type *duptype(Type *base);
diff --git a/cc1/decl.c b/cc1/decl.c
index 0bffb41..3609c17 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
_AT_@ -662,7 +662,7 @@ redcl(Symbol *sym, Type *tp, Symbol **pars, int sclass)
int flags;
char *name = sym->name;
- if (!eqtype(sym->type, tp)) {
+ if (!eqtype(sym->type, tp, 1)) {
errorp("conflicting types for '%s'", name);
return sym;
}
diff --git a/cc1/expr.c b/cc1/expr.c
index fca3f9b..29ea4db 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -151,7 +151,7 @@ chkternary(Node *yes, Node *no)
* take a look to 6.5.15
*/
- if (!eqtype(yes->type, no->type)) {
+ if (!eqtype(yes->type, no->type, 1)) {
if ((yes->type->prop & TARITH) && (no->type->prop & TARITH)) {
arithconv(&yes, &no);
} else if (yes->type->op != PTR && no->type->op != PTR) {
_AT_@ -178,7 +178,7 @@ chkternary(Node *yes, Node *no)
if (null(no))
no = convert(no, yes->type, 0);
- if (!eqtype(yes->type, no->type))
+ if (!eqtype(yes->type, no->type, 1))
goto wrong_type;
}
}
_AT_@ -263,7 +263,7 @@ convert(Node *np, Type *newtp, char iscast)
{
Type *oldtp = np->type;
- if (eqtype(newtp, oldtp))
+ if (eqtype(newtp, oldtp, 0))
return np;
switch (oldtp->op) {
_AT_@ -368,7 +368,7 @@ pcompare(char op, Node *lp, Node *rp)
err = 1;
rp = convert(rp, pvoidtype, 1);
} else if (rp->type->op == PTR) {
- if (!eqtype(lp->type, rp->type))
+ if (!eqtype(lp->type, rp->type, 1))
err = 1;
} else {
err = 1;
diff --git a/cc1/init.c b/cc1/init.c
index fbdfc3e..cdd7aa4 100644
--- a/cc1/init.c
+++ b/cc1/init.c
_AT_@ -134,7 +134,7 @@ initialize(Type *tp)
return np;
}
- if (eqtype(tp, np->type))
+ if (eqtype(tp, np->type, 1))
return np;
if ((aux = convert(decay(np), tp, 0)) != NULL)
return aux;
diff --git a/cc1/types.c b/cc1/types.c
index 5974cff..f4fa6f9 100644
--- a/cc1/types.c
+++ b/cc1/types.c
_AT_@ -296,7 +296,7 @@ mktype(Type *tp, int op, TINT nelem, Type *pars[])
t = (op ^ (uintptr_t) tp >> 3) & NR_TYPE_HASH-1;
tbl = &typetab[t];
for (bp = *tbl; bp; bp = bp->next) {
- if (eqtype(bp, &type) && op != STRUCT && op != UNION) {
+ if (eqtype(bp, &type, 0) && op != STRUCT && op != UNION) {
/*
* pars was allocated by the caller
* but the type already exists, so
_AT_@ -314,7 +314,7 @@ mktype(Type *tp, int op, TINT nelem, Type *pars[])
}
int
-eqtype(Type *tp1, Type *tp2)
+eqtype(Type *tp1, Type *tp2, int equiv)
{
TINT n;
Type **p1, **p2;
_AT_@ -333,16 +333,18 @@ eqtype(Type *tp1, Type *tp2)
return 0;
p1 = tp1->p.pars, p2 = tp2->p.pars;
for (n = tp1->n.elem; n > 0; --n) {
- if (!eqtype(*p1++, *p2++))
+ if (!eqtype(*p1++, *p2++, equiv))
return 0;
}
goto check_base;
case ARY:
+ if (equiv && (tp1->n.elem == 0 || tp2->n.elem == 0))
+ goto check_base;
if (tp1->n.elem != tp2->n.elem)
return 0;
case PTR:
check_base:
- return eqtype(tp1->type, tp2->type);
+ return eqtype(tp1->type, tp2->type, equiv);
case VOID:
case ENUM:
return 0;
Received on Tue Aug 09 2016 - 14:25:44 CEST
This archive was generated by hypermail 2.3.0
: Tue Aug 09 2016 - 14:36:16 CEST