Ejemplo n.º 1
0
        public void Fill(LuaExpressionSyntax expression, IEnumerable <LuaStatementSyntax> sections)
        {
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }
            if (sections == null)
            {
                throw new ArgumentNullException(nameof(sections));
            }

            var body = RepeatStatement.Body;

            body.Statements.Add(caseLabelVariables_);
            body.Statements.Add(new LuaLocalVariableDeclaratorSyntax(Temp, expression));

            LuaIfStatementSyntax ifStatement = null;

            foreach (var section in sections)
            {
                LuaIfStatementSyntax statement = section as LuaIfStatementSyntax;
                if (statement != null)
                {
                    if (ifStatement == null)
                    {
                        ifStatement = statement;
                    }
                    else
                    {
                        LuaElseIfStatementSyntax elseIfStatement = new LuaElseIfStatementSyntax(statement.Condition);
                        elseIfStatement.Body.Statements.AddRange(statement.Body.Statements);
                        ifStatement.ElseIfStatements.Add(elseIfStatement);
                    }
                }
                else
                {
                    Contract.Assert(defaultBock_ == null);
                    defaultBock_ = (LuaBlockSyntax)section;
                }
            }

            if (ifStatement != null)
            {
                body.Statements.Add(ifStatement);
                if (defaultBock_ != null)
                {
                    LuaElseClauseSyntax elseClause = new LuaElseClauseSyntax();
                    elseClause.Body.Statements.AddRange(defaultBock_.Statements);
                    ifStatement.Else = elseClause;
                }
                headIfStatement_ = ifStatement;
            }
            else
            {
                if (defaultBock_ != null)
                {
                    body.Statements.AddRange(defaultBock_.Statements);
                }
            }
        }
Ejemplo n.º 2
0
 private void CheckHasDefaultLabel()
 {
     if (DefaultLabel != null)
     {
         Contract.Assert(defaultBock_ != null);
         caseLabelVariables_.Variables.Add(DefaultLabel);
         LuaLabeledStatement labeledStatement = new LuaLabeledStatement(DefaultLabel);
         RepeatStatement.Body.Statements.Add(labeledStatement);
         LuaIfStatementSyntax IfStatement = new LuaIfStatementSyntax(DefaultLabel);
         IfStatement.Body.Statements.AddRange(defaultBock_.Statements);
         RepeatStatement.Body.Statements.Add(IfStatement);
     }
 }
Ejemplo n.º 3
0
 private void CheckHasCaseLabel()
 {
     if (CaseLabels.Count > 0)
     {
         Contract.Assert(headIfStatement_ != null);
         caseLabelVariables_.Variables.AddRange(CaseLabels.Values);
         foreach (var pair in CaseLabels)
         {
             var caseLabelStatement = FindMatchIfStatement(pair.Key);
             LuaIdentifierNameSyntax labelIdentifier = pair.Value;
             RepeatStatement.Body.Statements.Add(new LuaLabeledStatement(labelIdentifier));
             LuaIfStatementSyntax ifStatement = new LuaIfStatementSyntax(labelIdentifier);
             ifStatement.Body.Statements.AddRange(caseLabelStatement.Statements);
             RepeatStatement.Body.Statements.Add(ifStatement);
         }
     }
 }