CPP: Create HeaderFile.noTopLevelCode from existing logic.

This commit is contained in:
Geoffrey White
2019-04-11 11:16:40 +01:00
parent 9e6b178d48
commit f381768a1e
2 changed files with 15 additions and 5 deletions

View File

@@ -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.

View File

@@ -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)
}
}
/**