[hackers] [scc] Move keyword initialization to more specific places || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Sun, 4 Oct 2015 22:01:07 +0200 (CEST)

commit 1537ee3c105f0ba568d4a3b40adf4021da40b7c9
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Sun Oct 4 21:07:40 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Sun Oct 4 21:07:40 2015 +0200

    Move keyword initialization to more specific places
    
    It is better if each module initializes the own keywords,
    instead of having a function that initializes the keywords
    for all the modules.

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 997febb..27a0d9a 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -46,6 +46,10 @@ struct limits {
         } min;
 };
 
+struct keyword {
+ char *str;
+ unsigned char token, value;
+};
 
 struct type {
         unsigned char op; /* type builder operator */
_AT_@ -345,9 +349,9 @@ extern Symbol *nextsym(Symbol *sym, int ns);
 extern Symbol *install(int ns, Symbol *sym);
 extern Symbol *newsym(int ns);
 extern void pushctx(void), popctx(void);
-extern void ikeywords(void);
 extern void killsym(Symbol *sym);
 extern Symbol *newlabel(void);
+extern void keywords(struct keyword *key, int ns);
 
 /* stmt.c */
 extern void compound(Symbol *lbreak, Symbol *lcont, Caselist *lswitch);
diff --git a/cc1/cpp.c b/cc1/cpp.c
index 88f51f6..a5ad74a 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
_AT_@ -37,12 +37,27 @@ icpp(void)
         static char sdate[17], stime[14];
         struct tm *tm;
         time_t t;
- char **bp, *list[] = {
+ static char **bp, *list[] = {
                 "__STDC__",
                 "__STDC_HOSTED__",
                 "__SCC__",
                 NULL
         };
+ static struct keyword keys[] = {
+ {"define", DEFINE, DEFINE},
+ {"include", INCLUDE, INCLUDE},
+ {"line", LINE, LINE},
+ {"ifdef", IFDEF, IFDEF},
+ {"if", IF, IF},
+ {"elif", ELIF, ELIF},
+ {"else", ELSE, ELSE},
+ {"ifndef", IFNDEF, IFNDEF},
+ {"endif", ENDIF, ENDIF},
+ {"undef", UNDEF, UNDEF},
+ {"pragma", PRAGMA, PRAGMA},
+ {"error", ERROR, ERROR},
+ {NULL, 0, 0}
+ };
 
         t = time(NULL);
         tm = localtime(&t);
_AT_@ -57,6 +72,7 @@ icpp(void)
 
         for (bp = list; *bp; ++bp)
                 defmacro(*bp)->u.s = "-1#1";
+ keywords(keys, NS_CPPCLAUSES);
 }
 
 static void
diff --git a/cc1/lex.c b/cc1/lex.c
index eb1e2d5..0fd977a 100644
--- a/cc1/lex.c
+++ b/cc1/lex.c
_AT_@ -39,6 +39,44 @@ allocinput(char *fname, FILE *fp)
 void
 ilex(char *fname)
 {
+ static struct keyword keys[] = {
+ {"auto", SCLASS, AUTO},
+ {"break", BREAK, BREAK},
+ {"_Bool", TYPE, BOOL},
+ {"case", CASE, CASE},
+ {"char", TYPE, CHAR},
+ {"const", TQUALIFIER, CONST},
+ {"continue", CONTINUE, CONTINUE},
+ {"default", DEFAULT, DEFAULT},
+ {"do", DO, DO},
+ {"double", TYPE, DOUBLE},
+ {"else", ELSE, ELSE},
+ {"enum", TYPE, ENUM},
+ {"extern", SCLASS, EXTERN},
+ {"float", TYPE, FLOAT},
+ {"for", FOR, FOR},
+ {"goto", GOTO, GOTO},
+ {"if", IF, IF},
+ {"inline", TQUALIFIER, INLINE},
+ {"int", TYPE, INT},
+ {"long", TYPE, LONG},
+ {"register", SCLASS, REGISTER},
+ {"restrict", TQUALIFIER, RESTRICT},
+ {"return", RETURN, RETURN},
+ {"short", TYPE, SHORT},
+ {"signed", TYPE, SIGNED},
+ {"sizeof", SIZEOF, SIZEOF},
+ {"static", SCLASS, STATIC},
+ {"struct", TYPE, STRUCT},
+ {"switch", SWITCH, SWITCH},
+ {"typedef", SCLASS, TYPEDEF},
+ {"union", TYPE, UNION},
+ {"unsigned", TYPE, UNSIGNED},
+ {"void", TYPE, VOID},
+ {"volatile", TQUALIFIER, VOLATILE},
+ {"while", WHILE, WHILE},
+ {NULL, 0, 0},
+ };
         FILE *fp;
 
         if (!fname) {
_AT_@ -52,6 +90,7 @@ ilex(char *fname)
         }
         allocinput(fname, fp);
         *input->begin = '\0';
+ keywords(keys, NS_KEYWORD);
 }
 
 bool
diff --git a/cc1/main.c b/cc1/main.c
index d9a20c3..c20f485 100644
--- a/cc1/main.c
+++ b/cc1/main.c
_AT_@ -75,7 +75,6 @@ main(int argc, char *argv[])
                 usage();
 
         icpp();
- ikeywords();
         ilex(*argv);
 
         if (onlycpp) {
diff --git a/cc1/symbol.c b/cc1/symbol.c
index 8c0a210..4db41df 100644
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
_AT_@ -282,11 +282,6 @@ install(int ns, Symbol *sym)
         return linkhash(sym);
 }
 
-struct keyword {
- char *str;
- unsigned char token, value;
-};
-
 void
 keywords(struct keyword *key, int ns)
 {
_AT_@ -305,62 +300,3 @@ keywords(struct keyword *key, int ns)
         counterid = 0;
         head = NULL;
 }
-
-void
-ikeywords(void)
-{
- static struct keyword ckeywords[] = {
- {"auto", SCLASS, AUTO},
- {"break", BREAK, BREAK},
- {"_Bool", TYPE, BOOL},
- {"case", CASE, CASE},
- {"char", TYPE, CHAR},
- {"const", TQUALIFIER, CONST},
- {"continue", CONTINUE, CONTINUE},
- {"default", DEFAULT, DEFAULT},
- {"do", DO, DO},
- {"double", TYPE, DOUBLE},
- {"else", ELSE, ELSE},
- {"enum", TYPE, ENUM},
- {"extern", SCLASS, EXTERN},
- {"float", TYPE, FLOAT},
- {"for", FOR, FOR},
- {"goto", GOTO, GOTO},
- {"if", IF, IF},
- {"inline", TQUALIFIER, INLINE},
- {"int", TYPE, INT},
- {"long", TYPE, LONG},
- {"register", SCLASS, REGISTER},
- {"restrict", TQUALIFIER, RESTRICT},
- {"return", RETURN, RETURN},
- {"short", TYPE, SHORT},
- {"signed", TYPE, SIGNED},
- {"sizeof", SIZEOF, SIZEOF},
- {"static", SCLASS, STATIC},
- {"struct", TYPE, STRUCT},
- {"switch", SWITCH, SWITCH},
- {"typedef", SCLASS, TYPEDEF},
- {"union", TYPE, UNION},
- {"unsigned", TYPE, UNSIGNED},
- {"void", TYPE, VOID},
- {"volatile", TQUALIFIER, VOLATILE},
- {"while", WHILE, WHILE},
- {NULL, 0, 0},
- }, cppclauses[] = {
- {"define", DEFINE, DEFINE},
- {"include", INCLUDE, INCLUDE},
- {"line", LINE, LINE},
- {"ifdef", IFDEF, IFDEF},
- {"if", IF, IF},
- {"elif", ELIF, ELIF},
- {"else", ELSE, ELSE},
- {"ifndef", IFNDEF, IFNDEF},
- {"endif", ENDIF, ENDIF},
- {"undef", UNDEF, UNDEF},
- {"pragma", PRAGMA, PRAGMA},
- {"error", ERROR, ERROR},
- {NULL, 0, 0}
- };
- keywords(ckeywords, NS_KEYWORD);
- keywords(cppclauses, NS_CPPCLAUSES);
-}
Received on Sun Oct 04 2015 - 22:01:07 CEST

This archive was generated by hypermail 2.3.0 : Sun Oct 04 2015 - 22:12:12 CEST