Ejemplo n.º 1
0
Archivo: context.cs Proyecto: ikvm/mono
		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;
		}
Ejemplo n.º 2
0
		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;			
		}
Ejemplo n.º 3
0
		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;
		}
Ejemplo n.º 4
0
 protected override string GetVariableMangledName(LocalInfo local_info)
 {
     return "<" + local_info.Name + ">__" + local_name_idx++.ToString ();
 }
Ejemplo n.º 5
0
			protected Emitter (Expression expr, LocalInfo li)
			{
				converted = expr;
				vi = li;
			}
Ejemplo n.º 6
0
			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;
			}
Ejemplo n.º 7
0
			public StringEmitter (Expression expr, LocalInfo li, Location loc):
				base (expr, li)
			{
				this.loc = loc;
			}
Ejemplo n.º 8
0
		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;
		}
Ejemplo n.º 9
0
		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;
		}
Ejemplo n.º 10
0
		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;
		}
Ejemplo n.º 11
0
		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;
		}
Ejemplo n.º 12
0
Archivo: context.cs Proyecto: ikvm/mono
		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");
			}
		}
Ejemplo n.º 13
0
Archivo: context.cs Proyecto: ikvm/mono
		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;
		}
Ejemplo n.º 14
0
		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;
		}
Ejemplo n.º 15
0
		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 ();
		}
Ejemplo n.º 16
0
		protected virtual void AddVariable (LocalInfo li)
		{
			Variables.Add (li.Name, li);
			Explicit.AddKnownVariable (li.Name, li);
		}
Ejemplo n.º 17
0
		public VariableInfo (LocalInfo local_info, int offset)
			: this (local_info.Name, local_info.VariableType, offset)
		{
			this.LocalInfo = local_info;
			this.IsParameter = false;
		}
Ejemplo n.º 18
0
		// <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;
		}
Ejemplo n.º 19
0
		//
		// 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;
		}
Ejemplo n.º 20
0
			public ExpressionEmitter (Expression converted, LocalInfo li) :
				base (converted, li)
			{
			}
Ejemplo n.º 21
0
		void ResolveLocalInfo ()
		{
			if (local_info == null) {
				local_info = Block.GetLocalInfo (Name);
				type = local_info.VariableType;
				is_readonly = local_info.ReadOnly;
			}
		}
Ejemplo n.º 22
0
		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);
		}
Ejemplo n.º 23
0
        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;
        }
Ejemplo n.º 24
0
		public HoistedLocalVariable (AnonymousMethodStorey scope, LocalInfo local, string name)
			: base (scope, name, local.VariableType)
		{
			this.name = local.Name;
		}
Ejemplo n.º 25
0
Archivo: eval.cs Proyecto: speier/shake
 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;
 }
Ejemplo n.º 26
0
			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;
			}
Ejemplo n.º 27
0
		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);
		}