warn.py revision 76d0065ef877532a5427907262dccd732d45c8f8
1#!/usr/bin/python
2# This file uses the following encoding: utf-8
3
4"""Grep warnings messages and output HTML tables or warning counts in CSV.
5
6Default is to output warnings in HTML tables grouped by warning severity.
7Use option --byproject to output tables grouped by source file projects.
8Use option --gencsv to output warning counts in CSV format.
9"""
10
11# List of important data structures and functions in this script.
12#
13# To parse and keep warning message in the input file:
14#   severity:                classification of message severity
15#   severity.range           [0, 1, ... last_severity_level]
16#   severity.colors          for header background
17#   severity.column_headers  for the warning count table
18#   severity.headers         for warning message tables
19#   warn_patterns:
20#   warn_patterns[w]['category']     tool that issued the warning, not used now
21#   warn_patterns[w]['description']  table heading
22#   warn_patterns[w]['members']      matched warnings from input
23#   warn_patterns[w]['option']       compiler flag to control the warning
24#   warn_patterns[w]['patterns']     regular expressions to match warnings
25#   warn_patterns[w]['projects'][p]  number of warnings of pattern w in p
26#   warn_patterns[w]['severity']     severity level
27#   project_list[p][0]               project name
28#   project_list[p][1]               regular expression to match a project path
29#   project_patterns[p]              re.compile(project_list[p][1])
30#   project_names[p]                 project_list[p][0]
31#   warning_messages     array of each warning message, without source url
32#   warning_records      array of [idx to warn_patterns,
33#                                  idx to project_names,
34#                                  idx to warning_messages]
35#   android_root
36#   platform_version
37#   target_product
38#   target_variant
39#   compile_patterns, parse_input_file
40#
41# To emit html page of warning messages:
42#   flags: --byproject, --url, --separator
43# Old stuff for static html components:
44#   html_script_style:  static html scripts and styles
45#   htmlbig:
46#   dump_stats, dump_html_prologue, dump_html_epilogue:
47#   emit_buttons:
48#   dump_fixed
49#   sort_warnings:
50#   emit_stats_by_project:
51#   all_patterns,
52#   findproject, classify_warning
53#   dump_html
54#
55# New dynamic HTML page's static JavaScript data:
56#   Some data are copied from Python to JavaScript, to generate HTML elements.
57#   FlagURL                args.url
58#   FlagSeparator          args.separator
59#   SeverityColors:        severity.colors
60#   SeverityHeaders:       severity.headers
61#   SeverityColumnHeaders: severity.column_headers
62#   ProjectNames:          project_names, or project_list[*][0]
63#   WarnPatternsSeverity:     warn_patterns[*]['severity']
64#   WarnPatternsDescription:  warn_patterns[*]['description']
65#   WarnPatternsOption:       warn_patterns[*]['option']
66#   WarningMessages:          warning_messages
67#   Warnings:                 warning_records
68#   StatsHeader:           warning count table header row
69#   StatsRows:             array of warning count table rows
70#
71# New dynamic HTML page's dynamic JavaScript data:
72#
73# New dynamic HTML related function to emit data:
74#   escape_string, strip_escape_string, emit_warning_arrays
75#   emit_js_data():
76#
77# To emit csv files of warning message counts:
78#   flag --gencsv
79#   description_for_csv, string_for_csv:
80#   count_severity(sev, kind):
81#   dump_csv():
82
83import argparse
84import multiprocessing
85import os
86import re
87import signal
88import sys
89
90parser = argparse.ArgumentParser(description='Convert a build log into HTML')
91parser.add_argument('--gencsv',
92                    help='Generate a CSV file with number of various warnings',
93                    action='store_true',
94                    default=False)
95parser.add_argument('--byproject',
96                    help='Separate warnings in HTML output by project names',
97                    action='store_true',
98                    default=False)
99parser.add_argument('--url',
100                    help='Root URL of an Android source code tree prefixed '
101                    'before files in warnings')
102parser.add_argument('--separator',
103                    help='Separator between the end of a URL and the line '
104                    'number argument. e.g. #')
105parser.add_argument('--processes',
106                    type=int,
107                    default=multiprocessing.cpu_count(),
108                    help='Number of parallel processes to process warnings')
109parser.add_argument(dest='buildlog', metavar='build.log',
110                    help='Path to build.log file')
111args = parser.parse_args()
112
113
114class Severity(object):
115  """Severity levels and attributes."""
116  # numbered by dump order
117  FIXMENOW = 0
118  HIGH = 1
119  MEDIUM = 2
120  LOW = 3
121  ANALYZER = 4
122  TIDY = 5
123  HARMLESS = 6
124  UNKNOWN = 7
125  SKIP = 8
126  range = range(SKIP + 1)
127  attributes = [
128      # pylint:disable=bad-whitespace
129      ['fuchsia',   'FixNow',    'Critical warnings, fix me now'],
130      ['red',       'High',      'High severity warnings'],
131      ['orange',    'Medium',    'Medium severity warnings'],
132      ['yellow',    'Low',       'Low severity warnings'],
133      ['hotpink',   'Analyzer',  'Clang-Analyzer warnings'],
134      ['peachpuff', 'Tidy',      'Clang-Tidy warnings'],
135      ['limegreen', 'Harmless',  'Harmless warnings'],
136      ['lightblue', 'Unknown',   'Unknown warnings'],
137      ['grey',      'Unhandled', 'Unhandled warnings']
138  ]
139  colors = [a[0] for a in attributes]
140  column_headers = [a[1] for a in attributes]
141  headers = [a[2] for a in attributes]
142
143warn_patterns = [
144    # pylint:disable=line-too-long,g-inconsistent-quotes
145    {'category': 'C/C++', 'severity': Severity.ANALYZER,
146     'description': 'clang-analyzer Security warning',
147     'patterns': [r".*: warning: .+\[clang-analyzer-security.*\]"]},
148    {'category': 'make', 'severity': Severity.MEDIUM,
149     'description': 'make: overriding commands/ignoring old commands',
150     'patterns': [r".*: warning: overriding commands for target .+",
151                  r".*: warning: ignoring old commands for target .+"]},
152    {'category': 'make', 'severity': Severity.HIGH,
153     'description': 'make: LOCAL_CLANG is false',
154     'patterns': [r".*: warning: LOCAL_CLANG is set to false"]},
155    {'category': 'make', 'severity': Severity.HIGH,
156     'description': 'SDK App using platform shared library',
157     'patterns': [r".*: warning: .+ \(.*app:sdk.*\) should not link to .+ \(native:platform\)"]},
158    {'category': 'make', 'severity': Severity.HIGH,
159     'description': 'System module linking to a vendor module',
160     'patterns': [r".*: warning: .+ \(.+\) should not link to .+ \(partition:.+\)"]},
161    {'category': 'make', 'severity': Severity.MEDIUM,
162     'description': 'Invalid SDK/NDK linking',
163     'patterns': [r".*: warning: .+ \(.+\) should not link to .+ \(.+\)"]},
164    {'category': 'C/C++', 'severity': Severity.HIGH, 'option': '-Wimplicit-function-declaration',
165     'description': 'Implicit function declaration',
166     'patterns': [r".*: warning: implicit declaration of function .+",
167                  r".*: warning: implicitly declaring library function"]},
168    {'category': 'C/C++', 'severity': Severity.SKIP,
169     'description': 'skip, conflicting types for ...',
170     'patterns': [r".*: warning: conflicting types for '.+'"]},
171    {'category': 'C/C++', 'severity': Severity.HIGH, 'option': '-Wtype-limits',
172     'description': 'Expression always evaluates to true or false',
173     'patterns': [r".*: warning: comparison is always .+ due to limited range of data type",
174                  r".*: warning: comparison of unsigned .*expression .+ is always true",
175                  r".*: warning: comparison of unsigned .*expression .+ is always false"]},
176    {'category': 'C/C++', 'severity': Severity.HIGH,
177     'description': 'Potential leak of memory, bad free, use after free',
178     'patterns': [r".*: warning: Potential leak of memory",
179                  r".*: warning: Potential memory leak",
180                  r".*: warning: Memory allocated by alloca\(\) should not be deallocated",
181                  r".*: warning: Memory allocated by .+ should be deallocated by .+ not .+",
182                  r".*: warning: 'delete' applied to a pointer that was allocated",
183                  r".*: warning: Use of memory after it is freed",
184                  r".*: warning: Argument to .+ is the address of .+ variable",
185                  r".*: warning: Argument to free\(\) is offset by .+ of memory allocated by",
186                  r".*: warning: Attempt to .+ released memory"]},
187    {'category': 'C/C++', 'severity': Severity.HIGH,
188     'description': 'Use transient memory for control value',
189     'patterns': [r".*: warning: .+Using such transient memory for the control value is .*dangerous."]},
190    {'category': 'C/C++', 'severity': Severity.HIGH,
191     'description': 'Return address of stack memory',
192     'patterns': [r".*: warning: Address of stack memory .+ returned to caller",
193                  r".*: warning: Address of stack memory .+ will be a dangling reference"]},
194    {'category': 'C/C++', 'severity': Severity.HIGH,
195     'description': 'Problem with vfork',
196     'patterns': [r".*: warning: This .+ is prohibited after a successful vfork",
197                  r".*: warning: Call to function '.+' is insecure "]},
198    {'category': 'C/C++', 'severity': Severity.HIGH, 'option': 'infinite-recursion',
199     'description': 'Infinite recursion',
200     'patterns': [r".*: warning: all paths through this function will call itself"]},
201    {'category': 'C/C++', 'severity': Severity.HIGH,
202     'description': 'Potential buffer overflow',
203     'patterns': [r".*: warning: Size argument is greater than .+ the destination buffer",
204                  r".*: warning: Potential buffer overflow.",
205                  r".*: warning: String copy function overflows destination buffer"]},
206    {'category': 'C/C++', 'severity': Severity.MEDIUM,
207     'description': 'Incompatible pointer types',
208     'patterns': [r".*: warning: assignment from incompatible pointer type",
209                  r".*: warning: return from incompatible pointer type",
210                  r".*: warning: passing argument [0-9]+ of '.*' from incompatible pointer type",
211                  r".*: warning: initialization from incompatible pointer type"]},
212    {'category': 'C/C++', 'severity': Severity.HIGH, 'option': '-fno-builtin',
213     'description': 'Incompatible declaration of built in function',
214     'patterns': [r".*: warning: incompatible implicit declaration of built-in function .+"]},
215    {'category': 'C/C++', 'severity': Severity.HIGH, 'option': '-Wincompatible-library-redeclaration',
216     'description': 'Incompatible redeclaration of library function',
217     'patterns': [r".*: warning: incompatible redeclaration of library function .+"]},
218    {'category': 'C/C++', 'severity': Severity.HIGH,
219     'description': 'Null passed as non-null argument',
220     'patterns': [r".*: warning: Null passed to a callee that requires a non-null"]},
221    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wunused-parameter',
222     'description': 'Unused parameter',
223     'patterns': [r".*: warning: unused parameter '.*'"]},
224    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wunused',
225     'description': 'Unused function, variable or label',
226     'patterns': [r".*: warning: '.+' defined but not used",
227                  r".*: warning: unused function '.+'",
228                  r".*: warning: private field '.+' is not used",
229                  r".*: warning: unused variable '.+'"]},
230    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wunused-value',
231     'description': 'Statement with no effect or result unused',
232     'patterns': [r".*: warning: statement with no effect",
233                  r".*: warning: expression result unused"]},
234    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wunused-result',
235     'description': 'Ignoreing return value of function',
236     'patterns': [r".*: warning: ignoring return value of function .+Wunused-result"]},
237    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wmissing-field-initializers',
238     'description': 'Missing initializer',
239     'patterns': [r".*: warning: missing initializer"]},
240    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wdelete-non-virtual-dtor',
241     'description': 'Need virtual destructor',
242     'patterns': [r".*: warning: delete called .* has virtual functions but non-virtual destructor"]},
243    {'category': 'cont.', 'severity': Severity.SKIP,
244     'description': 'skip, near initialization for ...',
245     'patterns': [r".*: warning: \(near initialization for '.+'\)"]},
246    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wdate-time',
247     'description': 'Expansion of data or time macro',
248     'patterns': [r".*: warning: expansion of date or time macro is not reproducible"]},
249    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wformat',
250     'description': 'Format string does not match arguments',
251     'patterns': [r".*: warning: format '.+' expects type '.+', but argument [0-9]+ has type '.+'",
252                  r".*: warning: more '%' conversions than data arguments",
253                  r".*: warning: data argument not used by format string",
254                  r".*: warning: incomplete format specifier",
255                  r".*: warning: unknown conversion type .* in format",
256                  r".*: warning: format .+ expects .+ but argument .+Wformat=",
257                  r".*: warning: field precision should have .+ but argument has .+Wformat",
258                  r".*: warning: format specifies type .+ but the argument has .*type .+Wformat"]},
259    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wformat-extra-args',
260     'description': 'Too many arguments for format string',
261     'patterns': [r".*: warning: too many arguments for format"]},
262    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wformat-invalid-specifier',
263     'description': 'Invalid format specifier',
264     'patterns': [r".*: warning: invalid .+ specifier '.+'.+format-invalid-specifier"]},
265    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wsign-compare',
266     'description': 'Comparison between signed and unsigned',
267     'patterns': [r".*: warning: comparison between signed and unsigned",
268                  r".*: warning: comparison of promoted \~unsigned with unsigned",
269                  r".*: warning: signed and unsigned type in conditional expression"]},
270    {'category': 'C/C++', 'severity': Severity.MEDIUM,
271     'description': 'Comparison between enum and non-enum',
272     'patterns': [r".*: warning: enumeral and non-enumeral type in conditional expression"]},
273    {'category': 'libpng', 'severity': Severity.MEDIUM,
274     'description': 'libpng: zero area',
275     'patterns': [r".*libpng warning: Ignoring attempt to set cHRM RGB triangle with zero area"]},
276    {'category': 'aapt', 'severity': Severity.MEDIUM,
277     'description': 'aapt: no comment for public symbol',
278     'patterns': [r".*: warning: No comment for public symbol .+"]},
279    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wmissing-braces',
280     'description': 'Missing braces around initializer',
281     'patterns': [r".*: warning: missing braces around initializer.*"]},
282    {'category': 'C/C++', 'severity': Severity.HARMLESS,
283     'description': 'No newline at end of file',
284     'patterns': [r".*: warning: no newline at end of file"]},
285    {'category': 'C/C++', 'severity': Severity.HARMLESS,
286     'description': 'Missing space after macro name',
287     'patterns': [r".*: warning: missing whitespace after the macro name"]},
288    {'category': 'C/C++', 'severity': Severity.LOW, 'option': '-Wcast-align',
289     'description': 'Cast increases required alignment',
290     'patterns': [r".*: warning: cast from .* to .* increases required alignment .*"]},
291    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wcast-qual',
292     'description': 'Qualifier discarded',
293     'patterns': [r".*: warning: passing argument [0-9]+ of '.+' discards qualifiers from pointer target type",
294                  r".*: warning: assignment discards qualifiers from pointer target type",
295                  r".*: warning: passing .+ to parameter of type .+ discards qualifiers",
296                  r".*: warning: assigning to .+ from .+ discards qualifiers",
297                  r".*: warning: initializing .+ discards qualifiers .+types-discards-qualifiers",
298                  r".*: warning: return discards qualifiers from pointer target type"]},
299    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wunknown-attributes',
300     'description': 'Unknown attribute',
301     'patterns': [r".*: warning: unknown attribute '.+'"]},
302    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wignored-attributes',
303     'description': 'Attribute ignored',
304     'patterns': [r".*: warning: '_*packed_*' attribute ignored",
305                  r".*: warning: attribute declaration must precede definition .+ignored-attributes"]},
306    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wvisibility',
307     'description': 'Visibility problem',
308     'patterns': [r".*: warning: declaration of '.+' will not be visible outside of this function"]},
309    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wattributes',
310     'description': 'Visibility mismatch',
311     'patterns': [r".*: warning: '.+' declared with greater visibility than the type of its field '.+'"]},
312    {'category': 'C/C++', 'severity': Severity.MEDIUM,
313     'description': 'Shift count greater than width of type',
314     'patterns': [r".*: warning: (left|right) shift count >= width of type"]},
315    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wextern-initializer',
316     'description': 'extern <foo> is initialized',
317     'patterns': [r".*: warning: '.+' initialized and declared 'extern'",
318                  r".*: warning: 'extern' variable has an initializer"]},
319    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wold-style-declaration',
320     'description': 'Old style declaration',
321     'patterns': [r".*: warning: 'static' is not at beginning of declaration"]},
322    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wreturn-type',
323     'description': 'Missing return value',
324     'patterns': [r".*: warning: control reaches end of non-void function"]},
325    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wimplicit-int',
326     'description': 'Implicit int type',
327     'patterns': [r".*: warning: type specifier missing, defaults to 'int'",
328                  r".*: warning: type defaults to 'int' in declaration of '.+'"]},
329    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wmain-return-type',
330     'description': 'Main function should return int',
331     'patterns': [r".*: warning: return type of 'main' is not 'int'"]},
332    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wuninitialized',
333     'description': 'Variable may be used uninitialized',
334     'patterns': [r".*: warning: '.+' may be used uninitialized in this function"]},
335    {'category': 'C/C++', 'severity': Severity.HIGH, 'option': '-Wuninitialized',
336     'description': 'Variable is used uninitialized',
337     'patterns': [r".*: warning: '.+' is used uninitialized in this function",
338                  r".*: warning: variable '.+' is uninitialized when used here"]},
339    {'category': 'ld', 'severity': Severity.MEDIUM, 'option': '-fshort-enums',
340     'description': 'ld: possible enum size mismatch',
341     'patterns': [r".*: warning: .* uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail"]},
342    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wpointer-sign',
343     'description': 'Pointer targets differ in signedness',
344     'patterns': [r".*: warning: pointer targets in initialization differ in signedness",
345                  r".*: warning: pointer targets in assignment differ in signedness",
346                  r".*: warning: pointer targets in return differ in signedness",
347                  r".*: warning: pointer targets in passing argument [0-9]+ of '.+' differ in signedness"]},
348    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wstrict-overflow',
349     'description': 'Assuming overflow does not occur',
350     'patterns': [r".*: warning: assuming signed overflow does not occur when assuming that .* is always (true|false)"]},
351    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wempty-body',
352     'description': 'Suggest adding braces around empty body',
353     'patterns': [r".*: warning: suggest braces around empty body in an 'if' statement",
354                  r".*: warning: empty body in an if-statement",
355                  r".*: warning: suggest braces around empty body in an 'else' statement",
356                  r".*: warning: empty body in an else-statement"]},
357    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wparentheses',
358     'description': 'Suggest adding parentheses',
359     'patterns': [r".*: warning: suggest explicit braces to avoid ambiguous 'else'",
360                  r".*: warning: suggest parentheses around arithmetic in operand of '.+'",
361                  r".*: warning: suggest parentheses around comparison in operand of '.+'",
362                  r".*: warning: logical not is only applied to the left hand side of this comparison",
363                  r".*: warning: using the result of an assignment as a condition without parentheses",
364                  r".*: warning: .+ has lower precedence than .+ be evaluated first .+Wparentheses",
365                  r".*: warning: suggest parentheses around '.+?' .+ '.+?'",
366                  r".*: warning: suggest parentheses around assignment used as truth value"]},
367    {'category': 'C/C++', 'severity': Severity.MEDIUM,
368     'description': 'Static variable used in non-static inline function',
369     'patterns': [r".*: warning: '.+' is static but used in inline function '.+' which is not static"]},
370    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wimplicit int',
371     'description': 'No type or storage class (will default to int)',
372     'patterns': [r".*: warning: data definition has no type or storage class"]},
373    {'category': 'C/C++', 'severity': Severity.MEDIUM,
374     'description': 'Null pointer',
375     'patterns': [r".*: warning: Dereference of null pointer",
376                  r".*: warning: Called .+ pointer is null",
377                  r".*: warning: Forming reference to null pointer",
378                  r".*: warning: Returning null reference",
379                  r".*: warning: Null pointer passed as an argument to a 'nonnull' parameter",
380                  r".*: warning: .+ results in a null pointer dereference",
381                  r".*: warning: Access to .+ results in a dereference of a null pointer",
382                  r".*: warning: Null pointer argument in"]},
383    {'category': 'cont.', 'severity': Severity.SKIP,
384     'description': 'skip, parameter name (without types) in function declaration',
385     'patterns': [r".*: warning: parameter names \(without types\) in function declaration"]},
386    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wstrict-aliasing',
387     'description': 'Dereferencing <foo> breaks strict aliasing rules',
388     'patterns': [r".*: warning: dereferencing .* break strict-aliasing rules"]},
389    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wpointer-to-int-cast',
390     'description': 'Cast from pointer to integer of different size',
391     'patterns': [r".*: warning: cast from pointer to integer of different size",
392                  r".*: warning: initialization makes pointer from integer without a cast"]},
393    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wint-to-pointer-cast',
394     'description': 'Cast to pointer from integer of different size',
395     'patterns': [r".*: warning: cast to pointer from integer of different size"]},
396    {'category': 'C/C++', 'severity': Severity.MEDIUM,
397     'description': 'Symbol redefined',
398     'patterns': [r".*: warning: "".+"" redefined"]},
399    {'category': 'cont.', 'severity': Severity.SKIP,
400     'description': 'skip, ... location of the previous definition',
401     'patterns': [r".*: warning: this is the location of the previous definition"]},
402    {'category': 'ld', 'severity': Severity.MEDIUM,
403     'description': 'ld: type and size of dynamic symbol are not defined',
404     'patterns': [r".*: warning: type and size of dynamic symbol `.+' are not defined"]},
405    {'category': 'C/C++', 'severity': Severity.MEDIUM,
406     'description': 'Pointer from integer without cast',
407     'patterns': [r".*: warning: assignment makes pointer from integer without a cast"]},
408    {'category': 'C/C++', 'severity': Severity.MEDIUM,
409     'description': 'Pointer from integer without cast',
410     'patterns': [r".*: warning: passing argument [0-9]+ of '.+' makes pointer from integer without a cast"]},
411    {'category': 'C/C++', 'severity': Severity.MEDIUM,
412     'description': 'Integer from pointer without cast',
413     'patterns': [r".*: warning: assignment makes integer from pointer without a cast"]},
414    {'category': 'C/C++', 'severity': Severity.MEDIUM,
415     'description': 'Integer from pointer without cast',
416     'patterns': [r".*: warning: passing argument [0-9]+ of '.+' makes integer from pointer without a cast"]},
417    {'category': 'C/C++', 'severity': Severity.MEDIUM,
418     'description': 'Integer from pointer without cast',
419     'patterns': [r".*: warning: return makes integer from pointer without a cast"]},
420    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wunknown-pragmas',
421     'description': 'Ignoring pragma',
422     'patterns': [r".*: warning: ignoring #pragma .+"]},
423    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-W#pragma-messages',
424     'description': 'Pragma warning messages',
425     'patterns': [r".*: warning: .+W#pragma-messages"]},
426    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wclobbered',
427     'description': 'Variable might be clobbered by longjmp or vfork',
428     'patterns': [r".*: warning: variable '.+' might be clobbered by 'longjmp' or 'vfork'"]},
429    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wclobbered',
430     'description': 'Argument might be clobbered by longjmp or vfork',
431     'patterns': [r".*: warning: argument '.+' might be clobbered by 'longjmp' or 'vfork'"]},
432    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wredundant-decls',
433     'description': 'Redundant declaration',
434     'patterns': [r".*: warning: redundant redeclaration of '.+'"]},
435    {'category': 'cont.', 'severity': Severity.SKIP,
436     'description': 'skip, previous declaration ... was here',
437     'patterns': [r".*: warning: previous declaration of '.+' was here"]},
438    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wswitch-enum',
439     'description': 'Enum value not handled in switch',
440     'patterns': [r".*: warning: .*enumeration value.* not handled in switch.+Wswitch"]},
441    {'category': 'java', 'severity': Severity.MEDIUM, 'option': '-encoding',
442     'description': 'Java: Non-ascii characters used, but ascii encoding specified',
443     'patterns': [r".*: warning: unmappable character for encoding ascii"]},
444    {'category': 'java', 'severity': Severity.MEDIUM,
445     'description': 'Java: Non-varargs call of varargs method with inexact argument type for last parameter',
446     'patterns': [r".*: warning: non-varargs call of varargs method with inexact argument type for last parameter"]},
447    {'category': 'java', 'severity': Severity.MEDIUM,
448     'description': 'Java: Unchecked method invocation',
449     'patterns': [r".*: warning: \[unchecked\] unchecked method invocation: .+ in class .+"]},
450    {'category': 'java', 'severity': Severity.MEDIUM,
451     'description': 'Java: Unchecked conversion',
452     'patterns': [r".*: warning: \[unchecked\] unchecked conversion"]},
453    {'category': 'java', 'severity': Severity.MEDIUM,
454     'description': '_ used as an identifier',
455     'patterns': [r".*: warning: '_' used as an identifier"]},
456
457    # Warnings from Error Prone.
458    {'category': 'java',
459     'severity': Severity.MEDIUM,
460     'description': 'Java: Use of deprecated member',
461     'patterns': [r'.*: warning: \[deprecation\] .+']},
462    {'category': 'java',
463     'severity': Severity.MEDIUM,
464     'description': 'Java: Unchecked conversion',
465     'patterns': [r'.*: warning: \[unchecked\] .+']},
466
467    # Warnings from Error Prone (auto generated list).
468    {'category': 'java',
469     'severity': Severity.LOW,
470     'description':
471         'Java: Deprecated item is not annotated with @Deprecated',
472     'patterns': [r".*: warning: \[DepAnn\] .+"]},
473    {'category': 'java',
474     'severity': Severity.LOW,
475     'description':
476         'Java: Fallthrough warning suppression has no effect if warning is suppressed',
477     'patterns': [r".*: warning: \[FallthroughSuppression\] .+"]},
478    {'category': 'java',
479     'severity': Severity.LOW,
480     'description':
481         'Java: Prefer \'L\' to \'l\' for the suffix to long literals',
482     'patterns': [r".*: warning: \[LongLiteralLowerCaseSuffix\] .+"]},
483    {'category': 'java',
484     'severity': Severity.LOW,
485     'description':
486         'Java: @Binds is a more efficient and declaritive mechanism for delegating a binding.',
487     'patterns': [r".*: warning: \[UseBinds\] .+"]},
488    {'category': 'java',
489     'severity': Severity.MEDIUM,
490     'description':
491         'Java: Assertions may be disabled at runtime and do not guarantee that execution will halt here; consider throwing an exception instead',
492     'patterns': [r".*: warning: \[AssertFalse\] .+"]},
493    {'category': 'java',
494     'severity': Severity.MEDIUM,
495     'description':
496         'Java: Classes that implement Annotation must override equals and hashCode. Consider using AutoAnnotation instead of implementing Annotation by hand.',
497     'patterns': [r".*: warning: \[BadAnnotationImplementation\] .+"]},
498    {'category': 'java',
499     'severity': Severity.MEDIUM,
500     'description':
501         'Java: BigDecimal(double) and BigDecimal.valueOf(double) may lose precision, prefer BigDecimal(String) or BigDecimal(long)',
502     'patterns': [r".*: warning: \[BigDecimalLiteralDouble\] .+"]},
503    {'category': 'java',
504     'severity': Severity.MEDIUM,
505     'description':
506         'Java: Mockito cannot mock final classes',
507     'patterns': [r".*: warning: \[CannotMockFinalClass\] .+"]},
508    {'category': 'java',
509     'severity': Severity.MEDIUM,
510     'description':
511         'Java: This code, which counts elements using a loop, can be replaced by a simpler library method',
512     'patterns': [r".*: warning: \[ElementsCountedInLoop\] .+"]},
513    {'category': 'java',
514     'severity': Severity.MEDIUM,
515     'description':
516         'Java: Empty top-level type declaration',
517     'patterns': [r".*: warning: \[EmptyTopLevelDeclaration\] .+"]},
518    {'category': 'java',
519     'severity': Severity.MEDIUM,
520     'description':
521         'Java: Classes that override equals should also override hashCode.',
522     'patterns': [r".*: warning: \[EqualsHashCode\] .+"]},
523    {'category': 'java',
524     'severity': Severity.MEDIUM,
525     'description':
526         'Java: An equality test between objects with incompatible types always returns false',
527     'patterns': [r".*: warning: \[EqualsIncompatibleType\] .+"]},
528    {'category': 'java',
529     'severity': Severity.MEDIUM,
530     'description':
531         'Java: If you return or throw from a finally, then values returned or thrown from the try-catch block will be ignored. Consider using try-with-resources instead.',
532     'patterns': [r".*: warning: \[Finally\] .+"]},
533    {'category': 'java',
534     'severity': Severity.MEDIUM,
535     'description':
536         'Java: This annotation has incompatible modifiers as specified by its @IncompatibleModifiers annotation',
537     'patterns': [r".*: warning: \[IncompatibleModifiers\] .+"]},
538    {'category': 'java',
539     'severity': Severity.MEDIUM,
540     'description':
541         'Java: Class should not implement both `Iterable` and `Iterator`',
542     'patterns': [r".*: warning: \[IterableAndIterator\] .+"]},
543    {'category': 'java',
544     'severity': Severity.MEDIUM,
545     'description':
546         'Java: Floating-point comparison without error tolerance',
547     'patterns': [r".*: warning: \[JUnit3FloatingPointComparisonWithoutDelta\] .+"]},
548    {'category': 'java',
549     'severity': Severity.MEDIUM,
550     'description':
551         'Java: Test class inherits from JUnit 3\'s TestCase but has JUnit 4 @Test annotations.',
552     'patterns': [r".*: warning: \[JUnitAmbiguousTestClass\] .+"]},
553    {'category': 'java',
554     'severity': Severity.MEDIUM,
555     'description':
556         'Java: Enum switch statement is missing cases',
557     'patterns': [r".*: warning: \[MissingCasesInEnumSwitch\] .+"]},
558    {'category': 'java',
559     'severity': Severity.MEDIUM,
560     'description':
561         'Java: Not calling fail() when expecting an exception masks bugs',
562     'patterns': [r".*: warning: \[MissingFail\] .+"]},
563    {'category': 'java',
564     'severity': Severity.MEDIUM,
565     'description':
566         'Java: method overrides method in supertype; expected @Override',
567     'patterns': [r".*: warning: \[MissingOverride\] .+"]},
568    {'category': 'java',
569     'severity': Severity.MEDIUM,
570     'description':
571         'Java: Source files should not contain multiple top-level class declarations',
572     'patterns': [r".*: warning: \[MultipleTopLevelClasses\] .+"]},
573    {'category': 'java',
574     'severity': Severity.MEDIUM,
575     'description':
576         'Java: This update of a volatile variable is non-atomic',
577     'patterns': [r".*: warning: \[NonAtomicVolatileUpdate\] .+"]},
578    {'category': 'java',
579     'severity': Severity.MEDIUM,
580     'description':
581         'Java: Static import of member uses non-canonical name',
582     'patterns': [r".*: warning: \[NonCanonicalStaticMemberImport\] .+"]},
583    {'category': 'java',
584     'severity': Severity.MEDIUM,
585     'description':
586         'Java: equals method doesn\'t override Object.equals',
587     'patterns': [r".*: warning: \[NonOverridingEquals\] .+"]},
588    {'category': 'java',
589     'severity': Severity.MEDIUM,
590     'description':
591         'Java: Constructors should not be annotated with @Nullable since they cannot return null',
592     'patterns': [r".*: warning: \[NullableConstructor\] .+"]},
593    {'category': 'java',
594     'severity': Severity.MEDIUM,
595     'description':
596         'Java: @Nullable should not be used for primitive types since they cannot be null',
597     'patterns': [r".*: warning: \[NullablePrimitive\] .+"]},
598    {'category': 'java',
599     'severity': Severity.MEDIUM,
600     'description':
601         'Java: void-returning methods should not be annotated with @Nullable, since they cannot return null',
602     'patterns': [r".*: warning: \[NullableVoid\] .+"]},
603    {'category': 'java',
604     'severity': Severity.MEDIUM,
605     'description':
606         'Java: Package names should match the directory they are declared in',
607     'patterns': [r".*: warning: \[PackageLocation\] .+"]},
608    {'category': 'java',
609     'severity': Severity.MEDIUM,
610     'description':
611         'Java: Second argument to Preconditions.* is a call to String.format(), which can be unwrapped',
612     'patterns': [r".*: warning: \[PreconditionsErrorMessageEagerEvaluation\] .+"]},
613    {'category': 'java',
614     'severity': Severity.MEDIUM,
615     'description':
616         'Java: Preconditions only accepts the %s placeholder in error message strings',
617     'patterns': [r".*: warning: \[PreconditionsInvalidPlaceholder\] .+"]},
618    {'category': 'java',
619     'severity': Severity.MEDIUM,
620     'description':
621         'Java: Passing a primitive array to a varargs method is usually wrong',
622     'patterns': [r".*: warning: \[PrimitiveArrayPassedToVarargsMethod\] .+"]},
623    {'category': 'java',
624     'severity': Severity.MEDIUM,
625     'description':
626         'Java: Protobuf fields cannot be null, so this check is redundant',
627     'patterns': [r".*: warning: \[ProtoFieldPreconditionsCheckNotNull\] .+"]},
628    {'category': 'java',
629     'severity': Severity.MEDIUM,
630     'description':
631         'Java: This annotation is missing required modifiers as specified by its @RequiredModifiers annotation',
632     'patterns': [r".*: warning: \[RequiredModifiers\] .+"]},
633    {'category': 'java',
634     'severity': Severity.MEDIUM,
635     'description':
636         'Java: A static variable or method should not be accessed from an object instance',
637     'patterns': [r".*: warning: \[StaticAccessedFromInstance\] .+"]},
638    {'category': 'java',
639     'severity': Severity.MEDIUM,
640     'description':
641         'Java: String comparison using reference equality instead of value equality',
642     'patterns': [r".*: warning: \[StringEquality\] .+"]},
643    {'category': 'java',
644     'severity': Severity.MEDIUM,
645     'description':
646         'Java: Declaring a type parameter that is only used in the return type is a misuse of generics: operations on the type parameter are unchecked, it hides unsafe casts at invocations of the method, and it interacts badly with method overload resolution.',
647     'patterns': [r".*: warning: \[TypeParameterUnusedInFormals\] .+"]},
648    {'category': 'java',
649     'severity': Severity.MEDIUM,
650     'description':
651         'Java: Using static imports for types is unnecessary',
652     'patterns': [r".*: warning: \[UnnecessaryStaticImport\] .+"]},
653    {'category': 'java',
654     'severity': Severity.MEDIUM,
655     'description':
656         'Java: Unsynchronized method overrides a synchronized method.',
657     'patterns': [r".*: warning: \[UnsynchronizedOverridesSynchronized\] .+"]},
658    {'category': 'java',
659     'severity': Severity.MEDIUM,
660     'description':
661         'Java: Non-constant variable missing @Var annotation',
662     'patterns': [r".*: warning: \[Var\] .+"]},
663    {'category': 'java',
664     'severity': Severity.MEDIUM,
665     'description':
666         'Java: Because of spurious wakeups, Object.wait() and Condition.await() must always be called in a loop',
667     'patterns': [r".*: warning: \[WaitNotInLoop\] .+"]},
668    {'category': 'java',
669     'severity': Severity.MEDIUM,
670     'description':
671         'Java: Subclasses of Fragment must be instantiable via Class#newInstance(): the class must be public, static and have a public nullary constructor',
672     'patterns': [r".*: warning: \[FragmentNotInstantiable\] .+"]},
673    {'category': 'java',
674     'severity': Severity.MEDIUM,
675     'description':
676         'Java: Hardcoded reference to /sdcard',
677     'patterns': [r".*: warning: \[HardCodedSdCardPath\] .+"]},
678    {'category': 'java',
679     'severity': Severity.MEDIUM,
680     'description':
681         'Java: Incompatible type as argument to Object-accepting Java collections method',
682     'patterns': [r".*: warning: \[CollectionIncompatibleType\] .+"]},
683    {'category': 'java',
684     'severity': Severity.MEDIUM,
685     'description':
686         'Java: @AssistedInject and @Inject should not be used on different constructors in the same class.',
687     'patterns': [r".*: warning: \[AssistedInjectAndInjectOnConstructors\] .+"]},
688    {'category': 'java',
689     'severity': Severity.MEDIUM,
690     'description':
691         'Java: Although Guice allows injecting final fields, doing so is not recommended because the injected value may not be visible to other threads.',
692     'patterns': [r".*: warning: \[GuiceInjectOnFinalField\] .+"]},
693    {'category': 'java',
694     'severity': Severity.MEDIUM,
695     'description':
696         'Java: This method is not annotated with @Inject, but it overrides a method that is annotated with @com.google.inject.Inject. Guice will inject this method, and it is recommended to annotate it explicitly.',
697     'patterns': [r".*: warning: \[OverridesGuiceInjectableMethod\] .+"]},
698    {'category': 'java',
699     'severity': Severity.MEDIUM,
700     'description':
701         'Java: Double-checked locking on non-volatile fields is unsafe',
702     'patterns': [r".*: warning: \[DoubleCheckedLocking\] .+"]},
703    {'category': 'java',
704     'severity': Severity.MEDIUM,
705     'description':
706         'Java: Writes to static fields should not be guarded by instance locks',
707     'patterns': [r".*: warning: \[StaticGuardedByInstance\] .+"]},
708    {'category': 'java',
709     'severity': Severity.MEDIUM,
710     'description':
711         'Java: Synchronizing on non-final fields is not safe: if the field is ever updated, different threads may end up locking on different objects.',
712     'patterns': [r".*: warning: \[SynchronizeOnNonFinalField\] .+"]},
713    {'category': 'java',
714     'severity': Severity.HIGH,
715     'description':
716         'Java: Reference equality used to compare arrays',
717     'patterns': [r".*: warning: \[ArrayEquals\] .+"]},
718    {'category': 'java',
719     'severity': Severity.HIGH,
720     'description':
721         'Java: hashcode method on array does not hash array contents',
722     'patterns': [r".*: warning: \[ArrayHashCode\] .+"]},
723    {'category': 'java',
724     'severity': Severity.HIGH,
725     'description':
726         'Java: Calling toString on an array does not provide useful information',
727     'patterns': [r".*: warning: \[ArrayToString.*\] .+"]},
728    {'category': 'java',
729     'severity': Severity.HIGH,
730     'description':
731         'Java: Arrays.asList does not autobox primitive arrays, as one might expect.',
732     'patterns': [r".*: warning: \[ArraysAsListPrimitiveArray\] .+"]},
733    {'category': 'java',
734     'severity': Severity.HIGH,
735     'description':
736         'Java: AsyncCallable should not return a null Future, only a Future whose result is null.',
737     'patterns': [r".*: warning: \[AsyncCallableReturnsNull\] .+"]},
738    {'category': 'java',
739     'severity': Severity.HIGH,
740     'description':
741         'Java: AsyncFunction should not return a null Future, only a Future whose result is null.',
742     'patterns': [r".*: warning: \[AsyncFunctionReturnsNull\] .+"]},
743    {'category': 'java',
744     'severity': Severity.HIGH,
745     'description':
746         'Java: Possible sign flip from narrowing conversion',
747     'patterns': [r".*: warning: \[BadComparable\] .+"]},
748    {'category': 'java',
749     'severity': Severity.HIGH,
750     'description':
751         'Java: Shift by an amount that is out of range',
752     'patterns': [r".*: warning: \[BadShiftAmount\] .+"]},
753    {'category': 'java',
754     'severity': Severity.HIGH,
755     'description':
756         'Java: valueOf provides better time and space performance',
757     'patterns': [r".*: warning: \[BoxedPrimitiveConstructor\] .+"]},
758    {'category': 'java',
759     'severity': Severity.HIGH,
760     'description':
761         'Java: The called constructor accepts a parameter with the same name and type as one of its caller\'s parameters, but its caller doesn\'t pass that parameter to it.  It\'s likely that it was intended to.',
762     'patterns': [r".*: warning: \[ChainingConstructorIgnoresParameter\] .+"]},
763    {'category': 'java',
764     'severity': Severity.HIGH,
765     'description':
766         'Java: Ignored return value of method that is annotated with @CheckReturnValue',
767     'patterns': [r".*: warning: \[CheckReturnValue\] .+"]},
768    {'category': 'java',
769     'severity': Severity.HIGH,
770     'description':
771         'Java: Inner class is non-static but does not reference enclosing class',
772     'patterns': [r".*: warning: \[ClassCanBeStatic\] .+"]},
773    {'category': 'java',
774     'severity': Severity.HIGH,
775     'description':
776         'Java: The source file name should match the name of the top-level class it contains',
777     'patterns': [r".*: warning: \[ClassName\] .+"]},
778    {'category': 'java',
779     'severity': Severity.HIGH,
780     'description':
781         'Java: This comparison method violates the contract',
782     'patterns': [r".*: warning: \[ComparisonContractViolated\] .+"]},
783    {'category': 'java',
784     'severity': Severity.HIGH,
785     'description':
786         'Java: Comparison to value that is out of range for the compared type',
787     'patterns': [r".*: warning: \[ComparisonOutOfRange\] .+"]},
788    {'category': 'java',
789     'severity': Severity.HIGH,
790     'description':
791         'Java: Non-compile-time constant expression passed to parameter with @CompileTimeConstant type annotation.',
792     'patterns': [r".*: warning: \[CompileTimeConstant\] .+"]},
793    {'category': 'java',
794     'severity': Severity.HIGH,
795     'description':
796         'Java: Exception created but not thrown',
797     'patterns': [r".*: warning: \[DeadException\] .+"]},
798    {'category': 'java',
799     'severity': Severity.HIGH,
800     'description':
801         'Java: Division by integer literal zero',
802     'patterns': [r".*: warning: \[DivZero\] .+"]},
803    {'category': 'java',
804     'severity': Severity.HIGH,
805     'description':
806         'Java: Empty statement after if',
807     'patterns': [r".*: warning: \[EmptyIf\] .+"]},
808    {'category': 'java',
809     'severity': Severity.HIGH,
810     'description':
811         'Java: == NaN always returns false; use the isNaN methods instead',
812     'patterns': [r".*: warning: \[EqualsNaN\] .+"]},
813    {'category': 'java',
814     'severity': Severity.HIGH,
815     'description':
816         'Java: Method annotated @ForOverride must be protected or package-private and only invoked from declaring class',
817     'patterns': [r".*: warning: \[ForOverride\] .+"]},
818    {'category': 'java',
819     'severity': Severity.HIGH,
820     'description':
821         'Java: Futures.getChecked requires a checked exception type with a standard constructor.',
822     'patterns': [r".*: warning: \[FuturesGetCheckedIllegalExceptionType\] .+"]},
823    {'category': 'java',
824     'severity': Severity.HIGH,
825     'description':
826         'Java: Calling getClass() on an object of type Class returns the Class object for java.lang.Class; you probably meant to operate on the object directly',
827     'patterns': [r".*: warning: \[GetClassOnClass\] .+"]},
828    {'category': 'java',
829     'severity': Severity.HIGH,
830     'description':
831         'Java: An object is tested for equality to itself using Guava Libraries',
832     'patterns': [r".*: warning: \[GuavaSelfEquals\] .+"]},
833    {'category': 'java',
834     'severity': Severity.HIGH,
835     'description':
836         'Java: contains() is a legacy method that is equivalent to containsValue()',
837     'patterns': [r".*: warning: \[HashtableContains\] .+"]},
838    {'category': 'java',
839     'severity': Severity.HIGH,
840     'description':
841         'Java: Cipher.getInstance() is invoked using either the default settings or ECB mode',
842     'patterns': [r".*: warning: \[InsecureCipherMode\] .+"]},
843    {'category': 'java',
844     'severity': Severity.HIGH,
845     'description':
846         'Java: Invalid syntax used for a regular expression',
847     'patterns': [r".*: warning: \[InvalidPatternSyntax\] .+"]},
848    {'category': 'java',
849     'severity': Severity.HIGH,
850     'description':
851         'Java: The argument to Class#isInstance(Object) should not be a Class',
852     'patterns': [r".*: warning: \[IsInstanceOfClass\] .+"]},
853    {'category': 'java',
854     'severity': Severity.HIGH,
855     'description':
856         'Java: jMock tests must have a @RunWith(JMock.class) annotation, or the Mockery field must have a @Rule JUnit annotation',
857     'patterns': [r".*: warning: \[JMockTestWithoutRunWithOrRuleAnnotation\] .+"]},
858    {'category': 'java',
859     'severity': Severity.HIGH,
860     'description':
861         'Java: Test method will not be run; please prefix name with "test"',
862     'patterns': [r".*: warning: \[JUnit3TestNotRun\] .+"]},
863    {'category': 'java',
864     'severity': Severity.HIGH,
865     'description':
866         'Java: setUp() method will not be run; Please add a @Before annotation',
867     'patterns': [r".*: warning: \[JUnit4SetUpNotRun\] .+"]},
868    {'category': 'java',
869     'severity': Severity.HIGH,
870     'description':
871         'Java: tearDown() method will not be run; Please add an @After annotation',
872     'patterns': [r".*: warning: \[JUnit4TearDownNotRun\] .+"]},
873    {'category': 'java',
874     'severity': Severity.HIGH,
875     'description':
876         'Java: Test method will not be run; please add @Test annotation',
877     'patterns': [r".*: warning: \[JUnit4TestNotRun\] .+"]},
878    {'category': 'java',
879     'severity': Severity.HIGH,
880     'description':
881         'Java: Printf-like format string does not match its arguments',
882     'patterns': [r".*: warning: \[MalformedFormatString\] .+"]},
883    {'category': 'java',
884     'severity': Severity.HIGH,
885     'description':
886         'Java: Use of "YYYY" (week year) in a date pattern without "ww" (week in year). You probably meant to use "yyyy" (year) instead.',
887     'patterns': [r".*: warning: \[MisusedWeekYear\] .+"]},
888    {'category': 'java',
889     'severity': Severity.HIGH,
890     'description':
891         'Java: A bug in Mockito will cause this test to fail at runtime with a ClassCastException',
892     'patterns': [r".*: warning: \[MockitoCast\] .+"]},
893    {'category': 'java',
894     'severity': Severity.HIGH,
895     'description':
896         'Java: Missing method call for verify(mock) here',
897     'patterns': [r".*: warning: \[MockitoUsage\] .+"]},
898    {'category': 'java',
899     'severity': Severity.HIGH,
900     'description':
901         'Java: Modifying a collection with itself',
902     'patterns': [r".*: warning: \[ModifyingCollectionWithItself\] .+"]},
903    {'category': 'java',
904     'severity': Severity.HIGH,
905     'description':
906         'Java: Compound assignments to bytes, shorts, chars, and floats hide dangerous casts',
907     'patterns': [r".*: warning: \[NarrowingCompoundAssignment\] .+"]},
908    {'category': 'java',
909     'severity': Severity.HIGH,
910     'description':
911         'Java: @NoAllocation was specified on this method, but something was found that would trigger an allocation',
912     'patterns': [r".*: warning: \[NoAllocation\] .+"]},
913    {'category': 'java',
914     'severity': Severity.HIGH,
915     'description':
916         'Java: Static import of type uses non-canonical name',
917     'patterns': [r".*: warning: \[NonCanonicalStaticImport\] .+"]},
918    {'category': 'java',
919     'severity': Severity.HIGH,
920     'description':
921         'Java: @CompileTimeConstant parameters should be final',
922     'patterns': [r".*: warning: \[NonFinalCompileTimeConstant\] .+"]},
923    {'category': 'java',
924     'severity': Severity.HIGH,
925     'description':
926         'Java: Calling getAnnotation on an annotation that is not retained at runtime.',
927     'patterns': [r".*: warning: \[NonRuntimeAnnotation\] .+"]},
928    {'category': 'java',
929     'severity': Severity.HIGH,
930     'description':
931         'Java: Numeric comparison using reference equality instead of value equality',
932     'patterns': [r".*: warning: \[NumericEquality\] .+"]},
933    {'category': 'java',
934     'severity': Severity.HIGH,
935     'description':
936         'Java: Comparison using reference equality instead of value equality',
937     'patterns': [r".*: warning: \[OptionalEquality\] .+"]},
938    {'category': 'java',
939     'severity': Severity.HIGH,
940     'description':
941         'Java: Varargs doesn\'t agree for overridden method',
942     'patterns': [r".*: warning: \[Overrides\] .+"]},
943    {'category': 'java',
944     'severity': Severity.HIGH,
945     'description':
946         'Java: Literal passed as first argument to Preconditions.checkNotNull() can never be null',
947     'patterns': [r".*: warning: \[PreconditionsCheckNotNull\] .+"]},
948    {'category': 'java',
949     'severity': Severity.HIGH,
950     'description':
951         'Java: First argument to `Preconditions.checkNotNull()` is a primitive rather than an object reference',
952     'patterns': [r".*: warning: \[PreconditionsCheckNotNullPrimitive\] .+"]},
953    {'category': 'java',
954     'severity': Severity.HIGH,
955     'description':
956         'Java: Protobuf fields cannot be null',
957     'patterns': [r".*: warning: \[ProtoFieldNullComparison\] .+"]},
958    {'category': 'java',
959     'severity': Severity.HIGH,
960     'description':
961         'Java: Comparing protobuf fields of type String using reference equality',
962     'patterns': [r".*: warning: \[ProtoStringFieldReferenceEquality\] .+"]},
963    {'category': 'java',
964     'severity': Severity.HIGH,
965     'description':
966         'Java:  Check for non-whitelisted callers to RestrictedApiChecker.',
967     'patterns': [r".*: warning: \[RestrictedApiChecker\] .+"]},
968    {'category': 'java',
969     'severity': Severity.HIGH,
970     'description':
971         'Java: Return value of this method must be used',
972     'patterns': [r".*: warning: \[ReturnValueIgnored\] .+"]},
973    {'category': 'java',
974     'severity': Severity.HIGH,
975     'description':
976         'Java: Variable assigned to itself',
977     'patterns': [r".*: warning: \[SelfAssignment\] .+"]},
978    {'category': 'java',
979     'severity': Severity.HIGH,
980     'description':
981         'Java: An object is compared to itself',
982     'patterns': [r".*: warning: \[SelfComparision\] .+"]},
983    {'category': 'java',
984     'severity': Severity.HIGH,
985     'description':
986         'Java: Variable compared to itself',
987     'patterns': [r".*: warning: \[SelfEquality\] .+"]},
988    {'category': 'java',
989     'severity': Severity.HIGH,
990     'description':
991         'Java: An object is tested for equality to itself',
992     'patterns': [r".*: warning: \[SelfEquals\] .+"]},
993    {'category': 'java',
994     'severity': Severity.HIGH,
995     'description':
996         'Java: Comparison of a size >= 0 is always true, did you intend to check for non-emptiness?',
997     'patterns': [r".*: warning: \[SizeGreaterThanOrEqualsZero\] .+"]},
998    {'category': 'java',
999     'severity': Severity.HIGH,
1000     'description':
1001         'Java: Calling toString on a Stream does not provide useful information',
1002     'patterns': [r".*: warning: \[StreamToString\] .+"]},
1003    {'category': 'java',
1004     'severity': Severity.HIGH,
1005     'description':
1006         'Java: StringBuilder does not have a char constructor; this invokes the int constructor.',
1007     'patterns': [r".*: warning: \[StringBuilderInitWithChar\] .+"]},
1008    {'category': 'java',
1009     'severity': Severity.HIGH,
1010     'description':
1011         'Java: Suppressing "deprecated" is probably a typo for "deprecation"',
1012     'patterns': [r".*: warning: \[SuppressWarningsDeprecated\] .+"]},
1013    {'category': 'java',
1014     'severity': Severity.HIGH,
1015     'description':
1016         'Java: throwIfUnchecked(knownCheckedException) is a no-op.',
1017     'patterns': [r".*: warning: \[ThrowIfUncheckedKnownChecked\] .+"]},
1018    {'category': 'java',
1019     'severity': Severity.HIGH,
1020     'description':
1021         'Java: Catching Throwable/Error masks failures from fail() or assert*() in the try block',
1022     'patterns': [r".*: warning: \[TryFailThrowable\] .+"]},
1023    {'category': 'java',
1024     'severity': Severity.HIGH,
1025     'description':
1026         'Java: Type parameter used as type qualifier',
1027     'patterns': [r".*: warning: \[TypeParameterQualifier\] .+"]},
1028    {'category': 'java',
1029     'severity': Severity.HIGH,
1030     'description':
1031         'Java: Non-generic methods should not be invoked with type arguments',
1032     'patterns': [r".*: warning: \[UnnecessaryTypeArgument\] .+"]},
1033    {'category': 'java',
1034     'severity': Severity.HIGH,
1035     'description':
1036         'Java: Instance created but never used',
1037     'patterns': [r".*: warning: \[UnusedAnonymousClass\] .+"]},
1038    {'category': 'java',
1039     'severity': Severity.HIGH,
1040     'description':
1041         'Java: Use of wildcard imports is forbidden',
1042     'patterns': [r".*: warning: \[WildcardImport\] .+"]},
1043    {'category': 'java',
1044     'severity': Severity.HIGH,
1045     'description':
1046         'Java: Method parameter has wrong package',
1047     'patterns': [r".*: warning: \[ParameterPackage\] .+"]},
1048    {'category': 'java',
1049     'severity': Severity.HIGH,
1050     'description':
1051         'Java: Certain resources in `android.R.string` have names that do not match their content',
1052     'patterns': [r".*: warning: \[MislabeledAndroidString\] .+"]},
1053    {'category': 'java',
1054     'severity': Severity.HIGH,
1055     'description':
1056         'Java: Return value of android.graphics.Rect.intersect() must be checked',
1057     'patterns': [r".*: warning: \[RectIntersectReturnValueIgnored\] .+"]},
1058    {'category': 'java',
1059     'severity': Severity.HIGH,
1060     'description':
1061         'Java: Invalid printf-style format string',
1062     'patterns': [r".*: warning: \[FormatString\] .+"]},
1063    {'category': 'java',
1064     'severity': Severity.HIGH,
1065     'description':
1066         'Java: @AssistedInject and @Inject cannot be used on the same constructor.',
1067     'patterns': [r".*: warning: \[AssistedInjectAndInjectOnSameConstructor\] .+"]},
1068    {'category': 'java',
1069     'severity': Severity.HIGH,
1070     'description':
1071         'Java: Injected constructors cannot be optional nor have binding annotations',
1072     'patterns': [r".*: warning: \[InjectedConstructorAnnotations\] .+"]},
1073    {'category': 'java',
1074     'severity': Severity.HIGH,
1075     'description':
1076         'Java: The target of a scoping annotation must be set to METHOD and/or TYPE.',
1077     'patterns': [r".*: warning: \[InjectInvalidTargetingOnScopingAnnotation\] .+"]},
1078    {'category': 'java',
1079     'severity': Severity.HIGH,
1080     'description':
1081         'Java: Abstract methods are not injectable with javax.inject.Inject.',
1082     'patterns': [r".*: warning: \[JavaxInjectOnAbstractMethod\] .+"]},
1083    {'category': 'java',
1084     'severity': Severity.HIGH,
1085     'description':
1086         'Java: @javax.inject.Inject cannot be put on a final field.',
1087     'patterns': [r".*: warning: \[JavaxInjectOnFinalField\] .+"]},
1088    {'category': 'java',
1089     'severity': Severity.HIGH,
1090     'description':
1091         'Java: A class may not have more than one injectable constructor.',
1092     'patterns': [r".*: warning: \[MoreThanOneInjectableConstructor\] .+"]},
1093    {'category': 'java',
1094     'severity': Severity.HIGH,
1095     'description':
1096         'Java: Using more than one qualifier annotation on the same element is not allowed.',
1097     'patterns': [r".*: warning: \[InjectMoreThanOneQualifier\] .+"]},
1098    {'category': 'java',
1099     'severity': Severity.HIGH,
1100     'description':
1101         'Java: A class can be annotated with at most one scope annotation',
1102     'patterns': [r".*: warning: \[InjectMoreThanOneScopeAnnotationOnClass\] .+"]},
1103    {'category': 'java',
1104     'severity': Severity.HIGH,
1105     'description':
1106         'Java: Annotations cannot be both Qualifiers/BindingAnnotations and Scopes',
1107     'patterns': [r".*: warning: \[OverlappingQualifierAndScopeAnnotation\] .+"]},
1108    {'category': 'java',
1109     'severity': Severity.HIGH,
1110     'description':
1111         'Java: Scope annotation on an interface or abstact class is not allowed',
1112     'patterns': [r".*: warning: \[InjectScopeAnnotationOnInterfaceOrAbstractClass\] .+"]},
1113    {'category': 'java',
1114     'severity': Severity.HIGH,
1115     'description':
1116         'Java: Scoping and qualifier annotations must have runtime retention.',
1117     'patterns': [r".*: warning: \[InjectScopeOrQualifierAnnotationRetention\] .+"]},
1118    {'category': 'java',
1119     'severity': Severity.HIGH,
1120     'description':
1121         'Java: Dagger @Provides methods may not return null unless annotated with @Nullable',
1122     'patterns': [r".*: warning: \[DaggerProvidesNull\] .+"]},
1123    {'category': 'java',
1124     'severity': Severity.HIGH,
1125     'description':
1126         'Java: Scope annotation on implementation class of AssistedInject factory is not allowed',
1127     'patterns': [r".*: warning: \[GuiceAssistedInjectScoping\] .+"]},
1128    {'category': 'java',
1129     'severity': Severity.HIGH,
1130     'description':
1131         'Java: A constructor cannot have two @Assisted parameters of the same type unless they are disambiguated with named @Assisted annotations. ',
1132     'patterns': [r".*: warning: \[GuiceAssistedParameters\] .+"]},
1133    {'category': 'java',
1134     'severity': Severity.HIGH,
1135     'description':
1136         'Java: This method is not annotated with @Inject, but it overrides a  method that is  annotated with @javax.inject.Inject.',
1137     'patterns': [r".*: warning: \[OverridesJavaxInjectableMethod\] .+"]},
1138    {'category': 'java',
1139     'severity': Severity.HIGH,
1140     'description':
1141         'Java: Checks for unguarded accesses to fields and methods with @GuardedBy annotations',
1142     'patterns': [r".*: warning: \[GuardedByChecker\] .+"]},
1143    {'category': 'java',
1144     'severity': Severity.HIGH,
1145     'description':
1146         'Java: Invalid @GuardedBy expression',
1147     'patterns': [r".*: warning: \[GuardedByValidator\] .+"]},
1148    {'category': 'java',
1149     'severity': Severity.HIGH,
1150     'description':
1151         'Java: Type declaration annotated with @Immutable is not immutable',
1152     'patterns': [r".*: warning: \[Immutable\] .+"]},
1153    {'category': 'java',
1154     'severity': Severity.HIGH,
1155     'description':
1156         'Java: This method does not acquire the locks specified by its @LockMethod annotation',
1157     'patterns': [r".*: warning: \[LockMethodChecker\] .+"]},
1158    {'category': 'java',
1159     'severity': Severity.HIGH,
1160     'description':
1161         'Java: This method does not acquire the locks specified by its @UnlockMethod annotation',
1162     'patterns': [r".*: warning: \[UnlockMethod\] .+"]},
1163
1164    {'category': 'java',
1165     'severity': Severity.UNKNOWN,
1166     'description': 'Java: Unclassified/unrecognized warnings',
1167     'patterns': [r".*: warning: \[.+\] .+"]},
1168
1169    {'category': 'aapt', 'severity': Severity.MEDIUM,
1170     'description': 'aapt: No default translation',
1171     'patterns': [r".*: warning: string '.+' has no default translation in .*"]},
1172    {'category': 'aapt', 'severity': Severity.MEDIUM,
1173     'description': 'aapt: Missing default or required localization',
1174     'patterns': [r".*: warning: \*\*\*\* string '.+' has no default or required localization for '.+' in .+"]},
1175    {'category': 'aapt', 'severity': Severity.MEDIUM,
1176     'description': 'aapt: String marked untranslatable, but translation exists',
1177     'patterns': [r".*: warning: string '.+' in .* marked untranslatable but exists in locale '??_??'"]},
1178    {'category': 'aapt', 'severity': Severity.MEDIUM,
1179     'description': 'aapt: empty span in string',
1180     'patterns': [r".*: warning: empty '.+' span found in text '.+"]},
1181    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1182     'description': 'Taking address of temporary',
1183     'patterns': [r".*: warning: taking address of temporary"]},
1184    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1185     'description': 'Possible broken line continuation',
1186     'patterns': [r".*: warning: backslash and newline separated by space"]},
1187    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wundefined-var-template',
1188     'description': 'Undefined variable template',
1189     'patterns': [r".*: warning: instantiation of variable .* no definition is available"]},
1190    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wundefined-inline',
1191     'description': 'Inline function is not defined',
1192     'patterns': [r".*: warning: inline function '.*' is not defined"]},
1193    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Warray-bounds',
1194     'description': 'Array subscript out of bounds',
1195     'patterns': [r".*: warning: array subscript is above array bounds",
1196                  r".*: warning: Array subscript is undefined",
1197                  r".*: warning: array subscript is below array bounds"]},
1198    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1199     'description': 'Excess elements in initializer',
1200     'patterns': [r".*: warning: excess elements in .+ initializer"]},
1201    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1202     'description': 'Decimal constant is unsigned only in ISO C90',
1203     'patterns': [r".*: warning: this decimal constant is unsigned only in ISO C90"]},
1204    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wmain',
1205     'description': 'main is usually a function',
1206     'patterns': [r".*: warning: 'main' is usually a function"]},
1207    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1208     'description': 'Typedef ignored',
1209     'patterns': [r".*: warning: 'typedef' was ignored in this declaration"]},
1210    {'category': 'C/C++', 'severity': Severity.HIGH, 'option': '-Waddress',
1211     'description': 'Address always evaluates to true',
1212     'patterns': [r".*: warning: the address of '.+' will always evaluate as 'true'"]},
1213    {'category': 'C/C++', 'severity': Severity.FIXMENOW,
1214     'description': 'Freeing a non-heap object',
1215     'patterns': [r".*: warning: attempt to free a non-heap object '.+'"]},
1216    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wchar-subscripts',
1217     'description': 'Array subscript has type char',
1218     'patterns': [r".*: warning: array subscript .+ type 'char'.+Wchar-subscripts"]},
1219    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1220     'description': 'Constant too large for type',
1221     'patterns': [r".*: warning: integer constant is too large for '.+' type"]},
1222    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Woverflow',
1223     'description': 'Constant too large for type, truncated',
1224     'patterns': [r".*: warning: large integer implicitly truncated to unsigned type"]},
1225    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Winteger-overflow',
1226     'description': 'Overflow in expression',
1227     'patterns': [r".*: warning: overflow in expression; .*Winteger-overflow"]},
1228    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Woverflow',
1229     'description': 'Overflow in implicit constant conversion',
1230     'patterns': [r".*: warning: overflow in implicit constant conversion"]},
1231    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1232     'description': 'Declaration does not declare anything',
1233     'patterns': [r".*: warning: declaration 'class .+' does not declare anything"]},
1234    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wreorder',
1235     'description': 'Initialization order will be different',
1236     'patterns': [r".*: warning: '.+' will be initialized after",
1237                  r".*: warning: field .+ will be initialized after .+Wreorder"]},
1238    {'category': 'cont.', 'severity': Severity.SKIP,
1239     'description': 'skip,   ....',
1240     'patterns': [r".*: warning:   '.+'"]},
1241    {'category': 'cont.', 'severity': Severity.SKIP,
1242     'description': 'skip,   base ...',
1243     'patterns': [r".*: warning:   base '.+'"]},
1244    {'category': 'cont.', 'severity': Severity.SKIP,
1245     'description': 'skip,   when initialized here',
1246     'patterns': [r".*: warning:   when initialized here"]},
1247    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wmissing-parameter-type',
1248     'description': 'Parameter type not specified',
1249     'patterns': [r".*: warning: type of '.+' defaults to 'int'"]},
1250    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wmissing-declarations',
1251     'description': 'Missing declarations',
1252     'patterns': [r".*: warning: declaration does not declare anything"]},
1253    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wmissing-noreturn',
1254     'description': 'Missing noreturn',
1255     'patterns': [r".*: warning: function '.*' could be declared with attribute 'noreturn'"]},
1256    # pylint:disable=anomalous-backslash-in-string
1257    # TODO(chh): fix the backslash pylint warning.
1258    {'category': 'gcc', 'severity': Severity.MEDIUM,
1259     'description': 'Invalid option for C file',
1260     'patterns': [r".*: warning: command line option "".+"" is valid for C\+\+\/ObjC\+\+ but not for C"]},
1261    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1262     'description': 'User warning',
1263     'patterns': [r".*: warning: #warning "".+"""]},
1264    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wvexing-parse',
1265     'description': 'Vexing parsing problem',
1266     'patterns': [r".*: warning: empty parentheses interpreted as a function declaration"]},
1267    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wextra',
1268     'description': 'Dereferencing void*',
1269     'patterns': [r".*: warning: dereferencing 'void \*' pointer"]},
1270    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1271     'description': 'Comparison of pointer and integer',
1272     'patterns': [r".*: warning: ordered comparison of pointer with integer zero",
1273                  r".*: warning: .*comparison between pointer and integer"]},
1274    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1275     'description': 'Use of error-prone unary operator',
1276     'patterns': [r".*: warning: use of unary operator that may be intended as compound assignment"]},
1277    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wwrite-strings',
1278     'description': 'Conversion of string constant to non-const char*',
1279     'patterns': [r".*: warning: deprecated conversion from string constant to '.+'"]},
1280    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wstrict-prototypes',
1281     'description': 'Function declaration isn''t a prototype',
1282     'patterns': [r".*: warning: function declaration isn't a prototype"]},
1283    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wignored-qualifiers',
1284     'description': 'Type qualifiers ignored on function return value',
1285     'patterns': [r".*: warning: type qualifiers ignored on function return type",
1286                  r".*: warning: .+ type qualifier .+ has no effect .+Wignored-qualifiers"]},
1287    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1288     'description': '<foo> declared inside parameter list, scope limited to this definition',
1289     'patterns': [r".*: warning: '.+' declared inside parameter list"]},
1290    {'category': 'cont.', 'severity': Severity.SKIP,
1291     'description': 'skip, its scope is only this ...',
1292     'patterns': [r".*: warning: its scope is only this definition or declaration, which is probably not what you want"]},
1293    {'category': 'C/C++', 'severity': Severity.LOW, 'option': '-Wcomment',
1294     'description': 'Line continuation inside comment',
1295     'patterns': [r".*: warning: multi-line comment"]},
1296    {'category': 'C/C++', 'severity': Severity.LOW, 'option': '-Wcomment',
1297     'description': 'Comment inside comment',
1298     'patterns': [r".*: warning: "".+"" within comment"]},
1299    # Warning "value stored is never read" could be from clang-tidy or clang static analyzer.
1300    {'category': 'C/C++', 'severity': Severity.ANALYZER,
1301     'description': 'clang-analyzer Value stored is never read',
1302     'patterns': [r".*: warning: Value stored to .+ is never read.*clang-analyzer-deadcode.DeadStores"]},
1303    {'category': 'C/C++', 'severity': Severity.LOW,
1304     'description': 'Value stored is never read',
1305     'patterns': [r".*: warning: Value stored to .+ is never read"]},
1306    {'category': 'C/C++', 'severity': Severity.LOW, 'option': '-Wdeprecated-declarations',
1307     'description': 'Deprecated declarations',
1308     'patterns': [r".*: warning: .+ is deprecated.+deprecated-declarations"]},
1309    {'category': 'C/C++', 'severity': Severity.LOW, 'option': '-Wdeprecated-register',
1310     'description': 'Deprecated register',
1311     'patterns': [r".*: warning: 'register' storage class specifier is deprecated"]},
1312    {'category': 'C/C++', 'severity': Severity.LOW, 'option': '-Wpointer-sign',
1313     'description': 'Converts between pointers to integer types with different sign',
1314     'patterns': [r".*: warning: .+ converts between pointers to integer types with different sign"]},
1315    {'category': 'C/C++', 'severity': Severity.HARMLESS,
1316     'description': 'Extra tokens after #endif',
1317     'patterns': [r".*: warning: extra tokens at end of #endif directive"]},
1318    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wenum-compare',
1319     'description': 'Comparison between different enums',
1320     'patterns': [r".*: warning: comparison between '.+' and '.+'.+Wenum-compare"]},
1321    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wconversion',
1322     'description': 'Conversion may change value',
1323     'patterns': [r".*: warning: converting negative value '.+' to '.+'",
1324                  r".*: warning: conversion to '.+' .+ may (alter|change)"]},
1325    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wconversion-null',
1326     'description': 'Converting to non-pointer type from NULL',
1327     'patterns': [r".*: warning: converting to non-pointer type '.+' from NULL"]},
1328    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wnull-conversion',
1329     'description': 'Converting NULL to non-pointer type',
1330     'patterns': [r".*: warning: implicit conversion of NULL constant to '.+'"]},
1331    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wnon-literal-null-conversion',
1332     'description': 'Zero used as null pointer',
1333     'patterns': [r".*: warning: expression .* zero treated as a null pointer constant"]},
1334    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1335     'description': 'Implicit conversion changes value',
1336     'patterns': [r".*: warning: implicit conversion .* changes value from .* to .*-conversion"]},
1337    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1338     'description': 'Passing NULL as non-pointer argument',
1339     'patterns': [r".*: warning: passing NULL to non-pointer argument [0-9]+ of '.+'"]},
1340    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wctor-dtor-privacy',
1341     'description': 'Class seems unusable because of private ctor/dtor',
1342     'patterns': [r".*: warning: all member functions in class '.+' are private"]},
1343    # skip this next one, because it only points out some RefBase-based classes where having a private destructor is perfectly fine
1344    {'category': 'C/C++', 'severity': Severity.SKIP, 'option': '-Wctor-dtor-privacy',
1345     'description': 'Class seems unusable because of private ctor/dtor',
1346     'patterns': [r".*: warning: 'class .+' only defines a private destructor and has no friends"]},
1347    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wctor-dtor-privacy',
1348     'description': 'Class seems unusable because of private ctor/dtor',
1349     'patterns': [r".*: warning: 'class .+' only defines private constructors and has no friends"]},
1350    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wgnu-static-float-init',
1351     'description': 'In-class initializer for static const float/double',
1352     'patterns': [r".*: warning: in-class initializer for static data member of .+const (float|double)"]},
1353    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wpointer-arith',
1354     'description': 'void* used in arithmetic',
1355     'patterns': [r".*: warning: pointer of type 'void \*' used in (arithmetic|subtraction)",
1356                  r".*: warning: arithmetic on .+ to void is a GNU extension.*Wpointer-arith",
1357                  r".*: warning: wrong type argument to increment"]},
1358    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wsign-promo',
1359     'description': 'Overload resolution chose to promote from unsigned or enum to signed type',
1360     'patterns': [r".*: warning: passing '.+' chooses '.+' over '.+'.*Wsign-promo"]},
1361    {'category': 'cont.', 'severity': Severity.SKIP,
1362     'description': 'skip,   in call to ...',
1363     'patterns': [r".*: warning:   in call to '.+'"]},
1364    {'category': 'C/C++', 'severity': Severity.HIGH, 'option': '-Wextra',
1365     'description': 'Base should be explicitly initialized in copy constructor',
1366     'patterns': [r".*: warning: base class '.+' should be explicitly initialized in the copy constructor"]},
1367    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1368     'description': 'VLA has zero or negative size',
1369     'patterns': [r".*: warning: Declared variable-length array \(VLA\) has .+ size"]},
1370    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1371     'description': 'Return value from void function',
1372     'patterns': [r".*: warning: 'return' with a value, in function returning void"]},
1373    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': 'multichar',
1374     'description': 'Multi-character character constant',
1375     'patterns': [r".*: warning: multi-character character constant"]},
1376    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': 'writable-strings',
1377     'description': 'Conversion from string literal to char*',
1378     'patterns': [r".*: warning: .+ does not allow conversion from string literal to 'char \*'"]},
1379    {'category': 'C/C++', 'severity': Severity.LOW, 'option': '-Wextra-semi',
1380     'description': 'Extra \';\'',
1381     'patterns': [r".*: warning: extra ';' .+extra-semi"]},
1382    {'category': 'C/C++', 'severity': Severity.LOW,
1383     'description': 'Useless specifier',
1384     'patterns': [r".*: warning: useless storage class specifier in empty declaration"]},
1385    {'category': 'C/C++', 'severity': Severity.LOW, 'option': '-Wduplicate-decl-specifier',
1386     'description': 'Duplicate declaration specifier',
1387     'patterns': [r".*: warning: duplicate '.+' declaration specifier"]},
1388    {'category': 'logtags', 'severity': Severity.LOW,
1389     'description': 'Duplicate logtag',
1390     'patterns': [r".*: warning: tag \".+\" \(.+\) duplicated in .+"]},
1391    {'category': 'logtags', 'severity': Severity.LOW, 'option': 'typedef-redefinition',
1392     'description': 'Typedef redefinition',
1393     'patterns': [r".*: warning: redefinition of typedef '.+' is a C11 feature"]},
1394    {'category': 'logtags', 'severity': Severity.LOW, 'option': 'gnu-designator',
1395     'description': 'GNU old-style field designator',
1396     'patterns': [r".*: warning: use of GNU old-style field designator extension"]},
1397    {'category': 'logtags', 'severity': Severity.LOW, 'option': 'missing-field-initializers',
1398     'description': 'Missing field initializers',
1399     'patterns': [r".*: warning: missing field '.+' initializer"]},
1400    {'category': 'logtags', 'severity': Severity.LOW, 'option': 'missing-braces',
1401     'description': 'Missing braces',
1402     'patterns': [r".*: warning: suggest braces around initialization of",
1403                  r".*: warning: too many braces around scalar initializer .+Wmany-braces-around-scalar-init",
1404                  r".*: warning: braces around scalar initializer"]},
1405    {'category': 'logtags', 'severity': Severity.LOW, 'option': 'sign-compare',
1406     'description': 'Comparison of integers of different signs',
1407     'patterns': [r".*: warning: comparison of integers of different signs.+sign-compare"]},
1408    {'category': 'logtags', 'severity': Severity.LOW, 'option': 'dangling-else',
1409     'description': 'Add braces to avoid dangling else',
1410     'patterns': [r".*: warning: add explicit braces to avoid dangling else"]},
1411    {'category': 'logtags', 'severity': Severity.LOW, 'option': 'initializer-overrides',
1412     'description': 'Initializer overrides prior initialization',
1413     'patterns': [r".*: warning: initializer overrides prior initialization of this subobject"]},
1414    {'category': 'logtags', 'severity': Severity.LOW, 'option': 'self-assign',
1415     'description': 'Assigning value to self',
1416     'patterns': [r".*: warning: explicitly assigning value of .+ to itself"]},
1417    {'category': 'logtags', 'severity': Severity.LOW, 'option': 'gnu-variable-sized-type-not-at-end',
1418     'description': 'GNU extension, variable sized type not at end',
1419     'patterns': [r".*: warning: field '.+' with variable sized type '.+' not at the end of a struct or class"]},
1420    {'category': 'logtags', 'severity': Severity.LOW, 'option': 'tautological-constant-out-of-range-compare',
1421     'description': 'Comparison of constant is always false/true',
1422     'patterns': [r".*: comparison of .+ is always .+Wtautological-constant-out-of-range-compare"]},
1423    {'category': 'logtags', 'severity': Severity.LOW, 'option': 'overloaded-virtual',
1424     'description': 'Hides overloaded virtual function',
1425     'patterns': [r".*: '.+' hides overloaded virtual function"]},
1426    {'category': 'logtags', 'severity': Severity.LOW, 'option': 'incompatible-pointer-types',
1427     'description': 'Incompatible pointer types',
1428     'patterns': [r".*: warning: incompatible pointer types .+Wincompatible-pointer-types"]},
1429    {'category': 'logtags', 'severity': Severity.LOW, 'option': 'asm-operand-widths',
1430     'description': 'ASM value size does not match register size',
1431     'patterns': [r".*: warning: value size does not match register size specified by the constraint and modifier"]},
1432    {'category': 'C/C++', 'severity': Severity.LOW, 'option': 'tautological-compare',
1433     'description': 'Comparison of self is always false',
1434     'patterns': [r".*: self-comparison always evaluates to false"]},
1435    {'category': 'C/C++', 'severity': Severity.LOW, 'option': 'constant-logical-operand',
1436     'description': 'Logical op with constant operand',
1437     'patterns': [r".*: use of logical '.+' with constant operand"]},
1438    {'category': 'C/C++', 'severity': Severity.LOW, 'option': 'literal-suffix',
1439     'description': 'Needs a space between literal and string macro',
1440     'patterns': [r".*: warning: invalid suffix on literal.+ requires a space .+Wliteral-suffix"]},
1441    {'category': 'C/C++', 'severity': Severity.LOW, 'option': '#warnings',
1442     'description': 'Warnings from #warning',
1443     'patterns': [r".*: warning: .+-W#warnings"]},
1444    {'category': 'C/C++', 'severity': Severity.LOW, 'option': 'absolute-value',
1445     'description': 'Using float/int absolute value function with int/float argument',
1446     'patterns': [r".*: warning: using .+ absolute value function .+ when argument is .+ type .+Wabsolute-value",
1447                  r".*: warning: absolute value function '.+' given .+ which may cause truncation .+Wabsolute-value"]},
1448    {'category': 'C/C++', 'severity': Severity.LOW, 'option': '-Wc++11-extensions',
1449     'description': 'Using C++11 extensions',
1450     'patterns': [r".*: warning: 'auto' type specifier is a C\+\+11 extension"]},
1451    {'category': 'C/C++', 'severity': Severity.LOW,
1452     'description': 'Refers to implicitly defined namespace',
1453     'patterns': [r".*: warning: using directive refers to implicitly-defined namespace .+"]},
1454    {'category': 'C/C++', 'severity': Severity.LOW, 'option': '-Winvalid-pp-token',
1455     'description': 'Invalid pp token',
1456     'patterns': [r".*: warning: missing .+Winvalid-pp-token"]},
1457
1458    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1459     'description': 'Operator new returns NULL',
1460     'patterns': [r".*: warning: 'operator new' must not return NULL unless it is declared 'throw\(\)' .+"]},
1461    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wnull-arithmetic',
1462     'description': 'NULL used in arithmetic',
1463     'patterns': [r".*: warning: NULL used in arithmetic",
1464                  r".*: warning: comparison between NULL and non-pointer"]},
1465    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': 'header-guard',
1466     'description': 'Misspelled header guard',
1467     'patterns': [r".*: warning: '.+' is used as a header guard .+ followed by .+ different macro"]},
1468    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': 'empty-body',
1469     'description': 'Empty loop body',
1470     'patterns': [r".*: warning: .+ loop has empty body"]},
1471    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': 'enum-conversion',
1472     'description': 'Implicit conversion from enumeration type',
1473     'patterns': [r".*: warning: implicit conversion from enumeration type '.+'"]},
1474    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': 'switch',
1475     'description': 'case value not in enumerated type',
1476     'patterns': [r".*: warning: case value not in enumerated type '.+'"]},
1477    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1478     'description': 'Undefined result',
1479     'patterns': [r".*: warning: The result of .+ is undefined",
1480                  r".*: warning: passing an object that .+ has undefined behavior \[-Wvarargs\]",
1481                  r".*: warning: 'this' pointer cannot be null in well-defined C\+\+ code;",
1482                  r".*: warning: shifting a negative signed value is undefined"]},
1483    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1484     'description': 'Division by zero',
1485     'patterns': [r".*: warning: Division by zero"]},
1486    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1487     'description': 'Use of deprecated method',
1488     'patterns': [r".*: warning: '.+' is deprecated .+"]},
1489    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1490     'description': 'Use of garbage or uninitialized value',
1491     'patterns': [r".*: warning: .+ is a garbage value",
1492                  r".*: warning: Function call argument is an uninitialized value",
1493                  r".*: warning: Undefined or garbage value returned to caller",
1494                  r".*: warning: Called .+ pointer is.+uninitialized",
1495                  r".*: warning: Called .+ pointer is.+uninitalized",  # match a typo in compiler message
1496                  r".*: warning: Use of zero-allocated memory",
1497                  r".*: warning: Dereference of undefined pointer value",
1498                  r".*: warning: Passed-by-value .+ contains uninitialized data",
1499                  r".*: warning: Branch condition evaluates to a garbage value",
1500                  r".*: warning: The .+ of .+ is an uninitialized value.",
1501                  r".*: warning: .+ is used uninitialized whenever .+sometimes-uninitialized",
1502                  r".*: warning: Assigned value is garbage or undefined"]},
1503    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1504     'description': 'Result of malloc type incompatible with sizeof operand type',
1505     'patterns': [r".*: warning: Result of '.+' is converted to .+ incompatible with sizeof operand type"]},
1506    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wsizeof-array-argument',
1507     'description': 'Sizeof on array argument',
1508     'patterns': [r".*: warning: sizeof on array function parameter will return"]},
1509    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wsizeof-pointer-memacces',
1510     'description': 'Bad argument size of memory access functions',
1511     'patterns': [r".*: warning: .+\[-Wsizeof-pointer-memaccess\]"]},
1512    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1513     'description': 'Return value not checked',
1514     'patterns': [r".*: warning: The return value from .+ is not checked"]},
1515    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1516     'description': 'Possible heap pollution',
1517     'patterns': [r".*: warning: .*Possible heap pollution from .+ type .+"]},
1518    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1519     'description': 'Allocation size of 0 byte',
1520     'patterns': [r".*: warning: Call to .+ has an allocation size of 0 byte"]},
1521    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1522     'description': 'Result of malloc type incompatible with sizeof operand type',
1523     'patterns': [r".*: warning: Result of '.+' is converted to .+ incompatible with sizeof operand type"]},
1524    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wfor-loop-analysis',
1525     'description': 'Variable used in loop condition not modified in loop body',
1526     'patterns': [r".*: warning: variable '.+' used in loop condition.*Wfor-loop-analysis"]},
1527    {'category': 'C/C++', 'severity': Severity.MEDIUM,
1528     'description': 'Closing a previously closed file',
1529     'patterns': [r".*: warning: Closing a previously closed file"]},
1530    {'category': 'C/C++', 'severity': Severity.MEDIUM, 'option': '-Wunnamed-type-template-args',
1531     'description': 'Unnamed template type argument',
1532     'patterns': [r".*: warning: template argument.+Wunnamed-type-template-args"]},
1533
1534    {'category': 'C/C++', 'severity': Severity.HARMLESS,
1535     'description': 'Discarded qualifier from pointer target type',
1536     'patterns': [r".*: warning: .+ discards '.+' qualifier from pointer target type"]},
1537    {'category': 'C/C++', 'severity': Severity.HARMLESS,
1538     'description': 'Use snprintf instead of sprintf',
1539     'patterns': [r".*: warning: .*sprintf is often misused; please use snprintf"]},
1540    {'category': 'C/C++', 'severity': Severity.HARMLESS,
1541     'description': 'Unsupported optimizaton flag',
1542     'patterns': [r".*: warning: optimization flag '.+' is not supported"]},
1543    {'category': 'C/C++', 'severity': Severity.HARMLESS,
1544     'description': 'Extra or missing parentheses',
1545     'patterns': [r".*: warning: equality comparison with extraneous parentheses",
1546                  r".*: warning: .+ within .+Wlogical-op-parentheses"]},
1547    {'category': 'C/C++', 'severity': Severity.HARMLESS, 'option': 'mismatched-tags',
1548     'description': 'Mismatched class vs struct tags',
1549     'patterns': [r".*: warning: '.+' defined as a .+ here but previously declared as a .+mismatched-tags",
1550                  r".*: warning: .+ was previously declared as a .+mismatched-tags"]},
1551
1552    # these next ones are to deal with formatting problems resulting from the log being mixed up by 'make -j'
1553    {'category': 'C/C++', 'severity': Severity.SKIP,
1554     'description': 'skip, ,',
1555     'patterns': [r".*: warning: ,$"]},
1556    {'category': 'C/C++', 'severity': Severity.SKIP,
1557     'description': 'skip,',
1558     'patterns': [r".*: warning: $"]},
1559    {'category': 'C/C++', 'severity': Severity.SKIP,
1560     'description': 'skip, In file included from ...',
1561     'patterns': [r".*: warning: In file included from .+,"]},
1562
1563    # warnings from clang-tidy
1564    {'category': 'C/C++', 'severity': Severity.TIDY,
1565     'description': 'clang-tidy readability',
1566     'patterns': [r".*: .+\[readability-.+\]$"]},
1567    {'category': 'C/C++', 'severity': Severity.TIDY,
1568     'description': 'clang-tidy c++ core guidelines',
1569     'patterns': [r".*: .+\[cppcoreguidelines-.+\]$"]},
1570    {'category': 'C/C++', 'severity': Severity.TIDY,
1571     'description': 'clang-tidy google-default-arguments',
1572     'patterns': [r".*: .+\[google-default-arguments\]$"]},
1573    {'category': 'C/C++', 'severity': Severity.TIDY,
1574     'description': 'clang-tidy google-runtime-int',
1575     'patterns': [r".*: .+\[google-runtime-int\]$"]},
1576    {'category': 'C/C++', 'severity': Severity.TIDY,
1577     'description': 'clang-tidy google-runtime-operator',
1578     'patterns': [r".*: .+\[google-runtime-operator\]$"]},
1579    {'category': 'C/C++', 'severity': Severity.TIDY,
1580     'description': 'clang-tidy google-runtime-references',
1581     'patterns': [r".*: .+\[google-runtime-references\]$"]},
1582    {'category': 'C/C++', 'severity': Severity.TIDY,
1583     'description': 'clang-tidy google-build',
1584     'patterns': [r".*: .+\[google-build-.+\]$"]},
1585    {'category': 'C/C++', 'severity': Severity.TIDY,
1586     'description': 'clang-tidy google-explicit',
1587     'patterns': [r".*: .+\[google-explicit-.+\]$"]},
1588    {'category': 'C/C++', 'severity': Severity.TIDY,
1589     'description': 'clang-tidy google-readability',
1590     'patterns': [r".*: .+\[google-readability-.+\]$"]},
1591    {'category': 'C/C++', 'severity': Severity.TIDY,
1592     'description': 'clang-tidy google-global',
1593     'patterns': [r".*: .+\[google-global-.+\]$"]},
1594    {'category': 'C/C++', 'severity': Severity.TIDY,
1595     'description': 'clang-tidy google- other',
1596     'patterns': [r".*: .+\[google-.+\]$"]},
1597    {'category': 'C/C++', 'severity': Severity.TIDY,
1598     'description': 'clang-tidy modernize',
1599     'patterns': [r".*: .+\[modernize-.+\]$"]},
1600    {'category': 'C/C++', 'severity': Severity.TIDY,
1601     'description': 'clang-tidy misc',
1602     'patterns': [r".*: .+\[misc-.+\]$"]},
1603    {'category': 'C/C++', 'severity': Severity.TIDY,
1604     'description': 'clang-tidy performance-faster-string-find',
1605     'patterns': [r".*: .+\[performance-faster-string-find\]$"]},
1606    {'category': 'C/C++', 'severity': Severity.TIDY,
1607     'description': 'clang-tidy performance-for-range-copy',
1608     'patterns': [r".*: .+\[performance-for-range-copy\]$"]},
1609    {'category': 'C/C++', 'severity': Severity.TIDY,
1610     'description': 'clang-tidy performance-implicit-cast-in-loop',
1611     'patterns': [r".*: .+\[performance-implicit-cast-in-loop\]$"]},
1612    {'category': 'C/C++', 'severity': Severity.TIDY,
1613     'description': 'clang-tidy performance-unnecessary-copy-initialization',
1614     'patterns': [r".*: .+\[performance-unnecessary-copy-initialization\]$"]},
1615    {'category': 'C/C++', 'severity': Severity.TIDY,
1616     'description': 'clang-tidy performance-unnecessary-value-param',
1617     'patterns': [r".*: .+\[performance-unnecessary-value-param\]$"]},
1618    {'category': 'C/C++', 'severity': Severity.ANALYZER,
1619     'description': 'clang-analyzer Unreachable code',
1620     'patterns': [r".*: warning: This statement is never executed.*UnreachableCode"]},
1621    {'category': 'C/C++', 'severity': Severity.ANALYZER,
1622     'description': 'clang-analyzer Size of malloc may overflow',
1623     'patterns': [r".*: warning: .* size of .* may overflow .*MallocOverflow"]},
1624    {'category': 'C/C++', 'severity': Severity.ANALYZER,
1625     'description': 'clang-analyzer Stream pointer might be NULL',
1626     'patterns': [r".*: warning: Stream pointer might be NULL .*unix.Stream"]},
1627    {'category': 'C/C++', 'severity': Severity.ANALYZER,
1628     'description': 'clang-analyzer Opened file never closed',
1629     'patterns': [r".*: warning: Opened File never closed.*unix.Stream"]},
1630    {'category': 'C/C++', 'severity': Severity.ANALYZER,
1631     'description': 'clang-analyzer sozeof() on a pointer type',
1632     'patterns': [r".*: warning: .*calls sizeof.* on a pointer type.*SizeofPtr"]},
1633    {'category': 'C/C++', 'severity': Severity.ANALYZER,
1634     'description': 'clang-analyzer Pointer arithmetic on non-array variables',
1635     'patterns': [r".*: warning: Pointer arithmetic on non-array variables .*PointerArithm"]},
1636    {'category': 'C/C++', 'severity': Severity.ANALYZER,
1637     'description': 'clang-analyzer Subtraction of pointers of different memory chunks',
1638     'patterns': [r".*: warning: Subtraction of two pointers .*PointerSub"]},
1639    {'category': 'C/C++', 'severity': Severity.ANALYZER,
1640     'description': 'clang-analyzer Access out-of-bound array element',
1641     'patterns': [r".*: warning: Access out-of-bound array element .*ArrayBound"]},
1642    {'category': 'C/C++', 'severity': Severity.ANALYZER,
1643     'description': 'clang-analyzer Out of bound memory access',
1644     'patterns': [r".*: warning: Out of bound memory access .*ArrayBoundV2"]},
1645    {'category': 'C/C++', 'severity': Severity.ANALYZER,
1646     'description': 'clang-analyzer Possible lock order reversal',
1647     'patterns': [r".*: warning: .* Possible lock order reversal.*PthreadLock"]},
1648    {'category': 'C/C++', 'severity': Severity.ANALYZER,
1649     'description': 'clang-analyzer Argument is a pointer to uninitialized value',
1650     'patterns': [r".*: warning: .* argument is a pointer to uninitialized value .*CallAndMessage"]},
1651    {'category': 'C/C++', 'severity': Severity.ANALYZER,
1652     'description': 'clang-analyzer cast to struct',
1653     'patterns': [r".*: warning: Casting a non-structure type to a structure type .*CastToStruct"]},
1654    {'category': 'C/C++', 'severity': Severity.ANALYZER,
1655     'description': 'clang-analyzer call path problems',
1656     'patterns': [r".*: warning: Call Path : .+"]},
1657    {'category': 'C/C++', 'severity': Severity.ANALYZER,
1658     'description': 'clang-analyzer other',
1659     'patterns': [r".*: .+\[clang-analyzer-.+\]$",
1660                  r".*: Call Path : .+$"]},
1661    {'category': 'C/C++', 'severity': Severity.TIDY,
1662     'description': 'clang-tidy CERT',
1663     'patterns': [r".*: .+\[cert-.+\]$"]},
1664    {'category': 'C/C++', 'severity': Severity.TIDY,
1665     'description': 'clang-tidy llvm',
1666     'patterns': [r".*: .+\[llvm-.+\]$"]},
1667    {'category': 'C/C++', 'severity': Severity.TIDY,
1668     'description': 'clang-diagnostic',
1669     'patterns': [r".*: .+\[clang-diagnostic-.+\]$"]},
1670
1671    # catch-all for warnings this script doesn't know about yet
1672    {'category': 'C/C++', 'severity': Severity.UNKNOWN,
1673     'description': 'Unclassified/unrecognized warnings',
1674     'patterns': [r".*: warning: .+"]},
1675]
1676
1677
1678def project_name_and_pattern(name, pattern):
1679  return [name, '(^|.*/)' + pattern + '/.*: warning:']
1680
1681
1682def simple_project_pattern(pattern):
1683  return project_name_and_pattern(pattern, pattern)
1684
1685
1686# A list of [project_name, file_path_pattern].
1687# project_name should not contain comma, to be used in CSV output.
1688project_list = [
1689    simple_project_pattern('art'),
1690    simple_project_pattern('bionic'),
1691    simple_project_pattern('bootable'),
1692    simple_project_pattern('build'),
1693    simple_project_pattern('cts'),
1694    simple_project_pattern('dalvik'),
1695    simple_project_pattern('developers'),
1696    simple_project_pattern('development'),
1697    simple_project_pattern('device'),
1698    simple_project_pattern('doc'),
1699    # match external/google* before external/
1700    project_name_and_pattern('external/google', 'external/google.*'),
1701    project_name_and_pattern('external/non-google', 'external'),
1702    simple_project_pattern('frameworks/av/camera'),
1703    simple_project_pattern('frameworks/av/cmds'),
1704    simple_project_pattern('frameworks/av/drm'),
1705    simple_project_pattern('frameworks/av/include'),
1706    simple_project_pattern('frameworks/av/media/common_time'),
1707    simple_project_pattern('frameworks/av/media/img_utils'),
1708    simple_project_pattern('frameworks/av/media/libcpustats'),
1709    simple_project_pattern('frameworks/av/media/libeffects'),
1710    simple_project_pattern('frameworks/av/media/libmediaplayerservice'),
1711    simple_project_pattern('frameworks/av/media/libmedia'),
1712    simple_project_pattern('frameworks/av/media/libstagefright'),
1713    simple_project_pattern('frameworks/av/media/mtp'),
1714    simple_project_pattern('frameworks/av/media/ndk'),
1715    simple_project_pattern('frameworks/av/media/utils'),
1716    project_name_and_pattern('frameworks/av/media/Other',
1717                             'frameworks/av/media'),
1718    simple_project_pattern('frameworks/av/radio'),
1719    simple_project_pattern('frameworks/av/services'),
1720    simple_project_pattern('frameworks/av/soundtrigger'),
1721    project_name_and_pattern('frameworks/av/Other', 'frameworks/av'),
1722    simple_project_pattern('frameworks/base/cmds'),
1723    simple_project_pattern('frameworks/base/core'),
1724    simple_project_pattern('frameworks/base/drm'),
1725    simple_project_pattern('frameworks/base/media'),
1726    simple_project_pattern('frameworks/base/libs'),
1727    simple_project_pattern('frameworks/base/native'),
1728    simple_project_pattern('frameworks/base/packages'),
1729    simple_project_pattern('frameworks/base/rs'),
1730    simple_project_pattern('frameworks/base/services'),
1731    simple_project_pattern('frameworks/base/tests'),
1732    simple_project_pattern('frameworks/base/tools'),
1733    project_name_and_pattern('frameworks/base/Other', 'frameworks/base'),
1734    simple_project_pattern('frameworks/compile/libbcc'),
1735    simple_project_pattern('frameworks/compile/mclinker'),
1736    simple_project_pattern('frameworks/compile/slang'),
1737    project_name_and_pattern('frameworks/compile/Other', 'frameworks/compile'),
1738    simple_project_pattern('frameworks/minikin'),
1739    simple_project_pattern('frameworks/ml'),
1740    simple_project_pattern('frameworks/native/cmds'),
1741    simple_project_pattern('frameworks/native/include'),
1742    simple_project_pattern('frameworks/native/libs'),
1743    simple_project_pattern('frameworks/native/opengl'),
1744    simple_project_pattern('frameworks/native/services'),
1745    simple_project_pattern('frameworks/native/vulkan'),
1746    project_name_and_pattern('frameworks/native/Other', 'frameworks/native'),
1747    simple_project_pattern('frameworks/opt'),
1748    simple_project_pattern('frameworks/rs'),
1749    simple_project_pattern('frameworks/webview'),
1750    simple_project_pattern('frameworks/wilhelm'),
1751    project_name_and_pattern('frameworks/Other', 'frameworks'),
1752    simple_project_pattern('hardware/akm'),
1753    simple_project_pattern('hardware/broadcom'),
1754    simple_project_pattern('hardware/google'),
1755    simple_project_pattern('hardware/intel'),
1756    simple_project_pattern('hardware/interfaces'),
1757    simple_project_pattern('hardware/libhardware'),
1758    simple_project_pattern('hardware/libhardware_legacy'),
1759    simple_project_pattern('hardware/qcom'),
1760    simple_project_pattern('hardware/ril'),
1761    project_name_and_pattern('hardware/Other', 'hardware'),
1762    simple_project_pattern('kernel'),
1763    simple_project_pattern('libcore'),
1764    simple_project_pattern('libnativehelper'),
1765    simple_project_pattern('ndk'),
1766    # match vendor/unbungled_google/packages before other packages
1767    simple_project_pattern('unbundled_google'),
1768    simple_project_pattern('packages'),
1769    simple_project_pattern('pdk'),
1770    simple_project_pattern('prebuilts'),
1771    simple_project_pattern('system/bt'),
1772    simple_project_pattern('system/connectivity'),
1773    simple_project_pattern('system/core/adb'),
1774    simple_project_pattern('system/core/base'),
1775    simple_project_pattern('system/core/debuggerd'),
1776    simple_project_pattern('system/core/fastboot'),
1777    simple_project_pattern('system/core/fingerprintd'),
1778    simple_project_pattern('system/core/fs_mgr'),
1779    simple_project_pattern('system/core/gatekeeperd'),
1780    simple_project_pattern('system/core/healthd'),
1781    simple_project_pattern('system/core/include'),
1782    simple_project_pattern('system/core/init'),
1783    simple_project_pattern('system/core/libbacktrace'),
1784    simple_project_pattern('system/core/liblog'),
1785    simple_project_pattern('system/core/libpixelflinger'),
1786    simple_project_pattern('system/core/libprocessgroup'),
1787    simple_project_pattern('system/core/libsysutils'),
1788    simple_project_pattern('system/core/logcat'),
1789    simple_project_pattern('system/core/logd'),
1790    simple_project_pattern('system/core/run-as'),
1791    simple_project_pattern('system/core/sdcard'),
1792    simple_project_pattern('system/core/toolbox'),
1793    project_name_and_pattern('system/core/Other', 'system/core'),
1794    simple_project_pattern('system/extras/ANRdaemon'),
1795    simple_project_pattern('system/extras/cpustats'),
1796    simple_project_pattern('system/extras/crypto-perf'),
1797    simple_project_pattern('system/extras/ext4_utils'),
1798    simple_project_pattern('system/extras/f2fs_utils'),
1799    simple_project_pattern('system/extras/iotop'),
1800    simple_project_pattern('system/extras/libfec'),
1801    simple_project_pattern('system/extras/memory_replay'),
1802    simple_project_pattern('system/extras/micro_bench'),
1803    simple_project_pattern('system/extras/mmap-perf'),
1804    simple_project_pattern('system/extras/multinetwork'),
1805    simple_project_pattern('system/extras/perfprofd'),
1806    simple_project_pattern('system/extras/procrank'),
1807    simple_project_pattern('system/extras/runconuid'),
1808    simple_project_pattern('system/extras/showmap'),
1809    simple_project_pattern('system/extras/simpleperf'),
1810    simple_project_pattern('system/extras/su'),
1811    simple_project_pattern('system/extras/tests'),
1812    simple_project_pattern('system/extras/verity'),
1813    project_name_and_pattern('system/extras/Other', 'system/extras'),
1814    simple_project_pattern('system/gatekeeper'),
1815    simple_project_pattern('system/keymaster'),
1816    simple_project_pattern('system/libhidl'),
1817    simple_project_pattern('system/libhwbinder'),
1818    simple_project_pattern('system/media'),
1819    simple_project_pattern('system/netd'),
1820    simple_project_pattern('system/nvram'),
1821    simple_project_pattern('system/security'),
1822    simple_project_pattern('system/sepolicy'),
1823    simple_project_pattern('system/tools'),
1824    simple_project_pattern('system/update_engine'),
1825    simple_project_pattern('system/vold'),
1826    project_name_and_pattern('system/Other', 'system'),
1827    simple_project_pattern('toolchain'),
1828    simple_project_pattern('test'),
1829    simple_project_pattern('tools'),
1830    # match vendor/google* before vendor/
1831    project_name_and_pattern('vendor/google', 'vendor/google.*'),
1832    project_name_and_pattern('vendor/non-google', 'vendor'),
1833    # keep out/obj and other patterns at the end.
1834    ['out/obj',
1835     '.*/(gen|obj[^/]*)/(include|EXECUTABLES|SHARED_LIBRARIES|'
1836     'STATIC_LIBRARIES|NATIVE_TESTS)/.*: warning:'],
1837    ['other', '.*']  # all other unrecognized patterns
1838]
1839
1840project_patterns = []
1841project_names = []
1842warning_messages = []
1843warning_records = []
1844
1845
1846def initialize_arrays():
1847  """Complete global arrays before they are used."""
1848  global project_names, project_patterns
1849  project_names = [p[0] for p in project_list]
1850  project_patterns = [re.compile(p[1]) for p in project_list]
1851  for w in warn_patterns:
1852    w['members'] = []
1853    if 'option' not in w:
1854      w['option'] = ''
1855    # Each warning pattern has a 'projects' dictionary, that
1856    # maps a project name to number of warnings in that project.
1857    w['projects'] = {}
1858
1859
1860initialize_arrays()
1861
1862
1863android_root = ''
1864platform_version = 'unknown'
1865target_product = 'unknown'
1866target_variant = 'unknown'
1867
1868
1869##### Data and functions to dump html file. ##################################
1870
1871html_head_scripts = """\
1872  <script type="text/javascript">
1873  function expand(id) {
1874    var e = document.getElementById(id);
1875    var f = document.getElementById(id + "_mark");
1876    if (e.style.display == 'block') {
1877       e.style.display = 'none';
1878       f.innerHTML = '&#x2295';
1879    }
1880    else {
1881       e.style.display = 'block';
1882       f.innerHTML = '&#x2296';
1883    }
1884  };
1885  function expandCollapse(show) {
1886    for (var id = 1; ; id++) {
1887      var e = document.getElementById(id + "");
1888      var f = document.getElementById(id + "_mark");
1889      if (!e || !f) break;
1890      e.style.display = (show ? 'block' : 'none');
1891      f.innerHTML = (show ? '&#x2296' : '&#x2295');
1892    }
1893  };
1894  </script>
1895  <style type="text/css">
1896  th,td{border-collapse:collapse; border:1px solid black;}
1897  .button{color:blue;font-size:110%;font-weight:bolder;}
1898  .bt{color:black;background-color:transparent;border:none;outline:none;
1899      font-size:140%;font-weight:bolder;}
1900  .c0{background-color:#e0e0e0;}
1901  .c1{background-color:#d0d0d0;}
1902  .t1{border-collapse:collapse; width:100%; border:1px solid black;}
1903  </style>
1904  <script src="https://www.gstatic.com/charts/loader.js"></script>
1905"""
1906
1907
1908def html_big(param):
1909  return '<font size="+2">' + param + '</font>'
1910
1911
1912def dump_html_prologue(title):
1913  print '<html>\n<head>'
1914  print '<title>' + title + '</title>'
1915  print html_head_scripts
1916  emit_stats_by_project()
1917  print '</head>\n<body>'
1918  print html_big(title)
1919  print '<p>'
1920
1921
1922def dump_html_epilogue():
1923  print '</body>\n</head>\n</html>'
1924
1925
1926def sort_warnings():
1927  for i in warn_patterns:
1928    i['members'] = sorted(set(i['members']))
1929
1930
1931def emit_stats_by_project():
1932  """Dump a google chart table of warnings per project and severity."""
1933  # warnings[p][s] is number of warnings in project p of severity s.
1934  warnings = {p: {s: 0 for s in Severity.range} for p in project_names}
1935  for i in warn_patterns:
1936    s = i['severity']
1937    for p in i['projects']:
1938      warnings[p][s] += i['projects'][p]
1939
1940  # total_by_project[p] is number of warnings in project p.
1941  total_by_project = {p: sum(warnings[p][s] for s in Severity.range)
1942                      for p in project_names}
1943
1944  # total_by_severity[s] is number of warnings of severity s.
1945  total_by_severity = {s: sum(warnings[p][s] for p in project_names)
1946                       for s in Severity.range}
1947
1948  # emit table header
1949  stats_header = ['Project']
1950  for s in Severity.range:
1951    if total_by_severity[s]:
1952      stats_header.append("<span style='background-color:{}'>{}</span>".
1953                          format(Severity.colors[s],
1954                                 Severity.column_headers[s]))
1955  stats_header.append('TOTAL')
1956
1957  # emit a row of warning counts per project, skip no-warning projects
1958  total_all_projects = 0
1959  stats_rows = []
1960  for p in project_names:
1961    if total_by_project[p]:
1962      one_row = [p]
1963      for s in Severity.range:
1964        if total_by_severity[s]:
1965          one_row.append(warnings[p][s])
1966      one_row.append(total_by_project[p])
1967      stats_rows.append(one_row)
1968      total_all_projects += total_by_project[p]
1969
1970  # emit a row of warning counts per severity
1971  total_all_severities = 0
1972  one_row = ['<b>TOTAL</b>']
1973  for s in Severity.range:
1974    if total_by_severity[s]:
1975      one_row.append(total_by_severity[s])
1976      total_all_severities += total_by_severity[s]
1977  one_row.append(total_all_projects)
1978  stats_rows.append(one_row)
1979  print '<script>'
1980  emit_const_string_array('StatsHeader', stats_header)
1981  emit_const_object_array('StatsRows', stats_rows)
1982  print draw_table_javascript
1983  print '</script>'
1984
1985
1986def dump_stats():
1987  """Dump some stats about total number of warnings and such."""
1988  known = 0
1989  skipped = 0
1990  unknown = 0
1991  sort_warnings()
1992  for i in warn_patterns:
1993    if i['severity'] == Severity.UNKNOWN:
1994      unknown += len(i['members'])
1995    elif i['severity'] == Severity.SKIP:
1996      skipped += len(i['members'])
1997    else:
1998      known += len(i['members'])
1999  print 'Number of classified warnings: <b>' + str(known) + '</b><br>'
2000  print 'Number of skipped warnings: <b>' + str(skipped) + '</b><br>'
2001  print 'Number of unclassified warnings: <b>' + str(unknown) + '</b><br>'
2002  total = unknown + known + skipped
2003  extra_msg = ''
2004  if total < 1000:
2005    extra_msg = ' (low count may indicate incremental build)'
2006  print 'Total number of warnings: <b>' + str(total) + '</b>' + extra_msg
2007
2008
2009# New base table of warnings, [severity, warn_id, project, warning_message]
2010# Need buttons to show warnings in different grouping options.
2011# (1) Current, group by severity, id for each warning pattern
2012#     sort by severity, warn_id, warning_message
2013# (2) Current --byproject, group by severity,
2014#     id for each warning pattern + project name
2015#     sort by severity, warn_id, project, warning_message
2016# (3) New, group by project + severity,
2017#     id for each warning pattern
2018#     sort by project, severity, warn_id, warning_message
2019def emit_buttons():
2020  print ('<button class="button" onclick="expandCollapse(1);">'
2021         'Expand all warnings</button>\n'
2022         '<button class="button" onclick="expandCollapse(0);">'
2023         'Collapse all warnings</button>\n'
2024         '<button class="button" onclick="groupBySeverity();">'
2025         'Group warnings by severity</button>\n'
2026         '<button class="button" onclick="groupByProject();">'
2027         'Group warnings by project</button><br>')
2028
2029
2030def all_patterns(category):
2031  patterns = ''
2032  for i in category['patterns']:
2033    patterns += i
2034    patterns += ' / '
2035  return patterns
2036
2037
2038def dump_fixed():
2039  """Show which warnings no longer occur."""
2040  anchor = 'fixed_warnings'
2041  mark = anchor + '_mark'
2042  print ('\n<br><p style="background-color:lightblue"><b>'
2043         '<button id="' + mark + '" '
2044         'class="bt" onclick="expand(\'' + anchor + '\');">'
2045         '&#x2295</button> Fixed warnings. '
2046         'No more occurrences. Please consider turning these into '
2047         'errors if possible, before they are reintroduced in to the build'
2048         ':</b></p>')
2049  print '<blockquote>'
2050  fixed_patterns = []
2051  for i in warn_patterns:
2052    if not i['members']:
2053      fixed_patterns.append(i['description'] + ' (' +
2054                            all_patterns(i) + ')')
2055    if i['option']:
2056      fixed_patterns.append(' ' + i['option'])
2057  fixed_patterns.sort()
2058  print '<div id="' + anchor + '" style="display:none;"><table>'
2059  cur_row_class = 0
2060  for text in fixed_patterns:
2061    cur_row_class = 1 - cur_row_class
2062    # remove last '\n'
2063    t = text[:-1] if text[-1] == '\n' else text
2064    print '<tr><td class="c' + str(cur_row_class) + '">' + t + '</td></tr>'
2065  print '</table></div>'
2066  print '</blockquote>'
2067
2068
2069def find_project_index(line):
2070  for p in range(len(project_patterns)):
2071    if project_patterns[p].match(line):
2072      return p
2073  return -1
2074
2075
2076def classify_one_warning(line, results):
2077  for i in range(len(warn_patterns)):
2078    w = warn_patterns[i]
2079    for cpat in w['compiled_patterns']:
2080      if cpat.match(line):
2081        p = find_project_index(line)
2082        results.append([line, i, p])
2083        return
2084      else:
2085        # If we end up here, there was a problem parsing the log
2086        # probably caused by 'make -j' mixing the output from
2087        # 2 or more concurrent compiles
2088        pass
2089
2090
2091def classify_warnings(lines):
2092  results = []
2093  for line in lines:
2094    classify_one_warning(line, results)
2095  # After the main work, ignore all other signals to a child process,
2096  # to avoid bad warning/error messages from the exit clean-up process.
2097  if args.processes > 1:
2098    signal.signal(signal.SIGTERM, lambda *args: sys.exit(-signal.SIGTERM))
2099  return results
2100
2101
2102def parallel_classify_warnings(warning_lines):
2103  """Classify all warning lines with num_cpu parallel processes."""
2104  compile_patterns()
2105  num_cpu = args.processes
2106  if num_cpu > 1:
2107    groups = [[] for x in range(num_cpu)]
2108    i = 0
2109    for x in warning_lines:
2110      groups[i].append(x)
2111      i = (i + 1) % num_cpu
2112    pool = multiprocessing.Pool(num_cpu)
2113    group_results = pool.map(classify_warnings, groups)
2114  else:
2115    group_results = [classify_warnings(warning_lines)]
2116
2117  for result in group_results:
2118    for line, pattern_idx, project_idx in result:
2119      pattern = warn_patterns[pattern_idx]
2120      pattern['members'].append(line)
2121      message_idx = len(warning_messages)
2122      warning_messages.append(line)
2123      warning_records.append([pattern_idx, project_idx, message_idx])
2124      pname = '???' if project_idx < 0 else project_names[project_idx]
2125      # Count warnings by project.
2126      if pname in pattern['projects']:
2127        pattern['projects'][pname] += 1
2128      else:
2129        pattern['projects'][pname] = 1
2130
2131
2132def compile_patterns():
2133  """Precompiling every pattern speeds up parsing by about 30x."""
2134  for i in warn_patterns:
2135    i['compiled_patterns'] = []
2136    for pat in i['patterns']:
2137      i['compiled_patterns'].append(re.compile(pat))
2138
2139
2140def find_android_root(path):
2141  """Set and return android_root path if it is found."""
2142  global android_root
2143  parts = path.split('/')
2144  for idx in reversed(range(2, len(parts))):
2145    root_path = '/'.join(parts[:idx])
2146    # Android root directory should contain this script.
2147    if os.path.exists(root_path + '/build/tools/warn.py'):
2148      android_root = root_path
2149      return root_path
2150  return ''
2151
2152
2153def remove_android_root_prefix(path):
2154  """Remove android_root prefix from path if it is found."""
2155  if path.startswith(android_root):
2156    return path[1 + len(android_root):]
2157  else:
2158    return path
2159
2160
2161def normalize_path(path):
2162  """Normalize file path relative to android_root."""
2163  # If path is not an absolute path, just normalize it.
2164  path = os.path.normpath(path)
2165  if path[0] != '/':
2166    return path
2167  # Remove known prefix of root path and normalize the suffix.
2168  if android_root or find_android_root(path):
2169    return remove_android_root_prefix(path)
2170  else:
2171    return path
2172
2173
2174def normalize_warning_line(line):
2175  """Normalize file path relative to android_root in a warning line."""
2176  # replace fancy quotes with plain ol' quotes
2177  line = line.replace('‘', "'")
2178  line = line.replace('’', "'")
2179  line = line.strip()
2180  first_column = line.find(':')
2181  if first_column > 0:
2182    return normalize_path(line[:first_column]) + line[first_column:]
2183  else:
2184    return line
2185
2186
2187def parse_input_file(infile):
2188  """Parse input file, match warning lines."""
2189  global platform_version
2190  global target_product
2191  global target_variant
2192  line_counter = 0
2193
2194  # handle only warning messages with a file path
2195  warning_pattern = re.compile('^[^ ]*/[^ ]*: warning: .*')
2196
2197  # Collect all warnings into the warning_lines set.
2198  warning_lines = set()
2199  for line in infile:
2200    if warning_pattern.match(line):
2201      line = normalize_warning_line(line)
2202      warning_lines.add(line)
2203    elif line_counter < 50:
2204      # save a little bit of time by only doing this for the first few lines
2205      line_counter += 1
2206      m = re.search('(?<=^PLATFORM_VERSION=).*', line)
2207      if m is not None:
2208        platform_version = m.group(0)
2209      m = re.search('(?<=^TARGET_PRODUCT=).*', line)
2210      if m is not None:
2211        target_product = m.group(0)
2212      m = re.search('(?<=^TARGET_BUILD_VARIANT=).*', line)
2213      if m is not None:
2214        target_variant = m.group(0)
2215  return warning_lines
2216
2217
2218# Return s with escaped backslash and quotation characters.
2219def escape_string(s):
2220  return s.replace('\\', '\\\\').replace('"', '\\"')
2221
2222
2223# Return s without trailing '\n' and escape the quotation characters.
2224def strip_escape_string(s):
2225  if not s:
2226    return s
2227  s = s[:-1] if s[-1] == '\n' else s
2228  return escape_string(s)
2229
2230
2231def emit_warning_array(name):
2232  print 'var warning_{} = ['.format(name)
2233  for i in range(len(warn_patterns)):
2234    print '{},'.format(warn_patterns[i][name])
2235  print '];'
2236
2237
2238def emit_warning_arrays():
2239  emit_warning_array('severity')
2240  print 'var warning_description = ['
2241  for i in range(len(warn_patterns)):
2242    if warn_patterns[i]['members']:
2243      print '"{}",'.format(escape_string(warn_patterns[i]['description']))
2244    else:
2245      print '"",'  # no such warning
2246  print '];'
2247
2248scripts_for_warning_groups = """
2249  function compareMessages(x1, x2) { // of the same warning type
2250    return (WarningMessages[x1[2]] <= WarningMessages[x2[2]]) ? -1 : 1;
2251  }
2252  function byMessageCount(x1, x2) {
2253    return x2[2] - x1[2];  // reversed order
2254  }
2255  function bySeverityMessageCount(x1, x2) {
2256    // orer by severity first
2257    if (x1[1] != x2[1])
2258      return  x1[1] - x2[1];
2259    return byMessageCount(x1, x2);
2260  }
2261  const ParseLinePattern = /^([^ :]+):(\\d+):(.+)/;
2262  function addURL(line) {
2263    if (FlagURL == "") return line;
2264    if (FlagSeparator == "") {
2265      return line.replace(ParseLinePattern,
2266        "<a href='" + FlagURL + "/$1'>$1</a>:$2:$3");
2267    }
2268    return line.replace(ParseLinePattern,
2269      "<a href='" + FlagURL + "/$1" + FlagSeparator + "$2'>$1:$2</a>:$3");
2270  }
2271  function createArrayOfDictionaries(n) {
2272    var result = [];
2273    for (var i=0; i<n; i++) result.push({});
2274    return result;
2275  }
2276  function groupWarningsBySeverity() {
2277    // groups is an array of dictionaries,
2278    // each dictionary maps from warning type to array of warning messages.
2279    var groups = createArrayOfDictionaries(SeverityColors.length);
2280    for (var i=0; i<Warnings.length; i++) {
2281      var w = Warnings[i][0];
2282      var s = WarnPatternsSeverity[w];
2283      var k = w.toString();
2284      if (!(k in groups[s]))
2285        groups[s][k] = [];
2286      groups[s][k].push(Warnings[i]);
2287    }
2288    return groups;
2289  }
2290  function groupWarningsByProject() {
2291    var groups = createArrayOfDictionaries(ProjectNames.length);
2292    for (var i=0; i<Warnings.length; i++) {
2293      var w = Warnings[i][0];
2294      var p = Warnings[i][1];
2295      var k = w.toString();
2296      if (!(k in groups[p]))
2297        groups[p][k] = [];
2298      groups[p][k].push(Warnings[i]);
2299    }
2300    return groups;
2301  }
2302  var GlobalAnchor = 0;
2303  function createWarningSection(header, color, group) {
2304    var result = "";
2305    var groupKeys = [];
2306    var totalMessages = 0;
2307    for (var k in group) {
2308       totalMessages += group[k].length;
2309       groupKeys.push([k, WarnPatternsSeverity[parseInt(k)], group[k].length]);
2310    }
2311    groupKeys.sort(bySeverityMessageCount);
2312    for (var idx=0; idx<groupKeys.length; idx++) {
2313      var k = groupKeys[idx][0];
2314      var messages = group[k];
2315      var w = parseInt(k);
2316      var wcolor = SeverityColors[WarnPatternsSeverity[w]];
2317      var description = WarnPatternsDescription[w];
2318      if (description.length == 0)
2319          description = "???";
2320      GlobalAnchor += 1;
2321      result += "<table class='t1'><tr bgcolor='" + wcolor + "'><td>" +
2322                "<button class='bt' id='" + GlobalAnchor + "_mark" +
2323                "' onclick='expand(\\"" + GlobalAnchor + "\\");'>" +
2324                "&#x2295</button> " +
2325                description + " (" + messages.length + ")</td></tr></table>";
2326      result += "<div id='" + GlobalAnchor +
2327                "' style='display:none;'><table class='t1'>";
2328      var c = 0;
2329      messages.sort(compareMessages);
2330      for (var i=0; i<messages.length; i++) {
2331        result += "<tr><td class='c" + c + "'>" +
2332                  addURL(WarningMessages[messages[i][2]]) + "</td></tr>";
2333        c = 1 - c;
2334      }
2335      result += "</table></div>";
2336    }
2337    if (result.length > 0) {
2338      return "<br><span style='background-color:" + color + "'><b>" +
2339             header + ": " + totalMessages +
2340             "</b></span><blockquote><table class='t1'>" +
2341             result + "</table></blockquote>";
2342
2343    }
2344    return "";  // empty section
2345  }
2346  function generateSectionsBySeverity() {
2347    var result = "";
2348    var groups = groupWarningsBySeverity();
2349    for (s=0; s<SeverityColors.length; s++) {
2350      result += createWarningSection(SeverityHeaders[s], SeverityColors[s], groups[s]);
2351    }
2352    return result;
2353  }
2354  function generateSectionsByProject() {
2355    var result = "";
2356    var groups = groupWarningsByProject();
2357    for (i=0; i<groups.length; i++) {
2358      result += createWarningSection(ProjectNames[i], 'lightgrey', groups[i]);
2359    }
2360    return result;
2361  }
2362  function groupWarnings(generator) {
2363    GlobalAnchor = 0;
2364    var e = document.getElementById("warning_groups");
2365    e.innerHTML = generator();
2366  }
2367  function groupBySeverity() {
2368    groupWarnings(generateSectionsBySeverity);
2369  }
2370  function groupByProject() {
2371    groupWarnings(generateSectionsByProject);
2372  }
2373"""
2374
2375
2376# Emit a JavaScript const string
2377def emit_const_string(name, value):
2378  print 'const ' + name + ' = "' + escape_string(value) + '";'
2379
2380
2381# Emit a JavaScript const integer array.
2382def emit_const_int_array(name, array):
2383  print 'const ' + name + ' = ['
2384  for n in array:
2385    print str(n) + ','
2386  print '];'
2387
2388
2389# Emit a JavaScript const string array.
2390def emit_const_string_array(name, array):
2391  print 'const ' + name + ' = ['
2392  for s in array:
2393    print '"' + strip_escape_string(s) + '",'
2394  print '];'
2395
2396
2397# Emit a JavaScript const object array.
2398def emit_const_object_array(name, array):
2399  print 'const ' + name + ' = ['
2400  for x in array:
2401    print str(x) + ','
2402  print '];'
2403
2404
2405def emit_js_data():
2406  """Dump dynamic HTML page's static JavaScript data."""
2407  emit_const_string('FlagURL', args.url if args.url else '')
2408  emit_const_string('FlagSeparator', args.separator if args.separator else '')
2409  emit_const_string_array('SeverityColors', Severity.colors)
2410  emit_const_string_array('SeverityHeaders', Severity.headers)
2411  emit_const_string_array('SeverityColumnHeaders', Severity.column_headers)
2412  emit_const_string_array('ProjectNames', project_names)
2413  emit_const_int_array('WarnPatternsSeverity',
2414                       [w['severity'] for w in warn_patterns])
2415  emit_const_string_array('WarnPatternsDescription',
2416                          [w['description'] for w in warn_patterns])
2417  emit_const_string_array('WarnPatternsOption',
2418                          [w['option'] for w in warn_patterns])
2419  emit_const_string_array('WarningMessages', warning_messages)
2420  emit_const_object_array('Warnings', warning_records)
2421
2422draw_table_javascript = """
2423google.charts.load('current', {'packages':['table']});
2424google.charts.setOnLoadCallback(drawTable);
2425function drawTable() {
2426  var data = new google.visualization.DataTable();
2427  data.addColumn('string', StatsHeader[0]);
2428  for (var i=1; i<StatsHeader.length; i++) {
2429    data.addColumn('number', StatsHeader[i]);
2430  }
2431  data.addRows(StatsRows);
2432  for (var i=0; i<StatsRows.length; i++) {
2433    for (var j=0; j<StatsHeader.length; j++) {
2434      data.setProperty(i, j, 'style', 'border:1px solid black;');
2435    }
2436  }
2437  var table = new google.visualization.Table(document.getElementById('stats_table'));
2438  table.draw(data, {allowHtml: true, alternatingRowStyle: true});
2439}
2440"""
2441
2442
2443def dump_html():
2444  """Dump the html output to stdout."""
2445  dump_html_prologue('Warnings for ' + platform_version + ' - ' +
2446                     target_product + ' - ' + target_variant)
2447  dump_stats()
2448  print '<br><div id="stats_table"></div><br>'
2449  print '\n<script>'
2450  emit_js_data()
2451  print scripts_for_warning_groups
2452  print '</script>'
2453  emit_buttons()
2454  # Warning messages are grouped by severities or project names.
2455  print '<br><div id="warning_groups"></div>'
2456  if args.byproject:
2457    print '<script>groupByProject();</script>'
2458  else:
2459    print '<script>groupBySeverity();</script>'
2460  dump_fixed()
2461  dump_html_epilogue()
2462
2463
2464##### Functions to count warnings and dump csv file. #########################
2465
2466
2467def description_for_csv(category):
2468  if not category['description']:
2469    return '?'
2470  return category['description']
2471
2472
2473def string_for_csv(s):
2474  # Only some Java warning desciptions have used quotation marks.
2475  # TODO(chh): if s has double quote character, s should be quoted.
2476  if ',' in s:
2477    # TODO(chh): replace a double quote with two double quotes in s.
2478    return '"{}"'.format(s)
2479  return s
2480
2481
2482def count_severity(sev, kind):
2483  """Count warnings of given severity."""
2484  total = 0
2485  for i in warn_patterns:
2486    if i['severity'] == sev and i['members']:
2487      n = len(i['members'])
2488      total += n
2489      warning = string_for_csv(kind + ': ' + description_for_csv(i))
2490      print '{},,{}'.format(n, warning)
2491      # print number of warnings for each project, ordered by project name.
2492      projects = i['projects'].keys()
2493      projects.sort()
2494      for p in projects:
2495        print '{},{},{}'.format(i['projects'][p], p, warning)
2496  print '{},,{}'.format(total, kind + ' warnings')
2497  return total
2498
2499
2500# dump number of warnings in csv format to stdout
2501def dump_csv():
2502  """Dump number of warnings in csv format to stdout."""
2503  sort_warnings()
2504  total = 0
2505  for s in Severity.range:
2506    total += count_severity(s, Severity.column_headers[s])
2507  print '{},,{}'.format(total, 'All warnings')
2508
2509
2510def main():
2511  warning_lines = parse_input_file(open(args.buildlog, 'r'))
2512  parallel_classify_warnings(warning_lines)
2513  if args.gencsv:
2514    dump_csv()
2515  else:
2516    dump_html()
2517
2518
2519# Run main function if warn.py is the main program.
2520if __name__ == '__main__':
2521  main()
2522