From owner-p4-projects@FreeBSD.ORG Fri Jul 21 01:36:17 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 5D35716A4E2; Fri, 21 Jul 2006 01:36:17 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2236F16A4E0 for ; Fri, 21 Jul 2006 01:36:17 +0000 (UTC) (envelope-from swhitman@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id BE48643D49 for ; Fri, 21 Jul 2006 01:36:16 +0000 (GMT) (envelope-from swhitman@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k6L1aGDm085997 for ; Fri, 21 Jul 2006 01:36:16 GMT (envelope-from swhitman@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k6L1aGud085994 for perforce@freebsd.org; Fri, 21 Jul 2006 01:36:16 GMT (envelope-from swhitman@FreeBSD.org) Date: Fri, 21 Jul 2006 01:36:16 GMT Message-Id: <200607210136.k6L1aGud085994@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to swhitman@FreeBSD.org using -f From: Spencer Whitman To: Perforce Change Reviews Cc: Subject: PERFORCE change 102041 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Jul 2006 01:36:17 -0000 http://perforce.freebsd.org/chv.cgi?CH=102041 Change 102041 by swhitman@swhitman_joethecat on 2006/07/21 01:35:20 Added struct and struct head for argument list (more work on #define) (NOTE: the current submission does not compile) Affected files ... .. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/cpp.c#13 edit .. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/string.c#8 edit Differences ... ==== //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/cpp.c#13 (text+ko) ==== @@ -30,33 +30,44 @@ #define MAX_DEPTH 64 struct iarg { - const char *dir; - TAILQ_ENTRY(iarg) list; + const char *dir; + TAILQ_ENTRY(iarg) list; }; struct cppfilestate { - struct h *h; - int iflevel; - int elsestate[MAX_DEPTH]; - int off; - const char *hash; - const char *s, *e; - struct ref *r; + struct h *h; + int iflevel; + int elsestate[MAX_DEPTH]; + int off; + const char *hash; + const char *s, *e; + struct ref *r; +}; + +/* XXX This should prob be optimized to a tree or hash table but should work for now */ +struct macro_arg { + const char *name; /* Argument name */ + TAILQ_ENTRY(macro_arg) list; /* Entry into the argument list */ }; +TAILQ_HEAD(args_list_head, macro_arg); /* Macro argument list head */ + #define OBJ_MAC_TYPE 0/* For object like macros (no paraens, no arguments) */ #define FUNC_MAC_TYPE 1/* For function like macros (paraens and arguments) */ #define NONE_MAC_TYPE -1/* Inital value. Indecates type was not set */ struct define { const char *name; /* Name of the macro */ int mac_type; /* Object or function like macro */ - /* Arguments of the macro */ - /* Value of the macro */ - TAILQ_ENTRY(defines) list; /* Link to list of macros */ + struct args_list_head *args; /* Head of argument list */ + const char *value; /* Value of the macro */ + TAILQ_ENTRY(define) list; /* Link to list of macros */ }; + +#define INIT_DEF_ARG(def) *((def)->args) = { NULL, ((def)->args).tqh_first } //TAILQ_HEAD_INITIALIZER((def)->args) + static TAILQ_HEAD(,iarg) iarg = TAILQ_HEAD_INITIALIZER(iarg); -static TAILQ_HEAD(,defines) defines = TAILQ_HEAD_INITIALIZER(defines); +static TAILQ_HEAD(,define) define = TAILQ_HEAD_INITIALIZER(define); static void cppfile(struct h *h, struct ref *r); static void cpp_expand(struct cppfilestate *cfs, struct ref *r, @@ -206,42 +217,51 @@ static void cpp_include(CPP_ARGS) { - const char *p; - struct sourcefile *sf; - struct ref *r; + const char *p; + struct sourcefile *sf; + struct ref *r; + + r = NewRef(cfs->h); + r->type = INCL; + r->ref.b = h; + r->ref.e = e; + r->ref.r = cfs->r; + b = skipspace(cfs, b, e); + if (*b == '<') { + for (p = b + 1; p < e && *p != '>'; p++) + continue; + if (p >= e) + errx(1, "#include: filename missing '>'"); + p = String(b + 1, p); + sf = cpp_include_path(p); + if (sf == NULL) + errx(1, "#include: <%s> file not found", p); + } else if (*b == '"') { + for (p = b + 1; p < e && *p != '"'; p++) + continue; + if (p >= e) + errx(1, "#include: filename missing '\"'"); + p = String(b + 1, p); + sf = LoadFile(p); + if (sf == NULL) + sf = cpp_include_path(p); + if (sf == NULL) + errx(1, "#include: \"%s\" file not found", p); + } else + errx(1, "#include: filename must be in <..> or \"...\""); + r->sf = sf; + r->s = sf->s; + cppfile(cfs->h, r); +} + - r = NewRef(cfs->h); - r->type = INCL; - r->ref.b = h; - r->ref.e = e; - r->ref.r = cfs->r; - b = skipspace(cfs, b, e); - if (*b == '<') { - for (p = b + 1; p < e && *p != '>'; p++) - continue; - if (p >= e) - errx(1, "#include: filename missing '>'"); - p = String(b + 1, p); - sf = cpp_include_path(p); - if (sf == NULL) - errx(1, "#include: <%s> file not found", p); - } else if (*b == '"') { - for (p = b + 1; p < e && *p != '"'; p++) - continue; - if (p >= e) - errx(1, "#include: filename missing '\"'"); - p = String(b + 1, p); - sf = LoadFile(p); - if (sf == NULL) - sf = cpp_include_path(p); - if (sf == NULL) - errx(1, "#include: \"%s\" file not found", p); - } else - errx(1, "#include: filename must be in <..> or \"...\""); - r->sf = sf; - r->s = sf->s; - cppfile(cfs->h, r); -} +/* Pass this function a string to expand any and all macros */ +/*static void +cpp_macro_expand(const char *b __unused, const char *e __unused) +{ + + +}*/ /* @@ -256,7 +276,8 @@ cpp_add_define(const char *b, const char *e) { struct define *mac; - + struct define *tmp; + const char * name_b = b; const char * name_e; const char * p = b; @@ -273,7 +294,7 @@ /* XXX This is ugly; any better way to do this? */ ((name_e + 1 < e) && ((name_e[1] == '\\') && (name_e[2] == 's')))) { - printf("Defining object macro name %V\n",p); + printf("1Defining object macro name %V\n",String(name_b,name_e)); mac->mac_type = OBJ_MAC_TYPE; break; } @@ -288,32 +309,56 @@ } p = String(name_b,name_e); - if(isspace(*p) || *p == '\0') + if(isspace(*p) || *p == '\0') { + free(mac); errx(1, "no macro name given in #define directive"); + } mac->name = p; if(mac->mac_type == NONE_MAC_TYPE) { - printf("Defining object macro name %V\n", p); + printf("2Defining object macro name %V\n", p); mac->mac_type = OBJ_MAC_TYPE; } switch (mac->mac_type) { + case OBJ_MAC_TYPE: + mac->value = String(name_e,e); break; case FUNC_MAC_TYPE: - { + /* Make sure function macro is wellformed (has a matching ')', arguments * are correct, etc.) Add arguments to mac. */ + //INIT_DEF_ARG(mac); + //*(mac->args) = TAILQ_HEAD_INITIALIZER(*(mac->args)); + //TAILQ_INIT(mac->args); + /* do { + printf("here\n"); + ((mac->args))->tqh_first = NULL; + printf("1\n"); + (mac->args)->tqh_last = &TAILQ_FIRST((mac->args)); + printf("2\n"); + QMD_TRACE_HEAD(mac->args); + printf("3\n"); + } while (0);*/ - - } break; + default: break; } + /* Add this macro to the defined list */ + TAILQ_FOREACH(tmp, &define, list) { + if(tmp == NULL) { + TAILQ_INSERT_TAIL(&define, mac, list); + break; + } + + } + } @@ -333,15 +378,23 @@ } - +/* Note: The "#define" has already been stripped at this point */ static void cpp_define(CPP_ARGS) { /* struct cppfilestate *cfs __unused, const char *h __unused, const char *b __unused, const char *e __unused */ - printf("#define of %V\n",String(b,e)); + struct ref *r; + r = NewRef(cfs->h); + r->type = MACRO; + r->ref.b = h; + r->ref.e = e; + r->ref.r = cfs->r; + + printf("#define of %V\n",String(b,e)); + /* The first token is the macro name */ cpp_add_define(skipspace(cfs, b, e),e); @@ -423,7 +476,7 @@ cppchunk(cfs, NULL, NULL); - /* We must be looking at a preparcessor macro */ + /* We must be looking at a preparcessor command */ assert(*p == '#'); cfs->hash = s; /* Ignore unwanted whitespace */ @@ -436,22 +489,25 @@ D(1, "line <%V>\n", String(p, e)); - /* Scan thru the preprocessor keywords */ + /* Scan through the preprocessor keywords */ for (kw = cpp_kw; kw->q != NULL; kw++) { - if (*p < *kw->q) - break; - if (p + kw->l > e) - continue; - if (isident(p[kw->l])) - continue; - if (memcmp(kw->q, p, kw->l)) - continue; - p += kw->l; - /* If it exists, execute cpp function */ - if (kw->func != NULL) - kw->func(cfs, cfs->hash, p, e); - cfs->hash = NULL; - return; + /* XXX I don't understand this case; taking i out seems to work */ + /*if (*p < *kw->q) { + printf("%s<%s\n",p,kw->q); + break; + }*/ + if (p + kw->l > e) + continue; + if (isident(p[kw->l])) + continue; + if (memcmp(kw->q, p, kw->l)) + continue; + p += kw->l; + /* If it exists, execute cpp function */ + if (kw->func != NULL) + kw->func(cfs, cfs->hash, p, e); + cfs->hash = NULL; + return; } cfs->hash = NULL; ==== //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/string.c#8 (text+ko) ====