Nested class representing a static local variable. Template: class static'foo'x : IStaticInit { public T value; public void Init(Context ctx){ ... } }
Inheritance: NamedTypeSymbol
コード例 #1
0
ファイル: BoundStatement.cs プロジェクト: iolevel/peachpie
        void EmitInit(Emit.PEModuleBuilder module, DiagnosticBag diagnostic, PhpCompilation compilation, SynthesizedStaticLocHolder holder, BoundExpression initializer)
        {
            var loctype = holder.ValueField.Type;

            bool requiresContext = initializer != null && initializer.RequiresContext;

            if (requiresContext)
            {
                // emit Init only if it needs Context

                holder.EmitInit(module, (il) =>
                {
                    var cg = new CodeGenerator(il, module, diagnostic, OptimizationLevel.Release, false,
                        holder.ContainingType, new ArgPlace(compilation.CoreTypes.Context, 1), new ArgPlace(holder, 0));

                    var valuePlace = new FieldPlace(cg.ThisPlaceOpt, holder.ValueField);
                    
                    // Template: this.value = <initilizer>;

                    valuePlace.EmitStorePrepare(il);
                    cg.EmitConvert(initializer, valuePlace.TypeOpt);                    
                    valuePlace.EmitStore(il);

                    //
                    il.EmitRet(true);
                });
            }

            // default .ctor
            holder.EmitCtor(module, (il) =>
            {
                if (!requiresContext)
                {
                    // emit default value only if it won't be initialized by Init above

                    var cg = new CodeGenerator(il, module, diagnostic, OptimizationLevel.Release, false,
                        holder.ContainingType, null, new ArgPlace(holder, 0));

                    var valuePlace = new FieldPlace(cg.ThisPlaceOpt, holder.ValueField);

                    // Template: this.value = default(T);

                    valuePlace.EmitStorePrepare(il);
                    if (initializer != null)
                    {
                        cg.EmitConvert(initializer, valuePlace.TypeOpt);
                    }
                    else
                    {
                        cg.EmitLoadDefault(valuePlace.TypeOpt, 0);
                    }
                    valuePlace.EmitStore(il);
                }

                //
                il.EmitRet(true);
            });
        }
コード例 #2
0
        internal SynthesizedStaticLocHolder DeclareStaticLocalHolder(string locName, TypeSymbol locType)
        {
            var holder = new SynthesizedStaticLocHolder(_cg.Routine, locName, locType);

            _cg.Module.SynthesizedManager.AddNestedType(_container, holder);

            return holder;
        }
コード例 #3
0
ファイル: BoundVariable.cs プロジェクト: iolevel/peachpie
        internal override void EmitInit(CodeGenerator cg)
        {
            // variable holder class
            _holder = cg.Factory.DeclareStaticLocalHolder(this.Name, (TypeSymbol)this.Variable.Type);

            // local with its instance
            var symbol = new SynthesizedLocalSymbol(cg.Routine, this.Name, _holder);
            var loc = cg.Builder.LocalSlotManager.DeclareLocal(_holder, symbol, symbol.Name, SynthesizedLocalKind.OptimizerTemp, LocalDebugId.None, 0, LocalSlotConstraints.None, false, default(ImmutableArray<TypedConstant>), false);

            _holderPlace = new LocalPlace(loc);

            // place = holder.value
            _place = new FieldPlace(_holderPlace, _holder.ValueField);

            if (cg.HasUnoptimizedLocals)
            {
                // TODO reference to <locals>
            }
        }