public void AddParameter(LuaIdentifierNameSyntax parameter)
 {
     ParameterList.Parameters.Add(parameter);
 }
Пример #2
0
 public LuaPropertyOrEventIdentifierNameSyntax(bool isProperty, bool isGetOrAdd, LuaIdentifierNameSyntax name) : base(string.Empty)
 {
     IsProperty = isProperty;
     IsGetOrAdd = isGetOrAdd;
     Name       = name;
 }
Пример #3
0
 public LuaKeyValueTableItemSyntax(LuaIdentifierNameSyntax key, LuaExpressionSyntax value) : this(new LuaTableLiteralKeySyntax(key), value)
 {
 }
 public LuaInterfaceDeclarationSyntax(LuaIdentifierNameSyntax name)
 {
     UpdateIdentifiers(name, LuaIdentifierNameSyntax.Namespace, LuaIdentifierNameSyntax.Interface);
 }
 public LuaLocalVariableDeclaratorSyntax(LuaIdentifierNameSyntax identifier, LuaExpressionSyntax expression = null)
 {
     Declarator = new LuaVariableDeclaratorSyntax(identifier, expression);
 }
 public (LuaPropertyOrEventIdentifierNameSyntax, LuaPropertyOrEventIdentifierNameSyntax) AddEvent(LuaIdentifierNameSyntax name, LuaIdentifierNameSyntax innerName, LuaExpressionSyntax value, bool isImmutable, bool isStatic, bool isPrivate, LuaExpressionSyntax typeExpression, List <LuaStatementSyntax> statements)
 {
     return(AddPropertyOrEvent(false, name, innerName, value, isImmutable, isStatic, isPrivate, typeExpression, statements));
 }
 public LuaClassDeclarationSyntax(LuaIdentifierNameSyntax name)
 {
     UpdateIdentifiers(name, LuaIdentifierNameSyntax.Namespace, LuaIdentifierNameSyntax.Class, LuaIdentifierNameSyntax.Namespace);
 }
        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);
            }
        }
 public void AddEvent(LuaIdentifierNameSyntax name, LuaIdentifierNameSyntax innerName, LuaExpressionSyntax value, bool isImmutable, bool isStatic, bool isPrivate)
 {
     AddPropertyOrEvent(false, name, innerName, value, isImmutable, isStatic, isPrivate);
 }
Пример #10
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);
            }
        }
Пример #11
0
        private void AddResultTable(LuaIdentifierNameSyntax name, LuaExpressionSyntax value)
        {
            LuaKeyValueTableItemSyntax item = new LuaKeyValueTableItemSyntax(new LuaTableLiteralKeySyntax(name), value);

            resultTable_.Items.Add(item);
        }
Пример #12
0
 public LuaStringLiteralExpressionSyntax(LuaIdentifierNameSyntax identifier)
 {
     Identifier = identifier;
 }
Пример #13
0
        private void AddResultTable(LuaIdentifierNameSyntax name)
        {
            LuaKeyValueTableItemSyntax item = new LuaKeyValueTableItemSyntax(name, name);

            resultTable_.Items.Add(item);
        }
Пример #14
0
 public LuaParameterSyntax(LuaIdentifierNameSyntax identifier)
 {
     Identifier = identifier;
 }
        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)
                    {
                        LuaAssignmentExpressionSyntax assignment = new LuaAssignmentExpressionSyntax(name, value);
                        if (isImmutable)
                        {
                            methodList_.Statements.Add(new LuaExpressionStatementSyntax(assignment));
                        }
                        else
                        {
                            if (statements != null)
                            {
                                staticInitStatements_.AddRange(statements);
                            }
                            staticInitStatements_.Add(new LuaExpressionStatementSyntax(assignment));
                        }
                    }
                }
                else
                {
                    if (isReadOnly)
                    {
                        local_.Variables.Add(name);
                        if (value != null)
                        {
                            if (isImmutable)
                            {
                                LuaAssignmentExpressionSyntax assignment = new LuaAssignmentExpressionSyntax(name, value);
                                methodList_.Statements.Add(new LuaExpressionStatementSyntax(assignment));
                                AddResultTable(name);
                            }
                            else
                            {
                                if (statements != null)
                                {
                                    staticInitStatements_.AddRange(statements);
                                }
                                var assignment = new LuaAssignmentExpressionSyntax(name, value);
                                staticInitStatements_.Add(new LuaExpressionStatementSyntax(assignment));

                                var memberAccess = new LuaMemberAccessExpressionSyntax(LuaIdentifierNameSyntax.This, name);
                                staticInitStatements_.Add(new LuaAssignmentExpressionSyntax(memberAccess, name));
                            }
                        }
                    }
                    else
                    {
                        if (value != null)
                        {
                            if (isImmutable)
                            {
                                AddResultTable(name, value);
                            }
                            else
                            {
                                if (statements != null)
                                {
                                    staticInitStatements_.AddRange(statements);
                                }
                                var assignment = new LuaAssignmentExpressionSyntax(new LuaMemberAccessExpressionSyntax(LuaIdentifierNameSyntax.This, name), value);
                                staticInitStatements_.Add(new LuaExpressionStatementSyntax(assignment));
                            }
                        }
                    }
                }
            }
            else
            {
                if (value != null)
                {
                    if (isImmutable)
                    {
                        AddResultTable(name, value);
                    }
                    else
                    {
                        if (statements != null)
                        {
                            initStatements_.AddRange(statements);
                        }
                        AddInitFiled(name, value);
                    }
                }
            }
        }
Пример #16
0
 internal void AddMethodAttributes(LuaIdentifierNameSyntax name, List <LuaExpressionSyntax> attributes)
 {
     AddFieldAttributes(name, attributes);
 }
        private (LuaPropertyOrEventIdentifierNameSyntax, LuaPropertyOrEventIdentifierNameSyntax) 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);
            }
            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);
                }
                else
                {
                    getFunction.AddParameter(LuaIdentifierNameSyntax.Value);
                    var getAssignment = new LuaAssignmentExpressionSyntax(memberAccess, new LuaBinaryExpressionSyntax(memberAccess, Tokens.Plus, LuaIdentifierNameSyntax.Value));
                    getFunction.AddStatement(getAssignment);
                    setFunction.AddParameter(LuaIdentifierNameSyntax.Value);
                    var setAssignment = new LuaAssignmentExpressionSyntax(memberAccess, new LuaBinaryExpressionSyntax(memberAccess, Tokens.Sub, LuaIdentifierNameSyntax.Value));
                    setFunction.AddStatement(setAssignment);
                }
                methodList_.Statements.Add(new LuaAssignmentExpressionSyntax(get, getFunction));
                methodList_.Statements.Add(new LuaAssignmentExpressionSyntax(set, setFunction));
            }

            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);
            }

            return(get, set);
        }
Пример #18
0
 public LuaGotoStatement(LuaIdentifierNameSyntax identifier)
 {
     Identifier = identifier ?? throw new ArgumentNullException(nameof(identifier));
 }
        private void CheckCtorsFunction(LuaBlockSyntax body)
        {
            bool hasInit  = initStatements_.Count > 0;
            bool hasCtors = ctors_.Count > 0;

            if (hasCtors)
            {
                if (hasInit)
                {
                    if (ctors_.Count == 1)
                    {
                        ctors_.First().Function.Body.Statements.InsertRange(0, initStatements_);
                    }
                    else
                    {
                        var init = LuaIdentifierNameSyntax.Init;
                        AddInitFunction(body, init, GetInitFunction(), false);
                        foreach (var ctor in ctors_)
                        {
                            if (!ctor.Function.IsInvokeThisCtor)
                            {
                                var invocationInit = new LuaInvocationExpressionSyntax(init, LuaIdentifierNameSyntax.This);
                                ctor.Function.Body.Statements.Insert(0, new LuaExpressionStatementSyntax(invocationInit));
                            }
                        }
                    }
                }

                if (ctors_.Count == 1)
                {
                    var ctor = ctors_.First();
                    if (ctor.Function.Body.Statements.Count > 0)
                    {
                        if (ctor.Document != null)
                        {
                            body.AddStatement(ctor.Document);
                        }
                        AddInitFunction(body, LuaIdentifierNameSyntax.Ctor, ctor.Function);
                    }
                }
                else
                {
                    LuaTableExpression ctrosTable = new LuaTableExpression();
                    int index = 1;
                    foreach (var ctor in ctors_)
                    {
                        if (ctor.Document != null)
                        {
                            body.AddStatement(ctor.Document);
                        }
                        LuaIdentifierNameSyntax nameIdentifier = GetCtorNameString(index);
                        AddInitFunction(body, nameIdentifier, ctor.Function, false);
                        ctrosTable.Add(nameIdentifier);
                        ++index;
                    }
                    AddResultTable(LuaIdentifierNameSyntax.Ctor, ctrosTable);
                }
            }
            else
            {
                if (hasInit)
                {
                    AddInitFunction(body, LuaIdentifierNameSyntax.Ctor, GetInitFunction());
                }
            }
        }
Пример #20
0
 public LuaLabeledStatement(LuaIdentifierNameSyntax identifier, LuaStatementSyntax statement = null)
 {
     Identifier = identifier ?? throw new ArgumentNullException(nameof(identifier));
     Statement  = statement;
 }
 public LuaStructDeclarationSyntax(LuaIdentifierNameSyntax name)
 {
     UpdateIdentifiers(name, LuaIdentifierNameSyntax.Namespace, LuaIdentifierNameSyntax.Struct, LuaIdentifierNameSyntax.Namespace);
 }
 private void AddImport(LuaIdentifierNameSyntax name, LuaExpressionSyntax value)
 {
     importAreaStatements.Statements.Add(new LuaLocalVariableDeclaratorSyntax(name, value));
 }
 public LuaEnumDeclarationSyntax(string fullName, LuaIdentifierNameSyntax name, LuaCompilationUnitSyntax compilationUnit)
 {
     FullName        = fullName;
     CompilationUnit = compilationUnit;
     UpdateIdentifiers(name, LuaIdentifierNameSyntax.Namespace, LuaIdentifierNameSyntax.Enum);
 }
Пример #24
0
 public void AddParameter(LuaIdentifierNameSyntax identifier)
 {
     AddParameter(new LuaParameterSyntax(identifier));
 }
Пример #25
0
 public LuaPropertyOrEventIdentifierNameSyntax(bool isProperty, LuaIdentifierNameSyntax name) : this(isProperty, true, name)
 {
 }
 private void AddResultTable(LuaIdentifierNameSyntax name)
 {
     AddResultTable(new LuaKeyValueTableItemSyntax(name, name));
 }
Пример #27
0
 public LuaTableLiteralKeySyntax(LuaIdentifierNameSyntax identifier)
 {
     Identifier = identifier;
 }
 private void AddResultTable(LuaIdentifierNameSyntax name, LuaExpressionSyntax value)
 {
     AddResultTable(new LuaKeyValueTableItemSyntax(name, value));
 }
Пример #29
0
 internal void Add(LuaIdentifierNameSyntax key, LuaExpressionSyntax value)
 {
     Items.Add(new LuaKeyValueTableItemSyntax(key, value));
 }
Пример #30
0
 public LuaSwitchAdapterStatementSyntax(LuaIdentifierNameSyntax temp)
 {
     Temp = temp;
 }