public MSAst.Expression/*!*/ CreateVariable(AstGenerator/*!*/ ag, PythonVariable/*!*/ variable, bool emitDictionary) { Assert.NotNull(ag, variable); Debug.Assert(variable.Kind != VariableKind.Parameter); string name = SymbolTable.IdToString(variable.Name); switch (variable.Kind) { case VariableKind.Global: case VariableKind.GlobalLocal: return _variables[variable] = GetGlobal(name, ag, false); case VariableKind.Local: case VariableKind.HiddenLocal: if (ag.IsGlobal) { return _variables[variable] = GetGlobal(name, ag, true); } else if (variable.AccessedInNestedScope || (emitDictionary && variable.Kind != VariableKind.HiddenLocal)) { return ag.SetLocalLiftedVariable(variable, ag.LiftedVariable(variable, name, variable.AccessedInNestedScope)); } else { return _variables[variable] = ag.Variable(typeof(object), name); } default: throw Assert.Unreachable; } }
internal MSAst.Expression Transform(AstGenerator inner, bool needsWrapperMethod, bool needsLocalsDictionary, List<MSAst.Expression> init) { string name = SymbolTable.IdToString(Name); if (_variable.AccessedInNestedScope || needsLocalsDictionary) { ClosureExpression closureVar; if (needsWrapperMethod) { closureVar = inner.LiftedVariable(Variable, name, _variable.AccessedInNestedScope); } else { closureVar = inner.LiftedParameter(Variable, name); } inner.SetLocalLiftedVariable(_variable, closureVar); init.Add(closureVar.Create()); return closureVar; } else { MSAst.Expression parameter; if (needsWrapperMethod) { parameter = inner.Variable(typeof(object), name); } else { parameter = inner.Parameter(typeof(object), name); } inner.Globals.SetParameter(_variable, parameter); return parameter; } }