A group of CLR methods that are treated as a single Ruby method.
Inheritance: RubyMethodGroupBase
Ejemplo n.º 1
1
 // copy ctor
 private RubyMethodGroupInfo(RubyMethodGroupInfo/*!*/ info, RubyMemberFlags flags, RubyModule/*!*/ module)
     : base(info.MethodBases, flags, module) {
     _isStatic = info._isStatic;
     _hasVirtuals = info._hasVirtuals;
     _staticDispatchMethods = info._staticDispatchMethods;
     // Note: overloadOwners and maxCachedOverloadLevel are cleared whenever the group is copied.
 }
        private RubyMethodGroupInfo /*!*/ MakeAllMethodsGroup(RubyClass /*!*/ cls)
        {
            var overloads      = new MethodBase[_allMethods.Count];
            var overloadOwners = new RubyMethodGroupInfo[overloads.Length];
            int i = 0;

            foreach (var entry in _allMethods.Values)
            {
                overloads[i]      = entry.Overload;
                overloadOwners[i] = entry.Owner;
                i++;
            }

            var result = new RubyMethodGroupInfo(overloads, cls, overloadOwners, cls.IsSingletonClass);

            // update ownership of overloads owned by the new group:
            foreach (var entry in _allMethods.Values)
            {
                if (entry.Owner != null)
                {
                    entry.Owner.CachedInGroup(result);
                }
                else
                {
                    entry.Owner = result;
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a CLR method group.
        /// </summary>
        internal RubyMethodGroupInfo(MethodBase/*!*/[]/*!*/ methods, RubyModule/*!*/ declaringModule,
            RubyMethodGroupInfo/*!*/[] overloadOwners, bool isStatic)
            : base(methods, RubyMemberFlags.Public, declaringModule) {
            Debug.Assert(overloadOwners == null || methods.Length == overloadOwners.Length);

            _isStatic = isStatic;
            _overloadOwners = overloadOwners;
        }
Ejemplo n.º 4
0
 // copy ctor
 private RubyMethodGroupInfo(RubyMethodGroupInfo/*!*/ info, RubyMemberFlags flags, RubyModule/*!*/ module)
     : base(info.MethodBases, flags, module) {
     _isStatic = info._isStatic;
     _hasVirtuals = info._hasVirtuals;
     _staticDispatchMethods = info._staticDispatchMethods;
     // Note: overloadOwners and maxCachedOverloadLevel are cleared whenever the group is copied
     // The resulting group captures an immutable set of underlying CLR members.
 }
Ejemplo n.º 5
0
 // copy ctor
 private RubyMethodGroupInfo(RubyMethodGroupInfo /*!*/ info, RubyMemberFlags flags, RubyModule /*!*/ module)
     : base(flags, module)
 {
     _methodBases  = info._methodBases;
     _overloads    = info._overloads;
     _isRubyMethod = info._isRubyMethod;
     _isClrStatic  = info._isClrStatic;
 }
Ejemplo n.º 6
0
        // Called on this group whenever other group includes some overloads from this group.
        // Updates maxCachedOverloadLevel - the max. class hierarchy level which caches an overload owned by this group.
        internal void CachedInGroup(RubyMethodGroupInfo/*!*/ group) {
            Context.RequiresClassHierarchyLock();

            int groupLevel = ((RubyClass)group.DeclaringModule).Level;
            if (_maxCachedOverloadLevel < groupLevel) {
                _maxCachedOverloadLevel = groupLevel;
            }
        }
Ejemplo n.º 7
0
        internal override void BuildCallNoFlow(MetaObjectBuilder /*!*/ metaBuilder, CallArguments /*!*/ args, string /*!*/ name)
        {
            var actualArgs = RubyMethodGroupInfo.MakeActualArgs(metaBuilder, args, true, false, false, false);

            metaBuilder.Result = Methods.SetInstanceVariable.OpCall(
                AstFactory.Box(actualArgs[0]),
                AstFactory.Box(actualArgs[1]),
                args.ScopeExpression,
                AstUtils.Constant(InstanceVariableName)
                );
        }
Ejemplo n.º 8
0
        // Called on this group whenever other group includes some overloads from this group.
        // Updates maxCachedOverloadLevel - the max. class hierarchy level which caches an overload owned by this group.
        internal void CachedInGroup(RubyMethodGroupInfo /*!*/ group)
        {
            Context.RequiresClassHierarchyLock();

            int groupLevel = ((RubyClass)group.DeclaringModule).Level;

            if (_maxCachedOverloadLevel < groupLevel)
            {
                _maxCachedOverloadLevel = groupLevel;
            }
        }
Ejemplo n.º 9
0
        // thread safe: doesn't need any lock since it only accesses immutable state
        public bool TryGetClrConstructor(out RubyMemberInfo method) {
            OverloadInfo[] ctors;
            if (TypeTracker != null && (ctors = GetConstructors(TypeTracker.Type).ToArray()).Length > 0) {
                method = new RubyMethodGroupInfo(ctors, this, true);
                return true;
            }

            method = null;
            return false;
        }
Ejemplo n.º 10
0
        // thread safe: doesn't need any lock since it only accesses immutable state
        public bool TryGetClrConstructor(out RubyMemberInfo method) {
            ConstructorInfo[] ctors;
            if (TypeTracker != null && !TypeTracker.Type.IsInterface && (ctors = TypeTracker.Type.GetConstructors()) != null && ctors.Length > 0) {
                method = new RubyMethodGroupInfo(ctors, this, true);
                return true;
            }

            method = null;
            return false;
        }
Ejemplo n.º 11
0
 // copy ctor
 private RubyMethodGroupInfo(RubyMethodGroupInfo/*!*/ info, RubyMemberFlags flags, RubyModule/*!*/ module)
     : base(flags, module) {
     _methodBases = info._methodBases;
     _overloads = info._overloads;
     _isRubyMethod = info._isRubyMethod;
     _isClrStatic = info._isClrStatic;
 }
Ejemplo n.º 12
0
 // copy ctor
 private RubyMethodGroupInfo(RubyMethodGroupInfo/*!*/ info, MethodBase/*!*/[] methods)
     : base(methods, info.Flags, info.DeclaringModule) {
     _isStatic = info._isStatic;
     // Note: overloadOwners and maxCachedOverloadLevel are cleared whenever the group is copied.
 }
Ejemplo n.º 13
0
 // copy ctor
 private RubyMethodGroupInfo(RubyMethodGroupInfo/*!*/ info, RubyMemberFlags flags, RubyModule/*!*/ module)
     : this(info, flags, module, info._methodBases) {
 }
Ejemplo n.º 14
0
 // copy ctor
 private RubyMethodGroupInfo(RubyMethodGroupInfo/*!*/ info, MethodBase/*!*/[] methods)
     : base(methods, info.Flags, info.DeclaringModule) {
     _isStatic = info._isStatic;
     // Note: overloadOwners and maxCachedOverloadLevel are cleared whenever the group is copied.
     // The resulting group captures an immutable set of underlying CLR members.
 }
 // copy ctor
 private RubyMethodGroupInfo(RubyMethodGroupInfo /*!*/ info, RubyMemberFlags flags, RubyModule /*!*/ module)
     : base(info.MethodBases, flags, module)
 {
     _isStatic = info._isStatic;
 }
 // copy ctor
 private RubyMethodGroupInfo(RubyMethodGroupInfo /*!*/ info, OverloadInfo /*!*/[] methods)
     : base(methods, info.Flags, info.DeclaringModule)
 {
     _isStatic = info._isStatic;
 }
Ejemplo n.º 17
0
        private RubyMethodGroupInfo/*!*/ MakeAllMethodsGroup(RubyClass/*!*/ cls) {
            var overloads = new MethodBase[_allMethods.Count];
            var overloadOwners = new RubyMethodGroupInfo[overloads.Length];
            int i = 0;
            foreach (var entry in _allMethods.Values) {
                overloads[i] = entry.Overload;
                overloadOwners[i] = entry.Owner;
                i++;
            }

            var result = new RubyMethodGroupInfo(overloads, cls, overloadOwners, cls.IsSingletonClass);

            // update ownership of overloads owned by the new group:
            foreach (var entry in _allMethods.Values) {
                if (entry.Owner != null) {
                    entry.Owner.CachedInGroup(result);
                } else {
                    entry.Owner = result;
                }
            }

            return result;
        }
Ejemplo n.º 18
0
        // Returns the number of methods newly added to the dictionary.
        private bool AddMethodsOverwriteExisting(
            MemberInfo/*!*/[]/*!*/ newOverloads, RubyMethodGroupInfo/*!*/[] overloadOwners) {

            bool anyChange = false;
            for (int i = 0; i < newOverloads.Length; i++) {
                var method = (MethodBase)newOverloads[i];
                if (IsVisible(method)) {
                    var paramTypes = new ValueArray<Type>(ReflectionUtils.GetParameterTypes(method.GetParameters()));
                    if (_allMethods == null) {
                        _allMethods = new Dictionary<ValueArray<Type>, ClrOverloadInfo>();
                    }

                    _allMethods[paramTypes] = new ClrOverloadInfo {
                        Overload = method,
                        Owner = (overloadOwners != null) ? overloadOwners[i] : null
                    };

                    anyChange = true;
                }
            }
            return anyChange;
        }
Ejemplo n.º 19
0
 // copy ctor
 private RubyMethodGroupInfo(RubyMethodGroupInfo/*!*/ info, RubyMemberFlags flags, RubyModule/*!*/ module)
     : base(info.MethodBases, flags, module) {
     _isStatic = info._isStatic;
     _hasVirtuals = info._hasVirtuals;
     _staticDispatchMethods = info._staticDispatchMethods;
 }
Ejemplo n.º 20
0
 // copy ctor
 private RubyMethodGroupInfo(RubyMethodGroupInfo/*!*/ info, RubyMemberFlags flags, RubyModule/*!*/ module)
     : base(info.MethodBases, flags, module) {
     _isStatic = info._isStatic;
 }
Ejemplo n.º 21
0
 // copy ctor
 private RubyMethodGroupInfo(RubyMethodGroupInfo/*!*/ info, OverloadInfo/*!*/[] methods)
     : base(methods, info.Flags, info.DeclaringModule) {
     _isStatic = info._isStatic;
 }