Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 7 Jul 2006 02:18:45 GMT
From:      Spencer Whitman <swhitman@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 100829 for review
Message-ID:  <200607070218.k672IjrU079142@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=100829

Change 100829 by swhitman@swhitman_joethecat on 2006/07/07 02:18:24

	More commenting and debugging.  Started the #define macro 	function.

Affected files ...

.. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/cpp.c#7 edit
.. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/k.c#8 edit
.. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/k.h#6 edit
.. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/lexer.c#6 edit
.. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/string.c#6 edit
.. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/test.c#5 edit
.. //depot/projects/soc2006/swhitman-K_Kernel_Meta-Language/k/test.h#1 add

Differences ...

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

@@ -47,11 +47,14 @@
 static TAILQ_HEAD(,iarg) iarg = TAILQ_HEAD_INITIALIZER(iarg);
 
 static void cppfile(struct h *h, struct ref *r);
-static void cpp_expand(struct cppfilestate *cfs, struct ref *r, const char *s, const char *e);
+static void cpp_expand(struct cppfilestate *cfs, struct ref *r, 
+		       const char *s, const char *e);
 
-typedef void (cpp_func)(struct cppfilestate *, const char *, const char *, const char *);
+typedef void (cpp_func)(struct cppfilestate *, const char *, const char *, 
+			const char *);
 
-#define CPP_ARGS struct cppfilestate *cfs __unused, const char *h __unused, const char *b __unused, const char *e __unused
+#define CPP_ARGS struct cppfilestate *cfs __unused, const char *h __unused, \
+    const char *b __unused, const char *e __unused
 
 const char *mag_line, *mag_file;
 
@@ -153,7 +156,6 @@
   if (s == e)
     return;
   D(0x10, "expand   <%V>\n", String(s, e));
-  /* XXX HERE */
   Lexer(cfs->h->tokens, s, e);
 }
 
@@ -219,6 +221,14 @@
 }
 
 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));
+}
+
+static void
 cppchunk(struct cppfilestate *cfs, const char *s, const char *e)
 {
   /* NOTE: cfs-> is uninitalized for first call to cppchunk */
@@ -227,7 +237,6 @@
     return;
   }
   if (cfs->s != NULL)
-    /* XXX HERE */
     cpp_expand(cfs, cfs->r, cfs->s, cfs->e);
   cfs->s = s;
   cfs->e = e;
@@ -239,12 +248,12 @@
   unsigned	l;    /* Length of key word */
   cpp_func	*func;
 } cpp_kw[] = {
-  { "define",		0,	NULL		},
+  { "define",		0,	cpp_define	},
   { "error",		0,	cpp_error	},
   { "include",		0,	cpp_include	},
   { "pragma",		0,	cpp_pragma	},
   { "warning",		0,	cpp_warning	},
-  { NULL,			0,	NULL		}
+  { NULL,		0,	NULL		}
 };
 
 static void
@@ -268,18 +277,20 @@
 	   * pointing to a preparser function...
 	   */
 	  if (p >= e || *p != '#') {
-	    /* XXX off from cppfilestate is only used here and will always be 
-	       true */
+	    /* XXX "off" from cppfilestate is only used here so this will 
+	       always be true */
 	    if (!cfs->off) 
-	      /* XXX HERE */
 	      cppchunk(cfs, s, e);
+	    
 	    return;
 	  }
 
 	  cppchunk(cfs, NULL, NULL);
 	  
+	  /* We must be looking at a preparcessor macro */
 	  assert(*p == '#');
 	  cfs->hash = s;
+	  /* Ignore unwanted whitespace */
 	  p = skipspace(cfs, p + 1, e);
 	  e = trimspace(p, e);
 	  if (p == e) {
@@ -288,6 +299,8 @@
 	} 
 	
 	D(1, "line     <%V>\n", String(p, e));
+	
+	/* Scan thru the preprocessor keywords */
 	for (kw = cpp_kw; kw->q != NULL; kw++) {
 		if (*p < *kw->q)
 			break;
@@ -298,11 +311,13 @@
 		if (memcmp(kw->q, p, kw->l))
 			continue;
 		p += kw->l;
+		/* If it exists, execute cpp function */
 		if (kw->func != NULL)
-			kw->func(cfs, cfs->hash, p, e);
+		  kw->func(cfs, cfs->hash, p, e);
 		cfs->hash = NULL;
 		return;
 	}
+
 	cfs->hash = NULL;
 	if (isdigit(p[0])) /* Ignore "# %d \"%s\" */
 		return;
@@ -343,7 +358,6 @@
 		}
 
 		if (q == e) {
-		  /* XXX HERE */
 		  cppline(&cfs, p, q);		
 		  break;
 		}
@@ -402,7 +416,8 @@
 	h->r->sf = LoadFile(filename);
 	/* set the head refrence s struct to that of the sourcefile's */
 	h->r->s = h->r->sf->s;
+	/* Preprocess the file */
 	cppfile(h, h->r);
-	/* XXX HERE */
+	/* Add acumulated tokens to the lexer */
 	Lexer(h->tokens, NULL, NULL);
 }

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

@@ -1,3 +1,4 @@
+#include <sys/queue.h>
 
 #include <stdio.h>
 #include <unistd.h>
@@ -9,7 +10,6 @@
 #include <inttypes.h>
 #include <wchar.h>
 #include <printf.h>
-#include <sys/queue.h>
 
 #include "k.h"
 
@@ -179,7 +179,6 @@
 	  } else
 	    errx(1, "Unknown filename suffix %Q", p);
 
-	  /* XXX HERE */
 	  Cpp(hf, argv[ch]);
 	  
 	  if (0) 

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

@@ -34,12 +34,12 @@
 
 
 struct token {
-	unsigned		tok;
-	const char		*b, *e;
-	TAILQ_ENTRY(token)	list;
-	const char		*name;
-	struct symbol		*sym;
-	struct token		*chain;
+  unsigned		tok;
+  const char		*b, *e; /* pointers to token in original file */
+  TAILQ_ENTRY(token)  list;
+  const char		*name;
+  struct symbol		*sym;
+  struct token		*chain;
 };
 
 TAILQ_HEAD(tokenhead, token);

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

@@ -1,4 +1,4 @@
-#include <sys/queue.h>
+ #include <sys/queue.h>
 
 #include <stdio.h>
 #include <err.h>
@@ -62,6 +62,8 @@
 	t->tok = tok;
 	t->b = b;
 	t->e = e;
+
+	/* Add this token to the token list */
 	if (tok == CSTR) {
 	  tt = TAILQ_LAST(&ts->tokens, tokenhead);
 	  if (tt != NULL && tt->tok == CSTR) {
@@ -111,6 +113,7 @@
 	if (*ptr != '.') {
 		/* Integer part */
 		if (*ptr == '0' &&
+		    /* Hex, use base 16 */
 		    (ptr[1] == 'x' || ptr[1] == 'X') &&
 		    isxdigit(ptr[2])) {
 			ptr += 2;
@@ -145,31 +148,36 @@
 static const char *
 un_hash(const char *s, const char *e)
 {
-	const char *r;
-	char *p, *q;
-	int same = 1;
-
-	q = p = malloc(1 + (e - s));
-	assert(p != 0);
-	while (s < e) {
-		if (isspace(*s) || *s == '#') {
-			for (r = s; r < e && isspace(*r); r++)
-				continue;
-			if (r + 1 < e && *r == '#' && r[1] == '#') {
-				r += 2;
-				for (; r < e && isspace(*r); r++)
-					continue;
-				s = r;
-				same = 0;
-			}
-		}
-		*q++ = *s++;
-	}
-	*q = '\0';
-	if (!same)
-		return (p);
-	free(p);
-	return (NULL);
+  const char *r;
+  char *p; /*, *q;*/ /* XXX Q seems unneccessary (just a memory leak) */
+  int same = 1;
+  
+  /*q =*/ p = malloc(1 + (e - s));
+  assert(p != 0);
+  
+  while (s < e) {
+    /* XXX Isn't stdc only one '#' ? */
+    if (isspace(*s) || *s == '#') {
+      /* Skip the begining space */
+      for (r = s; r < e && isspace(*r); r++)
+	continue;
+      /* If r is not at the end, and points to "##..." */
+      if (r + 1 < e && *r == '#' && r[1] == '#') {
+	r += 2;
+	/* Skip spaces */
+	for (; r < e && isspace(*r); r++)
+	  continue;
+	s = r;
+	same = 0;
+      }
+    }
+    /**q++ = */ *s++;
+  }
+  /*  *q = '\0'; */
+  if (!same)
+    return (p);
+  free(p);
+  return (NULL);
 }
 
 void
@@ -184,38 +192,50 @@
   unsigned tok;
   struct token *t;
   
+  /* If there is no begining of the file, add whatever tokens we have so far */
   if (b == NULL) {
-    /* XXX HERE */
     add_token(ts, EOI, NULL, NULL);
     return;
   }
+
+  /* Make sure e is well formed */
   if (e == NULL)
     e = strchr(b, '\0');
   assert(e != NULL);
+  
   if (1) {
     printf("LEX1 %V\n", String(b, e));
   }
+
   p = un_hash(b, e);
   if (p != NULL) {
+    /* There were spaces and/or ##s, skip ahead of them */
     b = p;
     e = strchr(b, '\0');
     assert(e != NULL);
   }
+  /* XXX The above doesn't seem to do anything? */
   if (1) {
     printf("LEX2 %V\n", String(b, e));
   }
+
+  /* Lex everything */
   while (b < e) {
     
     switch(*b) {
-    case '\n': case '\r': case '\v': case '\f':
+    case '\n': case '\r': case '\v': case '\f': case '\t': case ' ':
+      /* If newline, return, ?, ?, tab, or space move to the next char */
       b++;
       continue;
+
     case '\\':
+      /* Only continue if "\" is followed by "\n" */
       if (b[1] == '\n') {
 	b += 2;
 	continue;
       }
-      break;
+      break; /* XXX Should this break here? I don't understand this case */
+
     case '/':
       if (b[1] == '*') {
 	/* Ignore comments */
@@ -230,18 +250,18 @@
       if (b[1] == '/')
 	errx(1, "// comment");
       break;
-    case '\t':
-    case ' ':
-      b++;
-      continue;
+      
     case '\'':
+      /* Add a char */      
       if (b[1] != '\\' && b[2] == '\'') {
 	t = add_token(ts, CNUM, b, b + 3);
 				t->name = String(b, b + 3);
 				b += 3;
 				continue;
       }
+      
       if (b[1] == '\\') {
+	/* Determine if it is a valid '\something' char */
 	i = BackSlash(b + 2, &p);
 	if (i >= 0 && *p == '\'') {
 	  p++;
@@ -252,32 +272,41 @@
 	}
       }
       break;
+
     case '"':
+      /* Add a string */
       s = StringEnd(b, e);
       assert(s != NULL);
       printf("Lex: \"%V\"\n", String(b, s));
       t = add_token(ts, CSTR, b, s);
 			b = s;
 			continue;
+
     case '#':
+      /* XXX Not quite sure what this case does */
       printf("# %V\n", String(b, e));
       u = strtoul(b + 1, &q, 0);
       if (q == NULL)
 	errx(1, "Preproc børk1");
+      /* Skip whitespace and if char is >= LOW_TOKEN */
       while (isspace(*q) && !isvert(*q))
 	q++;
+
       if (*q != '"')
 	printf("Preproc børk2 (%02x) %V\n",
 	       *q, String(b, e));
+
       s = StringEnd(q, e);
       posf = String(q, s);
       while (s < e && !isvert(*s))
 	s++;
       b = s;
       continue;
+
     case '.':
     case '0': case '1': case '2': case '3': case '4':
     case '5': case '6': case '7': case '8': case '9':
+      /* Find the end of this number, and add it to the list */
       s = NumberEnd(b);
       if (s != NULL) {
 	t = add_token(ts, CNUM, b, s);
@@ -286,15 +315,21 @@
 	continue;
       }
       break;
+
     default:
       break;
-    }
+    } /* switch(*b) */
+
     tok = fixed_token(b, &s);
+
+    /* If we saw normal token (?) add it to the list */
     if (tok > 0) {
       t = add_token(ts, tok, b, s);
       b = s;
       continue;
     }
+    
+    /* Add this token to the end of the ident1 (XXX Not sure what that is) */
     if (isident1(b[0])) {
       for (p = b + 1; isident(*p); p++)
 	continue;
@@ -303,6 +338,8 @@
       b += (p - b);
       continue;
     }
+
+    /* Failed to recognize what we saw, so exit */
     strncpy(buf, b, 20);
     printf("Unknown: >>>>%V\n", buf);
     exit (0);

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

@@ -199,6 +199,7 @@
 	int i;
 	const char *p, *s;
 
+	/* Return the address of the end of the string */
 	for (p = ptr + 1; p < ep;) {
 		if (*p == '"')
 			return (p + 1);

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

@@ -1,4 +1,4 @@
-
+#include "test.h"
 
 int
 main(int argc, char **argv)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200607070218.k672IjrU079142>