mirror of
https://github.com/github/codeql.git
synced 2026-04-27 01:35:13 +02:00
CPP: Create HeaderFile.noTopLevelCode from existing logic.
This commit is contained in:
@@ -133,11 +133,7 @@ where not hf instanceof IncludeGuardedHeader
|
||||
// Exclude files which contain no declaration entries or top level
|
||||
// declarations (e.g. just preprocessor directives; or non-top level
|
||||
// code).
|
||||
and (
|
||||
exists(DeclarationEntry de | de.getFile() = hf) or
|
||||
exists(Declaration d | d.getFile() = hf and d.isTopLevel()) or
|
||||
exists(UsingEntry ue | ue.getFile() = hf)
|
||||
)
|
||||
and not hf.noTopLevelCode()
|
||||
// Exclude files which look like they contain 'x-macros'
|
||||
and not hasXMacro(hf)
|
||||
// Exclude files which are always #imported.
|
||||
|
||||
@@ -453,6 +453,20 @@ class HeaderFile extends File {
|
||||
exists(Include i | i.getIncludedFile() = this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if this header file does not contain any declaration entries or top level
|
||||
* declarations. For example it might be:
|
||||
* - a file containing only preprocessor directives and/or comments
|
||||
* - an empty file
|
||||
* - a file that contains non-top level code or data that's included in an
|
||||
* unusual way
|
||||
*/
|
||||
predicate noTopLevelCode()
|
||||
{
|
||||
not exists(DeclarationEntry de | de.getFile() = this) and
|
||||
not exists(Declaration d | d.getFile() = this and d.isTopLevel()) and
|
||||
not exists(UsingEntry ue | ue.getFile() = this)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user