Exemple #1
0
        ///// <summary>
        ///// Reflect <c>Module</c> with global declarations.
        ///// </summary>
        ///// <param name="functions">Dictionary of reflected functions.</param>
        ///// <param name="constants">Dictionary of reflected constants.</param>
        ///// <param name="module">The module to reflect functions and constants from.</param>
        //private void ReflectGlobals(
        //    //Dictionary<string, DTypeDesc>/*!*/ types,
        //    Dictionary<string, DRoutineDesc>/*!*/ functions,
        //    DualDictionary<string, DConstantDesc>/*!*/ constants,
        //    Module/*!*/module)
        //{
        //    // functions (arglesses & argfulls):
        //    FullReflectFunctions(module.GetMethods(BindingFlags.Public | BindingFlags.Static), functions, true);

        //    // constants:
        //    ReflectConstants(module.GetFields(BindingFlags.Public | BindingFlags.Static), constants);
        //}

        /// <summary>
        /// Find the MethodInfo representing argless stub for the specified method. If the method
        /// is found, it will be added using <c>AddArglessStub</c>.
        /// </summary>
        /// <param name="realMethods">List of MethodInfos to search from.</param>
        /// <param name="functions">Dictionary of reflected functions.</param>
        /// <param name="method">Argfull overload which argless stub is searched.</param>
        /// <param name="impl_func">ImplementsFunction attribute of tjhe <c>method</c>.</param>
        /// <returns>DRoutineDesc of argless stub or null if it was not found.</returns>
        private DRoutineDesc FindArglessStub(
            MethodInfo[] /*!!*/ realMethods, Dictionary <string, DRoutineDesc> /*!*/ functions,
            MethodInfo /*!*/ method, ImplementsFunctionAttribute /*!*/ impl_func)
        {
            foreach (var argless in realMethods)
            {
                if (argless.Name == method.Name && argless != method &&
                    PhpFunctionUtils.IsArglessStub(argless, null))
                {
                    // we have found the argless stub for the impl_func in the realMethods list
                    return(AddArglessStub(functions, argless, impl_func.Name));
                }
            }

            return(null);
        }
Exemple #2
0
        /// <summary>
        ///	reflect global functions in &lt;Script&gt; class
        /// TODO: consider merging with PhpTypeDesc.FullReflectMethods
        /// </summary>
        /// <param name="functions">Dictionary for functions</param>
        /// <param name="scriptType">The type to reflect from.</param>
        private static void ReflectScriptTypeFunctions(Type scriptType, Dictionary <string, DRoutineDesc> functions)
        {
            MethodInfo[] real_methods = scriptType.GetMethods(DTypeDesc.MembersReflectionBindingFlags);
            Dictionary <string, MethodInfo> argless_stubs = new Dictionary <string, MethodInfo>(real_methods.Length / 3);

            // first pass - fill argless_stubs
            for (int i = 0; i < real_methods.Length; i++)
            {
                MethodInfo info = real_methods[i];
                if ((info.Attributes & MethodAttributes.MemberAccessMask) != MethodAttributes.PrivateScope)
                {
                    if (PhpFunctionUtils.IsArglessStub(info, null))
                    {
                        argless_stubs.Add(info.Name, info);
                        real_methods[i] = null;
                    }
                }
                else
                {
                    real_methods[i] = null;                  // expunge private scope methods
                }
            }

            // second pass - match argfulls
            foreach (MethodInfo info in real_methods)
            {
                // argfull detection:
                if (info == null || !PhpFunctionUtils.IsArgfullOverload(info, null))
                {
                    continue;
                }

                // TODO: namespaces!!

                if (functions.ContainsKey(info.Name))
                {
                    throw new InvalidOperationException("Function '" + info.Name + "' redeclaration.");   // compilation unit contains more functions with the same name
                }
                // find the argless:
                MethodInfo argless_info = null;
                if (!argless_stubs.TryGetValue(info.Name, out argless_info))
                {
                    // argless has to be generated on-the-fly
                    throw new NotImplementedException("Generating argless stubs for imported PHP types is not yet implemented");
                }

                if (!PhpFunctionUtils.IsRealConditionalDefinition(info.Name))
                {
                    Name                name = new Name(info.Name);
                    DRoutineDesc        func_desc;
                    PhpMemberAttributes attrs = Enums.GetMemberAttributes(info);

                    // this method has not been populated -> create a new PhpRoutineDesc
                    func_desc = new PhpRoutineDesc(attrs, (RoutineDelegate)Delegate.CreateDelegate(Types.RoutineDelegate, argless_info), true);
                    functions.Add(info.Name, func_desc);

                    //
                    if (func_desc.Member == null)
                    {
                        PhpFunction func = new PhpFunction(new QualifiedName(name), (PhpRoutineDesc)func_desc, info, argless_info);
                        func.WriteUp(PhpRoutineSignature.FromArgfullInfo(func, info));
                        func_desc.Member = func;
                    }
                }
            }
        }