예제 #1
0
def generateHeadersDag(options, compilerFacade):
    dag = HeadersDag()

    compilationOptions = compilerFacade.processCompOptions(
        options.compilation_options)

    for sourceFilename in options.files:
        print("Processing... ", sourceFilename, ", found ",
              len(dag.getNodes()), " till now.")

        headers = compilerFacade.getHeaders(sourceFilename, compilationOptions)

        for line in headers.split("\n"):
            if len(line) == 0:
                continue

            try:
                dag.add(*compilerFacade.parseLine(line))
            except Exception as e:
                print("Warning: ", e)

        dag.processOneFile()

    print("All files processed, found", len(dag.getNodes()), "headers.")

    return dag
예제 #2
0
    def test_processOneFile( self ):
        # . A
        # . B
        # . C

        headers = HeadersDag()

        nodeA = headers.add( 1, "A" )
        nodeB = headers.add( 1, "B" )
        nodeC = headers.add( 1, "C" )

        headers.processOneFile()

        self.assertFalse( nodeA.isIncluded() )
        self.assertFalse( nodeB.isIncluded() )
        self.assertFalse( nodeC.isIncluded() )

        self.assertEqual( nodeA.getColor(), DfsNode.White )
        self.assertEqual( nodeB.getColor(), DfsNode.White )
        self.assertEqual( nodeC.getColor(), DfsNode.White )

        self.assertTrue( nodeA.getCounter(), 1 )
        self.assertTrue( nodeB.getCounter(), 1 )
        self.assertTrue( nodeC.getCounter(), 1 )

        # . A  <
        # .. D <
        # . B  <
        # .. D <
        # . C

        nodeA = headers.add( 1, "A" )
        nodeD = headers.add( 2, "D" )
        nodeB = headers.add( 1, "B" )
        nodeD = headers.add( 2, "D" )

        headers.processOneFile()

        self.assertFalse( nodeA.isIncluded() )
        self.assertFalse( nodeB.isIncluded() )
        self.assertFalse( nodeC.isIncluded() )
        self.assertFalse( nodeD.isIncluded() )

        self.assertEqual( nodeA.getColor(), DfsNode.White )
        self.assertEqual( nodeB.getColor(), DfsNode.White )
        self.assertEqual( nodeC.getColor(), DfsNode.White )

        self.assertTrue( nodeA.getCounter(), 2 )
        self.assertTrue( nodeB.getCounter(), 2 )
        self.assertTrue( nodeC.getCounter(), 1 )
        self.assertTrue( nodeD.getCounter(), 1 )
예제 #3
0
    def test_processOneFile(self):
        # . A
        # . B
        # . C

        headers = HeadersDag()

        nodeA = headers.add(1, "A")
        nodeB = headers.add(1, "B")
        nodeC = headers.add(1, "C")

        headers.processOneFile()

        self.assertFalse(nodeA.isIncluded())
        self.assertFalse(nodeB.isIncluded())
        self.assertFalse(nodeC.isIncluded())

        self.assertEqual(nodeA.getColor(), DfsNode.White)
        self.assertEqual(nodeB.getColor(), DfsNode.White)
        self.assertEqual(nodeC.getColor(), DfsNode.White)

        self.assertTrue(nodeA.getCounter(), 1)
        self.assertTrue(nodeB.getCounter(), 1)
        self.assertTrue(nodeC.getCounter(), 1)

        # . A  <
        # .. D <
        # . B  <
        # .. D <
        # . C

        nodeA = headers.add(1, "A")
        nodeD = headers.add(2, "D")
        nodeB = headers.add(1, "B")
        nodeD = headers.add(2, "D")

        headers.processOneFile()

        self.assertFalse(nodeA.isIncluded())
        self.assertFalse(nodeB.isIncluded())
        self.assertFalse(nodeC.isIncluded())
        self.assertFalse(nodeD.isIncluded())

        self.assertEqual(nodeA.getColor(), DfsNode.White)
        self.assertEqual(nodeB.getColor(), DfsNode.White)
        self.assertEqual(nodeC.getColor(), DfsNode.White)

        self.assertTrue(nodeA.getCounter(), 2)
        self.assertTrue(nodeB.getCounter(), 2)
        self.assertTrue(nodeC.getCounter(), 1)
        self.assertTrue(nodeD.getCounter(), 1)
예제 #4
0
class TestRecursiveFilter( unittest.TestCase ):
    def setUp( self ):
        self._dag = HeadersDag()

        # a
        #  b
        #   c
        #  c

        self._a = self._dag.add( 1, "a" )
        self._b = self._dag.add( 2, "b" )
        self._c = self._dag.add( 3, "c" )
        self._c = self._dag.add( 2, "c" )
        self._dag.processOneFile()

        self._options = OptionsMock()

        self._tSorter = TopologicalSorter( self._dag )

    def test_1( self ):
        rFilter = RecursiveFilter( self._tSorter, (lambda x: x.getData() == "a"), self._options )

        self.assertFalse( self._a.isIncluded() )
        self.assertFalse( self._b.isIncluded() )
        self.assertFalse( self._c.isIncluded() )

        self.assertEqual( self._a.getColor(), DfsNode.White )
        self.assertEqual( self._b.getColor(), DfsNode.White )
        self.assertEqual( self._c.getColor(), DfsNode.White )

        self.assertEqual( rFilter.getNodes(), [ self._a ] )

    def test_2( self ):
        rFilter = RecursiveFilter( self._tSorter, (lambda x: x.getData() == "b"), self._options )

        self.assertFalse( self._a.isIncluded() )
        self.assertFalse( self._b.isIncluded() )
        self.assertFalse( self._c.isIncluded() )

        self.assertEqual( self._a.getColor(), DfsNode.White )
        self.assertEqual( self._b.getColor(), DfsNode.White )
        self.assertEqual( self._c.getColor(), DfsNode.White )

        self.assertEqual( rFilter.getNodes(), [ self._b ] )

    def test_3( self ):
        rFilter = RecursiveFilter( self._tSorter, (lambda x: x.getData() == "c"), self._options )

        self.assertFalse( self._a.isIncluded() )
        self.assertFalse( self._b.isIncluded() )
        self.assertFalse( self._c.isIncluded() )

        self.assertEqual( self._a.getColor(), DfsNode.White )
        self.assertEqual( self._b.getColor(), DfsNode.White )
        self.assertEqual( self._c.getColor(), DfsNode.White )

        self.assertEqual( rFilter.getNodes(), [ self._c ] )

    def test_4( self ):
        rFilter = RecursiveFilter( self._tSorter, (lambda x: True), self._options )

        self.assertFalse( self._a.isIncluded() )
        self.assertFalse( self._b.isIncluded() )
        self.assertFalse( self._c.isIncluded() )

        self.assertEqual( self._a.getColor(), DfsNode.White )
        self.assertEqual( self._b.getColor(), DfsNode.White )
        self.assertEqual( self._c.getColor(), DfsNode.White )

        self.assertEqual( rFilter.getNodes(), [ self._a ] )

    def test_5( self ):
        rFilter = RecursiveFilter( self._tSorter, (lambda x: False), self._options )

        self.assertFalse( self._a.isIncluded() )
        self.assertFalse( self._b.isIncluded() )
        self.assertFalse( self._c.isIncluded() )

        self.assertEqual( self._a.getColor(), DfsNode.White )
        self.assertEqual( self._b.getColor(), DfsNode.White )
        self.assertEqual( self._c.getColor(), DfsNode.White )

        self.assertEqual( rFilter.getNodes(), [] )
예제 #5
0
class TestRecursiveFilter(unittest.TestCase):
    def setUp(self):
        self._dag = HeadersDag()

        # a
        #  b
        #   c
        #  c

        self._a = self._dag.add(1, "a")
        self._b = self._dag.add(2, "b")
        self._c = self._dag.add(3, "c")
        self._c = self._dag.add(2, "c")
        self._dag.processOneFile()

        self._options = OptionsMock()

        self._tSorter = TopologicalSorter(self._dag)

    def test_1(self):
        rFilter = RecursiveFilter(self._tSorter,
                                  (lambda x: x.getData() == "a"),
                                  self._options)

        self.assertFalse(self._a.isIncluded())
        self.assertFalse(self._b.isIncluded())
        self.assertFalse(self._c.isIncluded())

        self.assertEqual(self._a.getColor(), DfsNode.White)
        self.assertEqual(self._b.getColor(), DfsNode.White)
        self.assertEqual(self._c.getColor(), DfsNode.White)

        self.assertEqual(rFilter.getNodes(), [self._a])

    def test_2(self):
        rFilter = RecursiveFilter(self._tSorter,
                                  (lambda x: x.getData() == "b"),
                                  self._options)

        self.assertFalse(self._a.isIncluded())
        self.assertFalse(self._b.isIncluded())
        self.assertFalse(self._c.isIncluded())

        self.assertEqual(self._a.getColor(), DfsNode.White)
        self.assertEqual(self._b.getColor(), DfsNode.White)
        self.assertEqual(self._c.getColor(), DfsNode.White)

        self.assertEqual(rFilter.getNodes(), [self._b])

    def test_3(self):
        rFilter = RecursiveFilter(self._tSorter,
                                  (lambda x: x.getData() == "c"),
                                  self._options)

        self.assertFalse(self._a.isIncluded())
        self.assertFalse(self._b.isIncluded())
        self.assertFalse(self._c.isIncluded())

        self.assertEqual(self._a.getColor(), DfsNode.White)
        self.assertEqual(self._b.getColor(), DfsNode.White)
        self.assertEqual(self._c.getColor(), DfsNode.White)

        self.assertEqual(rFilter.getNodes(), [self._c])

    def test_4(self):
        rFilter = RecursiveFilter(self._tSorter, (lambda x: True),
                                  self._options)

        self.assertFalse(self._a.isIncluded())
        self.assertFalse(self._b.isIncluded())
        self.assertFalse(self._c.isIncluded())

        self.assertEqual(self._a.getColor(), DfsNode.White)
        self.assertEqual(self._b.getColor(), DfsNode.White)
        self.assertEqual(self._c.getColor(), DfsNode.White)

        self.assertEqual(rFilter.getNodes(), [self._a])

    def test_5(self):
        rFilter = RecursiveFilter(self._tSorter, (lambda x: False),
                                  self._options)

        self.assertFalse(self._a.isIncluded())
        self.assertFalse(self._b.isIncluded())
        self.assertFalse(self._c.isIncluded())

        self.assertEqual(self._a.getColor(), DfsNode.White)
        self.assertEqual(self._b.getColor(), DfsNode.White)
        self.assertEqual(self._c.getColor(), DfsNode.White)

        self.assertEqual(rFilter.getNodes(), [])