@@ -111,20 +111,46 @@ private predicate locationIncludesPosition(Location loc, int line, int col) {
111
111
col <= loc .getEndColumn ( )
112
112
}
113
113
114
+ /** A file containing an ERB directive. */
115
+ private class ErbDirectiveFile extends File {
116
+ pragma [ nomagic]
117
+ ErbDirectiveFile ( ) { this = any ( ErbDirective dir ) .getLocation ( ) .getFile ( ) }
118
+
119
+ /** Gets a statement in this file. */
120
+ pragma [ nomagic]
121
+ Stmt getAStmt ( int startLine , int startColumn ) {
122
+ exists ( Location loc |
123
+ result .getLocation ( ) = loc and
124
+ loc .getFile ( ) = this and
125
+ loc .getStartLine ( ) = startLine and
126
+ loc .getStartColumn ( ) = startColumn
127
+ )
128
+ }
129
+ }
130
+
114
131
/**
115
132
* A directive in an ERB template.
116
133
*/
117
134
class ErbDirective extends TDirectiveNode , ErbAstNode {
118
- private predicate containsStartOf ( Location loc ) {
119
- loc .getFile ( ) = this .getLocation ( ) .getFile ( ) and
120
- locationIncludesPosition ( this .getLocation ( ) , loc .getStartLine ( ) , loc .getStartColumn ( ) )
135
+ /** Holds if this directive spans line `line` in the file `file`. */
136
+ pragma [ nomagic]
137
+ private predicate spans ( ErbDirectiveFile file , int line ) {
138
+ exists ( Location loc |
139
+ loc = this .getLocation ( ) and
140
+ file = loc .getFile ( ) and
141
+ line in [ loc .getStartLine ( ) .. loc .getEndLine ( ) ]
142
+ )
121
143
}
122
144
123
145
private predicate containsStmtStart ( Stmt s ) {
124
- this .containsStartOf ( s .getLocation ( ) ) and
125
146
// `Toplevel` statements are not contained within individual directives,
126
147
// though their start location may appear within a directive location
127
- not s instanceof Toplevel
148
+ not s instanceof Toplevel and
149
+ exists ( ErbDirectiveFile file , int startLine , int startColumn |
150
+ this .spans ( file , startLine ) and
151
+ s = file .getAStmt ( startLine , startColumn ) and
152
+ locationIncludesPosition ( this .getLocation ( ) , startLine , startColumn )
153
+ )
128
154
}
129
155
130
156
/**
0 commit comments