Example #1
0
        //todo: redesign nested if statements - currently are not supported
        public override object VisitSelectionStatement(CLanguageParser.SelectionStatementContext context)
        {
            var assignments = context
                              .GetFirstDescendant <CLanguageParser.CompoundStatementContext>()
                              .GetDescendants <CLanguageParser.AssignmentExpressionContext>()
                              .Where(x => x.ChildCount > 1)
                              .ToList();
            var functionName = context
                               .GetFunction()
                               .GetFirstDescendant <CLanguageParser.DirectDeclaratorContext>()
                               .GetName();
            var ifStatement = new IfStatement {
                Context        = context,
                Assignments    = assignments,
                ElseStatements = context
                                 .statement()
                                 .Skip(1)
                                 .Select(x => new ElseStatement {
                    Context     = x,
                    Assignments = assignments
                })
                                 .ToList()
            };

            DataStructure[functionName].AddIfStatement(ifStatement);

            return(base.VisitSelectionStatement(context));
        }
        public List <RelationalExpression> GetAssignmentRelations(CLanguageParser.SelectionStatementContext context)
        {
            // TODO: partial functionality
            string functionName = context
                                  .GetFunction()
                                  .GetFirstDescendant <CLanguageParser.DirectDeclaratorContext>()
                                  .GetName();
            IfStatement ifStatement = _dataStructure[functionName]
                                      .IfStatements
                                      .First(x => x.StartIndex == context.GetStartIndex());
            List <RelationalExpression> expressions = ifStatement
                                                      .Assignments
                                                      .Concat(ifStatement.ElseStatements.SelectMany(x => x.Assignments))
                                                      .Select(GetRelationalExpression)
                                                      .ToList();

            return(expressions);
        }