Пример #1
0
        /// <summary>
        /// Adds referenced symbol into the map.
        /// In case of redeclaration, the handle is added to the list.
        /// </summary>
        /// <exception cref="PhpFatalErrorException">The routine is already defined as a user routine.</exception>
        public static ClrRoutineInfo /*!*/ DeclareAppRoutine(string name, MethodInfo method)
        {
            ClrRoutineInfo routine;

            if (s_nameToIndex.TryGetValue(name, out var index))
            {
                Debug.Assert(index != 0);

                if (index > 0)  // already taken by user routine
                {
                    RedeclarationError(name);
                }

                (routine = s_appRoutines[-index - 1]).AddOverload(method);
            }
            else
            {
                index = -s_appRoutines.Count - 1;
                s_appRoutines.Add(routine = new ClrRoutineInfo(index, name, method));
                s_nameToIndex[name]       = index;
            }

            //
            return(routine);
        }
Пример #2
0
        /// <summary>
        /// Adds referenced symbol into the map.
        /// In case of redeclaration, the handle is added to the list.
        /// </summary>
        public static void DeclareRoutine(string name, RuntimeMethodHandle handle)
        {
            // TODO: W lock

            int index;

            if (NameToIndex.TryGetValue(name, out index))
            {
                Debug.Assert(index != 0);

                if (index > 0)  // already taken by user routine
                {
                    throw new InvalidOperationException();
                }

                ((ClrRoutineInfo)AppRoutines[-index - 1]).AddOverload(handle);
            }
            else
            {
                index = -AppRoutines.Count - 1;
                var routine = new ClrRoutineInfo(index, name, handle);
                AppRoutines.Add(routine);
                NameToIndex[name] = index;

                // register the routine within the extensions table
                ExtensionsAppContext.ExtensionsTable.AddRoutine(routine);
            }
        }
Пример #3
0
        /// <summary>
        /// Adds referenced symbol into the map.
        /// In case of redeclaration, the handle is added to the list.
        /// </summary>
        /// <exception cref="InvalidOperationException">The routine is already defined as a user routine.</exception>
        public static ClrRoutineInfo /*!*/ DeclareAppRoutine(string name, MethodInfo method)
        {
            ClrRoutineInfo routine;

            // TODO: W lock

            int index;

            if (_nameToIndex.TryGetValue(name, out index))
            {
                Debug.Assert(index != 0);

                if (index > 0)  // already taken by user routine
                {
                    throw new InvalidOperationException();
                }

                (routine = (ClrRoutineInfo)_appRoutines[-index - 1]).AddOverload(method);
            }
            else
            {
                index   = -_appRoutines.Count - 1;
                routine = new ClrRoutineInfo(index, name, method);
                _appRoutines.Add(routine);
                _nameToIndex[name] = index;
            }

            //
            return(routine);
        }
Пример #4
0
        /// <summary>
        /// Adds referenced symbol into the map.
        /// In case of redeclaration, the handle is added to the list.
        /// </summary>
        public static void DeclareRoutine(string name, RuntimeMethodHandle handle)
        {
            // TODO: W lock

            int index;
            if (NameToIndex.TryGetValue(name, out index))
            {
                Debug.Assert(index != 0);

                if (index > 0)  // already taken by user routine
                {
                    throw new InvalidOperationException();
                }

                ((ClrRoutineInfo)AppRoutines[-index - 1]).AddOverload(handle);
            }
            else
            {
                index = -AppRoutines.Count - 1;
                var routine = new ClrRoutineInfo(index, name, handle);
                AppRoutines.Add(routine);
                NameToIndex[name] = index;

                // register the routine within the extensions table
                ExtensionsAppContext.ExtensionsTable.AddRoutine(routine);
            }
        }
Пример #5
0
        /// <summary>
        /// Adds referenced symbol into the map.
        /// In case of redeclaration, the handle is added to the list.
        /// </summary>
        /// <exception cref="InvalidOperationException">The routine is already defined as a user routine.</exception>
        public static ClrRoutineInfo /*!*/ DeclareAppRoutine(string name, MethodInfo method)
        {
            ClrRoutineInfo routine;

            // TODO: W lock

            int index;

            if (_nameToIndex.TryGetValue(name, out index))
            {
                Debug.Assert(index != 0);

                if (index > 0)  // already taken by user routine
                {
                    throw new InvalidOperationException();
                }

                (routine = (ClrRoutineInfo)_appRoutines[-index - 1]).AddOverload(method);
            }
            else
            {
                index   = -_appRoutines.Count - 1;
                routine = new ClrRoutineInfo(index, name, method);
                _appRoutines.Add(routine);
                _nameToIndex[name] = index;

                // register the routine within the extensions table
                ExtensionsAppContext.ExtensionsTable.AddRoutine(
                    container: method.DeclaringType,
                    routine: routine);
            }

            //
            return(routine);
        }
Пример #6
0
        /// <summary>
        /// Adds routine within its associated extension.
        /// </summary>
        /// <param name="routine">Library routine to be included in the table.</param>
        public void AddRoutine(ClrRoutineInfo routine)
        {
            if (routine == null)
            {
                throw new ArgumentNullException(nameof(routine));
            }

            foreach (var m in routine.Methods)
            {
                var tinfo = m.DeclaringType.GetTypeInfo();

                //
                var attrs = tinfo.GetCustomAttributes <PhpExtensionAttribute>();
                if (attrs != null)
                {
                    foreach (var attr in attrs)
                    {
                        AddRoutine(attr, routine);
                        VisitExtensionAttribute(attr);
                    }
                }

                //
                AddAssembly(tinfo.Assembly);
            }
        }
Пример #7
0
        void AddRoutine(PhpExtensionAttribute extension, ClrRoutineInfo routine)
        {
            var extensions = extension.Extensions;

            for (int i = 0; i < extensions.Length; i++)
            {
                EnsureExtension(extensions[i]).Routines.Add(routine);
            }
        }
Пример #8
0
        /// <summary>
        /// Adds routine within its associated extension.
        /// </summary>
        /// <param name="container">Type containing the routine declaration. Will be reflected for optional <see cref="PhpExtensionAttribute"/>.</param>
        /// <param name="routine">Library routine to be included in the table.</param>
        internal void AddRoutine(Type /*!*/ container, ClrRoutineInfo /*!*/ routine)
        {
            var extinfo = container.GetCustomAttribute <PhpExtensionAttribute>();

            if (extinfo != null)
            {
                AddRoutine(extinfo, routine);
                VisitExtensionAttribute(extinfo);
            }

            //
            AddAssembly(container.Assembly);
        }
Пример #9
0
        /// <summary>
        /// Adds routine within its associated extension(s).
        /// </summary>
        /// <param name="attr">Corresponding <see cref="PhpExtensionAttribute"/> of the containing class. Can be <c>null</c>.</param>
        /// <param name="routine">Library routine to be included into the table.</param>
        internal void AddRoutine(PhpExtensionAttribute attr, ClrRoutineInfo /*!*/ routine)
        {
            if (attr == null)
            {
                return;
            }

            var extensions = attr.Extensions;

            for (int i = 0; i < extensions.Length; i++)
            {
                EnsureExtensionInfo(extensions[i]).Routines.Add(routine);
            }
        }
Пример #10
0
        /// <summary>
        /// Adds routine within its associated extension.
        /// </summary>
        /// <param name="routine">Library routine to be included in the table.</param>
        public void AddRoutine(ClrRoutineInfo routine)
        {
            if (routine == null)
            {
                throw new ArgumentNullException(nameof(routine));
            }

            foreach (var m in routine.Methods)
            {
                var tinfo = m.DeclaringType.GetTypeInfo();

                //
                var attr = tinfo.GetCustomAttribute<PhpExtensionAttribute>();
                if (attr != null)
                {
                    AddRoutine(attr, routine);
                }

                //
                AddAssembly(tinfo.Assembly);
            }
        }
Пример #11
0
 void AddRoutine(PhpExtensionAttribute extension, ClrRoutineInfo routine)
 {
     var extensions = extension.Extensions;
     for (int i = 0; i < extensions.Length; i++)
     {
         EnsureExtension(extensions[i]).Add(routine);
     }
 }