1010 * statistical
1111 * non-attributable
1212 */
13+
1314import cpp
1415
1516predicate functionUsesVariable ( Function source , Variable v , File target ) {
1617 v .getAnAccess ( ) .getEnclosingFunction ( ) = source and
17- not ( v .( LocalScopeVariable ) .getFunction ( ) = source ) and
18+ not v .( LocalScopeVariable ) .getFunction ( ) = source and
1819 v .getFile ( ) = target
1920}
2021
@@ -25,23 +26,23 @@ predicate functionUsesFunction(Function source, Function f, File target) {
2526
2627predicate dependencyCount ( Function source , File target , int res ) {
2728 res = strictcount ( Declaration d |
28- functionUsesVariable ( source , d , target ) or
29- functionUsesFunction ( source , d , target )
30- )
29+ functionUsesVariable ( source , d , target ) or
30+ functionUsesFunction ( source , d , target )
31+ )
3132}
3233
3334predicate selfDependencyCountOrZero ( Function source , int res ) {
34- exists ( File target
35- | target = source . getFile ( ) and onlyInFile ( source , target )
36- | res = max ( int i | dependencyCount ( source , target , i ) or i = 0 ) )
35+ exists ( File target | target = source . getFile ( ) and onlyInFile ( source , target ) |
36+ res = max ( int i | dependencyCount ( source , target , i ) or i = 0 )
37+ )
3738}
3839
3940predicate dependsHighlyOn ( Function source , File target , int res ) {
4041 dependencyCount ( source , target , res ) and
4142 target .fromSource ( ) and
4243 exists ( int selfCount |
4344 selfDependencyCountOrZero ( source , selfCount ) and
44- res > 2 * selfCount and
45+ res > 2 * selfCount and
4546 res > 4
4647 )
4748}
@@ -52,14 +53,18 @@ predicate onlyInFile(Function f, File file) {
5253}
5354
5455from Function f , File other , int selfCount , int depCount , string selfDeps
55- where dependsHighlyOn ( f , other , depCount ) and
56- selfDependencyCountOrZero ( f , selfCount ) and
57- not exists ( File yetAnother | dependsHighlyOn ( f , yetAnother , _) and yetAnother != other ) and
58- not other instanceof HeaderFile and
59- not f instanceof MemberFunction
60- and if selfCount = 0 then selfDeps = "0 dependencies"
61- else if selfCount = 1 then selfDeps = "only 1 dependency"
62- else selfDeps = "only " + selfCount .toString ( ) + " dependencies"
63- select f , "Function " + f .getName ( ) + " could be moved to file $@" +
64- " since it has " + depCount .toString ( ) + " dependencies to that file, but " +
65- selfDeps + " to its own file." , other , other .getBaseName ( )
56+ where
57+ dependsHighlyOn ( f , other , depCount ) and
58+ selfDependencyCountOrZero ( f , selfCount ) and
59+ not exists ( File yetAnother | dependsHighlyOn ( f , yetAnother , _) and yetAnother != other ) and
60+ not other instanceof HeaderFile and
61+ not f instanceof MemberFunction and
62+ if selfCount = 0
63+ then selfDeps = "0 dependencies"
64+ else
65+ if selfCount = 1
66+ then selfDeps = "only 1 dependency"
67+ else selfDeps = "only " + selfCount .toString ( ) + " dependencies"
68+ select f ,
69+ "Function " + f .getName ( ) + " could be moved to file $@" + " since it has " + depCount .toString ( ) +
70+ " dependencies to that file, but " + selfDeps + " to its own file." , other , other .getBaseName ( )
0 commit comments