internal void AddBaseTypes(IEnumerable <LuaExpressionSyntax> baseTypes, LuaSpeaicalGenericType genericArgument = null)
        {
            bool hasLazyGenericArgument = false;

            if (genericArgument != null)
            {
                if (genericArgument.IsLazy)
                {
                    hasLazyGenericArgument = true;
                }
                else
                {
                    AddResultTable(genericArgument.Name, genericArgument.Value);
                }
            }

            LuaTableInitializerExpression table = new LuaTableInitializerExpression();

            table.Items.AddRange(baseTypes.Select(i => new LuaSingleTableItemSyntax(i)));
            LuaFunctionExpressionSyntax functionExpression = new LuaFunctionExpressionSyntax();

            functionExpression.AddParameter(LuaIdentifierNameSyntax.Global);
            if (hasLazyGenericArgument)
            {
                functionExpression.AddParameter(LuaIdentifierNameSyntax.This);
                var assignment = new LuaAssignmentExpressionSyntax(new LuaMemberAccessExpressionSyntax(LuaIdentifierNameSyntax.This, genericArgument.Name), genericArgument.Value);
                functionExpression.AddStatement(assignment);
            }
            functionExpression.AddStatement(new LuaReturnStatementSyntax(table));
            AddResultTable(LuaIdentifierNameSyntax.Inherits, functionExpression);
        }
        internal void AddBaseTypes(IEnumerable <LuaExpressionSyntax> baseTypes, LuaSpeaicalGenericType genericArgument, List <LuaIdentifierNameSyntax> baseCopyFields)
        {
            bool hasLazyGenericArgument = false;

            if (genericArgument != null)
            {
                if (genericArgument.IsLazy)
                {
                    hasLazyGenericArgument = true;
                }
                else
                {
                    AddResultTable(genericArgument.Name, genericArgument.Value);
                }
            }

            bool hasBaseCopyField = baseCopyFields != null && baseCopyFields.Count > 0;
            LuaFunctionExpressionSyntax functionExpression = new LuaFunctionExpressionSyntax();

            functionExpression.AddParameter(LuaIdentifierNameSyntax.Global);
            if (hasLazyGenericArgument || hasBaseCopyField)
            {
                functionExpression.AddParameter(LuaIdentifierNameSyntax.This);
            }

            if (hasLazyGenericArgument)
            {
                var assignment = new LuaAssignmentExpressionSyntax(new LuaMemberAccessExpressionSyntax(LuaIdentifierNameSyntax.This, genericArgument.Name), genericArgument.Value);
                functionExpression.AddStatement(assignment);
            }

            LuaTableExpression table = new LuaTableExpression();

            if (hasBaseCopyField)
            {
                var baseIdentifier = LuaIdentifierNameSyntax.Base;
                functionExpression.AddStatement(new LuaLocalVariableDeclaratorSyntax(baseIdentifier, baseTypes.First()));
                foreach (var field in baseCopyFields)
                {
                    var left  = new LuaMemberAccessExpressionSyntax(LuaIdentifierNameSyntax.This, field);
                    var right = new LuaMemberAccessExpressionSyntax(baseIdentifier, field);
                    functionExpression.AddStatement(new LuaAssignmentExpressionSyntax(left, right));

                    table.Items.Add(new LuaSingleTableItemSyntax(baseIdentifier));
                    table.Items.AddRange(baseTypes.Skip(1).Select(i => new LuaSingleTableItemSyntax(i)));
                }
            }
            else
            {
                table.Items.AddRange(baseTypes.Select(i => new LuaSingleTableItemSyntax(i)));
            }

            functionExpression.AddStatement(new LuaReturnStatementSyntax(table));
            AddResultTable(LuaIdentifierNameSyntax.Inherits, functionExpression);
        }
 private void CheckAttributes()
 {
     if (attributes_.Items.Count > 0)
     {
         LuaFunctionExpressionSyntax functionExpression = new LuaFunctionExpressionSyntax();
         functionExpression.AddParameter(LuaIdentifierNameSyntax.Global);
         functionExpression.AddStatement(new LuaReturnStatementSyntax(attributes_));
         AddResultTable(LuaIdentifierNameSyntax.Attributes, functionExpression);
     }
 }
Esempio n. 4
0
 private void CheckAttributes()
 {
     if (attributes_.Items.Count > 0)
     {
         LuaTableInitializerExpression metaDataTable = new LuaTableInitializerExpression();
         metaDataTable.Items.Add(new LuaKeyValueTableItemSyntax(new LuaTableLiteralKeySyntax(LuaIdentifierNameSyntax.Attributes), attributes_));
         LuaFunctionExpressionSyntax functionExpression = new LuaFunctionExpressionSyntax();
         functionExpression.AddParameter(LuaIdentifierNameSyntax.Global);
         functionExpression.AddStatement(new LuaReturnStatementSyntax(metaDataTable));
         AddResultTable(LuaIdentifierNameSyntax.Metadata, functionExpression);
     }
 }
Esempio n. 5
0
 private void CheckMetadata()
 {
     if (metadata_ != null)
     {
         SortMetaData(metaFields_);
         SortMetaData(metaProperties_);
         SortMetaData(metaMethods_);
         LuaFunctionExpressionSyntax functionExpression = new LuaFunctionExpressionSyntax();
         functionExpression.AddParameter(LuaIdentifierNameSyntax.Global);
         functionExpression.AddStatement(new LuaReturnStatementSyntax(metadata_));
         AddResultTable(LuaIdentifierNameSyntax.Metadata, functionExpression);
     }
 }
Esempio n. 6
0
        internal void AddBaseTypes(IEnumerable <LuaExpressionSyntax> baseTypes)
        {
            var global = LuaIdentifierNameSyntax.Global;
            LuaTableInitializerExpression table = new LuaTableInitializerExpression();

            foreach (var baseType in baseTypes)
            {
                LuaMemberAccessExpressionSyntax memberAccess = new LuaMemberAccessExpressionSyntax(global, baseType);
                table.Items.Add(new LuaSingleTableItemSyntax(memberAccess));
            }
            LuaFunctionExpressionSyntax functionExpression = new LuaFunctionExpressionSyntax();

            functionExpression.AddParameter(global);
            functionExpression.AddStatement(new LuaReturnStatementSyntax(table));
            AddResultTable(LuaIdentifierNameSyntax.Inherits, functionExpression);
        }
Esempio n. 7
0
        private void CheckMetadata()
        {
            if (metadata_ != null)
            {
                if (metaMethods_ != null)
                {
                    metaMethods_.Items.Sort((x, y) => MetaDataName(x).CompareTo(MetaDataName(y)));
                }

                LuaFunctionExpressionSyntax functionExpression = new LuaFunctionExpressionSyntax();
                functionExpression.AddParameter(LuaIdentifierNameSyntax.Global);
                functionExpression.AddParameter(LuaSyntaxNode.Tokens.Ref);
                functionExpression.AddStatement(new LuaReturnStatementSyntax(metadata_));
                AddResultTable(LuaIdentifierNameSyntax.Metadata, functionExpression);
            }
        }
Esempio n. 8
0
 private void CheckMetadata(LuaRenderer renderer)
 {
     if (metadata_ != null)
     {
         SortMetaData(metaFields_);
         SortMetaData(metaProperties_);
         SortMetaData(metaMethods_);
         if (renderer.Setting.IsClassic)
         {
             CheckMetadataMoreThanUpvalues();
         }
         var functionExpression = new LuaFunctionExpressionSyntax();
         functionExpression.AddParameter(LuaIdentifierNameSyntax.Global);
         functionExpression.AddStatement(new LuaReturnStatementSyntax(metadata_));
         AddResultTable(LuaIdentifierNameSyntax.Metadata, functionExpression);
     }
 }
Esempio n. 9
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);
        }
Esempio n. 10
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);
            }
        }