[hackers] [scc] [cc1] Create deftype() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 14 Dec 2016 13:44:06 +0100 (CET)

commit e6e67bde1898d8478134a77583129e1f28e2ca12
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Wed Dec 14 13:41:37 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Wed Dec 14 13:44:01 2016 +0100

    [cc1] Create deftype()
    
    This function does all the steps needed when a new type is defined,
    instead of copying the same all the time.

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 9cd4e7a..8f88d07 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -349,6 +349,7 @@ extern void warn(char *fmt, ...);
 extern void unexpected(void);
 extern void errorp(char *fmt, ...);
 extern void cpperror(char *fmt, ...);
+extern Type *deftype(Type *tp);
 
 /* types.c */
 extern int eqtype(Type *tp1, Type *tp2, int eqflag);
diff --git a/cc1/decl.c b/cc1/decl.c
index a67149e..b4930c1 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
_AT_@ -521,7 +521,6 @@ structdcl(void)
 
         if (tp->prop & TDEFINED && sym->ctx == curctx)
                 error("redefinition of struct/union '%s'", sym->name);
- tp->prop |= TDEFINED;
 
         if (nested == NR_STRUCT_LEVEL)
                 error("too many levels of nested structure or union definitions");
_AT_@ -532,8 +531,7 @@ structdcl(void)
         }
         --nested;
 
- typesize(tp);
- emit(OTYP, tp);
+ deftype(tp);
         namespace = ns;
         expect('}');
         return tp;
_AT_@ -555,9 +553,7 @@ enumdcl(void)
                 goto restore_name;
         if (tp->prop & TDEFINED)
                 errorp("redefinition of enumeration '%s'", tagsym->name);
- tp->prop |= TDEFINED;
- emit(OTYP, tp);
- typesize(tp);
+ deftype(tp);
         namespace = NS_IDEN;
 
         /* TODO: check incorrect values in val */
diff --git a/cc1/init.c b/cc1/init.c
index 1f55e01..bbffa54 100644
--- a/cc1/init.c
+++ b/cc1/init.c
_AT_@ -120,9 +120,8 @@ initialize(Type *tp)
                 }
                 len = sym->type->n.elem-1;
                 if (!(tp->prop & TDEFINED)) {
- tp->prop |= TDEFINED;
                         tp->n.elem = len+1;
- typesize(tp);
+ deftype(tp);
                 } else if (tp->n.elem < len) {
                         warn("initializer-string for array of chars is too long");
                 }
diff --git a/cc1/types.c b/cc1/types.c
index 39f5bce..fa6f6e9 100644
--- a/cc1/types.c
+++ b/cc1/types.c
_AT_@ -242,6 +242,15 @@ typesize(Type *tp)
         }
 }
 
+Type *
+deftype(Type *tp)
+{
+ tp->prop |= TDEFINED;
+ typesize(tp);
+ emit(OTYP, tp);
+ return tp;
+}
+
 static Type *
 newtype(Type *base)
 {
Received on Wed Dec 14 2016 - 13:44:06 CET

This archive was generated by hypermail 2.3.0 : Wed Dec 14 2016 - 13:48:15 CET