public void Signature(MethodReference method, MethodSignature signature, TypeReferenceContext context, bool forConstructor, bool allowCache)
        {
            // Reduce method signature heap usage
            if (
                !forConstructor &&
                (signature.GenericParameterCount == 0)
                )
            {
                if (signature.ParameterCount == 0)
                {
                    if (
                        (signature.ReturnType == null) ||
                        (signature.ReturnType.FullName == "System.Void")
                        )
                    {
                        WriteRaw("JSIL.MethodSignature.Void");
                        return;
                    }
                    else if (!TypeUtil.IsOpenType(signature.ReturnType))
                    {
                        WriteRaw("JSIL.MethodSignature.Return");
                        LPar();
                        TypeReference(signature.ReturnType, context);
                        RPar();
                        return;
                    }
                }
                else if (
                    (
                        (signature.ReturnType == null) ||
                        (signature.ReturnType.FullName == "System.Void")
                    ) &&
                    (signature.ParameterCount == 1) &&
                    !TypeUtil.IsOpenType(signature.ParameterTypes[0])
                    )
                {
                    WriteRaw("JSIL.MethodSignature.Action");
                    LPar();
                    TypeReference(signature.ParameterTypes[0], context);
                    RPar();
                    return;
                }
            }

            if (forConstructor)
            {
                WriteRaw("new JSIL.ConstructorSignature");
            }
            else
            {
                WriteRaw("new JSIL.MethodSignature");
            }

            LPar();

            var oldSignature = context.SignatureMethod;

            context.SignatureMethod = method;

            try {
                if (forConstructor)
                {
                    TypeReference(method.DeclaringType, context);

                    Comma();
                }
                else
                {
                    if ((signature.ReturnType == null) || (signature.ReturnType.FullName == "System.Void"))
                    {
                        WriteRaw("null");
                    }
                    else
                    {
                        if ((context.EnclosingMethod != null) && !TypeUtil.IsOpenType(signature.ReturnType))
                        {
                            TypeIdentifier(signature.ReturnType as dynamic, context, false);
                        }
                        else
                        {
                            TypeReference(signature.ReturnType, context);
                        }
                    }

                    Comma();
                }

                if (signature.ParameterCount > 0)
                {
                    OpenBracket(false);
                    CommaSeparatedListCore(
                        signature.ParameterTypes, (pt) => {
                        if ((context.EnclosingMethod != null) && !TypeUtil.IsOpenType(pt))
                        {
                            TypeIdentifier(pt as dynamic, context, false);
                        }
                        else
                        {
                            TypeReference(pt, context);
                        }
                    }
                        );
                    CloseBracket(false);
                }
                else
                {
                    WriteRaw("null");
                }

                if (!forConstructor &&
                    (signature.GenericParameterNames != null) &&
                    (signature.GenericParameterCount > 0)
                    )
                {
                    Comma();
                    OpenBracket(false);
                    CommaSeparatedList(signature.GenericParameterNames, context, ListValueType.Primitive);
                    CloseBracket(false);
                }
            } finally {
                context.SignatureMethod = oldSignature;
            }

            RPar();
        }
 public void MethodSignature(MethodReference method, MethodSignature signature, TypeReferenceContext context)
 {
     Signature(method, signature, context, false, true);
 }
예제 #3
0
 public NamedMethodSignature(string name, MethodSignature signature)
 {
     Name      = name;
     Signature = signature;
     _Hash     = null;
 }
 public void ConstructorSignature(MethodReference method, MethodSignature signature, TypeReferenceContext context)
 {
     Signature(method, signature, context, true, true);
 }
예제 #5
0
        public void MethodSignature(MethodReference method, MethodSignature signature, TypeReferenceContext context)
        {
            // The signature cache can cause problems inside methods for generic signatures.
            var cached = Configuration.Optimizer.CacheMethodSignatures.GetValueOrDefault(true);

            // We also don't want to use the cache for method definitions in skeletons.
            if (Stubbed && Configuration.GenerateSkeletonsForStubbedAssemblies.GetValueOrDefault(false))
            {
                cached = false;
            }

            if (cached && ((context.InvokingMethod != null) || (context.EnclosingMethod != null)))
            {
                if (TypeUtil.IsOpenType(signature.ReturnType))
                {
                    cached = false;
                }
                else if (signature.ParameterTypes.Any(TypeUtil.IsOpenType))
                {
                    cached = false;
                }
            }

            if (cached)
            {
                var defineNew = (context.InvokingMethod == null) && (context.EnclosingMethod == null);

                WriteRaw(defineNew ? "$sig.make" : "$sig.get");
                LPar();

                Value(signature.ID);

                /*
                 * FIXME: Not possible since IDs for jsil.core/jsil.bootstrap APIs aren't defined.
                 * if (!defineNew) {
                 *  RPar();
                 *  return;
                 * }
                 */

                Comma();
            }
            else
            {
                LPar();

                WriteRaw("new JSIL.MethodSignature");
                LPar();
            }

            var oldSignature = context.SignatureMethod;

            context.SignatureMethod = method;

            try {
                if ((signature.ReturnType == null) || (signature.ReturnType.FullName == "System.Void"))
                {
                    WriteRaw("null");
                }
                else
                {
                    if ((context.EnclosingMethod != null) && !TypeUtil.IsOpenType(signature.ReturnType))
                    {
                        TypeIdentifier(signature.ReturnType as dynamic, context, false);
                    }
                    else
                    {
                        TypeReference(signature.ReturnType, context);
                    }
                }

                Comma();
                OpenBracket(false);

                CommaSeparatedListCore(
                    signature.ParameterTypes, (pt) => {
                    if ((context.EnclosingMethod != null) && !TypeUtil.IsOpenType(pt))
                    {
                        TypeIdentifier(pt as dynamic, context, false);
                    }
                    else
                    {
                        TypeReference(pt, context);
                    }
                }
                    );

                CloseBracket(false);

                if (signature.GenericParameterNames != null)
                {
                    Comma();
                    OpenBracket(false);
                    CommaSeparatedList(signature.GenericParameterNames, context, ListValueType.Primitive);
                    CloseBracket(false);
                }
            } finally {
                context.SignatureMethod = oldSignature;
            }

            RPar();

            if (!cached)
            {
                RPar();
            }
        }