Python: Detect a wider range of generated files.

This commit is contained in:
Mark Shannon
2018-12-27 14:45:01 +00:00
parent d566141273
commit 6b5ad0d928
4 changed files with 28 additions and 3 deletions

View File

@@ -24,6 +24,8 @@ library class GenericGeneratedFile extends GeneratedFile {
(lax_generated_by(this, _) or lax_generated_from(this, _)) and dont_modify(this)
or
strict_generated_by(this, _) or strict_generated_from(this, _)
or
auto_generated(this)
)
}
@@ -78,8 +80,15 @@ private predicate dont_modify(File f) {
comment_or_docstring(f, _).regexpMatch("(?is).*\\b(Do not|Don't) (edit|modify|make changes)\\b.*")
}
private predicate auto_generated(File f) {
exists(Comment c |
c.getLocation().getFile() = f and
c.getText().regexpMatch("(?is)# *this +(code|file) +is +(auto(matically)?[ -]?generated|created automatically).*")
)
}
/**
/**
* A file generated by a template engine
*/
abstract library class SpecificGeneratedFile extends GeneratedFile {

View File

@@ -1,3 +1,4 @@
| antlr.py | none |
| generic.py | tools/idna-data |
| sphinx.py | Sphinx |
| swig.py | SWIG |

View File

@@ -2,5 +2,9 @@
import python
import semmle.python.filters.GeneratedCode
from GeneratedFile f
select f.toString(), f.getTool()
from GeneratedFile f, string tool
where
tool = f.getTool()
or
not exists(f.getTool()) and tool = "none"
select f.toString(), tool

View File

@@ -0,0 +1,11 @@
# $ANTLR 3.0.1 C.g 2010-02-23 09:58:53
from antlr3 import *
from antlr3.compat import set, frozenset
## @file
# The file defines the parser for C source files.
#
# THIS FILE IS AUTO-GENERATED.
#
##