Module Name: src Committed By: rillig Date: Sun Oct 4 20:57:27 UTC 2020
Modified Files: src/usr.bin/make: parse.c Log Message: make(1): clean up remaining details in variable assignment parser To generate a diff of this commit: cvs rdiff -u -r1.358 -r1.359 src/usr.bin/make/parse.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/parse.c diff -u src/usr.bin/make/parse.c:1.358 src/usr.bin/make/parse.c:1.359 --- src/usr.bin/make/parse.c:1.358 Sun Oct 4 20:37:11 2020 +++ src/usr.bin/make/parse.c Sun Oct 4 20:57:26 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.358 2020/10/04 20:37:11 rillig Exp $ */ +/* $NetBSD: parse.c,v 1.359 2020/10/04 20:57:26 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.358 2020/10/04 20:37:11 rillig Exp $"); +MAKE_RCSID("$NetBSD: parse.c,v 1.359 2020/10/04 20:57:26 rillig Exp $"); /* types and constants */ @@ -1680,6 +1680,10 @@ Parse_IsVar(const char *p, VarAssign *ou while (*p == ' ' || *p == '\t') p++; + /* During parsing, the '+' of the '+=' operator is initially parsed + * as part of the variable name. It is later corrected, as is the ':sh' + * modifier. Of these two (nameEnd and op), the earlier one determines the + * actual end of the variable name. */ out_var->nameStart = p; #ifdef CLEANUP out_var->nameEndDraft = NULL; @@ -1744,13 +1748,12 @@ Parse_IsVar(const char *p, VarAssign *ou /* Determine the assignment operator and adjust the end of the variable * name accordingly. */ static void -ParseVarassignOp(VarAssign *var, const char **out_op, GNode *ctxt) +ParseVarassignOp(VarAssign *var) { const char *op = var->eq; const char * const name = var->nameStart; VarAssignOp type; - var->varname = NULL; if (op > name && op[-1] == '+') { type = VAR_APPEND; op--; @@ -1780,8 +1783,11 @@ ParseVarassignOp(VarAssign *var, const c #endif } - *out_op = op; - var->op = type; + { + const char *nameEnd = var->nameEndDraft < op ? var->nameEndDraft : op; + var->varname = bmake_strsedup(var->nameStart, nameEnd); + var->op = type; + } } static void @@ -1915,27 +1921,12 @@ Parse_DoVar(VarAssign *var, GNode *ctxt) const char *avalue; /* actual value */ char *evalue = NULL; /* expanded value */ - /* The variable name consists of a single word (that is, no whitespace). - * It ends at the whitespace after that word (nameEnd). If there is no - * whitespace, the name is followed directly by the assignment operator - * (op). During parsing, the '+' of the '+=' operator is initially parsed - * as part of the variable name. It is later corrected, as is the ':sh' - * modifier. Of these two (nameEnd and op), the earlier one determines the - * actual end of the variable name. */ - const char *op; - - ParseVarassignOp(var, &op, ctxt); + ParseVarassignOp(var); uvalue = var->value; avalue = uvalue; VarCheckSyntax(var->op, uvalue, ctxt); - - if (var->varname == NULL) { - const char *nameEnd = var->nameEndDraft < op ? var->nameEndDraft : op; - var->varname = bmake_strsedup(var->nameStart, nameEnd); - } - if (VarAssign_Eval(var, uvalue, &avalue, &evalue, ctxt)) VarAssignSpecial(var->varname, avalue);