Mon Nov 2 16:55:18 2020 UTC ()
make(1): merge variables p and nested_p in ApplyModifiersIndirect

When the code was still in ApplyModifiers, the variable nested_p was
necessary to distinguish the parsing position in the nested modifier
from the parsing position of the main expression.


(rillig)
diff -r1.643 -r1.644 src/usr.bin/make/var.c

cvs diff -r1.643 -r1.644 src/usr.bin/make/var.c (expand / switch to unified diff)

--- src/usr.bin/make/var.c 2020/11/02 16:48:49 1.643
+++ src/usr.bin/make/var.c 2020/11/02 16:55:18 1.644
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: var.c,v 1.643 2020/11/02 16:48:49 rillig Exp $ */ 1/* $NetBSD: var.c,v 1.644 2020/11/02 16:55:18 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -120,27 +120,27 @@ @@ -120,27 +120,27 @@
120#include <regex.h> 120#include <regex.h>
121#endif 121#endif
122#include <errno.h> 122#include <errno.h>
123#include <inttypes.h> 123#include <inttypes.h>
124#include <limits.h> 124#include <limits.h>
125#include <time.h> 125#include <time.h>
126 126
127#include "make.h" 127#include "make.h"
128#include "dir.h" 128#include "dir.h"
129#include "job.h" 129#include "job.h"
130#include "metachar.h" 130#include "metachar.h"
131 131
132/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ 132/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
133MAKE_RCSID("$NetBSD: var.c,v 1.643 2020/11/02 16:48:49 rillig Exp $"); 133MAKE_RCSID("$NetBSD: var.c,v 1.644 2020/11/02 16:55:18 rillig Exp $");
134 134
135#define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1) 135#define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
136#define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2) 136#define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
137#define VAR_DEBUG3(fmt, arg1, arg2, arg3) DEBUG3(VAR, fmt, arg1, arg2, arg3) 137#define VAR_DEBUG3(fmt, arg1, arg2, arg3) DEBUG3(VAR, fmt, arg1, arg2, arg3)
138#define VAR_DEBUG4(fmt, arg1, arg2, arg3, arg4) DEBUG4(VAR, fmt, arg1, arg2, arg3, arg4) 138#define VAR_DEBUG4(fmt, arg1, arg2, arg3, arg4) DEBUG4(VAR, fmt, arg1, arg2, arg3, arg4)
139 139
140ENUM_FLAGS_RTTI_3(VarEvalFlags, 140ENUM_FLAGS_RTTI_3(VarEvalFlags,
141 VARE_UNDEFERR, VARE_WANTRES, VARE_ASSIGN); 141 VARE_UNDEFERR, VARE_WANTRES, VARE_ASSIGN);
142 142
143/* 143/*
144 * This lets us tell if we have replaced the original environ 144 * This lets us tell if we have replaced the original environ
145 * (which we cannot free). 145 * (which we cannot free).
146 */ 146 */
@@ -3262,56 +3262,52 @@ typedef enum ApplyModifiersIndirectResul @@ -3262,56 +3262,52 @@ typedef enum ApplyModifiersIndirectResul
3262 AMIR_APPLY_MODS, 3262 AMIR_APPLY_MODS,
3263 AMIR_OUT 3263 AMIR_OUT
3264} ApplyModifiersIndirectResult; 3264} ApplyModifiersIndirectResult;
3265 3265
3266/* While expanding a variable expression, expand and apply indirect 3266/* While expanding a variable expression, expand and apply indirect
3267 * modifiers. */ 3267 * modifiers. */
3268static ApplyModifiersIndirectResult 3268static ApplyModifiersIndirectResult
3269ApplyModifiersIndirect( 3269ApplyModifiersIndirect(
3270 ApplyModifiersState *const st, 3270 ApplyModifiersState *const st,
3271 const char **inout_p, 3271 const char **inout_p,
3272 void **const out_freeIt 3272 void **const out_freeIt
3273) { 3273) {
3274 const char *p = *inout_p; 3274 const char *p = *inout_p;
3275 const char *nested_p = p; 
3276 const char *mods; 3275 const char *mods;
3277 void *mods_freeIt; 3276 void *mods_freeIt;
3278 3277
3279 (void)Var_Parse(&nested_p, st->ctxt, st->eflags, &mods, &mods_freeIt); 3278 (void)Var_Parse(&p, st->ctxt, st->eflags, &mods, &mods_freeIt);
3280 /* TODO: handle errors */ 3279 /* TODO: handle errors */
3281 3280
3282 /* 3281 /*
3283 * If we have not parsed up to st->endc or ':', we are not 3282 * If we have not parsed up to st->endc or ':', we are not
3284 * interested. This means the expression ${VAR:${M_1}${M_2}} 3283 * interested. This means the expression ${VAR:${M_1}${M_2}}
3285 * is not accepted, but ${VAR:${M_1}:${M_2}} is. 3284 * is not accepted, but ${VAR:${M_1}:${M_2}} is.
3286 */ 3285 */
3287 if (mods[0] != '\0' && 3286 if (mods[0] != '\0' && *p != '\0' && *p != ':' && *p != st->endc) {
3288 *nested_p != '\0' && *nested_p != ':' && *nested_p != st->endc) { 
3289 if (DEBUG(LINT)) 3287 if (DEBUG(LINT))
3290 Parse_Error(PARSE_FATAL, 3288 Parse_Error(PARSE_FATAL,
3291 "Missing delimiter ':' after indirect modifier \"%.*s\"", 3289 "Missing delimiter ':' after indirect modifier \"%.*s\"",
3292 (int)(nested_p - p), p); 3290 (int)(p - *inout_p), *inout_p);
3293 3291
3294 free(mods_freeIt); 3292 free(mods_freeIt);
3295 /* XXX: apply_mods doesn't sound like "not interested". */ 3293 /* XXX: apply_mods doesn't sound like "not interested". */
3296 /* XXX: Why is the indirect modifier parsed again by 3294 /* XXX: Why is the indirect modifier parsed again by
3297 * apply_mods? If any, p should be advanced to nested_p. */ 3295 * apply_mods? If any, p should be advanced to nested_p. */
3298 return AMIR_APPLY_MODS; 3296 return AMIR_APPLY_MODS;
3299 } 3297 }
3300 3298
3301 VAR_DEBUG3("Indirect modifier \"%s\" from \"%.*s\"\n", 3299 VAR_DEBUG3("Indirect modifier \"%s\" from \"%.*s\"\n",
3302 mods, (int)(size_t)(nested_p - p), p); 3300 mods, (int)(p - *inout_p), *inout_p);
3303 
3304 p = nested_p; 
3305 3301
3306 if (mods[0] != '\0') { 3302 if (mods[0] != '\0') {
3307 const char *rval_pp = mods; 3303 const char *rval_pp = mods;
3308 st->val = ApplyModifiers(&rval_pp, st->val, '\0', '\0', st->v, 3304 st->val = ApplyModifiers(&rval_pp, st->val, '\0', '\0', st->v,
3309 &st->exprFlags, st->ctxt, st->eflags, out_freeIt); 3305 &st->exprFlags, st->ctxt, st->eflags, out_freeIt);
3310 if (st->val == var_Error 3306 if (st->val == var_Error
3311 || (st->val == varUndefined && !(st->eflags & VARE_UNDEFERR)) 3307 || (st->val == varUndefined && !(st->eflags & VARE_UNDEFERR))
3312 || *rval_pp != '\0') { 3308 || *rval_pp != '\0') {
3313 free(mods_freeIt); 3309 free(mods_freeIt);
3314 *inout_p = p; 3310 *inout_p = p;
3315 return AMIR_OUT; /* error already reported */ 3311 return AMIR_OUT; /* error already reported */
3316 } 3312 }
3317 } 3313 }