OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [tags/] [eco32-0.26/] [lcc/] [cpp/] [nlist.c] - Diff between revs 4 and 270

Only display areas with differences | Details | Blame | View Log

Rev 4 Rev 270
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include "cpp.h"
#include "cpp.h"
 
 
extern  int getopt(int, char *const *, const char *);
extern  int getopt(int, char *const *, const char *);
extern  char    *optarg;
extern  char    *optarg;
extern  int     optind;
extern  int     optind;
extern  int     verbose;
extern  int     verbose;
extern  int     Cplusplus;
extern  int     Cplusplus;
Nlist   *kwdefined;
Nlist   *kwdefined;
 
 
#define NLSIZE  128
#define NLSIZE  128
 
 
static Nlist    *nlist[NLSIZE];
static Nlist    *nlist[NLSIZE];
 
 
struct  kwtab {
struct  kwtab {
        char    *kw;
        char    *kw;
        int     val;
        int     val;
        int     flag;
        int     flag;
} kwtab[] = {
} kwtab[] = {
        "if",           KIF,            ISKW,
        "if",           KIF,            ISKW,
        "ifdef",        KIFDEF,         ISKW,
        "ifdef",        KIFDEF,         ISKW,
        "ifndef",       KIFNDEF,        ISKW,
        "ifndef",       KIFNDEF,        ISKW,
        "elif",         KELIF,          ISKW,
        "elif",         KELIF,          ISKW,
        "else",         KELSE,          ISKW,
        "else",         KELSE,          ISKW,
        "endif",        KENDIF,         ISKW,
        "endif",        KENDIF,         ISKW,
        "include",      KINCLUDE,       ISKW,
        "include",      KINCLUDE,       ISKW,
        "define",       KDEFINE,        ISKW,
        "define",       KDEFINE,        ISKW,
        "undef",        KUNDEF,         ISKW,
        "undef",        KUNDEF,         ISKW,
        "line",         KLINE,          ISKW,
        "line",         KLINE,          ISKW,
        "error",        KERROR,         ISKW,
        "error",        KERROR,         ISKW,
        "pragma",       KPRAGMA,        ISKW,
        "pragma",       KPRAGMA,        ISKW,
        "eval",         KEVAL,          ISKW,
        "eval",         KEVAL,          ISKW,
        "defined",      KDEFINED,       ISDEFINED+ISUNCHANGE,
        "defined",      KDEFINED,       ISDEFINED+ISUNCHANGE,
        "ident",        KPRAGMA,        ISKW,   /* treat like pragma (ignored) */
        "ident",        KPRAGMA,        ISKW,   /* treat like pragma (ignored) */
        "__LINE__",     KLINENO,        ISMAC+ISUNCHANGE,
        "__LINE__",     KLINENO,        ISMAC+ISUNCHANGE,
        "__FILE__",     KFILE,          ISMAC+ISUNCHANGE,
        "__FILE__",     KFILE,          ISMAC+ISUNCHANGE,
        "__DATE__",     KDATE,          ISMAC+ISUNCHANGE,
        "__DATE__",     KDATE,          ISMAC+ISUNCHANGE,
        "__TIME__",     KTIME,          ISMAC+ISUNCHANGE,
        "__TIME__",     KTIME,          ISMAC+ISUNCHANGE,
        "__STDC__",     KSTDC,          ISUNCHANGE,
        "__STDC__",     KSTDC,          ISUNCHANGE,
        NULL
        NULL
};
};
 
 
unsigned long   namebit[077+1];
unsigned long   namebit[077+1];
Nlist   *np;
Nlist   *np;
 
 
void
void
setup_kwtab(void)
setup_kwtab(void)
{
{
        struct kwtab *kp;
        struct kwtab *kp;
        Nlist *np;
        Nlist *np;
        Token t;
        Token t;
        static Token deftoken[1] = {{ NAME, 0, 0, 0, 7, (uchar*)"defined" }};
        static Token deftoken[1] = {{ NAME, 0, 0, 0, 7, (uchar*)"defined" }};
        static Tokenrow deftr = { deftoken, deftoken, deftoken+1, 1 };
        static Tokenrow deftr = { deftoken, deftoken, deftoken+1, 1 };
 
 
        for (kp=kwtab; kp->kw; kp++) {
        for (kp=kwtab; kp->kw; kp++) {
                t.t = (uchar*)kp->kw;
                t.t = (uchar*)kp->kw;
                t.len = strlen(kp->kw);
                t.len = strlen(kp->kw);
                np = lookup(&t, 1);
                np = lookup(&t, 1);
                np->flag = kp->flag;
                np->flag = kp->flag;
                np->val = kp->val;
                np->val = kp->val;
                if (np->val == KDEFINED) {
                if (np->val == KDEFINED) {
                        kwdefined = np;
                        kwdefined = np;
                        np->val = NAME;
                        np->val = NAME;
                        np->vp = &deftr;
                        np->vp = &deftr;
                        np->ap = 0;
                        np->ap = 0;
                }
                }
        }
        }
}
}
 
 
Nlist *
Nlist *
lookup(Token *tp, int install)
lookup(Token *tp, int install)
{
{
        unsigned int h;
        unsigned int h;
        Nlist *np;
        Nlist *np;
        uchar *cp, *cpe;
        uchar *cp, *cpe;
 
 
        h = 0;
        h = 0;
        for (cp=tp->t, cpe=cp+tp->len; cp<cpe; )
        for (cp=tp->t, cpe=cp+tp->len; cp<cpe; )
                h += *cp++;
                h += *cp++;
        h %= NLSIZE;
        h %= NLSIZE;
        np = nlist[h];
        np = nlist[h];
        while (np) {
        while (np) {
                if (*tp->t==*np->name && tp->len==np->len
                if (*tp->t==*np->name && tp->len==np->len
                 && strncmp((char*)tp->t, (char*)np->name, tp->len)==0)
                 && strncmp((char*)tp->t, (char*)np->name, tp->len)==0)
                        return np;
                        return np;
                np = np->next;
                np = np->next;
        }
        }
        if (install) {
        if (install) {
                np = new(Nlist);
                np = new(Nlist);
                np->vp = NULL;
                np->vp = NULL;
                np->ap = NULL;
                np->ap = NULL;
                np->flag = 0;
                np->flag = 0;
                np->val = 0;
                np->val = 0;
                np->len = tp->len;
                np->len = tp->len;
                np->name = newstring(tp->t, tp->len, 0);
                np->name = newstring(tp->t, tp->len, 0);
                np->next = nlist[h];
                np->next = nlist[h];
                nlist[h] = np;
                nlist[h] = np;
                quickset(tp->t[0], tp->len>1? tp->t[1]:0);
                quickset(tp->t[0], tp->len>1? tp->t[1]:0);
                return np;
                return np;
        }
        }
        return NULL;
        return NULL;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.