~widelands-dev/widelands/bug-1803602-reveal-frisian-campaign

« back to all changes in this revision

Viewing changes to cmake/codecheck/rules/loop_with_numerical_constant_condition

  • Committer: qcs
  • Date: 2010-02-05 01:13:20 UTC
  • Revision ID: git-v1:136d6c48811c97ec1f98301726134b0de66f868c
Manual merge of cmake-migration branch to trunk

git-svn-id: https://widelands.svn.sourceforge.net/svnroot/widelands/trunk@5030 37b2a8de-5219-0410-9f54-a31bc463ab9c

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
 
 
4
"""
 
5
This catches a numerical constant used as a loop condition. Instead of while
 
6
(true) or while (1), one should write for (;;). But it avoids catching some
 
7
cases that are used in macro definitions (see
 
8
[http://vivekkutal.blogspot.com/2006/03/do-while0.html]):
 
9
    #define macro(...) do {...} while (false)
 
10
"""
 
11
 
 
12
error_msg="Do not use numerical constants in loop condition!"
 
13
 
 
14
regexp =r"""(^.?|[^}].|.[^ ])while *\((true|false|(0x[[:xdigit:]]+|[[:digit:]]+)[Uu]?(L|l|LL|ll)?|[[:digit:]]*\.[[:digit:]]+[Ll]?)\)"""
 
15
 
 
16
forbidden = [
 
17
    'while (false)',
 
18
    'while (true)',
 
19
    'while (0)',
 
20
    'while (1)',
 
21
    'while (00)',
 
22
    'while (0U)',
 
23
    'while (0u)',
 
24
    'while (0UL)',
 
25
    'while (0uL)',
 
26
    'while (0Ul)',
 
27
    'while (0ul)',
 
28
    'while (0ULL)',
 
29
    'while (0uLL)',
 
30
    'while (0Ull)',
 
31
    'while (0ull)',
 
32
    'while (01)',
 
33
    'while (1U)',
 
34
    'while (1u)',
 
35
    'while (1UL)',
 
36
    'while (1uL)',
 
37
    'while (1Ul)',
 
38
    'while (1ul)',
 
39
    'while (1ULL)',
 
40
    'while (1uLL)',
 
41
    'while (1Ull)',
 
42
    'while (1ull)',
 
43
    'while (01.1)',
 
44
    'while (.1)',
 
45
    'while (.1L)',
 
46
    'while (.1l)',
 
47
    'while (.0)',
 
48
    'while (.0L)',
 
49
    'while (.0l)',
 
50
    'while (1.01)',
 
51
    'while (1.01L)',
 
52
    'while (1.01l)',
 
53
    'while (0xf)',
 
54
    'while (0x9d)',
 
55
    ' while (0x9d)',
 
56
    '  while (0x9d)',
 
57
]
 
58
 
 
59
allowed = [
 
60
    'for (;;)',
 
61
    'while (a)',
 
62
    'while (1 + b)',
 
63
    '} while (false)',
 
64
]