Exemplo n.º 1
0
        public Method CreateFinallyHost(TryFinallyBlock block)
        {
            var method = new Method(storey, new TypeExpression(storey.Compiler.BuiltinTypes.Void, loc),
                                    Modifiers.COMPILER_GENERATED, new MemberName(CompilerGeneratedContainer.MakeName(null, null, "Finally", finally_hosts_counter++), loc),
                                    ParametersCompiled.EmptyReadOnlyParameters, null);

            method.Block = new ToplevelBlock(method.Compiler, method.ParameterInfo, loc);
            method.Block.IsCompilerGenerated = true;
            method.Block.AddStatement(new TryFinallyBlockProxyStatement(this, block));

            storey.AddMember(method);
            return(method);
        }
Exemplo n.º 2
0
        protected override Expression DoResolve(ResolveContext ec)
        {
            var expr = base.DoResolve(ec);

            if (expr == null)
            {
                return(null);
            }

            if (ec.IsInProbingMode)
            {
                return(expr);
            }

            //
            // Cache any static delegate creation
            //
            if (method_group.InstanceExpression != null)
            {
                return(expr);
            }

            //
            // Cannot easily cache types with MVAR
            //
            if (ContainsMethodTypeParameter(type))
            {
                return(expr);
            }

            if (ContainsMethodTypeParameter(method_group.BestCandidate.DeclaringType))
            {
                return(expr);
            }

            //
            // Create type level cache for a delegate instance
            //
            var parent = ec.CurrentMemberDefinition.Parent.PartialContainer;
            int id     = parent.MethodGroupsCounter++;

            mg_cache = new Field(parent, new TypeExpression(type, loc),
                                 Modifiers.STATIC | Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED,
                                 new MemberName(CompilerGeneratedContainer.MakeName(null, "f", "mg$cache", id), loc), null);
            mg_cache.Define();
            parent.AddField(mg_cache);

            return(expr);
        }
        public Method CreateFinallyHost(TryFinallyBlock block)
        {
            var method = new Method(storey, new TypeExpression(storey.Compiler.BuiltinTypes.Void, loc),
                                    Modifiers.COMPILER_GENERATED, new MemberName(CompilerGeneratedContainer.MakeName(null, null, "Finally", finally_hosts_counter++), loc),
                                    ParametersCompiled.EmptyReadOnlyParameters, null);

            method.Block = new ToplevelBlock(method.Compiler, method.ParameterInfo, loc);
            method.Block.IsCompilerGenerated = true;
            method.Block.AddStatement(new TryFinallyBlockProxyStatement(this, block));

            // Cannot it add to storey because it'd be emitted before nested
            // anonoymous methods which could capture shared variable

            return(method);
        }