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.
This commit is contained in:
parent
27b5f91738
commit
09fc919e11
|
@ -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
|
* Copyright (c) 1988, 1989, 1990, 1993
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
|
|
||||||
#include "make.h"
|
#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.
|
/* Allocate and initialize a list node.
|
||||||
*
|
*
|
||||||
|
@ -499,43 +499,43 @@ Lst_Dequeue(List *list)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Stack_Init(Stack *stack)
|
Vector_Init(Vector *v)
|
||||||
{
|
{
|
||||||
stack->len = 0;
|
v->len = 0;
|
||||||
stack->cap = 10;
|
v->cap = 10;
|
||||||
stack->items = bmake_malloc(stack->cap * sizeof stack->items[0]);
|
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) {
|
if (v->len >= v->cap) {
|
||||||
stack->cap *= 2;
|
v->cap *= 2;
|
||||||
stack->items = bmake_realloc(stack->items,
|
v->items = bmake_realloc(v->items,
|
||||||
stack->cap * sizeof stack->items[0]);
|
v->cap * sizeof v->items[0]);
|
||||||
}
|
}
|
||||||
stack->items[stack->len] = datum;
|
v->items[v->len] = datum;
|
||||||
stack->len++;
|
v->len++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *Stack_Pop(Stack *stack)
|
void *Vector_Pop(Vector *v)
|
||||||
{
|
{
|
||||||
void *datum;
|
void *datum;
|
||||||
|
|
||||||
assert(stack->len > 0);
|
assert(v->len > 0);
|
||||||
stack->len--;
|
v->len--;
|
||||||
datum = stack->items[stack->len];
|
datum = v->items[v->len];
|
||||||
#ifdef CLEANUP
|
#ifdef CLEANUP
|
||||||
stack->items[stack->len] = NULL;
|
v->items[v->len] = NULL;
|
||||||
#endif
|
#endif
|
||||||
return datum;
|
return datum;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stack_Done(Stack *stack)
|
void Vector_Done(Vector *v)
|
||||||
{
|
{
|
||||||
free(stack->items);
|
free(v->items);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
||||||
|
@ -210,18 +210,17 @@ void Lst_Enqueue(List *, void *);
|
||||||
/* Remove the head node of the queue and return its datum. */
|
/* Remove the head node of the queue and return its datum. */
|
||||||
void *Lst_Dequeue(List *);
|
void *Lst_Dequeue(List *);
|
||||||
|
|
||||||
/* A stack is a very simple collection of items that only allows access to the
|
/* A vector is an ordered collection of items, allowing fast indexed access. */
|
||||||
* top-most item. */
|
typedef struct Vector {
|
||||||
typedef struct Stack {
|
|
||||||
void **items;
|
void **items;
|
||||||
size_t len;
|
size_t len;
|
||||||
size_t cap;
|
size_t cap;
|
||||||
} Stack;
|
} Vector;
|
||||||
|
|
||||||
void Stack_Init(Stack *);
|
void Vector_Init(Vector *);
|
||||||
Boolean Stack_IsEmpty(Stack *);
|
Boolean Vector_IsEmpty(Vector *);
|
||||||
void Stack_Push(Stack *, void *);
|
void Vector_Push(Vector *, void *);
|
||||||
void *Stack_Pop(Stack *);
|
void *Vector_Pop(Vector *);
|
||||||
void Stack_Done(Stack *);
|
void Vector_Done(Vector *);
|
||||||
|
|
||||||
#endif /* MAKE_LST_H */
|
#endif /* MAKE_LST_H */
|
||||||
|
|
|
@ -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
|
* Copyright (c) 1988, 1989, 1990, 1993
|
||||||
|
@ -131,7 +131,7 @@
|
||||||
#include "pathnames.h"
|
#include "pathnames.h"
|
||||||
|
|
||||||
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
|
/* "@(#)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 */
|
/* types and constants */
|
||||||
|
|
||||||
|
@ -280,7 +280,7 @@ static IFile *curFile;
|
||||||
* (not printed since it is below a .for loop)
|
* (not printed since it is below a .for loop)
|
||||||
* includes[0]: include-main.mk:27
|
* includes[0]: include-main.mk:27
|
||||||
*/
|
*/
|
||||||
static Stack /* of *IFile */ includes;
|
static Vector /* of IFile pointer */ includes;
|
||||||
|
|
||||||
/* include paths (lists of directories) */
|
/* include paths (lists of directories) */
|
||||||
SearchPath *parseIncPath; /* dirs for "..." includes */
|
SearchPath *parseIncPath; /* dirs for "..." includes */
|
||||||
|
@ -2300,7 +2300,6 @@ GetActuallyIncludingFile(void)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
/* XXX: Stack was supposed to be an opaque data structure. */
|
|
||||||
for (i = includes.len; i > 0; i--) {
|
for (i = includes.len; i > 0; i--) {
|
||||||
IFile *parent = includes.items[i - 1];
|
IFile *parent = includes.items[i - 1];
|
||||||
IFile *child = i < includes.len ? includes.items[i] : curFile;
|
IFile *child = i < includes.len ? includes.items[i] : curFile;
|
||||||
|
@ -2384,7 +2383,7 @@ Parse_SetInput(const char *name, int line, int fd,
|
||||||
|
|
||||||
if (curFile != NULL)
|
if (curFile != NULL)
|
||||||
/* Save existing file info */
|
/* Save existing file info */
|
||||||
Stack_Push(&includes, curFile);
|
Vector_Push(&includes, curFile);
|
||||||
|
|
||||||
/* Allocate and fill in new structure */
|
/* Allocate and fill in new structure */
|
||||||
curFile = bmake_malloc(sizeof *curFile);
|
curFile = bmake_malloc(sizeof *curFile);
|
||||||
|
@ -2579,7 +2578,7 @@ ParseEOF(void)
|
||||||
free(curFile->P_str);
|
free(curFile->P_str);
|
||||||
free(curFile);
|
free(curFile);
|
||||||
|
|
||||||
if (Stack_IsEmpty(&includes)) {
|
if (Vector_IsEmpty(&includes)) {
|
||||||
curFile = NULL;
|
curFile = NULL;
|
||||||
/* We've run out of input */
|
/* We've run out of input */
|
||||||
Var_Delete(".PARSEDIR", VAR_GLOBAL);
|
Var_Delete(".PARSEDIR", VAR_GLOBAL);
|
||||||
|
@ -2589,7 +2588,7 @@ ParseEOF(void)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
curFile = Stack_Pop(&includes);
|
curFile = Vector_Pop(&includes);
|
||||||
DEBUG2(PARSE, "ParseEOF: returning to file %s, line %d\n",
|
DEBUG2(PARSE, "ParseEOF: returning to file %s, line %d\n",
|
||||||
curFile->fname, curFile->lineno);
|
curFile->fname, curFile->lineno);
|
||||||
|
|
||||||
|
@ -3127,7 +3126,7 @@ Parse_Init(void)
|
||||||
parseIncPath = Lst_Init();
|
parseIncPath = Lst_Init();
|
||||||
sysIncPath = Lst_Init();
|
sysIncPath = Lst_Init();
|
||||||
defIncPath = Lst_Init();
|
defIncPath = Lst_Init();
|
||||||
Stack_Init(&includes);
|
Vector_Init(&includes);
|
||||||
#ifdef CLEANUP
|
#ifdef CLEANUP
|
||||||
targCmds = Lst_Init();
|
targCmds = Lst_Init();
|
||||||
#endif
|
#endif
|
||||||
|
@ -3143,8 +3142,8 @@ Parse_End(void)
|
||||||
Lst_Destroy(defIncPath, Dir_Destroy);
|
Lst_Destroy(defIncPath, Dir_Destroy);
|
||||||
Lst_Destroy(sysIncPath, Dir_Destroy);
|
Lst_Destroy(sysIncPath, Dir_Destroy);
|
||||||
Lst_Destroy(parseIncPath, Dir_Destroy);
|
Lst_Destroy(parseIncPath, Dir_Destroy);
|
||||||
assert(Stack_IsEmpty(&includes));
|
assert(Vector_IsEmpty(&includes));
|
||||||
Stack_Done(&includes);
|
Vector_Done(&includes);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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"
|
.if ${.INCLUDEDFROMFILE} == "include-main.mk"
|
||||||
. info sub-before-ok
|
. info sub-before-ok
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
# To see the variable 'includes' in action:
|
# To see the variable 'includes' in action:
|
||||||
#
|
#
|
||||||
# Breakpoints:
|
# Breakpoints:
|
||||||
# Parse_File at "Stack_Push(&includes, curFile)"
|
# Parse_File at "Vector_Push(&includes, curFile)"
|
||||||
# ParseMessage at entry
|
# ParseMessage at entry
|
||||||
# Watches:
|
# Watches:
|
||||||
# ((const IFile *[10])(*includes.items))
|
# ((const IFile *[10])(*includes.items))
|
||||||
|
|
|
@ -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
|
* Copyright (c) 1988, 1989, 1990, 1993
|
||||||
|
@ -121,7 +121,7 @@
|
||||||
#include "metachar.h"
|
#include "metachar.h"
|
||||||
|
|
||||||
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
|
/* "@(#)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_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
|
||||||
#define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
|
#define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
|
||||||
|
@ -3856,16 +3856,16 @@ Var_Stats(void)
|
||||||
void
|
void
|
||||||
Var_Dump(GNode *ctxt)
|
Var_Dump(GNode *ctxt)
|
||||||
{
|
{
|
||||||
Stack varnames;
|
Vector varnames;
|
||||||
Hash_Search iter;
|
Hash_Search iter;
|
||||||
Hash_Entry *he;
|
Hash_Entry *he;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
Stack_Init(&varnames);
|
Vector_Init(&varnames);
|
||||||
for (he = Hash_EnumFirst(&ctxt->context, &iter);
|
for (he = Hash_EnumFirst(&ctxt->context, &iter);
|
||||||
he != NULL;
|
he != NULL;
|
||||||
he = Hash_EnumNext(&iter))
|
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);
|
qsort(varnames.items, varnames.len, sizeof varnames.items[0], str_cmp_asc);
|
||||||
|
|
||||||
|
@ -3875,5 +3875,5 @@ Var_Dump(GNode *ctxt)
|
||||||
debug_printf("%-16s = %s\n", varname, Buf_GetAll(&var->val, NULL));
|
debug_printf("%-16s = %s\n", varname, Buf_GetAll(&var->val, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
Stack_Done(&varnames);
|
Vector_Done(&varnames);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue