PERFORCE change 101320 for review

Spencer Whitman swhitman at FreeBSD.org
Wed Jul 12 02:45:37 UTC 2006


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

Change 101320 by swhitman at swhitman_joethecat on 2006/07/12 02:44:37

	Work on #define

Affected files ...

.. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/cpp.c#10 edit
.. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/k.c#10 edit
.. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/k.h#7 edit
.. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/lexer.c#8 edit

Differences ...

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

@@ -45,7 +45,10 @@
 };
 
 struct define {
-  TAILQ_ENTRY(defines)           list;
+  const char                     *name; /* Name of the 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);
@@ -88,23 +91,23 @@
 static const char *
 skipspace(struct cppfilestate *cfs, const char *s, const char *e)
 {
-	/* skip leading spaces, including line continuation */
-	while (s < e) {
-	  /* XXX This code will choke on single \'s or /'s */
-	  /* XXX Not sure if this is what needs to be edited */
-	  if (*s == '\\' && s + 1 < e && isvert(s[1])) {
-	    s++;
-	    continue;
-	  }
-	  if (*s == '/') {
-	    s = skipcomment(cfs, s, e);
-	    s++;
-	  }
-	  if (!isspace(*s))
-	    break;
-	  s++;
-	}
-	return (s);
+  /* skip leading spaces, including line continuation */
+  while (s < e) {
+    /* XXX This code will choke on single \'s or /'s */
+    /* XXX Not sure if this is what needs to be edited */
+    if (*s == '\\' && s + 1 < e && isvert(s[1])) {
+      s++;
+      continue;
+    }
+    if (*s == '/') {
+      s = skipcomment(cfs, s, e);
+      s++;
+    }
+    if (!isspace(*s))
+      break;
+    s++;
+  }
+  return (s);
 }
 
 static const char *
@@ -229,14 +232,39 @@
 /*
  * Define statment should be of the form:
  * #define NAME(vars) value
- * If value continues along more than one line, it should end with a \\n
+ * 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.
  */
 static void
 cpp_define(CPP_ARGS)
 {
   /*  struct cppfilestate *cfs __unused, const char *h __unused, 
       const char *b __unused, const char *e __unused */
+  const char * name_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);
+  
+  /* 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));
+    }
+    /* Function like macro */
+    else if (*name_e == '(') {
+      printf("Defining function macro name %V\n",String(name_b,name_e));
+    }
+    else
+      continue;
+  }
+  
 }
 
 static void
@@ -245,6 +273,7 @@
   /*  struct cppfilestate *cfs __unused, const char *h __unused, 
       const char *b __unused, const char *e __unused */
   printf("#undef of %V\n",String(b,e));
+
 }
 
 static void

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


==== //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/k.h#7 (text+ko) ====


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

@@ -149,7 +149,7 @@
 un_hash(const char *s, const char *e)
 {
   const char *r;
-  char *p; /*, *q;*/ /* XXX Q seems unneccessary (just a memory leak) */
+  char *p; /*, *q;*/ /* XXX q seems unneccessary (just a memory leak) */
   int same = 1;
   
   /*q =*/ p = malloc(1 + (e - s));
@@ -283,7 +283,7 @@
 			continue;
 
     case '#':
-      /* XXX Not quite sure what this case does */
+      /* Stringification (?) */
       printf("# %V\n", String(b, e));
       u = strtoul(b + 1, &q, 0);
       if (q == NULL)


More information about the p4-projects mailing list