PERFORCE change 104562 for review

Spencer Whitman swhitman at FreeBSD.org
Sat Aug 19 20:12:06 UTC 2006


http://perforce.freebsd.org/chv.cgi?CH=104562

Change 104562 by swhitman at swhitman_joethecat on 2006/08/19 20:11:34

	More work on macro replacment.

Affected files ...

.. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/cpp.c#18 edit

Differences ...

==== //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/cpp.c#18 (text+ko) ====

@@ -191,49 +191,34 @@
 	fprintf(stderr, "PRAGMA: <%V>\n", String(b, e));
 }
 
-#if 0
-
 static const char *
-replace_word(const char * word) {
+replace_word(const char * word, const char * newend) {
 
+  /* XXX set new end to the end of the string */
   struct define * tmp;
   
   TAILQ_FOREACH(tmp, &define, list) { 
-    if (String(word,NULL) == (tmp->name)) {
+    if (word == (tmp->name)) {
       return (tmp->value);
     }
   }  
   return word;
 }
 
+/* Puts the begining of the first word from begin in s and the end in e */
+static void
+grab_word(const char * begin, const char * end, const char * s, const char * e)
+{
+  const char * tmp;
+  s = e = NULL; 
+  for(tmp = begin; tmp < end; tmp++) {
+    /* Find the first char of an identifier */
+    /* Check if the identifier could be a macro */
+    /* Stop if it can, continue if it can't */
+  }
 
-static const char *
-expand_macro(struct define * mac, struct arg_ind * head) {
-  
-}
-
-
-static const char *
-get_name(const char * word) {
-  const char e = strstr(word,"(");
-  if(e == NULL)
-    return word;
-      
-  return String(word,e);
-}
-
-static const char *
-get_arg(const char * word) {
-  const char e = NULL;
 }
 
-static const char *
-expand_string(const char * str) {
-  
-}
-
-#endif
-
 /* -------------------------------------------------------------------*/
 
 static void
@@ -244,16 +229,28 @@
   assert(e != NULL);
   if (s == e)
     return;
-  
-  /* Expand any macros before passing String(s,e) to the lexer */
-  
-  /* Search through and grab each word to test if it is a macro */
-  for(;;) {
-    break;
+
+  const char * curr;
+  const char * tempstart = NULL;
+  const char * tempend = NULL;
+  const char * new_end = NULL;
+  const char * new_word;
+
+  for(curr = s; curr < e; curr++) {
+    /* Search through and grab each word to test if it is a macro */
+    grab_word(curr,e,tempstart,tempend);
+    new_word = replace_word(String(tempstart,tempend), newend);
+    
+    if(new_word == tempstart) { /* Didn't macro expand, this string is ready to lex */
+      D(0x10, "expand   <%V>\n", String(s, e));
+      Lexer(cfs->h->tokens, s, e);
+    } else  /* We did some expansions.  Re expand the expanded output */
+      cpp_expand(cfs,rr,new_word,new_end); /* XXX This does not catch recursive macro's */
+                                           /* XXX So #define FOO FOO will cause this to */
+                                           /* XXX loop forever */
+    curr = tempend; 
   }
 
-  D(0x10, "expand   <%V>\n", String(s, e));
-  Lexer(cfs->h->tokens, s, e);
 }
 
 /* -------------------------------------------------------------------*/


More information about the p4-projects mailing list