コード例 #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
ファイル: ExpandCastExpressions.cs プロジェクト: Don191/JSIL
 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();
        }
コード例 #8
0
            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
ファイル: PackedStructArray.cs プロジェクト: kboga/JSIL
        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
ファイル: ExpandCastExpressions.cs プロジェクト: ticuth/JSIL
 public ExpandCastExpressions(TypeSystem typeSystem, JSSpecialIdentifiers js, JSILIdentifier jsil, ITypeInfoSource typeInfo, MethodTypeFactory methodTypeFactory)
 {
     TypeSystem        = typeSystem;
     JS                = js;
     JSIL              = jsil;
     TypeInfo          = typeInfo;
     MethodTypeFactory = methodTypeFactory;
 }
コード例 #15
0
 public SynthesizePropertySetterReturnValues (
     TypeSystem typeSystem, ITypeInfoSource typeInfo,
     IFunctionSource functionSource
 ) {
     TypeSystem = typeSystem;
     TypeInfo = typeInfo;
     FunctionSource = functionSource;
 }
コード例 #16
0
ファイル: CacheBaseMethods.cs プロジェクト: wdstest/SharpJS
 public BaseMethodCacher(ITypeInfoSource typeInfo, TypeDefinition thisType)
 {
     TypeInfo      = typeInfo;
     ThisType      = thisType;
     CachedMethods = new Dictionary <QualifiedMemberIdentifier, CachedMethodRecord>(
         new QualifiedMemberIdentifier.Comparer(TypeInfo)
         );
 }
コード例 #17
0
ファイル: JavascriptAstEmitter.cs プロジェクト: xen2/JSIL
 public JavascriptAstEmitter(JavascriptFormatter output, JSILIdentifier jsil, TypeSystem typeSystem, ITypeInfoSource typeInfo)
 {
     Output     = output;
     JSIL       = jsil;
     TypeSystem = typeSystem;
     TypeInfo   = typeInfo;
     IncludeTypeParens.Push(false);
 }
コード例 #18
0
 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;
 }
コード例 #21
0
 public SynthesizePropertySetterReturnValues(
     TypeSystem typeSystem, ITypeInfoSource typeInfo,
     IFunctionSource functionSource
     )
 {
     TypeSystem     = typeSystem;
     TypeInfo       = typeInfo;
     FunctionSource = functionSource;
 }
コード例 #22
0
ファイル: FunctionCache.cs プロジェクト: dosh1974/JSIL
        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
ファイル: FunctionCache.cs プロジェクト: carcer/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();

            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
ファイル: FunctionCache.cs プロジェクト: robterrell/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();
 }
コード例 #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
ファイル: FunctionCache.cs プロジェクト: Ocelloid/JSIL
        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
ファイル: SpecialIdentifiers.cs プロジェクト: RainsSoft/JSIL
        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
ファイル: JSNodeTypes.cs プロジェクト: wdstest/SharpJS
        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));
        }
コード例 #38
0
 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
ファイル: TypeUtil.cs プロジェクト: VictorHenriquez/JSIL
        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;
            }
                       ));
        }
コード例 #42
0
 public ConvertPropertyAccessesToInvocations (TypeSystem typeSystem, ITypeInfoSource typeInfo) {
     TypeSystem = typeSystem;
     TypeInfo = typeInfo;
 }
コード例 #43
0
ファイル: SpecialIdentifiers.cs プロジェクト: RainsSoft/JSIL
 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);
 }
コード例 #44
0
 public SynthesizePropertySetterReturnValues (TypeSystem typeSystem, ITypeInfoSource typeInfo) {
     TypeSystem = typeSystem;
     TypeInfo = typeInfo;
 }
コード例 #45
0
 public EliminatePointlessFinallyBlocks (QualifiedMemberIdentifier member, IFunctionSource functionSource, TypeSystem typeSystem, ITypeInfoSource typeInfo)
     : base (member, functionSource) {
     TypeSystem = typeSystem;
     TypeInfo = typeInfo;
 }
コード例 #46
0
ファイル: TypeUtil.cs プロジェクト: simon-heinen/JSIL
        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;
                }
            );
        }
コード例 #47
0
 public OptimizePropertyMutationAssignments (TypeSystem typeSystem, ITypeInfoSource typeInfo) {
     TypeSystem = typeSystem;
     TypeInfo = typeInfo;
 }
コード例 #48
0
 public IntroduceVariableDeclarations(IDictionary<string, JSVariable> variables, ITypeInfoSource typeInfo)
 {
     Variables = variables;
     TypeInfo = typeInfo;
 }