Skip to content

Commit b611e7c

Browse files
authored
Merge pull request #14715 from github/redsun82/gen-file-docs
Swift: add more doc strings to generated things
2 parents b858a28 + 331fbf3 commit b611e7c

File tree

663 files changed

+6062
-666
lines changed

Some content is hidden

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

663 files changed

+6062
-666
lines changed

misc/codegen/generators/qlgen.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ def _get_doc(cls: schema.Class, prop: schema.Property, plural=None):
102102
return f"{prop_name} of this {class_name}"
103103

104104

105-
def get_ql_property(cls: schema.Class, prop: schema.Property, lookup: typing.Dict[str, schema.Class], prev_child: str = "") -> ql.Property:
105+
def get_ql_property(cls: schema.Class, prop: schema.Property, lookup: typing.Dict[str, schema.Class],
106+
prev_child: str = "") -> ql.Property:
106107
args = dict(
107108
type=prop.type if not prop.is_predicate else "predicate",
108109
qltest_skip="qltest_skip" in prop.pragmas,
@@ -310,7 +311,8 @@ def _get_stub(cls: schema.Class, base_import: str, generated_import_prefix: str)
310311
]
311312
else:
312313
accessors = []
313-
return ql.Stub(name=cls.name, base_import=base_import, import_prefix=generated_import_prefix, synth_accessors=accessors)
314+
return ql.Stub(name=cls.name, base_import=base_import, import_prefix=generated_import_prefix,
315+
synth_accessors=accessors, ql_internal="ql_internal" in cls.pragmas)
314316

315317

316318
def generate(opts, renderer):
@@ -426,7 +428,7 @@ def generate(opts, renderer):
426428
for stub_file, data in stubs.items():
427429
renderer.render(data, stub_file)
428430
renderer.render(ql.Synth.Types(root.name, generated_import_prefix,
429-
final_synth_types, non_final_synth_types), out / "Synth.qll")
431+
final_synth_types, non_final_synth_types), out / "Synth.qll")
430432
renderer.render(ql.ImportList(constructor_imports), out / "SynthConstructors.qll")
431433
renderer.render(ql.ImportList(synth_constructor_imports), out / "PureSynthConstructors.qll")
432434
if opts.ql_format:

misc/codegen/lib/ql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class Stub:
166166
base_import: str
167167
import_prefix: str
168168
synth_accessors: List[SynthUnderlyingAccessor] = field(default_factory=list)
169+
ql_internal: bool = False
169170

170171
@property
171172
def has_synth_accessors(self) -> bool:

misc/codegen/templates/ql_class.mustache

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
// generated by {{generator}}
2+
/**
3+
* This module provides the generated definition of `{{name}}`.
4+
* INTERNAL: Do not import directly.
5+
*/
6+
27
private import {{import_prefix}}.Synth
38
private import {{import_prefix}}.Raw
49
{{#imports}}
510
import {{.}}
611
{{/imports}}
712

813
module Generated {
9-
{{#has_doc}}
1014
/**
11-
{{#ql_internal}}
12-
* INTERNAL: Do not use.
13-
{{/ql_internal}}
1415
{{#doc}}
1516
* {{.}}
1617
{{/doc}}
18+
* INTERNAL: Do not reference the `Generated::{{name}}` class directly.
19+
* Use the subclass `{{name}}`, where the following predicates are available.
1720
*/
18-
{{/has_doc}}
1921
class {{name}} extends Synth::T{{name}}{{#bases}}, {{.}}{{/bases}} {
2022
{{#root}}
2123
/**
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
// generated by {{generator}}
2+
/**
3+
* This module exports all modules providing `Element` subclasses.
4+
*/
5+
26
{{#imports}}
37
import {{.}}
48
{{/imports}}

misc/codegen/templates/ql_parent.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// generated by {{generator}}
2+
/**
3+
* This module provides the generated parent/child relationship.
4+
*/
25

36
{{#imports}}
47
import {{.}}

misc/codegen/templates/ql_stub.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
// generated by {{generator}}, remove this comment if you wish to edit this file
2+
/**
3+
* This module provides a hand-modifiable wrapper around the generated class `{{name}}`.
4+
{{#ql_internal}}
5+
* INTERNAL: Do not use.
6+
{{/ql_internal}}
7+
*/
28
private import {{base_import}}
39
{{#has_synth_accessors}}
410
private import {{import_prefix}}.Raw

misc/codegen/templates/ql_synth_constructor_stub.mustache

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
// generated by {{generator}}, remove this comment if you wish to edit this file
2+
/**
3+
* This module defines the hook used internally to tweak the characteristic predicate of
4+
* `{{cls.name}}` synthesized instances.
5+
* INTERNAL: Do not use.
6+
*/
27
private import {{import_prefix}}.Raw
38
{{#cls}}
49
{{#is_db}}
@@ -7,6 +12,10 @@ private import {{import_prefix}}.PureSynthConstructors
712
{{/has_subtracted_synth_types}}
813
{{/is_db}}
914

15+
/**
16+
* The characteristic predicate of `{{name}}` synthesized instances.
17+
* INTERNAL: Do not use.
18+
*/
1019
predicate construct{{name}}({{#params}}{{^first}}, {{/first}}{{type}} {{param}}{{/params}}) {
1120
{{#is_db}}
1221
{{#subtracted_synth_types}}{{^first}} and {{/first}}not construct{{name}}(id){{/subtracted_synth_types}}

misc/codegen/test/test_qlgen.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ def test_one_empty_class(generate_classes):
153153
}
154154

155155

156+
def test_one_empty_internal_class(generate_classes):
157+
assert generate_classes([
158+
schema.Class("A", pragmas=["ql_internal"])
159+
]) == {
160+
"A.qll": (a_ql_stub(name="A", ql_internal=True),
161+
a_ql_class(name="A", final=True, ql_internal=True)),
162+
}
163+
164+
156165
def test_hierarchy(generate_classes):
157166
assert generate_classes([
158167
schema.Class("D", bases=["B", "C"]),

swift/ql/.generated.list

Lines changed: 654 additions & 654 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swift/ql/lib/codeql/swift/elements.qll

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)