Skip to content

Commit 2fdf766

Browse files
committed
C#: Address review comments.
1 parent abe5d0d commit 2fdf766

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

csharp/ql/src/Stubs/MinimalStubsFromSource.ql

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,10 @@ class UsedInSource extends GeneratedDeclaration {
1717
or
1818
this = any(Call c).getTarget()
1919
or
20-
exists(ValueOrRefType t | t.fromSource() | this = t.getABaseType())
21-
or
22-
exists(Variable v | v.fromSource() | this = v.getType())
20+
this = any(TypeMention tm).getType()
2321
or
2422
exists(Virtualizable v | v.fromSource() | this = v.getImplementee() or this = v.getOverridee())
2523
or
26-
this = any(Attribute a).getType()
27-
or
2824
this = any(Attribute a).getType().getAConstructor()
2925
)
3026
and

csharp/ql/src/Stubs/Stubs.qll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private class GeneratedNamespace extends Namespace, GeneratedElement {
239239
final string getStubs() {
240240
result = getPreamble() +
241241
getTypeStubs() +
242-
getSubNamespaces(0) +
242+
getSubNamespaces() +
243243
getPostAmble()
244244
}
245245

@@ -254,10 +254,9 @@ private class GeneratedNamespace extends Namespace, GeneratedElement {
254254
result = count(GeneratedNamespace g | g.getParentNamespace() = this)
255255
}
256256

257-
private string getSubNamespaces(int n) {
258-
result = getChildNamespace(n).getStubs() + getSubNamespaces(n+1)
259-
or
260-
n = getChildNamespaceCount() and result = ""
257+
language[monotonicAggregates]
258+
private string getSubNamespaces() {
259+
result = concat(int i | exists(getChildNamespace(i)) | getChildNamespace(i).getStubs())
261260
}
262261

263262
private string getTypeStubs() {

csharp/ql/src/Stubs/make_stubs.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import sys
1212
import os
13+
import subprocess
1314

1415
print('Script to generate stub.cs files for C# qltest projects')
1516

@@ -42,9 +43,9 @@
4243
print("Test directory does not contain .cs files. Please specify a working qltest directory.")
4344
exit(1)
4445

45-
cmd = 'odasa selfTest'
46-
print(cmd)
47-
if os.system(cmd):
46+
cmd = ['odasa', 'selfTest']
47+
print('Running ' + ' '.join(cmd))
48+
if subprocess.check_call(cmd):
4849
print("odasa selfTest failed. Ensure odasa is on your current path.")
4950
exit(1)
5051

@@ -57,9 +58,9 @@
5758
os.remove(outputFile) # It would interfere with the test.
5859
print("Removed previous", outputFile)
5960

60-
cmd = 'odasa qltest --optimize --leave-temp-files "' + testDir + '"'
61-
print(cmd)
62-
if os.system(cmd) != 0:
61+
cmd = ['odasa', 'qltest', '--optimize', '--leave-temp-files', testDir]
62+
print('Running ' + ' '.join(cmd))
63+
if subprocess.check_call(cmd):
6364
print("qltest failed. Please fix up the test before proceeding.")
6465
exit(1)
6566

@@ -69,9 +70,9 @@
6970
print("Expected database directory " + dbDir + " not found. Please contact Semmle.")
7071
exit(1)
7172

72-
cmd = 'odasa runQuery --query "' + os.path.join(csharpQueries, 'MinimalStubsFromSource.ql') + '" --db "' + dbDir +'" --output-file "' + outputFile + '"'
73-
print(cmd)
74-
if os.system(cmd):
73+
cmd = ['odasa', 'runQuery', '--query', os.path.join(csharpQueries, 'MinimalStubsFromSource.ql'), '--db', dbDir, '--output-file', outputFile]
74+
print('Running ' + ' '.join(cmd))
75+
if subprocess.check_call(cmd):
7576
print('Failed to run the query to generate output file. Please contact Semmle.')
7677
exit(1)
7778

@@ -93,10 +94,9 @@
9394
f.write(contents)
9495
f.close()
9596

96-
cmd = 'odasa qltest --optimize "' + testDir + '"'
97-
print(cmd)
98-
99-
if os.system(cmd):
97+
cmd = ['odasa', 'qltest', '--optimize', testDir]
98+
print('Running ' + ' '.join(cmd))
99+
if subprocess.check_call(cmd):
100100
print('\nTest failed. You may need to fix up', outputFile)
101101
print('It may help to view', outputFile, ' in Visual Studio')
102102
print("Next steps:")

0 commit comments

Comments
 (0)