Module Name: src Committed By: rillig Date: Sun Dec 6 14:20:20 UTC 2020
Modified Files: src/usr.bin/make: var.c Log Message: make(1): move type definitions in var.c to the top To generate a diff of this commit: cvs rdiff -u -r1.709 -r1.710 src/usr.bin/make/var.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.709 src/usr.bin/make/var.c:1.710 --- src/usr.bin/make/var.c:1.709 Sun Dec 6 13:51:06 2020 +++ src/usr.bin/make/var.c Sun Dec 6 14:20:20 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.709 2020/12/06 13:51:06 rillig Exp $ */ +/* $NetBSD: var.c,v 1.710 2020/12/06 14:20:20 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -130,57 +130,8 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.709 2020/12/06 13:51:06 rillig Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.710 2020/12/06 14:20:20 rillig Exp $"); -ENUM_FLAGS_RTTI_3(VarEvalFlags, - VARE_UNDEFERR, VARE_WANTRES, VARE_KEEP_DOLLAR); - -/* - * This lets us tell if we have replaced the original environ - * (which we cannot free). - */ -char **savedEnv = NULL; - -/* Special return value for Var_Parse, indicating a parse error. It may be - * caused by an undefined variable, a syntax error in a modifier or - * something entirely different. */ -char var_Error[] = ""; - -/* Special return value for Var_Parse, indicating an undefined variable in - * a case where VARE_UNDEFERR is not set. This undefined variable is - * typically a dynamic variable such as ${.TARGET}, whose expansion needs to - * be deferred until it is defined in an actual target. */ -static char varUndefined[] = ""; - -/* - * Traditionally this make consumed $$ during := like any other expansion. - * Other make's do not, and this make follows straight since 2016-01-09. - * - * This knob allows controlling the behavior. - * FALSE to consume $$ during := assignment. - * TRUE to preserve $$ during := assignment. - */ -#define MAKE_SAVE_DOLLARS ".MAKE.SAVE_DOLLARS" -static Boolean save_dollars = TRUE; - -/* - * Internally, variables are contained in four different contexts. - * 1) the environment. They cannot be changed. If an environment - * variable is appended to, the result is placed in the global - * context. - * 2) the global context. Variables set in the makefiles are located - * here. - * 3) the command-line context. All variables set on the command line - * are placed in this context. - * 4) the local context. Each target has associated with it a context - * list. On this list are located the structures describing such - * local variables as $(@) and $(*) - * The four contexts are searched in the reverse order from which they are - * listed (but see opts.checkEnvFirst). - */ -GNode *VAR_INTERNAL; /* variables from make itself */ -GNode *VAR_GLOBAL; /* variables from the makefile */ -GNode *VAR_CMDLINE; /* variables defined on the command-line */ typedef enum VarFlags { VAR_NONE = 0, @@ -223,10 +174,6 @@ typedef enum VarFlags { VAR_READONLY = 0x80 } VarFlags; -ENUM_FLAGS_RTTI_6(VarFlags, - VAR_IN_USE, VAR_FROM_ENV, - VAR_EXPORTED, VAR_REEXPORT, VAR_FROM_CMD, VAR_READONLY); - /* Variables are defined using one of the VAR=value assignments. Their * value can be queried by expressions such as $V, ${VAR}, or with modifiers * such as ${VAR:S,from,to,g:Q}. @@ -260,17 +207,6 @@ typedef struct Var { VarFlags flags; } Var; -/* - * Exporting vars is expensive so skip it if we can - */ -typedef enum VarExportedMode { - VAR_EXPORTED_NONE, - VAR_EXPORTED_SOME, - VAR_EXPORTED_ALL -} VarExportedMode; - -static VarExportedMode var_exportedVars = VAR_EXPORTED_NONE; - typedef enum VarExportFlags { VAR_EXPORT_NORMAL = 0, /* @@ -284,6 +220,15 @@ typedef enum VarExportFlags { VAR_EXPORT_LITERAL = 0x02 } VarExportFlags; +/* + * Exporting vars is expensive so skip it if we can + */ +typedef enum VarExportedMode { + VAR_EXPORTED_NONE, + VAR_EXPORTED_SOME, + VAR_EXPORTED_ALL +} VarExportedMode; + /* Flags for pattern matching in the :S and :C modifiers */ typedef enum VarPatternFlags { VARP_NONE = 0, @@ -297,6 +242,71 @@ typedef enum VarPatternFlags { VARP_ANCHOR_END = 1 << 3 } VarPatternFlags; +/* SepBuf is a string being built from words, interleaved with separators. */ +typedef struct SepBuf { + Buffer buf; + Boolean needSep; + /* Usually ' ', but see the ':ts' modifier. */ + char sep; +} SepBuf; + + +ENUM_FLAGS_RTTI_3(VarEvalFlags, + VARE_UNDEFERR, VARE_WANTRES, VARE_KEEP_DOLLAR); + +/* + * This lets us tell if we have replaced the original environ + * (which we cannot free). + */ +char **savedEnv = NULL; + +/* Special return value for Var_Parse, indicating a parse error. It may be + * caused by an undefined variable, a syntax error in a modifier or + * something entirely different. */ +char var_Error[] = ""; + +/* Special return value for Var_Parse, indicating an undefined variable in + * a case where VARE_UNDEFERR is not set. This undefined variable is + * typically a dynamic variable such as ${.TARGET}, whose expansion needs to + * be deferred until it is defined in an actual target. */ +static char varUndefined[] = ""; + +/* + * Traditionally this make consumed $$ during := like any other expansion. + * Other make's do not, and this make follows straight since 2016-01-09. + * + * This knob allows controlling the behavior. + * FALSE to consume $$ during := assignment. + * TRUE to preserve $$ during := assignment. + */ +#define MAKE_SAVE_DOLLARS ".MAKE.SAVE_DOLLARS" +static Boolean save_dollars = TRUE; + +/* + * Internally, variables are contained in four different contexts. + * 1) the environment. They cannot be changed. If an environment + * variable is appended to, the result is placed in the global + * context. + * 2) the global context. Variables set in the makefiles are located + * here. + * 3) the command-line context. All variables set on the command line + * are placed in this context. + * 4) the local context. Each target has associated with it a context + * list. On this list are located the structures describing such + * local variables as $(@) and $(*) + * The four contexts are searched in the reverse order from which they are + * listed (but see opts.checkEnvFirst). + */ +GNode *VAR_INTERNAL; /* variables from make itself */ +GNode *VAR_GLOBAL; /* variables from the makefile */ +GNode *VAR_CMDLINE; /* variables defined on the command-line */ + +ENUM_FLAGS_RTTI_6(VarFlags, + VAR_IN_USE, VAR_FROM_ENV, + VAR_EXPORTED, VAR_REEXPORT, VAR_FROM_CMD, VAR_READONLY); + +static VarExportedMode var_exportedVars = VAR_EXPORTED_NONE; + static Var * VarNew(const char *name, void *name_freeIt, const char *value, VarFlags flags) { @@ -1068,14 +1078,6 @@ Var_ValueDirect(const char *name, GNode } -/* SepBuf is a string being built from words, interleaved with separators. */ -typedef struct SepBuf { - Buffer buf; - Boolean needSep; - /* Usually ' ', but see the ':ts' modifier. */ - char sep; -} SepBuf; - static void SepBuf_Init(SepBuf *buf, char sep) {