Skip to content

Commit 8de7df9

Browse files
committed
Swift: add auto-generated docs for getters
1 parent 4d87abe commit 8de7df9

File tree

131 files changed

+1699
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+1699
-1
lines changed

swift/codegen/templates/ql_class.mustache

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,38 @@ module Generated {
1414
*/
1515
{{/has_doc}}
1616
class {{name}} extends Synth::T{{name}}{{#bases}}, {{.}}{{/bases}} {
17-
{{#root}}
17+
{{#root}}
18+
/**
19+
* Gets the string representation of this element.
20+
*/
1821
string toString() { none() } // overridden by subclasses
1922

23+
/**
24+
* Gets the name of a primary CodeQL class to which this element belongs.
25+
*
26+
* This is the most precise syntactic category to which they belong; for
27+
* example, `CallExpr` is a primary class, but `ApplyExpr` is not.
28+
*
29+
* There might be some corner cases when this returns multiple classes, or none.
30+
*/
2031
string getAPrimaryQlClass() { none() } // overridden by subclasses
2132

33+
/**
34+
* Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs.
35+
*/
2236
final string getPrimaryQlClasses() { result = concat(this.getAPrimaryQlClass(), ",") }
2337

38+
/**
39+
* Gets the most immediate element that should substitute this element in the explicit AST, if any.
40+
* Classes can override this to indicate this node should be in the "hidden" AST, mostly reserved
41+
* for conversions and syntactic sugar nodes like parentheses.
42+
*/
2443
{{name}} getResolveStep() { none() } // overridden by subclasses
2544

45+
/**
46+
* Gets the element that should substitute this element in the explicit AST, applying `getResolveStep`
47+
* transitively.
48+
*/
2649
final {{name}} resolve() {
2750
not exists(getResolveStep()) and result = this
2851
or
@@ -35,6 +58,10 @@ module Generated {
3558
{{#properties}}
3659

3760
{{#type_is_class}}
61+
/**
62+
* Gets the {{#is_repeated}}`index`th {{/is_repeated}}{{doc_name}}{{#is_optional}}, if it exists{{/is_optional}}.
63+
* This is taken from the "hidden" AST and should only be used to be overridden by classes.
64+
*/
3865
{{type}} getImmediate{{singular}}({{#is_repeated}}int index{{/is_repeated}}) {
3966
{{^ipa}}
4067
result = Synth::convert{{type}}FromRaw(Synth::convert{{name}}ToRaw(this){{^root}}.(Raw::{{name}}){{/root}}.{{getter}}({{#is_repeated}}index{{/is_repeated}}))
@@ -44,12 +71,41 @@ module Generated {
4471
{{/ipa}}
4572
}
4673

74+
/**
75+
* Gets the {{#is_repeated}}`index`th {{/is_repeated}}{{doc_name}}{{#is_optional}}, if it exists{{/is_optional}}.
76+
{{#has_doc}}
77+
*
78+
{{#doc}}
79+
* {{.}}
80+
{{/doc}}
81+
{{/has_doc}}
82+
*/
4783
final {{type}} {{getter}}({{#is_repeated}}int index{{/is_repeated}}) {
4884
result = getImmediate{{singular}}({{#is_repeated}}index{{/is_repeated}}).resolve()
4985
}
5086

5187
{{/type_is_class}}
5288
{{^type_is_class}}
89+
{{^is_predicate}}
90+
/**
91+
* Gets the {{#is_repeated}}`index`th {{/is_repeated}}{{doc_name}}{{#is_optional}}, if it exists{{/is_optional}}.
92+
{{#has_doc}}
93+
*
94+
{{#doc}}
95+
* {{.}}
96+
{{/doc}}
97+
{{/has_doc}}
98+
*/
99+
{{/is_predicate}}
100+
{{#is_predicate}}
101+
{{#has_doc}}
102+
/**
103+
{{#doc}}
104+
* {{.}}
105+
{{/doc}}
106+
*/
107+
{{/has_doc}}
108+
{{/is_predicate}}
53109
{{type}} {{getter}}({{#is_repeated}}int index{{/is_repeated}}) {
54110
{{^ipa}}
55111
{{^is_predicate}}result = {{/is_predicate}}Synth::convert{{name}}ToRaw(this){{^root}}.(Raw::{{name}}){{/root}}.{{getter}}({{#is_repeated}}index{{/is_repeated}})
@@ -61,17 +117,26 @@ module Generated {
61117

62118
{{/type_is_class}}
63119
{{#is_optional}}
120+
/**
121+
* Holds if `{{getter}}({{#is_repeated}}index{{/is_repeated}})` exists.
122+
*/
64123
final predicate has{{singular}}({{#is_repeated}}int index{{/is_repeated}}) {
65124
exists({{getter}}({{#is_repeated}}index{{/is_repeated}}))
66125
}
67126
{{/is_optional}}
68127
{{#is_repeated}}
69128

129+
/**
130+
* Gets any of the {{doc_name_plural}}.
131+
*/
70132
final {{type}} {{indefinite_getter}}() {
71133
result = {{getter}}(_)
72134
}
73135
{{^is_optional}}
74136

137+
/**
138+
* Gets the number of {{doc_name_plural}}.
139+
*/
75140
final int getNumberOf{{plural}}() {
76141
result = count({{indefinite_getter}}())
77142
}

swift/ql/lib/codeql/swift/generated/Callable.qll

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,70 @@ import codeql.swift.elements.decl.ParamDecl
77

88
module Generated {
99
class Callable extends Synth::TCallable, Element {
10+
/**
11+
* Gets the self param, if it exists.
12+
* This is taken from the "hidden" AST and should only be used to be overridden by classes.
13+
*/
1014
ParamDecl getImmediateSelfParam() {
1115
result =
1216
Synth::convertParamDeclFromRaw(Synth::convertCallableToRaw(this)
1317
.(Raw::Callable)
1418
.getSelfParam())
1519
}
1620

21+
/**
22+
* Gets the self param, if it exists.
23+
*/
1724
final ParamDecl getSelfParam() { result = getImmediateSelfParam().resolve() }
1825

26+
/**
27+
* Holds if `getSelfParam()` exists.
28+
*/
1929
final predicate hasSelfParam() { exists(getSelfParam()) }
2030

31+
/**
32+
* Gets the `index`th param.
33+
* This is taken from the "hidden" AST and should only be used to be overridden by classes.
34+
*/
2135
ParamDecl getImmediateParam(int index) {
2236
result =
2337
Synth::convertParamDeclFromRaw(Synth::convertCallableToRaw(this)
2438
.(Raw::Callable)
2539
.getParam(index))
2640
}
2741

42+
/**
43+
* Gets the `index`th param.
44+
*/
2845
final ParamDecl getParam(int index) { result = getImmediateParam(index).resolve() }
2946

47+
/**
48+
* Gets any of the params.
49+
*/
3050
final ParamDecl getAParam() { result = getParam(_) }
3151

52+
/**
53+
* Gets the number of params.
54+
*/
3255
final int getNumberOfParams() { result = count(getAParam()) }
3356

57+
/**
58+
* Gets the body, if it exists.
59+
* This is taken from the "hidden" AST and should only be used to be overridden by classes.
60+
*/
3461
BraceStmt getImmediateBody() {
3562
result =
3663
Synth::convertBraceStmtFromRaw(Synth::convertCallableToRaw(this).(Raw::Callable).getBody())
3764
}
3865

66+
/**
67+
* Gets the body, if it exists.
68+
*/
3969
final BraceStmt getBody() { result = getImmediateBody().resolve() }
4070

71+
/**
72+
* Holds if `getBody()` exists.
73+
*/
4174
final predicate hasBody() { exists(getBody()) }
4275
}
4376
}

swift/ql/lib/codeql/swift/generated/Comment.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ module Generated {
77
class Comment extends Synth::TComment, Locatable {
88
override string getAPrimaryQlClass() { result = "Comment" }
99

10+
/**
11+
* Gets the text.
12+
*/
1013
string getText() { result = Synth::convertCommentToRaw(this).(Raw::Comment).getText() }
1114
}
1215
}

swift/ql/lib/codeql/swift/generated/Element.qll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,37 @@ private import codeql.swift.generated.Raw
44

55
module Generated {
66
class Element extends Synth::TElement {
7+
/**
8+
* Gets the string representation of this element.
9+
*/
710
string toString() { none() } // overridden by subclasses
811

12+
/**
13+
* Gets the name of a primary CodeQL class to which this element belongs.
14+
*
15+
* This is the most precise syntactic category to which they belong; for
16+
* example, `CallExpr` is a primary class, but `ApplyExpr` is not.
17+
*
18+
* There might be some corner cases when this returns multiple classes, or none.
19+
*/
920
string getAPrimaryQlClass() { none() } // overridden by subclasses
1021

22+
/**
23+
* Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs.
24+
*/
1125
final string getPrimaryQlClasses() { result = concat(this.getAPrimaryQlClass(), ",") }
1226

27+
/**
28+
* Gets the most immediate element that should substitute this element in the explicit AST, if any.
29+
* Classes can override this to indicate this node should be in the "hidden" AST, mostly reserved
30+
* for conversions and syntactic sugar nodes like parentheses.
31+
*/
1332
Element getResolveStep() { none() } // overridden by subclasses
1433

34+
/**
35+
* Gets the element that should substitute this element in the explicit AST, applying `getResolveStep`
36+
* transitively.
37+
*/
1538
final Element resolve() {
1639
not exists(getResolveStep()) and result = this
1740
or

swift/ql/lib/codeql/swift/generated/File.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import codeql.swift.elements.Element
55

66
module Generated {
77
class File extends Synth::TFile, Element {
8+
/**
9+
* Gets the name.
10+
*/
811
string getName() { result = Synth::convertFileToRaw(this).(Raw::File).getName() }
912
}
1013
}

swift/ql/lib/codeql/swift/generated/Locatable.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,25 @@ import codeql.swift.elements.Location
66

77
module Generated {
88
class Locatable extends Synth::TLocatable, Element {
9+
/**
10+
* Gets the location, if it exists.
11+
* This is taken from the "hidden" AST and should only be used to be overridden by classes.
12+
*/
913
Location getImmediateLocation() {
1014
result =
1115
Synth::convertLocationFromRaw(Synth::convertLocatableToRaw(this)
1216
.(Raw::Locatable)
1317
.getLocation())
1418
}
1519

20+
/**
21+
* Gets the location, if it exists.
22+
*/
1623
final Location getLocation() { result = getImmediateLocation().resolve() }
1724

25+
/**
26+
* Holds if `getLocation()` exists.
27+
*/
1828
final predicate hasLocation() { exists(getLocation()) }
1929
}
2030
}

swift/ql/lib/codeql/swift/generated/Location.qll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,40 @@ import codeql.swift.elements.File
66

77
module Generated {
88
class Location extends Synth::TLocation, Element {
9+
/**
10+
* Gets the file.
11+
* This is taken from the "hidden" AST and should only be used to be overridden by classes.
12+
*/
913
File getImmediateFile() {
1014
result =
1115
Synth::convertFileFromRaw(Synth::convertLocationToRaw(this).(Raw::Location).getFile())
1216
}
1317

18+
/**
19+
* Gets the file.
20+
*/
1421
final File getFile() { result = getImmediateFile().resolve() }
1522

23+
/**
24+
* Gets the start line.
25+
*/
1626
int getStartLine() { result = Synth::convertLocationToRaw(this).(Raw::Location).getStartLine() }
1727

28+
/**
29+
* Gets the start column.
30+
*/
1831
int getStartColumn() {
1932
result = Synth::convertLocationToRaw(this).(Raw::Location).getStartColumn()
2033
}
2134

35+
/**
36+
* Gets the end line.
37+
*/
2238
int getEndLine() { result = Synth::convertLocationToRaw(this).(Raw::Location).getEndLine() }
2339

40+
/**
41+
* Gets the end column.
42+
*/
2443
int getEndColumn() { result = Synth::convertLocationToRaw(this).(Raw::Location).getEndColumn() }
2544
}
2645
}

swift/ql/lib/codeql/swift/generated/decl/AbstractFunctionDecl.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import codeql.swift.elements.decl.ValueDecl
88
module Generated {
99
class AbstractFunctionDecl extends Synth::TAbstractFunctionDecl, GenericContext, ValueDecl,
1010
Callable {
11+
/**
12+
* Gets the name.
13+
*/
1114
string getName() {
1215
result = Synth::convertAbstractFunctionDeclToRaw(this).(Raw::AbstractFunctionDecl).getName()
1316
}

swift/ql/lib/codeql/swift/generated/decl/AbstractStorageDecl.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,32 @@ import codeql.swift.elements.decl.ValueDecl
66

77
module Generated {
88
class AbstractStorageDecl extends Synth::TAbstractStorageDecl, ValueDecl {
9+
/**
10+
* Gets the `index`th accessor decl.
11+
* This is taken from the "hidden" AST and should only be used to be overridden by classes.
12+
*/
913
AccessorDecl getImmediateAccessorDecl(int index) {
1014
result =
1115
Synth::convertAccessorDeclFromRaw(Synth::convertAbstractStorageDeclToRaw(this)
1216
.(Raw::AbstractStorageDecl)
1317
.getAccessorDecl(index))
1418
}
1519

20+
/**
21+
* Gets the `index`th accessor decl.
22+
*/
1623
final AccessorDecl getAccessorDecl(int index) {
1724
result = getImmediateAccessorDecl(index).resolve()
1825
}
1926

27+
/**
28+
* Gets any of the accessor decls.
29+
*/
2030
final AccessorDecl getAnAccessorDecl() { result = getAccessorDecl(_) }
2131

32+
/**
33+
* Gets the number of accessor decls.
34+
*/
2235
final int getNumberOfAccessorDecls() { result = count(getAnAccessorDecl()) }
2336
}
2437
}

swift/ql/lib/codeql/swift/generated/decl/ConcreteVarDecl.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ module Generated {
77
class ConcreteVarDecl extends Synth::TConcreteVarDecl, VarDecl {
88
override string getAPrimaryQlClass() { result = "ConcreteVarDecl" }
99

10+
/**
11+
* Gets the introducer int.
12+
*/
1013
int getIntroducerInt() {
1114
result = Synth::convertConcreteVarDeclToRaw(this).(Raw::ConcreteVarDecl).getIntroducerInt()
1215
}

0 commit comments

Comments
 (0)