示例#1
0
 public SConditionalStatement(SExpression condition, SStatement trueStatement, SStatement nextStatement)
     : base(condition != null ? "if: " + condition.CodeString : "", nextStatement)
 {
     Condition       = condition;
     IfTrueStatement = trueStatement;
     IfTrueStatement.SetNextStatement(null);
 }
示例#2
0
 public SLabeledStatement(string codeString, SExpression caseExpression, SStatement labeledStatement)
     : base(caseExpression != null ? "case " + caseExpression.CodeString : codeString,
            labeledStatement?.NextStatement)
 {
     LabeledStatement = labeledStatement;
     CaseExpression   = caseExpression;
 }
示例#3
0
 public virtual void SetNextStatement(SStatement nextStatement)
 {
     if (_nextStatementSet)
     {
         return;
     }
     NextStatement     = nextStatement;
     _nextStatementSet = true;
 }
示例#4
0
 public void SetLabeledStatement(SStatement labeledStatement)
 {
     if (_labeledStatementSet)
     {
         return;
     }
     LabeledStatement     = labeledStatement;
     _labeledStatementSet = true;
 }
示例#5
0
 public SSwitchStatement(SExpression condition, SStatement switchStatement,
                         SLabeledStatement[] jumpTargets, SStatement nextStatement)
     : base(condition != null ? "switch: " + condition.CodeString : "",
            new SLabeledStatement("switch break target", null, nextStatement) { Visible = false })
 {
     Condition       = condition;
     SwitchStatement = switchStatement;
     SwitchStatement.SetNextStatement(null);
     this.jumpTargets = (SLabeledStatement[])jumpTargets.Clone();
 }
示例#6
0
        public SJumpStatement(string codeString, SStatement nextStatement)
            : base(codeString, nextStatement)
        {
            var parts = codeString.Split(' ');

            if (parts[0] == "goto" && parts.Length > 1)
            {
                TargetIdentifier = parts[1];
            }
            else
            {
                TargetIdentifier = null;
            }

            ReturnedExpression = null;
        }
示例#7
0
        private void AddDirectedEdgeToElements(Graph <SStatement> graph, SStatement jumpTargetLabeledStatement,
                                               SStatement labeledStatement)
        {
            if (graph == null || jumpTargetLabeledStatement == null || labeledStatement == null)
            {
                return;
            }

            var a = FindNodes(graph, jumpTargetLabeledStatement.GetStatement());
            var b = FindNodes(graph, labeledStatement.GetStatement());

            foreach (var nodeStatement in a)
            {
                foreach (var statement in b)
                {
                    if (statement != nodeStatement)
                    {
                        graph.AddDirectedEdge(nodeStatement, statement, 1);
                    }
                }
            }
        }
示例#8
0
        private static List <GraphNode <SStatement> > FindNodes(Graph <SStatement> graph, SStatement statement1)
        {
            var hashSet = new HashSet <GraphNode <SStatement> >();

            foreach (var graphNode in graph.Nodes)
            {
                if (statement1 != null && graphNode.Value == statement1.GetStatement())
                {
                    hashSet.Add((GraphNode <SStatement>)graphNode);
                }
            }
            return(hashSet.ToList());
        }
示例#9
0
 public override bool Contains(SStatement statement)
 {
     return(statement == this || IfTrueStatement != null && IfTrueStatement.Contains(statement) ||
            ElseStatement != null && ElseStatement.Contains(statement));
 }
示例#10
0
 public abstract bool Contains(SStatement statement);
示例#11
0
 public override bool Contains(SStatement statement)
 {
     return(statement == this);
 }
示例#12
0
 public SJumpStatement(SExpression returnedExpression, SStatement nextStatement)
     : base("return " + returnedExpression.CodeString, nextStatement)
 {
     TargetIdentifier   = null;
     ReturnedExpression = returnedExpression;
 }
示例#13
0
 public override void SetNextStatement(SStatement nextStatement)
 {
     LabeledStatement.SetNextStatement(nextStatement);
 }
示例#14
0
 public override bool Contains(SStatement statement)
 {
     return(statement == this ||
            LabeledStatement != null &&
            LabeledStatement.Contains(statement));
 }
示例#15
0
 public override bool Contains(SStatement statement)
 {
     return(statement == this ||
            SwitchStatement != null &&
            SwitchStatement.Contains(statement));
 }
示例#16
0
 public SStatement(string codeString, SStatement nextStatement)
 {
     CodeString    = codeString;
     NextStatement = nextStatement;
 }
示例#17
0
 public SExpressionStatement(SExpression expression, SStatement nextStatement)
     : base(expression.CodeString, nextStatement)
 {
     _expression = expression;
 }