Date: Sat, 15 Jul 2006 16:31:31 GMT From: Spencer Whitman <swhitman@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 101656 for review Message-ID: <200607151631.k6FGVVDK082389@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=101656 Change 101656 by swhitman@swhitman_joethecat on 2006/07/15 16:30:42 More work on #define and #undef. Also added function shell for define and include list initail population (for defaults). Affected files ... .. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/cpp.c#11 edit .. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/k.c#11 edit .. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/k.h#8 edit Differences ... ==== //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/cpp.c#11 (text+ko) ==== @@ -44,11 +44,15 @@ struct ref *r; }; +#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) */ + struct define { - const char *name; /* Name of the macro */ - /* Arguments of the macro */ - /* Value of the macro */ - TAILQ_ENTRY(defines) list; /* Link to list of macros */ + 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 */ }; static TAILQ_HEAD(,iarg) iarg = TAILQ_HEAD_INITIALIZER(iarg); @@ -171,7 +175,7 @@ /* -------------------------------------------------------------------*/ static struct sourcefile * -cpp_include_path(const char *fn) +cpp_include_path(const char *filename) { struct iarg *ap; struct sourcefile *sf; @@ -179,7 +183,7 @@ sf = NULL; TAILQ_FOREACH(ap, &iarg, list) { - asprintf(&q, "%s/%s", ap->dir, fn); + asprintf(&q, "%s/%s", ap->dir, filename); assert(q != NULL); sf = LoadFile(q); free(q); @@ -189,6 +193,16 @@ return (sf); } +/* + * Initalize the include list (if necessary) and add default include paths + */ +static void +cpp_init_includes(void) +{ + +} + + static void cpp_include(CPP_ARGS) { @@ -229,42 +243,91 @@ cppfile(cfs->h, r); } + /* + * This function attempts to add a define specified by b and e to the define list * Define statment should be of the form: * #define NAME(vars) value - * If it continues along more than one line, the line should end with a \\n - * (this may already be taken care of). vars and value are both optional. + * If it continues along more than one line, the line should end with a \\n (backslash + * newline) (this may already be taken care of ?). vars and value are both optional. */ static void -cpp_define(CPP_ARGS) +cpp_add_define(const char *b, const char *e) { - /* struct cppfilestate *cfs __unused, const char *h __unused, - const char *b __unused, const char *e __unused */ - const char * name_b; + struct define *mac; + + const char * name_b = b; const char * name_e; - - printf("#define of %V\n",String(b,e)); - - /* The first token is the macro name */ - name_b = skipspace(cfs, b, e); - + const char * p = b; + + mac = malloc(sizeof *mac); + assert(mac != NULL); + /* Find the end of the name by finding the first white space char or '(' */ for(name_e = name_b; (name_e < e); name_e++) { /* Object like macro */ if ((isspace(*name_e)) || /* 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",String(name_b,name_e)); + printf("Defining object macro name %V\n",p); + mac->mac_type = OBJ_MAC_TYPE; + break; } /* Function like macro */ else if (*name_e == '(') { printf("Defining function macro name %V\n",String(name_b,name_e)); + mac->mac_type = FUNC_MAC_TYPE; + break; } else continue; } + /* XXX check for failure of either case */ + p = String(name_b,name_e); + mac->name = p; + switch (mac->mac_type) { + case OBJ_MAC_TYPE: + + case FUNC_MAC_TYPE: + /* Make sure function macro is wellformed (has a matching ')', arguments are correct, + * etc.) Add arguments to mac. + */ + default: + break; + } + +} + + +static void +cpp_remove_define(const char *name) +{ + printf("Removing macro %s\n",name); +} + +/* + * Initalize the define list (if necessary) and add built in #defines + */ +static void +cpp_init_defines(void) +{ + + +} + + +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)); + + /* The first token is the macro name */ + cpp_add_define(skipspace(cfs, b, e),e); + } static void @@ -274,6 +337,7 @@ const char *b __unused, const char *e __unused */ printf("#undef of %V\n",String(b,e)); + cpp_remove_define(String(b,e)); } static void @@ -431,7 +495,7 @@ } /* -------------------------------------------------------------------*/ - +/* XXX What if -I is used for a file not just a directory? */ void CppIarg(const char *incldir) { @@ -449,9 +513,27 @@ } void -CppDUarg(struct h *h __unused, const char *defn __unused, int def __unused) +CppDUarg(struct h *h __unused, const char *defn, int def) { + const char *p; + assert(defn != NULL); + + p = defn; + if (p[0] == '-' && (p[1] == 'D' || p[1] == 'U')) + p += 2; + /* Find the begining and end of defn */ + + switch(def) { + case DEF: + /* Send it to cpp_add_define() */ + break; + case UNDEF: + /* Send it to cpp_remove_define() */ + break; + default: + errx(1,"Unkown option %i passed as def to CppDUarg", def); + } } @@ -466,6 +548,13 @@ } + /* XXX Should these be here? or maybe in k, only want to do this once ever */ + /* Initalize the include list */ + cpp_init_includes(); + + /* Initalize the define list */ + cpp_init_defines(); + h->r = NewRef(h); h->r->type = ARG; h->r->sf = LoadFile(filename); ==== //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/k.c#11 (text+ko) ==== @@ -130,8 +130,8 @@ CppIarg("-I/usr/include"); #endif /* Get command line arguments - * D: Not implemented - * U: Not implemented + * D: Define macro optarg + * U: Undefine macro optarg * I: Include file optarg * W: Not implemented * c: Not implemented @@ -139,8 +139,8 @@ */ while ((ch = getopt(argc, argv, "cD:U:I:W:")) != -1) { switch (ch) { - case 'D': CppDUarg(hg, optarg, 1); break; - case 'U': CppDUarg(hg, optarg, 0); break; + case 'D': CppDUarg(hg, optarg, DEF); break; + case 'U': CppDUarg(hg, optarg, UNDEF); break; case 'I': CppIarg(optarg); break; case 'W': case 'c': ==== //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/k.h#8 (text+ko) ==== @@ -110,6 +110,10 @@ /* -------------------------------------------------------------------*/ +/* def flags for CppDUarg function */ +#define UNDEF 0 +#define DEF 1 + /* cpp.c */ void CppIarg(const char *incldir); void CppDUarg(struct h *, const char *defn, int def);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200607151631.k6FGVVDK082389>