@@ -23,13 +23,27 @@ abstract class Use extends Locatable {
2323 abstract string getUseType ( ) ;
2424}
2525
26- private newtype TDef =
27- TVariable ( Variable v ) or
28- TFormatArgsArgName ( Name name ) { name = any ( FormatArgsArg a ) .getName ( ) } or
29- TFormatArgsArgIndex ( Expr e ) { e = any ( FormatArgsArg a ) .getExpr ( ) }
26+ cached
27+ private module Cached {
28+ cached
29+ newtype TDef =
30+ TVariable ( Variable v ) or
31+ TFormatArgsArgName ( Name name ) { name = any ( FormatArgsArg a ) .getName ( ) } or
32+ TFormatArgsArgIndex ( Expr e ) { e = any ( FormatArgsArg a ) .getExpr ( ) }
33+
34+ /**
35+ * Gets an element, of kind `kind`, that element `use` uses, if any.
36+ */
37+ cached
38+ Definition definitionOf ( Use use , string kind ) {
39+ result = use .getDefinition ( ) and kind = use .getUseType ( )
40+ }
41+ }
42+
43+ predicate definitionOf = Cached:: definitionOf / 2 ;
3044
3145/** A definition */
32- class Definition extends TDef {
46+ class Definition extends Cached :: TDef {
3347 /** Gets the location of this variable. */
3448 Location getLocation ( ) {
3549 result = this .asVariable ( ) .getLocation ( ) or
@@ -38,13 +52,13 @@ class Definition extends TDef {
3852 }
3953
4054 /** Gets this definition as a `Variable` */
41- Variable asVariable ( ) { this = TVariable ( result ) }
55+ Variable asVariable ( ) { this = Cached :: TVariable ( result ) }
4256
4357 /** Gets this definition as a `Name` */
44- Name asName ( ) { this = TFormatArgsArgName ( result ) }
58+ Name asName ( ) { this = Cached :: TFormatArgsArgName ( result ) }
4559
4660 /** Gets this definition as an `Expr` */
47- Expr asExpr ( ) { this = TFormatArgsArgIndex ( result ) }
61+ Expr asExpr ( ) { this = Cached :: TFormatArgsArgIndex ( result ) }
4862
4963 /** Gets the string representation of this element. */
5064 string toString ( ) {
@@ -107,11 +121,3 @@ private class PositionalFormatArgumentUse extends Use instanceof PositionalForma
107121
108122 override string getUseType ( ) { result = "format argument" }
109123}
110-
111- /**
112- * Gets an element, of kind `kind`, that element `use` uses, if any.
113- */
114- cached
115- Definition definitionOf ( Use use , string kind ) {
116- result = use .getDefinition ( ) and kind = use .getUseType ( )
117- }
0 commit comments