Exemple #1
0
        /// <summary>
        /// Emit body of enumeration of referenced functions.
        /// </summary>
        internal void CreateEnumerateReferencedFunctions(DiagnosticBag diagnostic)
        {
            var method    = this.ScriptType.EnumerateReferencedFunctionsSymbol;
            var functions = GlobalSemantics.ResolveExtensionContainers(this.Compilation)
                            .SelectMany(c => c.GetMembers().OfType <MethodSymbol>())
                            .Where(GlobalSemantics.IsFunction);

            // void (Action<string, RuntimeMethodHandle> callback)
            var body = MethodGenerator.GenerateMethodBody(this, method,
                                                          (il) =>
            {
                var action_string_method = method.Parameters[0].Type;
                Debug.Assert(action_string_method.Name == "Action");
                var invoke = action_string_method.DelegateInvokeMethod();
                Debug.Assert(invoke != null);

                foreach (var f in functions)
                {
                    // callback.Invoke(f.Name, f)
                    il.EmitLoadArgumentOpcode(0);
                    il.EmitStringConstant(f.Name);
                    il.EmitLoadToken(this, diagnostic, f, null);
                    il.EmitCall(this, diagnostic, ILOpCode.Callvirt, invoke);
                }

                //
                il.EmitRet(true);
            },
                                                          null, diagnostic, false);

            SetMethodBody(method, body);
        }
        internal NamedTypeSymbol GetTypeFromTypeRef(ITypeRef t)
        {
            if (t is PrimitiveTypeRef)
            {
                return(GetTypeFromTypeRef((PrimitiveTypeRef)t));
            }
            else if (t is ClassTypeRef)
            {
                return((NamedTypeSymbol)GlobalSemantics.GetType(t.QualifiedName) ?? CoreTypes.Object.Symbol);
            }
            else if (t is ArrayTypeRef)
            {
                return(this.CoreTypes.PhpArray);
            }
            else if (t is LambdaTypeRef)
            {
            }

            throw new ArgumentException();
        }