Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cscan
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
COBOLworx
cscan
Commits
7efecf35
Commit
7efecf35
authored
4 years ago
by
James K. Lowden
Browse files
Options
Downloads
Patches
Plain Diff
support -W additional warning-igore files
parent
b9944858
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cscan
+38
-7
38 additions, 7 deletions
cscan
with
38 additions
and
7 deletions
cscan
+
38
−
7
View file @
7efecf35
...
@@ -218,27 +218,54 @@ def cast_pair(node):
...
@@ -218,27 +218,54 @@ def cast_pair(node):
class_name
(
node
.
expr
)
+
'
:
'
,
class_name
(
node
.
expr
)
+
'
:
'
,
string_of
(
node
))
string_of
(
node
))
def
read_ignores
(
filename
):
ignoring
=
[]
with
open
(
filename
)
as
f
:
for
input
in
f
:
elements
=
input
.
split
(
'
:
'
)
if
len
(
elements
)
>
2
:
output
=
'
:
'
.
join
(
elements
[:
2
]
)
ignoring
.
append
(
output
)
#rint(output)
return
ignoring
# Visitor for Cast nodes, to report where a cast is used.
# Visitor for Cast nodes, to report where a cast is used.
class
CastVisitor
(
c_ast
.
NodeVisitor
):
class
CastVisitor
(
c_ast
.
NodeVisitor
):
ncast
=
0
ignoring
=
()
def
__init__
(
self
,
ignoring
):
self
.
ignoring
=
ignoring
def
visit_Cast
(
self
,
node
):
def
visit_Cast
(
self
,
node
):
print
(
cast_pair
(
node
)
)
key
=
'
%s:%d
'
%
(
node
.
coord
.
file
,
node
.
coord
.
line
)
if
not
key
in
self
.
ignoring
:
def
show_casts
(
cpp
,
filename
):
print
(
cast_pair
(
node
)
)
self
.
ncast
+=
1
else
:
pass
# print('%s: (ignored)' % key)
def
show_casts
(
cpp
,
filename
,
ignoring
):
cpp_args
=
re
.
split
(
r
'
\s{2,}
'
,
environ
[
'
CSCAN_FLAGS
'
])
cpp_args
=
re
.
split
(
r
'
\s{2,}
'
,
environ
[
'
CSCAN_FLAGS
'
])
assert
(
len
(
cpp_args
)
>
1
)
assert
(
len
(
cpp_args
)
>
1
)
ast
=
parse_file
(
filename
,
use_cpp
=
True
,
ast
=
parse_file
(
filename
,
use_cpp
=
True
,
cpp_path
=
cpp
,
cpp_path
=
cpp
,
cpp_args
=
cpp_args
)
cpp_args
=
cpp_args
)
v
=
CastVisitor
()
try
:
ignoring
+=
read_ignores
(
'
.cscan-ignore
'
)
print
(
'
ignoring %d approved casts
'
%
len
(
ignoring
)
)
except
Exception
as
oops
:
print
(
oops
);
v
=
CastVisitor
(
ignoring
)
v
.
visit
(
ast
)
v
.
visit
(
ast
)
return
v
.
ncast
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
cpp
=
'
cpp
'
cpp
=
'
cpp
'
ignoring
=
[]
try
:
try
:
opts
,
args
=
getopt
(
sys
.
argv
[
1
:],
"
E:v
"
)
opts
,
args
=
getopt
(
sys
.
argv
[
1
:],
"
E:
W:
v
"
)
except
getopt
.
GetoptError
as
err
:
except
getopt
.
GetoptError
as
err
:
print
(
err
)
print
(
err
)
exit
(
1
)
exit
(
1
)
...
@@ -249,6 +276,8 @@ if __name__ == "__main__":
...
@@ -249,6 +276,8 @@ if __name__ == "__main__":
cpp
=
a
cpp
=
a
elif
o
==
'
-v
'
:
elif
o
==
'
-v
'
:
verbose
=
True
verbose
=
True
elif
o
==
'
-W
'
:
ignoring
+=
read_ignores
(
a
)
else
:
else
:
assert
False
,
"
unhandled option
"
assert
False
,
"
unhandled option
"
...
@@ -257,7 +286,9 @@ if __name__ == "__main__":
...
@@ -257,7 +286,9 @@ if __name__ == "__main__":
for
filename
in
sys
.
argv
[
narg
:]:
for
filename
in
sys
.
argv
[
narg
:]:
print
(
'
scanning
"
%s
"'
%
filename
)
print
(
'
scanning
"
%s
"'
%
filename
)
try
:
try
:
show_casts
(
cpp
,
filename
)
exit_status
=
show_casts
(
cpp
,
filename
,
ignoring
)
if
exit_status
>
0
:
break
except
CalledProcessError
as
erc
:
except
CalledProcessError
as
erc
:
print
(
'
%s in %s
'
%
(
erc
,
getcwd
()),
file
=
sys
.
stderr
)
print
(
'
%s in %s
'
%
(
erc
,
getcwd
()),
file
=
sys
.
stderr
)
exit
(
1
)
exit
(
1
)
...
...
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