as: Remove String type - scc - simple c99 compiler
 (HTM) git clone git://git.simple-cc.org/scc
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 70b4d78d91cd330d951b919534c0da553489be55
 (DIR) parent 19c55486c5a8029655ecff7674de7b3167211df5
 (HTM) Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
       Date:   Sun, 11 Feb 2024 15:29:14 +0100
       
       as: Remove String type
       
       This type was not used ever, and I don't remember why it was
       added, and I cannot find a simple reason why it should  be
       preserved.
       
       Diffstat:
         M src/cmd/as/as.h                     |      11 ++---------
         M src/cmd/as/ins.c                    |      12 ++++++------
         M src/cmd/as/parser.c                 |       2 +-
         M src/cmd/as/symbol.c                 |      24 ++++++------------------
       
       4 files changed, 15 insertions(+), 34 deletions(-)
       ---
 (DIR) diff --git a/src/cmd/as/as.h b/src/cmd/as/as.h
       @@ -77,14 +77,8 @@ typedef struct op Op;
        typedef struct section Section;
        typedef struct symbol Symbol;
        typedef struct node Node;
       -typedef struct string String;
        typedef void Format(Op *, Node **);
        
       -struct string {
       -        char *buf;
       -        size_t offset;
       -};
       -
        struct line {
                char *label;
                char *op;
       @@ -128,8 +122,8 @@ struct section {
        };
        
        struct symbol {
       -        String name;
       -        String type;
       +        char *name;
       +        char *type;
                unsigned char flags;
                unsigned char pass;
                TUINT value;
       @@ -162,7 +156,6 @@ extern Symbol *tmpsym(TUINT);
        extern void killtmp(void);
        extern int toobig(Node *, int);
        extern void dumpstab(char *);
       -extern String newstring(char *);
        
        /* main.c */
        extern Symbol *lookup(char *);
 (DIR) diff --git a/src/cmd/as/ins.c b/src/cmd/as/ins.c
       @@ -55,7 +55,7 @@ xstring(int which, Node **args)
                size_t len;
        
                while (np = *args++) {
       -                s = np->sym->name.buf;
       +                s = np->sym->name;
                        len = strlen(s);
                        len += which == XSTRING;
                        emit(s, len);
       @@ -139,7 +139,7 @@ symexp(int which, Op *op, Node **args)
                switch (which) {
                case EQU:
                        if (pass == 1 && (sym->flags & FDEF))
       -                        error("redefinition of symbol '%s'", sym->name.buf);
       +                        error("redefinition of symbol '%s'", sym->name);
                        sym->value = exp->value;
                        sym->flags |= FDEF;
                        break;
       @@ -149,7 +149,7 @@ symexp(int which, Op *op, Node **args)
                        sym->size = exp->value;
                        break;
                case TYPE:
       -                sym->type.buf = xstrdup(exp->name.buf);
       +                sym->type = xstrdup(exp->name);
                        break;
                }
        }
       @@ -185,9 +185,9 @@ section(Op *op, Node **args)
                char *attr = NULL;
        
                if (args[1])
       -                attr = args[1]->sym->name.buf;
       +                attr = args[1]->sym->name;
        
       -        setsec(sym->name.buf, attr);
       +        setsec(sym->name, attr);
        }
        
        void
       @@ -252,5 +252,5 @@ end(Op *op, Node **args)
        void
        include(Op *op, Node **args)
        {
       -        addinput(args[0]->sym->name.buf);
       +        addinput(args[0]->sym->name);
        }
 (DIR) diff --git a/src/cmd/as/parser.c b/src/cmd/as/parser.c
       @@ -145,7 +145,7 @@ string(void)
                l = yylen-2;
                s = memcpy(xmalloc(l+1), yytext+1, l);
                s[l] = '\0';
       -        sym->name.buf = s;
       +        sym->name = s;
        
                return STRING;
        }
 (DIR) diff --git a/src/cmd/as/symbol.c b/src/cmd/as/symbol.c
       @@ -33,7 +33,7 @@ dumpstab(char *msg)
                        fprintf(stderr, "[%d]", (int) (bp - hashtbl));
                        for (sym = *bp; sym; sym = sym->hash) {
                                fprintf(stderr, " -> %s:%0X:%0X",
       -                               sym->name.buf, sym->flags, sym->value);
       +                               sym->name, sym->flags, sym->value);
                        }
                        putc('\n', stderr);
                }
       @@ -52,7 +52,7 @@ lookup(char *name)
                if (*name == '.' && cursym) {
                        if (!cursym)
                                error("local label '%s' without global label", name);
       -                t = cursym->name.buf;
       +                t = cursym->name;
                        r = snprintf(buf, sizeof(buf), "%s%s", t, name);
                        if (r < 0 || r >= sizeof(buf))
                                error("too long local label '%s%s'", t, name);
       @@ -64,13 +64,13 @@ lookup(char *name)
                c = toupper(*name);
                list = &hashtbl[h];
                for (sym = *list; sym; sym = sym->hash) {
       -                t = sym->name.buf;
       +                t = sym->name;
                        if (c == toupper(*t) && !casecmp(t, name))
                                return sym;
                }
        
                sym = xmalloc(sizeof(*sym));
       -        sym->name = newstring(name);
       +        sym->name = xstrdup(name);
                sym->flags = 0;
                sym->size = sym->value = 0;
                sym->section = cursec;
       @@ -104,10 +104,10 @@ deflabel(char *name)
                        }
                        r = snprintf(label, sizeof(label),
                                     "%s%s",
       -                             cursym->name.buf, name);
       +                             cursym->name, name);
                        if (r == sizeof(label)) {
                                error("local label '%s' in '%s' produces too long symbol",
       -                              name, cursym->name.buf);
       +                              name, cursym->name);
                                return NULL;
                        }
                        name = label;
       @@ -302,15 +302,3 @@ killtmp(void)
                dealloc(tmpalloc);
                tmpalloc = NULL;
        }
       -
       -String
       -newstring(char *s)
       -{
       -        size_t len = strlen(s) + 1;
       -        String str;
       -
       -        str.offset = 0;
       -        str.buf = xmalloc(len);
       -        memcpy(str.buf, s, len);
       -        return str;
       -}