diff place.c @ 176:a2f047301c15

Replace Joerg's place_setfile with something that at least sort of works.
author David A. Holland
date Fri, 12 Jun 2015 02:55:02 -0400
parents d6e6b3940780
children 16b4451e34b8
line wrap: on
line diff
--- a/place.c	Fri Jun 12 02:38:04 2015 -0400
+++ b/place.c	Fri Jun 12 02:55:02 2015 -0400
@@ -53,7 +53,7 @@
 static const char *myprogname;
 
 ////////////////////////////////////////////////////////////
-// seenfiles
+// placefiles
 
 static
 struct placefile *
@@ -101,6 +101,58 @@
 	return place->file->dir;
 }
 
+static
+bool
+place_eq(const struct place *a, const struct place *b)
+{
+	if (a->type != b->type) {
+		return false;
+	}
+	if (a->file != b->file) {
+		return false;
+	}
+	if (a->line != b->line || a->column != b->column) {
+		return false;
+	}
+	return true;
+}
+
+static
+struct placefile *
+placefile_find(const struct place *incfrom, const char *name)
+{
+	unsigned i, num;
+	struct placefile *pf;
+
+	num = placefilearray_num(&placefiles);
+	for (i=0; i<num; i++) {
+		pf = placefilearray_get(&placefiles, i);
+		if (place_eq(incfrom, &pf->includedfrom) &&
+		    !strcmp(name, pf->name)) {
+			return pf;
+		}
+	}
+	return NULL;
+}
+
+void
+place_changefile(struct place *p, const char *name)
+{
+	struct placefile *pf;
+
+	assert(p->type == P_FILE);
+	if (!strcmp(name, p->file->name)) {
+		return;
+	}
+	pf = placefile_find(&p->file->includedfrom, name);
+	if (pf == NULL) {
+		pf = placefile_create(&p->file->includedfrom, name,
+				      p->file->fromsystemdir);
+		placefilearray_add(&placefiles, pf, NULL);
+	}
+	p->file = pf;
+}
+
 const struct placefile *
 place_addfile(const struct place *place, const char *file, bool issystem)
 {
@@ -154,17 +206,6 @@
 	p->column = 1;
 }
 
-void
-place_setfile(struct place *p, const char *name)
-{
-	assert(p->type == P_FILE);
-	if (strcmp(name, p->file->name) == 0) {
-		return;
-	}
-	p->file = placefile_create(&p->file->includedfrom, name,
-	    p->file->fromsystemdir);
-}
-
 const char *
 place_getname(const struct place *p)
 {