Ejemplo n.º 1
0
 def visitCase(self, case):
     """
     Connect the Case statement to the first statement of each when clause and
     the otherwise clause. Process the statements within each clause.
     """
     logger.debug("visitCase")
     for when_clause in case.whenClauses:
         if when_clause.statements is not None and len(when_clause.statements) > 0:
             # Connect to the beginning of the when clause
             first_when_statement = when_clause.statements[0]
             connect(case,first_when_statement)
             
             for statement in when_clause.statements:
                 self.visit(statement)
Ejemplo n.º 2
0
 def visitGoto(self, goto):
     """
     Connect the Goto to the first statement on the target line if
     it exists. Error if it does not.
     """
     # TODO: targetLogicalLine needs to be a constant for this
     # to work
     #print "CFG goto"
     logger.debug("visitGoto")
     #print "goto.targetLogicalLine = %s" % goto.targetLogicalLine.value
     goto_target = self.line_mapper.statementOnLine(goto.targetLogicalLine)
     #print "goto_target = %s" % goto_target
     if goto_target:
         connect(goto, goto_target)
     else:
         errors.error("No such line %s at line %s" % (goto.targetLogicalLine.value, goto.lineNum))
Ejemplo n.º 3
0
    def visitOnGoto(self, ongoto):
        """
        Connect the OnGoto to the first statement on each of the target lines
        if they exist. Error if they do not. Also connect to the first line of
        the out-of-range clause if present, and process each statement within
        that clause.
        """
        logger.debug("visitOnGoto")
        ongoto.targetStatements = [] # TODO: Fix this so it isn't a monkey patch!
        for targetLogicalLine in ongoto.targetLogicalLines:
            ongoto_target = self.line_mapper.statementOnLine(targetLogicalLine)
            if ongoto_target:
                connect(ongoto, ongoto_target)
                ongoto.targetStatements.append(ongoto_target)
            else:
                errors.error("No such line %s at line %s" % (targetLogicalLine.value, ongoto.lineNum))
        
        first_else_statement = None    
        if ongoto.outOfRangeClause is not None:
            if isinstance(ongoto.outOfRangeClause, list):
                if len(ongoto.outOfRangeClause) > 0:
                    # Connect to the beginning of the else clause
                    first_else_statement = ongoto.outOfRangeClause[0]
                    connect(ongoto, first_else_statement)
                    
                    for statement in ongoto.outOfRangeClause:
                        self.visit(statement)
            else:
                first_else_statement = ongoto.outOfRangeClause
                connect(ongoto, ongoto.outOfRangeClause)
                self.visit(ongoto.outOfRangeClause)
        ongoto.outOfRangeStatement = first_else_statement  # TODO: Fix this so it isn't a monkey patch!

        assert hasattr(ongoto, "targetStatements")
        assert hasattr(ongoto, "outOfRangeStatement")
Ejemplo n.º 4
0
 def visitIf(self, iff):
     """
     Connect the If to the initial statements of the true and false
     clauses.  Process each statement in both clauses.
     """
     following = findFollowingStatement(iff)
     if not following:
         errors.internal("Following statement to IF not found at line %d" % iff.lineNum)
     if iff.trueClause is not None:
         if isinstance(iff.trueClause, list):
             if len(iff.trueClause) > 0:
                 # Connect to the beginning of the true clause
                 first_true_statement = iff.trueClause[0]
                 connect(iff, first_true_statement)
                 
                 for statement in iff.trueClause:
                     self.visit(statement)
             else:
                 connect(iff.following) # TODO: Error!
         else:
             connect(iff, iff.trueClause)
             self.visit(iff.trueClause)                
     else:
         connect(iff, following)
             
     if iff.falseClause is not None:
         if isinstance(iff.falseClause, list):
             if len(iff.falseClause) > 0:
                 # Connect to the beginning of the false clause
                 first_false_statement = iff.falseClause[0]
                 connect(iff, first_false_statement)
                 
                 for statement in iff.falseClause:
                     self.visit(statement)
             else:
                 connect(iff.following) # TODO: Error!
         else:
             connect(iff, iff.falseClause)
             self.visit(iff.falseClause)
     else:
         connect(iff, following)