PERFORCE change 102377 for review
Spencer Whitman
swhitman at FreeBSD.org
Tue Jul 25 15:27:53 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=102377
Change 102377 by swhitman at swhitman_joethecat on 2006/07/25 15:27:03
Minor additions to #define processing
Affected files ...
.. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/cpp.c#15 edit
Differences ...
==== //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/cpp.c#15 (text+ko) ====
@@ -44,17 +44,12 @@
struct ref *r;
};
-/* XXX These should be optimized, but work for now */
-/* Each argument has a list of indexes of where it appears in the macro string */
-struct arg_ind {
- int offset;
- TAILQ_ENTRY(arg_ind) list;
-};
-
+/* XXX This should be optimized, but works for now */
struct macro_arg {
const char *name; /* Argument name */
- TAILQ_HEAD(,arg_ind) offsets; /* Offset list */
+ int length /* Length of the arg name */
+ int *offsets; /* Offset list */
TAILQ_ENTRY(macro_arg) list; /* Entry into the argument list */
};
@@ -66,11 +61,16 @@
int mac_type; /* Object or function like macro */
TAILQ_HEAD(,macro_arg) args; /* Head of argument list */
const char *value; /* Value of the macro */
+ int length; /* Length of the macro value */
TAILQ_ENTRY(define) list; /* Link to list of macros */
};
-/* XXX Implement this */
-#define FREE_LIST(HEAD,TYPE) do { \
+#define FREE_LIST(HEAD,TYPE,LIST) do { \
+ (TYPE) * tmpvar; \
+ TAILQ_FOREACH(tmpvar, (HEAD), LIST) { \
+ TAILQ_REMOVE(tmpvar, (HEAD), LIST); \
+ free(tmpvar); \
+ } \
}while(0)
static TAILQ_HEAD(,iarg) iarg = TAILQ_HEAD_INITIALIZER(iarg);
@@ -271,9 +271,9 @@
}
static void
-calculate_offsets(struct macro_arg *arg, struct define * mac __unused)
+calculate_offsets(struct macro_arg *arg __unused, struct define * mac __unused)
{
- TAILQ_INIT(&arg->offsets);
+
/* XXX Use strstr to find substrings of arg in mac */
}
@@ -303,6 +303,8 @@
}
}
+ new_arg->length = strlen(new_arg->name);
+
calculate_offsets(new_arg,mac);
printf("added argument named: <%V> to macro named <%V>\n",new_arg->name,
@@ -394,7 +396,7 @@
/* Macro was ill-formed. Free everything and exit with error */
if(*p != ')') {
- /* XXX Free everything */
+ FREE_LIST(&mac->args, struct macro_args, list);
free(mac);
errx(1, "Function macro has no ending \')\'");
}
@@ -405,13 +407,17 @@
break;
}
+ mac->length = strlen(mac->value);
+
/* Add this macro to the defined list */
TAILQ_FOREACH(tmp, &define, list) {
if(tmp == NULL) {
TAILQ_INSERT_TAIL(&define, mac, list);
break;
}
-
+ /* Warn if redefining a previous definition */
+ if(tmp->name == mac->name)
+ cpp_warning(cfs,NULL,b,e);
}
}
More information about the p4-projects
mailing list