Diff of /check_style.py [f931c6] .. [e50284]  Maximize  Restore

Switch to unified view

a/check_style.py b/check_style.py
...
...
66
elseif = re.compile(".*#else(if)*")
66
elseif = re.compile(".*#else(if)*")
67
doxygen_comment = re.compile(r"(\s*///|.*/\*\*<|.*///<)")
67
doxygen_comment = re.compile(r"(\s*///|.*/\*\*<|.*///<)")
68
namespace_close = re.compile(r".*(%s\snamespace|namespace\s%s)" % (identifier, identifier))
68
namespace_close = re.compile(r".*(%s\snamespace|namespace\s%s)" % (identifier, identifier))
69
http = re.compile(".*http://.*")
69
http = re.compile(".*http://.*")
70
return_statement = re.compile(".*return ")
70
return_statement = re.compile(".*return ")
71
operator_decl = re.compile(".*operator..*\(")
71
operator_decl = re.compile(".*operator%s" % binop)
72
bin_operator_decl = re.compile(".*operator%s" % binop)
72
pointer_missing_space = re.compile(".*%s\s+[*]%s" % (identifier, identifier))
73
pointer_missing_space = re.compile(".*%s\s+[*]%s" % (identifier, identifier))
73
reference_missing_space = re.compile(".*%s\s+[&]%s" % (identifier, identifier))
74
reference_missing_space = re.compile(".*%s\s+[&]%s" % (identifier, identifier))
74
binop_missing_space_before = re.compile(".*[^ \t\n]+%s" % binop)
75
binop_missing_space_before = re.compile(".*[^ \t\n]+%s" % binop)
75
binop_missing_space_after = re.compile(".*%s[^ ;\t\n]+" % binop)
76
binop_missing_space_after = re.compile(".*%s[^ ;\t\n]+" % binop)
76
spurious_one_line_block = re.compile("\s*[ ]|[\t]+catch .*{.*|[\t]+try {.*")
77
spurious_one_line_block = re.compile("\s*[ ]|[\t]+catch .*{.*|[\t]+try {.*")
78
const_inline_func = re.compile(".*const {")
77
79
78
simple_regexps = [
80
simple_regexps = [
79
    ( re.compile(r".*%s\(" % control_keyword), "missing space after control keyword"),
81
    ( re.compile(r".*%s\(" % control_keyword), "missing space after control keyword"),
80
    ( re.compile(".* ,"), "extra space before comma"),
82
    ( re.compile(".* ,"), "extra space before comma"),
81
    ( re.compile(r".*,[^ \n'\"].*"), "comma not followed by whitespace"),
83
    ( re.compile(r".*,[^ \n'\"].*"), "comma not followed by whitespace"),
...
...
135
    "QApplication",
137
    "QApplication",
136
    "setMainWidget",
138
    "setMainWidget",
137
    "QFileDialog::getExistingDirectory",
139
    "QFileDialog::getExistingDirectory",
138
    "QFileDialog::getOpenFileName",
140
    "QFileDialog::getOpenFileName",
139
    "isNull",
141
    "isNull",
142
  "CPU_PPC64_POWER5p",
140
]
143
]
141
144
142
false_positives = [
145
false_positives = [
146
"#define KERNEL_OFFSET 0xC0000000",
143
"   To value;",
147
"   To value;",
144
"template <typename To, typename From>",
148
"template <typename To, typename From>",
145
"To op_lexical_cast(From const & src)",
149
"To op_lexical_cast(From const & src)",
146
"string const begin_comment(\"/* \");",
150
"string const begin_comment(\"/* \");",
147
"   if ((pmc0 & ~0x1UL) != 0UL) {",
151
"   if ((pmc0 & ~0x1UL) != 0UL) {",
...
...
166
"#define MSR_IA32_APICBASE 0x1B",
170
"#define MSR_IA32_APICBASE 0x1B",
167
"#define GET_APIC_VERSION(x)    ((x)&0xFF)",
171
"#define GET_APIC_VERSION(x)    ((x)&0xFF)",
168
"#define GET_APIC_MAXLVT(x) (((x)>>16)&0xFF)",
172
"#define GET_APIC_MAXLVT(x) (((x)>>16)&0xFF)",
169
"#define APIC_INTEGRATED(x) ((x)&0xF0)",
173
"#define APIC_INTEGRATED(x) ((x)&0xF0)",
170
"#define CCCR_RESERVED_BITS 0x38030FFF",
174
"#define CCCR_RESERVED_BITS 0x38030FFF",
171
" *          // do something",
175
" *     // do something",
172
"   if (sample.vma & ~0xffffffffLLU)",
176
"   if (sample.vma & ~0xffffffffLLU)",
173
"   address = *(unsigned short *)phys_to_virt(0x40E);",
177
"   address = *(unsigned short *)phys_to_virt(0x40E);",
174
"       smp_scan_config(0xF0000,0x10000)) {",
178
"       smp_scan_config(0xF0000,0x10000)) {",
175
"   return sum & 0xFF;",
179
"   return sum & 0xFF;",
176
"             << \" valid range is [\" << OP_MIN_BUF_SIZE << \", \"",
180
"             << \" valid range is [\" << OP_MIN_BUF_SIZE << \", \"",
...
...
187
"   { \"///usr\", \"usr\" },",
191
"   { \"///usr\", \"usr\" },",
188
"   { \"///usr/dir\", \"dir\" },",
192
"   { \"///usr/dir\", \"dir\" },",
189
"   { \"///usr//dir\", \"dir\" },",
193
"   { \"///usr//dir\", \"dir\" },",
190
"   { \".//.//\" \"file_manip_tests.o\", \"file_manip_tests.o\" },",
194
"   { \".//.//\" \"file_manip_tests.o\", \"file_manip_tests.o\" },",
191
"template <typename Throw, typename Catch>",
195
"template <typename Throw, typename Catch>",
192
"            \"verbose output\", \"all,debug,bfd,level1,sfile,stats\"),",
196
"            \"verbose output\", \"all,debug,bfd,level1,sfile,stats,xml\"),",
193
"   sscanf(arg, \"%lx,%lx\", &kernel_start, &kernel_end);",
197
"   sscanf(arg, \"%lx,%lx\", &kernel_start, &kernel_end);",
194
"       event->user = copy_ulong(&c, ',');",
198
"       event->user = copy_ulong(&c, ',');",
195
"   glob_filter f1(\"foo,*bar\", \"foobar\");",
199
"   glob_filter f1(\"foo,*bar\", \"foobar\");",
196
"            \"comma separated list\", \"cpu,tid,tgid,unitmask,all\"),",
200
"            \"comma separated list\", \"cpu,tid,tgid,unitmask,all\"),",
197
"            \"comma separated list\", \"cpu,lib,tid,tgid,unitmask,all\"),",
201
"            \"comma separated list\", \"cpu,lib,tid,tgid,unitmask,all\"),",
...
...
216
"   left_rule.add_pattern(\"[ ]*\\\"(.*)\\\"[ ]*=.*\", \"\\\\1\");",
220
"   left_rule.add_pattern(\"[ ]*\\\"(.*)\\\"[ ]*=.*\", \"\\\\1\");",
217
"   var_value_rule.add_pattern(\".*=[ ]*\\\"(.*)\\\"\", \"\\\\1\");",
221
"   var_value_rule.add_pattern(\".*=[ ]*\\\"(.*)\\\"\", \"\\\\1\");",
218
"   var_name_rule.add_pattern(\"^\\\\$([_a-zA-Z][_a-zA-Z0-9]*)[ ]*=.*\", \"\\\\1\");",
222
"   var_name_rule.add_pattern(\"^\\\\$([_a-zA-Z][_a-zA-Z0-9]*)[ ]*=.*\", \"\\\\1\");",
219
"   synth_syms.reset(new asymbol * [cur_symcount + start]);",
223
"   synth_syms.reset(new asymbol * [cur_symcount + start]);",
220
"                                   + \" [self]\");",
224
"                                   + \" [self]\");",
225
"#elif (defined(__mips__) && (_MIPS_SIM == _MIPS_SIM_ABI32)) /*_MIPSEL */",
226
" sscanf(arg, \"%llx,%llx\", &xen_image.start, &xen_image.end);",
227
"           << \" valid range is [0 (use default), buffer size/2] \"",
228
"           << \" valid range is [\" << OP_MIN_CPU_BUF_SIZE << \", \"",
229
"           << \" valid range is [\" << OP_MIN_CPU_BUF_SIZE << \", \"",
230
"         ordered_samples.find(node[pos].key);",
231
"           << \" valid range is [\" << 0 << \", \"",
232
" void fill(size_type size, T const & value) {",
221
]
233
]
222
234
223
def err(file, nr, line, message):
235
def err(file, nr, line, message):
224
    global total_errors
236
    global total_errors
225
237
...
...
297
            return
309
            return
298
        if spurious_one_line_block.match(last):
310
        if spurious_one_line_block.match(last):
299
            return
311
            return
300
        if len(lines[nr-2].expandtabs()) >= 80:
312
        if len(lines[nr-2].expandtabs()) >= 80:
301
            return
313
            return
314
      if operator_decl.match(last):
315
          return
316
      if const_inline_func.match(last):
317
          return
318
      for false in false_positives:
319
          if false == last:
320
              return
302
        err(file, nr, lines[nr-1], "unnecessary brace around one line block")
321
        err(file, nr, lines[nr-1], "unnecessary brace around one line block")
303
322
304
in_comment = False
323
in_comment = False
305
324
306
def check_line(file, nr, line, prev_line, lines):
325
def check_line(file, nr, line, prev_line, lines):
...
...
338
        err(file, nr, line, "warning: possible missing space after pointer declaration")
357
        err(file, nr, line, "warning: possible missing space after pointer declaration")
339
358
340
    if reference_missing_space.match(line) and not return_statement.match(line):
359
    if reference_missing_space.match(line) and not return_statement.match(line):
341
        err(file, nr, line, "warning: possible missing space after reference declaration")
360
        err(file, nr, line, "warning: possible missing space after reference declaration")
342
361
343
    if binop_missing_space_before.match(line) and not operator_decl.match(line):
362
    if binop_missing_space_before.match(line) and not bin_operator_decl.match(line):
344
        err(file, nr, line, "warning: missing space before binary operator")
363
        err(file, nr, line, "warning: missing space before binary operator")
345
364
346
    if binop_missing_space_after.match(line) and not operator_decl.match(line):
365
    if binop_missing_space_after.match(line) and not bin_operator_decl.match(line):
347
        err(file, nr, line, "warning: missing space after binary operator")
366
        err(file, nr, line, "warning: missing space after binary operator")
348
367
349
    if opt.check_length and len(line) > 80:
368
    if opt.check_length and len(line) > 80:
350
        err(file, nr, line, "warning: line is of length %d" % len(line))
369
        err(file, nr, line, "warning: line is of length %d" % len(line))
351
370

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks