ref: 7c7fb51c9d0b8fd7f3497d87d6425eb9a9037e3d
parent: a91ac5f206e09a9f469430ee20f33eba870cfd9c
author: Roberto E. Vargas Caballero <[email protected]>
date: Sun Jul 13 02:49:43 EDT 2014
Remove type qualifiers They are good for anything and makes the code more difficult, so the compiler will accept them, but it will ignore them to.
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -113,14 +113,6 @@
*ullongtype, *llongtype,
*floattype, *doubletype, *ldoubletype;
-#define ISQUAL(t) (isqual((t)->op))
-#define UNQUAL(t) (ISQUAL(t) ? (t)->type : (t))
-#define BTYPE(t) (UNQUAL(t)->op)
-#define isqual(op) ((op) & TQUALIFIER)
-#define isconst(op) (((op) & (TQUALIFIER|CONST)) == \
- (TQUALIFIER|CONST))
-
-
enum {
FTN = 1, ENUM, TYPEIDEN, VOID, FLOAT, INT, BOOL,
STRUCT, UNION, PTR, ARY, CHAR, DOUBLE, SHORT,
@@ -168,7 +160,6 @@
typedef struct node {
void (*code)(struct node *);
Type *type;
- Type *utype;
uint8_t typeop;
struct {
bool lvalue : 1;
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -58,8 +58,7 @@
np->code = code;
np->type = tp;
- np->utype = UNQUAL(tp);
- np->typeop = np->utype->op;
+ np->typeop = tp->op;
np->u = u;
np->b.symbol = np->b.lvalue = 0;
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -467,7 +467,7 @@
do {
sym = declarator(tp, ID_EXPECTED);
sym->s.isdefined = 1;
- isfun = BTYPE(sym->type) != FTN;
+ isfun = sym->type->op != FTN;
switch (sclass) {
case TYPEDEF:
@@ -552,7 +552,7 @@
continue;
}
- if (BTYPE(tp) != FTN) {
+ if (tp->op != FTN) {
if (accept('='))
initializer(sym);
emitdcl(sym);
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -29,7 +29,7 @@
if (options.npromote)
return np;
- tp = np->utype;
+ tp = np->type;
r = tp->u.rank;
if (r > RANK_UINT || tp == inttype || tp == uinttype)
return np;
@@ -46,8 +46,8 @@
np1 = promote(*p1);
np2 = promote(*p2);
- tp1 = np1->utype;
- tp2 = np2->utype;
+ tp1 = np1->type;
+ tp2 = np2->type;
if (tp1 != tp2) {
if ((n = tp1->u.rank - tp2->u.rank) > 0)
np2 = castcode(np2, tp1);
@@ -63,10 +63,8 @@
{
if (!np->b.lvalue)
error("lvalue required in operation");
- if (np->utype == voidtype)
+ if (np->type == voidtype)
error("invalid use of void expression");
- if (isconst(tp->op))
- error("const value modified");
}
Node *
@@ -104,7 +102,7 @@
{
Type *tp;
- tp = mktype(np->utype->type, PTR, 0);
+ tp = mktype(np->type->type, PTR, 0);
return unarycode(OADDR, tp, np);
}
@@ -114,15 +112,12 @@
Node *
convert(Node *np, Type *tp, char iscast)
{
- Type *utp;
uint8_t t;
if (np->type == tp)
return np;
- utp = UNQUAL(tp);
- t = utp->op;
-
+ t = tp->op;
switch (np->typeop) {
case ENUM: case INT: case FLOAT:
switch (t) {
@@ -145,8 +140,8 @@
np = decay(np);
case PTR:
if (iscast ||
- utp == pvoidtype ||
- np->utype == pvoidtype) {
+ tp == pvoidtype ||
+ np->type == pvoidtype) {
/* TODO:
* we assume conversion between pointers
* do not need any operation, but due to
@@ -153,7 +148,6 @@
* alignment problems that may be false
*/
np->type = tp;
- np->utype = utp;
return np;
}
default:
@@ -171,13 +165,13 @@
Type *tp;
Node *size;
- tp = np1->utype;
+ tp = np1->type;
size = sizeofcode(tp->type);
if (np2->typeop == ARY)
np2 = decay(np2);
if (op == OSUB && np2->typeop == PTR) {
- if (tp != np2->utype)
+ if (tp != np2->type)
goto incorrect;
np1 = bincode(OSUB, inttype, np1, np2);
return bincode(ODIV, inttype, np1, size);
@@ -224,13 +218,6 @@
return bincode(op, np1->type, np1, np2);
}
-/*
- * FIXME:
- * Pointers to the same basic type after removing type qualifiers
- * can be compared. It means that utype pointer must be a field
- * of the type, not of the Node, because in other case is
- * hard doing this check
- */
static Node *
pcompare(char op, Node *np1, Node *np2)
{
@@ -305,7 +292,7 @@
unexpected();
switch (np->typeop) {
case STRUCT: case UNION:
- for (fp = np->utype->u.fields; fp; fp = fp->next) {
+ for (fp = np->type->u.fields; fp; fp = fp->next) {
if (!strcmp(fp->name, yytext)) {
next();
return fieldcode(np, fp);
@@ -352,9 +339,9 @@
static Node *
incdec(Node *np, char op)
{
- Type *tp = np->utype;
+ Type *tp = np->type;
- chklvalue(np, np->utype);
+ chklvalue(np, np->type);
switch (np->typeop) {
case PTR:
@@ -384,7 +371,7 @@
case ARY: case FTN:
np = decay(np);
case PTR:
- np = unarycode(op, np->utype->type, np);
+ np = unarycode(op, np->type->type, np);
np->b.lvalue = 1;
return np;
default: