ref: 30a652a5b0a4e6c240fc897f2445d59947c1e789
parent: 7ae2f8e3d575dd2e918c3b389779415e63902d8b
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Feb 9 06:24:13 EST 2012
Added fields for basic types These new fields in the type structure allow know the properties of the basic type without doing complex comparision
--- a/types.c
+++ b/types.c
@@ -2,18 +2,26 @@
#include <assert.h>
#include <stdlib.h>
+#include "tokens.h"
#include "types.h"
+
#define xcalloc calloc
-struct type tschar, tuchar; /* signed char, unsigned char */
-struct type tshort, tushort; /* short, unsigned short */
-struct type tint, tuint; /* int, unsigned int */
-struct type tfloat, tdouble, tldouble; /* float, double, long double */
-struct type tlong, tulong; /* long, unsgined long */
-struct type tllong, tullong; /* long long, unsigned long long */
-struct type tvoid; /* void */
-
+struct type tschar = {.btype = CHAR, .sign = 1};
+struct type tuchar = {.btype = CHAR, .sign = 0};
+struct type tshort = {.btype = SHORT, .sign = 1};
+struct type tushort = {.btype = SHORT, .sign = 0};
+struct type tint = {.btype = INT, .sign = 1};
+struct type tuint = {.btype = SHORT, .sign = 0};
+struct type tfloat = {.btype = FLOAT, .sign = 1};
+struct type tdouble = {.btype = DOUBLE, .sign = 1};
+struct type tldouble = {.btype = LDOUBLE, .sign = 1};
+struct type tlong = {.btype = LONG, .sign = 1};
+struct type tulong = {.btype = LONG, .sign = 0};
+struct type tllong = {.btype = LLONG, .sign = 1};
+struct type tullong = {.btype = LLONG, .sign = 0};
+struct type tvoid = {.btype = VOID, .sign = 0};
struct type *mktype(register struct type *base, unsigned char op)
{
--- a/types.h
+++ b/types.h
@@ -9,8 +9,12 @@
struct type *ptr; /* pointer */
struct type *ftn; /* function */
union {
- size_t nelem;
- } u;
+ struct {
+ unsigned btype : 4;
+ unsigned sign : 1;
+ };
+ size_t nelem; /* size of array */
+ };
};