Exemple #1
0
        public static void CheckAddInvocation(ICSharpCode.NRefactory.Semantics.MemberResolveResult res, string methodName)
        {
            var    member       = res.Member;
            string typeFullName = SkJs.GetEntityJsName(member.DeclaringType);
            bool   exported     = Sk.IsJsExported(member);

            if (!exported || typeDefaultIsExported.Contains(typeFullName))
            {
                InvocationLocation Loc = null;
                var firstNode          = res.GetFirstNode();
                if (firstNode != null)
                {
                    Loc = new InvocationLocation {
                        FileName = firstNode.GetFileName(), Line = firstNode.StartLocation.Line
                    }
                }
                ;

                if (Loc != null)
                {
                    if (member.IsStatic)
                    {
                        methodName = "Static_" + methodName;
                    }
                    AddInvocation(typeFullName, methodName, Loc);
                }
            }
        }
Exemple #2
0
        public static JsMemberExpression EntityMethodToJsFunctionRef(IMethod me)
        {
            var ownerType = me.GetDeclaringTypeDefinition();

            if (Sk.IsGlobalMethod(me))
            {
                var member = Js.Member(SkJs.GetEntityJsName(me));
                return(member);
            }
            else
            {
                var member = SkJs.EntityToMember(ownerType);
                if (!me.IsStatic)
                {
                    if (Sk.IsNativeType(ownerType))
                    {
                        member = member.Member("prototype");
                    }
                    else
                    {
                        member = member.Member("commonPrototype");
                    }
                }
                member = member.Member(SkJs.GetEntityJsName(me));
                return(member);
            }
        }
Exemple #3
0
 static string GetMethodPrefix(IMethod me)
 {
     if (me.IsExplicitInterfaceImplementation)
     {
         return(SkJs.GetEntityJsName(me.ImplementedInterfaceMembers.First().DeclaringType, true) + "$$"); //TODO: impl. of ns1.IName and ns2.IName (same name) will not work. Full path should added.
     }
     if (me.DeclaringType.Kind == TypeKind.Interface)
     {
         return(SkJs.GetEntityJsName(me.DeclaringType, true) + "$$");
     }
     return("");
 }
Exemple #4
0
        public static void AddYieldReturn(ICSharpCode.NRefactory.CSharp.YieldReturnStatement node)
        {
            var result = node.Expression.Resolve() as ICSharpCode.NRefactory.Semantics.ConversionResolveResult;

            try
            {
                if (result != null)
                {
                    string k;
                    if (result.Input.Type.Kind == TypeKind.Null)
                    {
                        k = "null";
                    }
                    else
                    {
                        k = SkJs.GetEntityJsName(result.Input.Type);
                    }

                    InvocationLocation loc = new InvocationLocation {
                        FileName = node.GetFileName(), Line = node.StartLocation.Line
                    };
                    if (!YieldType2Location.ContainsKey(k))
                    {
                        YieldType2Location.Add(k, new List <InvocationLocation> {
                            loc
                        });
                    }
                    else
                    {
                        YieldType2Location[k].Add(loc);
                    }
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
            }
        }
Exemple #5
0
        public static string GetEntityJsName(IMethod me2)
        {
            IMethod me;

            if (me2.IsConstructor && me2.DeclaringType.Kind == TypeKind.TypeParameter)//happens when invoking new T();
            {
                me = me2;
            }
            else
            {
                me = (IMethod)me2.MemberDefinition;
            }
            var name = me.Name;

            if (name != null)
            {
                if (name == ".ctor")
                {
                    name = "ctor";
                }
                else if (name == ".cctor")
                {
                    name = "cctor";
                }
            }

            var att = me.GetMetadata <JsMethodAttribute>(true);

            if (att != null && att.Name != null)
            {
                name = att.Name;
            }
            else if (me.DeclaringType.Kind == TypeKind.Delegate && me.Name == "Invoke")
            {
                return("");
            }
            else if (me.DeclaringType.IsGenericMethodArgument()) //happens when invoking new T() in method MyMethod<T>();
            {
                name = GetEntityJsName(me.DeclaringType);
            }
            //else if (me.DeclaringType.IsGenericTypeParameter()) //happens when invoking new T() in class List<T>;
            //{
            //    name = EntityTypeRefToMember(me.DeclaringType);
            //}
            else
            {
                var owner = me.GetOwner();
                if (owner != null && owner is IProperty)
                {
                    var pe = (IProperty)owner;
                    if (pe.SymbolKind == SymbolKind.Indexer && Sk.UseNativeIndexer(pe))
                    {
                        return("");
                    }
                    name = GetEntityJsName(pe);
                    if (me.IsGetter())
                    {
                        name = "get_" + name;
                    }
                    else
                    {
                        name = "set_" + name;
                    }
                }
            }

            // 前面有地方被统一修改
            if (me.DeclaringType.FullName == "System.Enum")
            {
                if (name == "ToString" || name == "toString")
                {
                    name = "System.Enum.GetName";
                }
            }

            if (Sk.NewInterfaceImplementation)
            {
                name = SkJs.GetMethodPrefix(me) + name;
            }

            if (!Sk.UseNativeOverloads(me))
            {
                if (me.TypeParameters.IsNotNullOrEmpty())
                {
                    name += "$" + me.TypeParameters.Count;
                }
                name += SkJs.GetOverloadedMethodSuffix(me);
            }
            return(name);
        }