Mon Nov 2 16:38:47 2020 UTC ()
make(1): inline and rename variables in ApplyModifiersIndirect


(rillig)
diff -r1.641 -r1.642 src/usr.bin/make/var.c

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

--- src/usr.bin/make/var.c 2020/11/01 23:17:40 1.641
+++ src/usr.bin/make/var.c 2020/11/02 16:38:47 1.642
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: var.c,v 1.641 2020/11/01 23:17:40 rillig Exp $ */ 1/* $NetBSD: var.c,v 1.642 2020/11/02 16:38:47 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.641 2020/11/01 23:17:40 rillig Exp $"); 133MAKE_RCSID("$NetBSD: var.c,v 1.642 2020/11/02 16:38:47 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 */
@@ -3263,70 +3263,69 @@ typedef enum ApplyModifiersIndirectResul @@ -3263,70 +3263,69 @@ typedef enum ApplyModifiersIndirectResul
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; 3275 const char *nested_p = p;
3276 void *freeIt; 3276 void *rval_freeIt;
3277 const char *rval; 3277 const char *rval;
3278 char c; 
3279 3278
3280 (void)Var_Parse(&nested_p, st->ctxt, st->eflags, &rval, &freeIt); 3279 (void)Var_Parse(&nested_p, st->ctxt, st->eflags, &rval, &rval_freeIt);
3281 /* TODO: handle errors */ 3280 /* TODO: handle errors */
3282 3281
3283 /* 3282 /*
3284 * If we have not parsed up to st->endc or ':', we are not 3283 * If we have not parsed up to st->endc or ':', we are not
3285 * interested. This means the expression ${VAR:${M_1}${M_2}} 3284 * interested. This means the expression ${VAR:${M_1}${M_2}}
3286 * is not accepted, but ${VAR:${M_1}:${M_2}} is. 3285 * is not accepted, but ${VAR:${M_1}:${M_2}} is.
3287 */ 3286 */
3288 if (rval[0] != '\0' && 3287 if (rval[0] != '\0' &&
3289 (c = *nested_p) != '\0' && c != ':' && c != st->endc) { 3288 *nested_p != '\0' && *nested_p != ':' && *nested_p != st->endc) {
3290 if (DEBUG(LINT)) 3289 if (DEBUG(LINT))
3291 Parse_Error(PARSE_FATAL, 3290 Parse_Error(PARSE_FATAL,
3292 "Missing delimiter ':' after indirect modifier \"%.*s\"", 3291 "Missing delimiter ':' after indirect modifier \"%.*s\"",
3293 (int)(nested_p - p), p); 3292 (int)(nested_p - p), p);
3294 3293
3295 free(freeIt); 3294 free(rval_freeIt);
3296 /* XXX: apply_mods doesn't sound like "not interested". */ 3295 /* XXX: apply_mods doesn't sound like "not interested". */
3297 /* XXX: Why is the indirect modifier parsed again by 3296 /* XXX: Why is the indirect modifier parsed again by
3298 * apply_mods? If any, p should be advanced to nested_p. */ 3297 * apply_mods? If any, p should be advanced to nested_p. */
3299 return AMIR_APPLY_MODS; 3298 return AMIR_APPLY_MODS;
3300 } 3299 }
3301 3300
3302 VAR_DEBUG3("Indirect modifier \"%s\" from \"%.*s\"\n", 3301 VAR_DEBUG3("Indirect modifier \"%s\" from \"%.*s\"\n",
3303 rval, (int)(size_t)(nested_p - p), p); 3302 rval, (int)(size_t)(nested_p - p), p);
3304 3303
3305 p = nested_p; 3304 p = nested_p;
3306 3305
3307 if (rval[0] != '\0') { 3306 if (rval[0] != '\0') {
3308 const char *rval_pp = rval; 3307 const char *rval_pp = rval;
3309 st->val = ApplyModifiers(&rval_pp, st->val, '\0', '\0', st->v, 3308 st->val = ApplyModifiers(&rval_pp, st->val, '\0', '\0', st->v,
3310 &st->exprFlags, st->ctxt, st->eflags, out_freeIt); 3309 &st->exprFlags, st->ctxt, st->eflags, out_freeIt);
3311 if (st->val == var_Error 3310 if (st->val == var_Error
3312 || (st->val == varUndefined && !(st->eflags & VARE_UNDEFERR)) 3311 || (st->val == varUndefined && !(st->eflags & VARE_UNDEFERR))
3313 || *rval_pp != '\0') { 3312 || *rval_pp != '\0') {
3314 free(freeIt); 3313 free(rval_freeIt);
3315 *inout_p = p; 3314 *inout_p = p;
3316 return AMIR_OUT; /* error already reported */ 3315 return AMIR_OUT; /* error already reported */
3317 } 3316 }
3318 } 3317 }
3319 free(freeIt); 3318 free(rval_freeIt);
3320 3319
3321 if (*p == ':') 3320 if (*p == ':')
3322 p++; 3321 p++;
3323 else if (*p == '\0' && st->endc != '\0') { 3322 else if (*p == '\0' && st->endc != '\0') {
3324 Error("Unclosed variable specification after complex " 3323 Error("Unclosed variable specification after complex "
3325 "modifier (expecting '%c') for %s", st->endc, st->v->name); 3324 "modifier (expecting '%c') for %s", st->endc, st->v->name);
3326 *inout_p = p; 3325 *inout_p = p;
3327 return AMIR_OUT; 3326 return AMIR_OUT;
3328 } 3327 }
3329 3328
3330 *inout_p = p; 3329 *inout_p = p;
3331 return AMIR_CONTINUE; 3330 return AMIR_CONTINUE;
3332} 3331}