Пример #1
0
        public void UndefinedLocalVariable()
        {
            Context      parent  = new Context();
            BlockContext context = new BlockContext(parent);

            Assert.IsFalse(context.HasLocalValue("foo"));
        }
Пример #2
0
        public async Task IndexBlockAsync(BlockContext blockContext)
        {
            var blockContent      = blockContext.BlockContent;
            var addressHistory    = blockContent.AddressHistory;
            var blockModel        = blockContent.BlockModel;
            var blockNumber       = (ulong)blockModel.Number;
            var contractAddresses = blockContent.DeployedContracts;
            var internalMessages  = blockContent.InternalMessages;
            var transactions      = blockContent.Transactions;
            var transfers         = blockContent.Transfers;

            await _blockRepository.SaveAsync(blockModel);

            #region ProcessTransactions

            try
            {
                await _transactionRepository.SaveManyForBlockAsync(transactions, blockNumber);
            }
            catch (Exception e)
            {
                foreach (var transaction in transactions)
                {
                    var trHash = transaction.TransactionHash;

                    await _transactionRepository.DeleteByHash(trHash);

                    await _internalMessageRepository.DeleteAllForHash(trHash);

                    await _addressHistoryRepository.DeleteByHash(trHash);

                    await _erc20ContractRepository.DeleteByHash(trHash);

                    await _erc20TransferHistoryRepository.DeleteAllForHash(trHash);
                }

                await _transactionRepository.SaveManyForBlockAsync(transactions, blockNumber);
            }

            #endregion

            await _internalMessageRepository.SaveManyForBlockAsync(internalMessages, blockNumber);

            await _addressHistoryRepository.SaveManyForBlockAsync(addressHistory, blockNumber);

            await _erc20TransferHistoryRepository.SaveForBlockAsync(transfers, blockNumber);

            contractAddresses.ForEach(_erc20ContractIndexingQueue.Enqueue);

            // Mark block as indexed
            await _indexingRabbitNotifier.NotifyAsync(new Lykke.Service.EthereumSamurai.Models.Messages.RabbitIndexingMessage()
            {
                BlockNumber         = blockNumber,
                IndexingMessageType = Lykke.Service.EthereumSamurai.Models.Messages.IndexingMessageType.Block
            });

            await _blockIndexationHistoryRepository.MarkBlockAsIndexed(blockNumber, blockContext.JobVersion);

            await _blockSyncedInfoRepository.SaveAsync(new BlockSyncedInfoModel(blockContext.IndexerId, (ulong)blockModel.Number));
        }
Пример #3
0
 public override Expression VisitBlock(BlockContext context)
 {
     using (_parserContext.PushScope())
     {
         return(Visit(context.statement_list()));
     }
 }
Пример #4
0
 public static MemberExpression Create(AbstractExpression target, AbstractMember member)
 {
     return(BlockContext.GetBlockOrThrow().PushExpression(new MemberExpression {
         Type = target.Type,
         Target = target,
         Member = member
     }));
 }
Пример #5
0
        public void Show(BlockContext blockContext, BlockTemplate blockTemplate)
        {
            gameObject.SetActive(true);
            var tooltip = Systems.Blocks.valuesStore.GetTooltip(blockContext, blockTemplate);

            Systems.UI.tooltips.tooltipGenerator.CreateRootView(tooltip, itemsContainer);
            UpdatePosition(true);
        }
Пример #6
0
 public static MemberExpression Create(AbstractExpression target, IdentifierName memberName)
 {
     return(BlockContext.GetBlockOrThrow().PushExpression(new MemberExpression {
         Type = target.Type,
         Target = target,
         Member = null,
         MemberName = memberName
     }));
 }
Пример #7
0
        public void ParentLocalVariable()
        {
            Context parent = new Context();

            parent.SetLocalValue("foo", "bar");
            BlockContext context = new BlockContext(parent);

            Assert.IsTrue(context.HasLocalValue("foo"));
            Assert.AreEqual("bar", context.GetLocalValue("foo"));
        }
Пример #8
0
        public void Setup(Transform transform, float speed, float range, float damage, object damageSource, BlockContext damageMask)
        {
            this.transform.position = transform.position;
            this.damage             = damage;
            this.lifeTime           = range / speed;
            this.damageSource       = damageSource;
            this.damageMask         = damageMask;

            rb.velocity = transform.right * speed;
        }
Пример #9
0
        public override void VisitStartBlock(BlockType type)
        {
            base.VisitStartBlock(type);
            BlockContext next    = new BlockContext(type, Writer);
            BlockContext current = CurrentBlock;

            if (current != null)
            {
                SuspendBlock(current, next);
            }
            StartBlock(next);
            _blockStack.Push(next);
        }
Пример #10
0
		protected override Expression CreateExpressionTree (ResolveContext ec, TypeSpec delegate_type)
		{
			if (ec.IsInProbingMode)
				return this;

			BlockContext bc = new BlockContext (ec.MemberContext, ec.ConstructorBlock, ec.BuiltinTypes.Void) {
				CurrentAnonymousMethod = ec.CurrentAnonymousMethod
			};

			Expression args = Parameters.CreateExpressionTree (bc, loc);
			Expression expr = Block.CreateExpressionTree (ec);
			if (expr == null)
				return null;

			Arguments arguments = new Arguments (2);
			arguments.Add (new Argument (expr));
			arguments.Add (new Argument (args));
			return CreateExpressionFactoryCall (ec, "Lambda",
				new TypeArguments (new TypeExpression (delegate_type, loc)),
				arguments);
		}
Пример #11
0
		public override bool Resolve (BlockContext ec)
		{
			return true;
		}
Пример #12
0
		//
		// Emits the code
		// 
		public void Emit (TypeDefinition parent)
		{
			var mc = (IMemberContext) method;

			method.ParameterInfo.ApplyAttributes (mc, MethodBuilder);

			ToplevelBlock block = method.Block;
			if (block != null) {
				BlockContext bc = new BlockContext (mc, block, method.ReturnType);
				if (block.Resolve (null, bc, method)) {
					debug_builder = member.Parent.CreateMethodSymbolEntry ();
					EmitContext ec = method.CreateEmitContext (MethodBuilder.GetILGenerator (), debug_builder);

					block.Emit (ec);
				}
			}
		}
Пример #13
0
		public string [] GetCompletions (string input, out string prefix)
		{
			prefix = "";
			if (input == null || input.Length == 0)
				return null;
			
			lock (evaluator_lock){
				if (!inited)
					Init ();
				
				bool partial_input;
				CSharpParser parser = ParseString (ParseMode.GetCompletions, input, out partial_input);
				if (parser == null){
					return null;
				}
				
				Class parser_result = parser.InteractiveResult;

#if NET_4_0
				var access = AssemblyBuilderAccess.RunAndCollect;
#else
				var access = AssemblyBuilderAccess.Run;
#endif
				var a = new AssemblyDefinitionDynamic (module, "completions");
				a.Create (AppDomain.CurrentDomain, access);
				module.SetDeclaringAssembly (a);

				// Need to setup MemberCache
				parser_result.CreateContainer ();

				var method = parser_result.Members[0] as Method;
				BlockContext bc = new BlockContext (method, method.Block, ctx.BuiltinTypes.Void);

				try {
					method.Block.Resolve (null, bc, method);
				} catch (CompletionResult cr) {
					prefix = cr.BaseText;
					return cr.Result;
				} 
			}
			return null;
		}
Пример #14
0
		//
		// Emits the code
		//
		public override void Emit ()
		{
			if (Parent.PartialContainer.IsComImport) {
				if (!IsDefault ()) {
					Report.Error (669, Location, "`{0}': A class with the ComImport attribute cannot have a user-defined constructor",
						Parent.GetSignatureForError ());
				}

				// Set as internal implementation and reset block data
				// to ensure no IL is generated
				ConstructorBuilder.SetImplementationFlags (MethodImplAttributes.InternalCall);
				block = null;
			}

			if ((ModFlags & Modifiers.DEBUGGER_HIDDEN) != 0)
				Module.PredefinedAttributes.DebuggerHidden.EmitAttribute (ConstructorBuilder);

			if (OptAttributes != null)
				OptAttributes.Emit ();

			base.Emit ();
			parameters.ApplyAttributes (this, ConstructorBuilder);


			BlockContext bc = new BlockContext (this, block, Compiler.BuiltinTypes.Void);
			bc.Set (ResolveContext.Options.ConstructorScope);

			if (block != null) {
				//
				// If we use a "this (...)" constructor initializer, then
				// do not emit field initializers, they are initialized in the other constructor
				//
				if (!(Initializer is ConstructorThisInitializer))
					Parent.PartialContainer.ResolveFieldInitializers (bc);

				if (!IsStatic) {
					if (Initializer == null) {
						if (Parent.PartialContainer.Kind == MemberKind.Struct) {
							//
							// If this is a non-static `struct' constructor and doesn't have any
							// initializer, it must initialize all of the struct's fields.
							//
							block.AddThisVariable (bc);
						} else if (Parent.PartialContainer.Kind == MemberKind.Class) {
							Initializer = new GeneratedBaseInitializer (Location);
						}
					}

					if (Initializer != null) {
						//
						// mdb format does not support reqions. Try to workaround this by emitting the
						// sequence point at initializer. Any breakpoint at constructor header should
						// be adjusted to this sequence point as it's the next one which follows.
						//
						block.AddScopeStatement (new StatementExpression (Initializer));
					}
				}

				if (block.Resolve (null, bc, this)) {
					debug_builder = Parent.CreateMethodSymbolEntry ();
					EmitContext ec = new EmitContext (this, ConstructorBuilder.GetILGenerator (), bc.ReturnType, debug_builder);
					ec.With (EmitContext.Options.ConstructorScope, true);

					block.Emit (ec);
				}
			}

			if (declarative_security != null) {
				foreach (var de in declarative_security) {
#if STATIC
					ConstructorBuilder.__AddDeclarativeSecurity (de);
#else
					ConstructorBuilder.AddDeclarativeSecurity (de.Key, de.Value);
#endif
				}
			}

			block = null;
		}
Пример #15
0
		public override bool ResolveUnreachable (BlockContext ec, bool warn)
		{
			return true;
		}
Пример #16
0
		public Expression CreateExpressionTree (BlockContext ec, Location loc)
		{
			var initializers = new ArrayInitializer (Count, loc);
			foreach (Parameter p in FixedParameters) {
				//
				// Each parameter expression is stored to local variable
				// to save some memory when referenced later.
				//
				StatementExpression se = new StatementExpression (p.CreateExpressionTreeVariable (ec), Location.Null);
				if (se.Resolve (ec)) {
					ec.CurrentBlock.AddScopeStatement (new TemporaryVariableReference.Declarator (p.ExpressionTreeVariableReference ()));
					ec.CurrentBlock.AddScopeStatement (se);
				}
				
				initializers.Add (p.ExpressionTreeVariableReference ());
			}

			return new ArrayCreation (
				Parameter.ResolveParameterExpressionType (ec, loc),
				initializers, loc);
		}
		public bool IsFullyInitialized (BlockContext bc, Location loc)
		{
			return TypeInfo.IsFullyInitialized (bc, this, loc);
		}
Пример #18
0
	public BlockContext block() {
		BlockContext _localctx = new BlockContext(Context, State);
		EnterRule(_localctx, 26, RULE_block);
		int _la;
		try {
			int _alt;
			EnterOuterAlt(_localctx, 1);
			{
			State = 468; blockStmt();
			State = 475;
			ErrorHandler.Sync(this);
			_alt = Interpreter.AdaptivePredict(TokenStream,33,Context);
			while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber ) {
				if ( _alt==1 ) {
					{
					{
					State = 470;
					_la = TokenStream.La(1);
					if (_la==WS) {
						{
						State = 469; Match(WS);
						}
					}

					State = 472; Match(T__1);
					}
					} 
				}
				State = 477;
				ErrorHandler.Sync(this);
				_alt = Interpreter.AdaptivePredict(TokenStream,33,Context);
			}
			State = 490;
			ErrorHandler.Sync(this);
			_alt = Interpreter.AdaptivePredict(TokenStream,36,Context);
			while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber ) {
				if ( _alt==1 ) {
					{
					{
					State = 481;
					ErrorHandler.Sync(this);
					_la = TokenStream.La(1);
					while (_la==NEWLINE) {
						{
						{
						State = 478; Match(NEWLINE);
						}
						}
						State = 483;
						ErrorHandler.Sync(this);
						_la = TokenStream.La(1);
					}
					State = 485;
					_la = TokenStream.La(1);
					if (_la==WS) {
						{
						State = 484; Match(WS);
						}
					}

					State = 487; blockStmt();
					}
					} 
				}
				State = 492;
				ErrorHandler.Sync(this);
				_alt = Interpreter.AdaptivePredict(TokenStream,36,Context);
			}
			State = 494;
			switch ( Interpreter.AdaptivePredict(TokenStream,37,Context) ) {
			case 1:
				{
				State = 493; Match(WS);
				}
				break;
			}
			State = 499;
			ErrorHandler.Sync(this);
			_alt = Interpreter.AdaptivePredict(TokenStream,38,Context);
			while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber ) {
				if ( _alt==1 ) {
					{
					{
					State = 496; Match(NEWLINE);
					}
					} 
				}
				State = 501;
				ErrorHandler.Sync(this);
				_alt = Interpreter.AdaptivePredict(TokenStream,38,Context);
			}
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			ErrorHandler.ReportError(this, re);
			ErrorHandler.Recover(this, re);
		}
		finally {
			ExitRule();
		}
		return _localctx;
	}
Пример #19
0
		public override bool Resolve (BlockContext bc)
		{
			if (!base.Resolve (bc))
				return false;

			expr = expr.Resolve (bc);

			return expr != null;
		}
Пример #20
0
		public void ResolveFieldInitializers (BlockContext ec)
		{
			Debug.Assert (!IsPartialPart);

			if (ec.IsStatic) {
				if (initialized_static_fields == null)
					return;

				bool has_complex_initializer = !ec.Module.Compiler.Settings.Optimize;
				int i;
				ExpressionStatement [] init = new ExpressionStatement [initialized_static_fields.Count];
				for (i = 0; i < initialized_static_fields.Count; ++i) {
					FieldInitializer fi = initialized_static_fields [i];
					ExpressionStatement s = fi.ResolveStatement (ec);
					if (s == null) {
						s = EmptyExpressionStatement.Instance;
					} else if (!fi.IsSideEffectFree) {
						has_complex_initializer |= true;
					}

					init [i] = s;
				}

				for (i = 0; i < initialized_static_fields.Count; ++i) {
					FieldInitializer fi = initialized_static_fields [i];
					//
					// Need special check to not optimize code like this
					// static int a = b = 5;
					// static int b = 0;
					//
					if (!has_complex_initializer && fi.IsDefaultInitializer)
						continue;

					ec.CurrentBlock.AddScopeStatement (new StatementExpression (init [i]));
				}

				return;
			}

			if (initialized_fields == null)
				return;

			for (int i = 0; i < initialized_fields.Count; ++i) {
				FieldInitializer fi = initialized_fields [i];
				ExpressionStatement s = fi.ResolveStatement (ec);
				if (s == null)
					continue;

				//
				// Field is re-initialized to its default value => removed
				//
				if (fi.IsDefaultInitializer && ec.Module.Compiler.Settings.Optimize)
					continue;

				ec.CurrentBlock.AddScopeStatement (new StatementExpression (s));
			}
		}
		// <summary>
		//   A struct's constructor must always assign all fields.
		//   This method checks whether it actually does so.
		// </summary>
		public bool IsFullyInitialized (BlockContext ec, VariableInfo vi, Location loc)
		{
			if (struct_info == null)
				return true;

			bool ok = true;
			FlowBranching branching = ec.CurrentBranching;
			for (int i = 0; i < struct_info.Count; i++) {
				var field = struct_info.Fields [i];

				if (!branching.IsStructFieldAssigned (vi, field.Name)) {
					if (field.MemberDefinition is Property.BackingField) {
						ec.Report.Error (843, loc,
							"An automatically implemented property `{0}' must be fully assigned before control leaves the constructor. Consider calling the default struct contructor from a constructor initializer",
							field.GetSignatureForError ());
					} else {
						ec.Report.Error (171, loc,
							"Field `{0}' must be fully assigned before control leaves the constructor",
							field.GetSignatureForError ());
					}
					ok = false;
				}
			}

			return ok;
		}
Пример #22
0
		public override Expression CreateExpressionTree (ResolveContext ec)
		{
			BlockContext bc = new BlockContext (ec.MemberContext, Block, ReturnType);
			Expression args = parameters.CreateExpressionTree (bc, loc);
			Expression expr = Block.CreateExpressionTree (ec);
			if (expr == null)
				return null;

			Arguments arguments = new Arguments (2);
			arguments.Add (new Argument (expr));
			arguments.Add (new Argument (args));
			return CreateExpressionFactoryCall (ec, "Lambda",
				new TypeArguments (new TypeExpression (type, loc)),
				arguments);
		}
Пример #23
0
		protected void EmitCall (EmitContext ec, Expression binder, Arguments arguments, bool isStatement)
		{
			//
			// This method generates all internal infrastructure for a dynamic call. The
			// reason why it's quite complicated is the mixture of dynamic and anonymous
			// methods. Dynamic itself requires a temporary class (ContainerX) and anonymous
			// methods can generate temporary storey as well (AnonStorey). Handling MVAR
			// type parameters rewrite is non-trivial in such case as there are various
			// combinations possible therefore the mutator is not straightforward. Secondly
			// we need to keep both MVAR(possibly VAR for anon storey) and type VAR to emit
			// correct Site field type and its access from EmitContext.
			//

			int dyn_args_count = arguments == null ? 0 : arguments.Count;
			int default_args = isStatement ? 1 : 2;
			var module = ec.Module;

			bool has_ref_out_argument = false;
			var targs = new TypeExpression[dyn_args_count + default_args];
			targs[0] = new TypeExpression (module.PredefinedTypes.CallSite.TypeSpec, loc);

			TypeExpression[] targs_for_instance = null;
			TypeParameterMutator mutator;

			var site_container = ec.CreateDynamicSite ();

			if (context_mvars != null) {
				TypeParameters tparam;
				TypeContainer sc = site_container;
				do {
					tparam = sc.CurrentTypeParameters;
					sc = sc.Parent;
				} while (tparam == null);

				mutator = new TypeParameterMutator (context_mvars, tparam);

				if (!ec.IsAnonymousStoreyMutateRequired) {
					targs_for_instance = new TypeExpression[targs.Length];
					targs_for_instance[0] = targs[0];
				}
			} else {
				mutator = null;
			}

			for (int i = 0; i < dyn_args_count; ++i) {
				Argument a = arguments[i];
				if (a.ArgType == Argument.AType.Out || a.ArgType == Argument.AType.Ref)
					has_ref_out_argument = true;

				var t = a.Type;

				// Convert any internal type like dynamic or null to object
				if (t.Kind == MemberKind.InternalCompilerType)
					t = ec.BuiltinTypes.Object;

				if (targs_for_instance != null)
					targs_for_instance[i + 1] = new TypeExpression (t, loc);

				if (mutator != null)
					t = t.Mutate (mutator);

				targs[i + 1] = new TypeExpression (t, loc);
			}

			TypeExpr del_type = null;
			TypeExpr del_type_instance_access = null;
			if (!has_ref_out_argument) {
				string d_name = isStatement ? "Action" : "Func";

				TypeExpr te = null;
				Namespace type_ns = module.GlobalRootNamespace.GetNamespace ("System", true);
				if (type_ns != null) {
					te = type_ns.LookupType (module, d_name, dyn_args_count + default_args, LookupMode.Normal, loc);
				}

				if (te != null) {
					if (!isStatement) {
						var t = type;
						if (t.Kind == MemberKind.InternalCompilerType)
							t = ec.BuiltinTypes.Object;

						if (targs_for_instance != null)
							targs_for_instance[targs_for_instance.Length - 1] = new TypeExpression (t, loc);

						if (mutator != null)
							t = t.Mutate (mutator);

						targs[targs.Length - 1] = new TypeExpression (t, loc);
					}

					del_type = new GenericTypeExpr (te.Type, new TypeArguments (targs), loc);
					if (targs_for_instance != null)
						del_type_instance_access = new GenericTypeExpr (te.Type, new TypeArguments (targs_for_instance), loc);
					else
						del_type_instance_access = del_type;
				}
			}

			//
			// Create custom delegate when no appropriate predefined delegate has been found
			//
			Delegate d;
			if (del_type == null) {
				TypeSpec rt = isStatement ? ec.BuiltinTypes.Void : type;
				Parameter[] p = new Parameter[dyn_args_count + 1];
				p[0] = new Parameter (targs[0], "p0", Parameter.Modifier.NONE, null, loc);

				var site = ec.CreateDynamicSite ();
				int index = site.Containers == null ? 0 : site.Containers.Count;

				if (mutator != null)
					rt = mutator.Mutate (rt);

				for (int i = 1; i < dyn_args_count + 1; ++i) {
					p[i] = new Parameter (targs[i], "p" + i.ToString ("X"), arguments[i - 1].Modifier, null, loc);
				}

				d = new Delegate (site, new TypeExpression (rt, loc),
					Modifiers.INTERNAL | Modifiers.COMPILER_GENERATED,
					new MemberName ("Container" + index.ToString ("X")),
					new ParametersCompiled (p), null);

				d.CreateContainer ();
				d.DefineContainer ();
				d.Define ();

				site.AddTypeContainer (d);
				del_type = new TypeExpression (d.CurrentType, loc);
				if (targs_for_instance != null) {
					del_type_instance_access = null;
				} else {
					del_type_instance_access = del_type;
				}
			} else {
				d = null;
			}

			var site_type_decl = new GenericTypeExpr (module.PredefinedTypes.CallSiteGeneric.TypeSpec, new TypeArguments (del_type), loc);
			var field = site_container.CreateCallSiteField (site_type_decl, loc);
			if (field == null)
				return;

			if (del_type_instance_access == null) {
				var dt = d.CurrentType.DeclaringType.MakeGenericType (module, context_mvars.Types);
				del_type_instance_access = new TypeExpression (MemberCache.GetMember (dt, d.CurrentType), loc);
			}

			var instanceAccessExprType = new GenericTypeExpr (module.PredefinedTypes.CallSiteGeneric.TypeSpec,
				new TypeArguments (del_type_instance_access), loc);

			if (instanceAccessExprType.ResolveAsType (ec.MemberContext) == null)
				return;

			bool inflate_using_mvar = context_mvars != null && ec.IsAnonymousStoreyMutateRequired;

			TypeSpec gt;
			if (inflate_using_mvar || context_mvars == null) {
				gt = site_container.CurrentType;
			} else {
				gt = site_container.CurrentType.MakeGenericType (module, context_mvars.Types);
			}

			// When site container already exists the inflated version has to be
			// updated manually to contain newly created field
			if (gt is InflatedTypeSpec && site_container.AnonymousMethodsCounter > 1) {
				var tparams = gt.MemberDefinition.TypeParametersCount > 0 ? gt.MemberDefinition.TypeParameters : TypeParameterSpec.EmptyTypes;
				var inflator = new TypeParameterInflator (module, gt, tparams, gt.TypeArguments);
				gt.MemberCache.AddMember (field.InflateMember (inflator));
			}

			FieldExpr site_field_expr = new FieldExpr (MemberCache.GetMember (gt, field), loc);

			BlockContext bc = new BlockContext (ec.MemberContext, null, ec.BuiltinTypes.Void);

			Arguments args = new Arguments (1);
			args.Add (new Argument (binder));
			StatementExpression s = new StatementExpression (new SimpleAssign (site_field_expr, new Invocation (new MemberAccess (instanceAccessExprType, "Create"), args)));

			using (ec.With (BuilderContext.Options.OmitDebugInfo, true)) {
				if (s.Resolve (bc)) {
					Statement init = new If (new Binary (Binary.Operator.Equality, site_field_expr, new NullLiteral (loc)), s, loc);
					init.Emit (ec);
				}

				args = new Arguments (1 + dyn_args_count);
				args.Add (new Argument (site_field_expr));
				if (arguments != null) {
					int arg_pos = 1;
					foreach (Argument a in arguments) {
						if (a is NamedArgument) {
							// Name is not valid in this context
							args.Add (new Argument (a.Expr, a.ArgType));
						} else {
							args.Add (a);
						}

						if (inflate_using_mvar && a.Type != targs[arg_pos].Type)
							a.Expr.Type = targs[arg_pos].Type;

						++arg_pos;
					}
				}

				Expression target = new DelegateInvocation (new MemberAccess (site_field_expr, "Target", loc).Resolve (bc), args, loc).Resolve (bc);
				if (target != null)
					target.Emit (ec);
			}
		}
Пример #24
0
		protected override bool DoResolve (BlockContext ec)
		{
			//
			// When delegate returns void, only expression statements can be used
			//
			if (ec.ReturnType.Kind == MemberKind.Void) {
				Expr = Expr.Resolve (ec);
				if (Expr == null)
					return false;

				statement = Expr as ExpressionStatement;
				if (statement == null)
					Expr.Error_InvalidExpressionStatement (ec);

				return true;
			}

			return base.DoResolve (ec);
		}
Пример #25
0
		public ExpressionStatement CreateExpressionTreeVariable (BlockContext ec)
		{
			if ((modFlags & Modifier.RefOutMask) != 0)
				ec.Report.Error (1951, Location, "An expression tree parameter cannot use `ref' or `out' modifier");

			expr_tree_variable = TemporaryVariableReference.Create (ResolveParameterExpressionType (ec, Location).Type, ec.CurrentBlock.ParametersBlock, Location);
			expr_tree_variable = (TemporaryVariableReference) expr_tree_variable.Resolve (ec);

			Arguments arguments = new Arguments (2);
			arguments.Add (new Argument (new TypeOf (parameter_type, Location)));
			arguments.Add (new Argument (new StringConstant (ec.BuiltinTypes, Name, Location)));
			return new SimpleAssign (ExpressionTreeVariableReference (),
				Expression.CreateExpressionFactoryCall (ec, "Parameter", null, arguments, Location));
		}
Пример #26
0
		public AnonymousExpression Compatible (ResolveContext ec, AnonymousExpression ae)
		{
			if (block.Resolved)
				return this;

			// TODO: Implement clone
			BlockContext aec = new BlockContext (ec, block, ReturnType);
			aec.CurrentAnonymousMethod = ae;

			var am = this as AnonymousMethodBody;

			if (ec.HasSet (ResolveContext.Options.InferReturnType) && am != null) {
				am.ReturnTypeInference = new TypeInferenceContext ();
			}

			var bc = ec as BlockContext;
			if (bc != null)
				aec.FlowOffset = bc.FlowOffset;

			var errors = ec.Report.Errors;

			bool res = Block.Resolve (ec.CurrentBranching, aec, null);

			if (am != null && am.ReturnTypeInference != null) {
				am.ReturnTypeInference.FixAllTypes (ec);
				ReturnType = am.ReturnTypeInference.InferredTypeArguments [0];
				am.ReturnTypeInference = null;

				//
				// If e is synchronous the inferred return type is T
				// If e is asynchronous the inferred return type is Task<T>
				//
				if (block.IsAsync && ReturnType != null) {
					ReturnType = ec.Module.PredefinedTypes.TaskGeneric.TypeSpec.MakeGenericType (ec, new [] { ReturnType });
				}
			}

			if (res && errors != ec.Report.Errors)
				return null;

			return res ? this : null;
		}