Beispiel #1
0
        internal void OutputInvocation(StringBuilder codeBuilder, CsLuaTranslater cs2lua, ExpressionSyntax exp, bool isMemberAccess, SemanticModel model, SyntaxNode node)
        {
            IMethodSymbol sym    = MethodSymbol;
            string        mname  = cs2lua.NameMangling(sym);
            string        prestr = string.Empty;

            if (isMemberAccess)
            {
                string fnOfIntf = "nil";
                bool   isExplicitInterfaceInvoke = cs2lua.CheckExplicitInterfaceAccess(sym, ref fnOfIntf);
                if (isExplicitInterfaceInvoke)
                {
                    codeBuilder.Append("invokewithinterface(");
                    cs2lua.VisitExpressionSyntax(exp);
                    codeBuilder.Append(", ");
                    codeBuilder.AppendFormat("{0}, \"{1}\"", fnOfIntf, mname);
                    prestr = ", ";
                }
                else
                {
                    if (IsBasicValueMethod)
                    {
                        codeBuilder.Append("invokeforbasicvalue(");
                        cs2lua.VisitExpressionSyntax(exp);
                        codeBuilder.Append(", ");
                        codeBuilder.AppendFormat("{0}, \"{1}\"", ClassKey, mname);
                        prestr = ", ";
                    }
                    else
                    {
                        if (sym.IsStatic)
                        {
                            codeBuilder.Append(ClassKey);
                            codeBuilder.Append(".");
                        }
                        else
                        {
                            cs2lua.VisitExpressionSyntax(exp);
                            codeBuilder.Append(":");
                        }
                        codeBuilder.Append(mname);
                        codeBuilder.Append("(");
                    }
                }
            }
            else
            {
                if (sym.MethodKind == MethodKind.DelegateInvoke)
                {
                    cs2lua.VisitExpressionSyntax(exp);
                }
                else if (sym.IsStatic)
                {
                    codeBuilder.AppendFormat("{0}.", ClassKey);
                    codeBuilder.Append(mname);
                }
                else
                {
                    codeBuilder.Append("this:");
                    codeBuilder.Append(mname);
                }
                codeBuilder.Append("(");
            }
            if (Args.Count + DefaultValueArgs.Count + GenericTypeArgs.Count > 0)
            {
                codeBuilder.Append(prestr);
            }
            bool useTypeNameString = false;

            if (IsComponentGetOrAdd && SymbolTable.LuaComponentByString)
            {
                var tArgs = sym.TypeArguments;
                if (tArgs.Length > 0 && tArgs[0].ContainingAssembly == AssemblySymbol)
                {
                    useTypeNameString = true;
                }
            }
            cs2lua.OutputArgumentList(Args, DefaultValueArgs, GenericTypeArgs, ArrayToParams, useTypeNameString, node);
            codeBuilder.Append(")");
        }
Beispiel #2
0
        internal void OutputInvocation(StringBuilder codeBuilder, CsLuaTranslater cs2lua, ExpressionSyntax exp, bool isMemberAccess, SemanticModel model, SyntaxNode node)
        {
            IMethodSymbol sym    = MethodSymbol;
            string        mname  = cs2lua.NameMangling(IsExtensionMethod && null != sym.ReducedFrom ? sym.ReducedFrom : sym);
            string        prestr = string.Empty;

            if (isMemberAccess)
            {
                string fnOfIntf = "nil";
                bool   isExplicitInterfaceInvoke = cs2lua.CheckExplicitInterfaceAccess(sym, ref fnOfIntf);
                if (sym.MethodKind == MethodKind.DelegateInvoke)
                {
                    var memberAccess = node as MemberAccessExpressionSyntax;
                    if (null != memberAccess)
                    {
                        cs2lua.OutputExpressionSyntax(exp);
                        codeBuilder.Append(".");
                        codeBuilder.Append(memberAccess.Name);
                        codeBuilder.Append("(");
                    }
                    else
                    {
                        //error;
                    }
                }
                else if (isExplicitInterfaceInvoke)
                {
                    codeBuilder.Append("invokewithinterface(");
                    cs2lua.OutputExpressionSyntax(exp);
                    codeBuilder.Append(", ");
                    codeBuilder.AppendFormat("{0}, \"{1}\"", fnOfIntf, mname);
                    prestr = ", ";
                }
                else if (IsExtensionMethod)
                {
                    codeBuilder.Append(ClassKey);
                    codeBuilder.Append(".");
                    codeBuilder.Append(mname);
                    codeBuilder.Append("(");
                }
                else if (IsBasicValueMethod)
                {
                    string ckey = CalcInvokeTarget(ClassKey, cs2lua, exp, model);
                    codeBuilder.Append("invokeforbasicvalue(");
                    cs2lua.OutputExpressionSyntax(exp);
                    codeBuilder.Append(", ");
                    codeBuilder.AppendFormat("{0}, {1}, \"{2}\"", ClassKey == SymbolTable.PrefixExternClassName("System.Enum") ? "true" : "false", ckey, mname);
                    prestr = ", ";
                }
                else if (IsArrayStaticMethod)
                {
                    codeBuilder.Append("invokearraystaticmethod(");
                    if (null == FirstRefArray)
                    {
                        codeBuilder.Append("nil, ");
                    }
                    else
                    {
                        cs2lua.OutputExpressionSyntax(FirstRefArray);
                        codeBuilder.Append(", ");
                    }
                    if (null == SecondRefArray)
                    {
                        codeBuilder.Append("nil, ");
                    }
                    else
                    {
                        cs2lua.OutputExpressionSyntax(SecondRefArray);
                        codeBuilder.Append(", ");
                    }
                    codeBuilder.AppendFormat("\"{0}\"", mname);
                    prestr = ", ";
                }
                else
                {
                    if (sym.IsStatic)
                    {
                        codeBuilder.Append(ClassKey);
                        codeBuilder.Append(".");
                    }
                    else
                    {
                        cs2lua.OutputExpressionSyntax(exp);
                        codeBuilder.Append(":");
                    }
                    codeBuilder.Append(mname);
                    codeBuilder.Append("(");
                }
            }
            else
            {
                if (sym.MethodKind == MethodKind.DelegateInvoke)
                {
                    cs2lua.OutputExpressionSyntax(exp);
                }
                else if (sym.IsStatic)
                {
                    codeBuilder.AppendFormat("{0}.", ClassKey);
                    codeBuilder.Append(mname);
                }
                else
                {
                    codeBuilder.Append("this:");
                    codeBuilder.Append(mname);
                }
                codeBuilder.Append("(");
            }
            if (Args.Count + DefaultValueArgs.Count + GenericTypeArgs.Count > 0)
            {
                codeBuilder.Append(prestr);
            }
            bool useTypeNameString = false;

            if (IsComponentGetOrAdd && SymbolTable.LuaComponentByString)
            {
                var tArgs = sym.TypeArguments;
                if (tArgs.Length > 0 && SymbolTable.Instance.IsCs2LuaSymbol(tArgs[0]))
                {
                    useTypeNameString = true;
                }
            }
            if (IsExtensionMethod)
            {
                var args = new List <ExpressionSyntax>();
                args.Add(exp);
                args.AddRange(Args);
                cs2lua.OutputArgumentList(args, DefaultValueArgs, GenericTypeArgs, ArrayToParams, useTypeNameString, node, ArgConversions.ToArray());
            }
            else
            {
                cs2lua.OutputArgumentList(Args, DefaultValueArgs, GenericTypeArgs, ArrayToParams, useTypeNameString, node, ArgConversions.ToArray());
            }
            codeBuilder.Append(")");
        }