| 321 | # list of g++ preprocessed C/C++ files to analyze |
| 322 | # |
| 323 | def processFile(inputFile, mapOutputFilename): |
| 324 | functionGenerator = FunctionGenerator() |
| 325 | directiveRegex = re.compile("^# (\d+) \"(.*)\"(.*)") |
| 326 | |
| 327 | with open(inputFile) as f, open(inputFile + "i", 'w') as output: |
| 328 | try: |
| 329 | lines = f.readlines() |
| 330 | lineIndex = -1 |
| 331 | |
| 332 | lastChar = '\0' |
| 333 | |
| 334 | # Logical location in a file based on GNU Preprocessor directives |
| 335 | ppFileName = inputFile |
| 336 | ppLineNum = 0 |
| 337 | |
| 338 | # Notes the first filename referenced by the pre-processor directives |
| 339 | # which should be the name of the file being compiled. |
| 340 | firstFilename = None |
| 341 | |
| 342 | # Marks at which line the preprocessor can start safely injecting |
| 343 | # generated, inlined code. A value of None indicates that the NanoLog |
| 344 | # header was not #include-d yet |
| 345 | inlineCodeInjectionLineIndex = None |
| 346 | |
| 347 | # Scan through the lines of the file parsing the preprocessor directives, |
| 348 | # identfying log statements, and replacing them with generated code. |
| 349 | while lineIndex < len(lines) - 1: |
| 350 | lineIndex = lineIndex + 1 |
| 351 | line = lines[lineIndex] |
| 352 | |
| 353 | # Keep track of of the preprocessor line number so that we can |
| 354 | # put in our own line markers as we inject code into the file |
| 355 | # and report errors. This line number should correspond to the |
| 356 | # actual user source line number. |
| 357 | ppLineNum = ppLineNum + 1 |
| 358 | |
| 359 | # Parse special preprocessor directives that follows the format |
| 360 | # '# lineNumber "filename" flags' |
| 361 | if line[0] == "#": |
| 362 | directive = directiveRegex.match(line) |
| 363 | if directive: |
| 364 | # -1 since the line num describes the line after it, not the |
| 365 | # current one, so we decrement it here before looping |
| 366 | ppLineNum = int(float(directive.group(1))) - 1 |
| 367 | |
| 368 | ppFileName = directive.group(2) |
| 369 | if not firstFilename: |
| 370 | firstFilename = ppFileName |
| 371 | |
| 372 | flags = directive.group(3).strip() |
| 373 | continue |
| 374 | |
| 375 | if INJECTION_MARKER in line: |
| 376 | inlineCodeInjectionLineIndex = lineIndex |
| 377 | continue |
| 378 | |
| 379 | if ppFileName in ignored_files: |
| 380 | continue |