コード例 #1
0
ファイル: InstanceImpl.cs プロジェクト: Waizik/BTDB
        public IILLocal GenMain(IGenerationContext context)
        {
            if (_instance == null)
            {
                context.IL.Ldnull();
                return(null);
            }
            var buildCRegLocals = context.GetSpecific <SingletonImpl.BuildCRegLocals>();
            var localInstance   = buildCRegLocals.Get(this);

            if (localInstance != null)
            {
                return(localInstance);
            }
            var localInstances = context.GetSpecific <InstancesLocalGenCtxHelper>().MainLocal;

            localInstance = context.IL.DeclareLocal(_instance.GetType(), "instance");
            context.IL
            .Ldloc(localInstances)
            .LdcI4(_instanceIndex)
            .LdelemRef()
            .UnboxAny(_instance.GetType())
            .Stloc(localInstance);
            buildCRegLocals.Add(this, localInstance);
            return(localInstance);
        }
コード例 #2
0
ファイル: SingletonImpl.cs プロジェクト: Xamarui/BTDB
 public void GenInitialization(IGenerationContext context)
 {
     var backupCtx = context.BuildContext;
     context.BuildContext = _buildCtx;
     _wrapping.GenInitialization(context);
     context.GetSpecific<SingletonsLocal>().Prepare();
     context.BuildContext = backupCtx;
 }
コード例 #3
0
ファイル: InstanceImpl.cs プロジェクト: Waizik/BTDB
 public void GenInitialization(IGenerationContext context)
 {
     if (_instance == null)
     {
         return;
     }
     context.GetSpecific <InstancesLocalGenCtxHelper>().Prepare();
 }
コード例 #4
0
ファイル: SingletonImpl.cs プロジェクト: miroslavpokorny/BTDB
        public void GenInitialization(IGenerationContext context)
        {
            var backupCtx = context.BuildContext;

            context.BuildContext = _buildCtx !;
            _wrapping.GenInitialization(context);
            context.GetSpecific <SingletonsLocal>().Prepare();
            context.BuildContext = backupCtx;
        }
コード例 #5
0
ファイル: FactoryImpl.cs プロジェクト: Xamarui/BTDB
 public IILLocal GenMain(IGenerationContext context)
 {
     var localInstances = context.GetSpecific<InstancesLocalGenCtxHelper>().MainLocal;
     var localInstance = context.IL.DeclareLocal(_type, "instance");
     context.IL
         .Ldloc(localInstances)
         .LdcI4(_instanceIndex)
         .LdelemRef()
         .Castclass(typeof(Func<object>))
         .Call(() => default(Func<object>).Invoke())
         .Castclass(_type)
         .Stloc(localInstance);
     return localInstance;
 }
コード例 #6
0
ファイル: FactoryImpl.cs プロジェクト: keeema/bbcore
        public IILLocal GenMain(IGenerationContext context)
        {
            var localInstances = context.GetSpecific <InstancesLocalGenCtxHelper>().MainLocal;
            var localInstance  = context.IL.DeclareLocal(_type, "instance");

            context.IL
            .Ldloc(localInstances)
            .LdcI4(_instanceIndex)
            .LdelemRef()
            .Castclass(typeof(Func <object>))
            .Call(() => default(Func <object>).Invoke())
            .Castclass(_type)
            .Stloc(localInstance);
            return(localInstance);
        }
コード例 #7
0
ファイル: InstanceImpl.cs プロジェクト: mano-cz/BTDB
 public IILLocal GenMain(IGenerationContext context)
 {
     if (_instance == null)
     {
         context.IL.Ldnull();
         return null;
     }
     var buildCRegLocals = context.GetSpecific<SingletonImpl.BuildCRegLocals>();
     var localInstance = buildCRegLocals.Get(this);
     if (localInstance != null)
     {
         return localInstance;
     }
     var localInstances = context.GetSpecific<InstancesLocalGenCtxHelper>().MainLocal;
     localInstance = context.IL.DeclareLocal(_instance.GetType(), "instance");
     context.IL
         .Ldloc(localInstances)
         .LdcI4(_instanceIndex)
         .LdelemRef()
         .UnboxAny(_instance.GetType())
         .Stloc(localInstance);
     buildCRegLocals.Add(this, localInstance);
     return localInstance;
 }
コード例 #8
0
ファイル: SingletonImpl.cs プロジェクト: miroslavpokorny/BTDB
        public bool IsCorruptingILStack(IGenerationContext context)
        {
            var buildCRegLocals = context.GetSpecific <BuildCRegLocals>();
            var localSingleton  = buildCRegLocals.Get(this);

            if (localSingleton != null)
            {
                return(false);
            }
            var obj = context.Container.Singletons[_singletonIndex];

            if (obj != null)
            {
                return(false);
            }
            return(true);
        }
コード例 #9
0
ファイル: FactoryImpl.cs プロジェクト: keeema/bbcore
 public void GenInitialization(IGenerationContext context)
 {
     context.GetSpecific <InstancesLocalGenCtxHelper>().Prepare();
 }
コード例 #10
0
ファイル: SingletonImpl.cs プロジェクト: miroslavpokorny/BTDB
        public IILLocal GenMain(IGenerationContext context)
        {
            var backupCtx = context.BuildContext;

            context.BuildContext = _buildCtx !;
            var il = context.IL;
            var buildCRegLocals = context.GetSpecific <BuildCRegLocals>();
            var localSingleton  = buildCRegLocals.Get(this);

            if (localSingleton != null)
            {
                return(localSingleton);
            }
            var localSingletons        = context.GetSpecific <SingletonsLocal>().MainLocal;
            var safeImplementationType = _implementationType.IsPublic ? _implementationType : typeof(object);

            localSingleton = il.DeclareLocal(safeImplementationType, "singleton");
            var obj = context.Container.Singletons[_singletonIndex];

            if (obj != null)
            {
                il
                .Ldloc(localSingletons !)
                .LdcI4(_singletonIndex)
                .LdelemRef()
                .Castclass(_implementationType)
                .Stloc(localSingleton);
                return(localSingleton);
            }
            var  localLockTaken  = il.DeclareLocal(typeof(bool), "lockTaken");
            var  localLock       = il.DeclareLocal(typeof(object), "lock");
            var  labelNull1      = il.DefineLabel();
            var  labelNotNull2   = il.DefineLabel();
            var  labelNotTaken   = il.DefineLabel();
            bool boolPlaceholder = false;

            il
            .Ldloc(localSingletons !)
            .LdcI4(_singletonIndex)
            .LdelemRef()
            .Dup()
            .Castclass(safeImplementationType)
            .Stloc(localSingleton)
            .Brtrue(labelNull1)
            .LdcI4(0)
            .Stloc(localLockTaken);
            context.PushToILStack(Need.ContainerNeed);
            il
            .Castclass(typeof(ContainerImpl))
            .Ldfld(() => default(ContainerImpl).SingletonLocks)
            .LdcI4(_singletonIndex)
            .LdelemRef()
            .Stloc(localLock)
            .Try()
            .Ldloc(localLock)
            .Ldloca(localLockTaken)
            .Call(() => Monitor.Enter(null, ref boolPlaceholder))
            .Ldloc(localSingletons)
            .LdcI4(_singletonIndex)
            .LdelemRef()
            .Dup()
            .Castclass(safeImplementationType)
            .Stloc(localSingleton)
            .Brtrue(labelNotNull2);
            buildCRegLocals.Push();
            var nestedLocal = _wrapping.GenMain(context);

            if (nestedLocal != null)
            {
                il.Ldloc(nestedLocal);
            }
            buildCRegLocals.Pop();
            il
            .Stloc(localSingleton)
            .Ldloc(localSingletons)
            .LdcI4(_singletonIndex)
            .Ldloc(localSingleton)
            .StelemRef()
            .Mark(labelNotNull2)
            .Finally()
            .Ldloc(localLockTaken)
            .BrfalseS(labelNotTaken)
            .Ldloc(localLock)
            .Call(() => Monitor.Exit(null))
            .Mark(labelNotTaken)
            .EndTry()
            .Mark(labelNull1);
            buildCRegLocals.Add(this, localSingleton);
            context.BuildContext = backupCtx;
            return(localSingleton);
        }
コード例 #11
0
ファイル: InstanceImpl.cs プロジェクト: mano-cz/BTDB
 public void GenInitialization(IGenerationContext context)
 {
     if (_instance == null) return;
     context.GetSpecific<InstancesLocalGenCtxHelper>().Prepare();
 }
コード例 #12
0
ファイル: SingletonImpl.cs プロジェクト: Xamarui/BTDB
 public bool IsCorruptingILStack(IGenerationContext context)
 {
     var buildCRegLocals = context.GetSpecific<BuildCRegLocals>();
     var localSingleton = buildCRegLocals.Get(this);
     if (localSingleton != null) return false;
     var obj = context.Container.Singletons[_singletonIndex];
     if (obj != null) return false;
     return true;
 }
コード例 #13
0
ファイル: SingletonImpl.cs プロジェクト: Xamarui/BTDB
 public IILLocal GenMain(IGenerationContext context)
 {
     var backupCtx = context.BuildContext;
     context.BuildContext = _buildCtx;
     var il = context.IL;
     var buildCRegLocals = context.GetSpecific<BuildCRegLocals>();
     var localSingleton = buildCRegLocals.Get(this);
     if (localSingleton != null)
     {
         return localSingleton;
     }
     var localSingletons = context.GetSpecific<SingletonsLocal>().MainLocal;
     var safeImplementationType = _implementationType.IsPublic ? _implementationType : typeof (object);
     localSingleton = il.DeclareLocal(safeImplementationType, "singleton");
     var obj = context.Container.Singletons[_singletonIndex];
     if (obj != null)
     {
         il
             .Ldloc(localSingletons)
             .LdcI4(_singletonIndex)
             .LdelemRef()
             .Castclass(_implementationType)
             .Stloc(localSingleton);
         return localSingleton;
     }
     var localLockTaken = il.DeclareLocal(typeof(bool), "lockTaken");
     var localLock = il.DeclareLocal(typeof(object), "lock");
     var labelNull1 = il.DefineLabel();
     var labelNotNull2 = il.DefineLabel();
     var labelNotTaken = il.DefineLabel();
     bool boolPlaceholder = false;
     il
         .Ldloc(localSingletons)
         .LdcI4(_singletonIndex)
         .LdelemRef()
         .Dup()
         .Castclass(safeImplementationType)
         .Stloc(localSingleton)
         .Brtrue(labelNull1)
         .LdcI4(0)
         .Stloc(localLockTaken);
     context.PushToILStack(Need.ContainerNeed);
     il
         .Castclass(typeof(ContainerImpl))
         .Ldfld(() => default(ContainerImpl).SingletonLocks)
         .LdcI4(_singletonIndex)
         .LdelemRef()
         .Stloc(localLock)
         .Try()
         .Ldloc(localLock)
         .Ldloca(localLockTaken)
         .Call(() => Monitor.Enter(null, ref boolPlaceholder))
         .Ldloc(localSingletons)
         .LdcI4(_singletonIndex)
         .LdelemRef()
         .Dup()
         .Castclass(safeImplementationType)
         .Stloc(localSingleton)
         .Brtrue(labelNotNull2);
     buildCRegLocals.Push();
     var nestedLocal = _wrapping.GenMain(context);
     if (nestedLocal != null)
     {
         il.Ldloc(nestedLocal);
     }
     buildCRegLocals.Pop();
     il
         .Stloc(localSingleton)
         .Ldloc(localSingletons)
         .LdcI4(_singletonIndex)
         .Ldloc(localSingleton)
         .StelemRef()
         .Mark(labelNotNull2)
         .Finally()
         .Ldloc(localLockTaken)
         .BrfalseS(labelNotTaken)
         .Ldloc(localLock)
         .Call(() => Monitor.Exit(null))
         .Mark(labelNotTaken)
         .EndTry()
         .Mark(labelNull1);
     buildCRegLocals.Add(this, localSingleton);
     context.BuildContext = backupCtx;
     return localSingleton;
 }
コード例 #14
0
 public void GenInitialization(IGenerationContext context)
 {
     context.GetSpecific<InstancesLocalGenCtxHelper>().Prepare();
 }