コード例 #1
0
ファイル: StateGenerator.cs プロジェクト: xdrie/SharpNative
        public void GenerateStates()
        {
            var lastState = new State(this);

            lastState.Statements.Add(ReturnOutOfState());

            currentState = new State(this)
            {
                NextState = lastState
            };
            node.Accept(this);

            // Post-process goto statements
            if (labelStates.Any())
            {
                var gotoSubstituter = new GotoSubstituter(compilation, labelStates);
                foreach (var state in states)
                {
                    state.Statements = state.Statements.Select(x => (StatementSyntax)x.Accept(gotoSubstituter)).ToList();
                }
            }

            var lastStatement = states.Last().Statements.LastOrDefault();

            if (lastStatement == null || (!(lastStatement is BreakStatementSyntax) && !(lastStatement is ReturnStatementSyntax)))
            {
                states.Last().Statements.Add(Cs.Break());
            }
        }