44
55private import AstNodes
66private import Expr
7+ private import Idents
8+ private import Variables
79private import internal.AstNodes
810private import internal.TreeSitter
911private import internal.Literals
@@ -14,6 +16,7 @@ private import internal.NullableReturnType
1416private import internal.Number
1517private import internal.String
1618private import internal.StringContent
19+ private import internal.SubscriptExpression
1720
1821/**
1922 * A literal in the AST.
@@ -29,6 +32,35 @@ class Array extends Literals instanceof ArrayImpl {
2932 Expr getElement ( int index ) { result = ArrayImpl .super .getElement ( index ) }
3033}
3134
35+ /**
36+ * A SubscriptExpression expression in the AST.
37+ */
38+ class SubscriptExpression extends Expr instanceof SubscriptExpressionImpl {
39+ /**
40+ * Gets the index of the subscript expression.
41+ */
42+ Expr getIndex ( ) { result = SubscriptExpressionImpl .super .getIndex ( ) }
43+
44+ /**
45+ * Gets the object of the subscript expression.
46+ */
47+ Idents getIdentifier ( ) { result = SubscriptExpressionImpl .super .getObject ( ) }
48+
49+ /**
50+ * Gets the array that this subscript expression is indexing into.
51+ * This is equivalent to the variable declaration that contains the
52+ * subscript expression.
53+ */
54+ Array getArray ( ) {
55+ exists ( VariableDeclaration variable |
56+ variable .getEnclosingCfgScope ( ) = this .getEnclosingCfgScope ( ) and
57+ variable .getIdentifier ( ) .getName ( ) = this .getIdentifier ( ) .getName ( )
58+ |
59+ result = variable .getInitializer ( )
60+ )
61+ }
62+ }
63+
3264/**
3365 * A Boolean unknown AST node.
3466 */
@@ -76,24 +108,23 @@ class StringLiteral extends Literals instanceof StringImpl {
76108 * Gets the value of the string literal.
77109 */
78110 string getValue ( ) {
79- result = concat ( int index , string output |
80- exists ( StringContentLiteral content |
81- content = StringImpl .super .getChild ( index ) and
82- output = content .getValue ( )
111+ result =
112+ concat ( int index , string output |
113+ exists ( StringContentLiteral content |
114+ content = StringImpl .super .getChild ( index ) and
115+ output = content .getValue ( )
116+ )
117+ or
118+ exists ( Interpolation interpolation |
119+ interpolation = StringImpl .super .getChild ( index ) and
120+ output = interpolation .getValue ( )
121+ )
122+ |
123+ output order by index
83124 )
84- or
85- exists ( Interpolation interpolation |
86- interpolation = StringImpl .super .getChild ( index ) and
87- output = interpolation .getValue ( )
88- )
89- |
90- output order by index
91- )
92125 }
93126
94- Interpolation getInterpolation ( int index ) {
95- result = StringImpl .super .getChild ( index )
96- }
127+ Interpolation getInterpolation ( int index ) { result = StringImpl .super .getChild ( index ) }
97128}
98129
99130/**
0 commit comments