示例#1
0
static void
add_define(char *name, int nargs, char *exps)
{
    struct defn *p;
    unsigned int h;

    if ((p = lookup_define(name)) != NULL)
    {
	if (nargs != p->nargs || strcmp(exps, p->exps) != 0)
	{
	    lexerror("Redefinition of #define %s", name);
	}
	return;
    }
    p = (struct defn *)xalloc(sizeof(struct defn));
    p->name = xalloc(strlen(name)+1);
    (void)strcpy(p->name, name);
    p->undef = 0;
    p->nargs = nargs;
    p->exps = xalloc(strlen(exps)+1);
    (void)strcpy(p->exps, exps);
    h = defhash(name);
    p->next = defns[h];
    defns[h] = p;
    /*(void)fprintf(stderr, "define '%s' %d '%s'\n", name, nargs, exps);*/
}
示例#2
0
文件: preprocess.c 项目: Elohim/FGmud
static void add_define (const char * name, int nargs, const char * exps)
{
    defn_t *p = lookup_definition(name);
    int h, len;

    /* trim off leading and trailing whitespace */
    while (uisspace(*exps)) exps++;
    for (len = strlen(exps);  len && uisspace(exps[len - 1]);  len--);
    if (*exps == '#' && *(exps + 1) == '#') {
        yyerror("'##' at start of macro definition");
        return;
    }
    if (len > 2 && *(exps + len - 2) == '#' && *(exps + len - 1) == '#') {
        yyerror("'##' at end of macro definition");
        return;
    }

    if (p) {
        if (p->flags & DEF_IS_UNDEFINED) {
            p->exps = (char *)DREALLOC(p->exps, len + 1, TAG_COMPILER, "add_define: redef");
            memcpy(p->exps, exps, len);
            p->exps[len] = 0;
            p->flags = 0;
            p->nargs = nargs;
        } else {
            if (p->flags & DEF_IS_PREDEF) {
                yyerror("Illegal to redefine predefined value.");
                return;
            }
            if (nargs != p->nargs || strcmp(exps, p->exps)) {
                char buf[200 + NSIZE];

                sprintf(buf, "redefinition of #define %s\n", name);
                yywarn(buf);

                p->exps = (char *)DREALLOC(p->exps, len + 1, TAG_COMPILER, "add_define: redef");
                memcpy(p->exps, exps, len);
                p->exps[len] = 0;
                p->nargs = nargs;
            }
#ifndef LEXER
            p->flags &= ~DEF_IS_NOT_LOCAL;
#endif
        }
    } else {
        p = ALLOCATE(defn_t, TAG_COMPILER, "add_define: def");
        p->name = (char *) DXALLOC(strlen(name) + 1, TAG_COMPILER, "add_define: def name");
        strcpy(p->name, name);
        p->exps = (char *) DXALLOC(len + 1, TAG_COMPILER, "add_define: def exps");
        memcpy(p->exps, exps, len);
        p->exps[len] = 0;
        p->flags = 0;
        p->nargs = nargs;
        h = defhash(name);
        p->next = defns[h];
        defns[h] = p;
    }
}
示例#3
0
文件: preprocess.c 项目: Elohim/FGmud
static defn_t *lookup_definition (const char * s)
{
    defn_t *p;
    int h;

    h = defhash(s);
    for (p = defns[h]; p; p = p->next)
        if (strcmp(s, p->name) == 0)
            return p;
    return 0;
}
示例#4
0
struct defn *
lookup_define(char *s)
{
    struct defn *p;
    int h;

    h = defhash(s);
    for (p = defns[h]; p; p = p->next)
	if (!p->undef && strcmp(s, p->name) == 0)
	    return p;
    return 0;
}
示例#5
0
static void add_define P3(char *, name, int, nargs, char *, exps)
{
    defn_t *p = lookup_definition(name);
    int h;

    if (p) {
	if (p->flags & DEF_IS_UNDEFINED) {
	    p->exps = (char *)DREALLOC(p->exps, strlen(exps) + 1, TAG_COMPILER, "add_define: redef");
	    strcpy(p->exps, exps);
	    p->flags = 0;
	    p->nargs = nargs;
	} else {
	    if (p->flags & DEF_IS_PREDEF) {
		yyerror("Illegal to redefine predefined value.");
		return;
	    }
	    if (nargs != p->nargs || strcmp(exps, p->exps)) {
		char buf[200 + NSIZE];
		
		sprintf(buf, "redefinition of #define %s\n", name);
		yywarn(buf);
		
		p->exps = (char *)DREALLOC(p->exps, strlen(exps) + 1, TAG_COMPILER, "add_define: redef");
		strcpy(p->exps, exps);
		p->nargs = nargs;
	    }
#ifndef LEXER
	    p->flags &= ~DEF_IS_NOT_LOCAL;
#endif
	}
    } else {
	p = ALLOCATE(defn_t, TAG_COMPILER, "add_define: def");
	p->name = (char *) DXALLOC(strlen(name) + 1, TAG_COMPILER, "add_define: def name");
	strcpy(p->name, name);
	p->exps = (char *) DXALLOC(strlen(exps) + 1, TAG_COMPILER, "add_define: def exps");
	strcpy(p->exps, exps);
	p->flags = 0;
	p->nargs = nargs;
	h = defhash(name);
	p->next = defns[h];
	defns[h] = p;
    }
}