PERFORCE change 100539 for review

Spencer Whitman swhitman at FreeBSD.org
Tue Jul 4 03:54:25 UTC 2006


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

Change 100539 by swhitman at swhitman_joethecat on 2006/07/04 03:53:22

	More commenting.  (The "XXX HERE" comments are placemarks)

Affected files ...

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

Differences ...

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

@@ -4,6 +4,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
+
 #include "k.h"
 
 #undef CPP_DEBUG
@@ -55,7 +56,9 @@
 const char *mag_line, *mag_file;
 
 /* -------------------------------------------------------------------*/
-
+/* Returns pointer to the end of a (potential) comment starting at b and ending
+ * before e 
+ */
 static const char *
 skipcomment(struct cppfilestate *cfs, const char *b, const char *e)
 {
@@ -71,23 +74,27 @@
 }
 
 /* -------------------------------------------------------------------*/
-
+/* Returns a pointer to first non whitespace, non comment character after s but
+ * before e 
+ */
 static const char *
 skipspace(struct cppfilestate *cfs, const char *s, const char *e)
 {
-	/* skip leading space, including line continuation */
+	/* skip leading spaces, including line continuation */
 	while (s < e) {
-		if (*s == '\\' && s + 1 < e && isvert(s[1])) {
-			s++;
-			continue;
-		}
-		if (*s == '/') {
-			s = skipcomment(cfs, s, e);
-			s++;
-		}
-		if (!isspace(*s))
-			break;
-		s++;
+	  /* 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);
 }
@@ -141,12 +148,13 @@
 cpp_expand(struct cppfilestate *cfs, struct ref *rr __unused, const char *s, const char *e)
 {
 
-	assert(s != NULL);
-	assert(e != NULL);
-	if (s == e)
-		return;
-	D(0x10, "expand   <%V>\n", String(s, e));
-	Lexer(cfs->h->tokens, s, e);
+  assert(s != NULL);
+  assert(e != NULL);
+  if (s == e)
+    return;
+  D(0x10, "expand   <%V>\n", String(s, e));
+  /* XXX HERE */
+  Lexer(cfs->h->tokens, s, e);
 }
 
 /* -------------------------------------------------------------------*/
@@ -213,29 +221,30 @@
 static void
 cppchunk(struct cppfilestate *cfs, const char *s, const char *e)
 {
-
-	if (s != NULL && s == cfs->e) {
-		cfs->e = e;
-		return;
-	}
-	if (cfs->s != NULL)
-		cpp_expand(cfs, cfs->r, cfs->s, cfs->e);
-	cfs->s = s;
-	cfs->e = e;
+  /* NOTE: cfs-> is uninitalized for first call to cppchunk */
+  if (s != NULL && s == cfs->e) {
+    cfs->e = e;
+    return;
+  }
+  if (cfs->s != NULL)
+    /* XXX HERE */
+    cpp_expand(cfs, cfs->r, cfs->s, cfs->e);
+  cfs->s = s;
+  cfs->e = e;
 }
 
 
 static struct cpp_kw {
-	const char	*q;
-	unsigned	l;
-	cpp_func	*func;
+  const char	*q;
+  unsigned	l;    /* Length of key word */
+  cpp_func	*func;
 } cpp_kw[] = {
-	{ "define",		0,	NULL		},
-	{ "error",		0,	cpp_error	},
-	{ "include",		0,	cpp_include	},
-	{ "pragma",		0,	cpp_pragma	},
-	{ "warning",		0,	cpp_warning	},
-	{ NULL,			0,	NULL		}
+  { "define",		0,	NULL		},
+  { "error",		0,	cpp_error	},
+  { "include",		0,	cpp_include	},
+  { "pragma",		0,	cpp_pragma	},
+  { "warning",		0,	cpp_warning	},
+  { NULL,			0,	NULL		}
 };
 
 static void
@@ -244,6 +253,7 @@
 	const char *p;
 	struct cpp_kw *kw;
 
+	/* Set up length argument for cpp_kw[] if necessary */
 	if (cpp_kw[0].l == 0) 
 		for (kw = cpp_kw; kw->q != NULL; kw++) 
 			kw->l = strlen(kw->q);
@@ -252,23 +262,31 @@
 
 	/* skip leading space, including line continuation */
 	p = skipspace(cfs, s, e);
+	
 	if (!cfs->hash) {
-		if (p >= e || *p != '#') {
-			if (!cfs->off)
-				cppchunk(cfs, s, e);
-			return;
-		}
-		cppchunk(cfs, NULL, NULL);
+	  /* If we have reached the end of the mmaped space or we are not 
+	   * pointing to a preparser function...
+	   */
+	  if (p >= e || *p != '#') {
+	    /* XXX off from cppfilestate is only used here and will always be 
+	       true */
+	    if (!cfs->off) 
+	      /* XXX HERE */
+	      cppchunk(cfs, s, e);
+	    return;
+	  }
 
-		assert(*p == '#');
-		cfs->hash = s;
-		p = skipspace(cfs, p + 1, e);
-		e = trimspace(p, e);
-		if (p == e) {
-			return;
-		}
+	  cppchunk(cfs, NULL, NULL);
+	  
+	  assert(*p == '#');
+	  cfs->hash = s;
+	  p = skipspace(cfs, p + 1, e);
+	  e = trimspace(p, e);
+	  if (p == e) {
+	    return;
+	  }
 	} 
-
+	
 	D(1, "line     <%V>\n", String(p, e));
 	for (kw = cpp_kw; kw->q != NULL; kw++) {
 		if (*p < *kw->q)
@@ -301,7 +319,6 @@
 	assert(r != NULL);
 	assert(r->sf != NULL);
 	
-	/* For debug only */
 	D(1, "cppfile(%s)\n", r->sf->filename);
 
 	memset(&cfs, 0, sizeof cfs);
@@ -309,12 +326,12 @@
 	cfs.h = h;
 	cfs.r = r;
 
-	p = r->s.b;
-	e = r->s.e;
-	/* XXX HERE */
+	p = r->s.b; /* p = the first mmaped address */
+	e = r->s.e; /* e = the end of the mmaped space */
+	/* Scan through r's s struct*/
 	for (q = p; q < e; q++) {
 
-		/* find NL */
+		/* find the end of the line, skipping any comments */
 		while (q < e && *q != '\n') {
 			if (*q != '/') {
 				q++;
@@ -326,8 +343,9 @@
 		}
 
 		if (q == e) {
-			cppline(&cfs, p, q);		
-			break;
+		  /* XXX HERE */
+		  cppline(&cfs, p, q);		
+		  break;
 		}
 		/* back up over any CRs */
 		t = q;
@@ -382,6 +400,7 @@
 	h->r = NewRef(h);
 	h->r->type = ARG;
 	h->r->sf = LoadFile(filename);
+	/* set the head refrence s struct to that of the sourcefile's */
 	h->r->s = h->r->sf->s;
 	cppfile(h, h->r);
 	/* XXX HERE */

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

@@ -1,9 +1,10 @@
+#include <sys/mman.h>
+#include <sys/stat.h>
+
 #include <assert.h>
 #include <err.h>
 #include <fcntl.h>
 #include <stdlib.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
 
 #include "k.h"
 
@@ -17,7 +18,8 @@
 	struct stat st;
 	void *p;
 	int fd;
-
+	
+	/* Add filename to the list of strings */
 	filename = String(filename, NULL);
 
 	/* Check if this file has been loaded already */

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

@@ -178,7 +178,8 @@
 	    PushSymScope(hf);
 	  } 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#5 (text+ko) ====

@@ -1,6 +1,7 @@
 
+#include <sys/queue.h>
+
 #include "token_defs.h"
-#include <sys/queue.h>
 
 /* -------------------------------------------------------------------*/
 

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

@@ -1,3 +1,5 @@
+#include <sys/queue.h>
+
 #include <stdio.h>
 #include <err.h>
 #include <assert.h>
@@ -6,7 +8,6 @@
 #include <stdlib.h>
 #include <inttypes.h>
 #include <wchar.h>
-#include <sys/queue.h>
 
 #include "k.h"
 
@@ -62,17 +63,17 @@
 	t->b = b;
 	t->e = e;
 	if (tok == CSTR) {
-		tt = TAILQ_LAST(&ts->tokens, tokenhead);
-		if (tt != NULL && tt->tok == CSTR) {
-			while (tt->chain != NULL)
-				tt = tt->chain;
-			tt->chain = t;
-			return (t);
-		}
+	  tt = TAILQ_LAST(&ts->tokens, tokenhead);
+	  if (tt != NULL && tt->tok == CSTR) {
+	    while (tt->chain != NULL)
+	      tt = tt->chain;
+	    tt->chain = t;
+	    return (t);
+	  }
 	}
 	TAILQ_INSERT_TAIL(&ts->tokens, t, list);
-if (0) 
-printf("Add_Token \t%p %#T\n", ts, t);
+	if (0) 
+	  printf("Add_Token \t%p %#T\n", ts, t);
 	return (t);
 }
 
@@ -174,134 +175,136 @@
 void
 Lexer(struct tokens *ts, const char *b, const char *e)
 {
-	const char *posf;
-	char buf[BUFSIZ];
-	const char *p, *s;
-	char *q;
-	unsigned u;
-	int i;
-	unsigned tok;
-	struct token *t;
-
-	if (b == NULL) {
-		add_token(ts, EOI, NULL, NULL);
-		return;
+  const char *posf;
+  char buf[BUFSIZ];
+  const char *p, *s;
+  char *q;
+  unsigned u;
+  int i;
+  unsigned tok;
+  struct token *t;
+  
+  if (b == NULL) {
+    /* XXX HERE */
+    add_token(ts, EOI, NULL, NULL);
+    return;
+  }
+  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) {
+    b = p;
+    e = strchr(b, '\0');
+    assert(e != NULL);
+  }
+  if (1) {
+    printf("LEX2 %V\n", String(b, e));
+  }
+  while (b < e) {
+    
+    switch(*b) {
+    case '\n': case '\r': case '\v': case '\f':
+      b++;
+      continue;
+    case '\\':
+      if (b[1] == '\n') {
+	b += 2;
+	continue;
+      }
+      break;
+    case '/':
+      if (b[1] == '*') {
+	/* Ignore comments */
+	for (b += 2; b + 1 < e; b++) {
+	  if (b[0] == '*' && b[1] == '/') {
+	    b += 2;
+	    break;
+	  }
 	}
-	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) {
-		b = p;
-		e = strchr(b, '\0');
-		assert(e != NULL);
-	}
-if (1) {
-	printf("LEX2 %V\n", String(b, e));
-}
-	while (b < e) {
-		
-		switch(*b) {
-		case '\n': case '\r': case '\v': case '\f':
-			b++;
-			continue;
-		case '\\':
-			if (b[1] == '\n') {
-				b += 2;
-				continue;
-			}
-			break;
-		case '/':
-			if (b[1] == '*') {
-				for (b += 2; b + 1 < e; b++) {
-					if (b[0] == '*' && b[1] == '/') {
-						b += 2;
-						break;
-					}
-				}
-				continue;
-			}
-			if (b[1] == '/')
-				errx(1, "// comment");
-			break;
-		case '\t':
-		case ' ':
-			b++;
-			continue;
-		case '\'':
-			if (b[1] != '\\' && b[2] == '\'') {
-				t = add_token(ts, CNUM, b, b + 3);
+	continue;
+      }
+      if (b[1] == '/')
+	errx(1, "// comment");
+      break;
+    case '\t':
+    case ' ':
+      b++;
+      continue;
+    case '\'':
+      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] == '\\') {
-				i = BackSlash(b + 2, &p);
-				if (i >= 0 && *p == '\'') {
-					p++;
-					t = add_token(ts, CNUM, b, p);
-					t->name = String(b, p);
-					b = p;
-					continue;
-				}
-			}
-			break;
-		case '"':
-			s = StringEnd(b, e);
-			assert(s != NULL);
-printf("Lex: \"%V\"\n", String(b, s));
-			t = add_token(ts, CSTR, b, s);
+      }
+      if (b[1] == '\\') {
+	i = BackSlash(b + 2, &p);
+	if (i >= 0 && *p == '\'') {
+	  p++;
+	  t = add_token(ts, CNUM, b, p);
+	  t->name = String(b, p);
+	  b = p;
+	  continue;
+	}
+      }
+      break;
+    case '"':
+      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 '#':
-printf("# %V\n", String(b, e));
-			u = strtoul(b + 1, &q, 0);
-			if (q == NULL)
-				errx(1, "Preproc børk1");
-			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':
-			s = NumberEnd(b);
-			if (s != NULL) {
-				t = add_token(ts, CNUM, b, s);
-				t->name = String(b, s);
-				b = s;
-				continue;
-			}
-			break;
-		default:
-			break;
-		}
-		tok = fixed_token(b, &s);
-		if (tok > 0) {
-			t = add_token(ts, tok, b, s);
-			b = s;
-			continue;
-		}
-		if (isident1(b[0])) {
-			for (p = b + 1; isident(*p); p++)
-				continue;
-			t = add_token(ts, ID, b, p);
-			t->name = String(b, p);
-			b += (p - b);
-			continue;
-		}
-		strncpy(buf, b, 20);
-		printf("Unknown: >>>>%V\n", buf);
-		exit (0);
-	}
+    case '#':
+      printf("# %V\n", String(b, e));
+      u = strtoul(b + 1, &q, 0);
+      if (q == NULL)
+	errx(1, "Preproc børk1");
+      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':
+      s = NumberEnd(b);
+      if (s != NULL) {
+	t = add_token(ts, CNUM, b, s);
+	t->name = String(b, s);
+	b = s;
+	continue;
+      }
+      break;
+    default:
+      break;
+    }
+    tok = fixed_token(b, &s);
+    if (tok > 0) {
+      t = add_token(ts, tok, b, s);
+      b = s;
+      continue;
+    }
+    if (isident1(b[0])) {
+      for (p = b + 1; isident(*p); p++)
+	continue;
+      t = add_token(ts, ID, b, p);
+      t->name = String(b, p);
+      b += (p - b);
+      continue;
+    }
+    strncpy(buf, b, 20);
+    printf("Unknown: >>>>%V\n", buf);
+    exit (0);
+  }
 }

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

@@ -36,30 +36,39 @@
 {
 	struct string *s;
 	struct string_head *h;
-	unsigned l, hash; /* XXX hash is unused here */
+	unsigned l; /* hash; */ /* XXX hash is unused here */
 
 	assert(b != NULL);
+	
 	if (e == NULL) {
 		e = strchr(b, '\0');
 		assert(e != NULL);
 	}
+
+	/* If the end is equal to the begining, it's an empty string */
 	if (e == b)
 		return ("");
+
 	assert(e > b);
 	l = e - b;
-	hash = *b;
+
+	/*	hash = *b;
 	if (l > 1)
-		hash = (hash << 8) | b[1];
+	hash = (hash << 8) | b[1]; */
+
 	/* Have we already inserted this string into the hash table? */
 	h = &strings[*b % NHASH];
 	LIST_FOREACH(s, h, list) {
 		if (b == s->string)
 			return (s->string);
+		/* Not the same string if they are of different lengths */
 		if (s->l != l)
 			continue;
 		if (!memcmp(s->string, b, l))
 			return (s->string);
 	}
+
+	/* Add this string to the list */
 	s = calloc(sizeof *s, 1);
 	assert(s != NULL);
 	s->string = malloc(l + 1);
@@ -68,6 +77,7 @@
 	s->string[l] = '\0';
 	s->l = l;
 	LIST_INSERT_HEAD(h, s, list);
+
 	return (s->string);
 }
 

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

@@ -33,3 +33,4 @@
 		putchar (i & 0x01 ? '*' : ' ');
 	}
 }
+

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



More information about the p4-projects mailing list