Пример #1
0
 private void AddInitFunction(LuaBlockSyntax body, LuaIdentifierNameSyntax name, LuaFunctionExpressionSyntax initFunction, bool isAddItem = true)
 {
     local_.Variables.Add(name);
     body.Statements.Add(name.Assignment(initFunction));
     if (isAddItem)
     {
         AddResultTable(name);
     }
 }
Пример #2
0
 public LuaGotoCaseAdapterStatement(LuaIdentifierNameSyntax identifier)
 {
     if (identifier == null)
     {
         throw new ArgumentNullException(nameof(identifier));
     }
     Assignment    = identifier.Assignment(LuaIdentifierNameSyntax.True);
     GotoStatement = new LuaGotoStatement(identifier);
 }
Пример #3
0
        public void AddMethod(LuaIdentifierNameSyntax name, LuaFunctionExpressionSyntax method, bool isPrivate, LuaDocumentStatement document = null, bool isMoreThanLocalVariables = false, bool isInterfaceDefaultMethod = false)
        {
            if (document != null && document.HasIgnoreAttribute)
            {
                return;
            }

            if (isMoreThanLocalVariables)
            {
                CheckTooManyVariables(true);
                if (document != null && !document.IsEmpty)
                {
                    methodList_.Statements.Add(document);
                }
                var left = LuaIdentifierNameSyntax.MorenManyLocalVarTempTable.MemberAccess(name);
                methodList_.Statements.Add(left.Assignment(method));
                if (isInterfaceDefaultMethod)
                {
                    AddInterfaceDefaultMethod(name, left);
                }
                else
                {
                    AddResultTable(name, left);
                }
            }
            else
            {
                local_.Variables.Add(name);
                if (document != null && !document.IsEmpty)
                {
                    methodList_.Statements.Add(document);
                }
                methodList_.Statements.Add(name.Assignment(method));
                if (!isPrivate)
                {
                    if (isInterfaceDefaultMethod)
                    {
                        AddInterfaceDefaultMethod(name);
                    }
                    else
                    {
                        AddResultTable(name);
                    }
                }
            }
        }
Пример #4
0
 public void AddField(LuaIdentifierNameSyntax name, LuaExpressionSyntax value, bool isImmutable, bool isStatic, bool isPrivate, bool isReadOnly, List <LuaStatementSyntax> statements, bool isMoreThanLocalVariables)
 {
     if (isStatic)
     {
         if (isPrivate)
         {
             local_.Variables.Add(name);
             if (value != null)
             {
                 var assignment = name.Assignment(value);
                 if (isImmutable)
                 {
                     methodList_.Statements.Add(assignment);
                 }
                 else
                 {
                     if (statements != null)
                     {
                         staticInitStatements_.AddRange(statements);
                     }
                     staticInitStatements_.Add(assignment);
                 }
             }
         }
         else
         {
             if (isReadOnly)
             {
                 if (isMoreThanLocalVariables && value != null && isImmutable)
                 {
                     CheckTooManyVariables(true);
                     var left = LuaIdentifierNameSyntax.MorenManyLocalVarTempTable.MemberAccess(name);
                     methodList_.Statements.Add(left.Assignment(value));
                     AddResultTable(name, left);
                 }
                 else
                 {
                     local_.Variables.Add(name);
                     if (value != null)
                     {
                         var assignment = name.Assignment(value);
                         if (isImmutable)
                         {
                             methodList_.Statements.Add(assignment);
                             AddResultTable(name);
                         }
                         else
                         {
                             if (statements != null)
                             {
                                 staticInitStatements_.AddRange(statements);
                             }
                             staticInitStatements_.Add(assignment);
                             staticInitStatements_.Add(LuaIdentifierNameSyntax.This.MemberAccess(name).Assignment(name));
                         }
                     }
                 }
             }
             else
             {
                 if (value != null)
                 {
                     if (isImmutable)
                     {
                         AddResultTable(name, value);
                     }
                     else
                     {
                         if (statements != null)
                         {
                             staticInitStatements_.AddRange(statements);
                         }
                         staticInitStatements_.Add(LuaIdentifierNameSyntax.This.MemberAccess(name).Assignment(value));
                     }
                 }
             }
         }
     }
     else
     {
         if (value != null)
         {
             if (isImmutable)
             {
                 AddResultTable(name, value);
             }
             else
             {
                 if (statements != null)
                 {
                     initStatements_.AddRange(statements);
                 }
                 AddInitFiled(name, value);
             }
         }
     }
 }
Пример #5
0
        private void CheckUsingDeclares()
        {
            var imports = UsingDeclares.Where(i => !i.IsFromCode).ToList();

            if (imports.Count > 0)
            {
                imports.Sort();
                foreach (var import in imports)
                {
                    AddImport(import.NewPrefix, import.Prefix);
                }
            }

            var genericImports = GenericUsingDeclares.Where(i => !i.IsFromCode).ToList();

            if (genericImports.Count > 0)
            {
                genericImports.Sort();
                foreach (var import in genericImports)
                {
                    AddImport(import.NewName, import.InvocationExpression);
                }
            }

            var usingDeclares   = UsingDeclares.Where(i => i.IsFromCode).ToList();
            var genericDeclares = GenericUsingDeclares.Where(i => i.IsFromCode).ToList();

            if (usingDeclares.Count > 0 || genericDeclares.Count > 0)
            {
                usingDeclares.Sort();
                genericDeclares.Sort();

                foreach (var usingDeclare in usingDeclares)
                {
                    AddImport(usingDeclare.NewPrefix, null);
                }

                foreach (var usingDeclare in genericDeclares)
                {
                    AddImport(usingDeclare.NewName, null);
                }

                var global             = LuaIdentifierNameSyntax.Global;
                var functionExpression = new LuaFunctionExpressionSyntax();
                functionExpression.AddParameter(global);
                foreach (var usingDeclare in usingDeclares)
                {
                    LuaIdentifierNameSyntax newPrefixIdentifier = usingDeclare.NewPrefix;
                    if (usingDeclare.Prefix != usingDeclare.NewPrefix)
                    {
                        functionExpression.Body.AddStatement(newPrefixIdentifier.Assignment(usingDeclare.Prefix));
                    }
                    else
                    {
                        functionExpression.Body.AddStatement(newPrefixIdentifier.Assignment(global.MemberAccess(usingDeclare.Prefix)));
                    }
                }

                foreach (var usingDeclare in genericDeclares)
                {
                    functionExpression.Body.AddStatement(((LuaIdentifierNameSyntax)usingDeclare.NewName).Assignment(usingDeclare.InvocationExpression));
                }

                var invocationExpression = new LuaInvocationExpressionSyntax(LuaIdentifierNameSyntax.Import, functionExpression);
                importAreaStatements.Statements.Add(invocationExpression);
            }

            int index = Statements.FindIndex(i => i is LuaNamespaceDeclarationSyntax);

            if (index != -1)
            {
                Statements.Insert(index, importAreaStatements);
            }
        }
Пример #6
0
 public void AddField(LuaIdentifierNameSyntax name, LuaExpressionSyntax value, bool isImmutable, bool isStatic, bool isPrivate, bool isReadOnly, List <LuaStatementSyntax> statements)
 {
     if (isStatic)
     {
         if (isPrivate)
         {
             local_.Variables.Add(name);
             if (value != null)
             {
                 var assignment = name.Assignment(value);
                 if (isImmutable)
                 {
                     methodList_.Statements.Add(assignment);
                 }
                 else
                 {
                     if (statements != null)
                     {
                         staticInitStatements_.AddRange(statements);
                     }
                     staticInitStatements_.Add(assignment);
                 }
             }
         }
         else
         {
             if (isReadOnly)
             {
                 local_.Variables.Add(name);
                 if (value != null)
                 {
                     var assignment = name.Assignment(value);
                     if (isImmutable)
                     {
                         methodList_.Statements.Add(assignment);
                         AddResultTable(name);
                     }
                     else
                     {
                         if (statements != null)
                         {
                             staticInitStatements_.AddRange(statements);
                         }
                         staticInitStatements_.Add(assignment);
                         staticInitStatements_.Add(LuaIdentifierNameSyntax.This.MemberAccess(name).Assignment(name));
                     }
                 }
             }
             else
             {
                 if (value != null)
                 {
                     if (isImmutable)
                     {
                         AddResultTable(name, value);
                     }
                     else
                     {
                         if (statements != null)
                         {
                             staticInitStatements_.AddRange(statements);
                         }
                         staticInitStatements_.Add(LuaIdentifierNameSyntax.This.MemberAccess(name).Assignment(value));
                     }
                 }
             }
         }
     }
     else
     {
         if (value != null)
         {
             if (isImmutable)
             {
                 AddResultTable(name, value);
             }
             else
             {
                 if (statements != null)
                 {
                     initStatements_.AddRange(statements);
                 }
                 AddInitFiled(name, value);
             }
         }
     }
 }