Package rosmake :: Module gcc_output_parse
[frames] | no frames]

Source Code for Module rosmake.gcc_output_parse

 1  #! /usr/bin/env python 
 2   
 3  import re 
 4   
5 -class Warnings:
6 """ Extract warnings from GCC's output 7 8 Analyzes compiler output and classifies warnings. 9 """ 10 11 _warning_pattern_map = { 12 'antiquated':' antiquated', 13 'deprecated' : ' deprecated', 14 'unused_func' : ' defined but not used', 15 'isoc' : ' ISO C', 16 'missing_init' : ' missing initializer', 17 'out_of_bounds' : ' subscript .*? bounds', 18 'unused_var' : ' unused variable' 19 } 20
21 - def __init__(self, console_output):
22 self.warning_lines = [ x for x in console_output.splitlines() if x.find(" warning:") > 0 ]
23
24 - def byType(self, warntype):
25 """ Extract warning messages corresponding to warntype. 26 The warntypes can be all keys of the _warning_pattern_map dictionary. 27 @param warntype: The type of warning message that should be extracted. 28 @type warntype: str 29 @return a list of warning messages 30 @rtype list 31 """ 32 return [ x for x in self.warning_lines if re.search(self._warning_pattern_map[warntype], x) ]
33
34 - def analyze(self):
35 """ Get dictionary of classified warnings. 36 37 @return A dictionary of lists of warning messages indexed by the warning type 38 @rtype {str:[str]} 39 """ 40 return dict( [ (t,self.byType(t)) for t,p in self._warning_pattern_map.items() ] )
41