Beispiel #1
0
        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);
        }
Beispiel #2
0
 public void GenInitialization(IGenerationContext context)
 {
     var backupCtx = context.BuildContext;
     context.BuildContext = _buildCtx;
     _wrapping.GenInitialization(context);
     context.GetSpecific<SingletonsLocal>().Prepare();
     context.BuildContext = backupCtx;
 }
Beispiel #3
0
 public void GenInitialization(IGenerationContext context)
 {
     if (_instance == null)
     {
         return;
     }
     context.GetSpecific <InstancesLocalGenCtxHelper>().Prepare();
 }
Beispiel #4
0
        public void GenInitialization(IGenerationContext context)
        {
            var backupCtx = context.BuildContext;

            context.BuildContext = _buildCtx !;
            _wrapping.GenInitialization(context);
            context.GetSpecific <SingletonsLocal>().Prepare();
            context.BuildContext = backupCtx;
        }
Beispiel #5
0
 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;
 }
Beispiel #6
0
        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);
        }
Beispiel #7
0
 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;
 }
Beispiel #8
0
        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);
        }
Beispiel #9
0
 public void GenInitialization(IGenerationContext context)
 {
     context.GetSpecific <InstancesLocalGenCtxHelper>().Prepare();
 }
Beispiel #10
0
        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);
        }
Beispiel #11
0
 public void GenInitialization(IGenerationContext context)
 {
     if (_instance == null) return;
     context.GetSpecific<InstancesLocalGenCtxHelper>().Prepare();
 }
Beispiel #12
0
 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;
 }
Beispiel #13
0
 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;
 }
 public void GenInitialization(IGenerationContext context)
 {
     context.GetSpecific<InstancesLocalGenCtxHelper>().Prepare();
 }