public bool MustCaptureVariable (LocalInfo local) { if (CurrentAnonymousMethod == null) return false; // FIXME: IsIterator is too aggressive, we should capture only if child // block contains yield if (CurrentAnonymousMethod.IsIterator) return true; return local.Block.Toplevel != CurrentBlock.Toplevel; }
public LocalInfo Clone (CloneContext clonectx) { // // Variables in anonymous block are not resolved yet // if (VariableType == null) return new LocalInfo ((FullNamedExpression) Type.Clone (clonectx), Name, clonectx.LookupBlock (Block), Location); // // Variables in method block are resolved // LocalInfo li = new LocalInfo (null, Name, clonectx.LookupBlock (Block), Location); li.VariableType = VariableType; return li; }
protected virtual string GetVariableMangledName (LocalInfo local_info) { // // No need to mangle anonymous method hoisted variables cause they // are hoisted in their own scopes // return local_info.Name; }
protected override string GetVariableMangledName(LocalInfo local_info) { return "<" + local_info.Name + ">__" + local_name_idx++.ToString (); }
protected Emitter (Expression expr, LocalInfo li) { converted = expr; vi = li; }
public StringEmitter (Expression expr, LocalInfo li, Location loc): base (expr, li) { pinned_string = new LocalInfo (new TypeExpression (TypeManager.string_type, loc), null, null, loc); pinned_string.Pinned = true; }
public StringEmitter (Expression expr, LocalInfo li, Location loc): base (expr, li) { this.loc = loc; }
public LocalInfo AddTemporaryVariable (TypeExpr te, Location loc) { Report.Debug (64, "ADD TEMPORARY", this, Toplevel, loc); if (temporary_variables == null) temporary_variables = new List<LocalInfo> (); int id = ++next_temp_id; string name = "$s_" + id.ToString (); LocalInfo li = new LocalInfo (te, name, this, loc); li.CompilerGenerated = true; temporary_variables.Add (li); return li; }
public LocalInfo LookupVariable (LocalInfo from) { LocalInfo result = (LocalInfo) variable_map [from]; if (result == null) throw new Exception ("LookupVariable: looking up a variable that has not been registered yet"); return result; }
public LocalInfo AddVariable (Expression type, string name, Location l) { if (!CheckParentConflictName (Toplevel, name, l)) return null; if (Toplevel.GenericMethod != null) { foreach (TypeParameter tp in Toplevel.GenericMethod.CurrentTypeParameters) { if (tp.Name == name) { Report.SymbolRelatedToPreviousError (tp); Error_AlreadyDeclaredTypeParameter (loc, name, "local variable"); return null; } } } IKnownVariable kvi = Explicit.GetKnownVariable (name); if (kvi != null) { Report.SymbolRelatedToPreviousError (kvi.Location, name); Error_AlreadyDeclared (l, name, "child"); return null; } LocalInfo vi = new LocalInfo (type, name, this, l); AddVariable (vi); if ((flags & Flags.VariablesInitialized) != 0) throw new InternalErrorException ("block has already been resolved"); return vi; }
public void AddVariableMap (LocalInfo from, LocalInfo to) { if (variable_map == null) variable_map = new Hashtable (); if (variable_map.Contains (from)) return; variable_map [from] = to; }
public LocalInfo LookupVariable (LocalInfo from) { try { return variable_map[from]; } catch (KeyNotFoundException) { throw new Exception ("LookupVariable: looking up a variable that has not been registered yet"); } }
public void AddVariableMap (LocalInfo from, LocalInfo to) { if (variable_map == null) variable_map = new Dictionary<LocalInfo, LocalInfo> (); else if (variable_map.ContainsKey (from)) return; variable_map[from] = to; }
public LocalInfo AddVariable (Expression type, string name, Location l) { if (!CheckParentConflictName (Toplevel, name, l)) return null; IKnownVariable kvi = Explicit.GetKnownVariable (name); if (kvi != null) { Toplevel.Report.SymbolRelatedToPreviousError (kvi.Location, name); Error_AlreadyDeclared (l, name, "child"); return null; } LocalInfo vi = new LocalInfo ((FullNamedExpression) type, name, this, l); AddVariable (vi); if ((flags & Flags.VariablesInitialized) != 0) throw new InternalErrorException ("block has already been resolved"); return vi; }
protected VariableInfo (VariableInfo parent, TypeInfo type) { this.Name = parent.Name; this.TypeInfo = type; this.Offset = parent.Offset + type.Offset; this.Parent = parent; this.Length = type.TotalLength; this.IsParameter = parent.IsParameter; this.LocalInfo = parent.LocalInfo; Initialize (); }
protected virtual void AddVariable (LocalInfo li) { Variables.Add (li.Name, li); Explicit.AddKnownVariable (li.Name, li); }
public VariableInfo (LocalInfo local_info, int offset) : this (local_info.Name, local_info.VariableType, offset) { this.LocalInfo = local_info; this.IsParameter = false; }
// <summary> // This is used by non-static `struct' constructors which do not have an // initializer - in this case, the constructor must initialize all of the // struct's fields. To do this, we add a "this" variable and use the flow // analysis code to ensure that it's been fully initialized before control // leaves the constructor. // </summary> public LocalInfo AddThisVariable (TypeContainer ds, Location l) { if (this_variable == null) { this_variable = new LocalInfo (ds, this, l); this_variable.Used = true; this_variable.IsThis = true; Variables.Add ("this", this_variable); } return this_variable; }
// // Setting `is_readonly' to false will allow you to create a writable // reference to a read-only variable. This is used by foreach and using. // public LocalVariableReference (Block block, string name, Location l, LocalInfo local_info, bool is_readonly) : this (block, name, l) { this.local_info = local_info; this.is_readonly = is_readonly; }
public ExpressionEmitter (Expression converted, LocalInfo li) : base (converted, li) { }
void ResolveLocalInfo () { if (local_info == null) { local_info = Block.GetLocalInfo (Name); type = local_info.VariableType; is_readonly = local_info.ReadOnly; } }
public void CaptureLocalVariable (ResolveContext ec, LocalInfo local_info) { ec.CurrentBlock.Explicit.HasCapturedVariable = true; if (ec.CurrentBlock.Explicit != local_info.Block.Explicit) AddReferenceFromChildrenBlock (ec.CurrentBlock.Explicit); if (local_info.HoistedVariant != null) return; HoistedVariable var = new HoistedLocalVariable (this, local_info, GetVariableMangledName (local_info)); local_info.HoistedVariant = var; if (hoisted_locals == null) hoisted_locals = new List<HoistedVariable> (); hoisted_locals.Add (var); }
protected override Expression DoResolve(ResolveContext ec) { eclass = ExprClass.Variable; TypeExpr te = new TypeExpression (type, loc); li = ec.CurrentBlock.AddTemporaryVariable (te, loc); if (!li.Resolve (ec)) return null; // // Don't capture temporary variables except when using // iterator redirection // if (ec.CurrentAnonymousMethod != null && ec.CurrentAnonymousMethod.IsIterator && ec.IsVariableCapturingRequired) { AnonymousMethodStorey storey = li.Block.Explicit.CreateAnonymousMethodStorey (ec); storey.CaptureLocalVariable (ec, li); } return this; }
public HoistedLocalVariable (AnonymousMethodStorey scope, LocalInfo local, string name) : base (scope, name, local.VariableType) { this.name = local.Name; }
public LocalVariableReferenceWithClassSideEffect(TypeContainer container, string name, Block current_block, string local_variable_id, LocalInfo li, Location loc) : base(current_block, local_variable_id, loc, li, false) { this.container = container; this.name = name; }
VariableDeclarationStatement CreateVariableDeclaration (LocalInfo info) { VariableDeclarationStatement result = new VariableDeclarationStatement (); result.AddChild ((INode)info.Type.Accept (this), CatchClause.Roles.ReturnType); VariableInitializer variable = new VariableInitializer (); variable.AddChild (new Identifier (info.Name, Convert (info.Location)), AbstractNode.Roles.Identifier); result.AddChild (variable, AbstractNode.Roles.Initializer); result.AddChild (new Identifier (info.Name, Convert (info.Location)), CatchClause.Roles.ReturnType); return result; }
public void CaptureLocalVariable (EmitContext ec, LocalInfo local_info) { if (local_info.HoistedVariableReference != null) return; HoistedVariable var = new HoistedLocalVariable (this, local_info, GetVariableMangledName (local_info)); local_info.HoistedVariableReference = var; has_hoisted_variable = true; if (hoisted_locals == null) hoisted_locals = new ArrayList (); hoisted_locals.Add (var); }