예제 #1
0
        public bool Equals(MemberIdentifier rhs, ITypeInfoSource typeInfo)
        {
            /*
             * if (this == rhs)
             *  return true;
             */

            if (IsStatic != rhs.IsStatic)
            {
                return(false);
            }

            if (Type != rhs.Type)
            {
                return(false);
            }

            if (GenericArgumentCount != rhs.GenericArgumentCount)
            {
                return(false);
            }

            if (!String.Equals(Name, rhs.Name))
            {
                return(false);
            }

            if (!TypesAreEqual(typeInfo, ReturnType, rhs.ReturnType))
            {
                return(false);
            }

            if ((ParameterTypes == AnyParameterTypes) || (rhs.ParameterTypes == AnyParameterTypes))
            {
            }
            else if ((ParameterTypes == null) || (rhs.ParameterTypes == null))
            {
                if (ParameterTypes != rhs.ParameterTypes)
                {
                    return(false);
                }
            }
            else
            {
                if (ParameterTypes.Length != rhs.ParameterTypes.Length)
                {
                    return(false);
                }

                for (int i = 0, c = ParameterTypes.Length; i < c; i++)
                {
                    if (!TypesAreEqual(typeInfo, ParameterTypes[i], rhs.ParameterTypes[i]))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
예제 #2
0
 public ExpandCastExpressions(TypeSystem typeSystem, JSSpecialIdentifiers js, JSILIdentifier jsil, ITypeInfoSource typeInfo)
 {
     TypeSystem = typeSystem;
     JS = js;
     JSIL = jsil;
     TypeInfo = typeInfo;
 }
예제 #3
0
 public BaseMethodCacher (ITypeInfoSource typeInfo, TypeDefinition thisType) {
     TypeInfo = typeInfo;
     ThisType = thisType;
     CachedMethods = new Dictionary<QualifiedMemberIdentifier, CachedMethodRecord>(
         new QualifiedMemberIdentifier.Comparer(TypeInfo)
     );
 }
예제 #4
0
        public MemberIdentifier(ITypeInfoSource ti, MethodReference mr, string newName = null)
        {
            IsStatic       = !mr.HasThis;
            Type           = MemberType.Method;
            Name           = newName ?? mr.Name;
            ReturnType     = mr.ReturnType;
            ParameterTypes = GetParameterTypes(mr.Parameters);

            if (mr is GenericInstanceMethod)
            {
                GenericArgumentCount = ((GenericInstanceMethod)mr).GenericArguments.Count;
            }
            else if (mr.HasGenericParameters)
            {
                GenericArgumentCount = mr.GenericParameters.Count;
            }
            else
            {
                GenericArgumentCount = 0;
            }

            ti.CacheProxyNames(mr);

            HashCode = Type.GetHashCode() ^ Name.GetHashCode();
        }
예제 #5
0
 public ExpandCastExpressions (TypeSystem typeSystem, JSSpecialIdentifiers js, JSILIdentifier jsil, ITypeInfoSource typeInfo, MethodTypeFactory methodTypeFactory) {
     TypeSystem = typeSystem;
     JS = js;
     JSIL = jsil;
     TypeInfo = typeInfo;
     MethodTypeFactory = methodTypeFactory;
 }
예제 #6
0
        public MemberIdentifier(ITypeInfoSource ti, PropertyReference pr)
        {
            Type                 = MemberType.Property;
            Name                 = pr.Name;
            ReturnType           = pr.PropertyType;
            GenericArgumentCount = 0;
            ParameterTypes       = null;
            ti.CacheProxyNames(pr);

            var pd = pr.Resolve();

            if (pd != null)
            {
                if (pd.GetMethod != null)
                {
                    ParameterTypes = GetParameterTypes(pd.GetMethod.Parameters);
                }
                else if (pd.SetMethod != null)
                {
                    ParameterTypes = GetParameterTypes(pd.SetMethod.Parameters)
                                     .Take(pd.SetMethod.Parameters.Count - 1).ToArray();
                }
            }

            HashCode = Type.GetHashCode() ^ Name.GetHashCode();
        }
예제 #7
0
        public MemberIdentifier(ITypeInfoSource ti, EventReference er)
        {
            Type                 = MemberType.Event;
            Name                 = er.Name;
            ReturnType           = er.EventType;
            GenericArgumentCount = 0;
            ParameterTypes       = null;
            ti.CacheProxyNames(er);

            var ed = er.Resolve();

            if (ed != null)
            {
                if (ed.AddMethod != null)
                {
                    IsStatic = ed.AddMethod.IsStatic;
                }
                else if (ed.RemoveMethod != null)
                {
                    IsStatic = ed.RemoveMethod.IsStatic;
                }
                else
                {
                    // FIXME
                    IsStatic = false;
                }
            }
            else
            {
                // FIXME
                IsStatic = false;
            }

            HashCode = Type.GetHashCode() ^ Name.GetHashCode();
        }
            public DefinitelyTypedEmptyAstEmitter(
                JavascriptFormatter output, JSILIdentifier jsil,
                TypeSystem typeSystem, ITypeInfoSource typeInfo,
                Configuration configuration
                )
            {
                //Configuration = configuration;
                //Output = output;
                //JSIL = jsil;
                TypeSystem = typeSystem;
                //TypeInfo = typeInfo;

                //IncludeTypeParens.Push(false);
                //PassByRefStack.Push(false);
                //OverflowCheckStack.Push(false);

                //VisitNestedFunctions = true;

                /*if (output.SourceMapBuilder != null)
                 * {
                 *  BeforeNodeProcessed += AddSourceMapInfo;
                 *  //AfterNodeProcessed += AddSourceMapInfoEnd;
                 * }*/
                ReferenceContext = new TypeReferenceContext();
            }
예제 #9
0
 public ExpandCastExpressions(TypeSystem typeSystem, JSSpecialIdentifiers js, JSILIdentifier jsil, ITypeInfoSource typeInfo)
 {
     TypeSystem = typeSystem;
     JS         = js;
     JSIL       = jsil;
     TypeInfo   = typeInfo;
 }
예제 #10
0
        public bool Equals(MemberReference lhs, MemberReference rhs, ITypeInfoSource typeInfo)
        {
            if ((lhs == null) || (rhs == null))
            {
                return(lhs == rhs);
            }

            if (lhs == rhs)
            {
                return(true);
            }

            var declaringType = rhs.DeclaringType.Resolve();

            if (declaringType == null)
            {
                return(false);
            }

            var rhsType = new TypeIdentifier(declaringType);

            if (!Type.Equals(rhsType))
            {
                return(false);
            }

            var rhsMember = MemberIdentifier.New(typeInfo, rhs);

            return(Member.Equals(rhsMember, typeInfo));
        }
예제 #11
0
        public static JSExpression FilterInvocationResult(
            MethodReference methodReference, MethodInfo method, 
            JSExpression result, 
            ITypeInfoSource typeInfo, TypeSystem typeSystem
        )
        {
            if (method == null)
                return result;

            var resultType = result.GetActualType(typeSystem);
            var resultIsPackedArray = PackedArrayUtil.IsPackedArrayType(resultType);
            var returnValueAttribute = method.Metadata.GetAttribute("JSIL.Meta.JSPackedArrayReturnValueAttribute");

            if (returnValueAttribute != null) {
                if (TypeUtil.IsOpenType(resultType)) {
                    // FIXME: We need to restrict substitution to when the result type is a generic parameter owned by the invocation...
                    resultType = JSExpression.SubstituteTypeArgs(typeInfo, resultType, methodReference);
                }

                if (!resultIsPackedArray)
                    return JSChangeTypeExpression.New(result, PackedArrayUtil.MakePackedArrayType(resultType, returnValueAttribute.Entries.First().Type), typeSystem);
            }

            return result;
        }
예제 #12
0
        public static MemberIdentifier New(ITypeInfoSource ti, MemberReference mr)
        {
            MethodReference   method;
            PropertyReference property;
            EventReference    evt;
            FieldReference    field;

            if ((method = mr as MethodReference) != null)
            {
                return(new MemberIdentifier(ti, method));
            }
            else if ((field = mr as FieldReference) != null)
            {
                return(new MemberIdentifier(ti, field));
            }
            else if ((property = mr as PropertyReference) != null)
            {
                return(new MemberIdentifier(ti, property));
            }
            else if ((evt = mr as EventReference) != null)
            {
                return(new MemberIdentifier(ti, evt));
            }
            else
            {
                throw new NotImplementedException(String.Format(
                                                      "Unsupported member reference type: {0}",
                                                      mr
                                                      ));
            }
        }
예제 #13
0
        public static JSExpression FilterInvocationResult(
            MethodReference methodReference, MethodInfo method,
            JSExpression result,
            ITypeInfoSource typeInfo, TypeSystem typeSystem
            )
        {
            if (method == null)
            {
                return(result);
            }

            var resultType           = result.GetActualType(typeSystem);
            var resultIsPackedArray  = PackedArrayUtil.IsPackedArrayType(resultType);
            var returnValueAttribute = method.Metadata.GetAttribute("JSIL.Meta.JSPackedArrayReturnValueAttribute");

            if (returnValueAttribute != null)
            {
                if (TypeUtil.IsOpenType(resultType))
                {
                    // FIXME: We need to restrict substitution to when the result type is a generic parameter owned by the invocation...
                    resultType = JSExpression.SubstituteTypeArgs(typeInfo, resultType, methodReference);
                }

                if (!resultIsPackedArray)
                {
                    return(JSChangeTypeExpression.New(result, PackedArrayUtil.MakePackedArrayType(resultType, returnValueAttribute.Entries.First().Type), typeSystem));
                }
            }

            return(result);
        }
예제 #14
0
 public ExpandCastExpressions(TypeSystem typeSystem, JSSpecialIdentifiers js, JSILIdentifier jsil, ITypeInfoSource typeInfo, MethodTypeFactory methodTypeFactory)
 {
     TypeSystem        = typeSystem;
     JS                = js;
     JSIL              = jsil;
     TypeInfo          = typeInfo;
     MethodTypeFactory = methodTypeFactory;
 }
 public SynthesizePropertySetterReturnValues (
     TypeSystem typeSystem, ITypeInfoSource typeInfo,
     IFunctionSource functionSource
 ) {
     TypeSystem = typeSystem;
     TypeInfo = typeInfo;
     FunctionSource = functionSource;
 }
예제 #16
0
 public BaseMethodCacher(ITypeInfoSource typeInfo, TypeDefinition thisType)
 {
     TypeInfo      = typeInfo;
     ThisType      = thisType;
     CachedMethods = new Dictionary <QualifiedMemberIdentifier, CachedMethodRecord>(
         new QualifiedMemberIdentifier.Comparer(TypeInfo)
         );
 }
예제 #17
0
 public JavascriptAstEmitter(JavascriptFormatter output, JSILIdentifier jsil, TypeSystem typeSystem, ITypeInfoSource typeInfo)
 {
     Output     = output;
     JSIL       = jsil;
     TypeSystem = typeSystem;
     TypeInfo   = typeInfo;
     IncludeTypeParens.Push(false);
 }
 public OptimizePropertyMutationAssignments (
     TypeSystem typeSystem, ITypeInfoSource typeInfo,
     IFunctionSource functionSource
 ) {
     TypeSystem = typeSystem;
     TypeInfo = typeInfo;
     FunctionSource = functionSource;
 }
예제 #19
0
        public bool Equals(QualifiedMemberIdentifier rhs, ITypeInfoSource typeInfo)
        {
            if (!Type.Equals(rhs.Type))
            {
                return(false);
            }

            return(Member.Equals(rhs.Member, typeInfo));
        }
예제 #20
0
 public EliminateSingleUseTemporaries (
     QualifiedMemberIdentifier member, IFunctionSource functionSource, 
     TypeSystem typeSystem, Dictionary<string, JSVariable> variables,
     ITypeInfoSource typeInfo
 ) : base (member, functionSource) {
     TypeSystem = typeSystem;
     Variables = variables;
     TypeInfo = typeInfo;
 }
 public SynthesizePropertySetterReturnValues(
     TypeSystem typeSystem, ITypeInfoSource typeInfo,
     IFunctionSource functionSource
     )
 {
     TypeSystem     = typeSystem;
     TypeInfo       = typeInfo;
     FunctionSource = functionSource;
 }
예제 #22
0
        public FunctionCache(ITypeInfoSource typeInfo)
        {
            TypeInfo = typeInfo;
            Comparer = new QualifiedMemberIdentifier.Comparer(typeInfo);

            Cache = new ConcurrentCache <QualifiedMemberIdentifier, Entry>(
                Environment.ProcessorCount, 4096, Comparer
                );
            PendingTransformsQueue = new ConcurrentHashQueue <QualifiedMemberIdentifier>(
                Math.Max(1, Environment.ProcessorCount / 4), 4096, Comparer
                );
            ActiveTransformPipelines = new ConcurrentDictionary <QualifiedMemberIdentifier, FunctionTransformPipeline>(
                Math.Max(1, Environment.ProcessorCount / 4), 128, Comparer
                );
            MethodTypes = new MethodTypeFactory();

            MakeCacheEntry = (id, method) => {
                PendingTransformsQueue.TryEnqueue(id);

                return(new Entry(id, Locks)
                {
                    Info = method.Method,
                    Reference = method.Reference,
                    SecondPass = new FunctionAnalysis2ndPass(this, method.Method)
                });
            };

            MakePopulatedCacheEntry = (id, args) => {
                var result = new JSFunctionExpression(
                    new JSMethod(args.Method, args.Info, MethodTypes),
                    args.Translator.Variables,
                    args.Parameters,
                    args.Body,
                    MethodTypes
                    );

                PendingTransformsQueue.TryEnqueue(id);

                return(new Entry(id, Locks)
                {
                    Info = args.Info,
                    Reference = args.Method,
                    Expression = result,
                    SpecialIdentifiers = args.Translator.SpecialIdentifiers
                });
            };

            MakeNullCacheEntry = (id, args) => {
                return(new Entry(id, Locks)
                {
                    Info = args.Info,
                    Reference = args.Method,
                    Expression = null
                });
            };
        }
예제 #23
0
 public EliminateSingleUseTemporaries(
     QualifiedMemberIdentifier member, IFunctionSource functionSource,
     TypeSystem typeSystem, Dictionary <string, JSVariable> variables,
     ITypeInfoSource typeInfo
     ) : base(member, functionSource)
 {
     TypeSystem = typeSystem;
     Variables  = variables;
     TypeInfo   = typeInfo;
 }
예제 #24
0
 public MethodSignature(
     ITypeInfoSource source, TypeReference returnType, TypeReference[] parameterTypes, string[] genericParameterNames
     )
 {
     TypeInfo              = source;
     ReturnType            = returnType;
     ParameterTypes        = parameterTypes;
     GenericParameterNames = genericParameterNames;
     ID = Interlocked.Increment(ref NextID);
 }
예제 #25
0
        public FunctionCache(ITypeInfoSource typeInfo)
        {
            var comparer = new QualifiedMemberIdentifier.Comparer(typeInfo);

            Cache = new ConcurrentCache <QualifiedMemberIdentifier, Entry>(
                Environment.ProcessorCount, 4096, comparer
                );
            OptimizationQueue = new ConcurrentHashQueue <QualifiedMemberIdentifier>(
                Math.Max(1, Environment.ProcessorCount / 4), 4096, comparer
                );
            MethodTypes = new MethodTypeFactory();

            MakeCacheEntry = (id, method) => {
                OptimizationQueue.TryEnqueue(id);

                return(new Entry {
                    Info = method.Method,
                    Reference = method.Reference,
                    Identifier = id,
                    ParameterNames = new HashSet <string>(from p in method.Method.Parameters select p.Name),
                    SecondPass = new FunctionAnalysis2ndPass(this, method.Method)
                });
            };

            MakePopulatedCacheEntry = (id, args) => {
                var result = new JSFunctionExpression(
                    new JSMethod(args.Method, args.Info, MethodTypes),
                    args.Translator.Variables,
                    args.Parameters,
                    args.Body,
                    MethodTypes
                    );

                OptimizationQueue.TryEnqueue(id);

                return(new Entry {
                    Identifier = id,
                    Info = args.Info,
                    Reference = args.Method,
                    Expression = result,
                    Variables = args.Translator.Variables,
                    ParameterNames = args.Translator.ParameterNames,
                    SpecialIdentifiers = args.Translator.SpecialIdentifiers
                });
            };

            MakeNullCacheEntry = (id, args) => {
                return(new Entry {
                    Identifier = id,
                    Info = args.Info,
                    Reference = args.Method,
                    Expression = null
                });
            };
        }
예제 #26
0
        public FunctionCache(ITypeInfoSource typeInfo)
        {
            var comparer = new QualifiedMemberIdentifier.Comparer(typeInfo);
            Cache = new ConcurrentCache<QualifiedMemberIdentifier, Entry>(
                Environment.ProcessorCount, 4096, comparer
            );
            OptimizationQueue = new ConcurrentHashQueue<QualifiedMemberIdentifier>(
                Math.Max(1, Environment.ProcessorCount / 4), 4096, comparer
            );
            MethodTypes = new MethodTypeFactory();

            MakeCacheEntry = (id, method) => {
                OptimizationQueue.TryEnqueue(id);

                return new Entry {
                    Info = method.Method,
                    Reference = method.Reference,
                    Identifier = id,
                    ParameterNames = new HashSet<string>(from p in method.Method.Parameters select p.Name),
                    SecondPass = new FunctionAnalysis2ndPass(this, method.Method)
                };
            };

            MakePopulatedCacheEntry = (id, args) => {
                var result = new JSFunctionExpression(
                    new JSMethod(args.Method, args.Info, MethodTypes),
                    args.Translator.Variables,
                    args.Parameters,
                    args.Body,
                    MethodTypes
                );

                OptimizationQueue.TryEnqueue(id);

                return new Entry {
                    Identifier = id,
                    Info = args.Info,
                    Reference = args.Method,
                    Expression = result,
                    Variables = args.Translator.Variables,
                    ParameterNames = args.Translator.ParameterNames,
                    SpecialIdentifiers = args.Translator.SpecialIdentifiers
                };
            };

            MakeNullCacheEntry = (id, args) => {
                return new Entry {
                    Identifier = id,
                    Info = args.Info,
                    Reference = args.Method,
                    Expression = null
                };
            };
        }
예제 #27
0
 public FunctionCache(ITypeInfoSource typeInfo)
 {
     var comparer = new QualifiedMemberIdentifier.Comparer(typeInfo);
     Cache = new ConcurrentCache<QualifiedMemberIdentifier, Entry>(
         Environment.ProcessorCount, 4096, comparer
     );
     OptimizationQueue = new ConcurrentHashQueue<QualifiedMemberIdentifier>(
         Math.Max(1, Environment.ProcessorCount / 4), 4096, comparer
     );
     MethodTypes = new MethodTypeFactory();
 }
예제 #28
0
        public MemberIdentifier(ITypeInfoSource ti, EventReference er)
        {
            Type                 = MemberType.Event;
            Name                 = er.Name;
            ReturnType           = er.EventType;
            GenericArgumentCount = 0;
            ParameterTypes       = null;
            ti.CacheProxyNames(er);

            HashCode = Type.GetHashCode() ^ Name.GetHashCode();
        }
예제 #29
0
        public FunctionCache(ITypeInfoSource typeInfo)
        {
            TypeInfo = typeInfo;
            Comparer = new QualifiedMemberIdentifier.Comparer(typeInfo);

            Cache = new ConcurrentCache<QualifiedMemberIdentifier, Entry>(
                Environment.ProcessorCount, 4096, Comparer
            );
            PendingTransformsQueue = new ConcurrentHashQueue<QualifiedMemberIdentifier>(
                Math.Max(1, Environment.ProcessorCount / 4), 4096, Comparer
            );
            ActiveTransformPipelines = new ConcurrentDictionary<QualifiedMemberIdentifier, FunctionTransformPipeline>(
                Math.Max(1, Environment.ProcessorCount / 4), 128, Comparer
            );
            MethodTypes = new MethodTypeFactory();

            MakeCacheEntry = (id, method) => {
                PendingTransformsQueue.TryEnqueue(id);

                return new Entry(id, Locks) {
                    Info = method.Method,
                    Reference = method.Reference,
                    SecondPass = new FunctionAnalysis2ndPass(this, method.Method)
                };
            };

            MakePopulatedCacheEntry = (id, args) => {
                var result = new JSFunctionExpression(
                    new JSMethod(args.Method, args.Info, MethodTypes),
                    args.Translator.Variables,
                    args.Parameters,
                    args.Body,
                    MethodTypes
                );

                PendingTransformsQueue.TryEnqueue(id);

                return new Entry(id, Locks) {
                    Info = args.Info,
                    Reference = args.Method,
                    Expression = result,
                    Variables = args.Translator.Variables,
                    SpecialIdentifiers = args.Translator.SpecialIdentifiers
                };
            };

            MakeNullCacheEntry = (id, args) => {
                return new Entry(id, Locks) {
                    Info = args.Info,
                    Reference = args.Method,
                    Expression = null
                };
            };
        }
예제 #30
0
        public MemberIdentifier(ITypeInfoSource ti, FieldReference fr)
        {
            Type                 = MemberType.Field;
            Name                 = fr.Name;
            ReturnType           = fr.FieldType;
            GenericArgumentCount = 0;
            ParameterTypes       = null;
            ti.CacheProxyNames(fr);

            HashCode = Type.GetHashCode() ^ Name.GetHashCode();
        }
예제 #31
0
파일: FunctionCache.cs 프로젝트: xen2/JSIL
        public FunctionCache(ITypeInfoSource typeInfo)
        {
            var comparer = new QualifiedMemberIdentifier.Comparer(typeInfo);

            Cache = new ConcurrentCache <QualifiedMemberIdentifier, Entry>(
                Environment.ProcessorCount, 4096, comparer
                );
            OptimizationQueue = new ConcurrentHashQueue <QualifiedMemberIdentifier>(
                Math.Max(1, Environment.ProcessorCount / 4), 4096, comparer
                );
            MethodTypes = new MethodTypeFactory();
        }
예제 #32
0
        public JSILIdentifier (
            MethodTypeFactory methodTypes, 
            TypeSystem typeSystem, 
            ITypeInfoSource typeInfo,
            JSSpecialIdentifiers js
        ) {
            TypeSystem = typeSystem;
            TypeInfo = typeInfo;
            MethodTypes = methodTypes;
            JS = js;

            GlobalNamespace = Dot("GlobalNamespace", TypeSystem.Object);
            CopyMembers = Dot("CopyMembers", TypeSystem.Void);
        }
예제 #33
0
        public static TypeReference SubstituteTypeArgs(ITypeInfoSource typeInfo, TypeReference type, MemberReference member)
        {
            var gp = (type as GenericParameter);

            if (gp != null)
            {
                if (gp.Owner.GenericParameterType == GenericParameterType.Method)
                {
                    var ownerIdentifier  = new MemberIdentifier(typeInfo, (MethodReference)gp.Owner);
                    var memberIdentifier = new MemberIdentifier(typeInfo, (dynamic)member);

                    if (!ownerIdentifier.Equals(memberIdentifier, typeInfo))
                    {
                        return(type);
                    }

                    if (!(member is GenericInstanceMethod))
                    {
                        return(type);
                    }
                }
                else
                {
                    var declaringType = member.DeclaringType.Resolve();
                    // FIXME: Is this right?
                    if (declaringType == null)
                    {
                        return(type);
                    }

                    var ownerResolved = ((TypeReference)gp.Owner).Resolve();
                    // FIXME: Is this right?
                    if (ownerResolved == null)
                    {
                        return(type);
                    }

                    var ownerIdentifier = new TypeIdentifier(ownerResolved);
                    var typeIdentifier  = new TypeIdentifier(declaringType);

                    if (!ownerIdentifier.Equals(typeIdentifier))
                    {
                        return(type);
                    }
                }
            }

            return(TypeAnalysis.SubstituteTypeArgs(type, member));
        }
예제 #34
0
        public JSILIdentifier(
            MethodTypeFactory methodTypes,
            TypeSystem typeSystem,
            ITypeInfoSource typeInfo,
            JSSpecialIdentifiers js
            )
        {
            TypeSystem  = typeSystem;
            TypeInfo    = typeInfo;
            MethodTypes = methodTypes;
            JS          = js;

            GlobalNamespace = Dot("GlobalNamespace", TypeSystem.Object);
            CopyMembers     = Dot("CopyMembers", TypeSystem.Void);
        }
예제 #35
0
        public JavascriptFormatter(
            TextWriter output, ITypeInfoSource typeInfo,
            AssemblyManifest manifest, AssemblyDefinition assembly,
            Configuration configuration, bool stubbed
            )
        {
            Output        = output;
            TypeInfo      = typeInfo;
            Manifest      = manifest;
            Assembly      = assembly;
            Configuration = configuration;
            Stubbed       = stubbed;

            PrivateToken = Manifest.GetPrivateToken(assembly);
            Manifest.AssignIdentifiers();
        }
예제 #36
0
        public MemberIdentifier(ITypeInfoSource ti, FieldReference fr)
        {
            Type                 = MemberType.Field;
            Name                 = fr.Name;
            ReturnType           = fr.FieldType;
            GenericArgumentCount = 0;
            ParameterTypes       = null;
            ti.CacheProxyNames(fr);

            var resolved = fr.Resolve();

            if (resolved != null)
            {
                IsStatic = resolved.IsStatic;
            }
            else
            {
                // FIXME
                IsStatic = false;
            }

            HashCode = Type.GetHashCode() ^ Name.GetHashCode();
        }
예제 #37
0
        public static TypeReference SubstituteTypeArgs(ITypeInfoSource typeInfo, TypeReference type, MemberReference member)
        {
            var gp = (type as GenericParameter);

            if (gp != null)
            {
                if (gp.Owner.GenericParameterType == GenericParameterType.Method)
                {
                    var ownerIdentifier  = new MemberIdentifier(typeInfo, gp.Owner as MethodReference);
                    var memberIdentifier = new MemberIdentifier(typeInfo, member as dynamic);

                    if (!ownerIdentifier.Equals(memberIdentifier, typeInfo))
                    {
                        return(type);
                    }

                    if (!(member is GenericInstanceMethod))
                    {
                        return(type);
                    }
                }
                else
                {
                    var declaringType   = member.DeclaringType;
                    var ownerIdentifier = new TypeIdentifier(gp.Owner as TypeReference);
                    var typeIdentifier  = new TypeIdentifier(declaringType);

                    if (!ownerIdentifier.Equals(typeIdentifier))
                    {
                        return(type);
                    }
                }
            }

            return(TypeAnalysis.SubstituteTypeArgs(type, member));
        }
 public EliminatePointlessFinallyBlocks(TypeSystem typeSystem, ITypeInfoSource typeInfo, IFunctionSource functionSource)
 {
     TypeSystem = typeSystem;
     TypeInfo = typeInfo;
     FunctionSource = functionSource;
 }
예제 #39
0
 public Comparer(ITypeInfoSource typeInfo)
 {
     TypeInfo = typeInfo;
 }
예제 #40
0
        public static bool TypesAreEqual(ITypeInfoSource typeInfo, TypeReference lhs, TypeReference rhs)
        {
            bool shallowMatch;

            if (lhs == rhs)
            {
                return(true);
            }
            else if (lhs == null || rhs == null)
            {
                return(false);
            }
            else if (TypeUtil.TypesAreTriviallyEqual(lhs, rhs, out shallowMatch))
            {
                return(true);
            }

            var lhsReference = lhs as ByReferenceType;
            var rhsReference = rhs as ByReferenceType;

            if ((lhsReference != null) || (rhsReference != null))
            {
                if ((lhsReference == null) || (rhsReference == null))
                {
                    return(false);
                }

                return(TypesAreEqual(typeInfo, lhsReference.ElementType, rhsReference.ElementType));
            }

            var lhsArray = lhs as ArrayType;
            var rhsArray = rhs as ArrayType;

            if ((lhsArray != null) || (rhsArray != null))
            {
                if ((lhsArray == null) || (rhsArray == null))
                {
                    return(false);
                }

                return(TypesAreEqual(typeInfo, lhsArray.ElementType, rhsArray.ElementType));
            }

            var lhsGit = lhs as GenericInstanceType;
            var rhsGit = rhs as GenericInstanceType;

            if ((lhsGit != null) && (rhsGit != null))
            {
                if (lhsGit.GenericArguments.Count != rhsGit.GenericArguments.Count)
                {
                    return(false);
                }

                if (!TypesAreEqual(typeInfo, lhsGit.ElementType, rhsGit.ElementType))
                {
                    return(false);
                }

                using (var eLeft = lhsGit.GenericArguments.GetEnumerator())
                    using (var eRight = rhsGit.GenericArguments.GetEnumerator())
                        while (eLeft.MoveNext() && eRight.MoveNext())
                        {
                            if (!TypesAreEqual(typeInfo, eLeft.Current, eRight.Current))
                            {
                                return(false);
                            }
                        }

                return(true);
            }

            string[] proxyTargets;
            if (
                typeInfo.TryGetProxyNames(lhs, out proxyTargets) &&
                (proxyTargets != null) &&
                proxyTargets.Contains(rhs.FullName)
                )
            {
                return(true);
            }
            else if (
                typeInfo.TryGetProxyNames(rhs, out proxyTargets) &&
                (proxyTargets != null) &&
                proxyTargets.Contains(lhs.FullName)
                )
            {
                return(true);
            }

            if (IsAnyType(lhs) || IsAnyType(rhs))
            {
                return(true);
            }

            return(TypeUtil.TypesAreEqual(lhs, rhs));
        }
예제 #41
0
        public static bool TypesAreAssignable(ITypeInfoSource typeInfo, TypeReference target, TypeReference source)
        {
            if ((target == null) || (source == null))
            {
                return(false);
            }

            // All values are assignable to object
            if (target.FullName == "System.Object")
            {
                return(true);
            }

            int targetDepth, sourceDepth;
            var targetDerefed = FullyDereferenceType(target, out targetDepth);
            var sourceDerefed = FullyDereferenceType(source, out sourceDepth);

            if (TypesAreEqual(targetDerefed, sourceDerefed))
            {
                if (targetDepth == sourceDepth)
                {
                    return(true);
                }
            }

            // HACK: System.Array and T[] do not implement IEnumerable<T>
            if (
                source.IsArray &&
                (target.Namespace == "System.Collections.Generic")
                )
            {
                var targetGit = target as GenericInstanceType;
                if (
                    (targetGit != null) &&
                    (targetGit.Name == "IEnumerable`1") &&
                    (targetGit.GenericArguments.FirstOrDefault() == ((ArrayType)source).ElementType)
                    )
                {
                    return(true);
                }
            }

            if (IsPointer(source))
            {
                // HACK: The .NET type system treats pointers and native ints as assignable to each other
                if (IsNativeInteger(target))
                {
                    return(true);
                }

                // HACK: T& = T* (but not T* = T& ...?)
                if (
                    target.IsByReference &&
                    TypesAreEqual(targetDerefed, source.GetElementType(), true)
                    )
                {
                    return(true);
                }

                // HACK
                if (IsIntegral(target))
                {
                    return(false);
                }
            }

            var cacheKey = new Tuple <string, string>(target.FullName, source.FullName);

            return(typeInfo.AssignabilityCache.GetOrCreate(
                       cacheKey, (key) => {
                bool result = false;

                var dSource = GetTypeDefinition(source);

                if (TypeInBases(source, target, false))
                {
                    result = true;
                }
                else if (dSource == null)
                {
                    result = false;
                }
                else if (TypesAreEqual(target, dSource))
                {
                    result = true;
                }
                else if ((dSource.BaseType != null) && TypesAreAssignable(typeInfo, target, dSource.BaseType))
                {
                    result = true;
                }
                else
                {
                    foreach (var iface in dSource.Interfaces)
                    {
                        if (TypesAreAssignable(typeInfo, target, iface))
                        {
                            result = true;
                            break;
                        }
                    }
                }

                return result;
            }
                       ));
        }
 public ConvertPropertyAccessesToInvocations (TypeSystem typeSystem, ITypeInfoSource typeInfo) {
     TypeSystem = typeSystem;
     TypeInfo = typeInfo;
 }
예제 #43
0
 public SpecialIdentifiers (MethodTypeFactory methodTypes, TypeSystem typeSystem, ITypeInfoSource typeInfo) {
     TypeSystem = typeSystem;
     JS = new JSSpecialIdentifiers(methodTypes, typeSystem);
     CLR = new CLRSpecialIdentifiers(typeSystem);
     JSIL = new JSILIdentifier(methodTypes, typeSystem, typeInfo, JS);
 }
 public SynthesizePropertySetterReturnValues (TypeSystem typeSystem, ITypeInfoSource typeInfo) {
     TypeSystem = typeSystem;
     TypeInfo = typeInfo;
 }
 public EliminatePointlessFinallyBlocks (QualifiedMemberIdentifier member, IFunctionSource functionSource, TypeSystem typeSystem, ITypeInfoSource typeInfo)
     : base (member, functionSource) {
     TypeSystem = typeSystem;
     TypeInfo = typeInfo;
 }
예제 #46
0
        public static bool TypesAreAssignable(ITypeInfoSource typeInfo, TypeReference target, TypeReference source)
        {
            if ((target == null) || (source == null))
                return false;

            // All values are assignable to object
            if (target.FullName == "System.Object")
                return true;

            int targetDepth, sourceDepth;
            if (TypesAreEqual(FullyDereferenceType(target, out targetDepth), FullyDereferenceType(source, out sourceDepth))) {
                if (targetDepth == sourceDepth)
                    return true;
            }

            // HACK: System.Array and T[] do not implement IEnumerable<T>
            if (
                source.IsArray &&
                (target.Namespace == "System.Collections.Generic")
            ) {
                var targetGit = target as GenericInstanceType;
                if (
                    (targetGit != null) &&
                    (targetGit.Name == "IEnumerable`1") &&
                    (targetGit.GenericArguments.FirstOrDefault() == source.GetElementType())
                )
                    return true;
            }

            // HACK: The .NET type system treats pointers and ints as assignable to each other
            if (IsIntegral(target) && IsPointer(source))
                return true;

            var cacheKey = new Tuple<string, string>(target.FullName, source.FullName);
            return typeInfo.AssignabilityCache.GetOrCreate(
                cacheKey, (key) => {
                    bool result = false;

                    var dSource = GetTypeDefinition(source);

                    if (TypeInBases(source, target, false))
                        result = true;
                    else if (dSource == null)
                        result = false;
                    else if (TypesAreEqual(target, dSource))
                        result = true;
                    else if ((dSource.BaseType != null) && TypesAreAssignable(typeInfo, target, dSource.BaseType))
                        result = true;
                    else {
                        foreach (var iface in dSource.Interfaces) {
                            if (TypesAreAssignable(typeInfo, target, iface)) {
                                result = true;
                                break;
                            }
                        }
                    }

                    return result;
                }
            );
        }
 public OptimizePropertyMutationAssignments (TypeSystem typeSystem, ITypeInfoSource typeInfo) {
     TypeSystem = typeSystem;
     TypeInfo = typeInfo;
 }
 public IntroduceVariableDeclarations(IDictionary<string, JSVariable> variables, ITypeInfoSource typeInfo)
 {
     Variables = variables;
     TypeInfo = typeInfo;
 }