Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
blender-dev-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-dev-tools
Commits
30d4611e
Commit
30d4611e
authored
6 years ago
by
Campbell Barton
Browse files
Options
Downloads
Patches
Plain Diff
check_style_c: fix error in case statement check
parent
19223f7a
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
check_source/check_style_c.py
+18
-1
18 additions, 1 deletion
check_source/check_style_c.py
readme.rst
+0
-1
0 additions, 1 deletion
readme.rst
tests/check_source/check_style_c_test.py
+18
-0
18 additions, 0 deletions
tests/check_source/check_style_c_test.py
with
36 additions
and
2 deletions
check_source/check_style_c.py
+
18
−
1
View file @
30d4611e
...
@@ -180,6 +180,19 @@ def tk_advance_line_to_token(index, direction, text, type_):
...
@@ -180,6 +180,19 @@ def tk_advance_line_to_token(index, direction, text, type_):
return
None
return
None
def
tk_advance_line_to_token_with_fn
(
index
,
direction
,
text
,
fn
):
"""
Advance to a token (on the same line).
"""
assert
(
isinstance
(
text
,
str
))
line
=
tokens
[
index
].
line
index
+=
direction
while
tokens
[
index
].
line
==
line
:
if
(
tokens
[
index
].
text
==
text
)
and
fn
(
tokens
[
index
]):
return
index
index
+=
direction
return
None
def
tk_advance_flag
(
index
,
direction
,
flag
):
def
tk_advance_flag
(
index
,
direction
,
flag
):
state
=
(
tokens
[
index
].
flag
&
flag
)
state
=
(
tokens
[
index
].
flag
&
flag
)
while
((
tokens
[
index
+
direction
].
flag
)
&
flag
==
state
)
and
index
>
0
:
while
((
tokens
[
index
+
direction
].
flag
)
&
flag
==
state
)
and
index
>
0
:
...
@@ -693,7 +706,11 @@ def blender_check_kw_switch(fn, index_kw_start, index_kw, index_kw_end):
...
@@ -693,7 +706,11 @@ def blender_check_kw_switch(fn, index_kw_start, index_kw, index_kw_end):
# case ABC :
# case ABC :
# should be...
# should be...
# case ABC:
# case ABC:
i_case
=
tk_advance_line_to_token
(
i
,
1
,
"
:
"
,
Token
.
Operator
)
# Note, this might be either 'Punctuation' or 'Operator', we need to check both.
i_case
=
tk_advance_line_to_token_with_fn
(
i
,
1
,
"
:
"
,
lambda
t
:
t
.
type
in
{
Token
.
Punctuation
,
Token
.
Operator
})
# can be None when the identifier isn't an 'int'
# can be None when the identifier isn't an 'int'
if
i_case
is
not
None
:
if
i_case
is
not
None
:
if
tokens
[
i_case
-
1
].
text
.
isspace
():
if
tokens
[
i_case
-
1
].
text
.
isspace
():
...
...
This diff is collapsed.
Click to expand it.
readme.rst
+
0
−
1
View file @
30d4611e
...
@@ -45,4 +45,3 @@ Utils
...
@@ -45,4 +45,3 @@ Utils
Programs (scripts) to help with development
Programs (scripts) to help with development
(currently for converting formats, creating mouse cursor, updating themes).
(currently for converting formats, creating mouse cursor, updating themes).
This diff is collapsed.
Click to expand it.
tests/check_source/check_style_c_test.py
+
18
−
0
View file @
30d4611e
...
@@ -319,6 +319,24 @@ void func(void)
...
@@ -319,6 +319,24 @@ void func(void)
\t\t
case 0:
\t\t
case 0:
\t\t\t
call();
\t\t\t
call();
\t\t\t
break;
\t\t\t
break;
\t
}
"""
+
FUNC_END
err_found
=
test_code
(
code
)
self
.
assertWarning
(
err_found
)
def
test_switch_with_turnary
(
self
):
# --------------------------------------------------------------------
code
=
FUNC_BEGIN
+
"""
\t
switch (value) {
\t\t
case ABC : a = b ? c : d; break;
\t\t\t
break;
\t
}
"""
+
FUNC_END
err_found
=
test_code
(
code
)
self
.
assertWarning
(
err_found
,
"
E132
"
)
code
=
FUNC_BEGIN
+
"""
\t
switch (value) {
\t\t
case ABC: a = b ? c : d; break;
\t\t\t
break;
\t
}
"""
+
FUNC_END
\t
}
"""
+
FUNC_END
err_found
=
test_code
(
code
)
err_found
=
test_code
(
code
)
self
.
assertWarning
(
err_found
)
self
.
assertWarning
(
err_found
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment