Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make make(1): rename Stack to Vector
details: https://anonhg.NetBSD.org/src/rev/ac63cd6061ac
branches: trunk
changeset: 941056:ac63cd6061ac
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Oct 18 08:58:29 2020 +0000
description:
make(1): rename Stack to Vector
Both Var_Dump and GetActuallyIncludingFile access more than only the top
item of the stack, therefore it is more honest to rename the data type.
diffstat:
usr.bin/make/lst.c | 44 +++++++++++++++++-----------------
usr.bin/make/lst.h | 19 ++++++-------
usr.bin/make/parse.c | 19 ++++++-------
usr.bin/make/unit-tests/include-sub.mk | 4 +-
usr.bin/make/var.c | 12 ++++----
5 files changed, 48 insertions(+), 50 deletions(-)
diffs (263 lines):
diff -r 73118c2a36a8 -r ac63cd6061ac usr.bin/make/lst.c
--- a/usr.bin/make/lst.c Sun Oct 18 08:52:15 2020 +0000
+++ b/usr.bin/make/lst.c Sun Oct 18 08:58:29 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.75 2020/10/17 17:47:14 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.76 2020/10/18 08:58:29 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -34,7 +34,7 @@
#include "make.h"
-MAKE_RCSID("$NetBSD: lst.c,v 1.75 2020/10/17 17:47:14 rillig Exp $");
+MAKE_RCSID("$NetBSD: lst.c,v 1.76 2020/10/18 08:58:29 rillig Exp $");
/* Allocate and initialize a list node.
*
@@ -499,43 +499,43 @@
}
void
-Stack_Init(Stack *stack)
+Vector_Init(Vector *v)
{
- stack->len = 0;
- stack->cap = 10;
- stack->items = bmake_malloc(stack->cap * sizeof stack->items[0]);
+ v->len = 0;
+ v->cap = 10;
+ v->items = bmake_malloc(v->cap * sizeof v->items[0]);
}
-Boolean Stack_IsEmpty(Stack *stack)
+Boolean Vector_IsEmpty(Vector *v)
{
- return stack->len == 0;
+ return v->len == 0;
}
-void Stack_Push(Stack *stack, void *datum)
+void Vector_Push(Vector *v, void *datum)
{
- if (stack->len >= stack->cap) {
- stack->cap *= 2;
- stack->items = bmake_realloc(stack->items,
- stack->cap * sizeof stack->items[0]);
+ if (v->len >= v->cap) {
+ v->cap *= 2;
+ v->items = bmake_realloc(v->items,
+ v->cap * sizeof v->items[0]);
}
- stack->items[stack->len] = datum;
- stack->len++;
+ v->items[v->len] = datum;
+ v->len++;
}
-void *Stack_Pop(Stack *stack)
+void *Vector_Pop(Vector *v)
{
void *datum;
- assert(stack->len > 0);
- stack->len--;
- datum = stack->items[stack->len];
+ assert(v->len > 0);
+ v->len--;
+ datum = v->items[v->len];
#ifdef CLEANUP
- stack->items[stack->len] = NULL;
+ v->items[v->len] = NULL;
#endif
return datum;
}
-void Stack_Done(Stack *stack)
+void Vector_Done(Vector *v)
{
- free(stack->items);
+ free(v->items);
}
diff -r 73118c2a36a8 -r ac63cd6061ac usr.bin/make/lst.h
--- a/usr.bin/make/lst.h Sun Oct 18 08:52:15 2020 +0000
+++ b/usr.bin/make/lst.h Sun Oct 18 08:58:29 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.h,v 1.69 2020/09/26 17:15:20 rillig Exp $ */
+/* $NetBSD: lst.h,v 1.70 2020/10/18 08:58:29 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -210,18 +210,17 @@
/* Remove the head node of the queue and return its datum. */
void *Lst_Dequeue(List *);
-/* A stack is a very simple collection of items that only allows access to the
- * top-most item. */
-typedef struct Stack {
+/* A vector is an ordered collection of items, allowing fast indexed access. */
+typedef struct Vector {
void **items;
size_t len;
size_t cap;
-} Stack;
+} Vector;
-void Stack_Init(Stack *);
-Boolean Stack_IsEmpty(Stack *);
-void Stack_Push(Stack *, void *);
-void *Stack_Pop(Stack *);
-void Stack_Done(Stack *);
+void Vector_Init(Vector *);
+Boolean Vector_IsEmpty(Vector *);
+void Vector_Push(Vector *, void *);
+void *Vector_Pop(Vector *);
+void Vector_Done(Vector *);
#endif /* MAKE_LST_H */
diff -r 73118c2a36a8 -r ac63cd6061ac usr.bin/make/parse.c
--- a/usr.bin/make/parse.c Sun Oct 18 08:52:15 2020 +0000
+++ b/usr.bin/make/parse.c Sun Oct 18 08:58:29 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.383 2020/10/17 21:32:30 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.384 2020/10/18 08:58:29 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.383 2020/10/17 21:32:30 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.384 2020/10/18 08:58:29 rillig Exp $");
/* types and constants */
@@ -280,7 +280,7 @@
* (not printed since it is below a .for loop)
* includes[0]: include-main.mk:27
*/
-static Stack /* of *IFile */ includes;
+static Vector /* of IFile pointer */ includes;
/* include paths (lists of directories) */
SearchPath *parseIncPath; /* dirs for "..." includes */
@@ -2300,7 +2300,6 @@
{
size_t i;
- /* XXX: Stack was supposed to be an opaque data structure. */
for (i = includes.len; i > 0; i--) {
IFile *parent = includes.items[i - 1];
IFile *child = i < includes.len ? includes.items[i] : curFile;
@@ -2384,7 +2383,7 @@
if (curFile != NULL)
/* Save existing file info */
- Stack_Push(&includes, curFile);
+ Vector_Push(&includes, curFile);
/* Allocate and fill in new structure */
curFile = bmake_malloc(sizeof *curFile);
@@ -2579,7 +2578,7 @@
free(curFile->P_str);
free(curFile);
- if (Stack_IsEmpty(&includes)) {
+ if (Vector_IsEmpty(&includes)) {
curFile = NULL;
/* We've run out of input */
Var_Delete(".PARSEDIR", VAR_GLOBAL);
@@ -2589,7 +2588,7 @@
return FALSE;
}
- curFile = Stack_Pop(&includes);
+ curFile = Vector_Pop(&includes);
DEBUG2(PARSE, "ParseEOF: returning to file %s, line %d\n",
curFile->fname, curFile->lineno);
@@ -3127,7 +3126,7 @@
parseIncPath = Lst_Init();
sysIncPath = Lst_Init();
defIncPath = Lst_Init();
- Stack_Init(&includes);
+ Vector_Init(&includes);
#ifdef CLEANUP
targCmds = Lst_Init();
#endif
@@ -3143,8 +3142,8 @@
Lst_Destroy(defIncPath, Dir_Destroy);
Lst_Destroy(sysIncPath, Dir_Destroy);
Lst_Destroy(parseIncPath, Dir_Destroy);
- assert(Stack_IsEmpty(&includes));
- Stack_Done(&includes);
+ assert(Vector_IsEmpty(&includes));
+ Vector_Done(&includes);
#endif
}
diff -r 73118c2a36a8 -r ac63cd6061ac usr.bin/make/unit-tests/include-sub.mk
--- a/usr.bin/make/unit-tests/include-sub.mk Sun Oct 18 08:52:15 2020 +0000
+++ b/usr.bin/make/unit-tests/include-sub.mk Sun Oct 18 08:58:29 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: include-sub.mk,v 1.4 2020/09/14 19:59:47 rillig Exp $
+# $NetBSD: include-sub.mk,v 1.5 2020/10/18 08:58:29 rillig Exp $
.if ${.INCLUDEDFROMFILE} == "include-main.mk"
. info sub-before-ok
@@ -20,7 +20,7 @@
# To see the variable 'includes' in action:
#
# Breakpoints:
-# Parse_File at "Stack_Push(&includes, curFile)"
+# Parse_File at "Vector_Push(&includes, curFile)"
# ParseMessage at entry
# Watches:
# ((const IFile *[10])(*includes.items))
diff -r 73118c2a36a8 -r ac63cd6061ac usr.bin/make/var.c
--- a/usr.bin/make/var.c Sun Oct 18 08:52:15 2020 +0000
+++ b/usr.bin/make/var.c Sun Oct 18 08:58:29 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.573 2020/10/18 08:47:54 rillig Exp $ */
+/* $NetBSD: var.c,v 1.574 2020/10/18 08:58:29 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -121,7 +121,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.573 2020/10/18 08:47:54 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.574 2020/10/18 08:58:29 rillig Exp $");
#define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
#define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
@@ -3856,16 +3856,16 @@
void
Var_Dump(GNode *ctxt)
{
- Stack varnames;
+ Vector varnames;
Hash_Search iter;
Hash_Entry *he;
size_t i;
- Stack_Init(&varnames);
+ Vector_Init(&varnames);
for (he = Hash_EnumFirst(&ctxt->context, &iter);
he != NULL;
he = Hash_EnumNext(&iter))
- Stack_Push(&varnames, he->name);
+ Vector_Push(&varnames, he->name);
qsort(varnames.items, varnames.len, sizeof varnames.items[0], str_cmp_asc);
@@ -3875,5 +3875,5 @@
debug_printf("%-16s = %s\n", varname, Buf_GetAll(&var->val, NULL));
}
- Stack_Done(&varnames);
+ Vector_Done(&varnames);
}
Home |
Main Index |
Thread Index |
Old Index