Esempio n. 1
0
        /// <summary>
        /// Reflect argfull stubs from the list of given methods.
        /// </summary>
        /// <param name="realMethods">List of MethodInfos to reflect.</param>
        /// <param name="functions">Dictionary of reflected functions.</param>
        /// <param name="lookForArgless">True to look for argless stub in <c>realMethods</c> if argless stub was not found in <c>functions</c>.</param>
        private void FullReflectFunctions(MethodInfo[] /*!!*/ realMethods, Dictionary <string, DRoutineDesc> /*!*/ functions, bool lookForArgless)
        {
            int i = 0;

            while (i < realMethods.Length)
            {
                MethodInfo method = realMethods[i];

                if (!method.IsGenericMethodDefinition)
                {
                    ImplementsFunctionAttribute impl_func = ImplementsFunctionAttribute.Reflect(method);
                    if (impl_func != null)
                    {
                        DRoutineDesc desc;

                        // argless is reflected already
                        // or argless was not reflected yet and can be found in realMethods list,
                        // otherwise an exception is thrown:
                        if (functions.TryGetValue(impl_func.Name, out desc) ||
                            (lookForArgless && (desc = FindArglessStub(realMethods, functions, method, impl_func)) != null) ||
                            (!Configuration.IsLoaded && !Configuration.IsBeingLoaded && (desc = AddEmptyArglessStub(functions, impl_func.Name)) != null))
                        {
                            if (desc.Member == null)
                            {
                                // first argfull overload occurrence //

                                // estimate overload count by counting subsequent methods with the same CLR name (heuristics):
                                int j = i + 1;
                                while (j < realMethods.Length && realMethods[j].Name == method.Name)
                                {
                                    j++;
                                }
                                int estimated_overload_count = j - i;

                                new PhpLibraryFunction((PhpLibraryFunctionDesc)desc, new Name(impl_func.Name), impl_func.Options,
                                                       estimated_overload_count);
                            }

                            PhpLibraryFunction.Overload overload;
                            desc.PhpLibraryFunction.AddOverload(method, out overload);

                            //if (NeedsArglessAttribute.IsSet(method))
                            //{/* function should be called via argless stub, occurs only if library function is defined in PHP library and calls arg-aware function inside */}
                        }
                        else
                        {
                            throw new ReflectionException(CoreResources.GetString("invalid_class_library_wrapper", dynamicWrapper.CodeBase));
                        }
                    }
                }

                i++;
            }
        }
Esempio n. 2
0
        private static Dictionary <string, List <PhpLibraryFunction.Overload> > /*!*/ GetLibraryFunctions(Type attr, Assembly /*!*/ assembly)
        {
            Dictionary <string, List <PhpLibraryFunction.Overload> > result =
                new Dictionary <string, List <PhpLibraryFunction.Overload> >(500);

            foreach (Type type in assembly.GetTypes())
            {
                if (PhpLibraryModule.IsLibraryType(type))
                {
                    foreach (MethodInfo method in type.GetMethods(BindingFlags.Public | BindingFlags.Static))
                    {
                        if (!method.IsGenericMethodDefinition)
                        {
                            ImplementsFunctionAttribute impl_func =
                                (attr == null)?
                                ImplementsFunctionAttribute.Reflect(method):
                                ImplementsFunctionAttribute.ReflectDynamic(attr, method);

                            if (impl_func != null)
                            {
                                List <PhpLibraryFunction.Overload> overloads;
                                if (!result.TryGetValue(impl_func.Name, out overloads))
                                {
                                    overloads = new List <PhpLibraryFunction.Overload>();
                                    result.Add(impl_func.Name, overloads);
                                }

                                if (PhpLibraryFunction.AddOverload(overloads, method, impl_func.Options) == DRoutine.InvalidOverloadIndex)
                                {
                                    throw new ReflectionException(CoreResources.GetString("invalid_class_library", assembly.CodeBase));
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }