Skip to content

Commit 93255df

Browse files
committed
C#: Add QL library support for the Line span directive.
1 parent 7e26466 commit 93255df

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

csharp/ql/lib/semmle/code/csharp/Preprocessor.qll

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,21 +208,40 @@ class HiddenLineDirective extends LineDirective {
208208
override string getAPrimaryQlClass() { result = "HiddenLineDirective" }
209209
}
210210

211+
abstract private class NumericOrSpanLineDirective extends LineDirective {
212+
/** Gets the referenced file of this directive. */
213+
File getReferencedFile() { directive_line_file(this, result) }
214+
}
215+
211216
/**
212-
* A numeric `#line` directive, such as `#line 200 file`
217+
* A numeric `#line` directive, such as `#line 200 file`.
213218
*/
214-
class NumericLineDirective extends LineDirective {
219+
class NumericLineDirective extends NumericOrSpanLineDirective {
215220
NumericLineDirective() { directive_lines(this, 2) }
216221

217222
/** Gets the line number of this directive. */
218223
int getLine() { directive_line_value(this, result) }
219224

220-
/** Gets the referenced file of this directive. */
221-
File getReferencedFile() { directive_line_file(this, result) }
222-
223225
override string getAPrimaryQlClass() { result = "NumericLineDirective" }
224226
}
225227

228+
/**
229+
* A line span `#line` directive, such as `#line (1, 1) - (3, 10) 5 file`.
230+
*/
231+
class SpanLineDirective extends NumericOrSpanLineDirective {
232+
SpanLineDirective() { directive_lines(this, 3) }
233+
234+
/** Gets the offset of this directive. */
235+
int getOffset() { directive_line_offset(this, result) }
236+
237+
/** Gets the span of this directive. */
238+
predicate span(int startLine, int startColumn, int endLine, int endColumn) {
239+
directive_line_span(this, startLine, startColumn, endLine, endColumn)
240+
}
241+
242+
override string getAPrimaryQlClass() { result = "SpanLineDirective" }
243+
}
244+
226245
/**
227246
* A `#region` directive.
228247
*/

0 commit comments

Comments
 (0)