[hackers] [scc] Split initialization of keywords || Roberto E. Vargas Caballero

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

commit fe8c715e58c377228207548a27aed474839feca5
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Sun Oct 4 20:39:32 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Sun Oct 4 20:41:29 2015 +0200

    Split initialization of keywords
    
    The initialization was thought for keywords
    in only two namespaces, but we know we will need
    add keywords in another namespaces, so it is a
    good idea to create a independent function.

diff --git a/cc1/symbol.c b/cc1/symbol.c
index 9b07096..8c0a210 100644
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
_AT_@ -282,13 +282,34 @@ install(int ns, Symbol *sym)
         return linkhash(sym);
 }
 
+struct keyword {
+ char *str;
+ unsigned char token, value;
+};
+
+void
+keywords(struct keyword *key, int ns)
+{
+ Symbol *sym;
+
+ for ( ; key->str; ++key) {
+ sym = linkhash(allocsym(ns, key->str));
+ sym->token = key->token;
+ sym->u.token = key->value;
+ }
+ /*
+ * Remove all the predefined symbols from * the symbol list. It
+ * will make faster some operations. There is no problem of memory
+ * leakeage because this memory is not ever freed
+ */
+ counterid = 0;
+ head = NULL;
+}
+
 void
 ikeywords(void)
 {
- static struct {
- char *str;
- unsigned char token, value;
- } *bp, keywords[] = {
+ static struct keyword ckeywords[] = {
                 {"auto", SCLASS, AUTO},
                 {"break", BREAK, BREAK},
                 {"_Bool", TYPE, BOOL},
_AT_@ -339,27 +360,7 @@ ikeywords(void)
                 {"pragma", PRAGMA, PRAGMA},
                 {"error", ERROR, ERROR},
                 {NULL, 0, 0}
- }, *list[] = {
- keywords,
- cppclauses,
- NULL
- }, **lp;
- Symbol *sym;
- int ns = NS_KEYWORD;
-
- for (lp = list; *lp; ++lp) {
- for (bp = *lp; bp->str; ++bp) {
- sym = linkhash(allocsym(ns, bp->str));
- sym->token = bp->token;
- sym->u.token = bp->value;
- }
- ns = NS_CPPCLAUSES;
- }
- /*
- * Remove all the predefined symbols from * the symbol list. It
- * will make faster some operations. There is no problem of memory
- * leakeage because this memory is not ever freed
- */
- counterid = 0;
- head = NULL;
+ };
+ 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:10 CEST