Lines Matching full:scope
114 * Var_Dump Print out all variables defined in the given scope.
153 * There are 3 kinds of variables: scope variables, environment variables,
156 * Scope variables are stored in GNode.vars. The only way to undefine
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.
330 * A scope collects variable names and their values.
332 * The main scope is SCOPE_GLOBAL, which contains the variables that are set
341 * There is no scope for environment variables, these are generated on-the-fly
344 * Each target has its own scope, containing the 7 target-local variables
346 * this scope.
483 GNode_FindVar(GNode *scope, Substring varname, unsigned hash) in GNode_FindVar() argument
485 return HashTable_FindValueBySubstringHash(&scope->vars, varname, hash); in GNode_FindVar()
489 * Find the variable in the scope, and maybe in other scopes as well.
493 * scope scope in which to look first
502 VarFindSubstring(Substring name, GNode *scope, bool elsewhere) in VarFindSubstring() argument
511 var = GNode_FindVar(scope, name, nameHash); in VarFindSubstring()
515 if (var == NULL && scope != SCOPE_CMDLINE) in VarFindSubstring()
518 if (!opts.checkEnvFirst && var == NULL && scope != SCOPE_GLOBAL) { in VarFindSubstring()
520 if (var == NULL && scope != SCOPE_INTERNAL) { in VarFindSubstring()
533 if (opts.checkEnvFirst && scope != SCOPE_GLOBAL) { in VarFindSubstring()
535 if (var == NULL && scope != SCOPE_INTERNAL) in VarFindSubstring()
548 VarFind(const char *name, GNode *scope, bool elsewhere) in VarFind() argument
550 return VarFindSubstring(Substring_InitStr(name), scope, elsewhere); in VarFind()
575 /* Add a new variable of the given name and value to the given scope. */
577 VarAdd(const char *name, const char *value, GNode *scope, VarSetFlags flags) in VarAdd() argument
579 HashEntry *he = HashTable_CreateEntry(&scope->vars, name, NULL); in VarAdd()
584 scope->name, name, value, ValueDescription(value)); in VarAdd()
589 * Remove a variable from a scope, freeing all related memory as well.
593 Var_Delete(GNode *scope, const char *varname) in Var_Delete() argument
595 HashEntry *he = HashTable_FindEntry(&scope->vars, varname); in Var_Delete()
600 scope->name, varname); in Var_Delete()
613 scope->name, varname); in Var_Delete()
623 DEBUG2(VAR, "%s: delete %s\n", scope->name, varname); in Var_Delete()
630 HashTable_DeleteEntry(&scope->vars, he); in Var_Delete()
637 Var_DeleteAll(GNode *scope) in Var_DeleteAll() argument
640 HashIter_Init(&hi, &scope->vars); in Var_DeleteAll()
650 * Undefine one or more variables from the global scope.
698 * local scope, skip it, else we can get Var_Subst in MayExport()
713 ExportVarEnv(Var *v, GNode *scope) in ExportVarEnv() argument
733 val = Var_Subst(expr, scope, VARE_EVAL); in ExportVarEnv()
734 if (scope != SCOPE_GLOBAL) { in ExportVarEnv()
786 ExportVar(const char *name, GNode *scope, VarExportMode mode) in ExportVar() argument
793 v = VarFind(name, scope, false); in ExportVar()
794 if (v == NULL && scope != SCOPE_GLOBAL) in ExportVar()
800 return ExportVarEnv(v, scope); in ExportVar()
812 Var_ReexportVars(GNode *scope) in Var_ReexportVars() argument
836 ExportVar(var->name.str, scope, VEM_ENV); in Var_ReexportVars()
849 ExportVar(varnames.words[i], scope, VEM_ENV); in Var_ReexportVars()
1031 Var_SetWithFlags(GNode *scope, const char *name, const char *val, in Var_SetWithFlags() argument
1040 scope->name, name, val); in Var_SetWithFlags()
1044 if (scope == SCOPE_GLOBAL in Var_SetWithFlags()
1053 scope->name, name, val); in Var_SetWithFlags()
1058 * Only look for a variable in the given scope since anything set in Var_SetWithFlags()
1059 * here will override anything in a lower scope, so there's not much in Var_SetWithFlags()
1062 v = VarFind(name, scope, false); in Var_SetWithFlags()
1064 if (scope == SCOPE_CMDLINE && !(flags & VAR_SET_NO_EXPORT)) { in Var_SetWithFlags()
1079 scope->name, name, val); in Var_SetWithFlags()
1092 scope->name, name, val); in Var_SetWithFlags()
1095 v = VarAdd(name, val, scope, flags); in Var_SetWithFlags()
1106 scope->name, name, val); in Var_SetWithFlags()
1113 scope->name, name, val, ValueDescription(val)); in Var_SetWithFlags()
1115 ExportVar(name, scope, VEM_PLAIN); in Var_SetWithFlags()
1118 if (scope == SCOPE_CMDLINE) { in Var_SetWithFlags()
1151 Var_Set(GNode *scope, const char *name, const char *val) in Var_Set() argument
1153 Var_SetWithFlags(scope, name, val, VAR_SET_NONE); in Var_Set()
1157 * In the scope, expand the variable name once, then create the variable or
1161 Var_SetExpand(GNode *scope, const char *name, const char *val) in Var_SetExpand() argument
1167 Var_Expand(&varname, scope, VARE_EVAL); in Var_SetExpand()
1173 scope->name, varname.str, val, name); in Var_SetExpand()
1175 Var_SetWithFlags(scope, varname.str, val, VAR_SET_NONE); in Var_SetExpand()
1206 Var_Append(GNode *scope, const char *name, const char *val) in Var_Append() argument
1210 v = VarFind(name, scope, scope == SCOPE_GLOBAL); in Var_Append()
1213 Var_SetWithFlags(scope, name, val, VAR_SET_NONE); in Var_Append()
1220 scope->name, name, val); in Var_Append()
1221 } else if (scope == SCOPE_CMDLINE || !v->fromCmd) { in Var_Append()
1225 DEBUG3(VAR, "%s: %s = %s\n", scope->name, name, v->val.data); in Var_Append()
1230 HashTable_CreateEntry(&scope->vars, name, NULL); in Var_Append()
1241 * In the scope, expand the variable name once. If the variable exists in the
1242 * scope, add a space and the value, otherwise set the variable to the value.
1244 * Appending to an environment variable only works in the global scope, that
1249 Var_AppendExpand(GNode *scope, const char *name, const char *val) in Var_AppendExpand() argument
1255 Var_Expand(&xname, scope, VARE_EVAL); in Var_AppendExpand()
1260 scope->name, xname.str, val, name); in Var_AppendExpand()
1262 Var_Append(scope, xname.str, val); in Var_AppendExpand()
1274 Var_Exists(GNode *scope, const char *name) in Var_Exists() argument
1276 Var *v = VarFind(name, scope, true); in Var_Exists()
1285 * See if the given variable exists, in the given scope or in other
1289 * scope scope in which to start search
1293 Var_ExistsExpand(GNode *scope, const char *name) in Var_ExistsExpand() argument
1298 Var_Expand(&varname, scope, VARE_EVAL); in Var_ExistsExpand()
1299 exists = Var_Exists(scope, varname.str); in Var_ExistsExpand()
1305 * Return the unexpanded value of the given variable in the given scope,
1317 Var_Value(GNode *scope, const char *name) in Var_Value() argument
1319 Var *v = VarFind(name, scope, true); in Var_Value()
1352 * up the variable in any other scope.
1485 GNode *scope; member
1509 Var_Expand(&rhs, args->scope, VARE_EVAL); in ModifyWord_SysVSubst()
1711 GNode *scope; member
1728 Var_SetWithFlags(args->scope, args->var, word.start, in ModifyWord_Loop()
1730 s = Var_Subst(args->body, args->scope, args->emode); in ModifyWord_Loop()
2033 GNode *const_member scope; member
2159 FStr nested_val = Var_Parse(&p, ch->expr->scope, in ParseModifierPartExpr()
2422 args.scope = expr->scope; in ApplyModifier_Loop()
2453 Var_Delete(expr->scope, args.var); in ApplyModifier_Loop()
2494 FStr val = Var_Parse(&p, ch->expr->scope, in ParseModifier_Defined()
2811 pattern = Var_Subst(pattern, expr->scope, expr->emode); in ParseModifier_Match()
3573 GNode *scope; in ApplyModifier_Assign() local
3611 scope = expr->scope; /* scope where v belongs */ in ApplyModifier_Assign()
3612 if (expr->defined == DEF_REGULAR && expr->scope != SCOPE_GLOBAL in ApplyModifier_Assign()
3613 && VarFind(expr->name, expr->scope, false) == NULL) in ApplyModifier_Assign()
3614 scope = SCOPE_GLOBAL; in ApplyModifier_Assign()
3617 Var_Append(scope, expr->name, val.str); in ApplyModifier_Assign()
3625 Var_Set(scope, expr->name, output); in ApplyModifier_Assign()
3630 Var_Set(scope, expr->name, val.str); in ApplyModifier_Assign()
3775 args.scope = expr->scope; in ApplyModifier_SysV()
3969 FStr mods = Var_Parse(&p, expr->scope, expr->emode); in ApplyModifiersIndirect()
4188 UndefinedShortVarValue(char varname, const GNode *scope) in UndefinedShortVarValue() argument
4190 if (scope == SCOPE_CMDLINE || scope == SCOPE_GLOBAL) { in UndefinedShortVarValue()
4192 * If substituting a local variable in a non-local scope, in UndefinedShortVarValue()
4220 GNode *scope, VarEvalMode emode, in ParseVarname() argument
4237 FStr nested_val = Var_Parse(&p, scope, emode); in ParseVarname()
4276 ParseVarnameShort(char varname, const char **pp, GNode *scope, in ParseVarnameShort() argument
4293 v = VarFind(name, scope, true); in ParseVarnameShort()
4302 val = UndefinedShortVarValue(varname, scope); in ParseVarnameShort()
4320 FindLocalLegacyVar(Substring varname, GNode *scope, in FindLocalLegacyVar() argument
4325 /* Only resolve these variables if scope is a "real" target. */ in FindLocalLegacyVar()
4326 if (scope == SCOPE_CMDLINE || scope == SCOPE_GLOBAL) in FindLocalLegacyVar()
4337 scope, false); in FindLocalLegacyVar()
4396 GNode *scope, in ParseVarnameLong() argument
4423 ParseVarname(&p, startc, endc, scope, nested_emode, &varname); in ParseVarnameLong()
4439 v = VarFindSubstring(name, scope, true); in ParseVarnameLong()
4452 v = FindLocalLegacyVar(name, scope, out_true_extraModifiers); in ParseVarnameLong()
4457 * non-local scope since they are not defined there. in ParseVarnameLong()
4460 (scope == SCOPE_CMDLINE || scope == SCOPE_GLOBAL); in ParseVarnameLong()
4501 #define Expr_Init(name, value, emode, scope, defined) \ argument
4502 (Expr) { name, value, emode, scope, defined }
4506 VarEvalMode emode, GNode *scope, ExprDefined defined) in Expr_Init() argument
4513 expr.scope = scope; in Expr_Init()
4555 * scope The scope for finding variables.
4579 Var_Parse(const char **pp, GNode *scope, VarEvalMode emode) in Var_Parse() argument
4588 * expanded in a non-local scope. The result is the text of the in Var_Parse()
4597 scope, DEF_REGULAR); in Var_Parse()
4616 if (!ParseVarnameShort(startc, pp, scope, emode, &val.str, &v)) in Var_Parse()
4621 if (!ParseVarnameLong(&p, startc, scope, emode, expr.emode, in Var_Parse()
4675 expanded = Var_Subst(Expr_Str(&expr), scope, expr.emode); in Var_Parse()
4728 VarSubstExpr(const char **pp, Buffer *buf, GNode *scope, VarEvalMode emode) in VarSubstExpr() argument
4732 FStr val = Var_Parse(&nested_p, scope, emode); in VarSubstExpr()
4781 * scope The scope in which to start searching for variables.
4786 Var_Subst(const char *str, GNode *scope, VarEvalMode emode) in Var_Subst() argument
4797 VarSubstExpr(&p, &res, scope, emode); in Var_Subst()
4806 Var_SubstInTarget(const char *str, GNode *scope) in Var_SubstInTarget() argument
4809 EvalStack_Push(VSK_TARGET, scope->name, NULL); in Var_SubstInTarget()
4811 res = Var_Subst(str, scope, VARE_EVAL); in Var_SubstInTarget()
4841 Var_Expand(FStr *str, GNode *scope, VarEvalMode emode) in Var_Expand() argument
4847 expanded = Var_Subst(str->str, scope, emode); in Var_Expand()
4867 /* Print all variables in a scope, sorted by name. */
4869 Var_Dump(GNode *scope) in Var_Dump() argument
4878 HashIter_Init(&hi, &scope->vars); in Var_Dump()
4887 const Var *var = HashTable_FindValue(&scope->vars, varname); in Var_Dump()