@@ -173,7 +173,7 @@ class Method extends MethodBase, TMethod {
173
173
result = this .getExplicitVisibilityModifier ( )
174
174
or
175
175
not exists ( this .getExplicitVisibilityModifier ( ) ) and
176
- exists ( Namespace n , int methodPos | isDeclaredIn ( this , n , methodPos ) |
176
+ exists ( ModuleBase n , int methodPos | isDeclaredIn ( this , n , methodPos ) |
177
177
// The relevant visibility modifier is the closest call that occurs before
178
178
// the definition of `m` (typically this means higher up the file).
179
179
result =
@@ -204,18 +204,35 @@ class Method extends MethodBase, TMethod {
204
204
VisibilityModifier getExplicitVisibilityModifier ( ) {
205
205
result .getMethodArgument ( ) = this
206
206
or
207
- isDeclaredIn ( result , this .getEnclosingModule ( ) , _) and
208
- result .getMethodArgument ( ) .getConstantValue ( ) .getStringlikeValue ( ) = this .getName ( )
207
+ exists ( ModuleBase n , string name |
208
+ methodIsDeclaredIn ( this , n , name ) and
209
+ modifiesIn ( result , n , name )
210
+ )
209
211
}
210
212
}
211
213
214
+ pragma [ nomagic]
215
+ private predicate modifiesIn ( VisibilityModifier vm , ModuleBase n , string name ) {
216
+ n = vm .getEnclosingModule ( ) and
217
+ name = vm .getMethodArgument ( ) .getConstantValue ( ) .getStringlikeValue ( )
218
+ }
219
+
212
220
/**
213
- * Holds if statement `m ` is declared in namespace `n` at position `pos`.
221
+ * Holds if statement `s ` is declared in namespace `n` at position `pos`.
214
222
*/
215
- pragma [ noinline]
216
- private predicate isDeclaredIn ( Stmt m , Namespace n , int pos ) {
217
- n = m .getEnclosingModule ( ) and
218
- n .getStmt ( pos ) = m
223
+ pragma [ nomagic]
224
+ private predicate isDeclaredIn ( Stmt s , ModuleBase n , int pos ) {
225
+ n = s .getEnclosingModule ( ) and
226
+ n .getStmt ( pos ) = s
227
+ }
228
+
229
+ /**
230
+ * Holds if method `m` with name `name` is declared in namespace `n`.
231
+ */
232
+ pragma [ nomagic]
233
+ private predicate methodIsDeclaredIn ( MethodBase m , ModuleBase n , string name ) {
234
+ isDeclaredIn ( m , n , _) and
235
+ name = m .getName ( )
219
236
}
220
237
221
238
/** A singleton method. */
@@ -273,11 +290,11 @@ class SingletonMethod extends MethodBase, TSingletonMethod {
273
290
override predicate isPrivate ( ) { super .isPrivate ( ) }
274
291
275
292
override VisibilityModifier getVisibilityModifier ( ) {
276
- result .getEnclosingModule ( ) = this . getEnclosingModule ( ) and
277
- (
278
- result . getMethodArgument ( ) = this
279
- or
280
- result . getMethodArgument ( ) . getConstantValue ( ) . getStringlikeValue ( ) = this . getName ( )
293
+ result .getMethodArgument ( ) = this
294
+ or
295
+ exists ( ModuleBase n , string name |
296
+ methodIsDeclaredIn ( this , n , name ) and
297
+ modifiesIn ( result , n , name )
281
298
)
282
299
}
283
300
}
0 commit comments