Skip to content

Commit c5cbf82

Browse files
authored
Merge pull request #17495 from hvitved/codegen/internal
Codegen: Create `internal` folders
2 parents 2837d25 + 8c0d2e9 commit c5cbf82

File tree

1,461 files changed

+2968
-2944
lines changed

Some content is hidden

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

1,461 files changed

+2968
-2944
lines changed

misc/codegen/generators/qlgen.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,11 @@ def _get_path(cls: schema.Class) -> pathlib.Path:
244244

245245

246246
def _get_path_impl(cls: schema.Class) -> pathlib.Path:
247-
return pathlib.Path(cls.group or "", cls.name+"Impl").with_suffix(".qll")
247+
return pathlib.Path(cls.group or "", "internal", cls.name+"Impl").with_suffix(".qll")
248+
249+
250+
def _get_path_public(cls: schema.Class) -> pathlib.Path:
251+
return pathlib.Path(cls.group or "", "internal" if "ql_internal" in cls.pragmas else "", cls.name).with_suffix(".qll")
248252

249253

250254
def _get_all_properties(cls: schema.Class, lookup: typing.Dict[str, schema.Class],
@@ -395,9 +399,11 @@ def generate(opts, renderer):
395399

396400
classes_by_dir_and_name = sorted(classes.values(), key=lambda cls: (cls.dir, cls.name))
397401
for c in classes_by_dir_and_name:
398-
path = get_import(stub_out / c.path, opts.root_dir)
402+
path = get_import(stub_out / c.dir / "internal" /
403+
c.name if c.internal else stub_out / c.path, opts.root_dir)
399404
imports[c.name] = path
400-
imports_impl[c.name + "Impl"] = path + "Impl"
405+
path_impl = get_import(stub_out / c.dir / "internal" / c.name, opts.root_dir)
406+
imports_impl[c.name + "Impl"] = path_impl + "Impl"
401407

402408
for c in classes.values():
403409
qll = out / c.path.with_suffix(".qll")
@@ -420,7 +426,8 @@ def generate(opts, renderer):
420426
qldoc = renderer.render_str(stub, template='ql_stub_class_qldoc')
421427
_patch_class_qldoc(c.name, qldoc, stub_file)
422428
class_public = _get_class_public(c)
423-
class_public_file = stub_out / path
429+
path_public = _get_path_public(c)
430+
class_public_file = stub_out / path_public
424431
class_public.imports = [imports[t] for t in classes_used_by[c.name]]
425432
renderer.render(class_public, class_public_file)
426433

@@ -472,7 +479,7 @@ def generate(opts, renderer):
472479
if synth_type.is_final:
473480
final_synth_types.append(synth_type)
474481
if synth_type.has_params:
475-
stub_file = stub_out / cls.group / f"{cls.name}Constructor.qll"
482+
stub_file = stub_out / cls.group / "internal" / f"{cls.name}Constructor.qll"
476483
if not renderer.is_customized_stub(stub_file):
477484
# stub rendering must be postponed as we might not have yet all subtracted synth types in `synth_type`
478485
stubs[stub_file] = ql.Synth.ConstructorStub(synth_type, import_prefix=generated_import_prefix)

misc/codegen/templates/ql_class_public.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// generated by {{generator}}, do not edit
22
/**
3-
* This module provides the public class `{{name}}`.
3+
* This module provides the {{^internal}}public {{/internal}}class `{{name}}`.
44
*/
55

6-
private import {{name}}Impl
6+
private import {{^internal}}internal.{{/internal}}{{name}}Impl
77
{{#imports}}
88
import {{.}}
99
{{/imports}}

misc/codegen/test/test_qlgen.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ def children_file(): return ql_output_path() / "ParentChild.qll"
3636

3737

3838
stub_import = "stub.path"
39+
stub_import_prefix_internal = stub_import + ".internal."
3940
stub_import_prefix = stub_import + "."
40-
root_import = stub_import_prefix + "Element"
41+
root_import = stub_import_prefix_internal + "Element"
4142
gen_import = "other.path"
4243
gen_import_prefix = gen_import + "."
4344

@@ -112,10 +113,13 @@ def _filter_generated_classes(ret, output_test_files=False):
112113
}
113114
base_files -= {pathlib.Path(f"{name}.qll") for name in
114115
("Raw", "Synth", "SynthConstructors", "PureSynthConstructors")}
116+
stub_files = {pathlib.Path(f.parent.parent, f.stem + ".qll") if f.parent.name ==
117+
"internal" and pathlib.Path(f.parent.parent, f.stem + ".qll") in base_files else f for f in stub_files}
115118
assert base_files <= stub_files
116119
return {
117-
str(f): (ret[stub_path() / f],
118-
ret[stub_path() / pathlib.Path(f.parent, f.stem + "Impl.qll")],
120+
str(f): (ret[stub_path() / "internal" / f] if stub_path() / "internal" / f in ret else ret[stub_path() / f],
121+
ret[stub_path() / pathlib.Path(f.parent, "internal" if not f.parent.name ==
122+
"internal" else "", f.stem + "Impl.qll")],
119123
ret[ql_output_path() / f])
120124
for f in base_files
121125
}
@@ -166,7 +170,7 @@ def test_one_empty_internal_class(generate_classes):
166170
]) == {
167171
"A.qll": (a_ql_class_public(name="A", internal=True),
168172
a_ql_stub(name="A"),
169-
a_ql_class(name="A", final=True, internal=True, imports=[stub_import_prefix + "A"])),
173+
a_ql_class(name="A", final=True, internal=True, imports=[stub_import_prefix_internal + "A"])),
170174
}
171175

172176

@@ -178,10 +182,10 @@ def test_hierarchy(generate_classes):
178182
schema.Class("A", derived={"B", "C"}),
179183
]) == {
180184
"A.qll": (a_ql_class_public(name="A"), a_ql_stub(name="A"), a_ql_class(name="A", imports=[stub_import_prefix + "A"])),
181-
"B.qll": (a_ql_class_public(name="B", imports=[stub_import_prefix + "A"]), a_ql_stub(name="B"), a_ql_class(name="B", bases=["A"], bases_impl=["AImpl::A"], imports=[stub_import_prefix + "AImpl::Impl as AImpl"])),
182-
"C.qll": (a_ql_class_public(name="C", imports=[stub_import_prefix + "A"]), a_ql_stub(name="C"), a_ql_class(name="C", bases=["A"], bases_impl=["AImpl::A"], imports=[stub_import_prefix + "AImpl::Impl as AImpl"])),
185+
"B.qll": (a_ql_class_public(name="B", imports=[stub_import_prefix + "A"]), a_ql_stub(name="B"), a_ql_class(name="B", bases=["A"], bases_impl=["AImpl::A"], imports=[stub_import_prefix_internal + "AImpl::Impl as AImpl"])),
186+
"C.qll": (a_ql_class_public(name="C", imports=[stub_import_prefix + "A"]), a_ql_stub(name="C"), a_ql_class(name="C", bases=["A"], bases_impl=["AImpl::A"], imports=[stub_import_prefix_internal + "AImpl::Impl as AImpl"])),
183187
"D.qll": (a_ql_class_public(name="D", imports=[stub_import_prefix + "B", stub_import_prefix + "C"]), a_ql_stub(name="D"), a_ql_class(name="D", final=True, bases=["B", "C"], bases_impl=["BImpl::B", "CImpl::C"],
184-
imports=[stub_import_prefix + cls + "Impl::Impl as " + cls + "Impl" for cls in "BC"])),
188+
imports=[stub_import_prefix_internal + cls + "Impl::Impl as " + cls + "Impl" for cls in "BC"])),
185189
}
186190

187191

@@ -210,15 +214,15 @@ def test_hierarchy_children(generate_children_implementations):
210214
schema.Class("C", bases=["A"], derived={"D"}, pragmas=["ql_internal"]),
211215
schema.Class("D", bases=["B", "C"]),
212216
]) == ql.GetParentImplementation(
213-
classes=[a_ql_class(name="A", internal=True, imports=[stub_import_prefix + "A"]),
217+
classes=[a_ql_class(name="A", internal=True, imports=[stub_import_prefix_internal + "A"]),
214218
a_ql_class(name="B", bases=["A"], bases_impl=["AImpl::A"], imports=[
215-
stub_import_prefix + "AImpl::Impl as AImpl"]),
219+
stub_import_prefix_internal + "AImpl::Impl as AImpl"]),
216220
a_ql_class(name="C", bases=["A"], bases_impl=["AImpl::A"], imports=[
217-
stub_import_prefix + "AImpl::Impl as AImpl"], internal=True),
221+
stub_import_prefix_internal + "AImpl::Impl as AImpl"], internal=True),
218222
a_ql_class(name="D", final=True, bases=["B", "C"], bases_impl=["BImpl::B", "CImpl::C"],
219-
imports=[stub_import_prefix + cls + "Impl::Impl as " + cls + "Impl" for cls in "BC"]),
223+
imports=[stub_import_prefix_internal + cls + "Impl::Impl as " + cls + "Impl" for cls in "BC"]),
220224
],
221-
imports=[stub_import] + [stub_import_prefix + cls for cls in "AC"],
225+
imports=[stub_import] + [stub_import_prefix_internal + cls for cls in "AC"],
222226
)
223227

224228

@@ -471,7 +475,7 @@ def test_class_dir(generate_classes):
471475
"B.qll": (a_ql_class_public(name="B", imports=[stub_import_prefix + "another.rel.path.A"]),
472476
a_ql_stub(name="B"),
473477
a_ql_class(name="B", final=True, bases=["A"], bases_impl=["AImpl::A"],
474-
imports=[stub_import_prefix + "another.rel.path.AImpl::Impl as AImpl"])),
478+
imports=[stub_import_prefix + "another.rel.path.internal.AImpl::Impl as AImpl"])),
475479
}
476480

477481

0 commit comments

Comments
 (0)