PERFORCE change 101786 for review
Spencer Whitman
swhitman at FreeBSD.org
Mon Jul 17 18:55:08 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=101786
Change 101786 by swhitman at swhitman_joethecat on 2006/07/17 18:54:10
More work on #define
Affected files ...
.. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/cpp.c#12 edit
.. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/k.h#9 edit
.. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/string.c#7 edit
Differences ...
==== //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/cpp.c#12 (text+ko) ====
@@ -44,9 +44,9 @@
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) */
-
+#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 */
@@ -245,11 +245,12 @@
/*
- * This function attempts to add a define specified by b and e to the define list
- * Define statment should be of the form:
+ * This function attempts to add a define specified by b and e to the define
+ * list. Define statments should be of the form:
* #define NAME(vars) value
- * 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.
+ * 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_add_define(const char *b, const char *e)
@@ -262,13 +263,16 @@
mac = malloc(sizeof *mac);
assert(mac != NULL);
+
+ mac->mac_type = NONE_MAC_TYPE;
/* 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')))) {
+ ((name_e + 1 < e) &&
+ ((name_e[1] == '\\') && (name_e[2] == 's')))) {
printf("Defining object macro name %V\n",p);
mac->mac_type = OBJ_MAC_TYPE;
break;
@@ -282,17 +286,30 @@
else
continue;
}
- /* XXX check for failure of either case */
+
p = String(name_b,name_e);
+ if(isspace(*p) || *p == '\0')
+ 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);
+ mac->mac_type = OBJ_MAC_TYPE;
+ }
switch (mac->mac_type) {
case OBJ_MAC_TYPE:
+ break;
case FUNC_MAC_TYPE:
- /* Make sure function macro is wellformed (has a matching ')', arguments are correct,
- * etc.) Add arguments to mac.
- */
+ {
+ /* Make sure function macro is wellformed (has a matching ')', arguments
+ * are correct, etc.) Add arguments to mac.
+ */
+
+
+ }
+ break;
default:
break;
}
==== //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/k.h#9 (text+ko) ====
@@ -161,7 +161,7 @@
void Coord(struct h *h, const char *b, const char *e, unsigned *line, const char **file);
unsigned BackSlash(const char *p, const char **n);
const char *StringEnd(const char *s, const char *e);
-
+/*const char *ParenEnd(const char *ptr, const char *ep);*/
/* symbol.c */
struct symbol *NewSymbol(struct sym_scope *scope, enum symspace spc, const char *t);
==== //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/string.c#7 (text+ko) ====
@@ -193,6 +193,21 @@
}
}
+/*
+const char *
+ParenEnd(const char *ptr, const char *ep)
+{
+ const char * p;
+
+ for(p = ptr +1; p < ep; p++) {
+ if(*p == ')')
+ return (p + 1);
+ }
+
+ return NULL;
+}
+*/
+
const char *
StringEnd(const char *ptr, const char *ep)
{
More information about the p4-projects
mailing list