Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6ef8e51

Browse files
committed
Fix code review findings in 'line' directives
1 parent f7832ad commit 6ef8e51

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class LineDirective extends PreprocessorDirective, @directive_line {
163163
/** Gets the succeeding `#line` directive in the file, if any. */
164164
LineDirective getSuccLineDirective() {
165165
result =
166-
rank[1](LineDirective next |
166+
min(LineDirective next |
167167
next.getFile() = this.getFile() and
168168
next.getLocation().getStartLine() > this.getLocation().getStartLine()
169169
|
@@ -216,10 +216,10 @@ class NumericLineDirective extends LineDirective {
216216
int getLine() { directive_line_values(this, result, _) }
217217

218218
/** Holds if this directive specifies a file name. */
219-
predicate hasFileName() { this.getFileName() != "" }
219+
predicate hasFileName() { exists(this.getFileName()) }
220220

221-
/** Gets the file name of this directive. */
222-
string getFileName() { directive_line_values(this, _, result) }
221+
/** Gets the file name of this directive, if any. */
222+
string getFileName() { directive_line_values(this, _, result) and result != "" }
223223

224224
override string getAPrimaryQlClass() { result = "NumericLineDirective" }
225225
}

csharp/ql/test/library-tests/comments/LineDirectives.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ hidden
44
| trivia.cs:25:1:25:38 | #line hidden |
55
lines
66
| trivia.cs:18:1:18:19 | #line ... | 200 | Special |
7-
| trivia.cs:27:1:27:9 | #line ... | 300 | |
7+
| trivia.cs:27:1:27:9 | #line ... | 300 | no file |
88
succ
99
| trivia.cs:18:1:18:19 | #line ... | trivia.cs:21:1:21:13 | #line default |
1010
| trivia.cs:21:1:21:13 | #line default | trivia.cs:25:1:25:38 | #line hidden |

csharp/ql/test/library-tests/comments/LineDirectives.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ query predicate default(DefaultLineDirective line) { any() }
55
query predicate hidden(HiddenLineDirective line) { any() }
66

77
query predicate lines(NumericLineDirective line, int l, string file) {
8-
line.getLine() = l and line.getFileName() = file
8+
line.getLine() = l and
9+
if line.hasFileName() then line.getFileName() = file else file = "no file"
910
}
1011

1112
query predicate succ(LineDirective d, LineDirective succ) { d.getSuccLineDirective() = succ }

0 commit comments

Comments
 (0)