Inheritance: INamedBlockVariable, ILocalVariable
コード例 #1
0
ファイル: statement.cs プロジェクト: alisci01/mono
			protected Emitter (Expression expr, LocalVariable li)
				: base (expr)
			{
				vi = li;
			}
コード例 #2
0
ファイル: anonymous.cs プロジェクト: erik-kallen/NRefactory
		public void CaptureLocalVariable (ResolveContext ec, LocalVariable localVariable)
		{
			if (this is StateMachine) {
				if (ec.CurrentBlock.ParametersBlock != localVariable.Block.ParametersBlock)
					ec.CurrentBlock.Explicit.HasCapturedVariable = true;
			} else {
				ec.CurrentBlock.Explicit.HasCapturedVariable = true;
			}

			var hoisted = localVariable.HoistedVariant;
			if (hoisted != null && hoisted.Storey != this && hoisted.Storey is StateMachine) {
				//
				// Variable is already hoisted but we need it in storey which can be shared
				//
				hoisted.Storey.hoisted_locals.Remove (hoisted);
				hoisted.Storey.Members.Remove (hoisted.Field);
				hoisted = null;
			}

			if (hoisted == null) {
				hoisted = new HoistedLocalVariable (this, localVariable, GetVariableMangledName (localVariable));
				localVariable.HoistedVariant = hoisted;

				if (hoisted_locals == null)
					hoisted_locals = new List<HoistedVariable> ();

				hoisted_locals.Add (hoisted);
			}

			if (ec.CurrentBlock.Explicit != localVariable.Block.Explicit && !(hoisted.Storey is StateMachine))
				hoisted.Storey.AddReferenceFromChildrenBlock (ec.CurrentBlock.Explicit);
		}
コード例 #3
0
ファイル: anonymous.cs プロジェクト: rabink/mono
		protected virtual string GetVariableMangledName (LocalVariable local_info)
		{
			//
			// No need to mangle anonymous method hoisted variables cause they
			// are hoisted in their own scopes
			//
			return local_info.Name;
		}
コード例 #4
0
ファイル: cs-parser.cs プロジェクト: segaman/NRefactory
void case_873()
#line 5818 "cs-parser.jay"
{
		var lt = (LocatedToken) yyVals[0+yyTop];
		var li = new LocalVariable (current_block, lt.Value, lt.Location);
		current_block.AddLocalName (li);
		current_variable = new BlockVariable ((FullNamedExpression) yyVals[-1+yyTop], li);
	  }
コード例 #5
0
ファイル: cs-parser.cs プロジェクト: segaman/NRefactory
void case_885()
#line 5899 "cs-parser.jay"
{
		start_block (GetLocation (yyVals[-5+yyTop]));
		current_block.IsCompilerGenerated = true;
		
		var lt = (LocatedToken) yyVals[-3+yyTop];
		var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
		current_block.AddLocalName (li);
		yyVal = li;
	  }
コード例 #6
0
ファイル: anonymous.cs プロジェクト: nylen/SharpDevelop
		public void CaptureLocalVariable (ResolveContext ec, LocalVariable 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);
		}
コード例 #7
0
ファイル: cs-parser.cs プロジェクト: segaman/NRefactory
void case_813()
#line 5458 "cs-parser.jay"
{
		var lt = (LocatedToken) yyVals[0+yyTop];	  
		var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
		var d = new BlockVariableDeclarator (li, null);
		current_variable.AddDeclarator (d);
		current_block.AddLocalName (li);
	  	lbag.AddLocation (d, GetLocation (yyVals[-1+yyTop]));
	  }
コード例 #8
0
ファイル: statement.cs プロジェクト: alisci01/mono
			public VariableDeclaration (LocalVariable li, Location loc)
				: base (li)
			{
				this.loc = loc;
			}
コード例 #9
0
ファイル: statement.cs プロジェクト: alisci01/mono
			protected override Expression ResolveInitializer (BlockContext bc, LocalVariable li, Expression initializer)
			{
				Assign assign;
				if (li.Type == InternalType.Dynamic) {
					initializer = initializer.Resolve (bc);
					if (initializer == null)
						return null;

					initializer = Convert.ImplicitConversionRequired (bc, initializer, TypeManager.idisposable_type, loc);
					if (initializer == null)
						return null;

					var var = LocalVariable.CreateCompilerGenerated (TypeManager.idisposable_type, bc.CurrentBlock, loc);
					assign = new SimpleAssign (var.CreateReferenceExpression (bc, loc), initializer, loc);
					assign.ResolveStatement (bc);

					dispose_call = CreateDisposeCall (bc, var);
					dispose_call.Resolve (bc);

					return assign;
				}

				if (li == Variable) {
					CheckIDiposableConversion (bc, li, initializer);
					dispose_call = CreateDisposeCall (bc, li);
					dispose_call.Resolve (bc);
				}

				return base.ResolveInitializer (bc, li, initializer);
			}
コード例 #10
0
ファイル: statement.cs プロジェクト: alisci01/mono
			protected override Expression ResolveInitializer (BlockContext bc, LocalVariable li, Expression initializer)
			{
				if (!Variable.Type.IsPointer && li == Variable) {
					bc.Report.Error (209, TypeExpression.Location,
						"The type of locals declared in a fixed statement must be a pointer type");
					return null;
				}

				//
				// The rules for the possible declarators are pretty wise,
				// but the production on the grammar is more concise.
				//
				// So we have to enforce these rules here.
				//
				// We do not resolve before doing the case 1 test,
				// because the grammar is explicit in that the token &
				// is present, so we need to test for this particular case.
				//

				if (initializer is Cast) {
					bc.Report.Error (254, initializer.Location, "The right hand side of a fixed statement assignment may not be a cast expression");
					return null;
				}

				initializer = initializer.Resolve (bc);

				if (initializer == null)
					return null;

				//
				// Case 1: Array
				//
				if (initializer.Type.IsArray) {
					TypeSpec array_type = TypeManager.GetElementType (initializer.Type);

					//
					// Provided that array_type is unmanaged,
					//
					if (!TypeManager.VerifyUnmanaged (bc.Compiler, array_type, loc))
						return null;

					//
					// and T* is implicitly convertible to the
					// pointer type given in the fixed statement.
					//
					ArrayPtr array_ptr = new ArrayPtr (initializer, array_type, loc);

					Expression converted = Convert.ImplicitConversionRequired (
						bc, array_ptr, li.Type, loc);
					if (converted == null)
						return null;

					//
					// fixed (T* e_ptr = (e == null || e.Length == 0) ? null : converted [0])
					//
					converted = new Conditional (new BooleanExpression (new Binary (Binary.Operator.LogicalOr,
						new Binary (Binary.Operator.Equality, initializer, new NullLiteral (loc), loc),
						new Binary (Binary.Operator.Equality, new MemberAccess (initializer, "Length"), new IntConstant (0, loc), loc), loc)),
							new NullPointer (loc),
							converted, loc);

					converted = converted.Resolve (bc);

					return new ExpressionEmitter (converted, li);
				}

				//
				// Case 2: string
				//
				if (initializer.Type == TypeManager.string_type) {
					return new StringEmitter (initializer, li, loc).Resolve (bc);
				}

				// Case 3: fixed buffer
				if (initializer is FixedBufferPtr) {
					return new ExpressionEmitter (initializer, li);
				}

				//
				// Case 4: & object.
				//
				bool already_fixed = true;
				Unary u = initializer as Unary;
				if (u != null && u.Oper == Unary.Operator.AddressOf) {
					IVariableReference vr = u.Expr as IVariableReference;
					if (vr == null || !vr.IsFixed) {
						already_fixed = false;
					}
				}

				if (already_fixed) {
					bc.Report.Error (213, loc, "You cannot use the fixed statement to take the address of an already fixed expression");
				}

				initializer = Convert.ImplicitConversionRequired (bc, initializer, li.Type, loc);
				return new ExpressionEmitter (initializer, li);
			}
コード例 #11
0
ファイル: statement.cs プロジェクト: alisci01/mono
			public VariableDeclaration (FullNamedExpression type, LocalVariable li)
				: base (type, li)
			{
			}
コード例 #12
0
ファイル: statement.cs プロジェクト: alisci01/mono
			protected override Expression DoResolve (ResolveContext rc)
			{
				pinned_string = new LocalVariable (vi.Block, "$pinned",
					LocalVariable.Flags.FixedVariable | LocalVariable.Flags.CompilerGenerated | LocalVariable.Flags.Used,
					vi.Location);

				pinned_string.Type = TypeManager.string_type;

				if (TypeManager.int_get_offset_to_string_data == null) {
					TypeManager.int_get_offset_to_string_data = TypeManager.GetPredefinedProperty (
						TypeManager.runtime_helpers_type, "OffsetToStringData", pinned_string.Location, TypeManager.int32_type);
				}

				eclass = ExprClass.Variable;
				type = TypeManager.int32_type;
				return this;
			}
コード例 #13
0
ファイル: statement.cs プロジェクト: alisci01/mono
			public StringEmitter (Expression expr, LocalVariable li, Location loc)
				: base (expr, li)
			{
			}
コード例 #14
0
ファイル: statement.cs プロジェクト: alisci01/mono
			public ExpressionEmitter (Expression converted, LocalVariable li) :
				base (converted, li)
			{
			}
コード例 #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 ();
		}
コード例 #16
0
ファイル: statement.cs プロジェクト: alisci01/mono
			protected virtual void CheckIDiposableConversion (BlockContext bc, LocalVariable li, Expression initializer)
			{
				var type = li.Type;

				if (type != TypeManager.idisposable_type && !type.ImplementsInterface (TypeManager.idisposable_type, false)) {
					if (TypeManager.IsNullableType (type)) {
						// it's handled in CreateDisposeCall
						return;
					}

					bc.Report.SymbolRelatedToPreviousError (type);
					var loc = type_expr == null ? initializer.Location : type_expr.Location;
					bc.Report.Error (1674, loc, "`{0}': type used in a using statement must be implicitly convertible to `System.IDisposable'",
						type.GetSignatureForError ());

					return;
				}
			}
コード例 #17
0
ファイル: flowanalysis.cs プロジェクト: yayanyang/monodevelop
		public VariableInfo (LocalVariable local_info, int offset)
			: this (local_info.Name, local_info.Type, offset)
		{
			this.IsParameter = false;
		}
コード例 #18
0
ファイル: statement.cs プロジェクト: alisci01/mono
			protected virtual Statement CreateDisposeCall (BlockContext bc, LocalVariable lv)
			{
				var lvr = lv.CreateReferenceExpression (bc, lv.Location);
				var type = lv.Type;
				var loc = lv.Location;

				if (TypeManager.void_dispose_void == null) {
					TypeManager.void_dispose_void = TypeManager.GetPredefinedMethod (
						TypeManager.idisposable_type, "Dispose", loc, TypeSpec.EmptyTypes);
				}

				var dispose_mg = MethodGroupExpr.CreatePredefined (TypeManager.void_dispose_void, TypeManager.idisposable_type, loc);
				dispose_mg.InstanceExpression = TypeManager.IsNullableType (type) ?
					new Cast (new TypeExpression (TypeManager.idisposable_type, loc), lvr, loc).Resolve (bc) :
					lvr;

				Statement dispose = new StatementExpression (new Invocation (dispose_mg, null));

				// Add conditional call when disposing possible null variable
				if (!type.IsStruct || TypeManager.IsNullableType (type))
					dispose = new If (new Binary (Binary.Operator.Inequality, lvr, new NullLiteral (loc), loc), dispose, loc);

				return dispose;
			}
コード例 #19
0
ファイル: cs-parser.cs プロジェクト: segaman/NRefactory
void case_800()
#line 5388 "cs-parser.jay"
{
		var lt = (LocatedToken) yyVals[0+yyTop];
		var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
		current_block.AddLocalName (li);
		current_variable = new BlockConstant ((FullNamedExpression) yyVals[-1+yyTop], li);
	  }
コード例 #20
0
ファイル: statement.cs プロジェクト: alisci01/mono
				public Body (TypeSpec type, LocalVariable variable,
								   Expression current, Statement statement,
								   Location loc)
				{
					this.type = type;
					this.variable = new LocalVariableReference (variable, loc);
					this.current = current;
					this.statement = statement;
					this.loc = loc;
				}
コード例 #21
0
ファイル: cs-parser.cs プロジェクト: segaman/NRefactory
void case_821()
#line 5501 "cs-parser.jay"
{
		var lt = (LocatedToken) yyVals[-2+yyTop];	  
		var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
		var d = new BlockVariableDeclarator (li, (Expression) yyVals[0+yyTop]);
		current_variable.AddDeclarator (d);
		current_block.AddLocalName (li);
	  	lbag.AddLocation (d, GetLocation (yyVals[-3+yyTop]), GetLocation (yyVals[-1+yyTop]));
	  }
コード例 #22
0
ファイル: statement.cs プロジェクト: alisci01/mono
				public RuntimeDispose (LocalVariable lv, Location loc)
					: base (lv, loc)
				{
				}
コード例 #23
0
ファイル: cs-parser.cs プロジェクト: segaman/NRefactory
void case_884()
#line 5882 "cs-parser.jay"
{
		Error_SyntaxError (yyToken);
	
		start_block (GetLocation (yyVals[-3+yyTop]));
		current_block.IsCompilerGenerated = true;
		
		var lt = (LocatedToken) yyVals[-1+yyTop];
		var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
		current_block.AddLocalName (li);
		
		Foreach f = new Foreach ((Expression) yyVals[-2+yyTop], li, null, null, null, GetLocation (yyVals[-4+yyTop]));
		current_block.AddStatement (f);
		
		lbag.AddStatement (f, GetLocation (yyVals[-3+yyTop]));
		yyVal = end_block (GetLocation (yyVals[0+yyTop]));
	  }
コード例 #24
0
ファイル: statement.cs プロジェクト: alisci01/mono
				protected override void CheckIDiposableConversion (BlockContext bc, LocalVariable li, Expression initializer)
				{
					// Defered to runtime check
				}
コード例 #25
0
ファイル: cs-parser.cs プロジェクト: segaman/NRefactory
void case_933()
#line 6259 "cs-parser.jay"
{
	    start_block (GetLocation (yyVals[-2+yyTop]));
	    
		current_block.IsCompilerGenerated = true;
		var lt = (LocatedToken) yyVals[0+yyTop];
		var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
		current_block.AddLocalName (li);
		current_variable = new Using.VariableDeclaration ((FullNamedExpression) yyVals[-1+yyTop], li);
	  }
コード例 #26
0
ファイル: statement.cs プロジェクト: alisci01/mono
				protected override Statement CreateDisposeCall (BlockContext bc, LocalVariable lv)
				{
					if (TypeManager.void_dispose_void == null) {
						TypeManager.void_dispose_void = TypeManager.GetPredefinedMethod (
							TypeManager.idisposable_type, "Dispose", loc, TypeSpec.EmptyTypes);
					}

					//
					// Fabricates code like
					//
					// if ((temp = vr as IDisposable) != null) temp.Dispose ();
					//

					var dispose_variable = LocalVariable.CreateCompilerGenerated (TypeManager.idisposable_type, bc.CurrentBlock, loc);

					var idisaposable_test = new Binary (Binary.Operator.Inequality, new CompilerAssign (
						dispose_variable.CreateReferenceExpression (bc, loc),
						new As (lv.CreateReferenceExpression (bc, loc), new TypeExpression (dispose_variable.Type, loc), loc),
						loc), new NullLiteral (loc), loc);

					var dispose_mg = MethodGroupExpr.CreatePredefined (TypeManager.void_dispose_void, TypeManager.idisposable_type, loc);
					dispose_mg.InstanceExpression = dispose_variable.CreateReferenceExpression (bc, loc);

					Statement dispose = new StatementExpression (new Invocation (dispose_mg, null));
					return new If (idisaposable_test, dispose, loc);
				}
コード例 #27
0
ファイル: anonymous.cs プロジェクト: rabink/mono
		public void CaptureLocalVariable (ResolveContext ec, LocalVariable localVariable)
		{
			if (this is StateMachine) {
				if (ec.CurrentBlock.ParametersBlock != localVariable.Block.ParametersBlock)
					ec.CurrentBlock.Explicit.HasCapturedVariable = true;
			} else {
				ec.CurrentBlock.Explicit.HasCapturedVariable = true;
			}

			var hoisted = localVariable.HoistedVariant;
			if (hoisted != null && hoisted.Storey != this && hoisted.Storey is StateMachine) {
				// TODO: It's too late the field is defined in HoistedLocalVariable ctor
				hoisted.Storey.hoisted_locals.Remove (hoisted);
				hoisted = null;
			}

			if (hoisted == null) {
				hoisted = new HoistedLocalVariable (this, localVariable, GetVariableMangledName (localVariable));
				localVariable.HoistedVariant = hoisted;

				if (hoisted_locals == null)
					hoisted_locals = new List<HoistedVariable> ();

				hoisted_locals.Add (hoisted);
			}

			if (ec.CurrentBlock.Explicit != localVariable.Block.Explicit && !(hoisted.Storey is StateMachine))
				hoisted.Storey.AddReferenceFromChildrenBlock (ec.CurrentBlock.Explicit);
		}
コード例 #28
0
ファイル: statement.cs プロジェクト: alisci01/mono
		public Foreach (Expression type, LocalVariable var, Expression expr, Statement stmt, Location l)
		{
			this.type = type;
			this.variable = var;
			this.expr = expr;
			statement = stmt;
			loc = l;
		}
コード例 #29
0
ファイル: anonymous.cs プロジェクト: rabink/mono
		public HoistedLocalVariable (AnonymousMethodStorey storey, LocalVariable local, string name)
			: base (storey, name, local.Type)
		{
		}
コード例 #30
0
ファイル: statement.cs プロジェクト: alisci01/mono
		// <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 LocalVariable AddThisVariable (BlockContext bc, TypeContainer ds, Location l)
		{
			if (this_variable == null) {
				this_variable = new LocalVariable (this, "this", LocalVariable.Flags.IsThis | LocalVariable.Flags.Used, l);
				this_variable.Type = ds.CurrentType;
				this_variable.PrepareForFlowAnalysis (bc);
			}

			return this_variable;
		}