Skip to content

Commit 9264b2a

Browse files
committed
Codegen: add internal to properties, rename ql_internal->internal
1 parent a8fcfd1 commit 9264b2a

File tree

6 files changed

+50
-29
lines changed

6 files changed

+50
-29
lines changed

misc/codegen/generators/qlgen.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def get_ql_property(cls: schema.Class, prop: schema.Property, lookup: typing.Dic
114114
description=prop.description,
115115
synth=bool(cls.synth) or prop.synth,
116116
type_is_hideable=lookup[prop.type].hideable if prop.type in lookup else False,
117+
internal="ql_internal" in prop.pragmas,
117118
)
118119
if prop.is_single:
119120
args.update(
@@ -151,7 +152,7 @@ def get_ql_property(cls: schema.Class, prop: schema.Property, lookup: typing.Dic
151152

152153

153154
def get_ql_class(cls: schema.Class, lookup: typing.Dict[str, schema.Class]) -> ql.Class:
154-
pragmas = {k: True for k in cls.pragmas if k.startswith("ql")}
155+
pragmas = {k: True for k in cls.pragmas if k.startswith("qltest")}
155156
prev_child = ""
156157
properties = []
157158
for p in cls.properties:
@@ -167,6 +168,7 @@ def get_ql_class(cls: schema.Class, lookup: typing.Dict[str, schema.Class]) -> q
167168
dir=pathlib.Path(cls.group or ""),
168169
doc=cls.doc,
169170
hideable=cls.hideable,
171+
internal="ql_internal" in cls.pragmas,
170172
**pragmas,
171173
)
172174

@@ -313,7 +315,7 @@ def _get_stub(cls: schema.Class, base_import: str, generated_import_prefix: str)
313315
accessors = []
314316
return ql.Stub(name=cls.name, base_import=base_import, import_prefix=generated_import_prefix,
315317
doc=cls.doc, synth_accessors=accessors,
316-
ql_internal="ql_internal" in cls.pragmas)
318+
internal="ql_internal" in cls.pragmas)
317319

318320

319321
_stub_qldoc_header = "// the following QLdoc is generated: if you need to edit it, do it in the schema file\n"
@@ -397,15 +399,15 @@ def generate(opts, renderer):
397399
_patch_class_qldoc(c.name, qldoc, stub_file)
398400

399401
# for example path/to/elements -> path/to/elements.qll
400-
renderer.render(ql.ImportList([i for name, i in imports.items() if not classes[name].ql_internal]),
402+
renderer.render(ql.ImportList([i for name, i in imports.items() if not classes[name].internal]),
401403
include_file)
402404

403405
elements_module = get_import(include_file, opts.root_dir)
404406

405407
renderer.render(
406408
ql.GetParentImplementation(
407409
classes=list(classes.values()),
408-
imports=[elements_module] + [i for name, i in imports.items() if classes[name].ql_internal],
410+
imports=[elements_module] + [i for name, i in imports.items() if classes[name].internal],
409411
),
410412
out / 'ParentChild.qll')
411413

misc/codegen/lib/ql.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Property:
4444
doc_plural: Optional[str] = None
4545
synth: bool = False
4646
type_is_hideable: bool = False
47+
internal: bool = False
4748

4849
def __post_init__(self):
4950
if self.tableparams:
@@ -112,7 +113,7 @@ class Class:
112113
qltest_skip: bool = False
113114
qltest_collapse_hierarchy: bool = False
114115
qltest_uncollapse_hierarchy: bool = False
115-
ql_internal: bool = False
116+
internal: bool = False
116117
doc: List[str] = field(default_factory=list)
117118
hideable: bool = False
118119

@@ -162,7 +163,7 @@ class Stub:
162163
base_import: str
163164
import_prefix: str
164165
synth_accessors: List[SynthUnderlyingAccessor] = field(default_factory=list)
165-
ql_internal: bool = False
166+
internal: bool = False
166167
doc: List[str] = field(default_factory=list)
167168

168169
@property
@@ -171,7 +172,7 @@ def has_synth_accessors(self) -> bool:
171172

172173
@property
173174
def has_qldoc(self) -> bool:
174-
return bool(self.doc) or self.ql_internal
175+
return bool(self.doc) or self.internal
175176

176177

177178
@dataclass

misc/codegen/templates/ql_stub_class_qldoc.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
{{#doc}}
44
* {{.}}
55
{{/doc}}
6-
{{#ql_internal}}
6+
{{#internal}}
77
* INTERNAL: Do not use.
8-
{{/ql_internal}}
8+
{{/internal}}
99
*/
1010
{{/has_qldoc}}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* This module provides a hand-modifiable wrapper around the generated class `{{name}}`.
3-
{{#ql_internal}}
3+
{{#internal}}
44
* INTERNAL: Do not use.
5-
{{/ql_internal}}
5+
{{/internal}}
66
*/

misc/codegen/test/test_ql.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ def test_class_with_children():
147147
assert cls.has_children is True
148148

149149

150-
@pytest.mark.parametrize("doc,ql_internal,expected",
150+
@pytest.mark.parametrize("doc,internal,expected",
151151
[
152152
(["foo", "bar"], False, True),
153153
(["foo", "bar"], True, True),
154154
([], False, False),
155155
([], True, True),
156156
])
157-
def test_has_doc(doc, ql_internal, expected):
158-
stub = ql.Stub("Class", base_import="foo", import_prefix="bar", doc=doc, ql_internal=ql_internal)
157+
def test_has_doc(doc, internal, expected):
158+
stub = ql.Stub("Class", base_import="foo", import_prefix="bar", doc=doc, internal=internal)
159159
assert stub.has_qldoc is expected
160160

161161

misc/codegen/test/test_qlgen.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ def test_one_empty_internal_class(generate_classes):
157157
assert generate_classes([
158158
schema.Class("A", pragmas=["ql_internal"])
159159
]) == {
160-
"A.qll": (a_ql_stub(name="A", ql_internal=True),
161-
a_ql_class(name="A", final=True, ql_internal=True)),
160+
"A.qll": (a_ql_stub(name="A", internal=True),
161+
a_ql_class(name="A", final=True, internal=True)),
162162
}
163163

164164

@@ -202,11 +202,11 @@ def test_hierarchy_children(generate_children_implementations):
202202
schema.Class("C", bases=["A"], derived={"D"}, pragmas=["ql_internal"]),
203203
schema.Class("D", bases=["B", "C"]),
204204
]) == ql.GetParentImplementation(
205-
classes=[a_ql_class(name="A", ql_internal=True),
205+
classes=[a_ql_class(name="A", internal=True),
206206
a_ql_class(name="B", bases=["A"], imports=[
207207
stub_import_prefix + "A"]),
208208
a_ql_class(name="C", bases=["A"], imports=[
209-
stub_import_prefix + "A"], ql_internal=True),
209+
stub_import_prefix + "A"], internal=True),
210210
a_ql_class(name="D", final=True, bases=["B", "C"],
211211
imports=[stub_import_prefix + cls for cls in "BC"]),
212212
],
@@ -228,6 +228,21 @@ def test_single_property(generate_classes):
228228
}
229229

230230

231+
def test_internal_property(generate_classes):
232+
assert generate_classes([
233+
schema.Class("MyObject", properties=[
234+
schema.SingleProperty("foo", "bar", pragmas=["ql_internal"])]),
235+
]) == {
236+
"MyObject.qll": (a_ql_stub(name="MyObject"),
237+
a_ql_class(name="MyObject", final=True,
238+
properties=[
239+
ql.Property(singular="Foo", type="bar", tablename="my_objects",
240+
tableparams=["this", "result"], doc="foo of this my object",
241+
internal=True),
242+
])),
243+
}
244+
245+
231246
def test_children(generate_classes):
232247
assert generate_classes([
233248
schema.Class("FakeRoot"),
@@ -424,7 +439,8 @@ def test_class_dir(generate_classes):
424439
schema.Class("A", derived={"B"}, group=dir),
425440
schema.Class("B", bases=["A"]),
426441
]) == {
427-
f"{dir}/A.qll": (a_ql_stub(name="A", import_prefix="another.rel.path."), a_ql_class(name="A", dir=pathlib.Path(dir))),
442+
f"{dir}/A.qll": (
443+
a_ql_stub(name="A", import_prefix="another.rel.path."), a_ql_class(name="A", dir=pathlib.Path(dir))),
428444
"B.qll": (a_ql_stub(name="B"),
429445
a_ql_class(name="B", final=True, bases=["A"],
430446
imports=[stub_import_prefix + "another.rel.path.A"])),
@@ -878,9 +894,9 @@ def test_stub_on_class_with_synth_from_class(generate_classes):
878894
ql.SynthUnderlyingAccessor(argument="Entity", type="Raw::A", constructorparams=["result"]),
879895
]),
880896
a_ql_class(name="MyObject", final=True, properties=[
881-
ql.Property(singular="Foo", type="bar", tablename="my_objects", synth=True,
882-
tableparams=["this", "result"], doc="foo of this my object"),
883-
])),
897+
ql.Property(singular="Foo", type="bar", tablename="my_objects", synth=True,
898+
tableparams=["this", "result"], doc="foo of this my object"),
899+
])),
884900
}
885901

886902

@@ -895,9 +911,9 @@ def test_stub_on_class_with_synth_on_arguments(generate_classes):
895911
ql.SynthUnderlyingAccessor(argument="Label", type="string", constructorparams=["_", "_", "result"]),
896912
]),
897913
a_ql_class(name="MyObject", final=True, properties=[
898-
ql.Property(singular="Foo", type="bar", tablename="my_objects", synth=True,
899-
tableparams=["this", "result"], doc="foo of this my object"),
900-
])),
914+
ql.Property(singular="Foo", type="bar", tablename="my_objects", synth=True,
915+
tableparams=["this", "result"], doc="foo of this my object"),
916+
])),
901917
}
902918

903919

@@ -909,7 +925,8 @@ def test_synth_property(generate_classes):
909925
"MyObject.qll": (a_ql_stub(name="MyObject"),
910926
a_ql_class(name="MyObject", final=True,
911927
properties=[
912-
ql.Property(singular="Foo", type="bar", tablename="my_objects", synth=True,
928+
ql.Property(singular="Foo", type="bar", tablename="my_objects",
929+
synth=True,
913930
tableparams=["this", "result"], doc="foo of this my object"),
914931
])),
915932
}
@@ -934,9 +951,10 @@ def test_hideable_property(generate_classes):
934951
"Other.qll": (a_ql_stub(name="Other"),
935952
a_ql_class(name="Other", imports=[stub_import_prefix + "MyObject"],
936953
final=True, properties=[
937-
ql.Property(singular="X", type="MyObject", tablename="others", type_is_hideable=True,
938-
tableparams=["this", "result"], doc="x of this other"),
939-
])),
954+
ql.Property(singular="X", type="MyObject", tablename="others",
955+
type_is_hideable=True,
956+
tableparams=["this", "result"], doc="x of this other"),
957+
])),
940958
}
941959

942960

0 commit comments

Comments
 (0)