public Scope(Scope parent, BodySyntax body, IScriptBuilder scriptBuilder) { Parent = parent; TypeManager = new BoundTypeManager(); if (body.Closure != null) { _sourceClosure = body.Closure; Closure = new BoundClosure( FindParentClosure(), body.Closure.Fields.Select(p => TypeManager.CreateType(p, BoundTypeKind.ClosureField)), scriptBuilder ); } foreach (var variable in body.Identifiers) { if (variable.Index.HasValue) { BoundClosure closure = null; if (variable.Closure != null) closure = GetClosure(variable.Closure); _arguments.Add(variable, new BoundArgument(variable.Name, variable.Index.Value, closure)); } else if (variable.Closure == null) { BoundLocalBase local; if (variable.Type == IdentifierType.Global) local = new BoundGlobal(variable.IsDeclared, TypeManager.CreateType(variable.Name, BoundTypeKind.Global)); else local = new BoundLocal(variable.IsDeclared, TypeManager.CreateType(variable.Name, BoundTypeKind.Local)); _locals.Add(variable, local); } } }
public BoundLocalBase GetLocal(IIdentifier identifier) { BoundLocalBase result; if (!_locals.TryGetValue(identifier, out result)) { Debug.Assert(identifier.Type == IdentifierType.Global); result = new BoundGlobal(false, TypeManager.CreateType(identifier.Name, BoundTypeKind.Global)); _locals.Add(identifier, result); } return result; }