Lines Matching defs:scope
114 * Var_Dump Print out all variables defined in the given scope.
138 * There are 3 kinds of variables: scope variables, environment variables,
142 * a scope variable is using the .undef directive. In particular, it must
145 * unintended way to undefine a scope variable, see varmod-loop-delete.mk.)
156 * For scope variables, it aliases the corresponding HashEntry name.
176 * Appending to its value depends on the scope, see var-op-append.mk.
315 * A scope collects variable names and their values.
317 * The main scope is SCOPE_GLOBAL, which contains the variables that are set
326 * There is no scope for environment variables, these are generated on-the-fly
329 * Each target has its own scope, containing the 7 target-local variables
331 * this scope.
468 GNode_FindVar(GNode *scope, Substring varname, unsigned hash)
470 return HashTable_FindValueBySubstringHash(&scope->vars, varname, hash);
474 * Find the variable in the scope, and maybe in other scopes as well.
478 * scope scope in which to look first
487 VarFindSubstring(Substring name, GNode *scope, bool elsewhere)
496 var = GNode_FindVar(scope, name, nameHash);
500 if (var == NULL && scope != SCOPE_CMDLINE)
503 if (!opts.checkEnvFirst && var == NULL && scope != SCOPE_GLOBAL) {
505 if (var == NULL && scope != SCOPE_INTERNAL) {
518 if (opts.checkEnvFirst && scope != SCOPE_GLOBAL) {
520 if (var == NULL && scope != SCOPE_INTERNAL)
533 VarFind(const char *name, GNode *scope, bool elsewhere)
535 return VarFindSubstring(Substring_InitStr(name), scope, elsewhere);
560 /* Add a new variable of the given name and value to the given scope. */
562 VarAdd(const char *name, const char *value, GNode *scope, VarSetFlags flags)
564 HashEntry *he = HashTable_CreateEntry(&scope->vars, name, NULL);
569 scope->name, name, value, ValueDescription(value));
574 * Remove a variable from a scope, freeing all related memory as well.
578 Var_Delete(GNode *scope, const char *varname)
580 HashEntry *he = HashTable_FindEntry(&scope->vars, varname);
585 scope->name, varname);
598 scope->name, varname);
608 DEBUG2(VAR, "%s: delete %s\n", scope->name, varname);
615 HashTable_DeleteEntry(&scope->vars, he);
622 Var_DeleteAll(GNode *scope)
625 HashIter_Init(&hi, &scope->vars);
635 * Undefine one or more variables from the global scope.
683 * local scope, skip it, else we can get Var_Subst
698 ExportVarEnv(Var *v, GNode *scope)
718 val = Var_Subst(expr, scope, VARE_EVAL);
719 if (scope != SCOPE_GLOBAL) {
771 ExportVar(const char *name, GNode *scope, VarExportMode mode)
778 v = VarFind(name, scope, false);
779 if (v == NULL && scope != SCOPE_GLOBAL)
785 return ExportVarEnv(v, scope);
797 Var_ReexportVars(GNode *scope)
821 ExportVar(var->name.str, scope, VEM_ENV);
834 ExportVar(varnames.words[i], scope, VEM_ENV);
1016 Var_SetWithFlags(GNode *scope, const char *name, const char *val,
1025 scope->name, name, val);
1029 if (scope == SCOPE_GLOBAL
1038 scope->name, name, val);
1043 * Only look for a variable in the given scope since anything set
1044 * here will override anything in a lower scope, so there's not much
1047 v = VarFind(name, scope, false);
1049 if (scope == SCOPE_CMDLINE && !(flags & VAR_SET_NO_EXPORT)) {
1064 scope->name, name, val);
1077 scope->name, name, val);
1080 v = VarAdd(name, val, scope, flags);
1091 scope->name, name, val);
1098 scope->name, name, val, ValueDescription(val));
1100 ExportVar(name, scope, VEM_PLAIN);
1103 if (scope == SCOPE_CMDLINE) {
1136 Var_Set(GNode *scope, const char *name, const char *val)
1138 Var_SetWithFlags(scope, name, val, VAR_SET_NONE);
1142 * In the scope, expand the variable name once, then create the variable or
1146 Var_SetExpand(GNode *scope, const char *name, const char *val)
1152 Var_Expand(&varname, scope, VARE_EVAL);
1158 scope->name, varname.str, val, name);
1160 Var_SetWithFlags(scope, varname.str, val, VAR_SET_NONE);
1191 Var_Append(GNode *scope, const char *name, const char *val)
1195 v = VarFind(name, scope, scope == SCOPE_GLOBAL);
1198 Var_SetWithFlags(scope, name, val, VAR_SET_NONE);
1205 scope->name, name, val);
1206 } else if (scope == SCOPE_CMDLINE || !v->fromCmd) {
1210 DEBUG3(VAR, "%s: %s = %s\n", scope->name, name, v->val.data);
1215 HashTable_CreateEntry(&scope->vars, name, NULL);
1226 * In the scope, expand the variable name once. If the variable exists in the
1227 * scope, add a space and the value, otherwise set the variable to the value.
1229 * Appending to an environment variable only works in the global scope, that
1234 Var_AppendExpand(GNode *scope, const char *name, const char *val)
1240 Var_Expand(&xname, scope, VARE_EVAL);
1245 scope->name, xname.str, val, name);
1247 Var_Append(scope, xname.str, val);
1259 Var_Exists(GNode *scope, const char *name)
1261 Var *v = VarFind(name, scope, true);
1270 * See if the given variable exists, in the given scope or in other
1274 * scope scope in which to start search
1278 Var_ExistsExpand(GNode *scope, const char *name)
1283 Var_Expand(&varname, scope, VARE_EVAL);
1284 exists = Var_Exists(scope, varname.str);
1290 * Return the unexpanded value of the given variable in the given scope,
1302 Var_Value(GNode *scope, const char *name)
1304 Var *v = VarFind(name, scope, true);
1337 * up the variable in any other scope.
1470 GNode *scope;
1494 Var_Expand(&rhs, args->scope, VARE_EVAL);
1695 GNode *scope;
1712 Var_SetWithFlags(args->scope, args->var, word.start,
1714 s = Var_Subst(args->body, args->scope, args->emode);
2017 GNode *const_member scope;
2143 FStr nested_val = Var_Parse(&p, ch->expr->scope,
2406 args.scope = expr->scope;
2437 Var_Delete(expr->scope, args.var);
2478 FStr val = Var_Parse(&p, ch->expr->scope,
2795 pattern = Var_Subst(pattern, expr->scope, expr->emode);
3553 GNode *scope;
3591 scope = expr->scope; /* scope where v belongs */
3592 if (expr->defined == DEF_REGULAR && expr->scope != SCOPE_GLOBAL
3593 && VarFind(expr->name, expr->scope, false) == NULL)
3594 scope = SCOPE_GLOBAL;
3597 Var_Append(scope, expr->name, val.str);
3605 Var_Set(scope, expr->name, output);
3610 Var_Set(scope, expr->name, val.str);
3755 args.scope = expr->scope;
3987 FStr mods = Var_Parse(&p, expr->scope, expr->emode);
4206 UndefinedShortVarValue(char varname, const GNode *scope)
4208 if (scope == SCOPE_CMDLINE || scope == SCOPE_GLOBAL) {
4210 * If substituting a local variable in a non-local scope,
4238 GNode *scope, VarEvalMode emode,
4255 FStr nested_val = Var_Parse(&p, scope, emode);
4294 ParseVarnameShort(char varname, const char **pp, GNode *scope,
4311 v = VarFind(name, scope, true);
4320 val = UndefinedShortVarValue(varname, scope);
4338 FindLocalLegacyVar(Substring varname, GNode *scope,
4343 /* Only resolve these variables if scope is a "real" target. */
4344 if (scope == SCOPE_CMDLINE || scope == SCOPE_GLOBAL)
4355 scope, false);
4414 GNode *scope,
4441 ParseVarname(&p, startc, endc, scope, nested_emode, &varname);
4457 v = VarFindSubstring(name, scope, true);
4470 v = FindLocalLegacyVar(name, scope, out_true_extraModifiers);
4475 * non-local scope since they are not defined there.
4478 (scope == SCOPE_CMDLINE || scope == SCOPE_GLOBAL);
4519 #define Expr_Init(name, value, emode, scope, defined) \
4520 (Expr) { name, value, emode, scope, defined }
4524 VarEvalMode emode, GNode *scope, ExprDefined defined)
4531 expr.scope = scope;
4573 * scope The scope for finding variables.
4597 Var_Parse(const char **pp, GNode *scope, VarEvalMode emode)
4606 * expanded in a non-local scope. The result is the text of the
4615 scope, DEF_REGULAR);
4634 if (!ParseVarnameShort(startc, pp, scope, emode, &val.str, &v))
4639 if (!ParseVarnameLong(&p, startc, scope, emode, expr.emode,
4693 expanded = Var_Subst(Expr_Str(&expr), scope, expr.emode);
4746 VarSubstExpr(const char **pp, Buffer *buf, GNode *scope, VarEvalMode emode)
4750 FStr val = Var_Parse(&nested_p, scope, emode);
4799 * scope The scope in which to start searching for variables.
4804 Var_Subst(const char *str, GNode *scope, VarEvalMode emode)
4815 VarSubstExpr(&p, &res, scope, emode);
4824 Var_SubstInTarget(const char *str, GNode *scope)
4827 EvalStack_Push(VSK_TARGET, scope->name, NULL);
4829 res = Var_Subst(str, scope, VARE_EVAL);
4859 Var_Expand(FStr *str, GNode *scope, VarEvalMode emode)
4865 expanded = Var_Subst(str->str, scope, emode);
4885 /* Print all variables in a scope, sorted by name. */
4887 Var_Dump(GNode *scope)
4896 HashIter_Init(&hi, &scope->vars);
4905 const Var *var = HashTable_FindValue(&scope->vars, varname);