コード例 #1
0
 private void AddStaticAssignmentNames(LuaBlockSyntax body)
 {
     if (staticAssignmentNames_.Count > 0)
     {
         var assignment = new LuaMultipleAssignmentExpressionSyntax();
         foreach (var identifierName in staticAssignmentNames_)
         {
             assignment.Lefts.Add(LuaIdentifierNameSyntax.This.MemberAccess(identifierName));
             assignment.Rights.Add(identifierName);
         }
         body.Statements.Add(assignment);
     }
 }
コード例 #2
0
        private void AddPropertyOrEvent(bool isProperty, LuaIdentifierNameSyntax name, LuaIdentifierNameSyntax innerName, LuaExpressionSyntax value, bool isImmutable, bool isStatic, bool isPrivate)
        {
            LuaIdentifierNameSyntax initMethodIdentifier;
            LuaPropertyOrEventIdentifierNameSyntax get, set;

            if (isProperty)
            {
                initMethodIdentifier = LuaIdentifierNameSyntax.Property;
                get = new LuaPropertyOrEventIdentifierNameSyntax(true, true, name);
                set = new LuaPropertyOrEventIdentifierNameSyntax(true, false, name);
            }
            else
            {
                initMethodIdentifier = LuaIdentifierNameSyntax.Event;
                get = new LuaPropertyOrEventIdentifierNameSyntax(false, true, name);
                set = new LuaPropertyOrEventIdentifierNameSyntax(false, false, name);
            }

            local_.Variables.Add(get);
            local_.Variables.Add(set);
            LuaMultipleAssignmentExpressionSyntax assignment = new LuaMultipleAssignmentExpressionSyntax();

            assignment.Lefts.Add(get);
            assignment.Lefts.Add(set);
            LuaInvocationExpressionSyntax invocation = new LuaInvocationExpressionSyntax(initMethodIdentifier);

            invocation.AddArgument(new LuaStringLiteralExpressionSyntax(innerName));
            assignment.Rights.Add(invocation);
            methodList_.Statements.Add(new LuaExpressionStatementSyntax(assignment));

            if (value != null)
            {
                if (isStatic)
                {
                    if (isImmutable)
                    {
                        AddResultTable(name, value);
                    }
                    else
                    {
                        LuaAssignmentExpressionSyntax thisAssignment = new LuaAssignmentExpressionSyntax(name, value);
                        staticLazyStatements_.Add(new LuaExpressionStatementSyntax(thisAssignment));
                    }
                }
                else
                {
                    if (isImmutable)
                    {
                        AddResultTable(name, value);
                    }
                    else
                    {
                        AddInitFiled(name, value);
                    }
                }
            }

            if (!isPrivate)
            {
                AddResultTable(get);
                AddResultTable(set);
            }
        }
コード例 #3
0
        private (LuaPropertyOrEventIdentifierNameSyntax, LuaPropertyOrEventIdentifierNameSyntax) AddPropertyOrEvent(bool isProperty, LuaIdentifierNameSyntax name, LuaIdentifierNameSyntax innerName, LuaExpressionSyntax value, bool isImmutable, bool isStatic, bool isPrivate, LuaExpressionSyntax typeExpression, List <LuaStatementSyntax> statements, bool isGetOnly = false)
        {
            LuaPropertyOrEventIdentifierNameSyntax get, set;

            if (isProperty)
            {
                get = new LuaPropertyOrEventIdentifierNameSyntax(true, true, name);
                set = isGetOnly ? null : new LuaPropertyOrEventIdentifierNameSyntax(true, false, name);
            }
            else
            {
                get = new LuaPropertyOrEventIdentifierNameSyntax(false, true, name);
                set = new LuaPropertyOrEventIdentifierNameSyntax(false, false, name);
            }

            local_.Variables.Add(get);
            if (set != null)
            {
                local_.Variables.Add(set);
            }
            if (!isStatic)
            {
                var initMethodIdentifier = isProperty ? LuaIdentifierNameSyntax.Property : LuaIdentifierNameSyntax.Event;
                var assignment           = new LuaMultipleAssignmentExpressionSyntax();
                assignment.Lefts.Add(get);
                if (set != null)
                {
                    assignment.Lefts.Add(set);
                }
                var invocation = new LuaInvocationExpressionSyntax(initMethodIdentifier, new LuaStringLiteralExpressionSyntax(innerName));
                if (set == null)
                {
                    invocation.AddArgument(LuaIdentifierNameSyntax.True);
                }
                assignment.Rights.Add(invocation);
                methodList_.Statements.Add(assignment);
            }
            else
            {
                var memberAccess = typeExpression.MemberAccess(innerName);
                var getFunction  = new LuaFunctionExpressionSyntax();
                var setFunction  = new LuaFunctionExpressionSyntax();
                if (isProperty)
                {
                    getFunction.AddStatement(new LuaReturnStatementSyntax(memberAccess));
                    setFunction.AddParameter(LuaIdentifierNameSyntax.Value);
                    setFunction.AddStatement(memberAccess.Assignment(LuaIdentifierNameSyntax.Value));
                }
                else
                {
                    getFunction.AddParameter(LuaIdentifierNameSyntax.Value);
                    var getAssignment = memberAccess.Assignment(memberAccess.Binary(Tokens.Plus, LuaIdentifierNameSyntax.Value));
                    getFunction.AddStatement(getAssignment);
                    setFunction.AddParameter(LuaIdentifierNameSyntax.Value);
                    var setAssignment = memberAccess.Assignment(memberAccess.Binary(Tokens.Sub, LuaIdentifierNameSyntax.Value));
                    setFunction.AddStatement(setAssignment);
                }
                methodList_.Statements.Add(get.Assignment(getFunction));
                if (set != null)
                {
                    methodList_.Statements.Add(set.Assignment(setFunction));
                }
            }

            if (value != null)
            {
                if (isStatic)
                {
                    if (isImmutable)
                    {
                        AddResultTable(innerName, value);
                    }
                    else
                    {
                        if (statements != null)
                        {
                            staticInitStatements_.AddRange(statements);
                        }
                        staticInitStatements_.Add(LuaIdentifierNameSyntax.This.MemberAccess(innerName).Assignment(value));
                    }
                }
                else
                {
                    if (isImmutable)
                    {
                        AddResultTable(innerName, value);
                    }
                    else
                    {
                        if (statements != null)
                        {
                            initStatements_.AddRange(statements);
                        }
                        AddInitFiled(innerName, value);
                    }
                }
            }

            if (!isPrivate)
            {
                AddResultTable(get);
                if (set != null)
                {
                    AddResultTable(set);
                }
            }

            return(get, set);
        }
コード例 #4
0
        private void AddPropertyOrEvent(bool isProperty, LuaIdentifierNameSyntax name, LuaIdentifierNameSyntax innerName, LuaExpressionSyntax value, bool isImmutable, bool isStatic, bool isPrivate, LuaExpressionSyntax typeExpression, List <LuaStatementSyntax> statements)
        {
            LuaPropertyOrEventIdentifierNameSyntax get, set;

            if (isProperty)
            {
                get = new LuaPropertyOrEventIdentifierNameSyntax(true, true, name);
                set = new LuaPropertyOrEventIdentifierNameSyntax(true, false, name);
            }
            else
            {
                get = new LuaPropertyOrEventIdentifierNameSyntax(false, true, name);
                set = new LuaPropertyOrEventIdentifierNameSyntax(false, false, name);
            }

            local_.Variables.Add(get);
            local_.Variables.Add(set);
            if (!isStatic)
            {
                LuaIdentifierNameSyntax initMethodIdentifier     = isProperty ? LuaIdentifierNameSyntax.Property : LuaIdentifierNameSyntax.Event;
                LuaMultipleAssignmentExpressionSyntax assignment = new LuaMultipleAssignmentExpressionSyntax();
                assignment.Lefts.Add(get);
                assignment.Lefts.Add(set);
                LuaInvocationExpressionSyntax invocation = new LuaInvocationExpressionSyntax(initMethodIdentifier);
                invocation.AddArgument(new LuaStringLiteralExpressionSyntax(innerName));
                assignment.Rights.Add(invocation);
                methodList_.Statements.Add(assignment.ToStatement());
            }
            else
            {
                var memberAccess = new LuaMemberAccessExpressionSyntax(typeExpression, innerName);
                var getFunction  = new LuaFunctionExpressionSyntax();
                var setFunction  = new LuaFunctionExpressionSyntax();
                if (isProperty)
                {
                    getFunction.AddStatement(new LuaReturnStatementSyntax(memberAccess));
                    setFunction.AddParameter(LuaIdentifierNameSyntax.Value);
                    var assignment = new LuaAssignmentExpressionSyntax(memberAccess, LuaIdentifierNameSyntax.Value);
                    setFunction.AddStatement(assignment.ToStatement());
                }
                else
                {
                    getFunction.AddParameter(LuaIdentifierNameSyntax.Value);
                    var getAssignment = new LuaAssignmentExpressionSyntax(memberAccess, new LuaBinaryExpressionSyntax(memberAccess, Tokens.Plus, LuaIdentifierNameSyntax.Value));
                    getFunction.AddStatement(getAssignment.ToStatement());
                    setFunction.AddParameter(LuaIdentifierNameSyntax.Value);
                    var setAssignment = new LuaAssignmentExpressionSyntax(memberAccess, new LuaBinaryExpressionSyntax(memberAccess, Tokens.Sub, LuaIdentifierNameSyntax.Value));
                    setFunction.AddStatement(setAssignment.ToStatement());
                }
                methodList_.Statements.Add(new LuaAssignmentExpressionSyntax(get, getFunction).ToStatement());
                methodList_.Statements.Add(new LuaAssignmentExpressionSyntax(set, setFunction).ToStatement());
            }

            if (value != null)
            {
                if (isStatic)
                {
                    if (isImmutable)
                    {
                        AddResultTable(innerName, value);
                    }
                    else
                    {
                        if (statements != null)
                        {
                            staticInitStatements_.AddRange(statements);
                        }
                        LuaAssignmentExpressionSyntax assignment = new LuaAssignmentExpressionSyntax(new LuaMemberAccessExpressionSyntax(LuaIdentifierNameSyntax.This, innerName), value);
                        staticInitStatements_.Add(new LuaExpressionStatementSyntax(assignment));
                    }
                }
                else
                {
                    if (isImmutable)
                    {
                        AddResultTable(innerName, value);
                    }
                    else
                    {
                        if (statements != null)
                        {
                            initStatements_.AddRange(statements);
                        }
                        AddInitFiled(innerName, value);
                    }
                }
            }

            if (!isPrivate)
            {
                AddResultTable(get);
                AddResultTable(set);
            }
        }