Exemple #1
0
        internal void Init(StatementSyntax syntax)
        {
            IsLoop        = true;
            IsIgnoreBreak = false;
            ContinueAnalysis cont = new ContinueAnalysis();

            cont.Visit(syntax);
            HaveContinue     = cont.ContinueCount > 0;
            HaveBreak        = cont.BreakCount > 0;
            BreakFlagVarName = string.Format("__compiler_continue_{0}", CsLuaTranslater.GetSourcePosForVar(syntax));
        }
Exemple #2
0
        internal static string CalcInvokeTarget(string classKey, CsLuaTranslater cs2lua, ExpressionSyntax exp, SemanticModel model)
        {
            TryAddExternEnum(classKey, exp, model);
            string ckey = classKey;

            if (classKey == SymbolTable.PrefixExternClassName("System.Enum"))
            {
                var oper = model.GetOperation(exp);
                if (oper.Type.TypeKind == TypeKind.Enum)
                {
                    var ci = cs2lua.GetCurClassInfo();
                    ci.AddReference(oper.Type);

                    ckey = ClassInfo.GetFullName(oper.Type);
                }
            }
            return(ckey);
        }
Exemple #3
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(")");
        }
Exemple #4
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(")");
        }