Lines Matching defs:scope
114 * Var_Dump Print out all variables defined in the given scope.
153 * There are 3 kinds of variables: scope variables, environment variables,
157 * a scope variable is using the .undef directive. In particular, it must
160 * unintended way to undefine a scope variable, see varmod-loop-delete.mk.)
171 * For scope variables, it aliases the corresponding HashEntry name.
191 * Appending to its value depends on the scope, see var-op-append.mk.
328 * A scope collects variable names and their values.
330 * The main scope is SCOPE_GLOBAL, which contains the variables that are set
339 * There is no scope for environment variables, these are generated on-the-fly
342 * Each target has its own scope, containing the 7 target-local variables
344 * this scope.
470 GNode_FindVar(GNode *scope, Substring varname, unsigned int hash)
472 return HashTable_FindValueBySubstringHash(&scope->vars, varname, hash);
476 * Find the variable in the scope, and maybe in other scopes as well.
480 * scope scope in which to look first
489 VarFindSubstring(Substring name, GNode *scope, bool elsewhere)
498 var = GNode_FindVar(scope, name, nameHash);
502 if (var == NULL && scope != SCOPE_CMDLINE)
505 if (!opts.checkEnvFirst && var == NULL && scope != SCOPE_GLOBAL) {
507 if (var == NULL && scope != SCOPE_INTERNAL) {
520 if (opts.checkEnvFirst && scope != SCOPE_GLOBAL) {
522 if (var == NULL && scope != SCOPE_INTERNAL)
535 VarFind(const char *name, GNode *scope, bool elsewhere)
537 return VarFindSubstring(Substring_InitStr(name), scope, elsewhere);
562 /* Add a new variable of the given name and value to the given scope. */
564 VarAdd(const char *name, const char *value, GNode *scope, VarSetFlags flags)
566 HashEntry *he = HashTable_CreateEntry(&scope->vars, name, NULL);
571 scope->name, name, value, ValueDescription(value));
576 * Remove a variable from a scope, freeing all related memory as well.
580 Var_Delete(GNode *scope, const char *varname)
582 HashEntry *he = HashTable_FindEntry(&scope->vars, varname);
587 scope->name, varname);
600 scope->name, varname);
610 DEBUG2(VAR, "%s: delete %s\n", scope->name, varname);
617 HashTable_DeleteEntry(&scope->vars, he);
624 Var_DeleteAll(GNode *scope)
627 HashIter_Init(&hi, &scope->vars);
637 * Undefine one or more variables from the global scope.
685 * local scope, skip it, else we can get Var_Subst
700 ExportVarEnv(Var *v, GNode *scope)
720 val = Var_Subst(expr, scope, VARE_EVAL);
721 if (scope != SCOPE_GLOBAL) {
773 ExportVar(const char *name, GNode *scope, VarExportMode mode)
780 v = VarFind(name, scope, false);
781 if (v == NULL && scope != SCOPE_GLOBAL)
787 return ExportVarEnv(v, scope);
799 Var_ReexportVars(GNode *scope)
823 ExportVar(var->name.str, scope, VEM_ENV);
836 ExportVar(varnames.words[i], scope, VEM_ENV);
1018 Var_SetWithFlags(GNode *scope, const char *name, const char *val,
1027 scope->name, name, val);
1031 if (scope == SCOPE_GLOBAL
1040 scope->name, name, val);
1045 * Only look for a variable in the given scope since anything set
1046 * here will override anything in a lower scope, so there's not much
1049 v = VarFind(name, scope, false);
1051 if (scope == SCOPE_CMDLINE && !(flags & VAR_SET_NO_EXPORT)) {
1066 scope->name, name, val);
1069 v = VarAdd(name, val, scope, flags);
1080 scope->name, name, val);
1087 scope->name, name, val, ValueDescription(val));
1089 ExportVar(name, scope, VEM_PLAIN);
1092 if (scope == SCOPE_CMDLINE) {
1125 Var_Set(GNode *scope, const char *name, const char *val)
1127 Var_SetWithFlags(scope, name, val, VAR_SET_NONE);
1131 * In the scope, expand the variable name once, then create the variable or
1135 Var_SetExpand(GNode *scope, const char *name, const char *val)
1141 Var_Expand(&varname, scope, VARE_EVAL);
1147 scope->name, varname.str, val, name);
1149 Var_SetWithFlags(scope, varname.str, val, VAR_SET_NONE);
1180 Var_Append(GNode *scope, const char *name, const char *val)
1184 v = VarFind(name, scope, scope == SCOPE_GLOBAL);
1187 Var_SetWithFlags(scope, name, val, VAR_SET_NONE);
1194 scope->name, name, val);
1195 } else if (scope == SCOPE_CMDLINE || !v->fromCmd) {
1199 DEBUG3(VAR, "%s: %s = %s\n", scope->name, name, v->val.data);
1204 HashTable_CreateEntry(&scope->vars, name, NULL);
1215 * In the scope, expand the variable name once. If the variable exists in the
1216 * scope, add a space and the value, otherwise set the variable to the value.
1218 * Appending to an environment variable only works in the global scope, that
1223 Var_AppendExpand(GNode *scope, const char *name, const char *val)
1229 Var_Expand(&xname, scope, VARE_EVAL);
1234 scope->name, xname.str, val, name);
1236 Var_Append(scope, xname.str, val);
1248 Var_Exists(GNode *scope, const char *name)
1250 Var *v = VarFind(name, scope, true);
1259 * See if the given variable exists, in the given scope or in other
1263 * scope scope in which to start search
1267 Var_ExistsExpand(GNode *scope, const char *name)
1272 Var_Expand(&varname, scope, VARE_EVAL);
1273 exists = Var_Exists(scope, varname.str);
1279 * Return the unexpanded value of the given variable in the given scope,
1291 Var_Value(GNode *scope, const char *name)
1293 Var *v = VarFind(name, scope, true);
1326 * up the variable in any other scope.
1465 GNode *scope;
1489 Var_Expand(&rhs, args->scope, VARE_EVAL);
1691 GNode *scope;
1708 Var_SetWithFlags(args->scope, args->var, word.start,
1710 s = Var_Subst(args->body, args->scope, args->emode);
2017 GNode *const_member scope;
2145 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);
3568 GNode *scope;
3599 scope = expr->scope; /* scope where v belongs */
3600 if (expr->defined == DEF_REGULAR && expr->scope != SCOPE_GLOBAL
3601 && VarFind(expr->name, expr->scope, false) == NULL)
3602 scope = SCOPE_GLOBAL;
3605 Var_Append(scope, expr->name, val.str);
3613 Var_Set(scope, expr->name, output);
3618 Var_Set(scope, expr->name, val.str);
3769 args.scope = expr->scope;
3964 FStr mods = Var_Parse(&p, expr->scope, expr->emode);
4185 UndefinedShortVarValue(char varname, const GNode *scope)
4187 if (scope == SCOPE_CMDLINE || scope == SCOPE_GLOBAL) {
4189 * If substituting a local variable in a non-local scope,
4217 GNode *scope, VarEvalMode emode,
4234 FStr nested_val = Var_Parse(&p, scope, emode);
4273 ParseVarnameShort(char varname, const char **pp, GNode *scope,
4290 v = VarFind(name, scope, true);
4299 val = UndefinedShortVarValue(varname, scope);
4314 FindLocalLegacyVar(Substring varname, GNode *scope,
4319 /* Only resolve these variables if scope is a "real" target. */
4320 if (scope == SCOPE_CMDLINE || scope == SCOPE_GLOBAL)
4331 scope, false);
4367 GNode *scope,
4392 ParseVarname(&p, startc, endc, scope, emode, &varname);
4408 v = VarFindSubstring(name, scope, true);
4421 v = FindLocalLegacyVar(name, scope, out_true_extraModifiers);
4426 * non-local scope since they are not defined there.
4429 (scope == SCOPE_CMDLINE || scope == SCOPE_GLOBAL);
4469 #define Expr_Init(name, value, emode, scope, defined) \
4470 (Expr) { name, value, emode, scope, defined }
4474 VarEvalMode emode, GNode *scope, ExprDefined defined)
4481 expr.scope = scope;
4523 * scope The scope for finding variables.
4549 Var_Parse(const char **pp, GNode *scope, VarEvalMode emode)
4558 * expanded in a non-local scope. The result is the text of the
4565 scope, DEF_REGULAR);
4583 if (!ParseVarnameShort(startc, pp, scope, emode, &val.str, &v))
4588 if (!ParseVarnameLong(&p, startc, scope, emode,
4597 if (scope->fname != NULL) {
4599 PrintLocation(stderr, false, scope);
4642 expanded = Var_Subst(Expr_Str(&expr), scope, nested_emode);
4702 VarSubstExpr(const char **pp, Buffer *buf, GNode *scope,
4707 FStr val = Var_Parse(&nested_p, scope, emode);
4776 * scope The scope in which to start searching for variables.
4781 Var_Subst(const char *str, GNode *scope, VarEvalMode emode)
4799 VarSubstExpr(&p, &res, scope, emode, &errorReported);
4808 Var_SubstInTarget(const char *str, GNode *scope)
4811 EvalStack_Push(VSK_TARGET, scope->name, NULL);
4812 res = Var_Subst(str, scope, VARE_EVAL);
4818 Var_Expand(FStr *str, GNode *scope, VarEvalMode emode)
4824 expanded = Var_Subst(str->str, scope, emode);
4844 /* Print all variables in a scope, sorted by name. */
4846 Var_Dump(GNode *scope)
4855 HashIter_Init(&hi, &scope->vars);
4864 const Var *var = HashTable_FindValue(&scope->vars, varname);