コード例 #1
0
ファイル: test_PpLexerLimits.py プロジェクト: cybort/cpip
 def test_01(self):
     """Tests 5.2.4.1 Translation limits - 64 nesting levels of conditional inclusion, non-exhaustive."""
     myIntRepr = self.retIntRep()
     myIncHandler = self.retIncHandler()
     print('self._itu size: %d' % len(self._itu.getvalue()))
     print('self._itu:\n', self._itu.getvalue())
     while 1:
         #print 'myIntRepr:', myIntRepr
         #print
         #print 'myIntRepr:', myIntRepr
         myLexer = PpLexer.PpLexer(
             'mt.h',
             myIncHandler,
             preIncFiles=[
                 io.StringIO(self.retPreIncludeMacros(myIntRepr)),
             ],
             diagnostic=None,
         )
         myToks = [t for t in myLexer.ppTokens() if not t.isWs()]
         #print '      Got:', myToks
         expToks = self.retExpTokensNoWs(myIntRepr)
         #print ' Expected:', expToks
         # TODO: Fix this test
         self.assertEqual(expToks, myToks)
         myLexer.finalise()
         if myIntRepr == 0:
             break
         myIntRepr -= 1
コード例 #2
0
    def testSimpleInclude(self):
        """TestIncludeHandler_UsrSys_MultipleDepth.testSimpleInclude(): Tests multiple depth #include statements that resolve to usr/sys."""
        #print
        myLexer = PpLexer.PpLexer('src/spam.c', self._incSim)
        result = ''.join([t.t for t in myLexer.ppTokens()])
        expectedResult = """Content of: system, include, spam.h\n\n\n\n\n"""
        self._printDiff(self.stringToTokens(result),
                        self.stringToTokens(expectedResult))
        self.assertEqual(result, expectedResult)
        myLexer.finalise()
        #print 'FileIncludeGraph:'
        #print myLexer.fileIncludeGraphRoot
        expGraph = """src/spam.c [0, 0]:  True "" ""
000001: #include usr/spam.h
  usr/spam.h [0, 0]:  True "" "['"spam.h"', 'CP=None', 'usr=usr']"
  000001: #include usr/inc/spam.h
    usr/inc/spam.h [0, 0]:  True "" "['"inc/spam.h"', 'CP=usr']"
    000001: #include sys/spam.h
      sys/spam.h [0, 0]:  True "" "['<spam.h>', 'sys=sys']"
      000001: #include sys/inc/spam.h
        sys/inc/spam.h [15, 10]:  True "" "['<inc/spam.h>', 'sys=sys']\""""
        # print('\nFileIncludeGraph:')
        # print('Actual:')
        # print(str(myLexer.fileIncludeGraphRoot))
        # print('Expected:')
        # print(str(expGraph))
        self.assertEqual(expGraph, str(myLexer.fileIncludeGraphRoot))
コード例 #3
0
    def testSimpleInclude_03(self):
        """TestIncludeHandler_UsrSys_Conditional.testSimpleInclude_03(): Tests conditional #include statements."""
        preDefMacros = [
            u"""#define INC 3
""",
        ]
        myLexer = PpLexer.PpLexer(
            'src/spam.c',
            self._incSim,
            preIncFiles=[StringIO.StringIO(x) for x in preDefMacros],
        )
        result = ''.join([t.t for t in myLexer.ppTokens()])
        expectedResult = """\n\nContent of: system, include, spam.h\n\n\n"""
        self._printDiff(self.stringToTokens(result),
                        self.stringToTokens(expectedResult))
        self.assertEqual(result, expectedResult)
        myLexer.finalise()
        #print 'FileIncludeGraph:'
        #print myLexer.fileIncludeGraphRoot
        expGraph = """Unnamed Pre-include [7, 4]:  True "" ""
src/spam.c [0, 0]:  True "" ""
000008: #include sys/inc/spam.h
  sys/inc/spam.h [15, 10]:  True "(!(INC == 0) && !(INC == 1) && !(INC == 2) && INC == 3)" "['<inc/spam.h>', 'sys=sys']\""""
        # print('\nFileIncludeGraph:')
        # print('Actual:')
        # print(str(myLexer.fileIncludeGraphRoot))
        # print('Expected:')
        # print(str(expGraph))
        self.assertEqual(expGraph, str(myLexer.fileIncludeGraphRoot))
コード例 #4
0
    def test_00(self):
        """TestPpLexerCoverage.test_00(): Tests code coverage."""
        #print
        myLexer = PpLexer.PpLexer('src/spam.c', self._incSim)
        resultTokS = [t for t in myLexer.ppTokens()]
        #self.pprintReplacementList(resultTokS)
        return
        assert (0)
        result = ''.join([t.t for t in resultTokS])
        expectedResult = """ \n\n \n\nContent of: system, include, spam.h\n\n\n\n\n"""
        self._printDiff(self.stringToTokens(result),
                        self.stringToTokens(expectedResult))
        self.assertEqual(result, expectedResult)
        myLexer.finalise()
        #print 'FileIncludeGraph:'
        #print myLexer.fileIncludeGraphRoot
        expGraph = """src/spam.c [20, 10]:  True ""
000002: #include usr\spam.h
        usr\spam.h [0, 0]:  True ""
        000001: #include usr\inc\spam.h
                usr\inc\spam.h [0, 0]:  True ""
                000001: #include sys\spam.h
                        sys\spam.h [0, 0]:  True ""
                        000001: #include sys\inc\spam.h
                                sys\inc\spam.h [15, 10]:  True \"\""""
        self.assertEqual(expGraph, str(myLexer.fileIncludeGraphRoot))
コード例 #5
0
    def testSimpleInclude_01(self):
        """TestIncludeHandler_UsrSys_Conditional.testSimpleInclude_01(): Tests conditional #include statements."""
        # Note using comments in the predef
        preDefMacros = [
            u"""#define INC /* comment */ 1
""",
        ]
        myLexer = PpLexer.PpLexer(
            'src/spam.c',
            self._incSim,
            preIncFiles=[StringIO.StringIO(x) for x in preDefMacros],
        )
        result = ''.join([t.t for t in myLexer.ppTokens()])
        expectedResult = """\n\nContent of: user, include, spam.h\n\n\n"""
        self._printDiff(self.stringToTokens(result),
                        self.stringToTokens(expectedResult))
        self.assertEqual(result, expectedResult)
        myLexer.finalise()
        #print 'FileIncludeGraph:'
        #print myLexer.fileIncludeGraphRoot
        expGraph = """Unnamed Pre-include [9, 4]:  True "" ""
src/spam.c [0, 0]:  True "" ""
000004: #include usr/inc/spam.h
  usr/inc/spam.h [15, 10]:  True "(!(INC == 0) && INC == 1)" "['"inc/spam.h"', 'CP=None', 'usr=usr']\""""
        # print('\nFileIncludeGraph:')
        # print('Actual:')
        # print(str(myLexer.fileIncludeGraphRoot))
        # print('Expected:')
        # print(str(expGraph))
        self.assertEqual(expGraph, str(myLexer.fileIncludeGraphRoot))
コード例 #6
0
def main():
    print('Processing:', sys.argv[1])
    myH = IncludeHandler.CppIncludeStdOs(
        theUsrDirs=[
            '../usr',
        ],
        theSysDirs=[
            '../sys',
        ],
    )
    myLex = PpLexer.PpLexer(sys.argv[1], myH)
    tu = ''.join(tok.t for tok in myLex.ppTokens(minWs=True))
    print(' Translation Unit '.center(75, '='))
    print(tu)
    print(' Translation Unit END '.center(75, '='))
    print()
    print(' File Include Graph '.center(75, '='))
    print(repr(myLex.fileIncludeGraphRoot))
    print(myLex.fileIncludeGraphRoot)
    print(' File Include Graph END '.center(75, '='))
    print()
    print(' Conditional Compilation Graph '.center(75, '='))
    print(myLex.condCompGraph)
    print(' Conditional Compilation Graph END '.center(75, '='))
    print()
    print(' Macro Environment '.center(75, '='))
    print(myLex.macroEnvironment)
    print(' Macro Environment END '.center(75, '='))
    print()
    print(' Macro History '.center(75, '='))
    print(myLex.macroEnvironment.macroHistory(incEnv=False, onlyRef=False))
    print(' Macro History END '.center(75, '='))
コード例 #7
0
ファイル: cpip_99.py プロジェクト: cybort/cpip
def main():
    try:
        print 'Processing:', sys.argv[1]
        myH = IncludeHandler.CppIncludeStdOs(
            theUsrDirs=[
                '../usr',
            ],
            theSysDirs=[
                '../sys',
            ],
        )
        myLex = PpLexer.PpLexer(sys.argv[1], myH)
        m = hashlib.md5()
        for tok in myLex.ppTokens(minWs=True, incCond=False):
            m.update(tok.t)
            #print tok
            #print tok.t,
            #print myLex.condState
            #print 'Bad File: %s, line %d, col %d' % (myLex.fileName, myLex.lineNum, myLex.colNum)
            #print myLex.fileStack
        #print
        #print myLex.fileIncludeGraphRoot
        #print
        #print myLex.definedMacros
        print
        print myLex.macroEnvironment.macroHistory(onlyRef=False)
        print
        print 'Checksum is: %s' % m.hexdigest()
        print
        print myLex._tokCountStk
    except ExceptionCpip, err:
        print 'Ooops: %s' % err
コード例 #8
0
ファイル: cpp.py プロジェクト: cybort/cpip
def _processFile(ituName,
                 incHandler,
                 stdPredefMacros,
                 preIncFiles,
                 showTokens,
                 dOptions):
    """Process the file."""
    myLexer = PpLexer.PpLexer(
                              ituName,
                              incHandler,
                              preIncFiles=preIncFiles,
                              stdPredefMacros=stdPredefMacros,
                              )
    tokenS = [tok for tok in myLexer.ppTokens(incWs=True, minWs=True, condLevel=0)]
    if 'D' in dOptions or len(dOptions) == 0:
        print(' Translation unit '.center(75, '-'))
        for tok in tokenS:
            if showTokens:
                print(tok)
            else:
                print(tok.t, end='')
        print(' END: Translation unit '.center(75, '-'))
    if 'M' in dOptions or 'D' in dOptions or 'N' in dOptions:
        print(' Macros '.center(75, '-'))
        if 'N' in dOptions:
            for m in sorted(myLexer.macroEnvironment.macros()):
                print(m)
        else:
            print(myLexer.macroEnvironment)
        print(' END: Macros '.center(75, '-'))
コード例 #9
0
ファイル: test_PpLexerPerf.py プロジェクト: cybort/cpip
 def test_00(self):
     """Test the time taken to process a 'real' code in test/PerfRealCode."""
     for aName in os.listdir(self.REAL_PATH):
         sys.stderr.write('\n')
         sys.stderr.write("Testing '%s' " % aName)
         myPath = os.path.join(self.REAL_PATH, aName)
         mySize = os.path.getsize(myPath)
         if sys.version_info.major == 2 and aName in ('doxygen.cpp',
                                                      'util.cpp'):
             # Under 2.7 this fails with Unicode EOL for some reason so just skip it:
             #
             # doxygen.cpp:
             # ExceptionCppDiagnosticUndefined: Can not evaluate constant expression
             # "!defined(_WIN32) || defined(__CYGWIN__)\u000D", error:
             # Evaluation of " (1)  or  (0)0 " gives error:
             # invalid syntax (<string>, line 1) at line=93, col=1 of file
             # "cpip/tests/integration/core/PerfRealCode/doxygen.cpp"
             #
             # util.cpp:
             # ExceptionCppDiagnosticUndefined: Can not evaluate constant expression
             # "0\u000D", error: Evaluation of " 0\u000D " gives error:
             # unexpected character after line continuation character
             # (<string>, line 1) at line=2510, col=1 of file
             # "cpip/tests/integration/core/PerfRealCode/util.cpp"
             continue
         myLexer = PpLexer.PpLexer(
             myPath,
             CppIncludeStdOs([], []),
             preIncFiles=[],
             diagnostic=None,
         )
         myToks, myTime = self.runLex(myLexer)
         sys.stderr.write(' %0.1f kB/S ' % (mySize / (1024 * myTime)))
コード例 #10
0
ファイル: test_PpLexerPerf.py プロジェクト: cybort/cpip
 def simpleLexWithContent(self, theContent):
     return PpLexer.PpLexer(
         'mt.h',
         CppIncludeStringIO([], [], theContent, {}),
         preIncFiles=[],
         diagnostic=None,
     )
コード例 #11
0
 def test_00(self):
     """CPIP core code coverage test."""
     myLexer = PpLexer.PpLexer(
              'mt.h',
              CppIncludeStringIO([], [], '', {}),
              )
     myToks = [t for t in myLexer.ppTokens()]
     self.assertEqual([], myToks)
     myLexer.finalise()
コード例 #12
0
def main():
    print('Processing:', sys.argv[1])
    myH = IncludeHandler.CppIncludeStdOs(
        theUsrDirs=['../usr',],
        theSysDirs=['../sys',],
        )
    myLex = PpLexer.PpLexer(sys.argv[1], myH)
    tu = ''.join(tok.t for tok in myLex.ppTokens(minWs=True))
    print(repr(myLex.fileIncludeGraphRoot))
コード例 #13
0
def main():
    print('Processing:', sys.argv[1])
    myH = IncludeHandler.CppIncludeStdOs(
        theUsrDirs=[
            'proj/usr',
        ],
        theSysDirs=[
            'proj/sys',
        ],
    )
    myLex = PpLexer.PpLexer(sys.argv[1], myH)
コード例 #14
0
def main():
    print('Processing:', sys.argv[1])
    myH = IncludeHandler.CppIncludeStdOs(
        theUsrDirs=[
            'proj/usr',
        ],
        theSysDirs=[
            'proj/sys',
        ],
    )
    myLex = PpLexer.PpLexer(sys.argv[1], myH)
    for tok in myLex.ppTokens():
        print(tok.t, end=' ')
コード例 #15
0
ファイル: test_PpLexerLimits.py プロジェクト: cybort/cpip
 def test_00(self):
     """Tests 5.2.4.1 Translation limits - 8 nesting levels of conditional inclusion, no predefines."""
     myLexer = PpLexer.PpLexer(
         'mt.h',
         self.retIncHandler(),
         preIncFiles=[
             io.StringIO(u'#define SPAM(x,y) x+y\n#define EGGS SPAM\n'),
         ],
         diagnostic=None,
     )
     myToks = [t for t in myLexer.ppTokens() if not t.isWs()]
     self.assertEqual(self.retExpTokensNoWs(0), myToks)
     myLexer.finalise()
コード例 #16
0
    def testSimpleInclude(self):
        """TestIncludeHandlerMacro_Simple.testSimpleInclude(): Tests multiple #include statements that resolve to usr/sys when expanded."""
        myLexer = PpLexer.PpLexer('src/spam.c', self._incSim)
        result = ''.join([t.t for t in myLexer.ppTokens()])
        expectedResult = """
Content of: user, spam.h

"""
        #print '  Actual:\n%s' % result
        #print 'Expected:\n%s' % expectedResult
        self._printDiff(self.stringToTokens(result),
                        self.stringToTokens(expectedResult))
        self.assertEqual(result, expectedResult)
        myLexer.finalise()
コード例 #17
0
ファイル: TestPpLexerPerf.py プロジェクト: csarn/cpip
 def test_00(self):
     """Test the time taken to process a 'real' code in test/PerfRealCode."""
     for aName in os.listdir(self.REAL_PATH):
         sys.stderr.write('\n')
         sys.stderr.write("Testing '%s' " % aName)
         myPath = os.path.join(self.REAL_PATH, aName)
         mySize = os.path.getsize(myPath)
         myLexer = PpLexer.PpLexer(
                  myPath,
                  CppIncludeStdOs([],[]),
                  preIncFiles=[],
                  diagnostic=None,
                  )
         myToks, myTime = self.runLex(myLexer)
         sys.stderr.write(' %0.1f kB/S ' % (mySize/(1024*myTime)))
コード例 #18
0
def main():
    print('Processing:', sys.argv[1])
    myH = IncludeHandler.CppIncludeStdOs(
        theUsrDirs=[
            '../usr',
        ],
        theSysDirs=[
            '../sys',
        ],
    )
    myLex = PpLexer.PpLexer(sys.argv[1], myH)
    tu = ''.join(tok.t for tok in myLex.ppTokens(minWs=True))
    myVis = FileIncludeGraph.FigVisitorTree(MyVisitorTreeNode)
    myLex.fileIncludeGraphRoot.acceptVisitor(myVis)
    myTree = myVis.tree()
    print(myTree)
コード例 #19
0
    def testSimpleInclude(self):
        """TestIncludeHandler_UsrSys_MacroFunction.testSimpleInclude(): Tests multiple #include statements with function-like macros."""
        myLexer = PpLexer.PpLexer('src/spam.c', self._incSim)
        result = ''.join([t.t for t in myLexer.ppTokens()])
        expectedResult = """
Content of: user, spam.h

Content of: user, include, spam.h
\n\n
Content of: system, spam.h

Content of: system, include, spam.h
\n"""
        #print '  Actual:\n%s' % result
        #print 'Expected:\n%s' % expectedResult
        self._printDiff(self.stringToTokens(result),
                        self.stringToTokens(expectedResult))
        self.assertEqual(result, expectedResult)
        myLexer.finalise()
コード例 #20
0
def preProcessForIncludes(theItu, incUsr, incSys, theDefineS, preIncS,
                          keepGoing, ignorePragma):
    """Pre-process a file for included files."""
    myIncH = IncludeHandler.CppIncludeStdOs(
        theUsrDirs=incUsr or [],
        theSysDirs=incSys or [],
    )
    myPreIncFiles = []
    # Add macros in psuedo pre-include
    if theDefineS:
        myStr = '\n'.join(
            ['#define ' + ' '.join(d.split('=')) for d in theDefineS]) + '\n'
        myPreIncFiles = [
            io.StringIO(myStr),
        ]
    myPreIncFiles.extend([open(f) for f in preIncS])
    myDiag = None
    if keepGoing:
        myDiag = CppDiagnostic.PreprocessDiagnosticKeepGoing()
    myPh = None
    if ignorePragma:
        myPh = PragmaHandler.PragmaHandlerNull()
    # Create the lexer.
    myLexer = PpLexer.PpLexer(
        theItu,
        myIncH,
        preIncFiles=myPreIncFiles,
        diagnostic=myDiag,
        pragmaHandler=myPh,
    )
    logging.info('Preprocessing TU: %s' % theItu)
    for t in myLexer.ppTokens():
        pass
    logging.info('Preprocessing TU done.')
    retVal = retIncludedFileSet(myLexer)
    # Remove any artificial files
    try:
        retVal.remove(PpLexer.UNNAMED_FILE_NAME)
    except KeyError:
        pass
    return retVal
コード例 #21
0
ファイル: cpp.py プロジェクト: h4ck3rm1k3/gcc-introspector
def tree_codes(file_name):
    report = []
    #print('Processing:', )
    myH = IncludeHandler.CppIncludeStdOs(
        theUsrDirs=[
            'proj/usr',
        ],
        theSysDirs=[
            'proj/sys',
        ],
    )
    myLex = PpLexer.PpLexer(file_name, myH)
    stack = []
    for tok in myLex.ppTokens():
        if tok.t == '\n':
            code = ("".join(stack))
            if re.match(r'^\s+$', code):
                pass
            else:
                if code:
                    # macro name
                    # class name
                    # class of node
                    # arguments?
                    #print "CODE(%s)"% code;
                    m = re.match(r'DEFTREECODE\((\w+),\"(\w+)",(\w+),(\d)\)',
                                 code)
                    report.append(m.groups())
            stack = []
        else:
            if tok.t == ' ':
                pass
            elif re.match(r'^[\s\n\t]*$', tok.t):
                pass
            else:
                #print "TOK(%s)" % tok.t
                stack.append(tok.t)
    return report
コード例 #22
0
ファイル: cpip_00.py プロジェクト: cybort/cpip
def main():
    print('Processing:', sys.argv[1])
    myH = IncludeHandler.CppIncludeStdOs(
        theUsrDirs=[
            '../usr',
        ],
        theSysDirs=[
            '../sys',
        ],
    )

    myLex = PpLexer.PpLexer(sys.argv[1], myH)
    for tok in myLex.ppTokens(minWs=True):
        #        print(tok.t, end=' ')
        #        print(myLex.condState)
        #        print(myLex.fileStack)
        #        print(myLex.fileLineCol)
        print(myLex.macroEnvironment)
    print(' File Include Graph '.center(75, '='))
    print(myLex.fileIncludeGraphRoot)
    print(' File Include Graph END '.center(75, '='))
    print(' Macro Environment '.center(75, '='))
    print(myLex.macroEnvironment)
    print(' Macro Environment END '.center(75, '='))
コード例 #23
0
def preprocessFileToOutput(ituPath, outDir, jobSpec):
    """Preprocess a single file. May raise ExceptionCpip (or worse!).
    Returns a PpProcessResult(ituPath, indexPath, tuIndexFileName(ituPath))."""
    assert os.path.isfile(ituPath)
    logging.info('preprocessFileToOutput(): %s' % ituPath)
    if not os.path.exists(outDir):
        try:
            os.makedirs(outDir)
        except OSError:
            pass
    myItuToHtmlFileSet = set()
    # Create the lexer.
    myLexer = PpLexer.PpLexer(ituPath,
                              jobSpec.incHandler,
                              preIncFiles=jobSpec.preIncFiles,
                              diagnostic=jobSpec.diagnostic,
                              pragmaHandler=jobSpec.pragmaHandler,
                              stdPredefMacros=jobSpec.preDefMacros,
                              gccExtensions=jobSpec.gccExtensions)
    myDestFile = os.path.join(outDir, tuFileName(ituPath))
    logging.info('TU in HTML:')
    logging.info('  %s', myDestFile)
    myTokCntr, mySetItuLines = Tu2Html.processTuToHtml(
        myLexer,
        myDestFile,
        ituPath,
        jobSpec.conditionalLevel,
        tuIndexFileName(ituPath),  # Path back to the index
        incItuAnchors=True,
    )
    logging.info('preprocessFileToOutput(): Processing TU done.')
    myFileCountMap = retFileCountMap(myLexer)
    # Write out the HTML for each source file
    for aSrc in sorted(myFileCountMap.keys()):
        myItuToHtmlFileSet.add(aSrc)
    # Now output state
    # Conditional compilation graph
    if 'C' in jobSpec.dumpList:
        _dumpCondCompGraph(myLexer)
    # File include graph
    if 'I' in jobSpec.dumpList:
        _dumpIncludeGraph(myLexer)
    # List files encountered
    if 'F' in jobSpec.dumpList:
        _dumpFileCount(myFileCountMap)
    # Token count
    if 'T' in jobSpec.dumpList:
        _dumpTokenCount(myTokCntr)
    # Macro environment
    if 'M' in jobSpec.dumpList:
        _dumpMacroEnv(myLexer)
    if 'R' in jobSpec.dumpList:
        _dumpMacroEnvDot(myLexer)
    # Macro environment and history


#     outPath = os.path.join(outDir, macroHistoryFileName(ituPath))
    logging.info('Macro history to:')
    logging.info('  %s', outDir)
    myMacroRefMap, macroHistoryIndexName = MacroHistoryHtml.processMacroHistoryToHtml(
        myLexer,
        outDir,
        ituPath,
        tuIndexFileName(ituPath),
    )
    # Write Include graph in SVG
    outPath = os.path.join(outDir, includeGraphFileNameSVG(ituPath))
    logging.info('Include graph (SVG) to:')
    logging.info('  %s', outPath)
    IncGraphSVGBase.processIncGraphToSvg(
        myLexer,
        outPath,
        IncGraphSVG.SVGTreeNodeMain,
        'left',
        '+',
    )
    # Write Include graph in Text
    logging.info('Writing include graph (TEXT) to:')
    logging.info('  %s', outPath)
    writeIncludeGraphAsText(outDir, ituPath, myLexer)
    # Include graph as a dot file
    if jobSpec.includeDOT:
        logging.info('Writing include graph (DOT) to:')
        logging.info('  %s', outPath)
        hasIncGraphDot = writeIncludeGraphAsDot(outDir, ituPath, myLexer)
    else:
        hasIncGraphDot = False
    # Write Conditional compilation graph in HTML
    outPath = os.path.join(outDir, includeGraphFileNameCcg(ituPath))
    logging.info('Conditional compilation graph in HTML:')
    logging.info('  %s', outPath)
    CppCondGraphToHtml.processCppCondGrphToHtml(
        myLexer,
        outPath,
        'Conditional Compilation Graph',
        tuIndexFileName(ituPath),
    )
    # This is an index for the TU
    writeTuIndexHtml(outDir, ituPath, myLexer, myFileCountMap, myTokCntr,
                     hasIncGraphDot, macroHistoryIndexName)
    logging.info('Done: %s', ituPath)
    # Write ITU HTML i.e. HTMLise the original files
    # Create a CppCondGraphVisitorConditionalLines
    myCcgvcl = CppCond.CppCondGraphVisitorConditionalLines()
    myLexer.condCompGraph.visit(myCcgvcl)
    for aSrc in sorted(myItuToHtmlFileSet):
        try:
            # Could be 'Unnamed Pre-include'
            if aSrc != PpLexer.UNNAMED_FILE_NAME:
                logging.info('ITU in HTML: .../%s', os.path.basename(aSrc))
                ItuToHtml.ItuToHtml(
                    aSrc,
                    outDir,
                    keepGoing=jobSpec.keepGoing,
                    macroRefMap=myMacroRefMap,
                    cppCondMap=myCcgvcl,
                    ituToTuLineSet=mySetItuLines if aSrc == ituPath else None,
                )
        except ItuToHtml.ExceptionItuToHTML as err:
            logging.error('Can not write ITU "%s" to HTML: %s', aSrc, str(err))
    indexPath = writeIndexHtml([
        ituPath,
    ], outDir, jobSpec)
    logging.info('preprocessFileToOutput(): %s DONE' % ituPath)
    # Return the path to the ITU and to the index.html path for consolidation
    # by the caller - to be used in multiprocessing.
    return PpProcessResult(ituPath, indexPath, tuIndexFileName(ituPath))
コード例 #24
0
    def test_00(self):
        _pathsUsr = [
            os.path.join('usr'),
            os.path.join('usr', 'inc'),
        ]
        _pathsSys = [
            os.path.join('sys'),
            os.path.join('sys', 'inc'),
        ]
        _initialTuContents = u"""Include usr/spam:
#include "spam.h"
Include usr/inc/eggs:
#include "inc/eggs.h"
Include sys/chips:
#include <chips.h>
Include sys/inc/beans:
#include <inc/beans.h>
"""
        _incFileMap = {
            os.path.join('usr', 'spam.h'):
            u"""Content of: user, spam.h
""",
            os.path.join('usr', 'inc', 'eggs.h'):
            u"""Content of: user, include, eggs.h
Which is much bigger.""",
            os.path.join('sys', 'chips.h'):
            u"""chips.h
""",
            os.path.join('sys', 'inc', 'beans.h'):
            u"""Content of: system, include, beans.h
Which is very big, 1, def, 345,
and loads of other things.
""",
        }
        _incSim = CppIncludeStringIO(
            _pathsUsr,
            _pathsSys,
            _initialTuContents,
            _incFileMap,
        )
        _incSim.validateCpStack()
        self.assertEqual([], _incSim.cpStack)
        self.assertEqual(0, _incSim.cpStackSize)
        myLexer = PpLexer.PpLexer('src/spam.c', _incSim)
        result = ''.join([t.t for t in myLexer.ppTokens()])
        #        print('Result:')
        #        print(result)
        expectedResult = """Include usr/spam:
Content of: user, spam.h

Include usr/inc/eggs:
Content of: user, include, eggs.h
Which is much bigger.
Include sys/chips:
chips.h

Include sys/inc/beans:
Content of: system, include, beans.h
Which is very big, 1, def, 345,
and loads of other things.

"""
        self.assertEqual(result, expectedResult)
        myLexer.finalise()
        myFigr = myLexer.fileIncludeGraphRoot
        #         print('FileIncludeGraph:')
        #         print(myFigr)
        # WARN: excape \b (two places on last two lines
        expGraph = """src/spam.c [32, 24]:  True "" ""
000002: #include usr/spam.h
  usr/spam.h [12, 8]:  True "" "['"spam.h"', 'CP=None', 'usr=usr']"
000004: #include usr/inc/eggs.h
  usr/inc/eggs.h [23, 15]:  True "" "['"inc/eggs.h"', 'CP=None', 'usr=usr']"
000006: #include sys/chips.h
  sys/chips.h [4, 3]:  True "" "['<chips.h>', 'sys=sys']"
000008: #include sys/inc/beans.h
  sys/inc/beans.h [44, 27]:  True "" "['<inc/beans.h>', 'sys=sys']\""""
        #         print('Exp FileIncludeGraph:')
        #         print(expGraph)
        #         self.maxDiff = None
        #for i, c in enumerate(str(myFigr)):
        #    if c != expGraph[i]:
        #        print '[%d] %s != %s' % (i, c, expGraph[i])
        self.assertEqual(expGraph, str(myFigr))
        #         print()
        #         myFigr.dumpGraph()
        self.assertEqual(expGraph, str(myFigr))
        # Now visit the graph
        myVis = FileIncludeGraph.FigVisitorTree(IncGraphSVG.SVGTreeNodeMain)
        myFigr.acceptVisitor(myVis)
        # Tree is now a graph of IncGraphSVG.SVGTreeNode
        myIgs = myVis.tree()
        #         print()
        #         print('myIgs')
        #print myIgs
        #         myIgs.dumpToStream()
        #         print()
        # Create a plot configuration
        myTpt = TreePlotTransform.TreePlotTransform(myIgs.plotCanvas, 'left',
                                                    '+')
        mySvg = io.StringIO()
        myIgs.plotToFileObj(mySvg, myTpt)
        #         print()
        #         print(mySvg.getvalue())
        for aPos in myTpt.genRootPos():
            for aDir in myTpt.genSweepDir():
                aTpt = TreePlotTransform.TreePlotTransform(
                    myIgs.plotCanvas, aPos, aDir)
                mySvg = io.StringIO()
                myIgs.plotToFileObj(mySvg, aTpt)