mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Codegen/Rust: allow renaming in QL
This adds a `ql.name` codegen pragma to change the name of a property on the QL side. This is useful to give more meaningful names than what we get from the generated rust AST.
This commit is contained in:
@@ -118,17 +118,18 @@ def get_ql_property(cls: schema.Class, prop: schema.Property, lookup: typing.Dic
|
||||
type_is_hideable="ql_hideable" in lookup[prop.type].pragmas if prop.type in lookup else False,
|
||||
internal="ql_internal" in prop.pragmas,
|
||||
)
|
||||
ql_name = prop.pragmas.get("ql_name", prop.name)
|
||||
if prop.is_single:
|
||||
args.update(
|
||||
singular=inflection.camelize(prop.name),
|
||||
singular=inflection.camelize(ql_name),
|
||||
tablename=inflection.tableize(cls.name),
|
||||
tableparams=["this"] + ["result" if p is prop else "_" for p in cls.properties if p.is_single],
|
||||
doc=_get_doc(cls, prop),
|
||||
)
|
||||
elif prop.is_repeated:
|
||||
args.update(
|
||||
singular=inflection.singularize(inflection.camelize(prop.name)),
|
||||
plural=inflection.pluralize(inflection.camelize(prop.name)),
|
||||
singular=inflection.singularize(inflection.camelize(ql_name)),
|
||||
plural=inflection.pluralize(inflection.camelize(ql_name)),
|
||||
tablename=inflection.tableize(f"{cls.name}_{prop.name}"),
|
||||
tableparams=["this", "index", "result"] if not prop.is_unordered else ["this", "result"],
|
||||
doc=_get_doc(cls, prop, plural=False),
|
||||
@@ -136,14 +137,14 @@ def get_ql_property(cls: schema.Class, prop: schema.Property, lookup: typing.Dic
|
||||
)
|
||||
elif prop.is_optional:
|
||||
args.update(
|
||||
singular=inflection.camelize(prop.name),
|
||||
singular=inflection.camelize(ql_name),
|
||||
tablename=inflection.tableize(f"{cls.name}_{prop.name}"),
|
||||
tableparams=["this", "result"],
|
||||
doc=_get_doc(cls, prop),
|
||||
)
|
||||
elif prop.is_predicate:
|
||||
args.update(
|
||||
singular=inflection.camelize(prop.name, uppercase_first_letter=False),
|
||||
singular=inflection.camelize(ql_name, uppercase_first_letter=False),
|
||||
tablename=inflection.underscore(f"{cls.name}_{prop.name}"),
|
||||
tableparams=["this"],
|
||||
doc=_get_doc(cls, prop),
|
||||
@@ -154,6 +155,8 @@ def get_ql_property(cls: schema.Class, prop: schema.Property, lookup: typing.Dic
|
||||
|
||||
|
||||
def get_ql_class(cls: schema.Class, lookup: typing.Dict[str, schema.Class]) -> ql.Class:
|
||||
if "ql_name" in cls.pragmas:
|
||||
raise Error("ql_name is not supported yet for classes, only for properties")
|
||||
prev_child = ""
|
||||
properties = []
|
||||
for p in cls.properties:
|
||||
|
||||
@@ -72,11 +72,11 @@ def include(source: str):
|
||||
@_dataclass
|
||||
class _Namespace:
|
||||
""" simple namespacing mechanism """
|
||||
name: str
|
||||
_name: str
|
||||
|
||||
def add(self, pragma: "_PragmaBase", key: str | None = None):
|
||||
self.__dict__[pragma.pragma] = pragma
|
||||
pragma.pragma = key or f"{self.name}_{pragma.pragma}"
|
||||
pragma.pragma = key or f"{self._name}_{pragma.pragma}"
|
||||
|
||||
|
||||
@_dataclass
|
||||
@@ -87,7 +87,7 @@ class _SynthModifier(_schema.PropertyModifier, _Namespace):
|
||||
prop.synth = self.synth
|
||||
|
||||
def negate(self) -> _schema.PropertyModifier:
|
||||
return _SynthModifier(self.name, False)
|
||||
return _SynthModifier(self._name, False)
|
||||
|
||||
|
||||
qltest = _Namespace("qltest")
|
||||
@@ -239,6 +239,7 @@ qltest.add(_ParametrizedClassPragma("test_with", inherited=True, factory=_schema
|
||||
ql.add(_ParametrizedClassPragma("default_doc_name", factory=lambda doc: doc))
|
||||
ql.add(_ClassPragma("hideable", inherited=True))
|
||||
ql.add(_Pragma("internal"))
|
||||
ql.add(_ParametrizedPragma("name", factory=lambda name: name))
|
||||
|
||||
cpp.add(_Pragma("skip"))
|
||||
|
||||
@@ -256,30 +257,24 @@ synth.add(_ParametrizedClassPragma("on_arguments", factory=lambda **kwargs:
|
||||
_schema.SynthInfo(on_arguments={k: _schema.get_type_name(t) for k, t in kwargs.items()})), key="synth")
|
||||
|
||||
|
||||
@_dataclass(frozen=True)
|
||||
class _PropertyModifierList(_schema.PropertyModifier):
|
||||
def __init__(self):
|
||||
self._mods = []
|
||||
_mods: tuple[_schema.PropertyModifier, ...]
|
||||
|
||||
def __or__(self, other: _schema.PropertyModifier):
|
||||
self._mods.append(other)
|
||||
return self
|
||||
return _PropertyModifierList(self._mods + (other,))
|
||||
|
||||
def modify(self, prop: Property):
|
||||
for m in self._mods:
|
||||
m.modify(prop)
|
||||
|
||||
|
||||
class _PropertyAnnotation:
|
||||
def __or__(self, other: _schema.PropertyModifier):
|
||||
return _PropertyModifierList() | other
|
||||
|
||||
|
||||
_ = _PropertyAnnotation()
|
||||
_ = _PropertyModifierList(())
|
||||
|
||||
drop = object()
|
||||
|
||||
|
||||
def annotate(annotated_cls: type, add_bases: _Iterable[type] | None = None, replace_bases: _Dict[type, type] | None = None, cfg: bool = False) -> _Callable[[type], _PropertyAnnotation]:
|
||||
def annotate(annotated_cls: type, add_bases: _Iterable[type] | None = None, replace_bases: _Dict[type, type] | None = None, cfg: bool = False) -> _Callable[[type], _PropertyModifierList]:
|
||||
"""
|
||||
Add or modify schema annotations after a class has been defined previously.
|
||||
|
||||
@@ -287,7 +282,7 @@ def annotate(annotated_cls: type, add_bases: _Iterable[type] | None = None, repl
|
||||
|
||||
`replace_bases` can be used to replace bases on the annotated class.
|
||||
"""
|
||||
def decorator(cls: type) -> _PropertyAnnotation:
|
||||
def decorator(cls: type) -> _PropertyModifierList:
|
||||
if cls.__name__ != "_":
|
||||
raise _schema.Error("Annotation classes must be named _")
|
||||
if cls.__doc__ is not None:
|
||||
@@ -307,7 +302,7 @@ def annotate(annotated_cls: type, add_bases: _Iterable[type] | None = None, repl
|
||||
del annotated_cls.__annotations__[p]
|
||||
elif p in annotated_cls.__annotations__:
|
||||
annotated_cls.__annotations__[p] |= a
|
||||
elif isinstance(a, (_PropertyAnnotation, _PropertyModifierList)):
|
||||
elif isinstance(a, (_PropertyModifierList, _PropertyModifierList)):
|
||||
raise _schema.Error(f"annotated property {p} not present in annotated class "
|
||||
f"{annotated_cls.__name__}")
|
||||
else:
|
||||
|
||||
12
rust/ql/.generated.list
generated
12
rust/ql/.generated.list
generated
@@ -1,4 +1,4 @@
|
||||
lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll e1d6ad3a582c15addb042ce1e054a916f81030f7a10a69408ab929679e9a92ad f1837efe28fb1ae5162437a482d35d24a792e133e10879284202c45e90c62ff6
|
||||
lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll c0438ab3e984fbf7ce2cc4ac64aafa115f36f2be700a819fd81f15d777f363b6 bc57c07b7f9472156cff3f878459872255c7ee4ba0767258129d0258789f98df
|
||||
lib/codeql/rust/elements/Abi.qll 4c973d28b6d628f5959d1f1cc793704572fd0acaae9a97dfce82ff9d73f73476 250f68350180af080f904cd34cb2af481c5c688dc93edf7365fd0ae99855e893
|
||||
lib/codeql/rust/elements/ArgList.qll 661f5100f5d3ef8351452d9058b663a2a5c720eea8cf11bedd628969741486a2 28e424aac01a90fb58cd6f9f83c7e4cf379eea39e636bc0ba07efc818be71c71
|
||||
lib/codeql/rust/elements/ArrayExpr.qll a3e6e122632f4011644ec31b37f88b32fe3f2b7e388e7e878a6883309937049f 12ccb5873d95c433da5606fd371d182ef2f71b78d0c53c2d6dec10fa45852bdc
|
||||
@@ -495,7 +495,7 @@ lib/codeql/rust/elements/internal/generated/MacroStmts.qll cb4f3c2721a4d0c8522e5
|
||||
lib/codeql/rust/elements/internal/generated/MacroType.qll c462824df4a002956c036966d15cd0bce206e664888f8d0c7834dedb38b3c0bf 947480f07c40128ef3d00ad4c3a29a685472b3e20a661680c22f6bb318205ed1
|
||||
lib/codeql/rust/elements/internal/generated/MatchArm.qll 8fb740a0f2e308782d9cf390672969cd7cf6e698e5b847fb02ae3fa6c205646f 42bfe8dd94fc24ec925fbd44016df111600f99d1216c9a698631373bb6048830
|
||||
lib/codeql/rust/elements/internal/generated/MatchArmList.qll 13362680c037fe83fef4653562cc10a4429078316b5ec7c47b076336cf4aca2e 41c674293c13eceaca62134ae0c6778541f6a5201cbc5c146f0ba01b898dc267
|
||||
lib/codeql/rust/elements/internal/generated/MatchExpr.qll 689d65f690fe05bc262d0a5bfe69bb4f8a142db387c5765fcc4958a9b49989f8 2979cd2017d0538870d17b2b7592c75cc05b706bd36c9de3e5dc38fa3a957e5b
|
||||
lib/codeql/rust/elements/internal/generated/MatchExpr.qll e1e5bf4623511028a6c2ebc6bb6e3c18ec9fe4f49ef4cd8654e5dc376121088d c0760592040b2df9a571cd766397a0f9c68684d24d72780756cae7a1878d102a
|
||||
lib/codeql/rust/elements/internal/generated/MatchGuard.qll 521a507883963106780f1782084c581fbcf1179863c7c15438c4db79e30e78dd 6226feffaaa8d828a42ece0c693e616cd375672eb987c3b7ff1ca15fa23c116a
|
||||
lib/codeql/rust/elements/internal/generated/Meta.qll 38fca2c9958b4179de311546fe0850319010aca9cd17c97d57e12b521c5d0947 740f99c9d41044ceebfcc9d29baaa22f59c11a40f45502a34aa587d423c018f8
|
||||
lib/codeql/rust/elements/internal/generated/MethodCallExpr.qll 17bffcc826851a8be32a1900b8fdf777f9bab6aed9f8268d566173c4974c1cf9 134a2860bdf16daafdb3e574c52a69d2598210653db89c2fa062ca25e8f8a649
|
||||
@@ -512,7 +512,7 @@ lib/codeql/rust/elements/internal/generated/ParamList.qll c808c9d84dd7800573832b
|
||||
lib/codeql/rust/elements/internal/generated/ParenExpr.qll bc0731505bfe88516205ec360582a4222d2681d11342c93e15258590ddee82f2 d4bd6e0c80cf1d63746c88d4bcb3a01d4c75732e5da09e3ebd9437ced227fb60
|
||||
lib/codeql/rust/elements/internal/generated/ParenPat.qll ce24b8f8ecbf0f204af200317405724063887257460c80cf250c39b2fdf37185 e7c87d37e1a0ca7ea03840017e1aa9ddb7f927f1f3b6396c0305b46aeee33db6
|
||||
lib/codeql/rust/elements/internal/generated/ParenType.qll 9cc954d73f8330dcac7b475f97748b63af5c8766dee9d2f2872c0a7e4c903537 c07534c8a9c683c4a9b11d490095647e420de0a0bfc23273eaf6f31b00244273
|
||||
lib/codeql/rust/elements/internal/generated/ParentChild.qll ae0288399423b8b69a98a520ff4d2cb53d15ec404696cf62b0ceea965e2258ba aed73c416d74b504c02ee2e9bc2a72881d851ad0819b331b59728a4084e14fdd
|
||||
lib/codeql/rust/elements/internal/generated/ParentChild.qll a19adfe192c88023b77f938d91f8539df6e42fa14172389537069decfe8baa7d 6be35ca8755d80c0365eeb9ecc51982fb0e24d2ed53ec6b17a15da4af6fbe6e6
|
||||
lib/codeql/rust/elements/internal/generated/Pat.qll 3605ac062be2f294ee73336e9669027b8b655f4ad55660e1eab35266275154ee 7f9400db2884d336dd1d21df2a8093759c2a110be9bf6482ce8e80ae0fd74ed4
|
||||
lib/codeql/rust/elements/internal/generated/Path.qll 4c1c8e840ed57880e574142b081b11d7a7428a009f10e3aa8f4645e211f6b2e0 989668cf0f1bdee7557e2f97c01e41d2a56848227fed41477833f5fc1e1d35f6
|
||||
lib/codeql/rust/elements/internal/generated/PathExpr.qll 2096e3c1db22ee488a761690adabfc9cfdea501c99f7c5d96c0019cb113fc506 54245ce0449c4e263173213df01e079d5168a758503a5dbd61b25ad35a311140
|
||||
@@ -525,7 +525,7 @@ lib/codeql/rust/elements/internal/generated/PtrType.qll 40099c5a4041314b66932dfd
|
||||
lib/codeql/rust/elements/internal/generated/PureSynthConstructors.qll ea294a3ba33fd1bc632046c4fedbcb84dcb961a8e4599969d65893b19d90e590 ea294a3ba33fd1bc632046c4fedbcb84dcb961a8e4599969d65893b19d90e590
|
||||
lib/codeql/rust/elements/internal/generated/RangeExpr.qll 23cca03bf43535f33b22a38894f70d669787be4e4f5b8fe5c8f7b964d30e9027 18624cef6c6b679eeace2a98737e472432e0ead354cca02192b4d45330f047c9
|
||||
lib/codeql/rust/elements/internal/generated/RangePat.qll efd93730de217cf50dcba5875595263a5eadf9f7e4e1272401342a094d158614 229b251b3d118932e31e78ac4dfb75f48b766f240f20d436062785606d44467b
|
||||
lib/codeql/rust/elements/internal/generated/Raw.qll ee5642a7a5ad75f48d4db10eccb197b1a11db2fc3432cf2e24a8bcbe83a474e2 134f2e0c87039d052dd31991017fb35597f37f28879abd702b62ec1d880118c6
|
||||
lib/codeql/rust/elements/internal/generated/Raw.qll f1af475812318f9fbfd1731a1e97ae77783bcc8a7ad45463cd9916e4c46e783a 1e06a7cd87c4c704f76bbc70ba3d7601ca6f1b3dd11f124ee448d8b834f7ce55
|
||||
lib/codeql/rust/elements/internal/generated/RecordExpr.qll eb6cb662e463f9260efae1a6ce874fa781172063b916ef1963f861e9942d308d 1a21cbccc8f3799ff13281e822818ebfb21d81591720a427cac3625512cb9d40
|
||||
lib/codeql/rust/elements/internal/generated/RecordExprField.qll 7e9f8663d3b74ebbc9603b10c9912f082febba6bd73d344b100bbd3edf837802 fbe6b578e7fd5d5a6f21bbb8c388957ab7210a6a249ec71510a50fb35b319ea1
|
||||
lib/codeql/rust/elements/internal/generated/RecordExprFieldList.qll 179a97211fe7aa6265085d4d54115cdbc0e1cd7c9b2135591e8f36d6432f13d3 dd44bbbc1e83a1ed3a587afb729d7debf7aeb7b63245de181726af13090e50c0
|
||||
@@ -845,10 +845,10 @@ test/extractor-tests/generated/MatchArm/MatchArm_getPat.ql b346bca229226414b32ac
|
||||
test/extractor-tests/generated/MatchArmList/MatchArmList.ql 14b5e110d48e2b77c85b7a188262e6a98300e0d4d507bb7ed9179c5802251dd6 4d091f06b12fef0fffe1c80a10f74438d8068f2fa09c50d5e240b6d140e60d90
|
||||
test/extractor-tests/generated/MatchArmList/MatchArmList_getArm.ql 4781d002538a92b7f40fb0ec3d61aeedb6348341ddc354bbdd3ff61b74d59767 ae0da9497a30ce006e03bdb70e0ee24b685df529ac15a7d99a6869b5f7d7b371
|
||||
test/extractor-tests/generated/MatchArmList/MatchArmList_getAttr.ql 4d7e6d152d2dbeb4c9f594becabea27d3b25fecbde40d791a2907c69cc0c9631 4be9be658bb22e1b764c4ebc8d6b99bf50fd939f35ea44fbb869056c14632bd4
|
||||
test/extractor-tests/generated/MatchExpr/MatchExpr.ql ec116bca37079488977a50beeba508c440cf337799947fcb810b6bd7a7605255 42dc7b5f0dd6fd91417d9846a7b4f678cbfcf095791aaf57c8d3b4548ce2dd98
|
||||
test/extractor-tests/generated/MatchExpr/MatchExpr.ql 22a3ace49ec98524388ccfb031c180eedc741cbc5b58a4815cc9e52fe292e6b3 5b56c71cbc02ac3aecfcbe93e7bbdb55727aae39d7949a7d8db3d6f93ea7ca80
|
||||
test/extractor-tests/generated/MatchExpr/MatchExpr_getAttr.ql cb8057372dcf24dfa02896ebf4e60a0b757dc4742b94011edc38f5b898ed4d25 6809695c2d3ac3b92c06049c9b920e8c0e99ee1998a11a7f181f2b0ceb47c197
|
||||
test/extractor-tests/generated/MatchExpr/MatchExpr_getExpr.ql 7baaa64071cf2666e3b2bc05630d92a7a3b6cf04a026b1f7053c5e2a735bcaa8 d9ba8d8bbff05cfc0461ab41295f921b48429b4376c29adf54428bd5a9aa5298
|
||||
test/extractor-tests/generated/MatchExpr/MatchExpr_getMatchArmList.ql d97055bcb0431e8b258b5ecdd98aa07cb24ece06b0cd658b697cd71da4ede8fc 5e9c03b2665ef6b2af98897996abb2e0a9c18d54eb64588340b8efbcee9793bd
|
||||
test/extractor-tests/generated/MatchExpr/MatchExpr_getMatchedExpr.ql 478585d26c2b301f474f04569deb79728c80b3f67fe5c2536b64f5a29dcccf30 750d24c48dc0f57992265c3fc60fbfa400263f58f74b7951774a383d3ae4ae0a
|
||||
test/extractor-tests/generated/MatchGuard/MatchGuard.ql 23e47ec1b13e2d80e31b57894a46ec789d6ab5ed1eb66bdb6bba9bd5ae71d3ef 7302f4a93108a83228e0ebd5b4a1bc6bccc1f6f0f3272054866fa90378c0dcc4
|
||||
test/extractor-tests/generated/MatchGuard/MatchGuard_getCondition.ql 8a79dd46798f111f8d0d5a975380b5cebe5e337267752b77b3718b268ba2773d 6691d8fb483f64fc7e3ad3f46e3129e0a1184d7beb9f83a1000acdbb081c8b5e
|
||||
test/extractor-tests/generated/Meta/Meta.ql 16f163f00ba2bbaa0a8c6f3f6710c860a8f61d02d43321c78e05a10a3606e39b ba982c6bb93ddb4fc2c44d24635bd487128a5b1d1f885214044c989a21f4d05a
|
||||
|
||||
2
rust/ql/.gitattributes
generated
vendored
2
rust/ql/.gitattributes
generated
vendored
@@ -849,8 +849,8 @@
|
||||
/test/extractor-tests/generated/MatchArmList/MatchArmList_getAttr.ql linguist-generated
|
||||
/test/extractor-tests/generated/MatchExpr/MatchExpr.ql linguist-generated
|
||||
/test/extractor-tests/generated/MatchExpr/MatchExpr_getAttr.ql linguist-generated
|
||||
/test/extractor-tests/generated/MatchExpr/MatchExpr_getExpr.ql linguist-generated
|
||||
/test/extractor-tests/generated/MatchExpr/MatchExpr_getMatchArmList.ql linguist-generated
|
||||
/test/extractor-tests/generated/MatchExpr/MatchExpr_getMatchedExpr.ql linguist-generated
|
||||
/test/extractor-tests/generated/MatchGuard/MatchGuard.ql linguist-generated
|
||||
/test/extractor-tests/generated/MatchGuard/MatchGuard_getCondition.ql linguist-generated
|
||||
/test/extractor-tests/generated/Meta/Meta.ql linguist-generated
|
||||
|
||||
@@ -514,14 +514,14 @@ module ExprTrees {
|
||||
|
||||
class MatchExprTree extends PostOrderTree instanceof MatchExpr {
|
||||
override predicate propagatesAbnormal(AstNode child) {
|
||||
child = [super.getExpr(), super.getAnArm().getExpr()]
|
||||
child = [super.getMatchedExpr(), super.getAnArm().getExpr()]
|
||||
}
|
||||
|
||||
override predicate first(AstNode node) { first(super.getExpr(), node) }
|
||||
override predicate first(AstNode node) { first(super.getMatchedExpr(), node) }
|
||||
|
||||
override predicate succ(AstNode pred, AstNode succ, Completion c) {
|
||||
// Edge from the scrutinee to the first arm or to the match expression if no arms.
|
||||
last(super.getExpr(), pred, c) and
|
||||
last(super.getMatchedExpr(), pred, c) and
|
||||
(
|
||||
first(super.getArm(0).getPat(), succ)
|
||||
or
|
||||
|
||||
@@ -1709,7 +1709,7 @@ module MakeCfgNodes<LocationSig Loc, InputSig<Loc> Input> {
|
||||
override predicate relevantChild(AstNode child) {
|
||||
none()
|
||||
or
|
||||
child = this.getExpr()
|
||||
child = this.getMatchedExpr()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1754,14 +1754,14 @@ module MakeCfgNodes<LocationSig Loc, InputSig<Loc> Input> {
|
||||
/**
|
||||
* Gets the expression of this match expression, if it exists.
|
||||
*/
|
||||
ExprCfgNode getExpr() {
|
||||
any(ChildMapping mapping).hasCfgChild(node, node.getExpr(), this, result)
|
||||
ExprCfgNode getMatchedExpr() {
|
||||
any(ChildMapping mapping).hasCfgChild(node, node.getMatchedExpr(), this, result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `getExpr()` exists.
|
||||
* Holds if `getMatchedExpr()` exists.
|
||||
*/
|
||||
predicate hasExpr() { exists(this.getExpr()) }
|
||||
predicate hasMatchedExpr() { exists(this.getMatchedExpr()) }
|
||||
|
||||
/**
|
||||
* Gets the match arm list of this match expression, if it exists.
|
||||
@@ -3451,14 +3451,14 @@ module MakeCfgNodes<LocationSig Loc, InputSig<Loc> Input> {
|
||||
cfgNode
|
||||
)
|
||||
or
|
||||
pred = "getExpr" and
|
||||
pred = "getMatchedExpr" and
|
||||
parent =
|
||||
any(Nodes::MatchExprCfgNode cfgNode, MatchExpr astNode |
|
||||
astNode = cfgNode.getMatchExpr() and
|
||||
child = getDesugared(astNode.getExpr()) and
|
||||
child = getDesugared(astNode.getMatchedExpr()) and
|
||||
i = -1 and
|
||||
hasCfgNode(child) and
|
||||
not child = cfgNode.getExpr().getAstNode()
|
||||
not child = cfgNode.getMatchedExpr().getAstNode()
|
||||
|
|
||||
cfgNode
|
||||
)
|
||||
|
||||
@@ -57,15 +57,17 @@ module Generated {
|
||||
/**
|
||||
* Gets the expression of this match expression, if it exists.
|
||||
*/
|
||||
Expr getExpr() {
|
||||
Expr getMatchedExpr() {
|
||||
result =
|
||||
Synth::convertExprFromRaw(Synth::convertMatchExprToRaw(this).(Raw::MatchExpr).getExpr())
|
||||
Synth::convertExprFromRaw(Synth::convertMatchExprToRaw(this)
|
||||
.(Raw::MatchExpr)
|
||||
.getMatchedExpr())
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `getExpr()` exists.
|
||||
* Holds if `getMatchedExpr()` exists.
|
||||
*/
|
||||
final predicate hasExpr() { exists(this.getExpr()) }
|
||||
final predicate hasMatchedExpr() { exists(this.getMatchedExpr()) }
|
||||
|
||||
/**
|
||||
* Gets the match arm list of this match expression, if it exists.
|
||||
|
||||
@@ -2030,13 +2030,13 @@ private module Impl {
|
||||
}
|
||||
|
||||
private Element getImmediateChildOfMatchExpr(MatchExpr e, int index, string partialPredicateCall) {
|
||||
exists(int b, int bExpr, int n, int nAttr, int nExpr, int nMatchArmList |
|
||||
exists(int b, int bExpr, int n, int nAttr, int nMatchedExpr, int nMatchArmList |
|
||||
b = 0 and
|
||||
bExpr = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfExpr(e, i, _)) | i) and
|
||||
n = bExpr and
|
||||
nAttr = n + 1 + max(int i | i = -1 or exists(e.getAttr(i)) | i) and
|
||||
nExpr = nAttr + 1 and
|
||||
nMatchArmList = nExpr + 1 and
|
||||
nMatchedExpr = nAttr + 1 and
|
||||
nMatchArmList = nMatchedExpr + 1 and
|
||||
(
|
||||
none()
|
||||
or
|
||||
@@ -2045,9 +2045,11 @@ private module Impl {
|
||||
result = e.getAttr(index - n) and
|
||||
partialPredicateCall = "Attr(" + (index - n).toString() + ")"
|
||||
or
|
||||
index = nAttr and result = e.getExpr() and partialPredicateCall = "Expr()"
|
||||
index = nAttr and result = e.getMatchedExpr() and partialPredicateCall = "MatchedExpr()"
|
||||
or
|
||||
index = nExpr and result = e.getMatchArmList() and partialPredicateCall = "MatchArmList()"
|
||||
index = nMatchedExpr and
|
||||
result = e.getMatchArmList() and
|
||||
partialPredicateCall = "MatchArmList()"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2172,7 +2172,7 @@ module Raw {
|
||||
/**
|
||||
* Gets the expression of this match expression, if it exists.
|
||||
*/
|
||||
Expr getExpr() { match_expr_exprs(this, result) }
|
||||
Expr getMatchedExpr() { match_expr_exprs(this, result) }
|
||||
|
||||
/**
|
||||
* Gets the match arm list of this match expression, if it exists.
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
| gen_match_expr.rs:5:5:8:5 | match x { ... } | getNumberOfAttrs: | 0 | hasExpr: | yes | hasMatchArmList: | yes |
|
||||
| gen_match_expr.rs:9:5:12:5 | match x { ... } | getNumberOfAttrs: | 0 | hasExpr: | yes | hasMatchArmList: | yes |
|
||||
| gen_match_expr.rs:5:5:8:5 | match x { ... } | getNumberOfAttrs: | 0 | hasMatched: | yes | hasMatchArmList: | yes |
|
||||
| gen_match_expr.rs:9:5:12:5 | match x { ... } | getNumberOfAttrs: | 0 | hasMatched: | yes | hasMatchArmList: | yes |
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
import codeql.rust.elements
|
||||
import TestUtils
|
||||
|
||||
from MatchExpr x, int getNumberOfAttrs, string hasExpr, string hasMatchArmList
|
||||
from MatchExpr x, int getNumberOfAttrs, string hasMatchedExpr, string hasMatchArmList
|
||||
where
|
||||
toBeTested(x) and
|
||||
not x.isUnknown() and
|
||||
getNumberOfAttrs = x.getNumberOfAttrs() and
|
||||
(if x.hasExpr() then hasExpr = "yes" else hasExpr = "no") and
|
||||
(if x.hasMatchedExpr() then hasMatchedExpr = "yes" else hasMatchedExpr = "no") and
|
||||
if x.hasMatchArmList() then hasMatchArmList = "yes" else hasMatchArmList = "no"
|
||||
select x, "getNumberOfAttrs:", getNumberOfAttrs, "hasExpr:", hasExpr, "hasMatchArmList:",
|
||||
hasMatchArmList
|
||||
select x, "getNumberOfAttrs:", getNumberOfAttrs, "hasMatchedExpr:", hasMatchedExpr,
|
||||
"hasMatchArmList:", hasMatchArmList
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
| gen_match_expr.rs:5:5:8:5 | match x { ... } | gen_match_expr.rs:5:11:5:11 | x |
|
||||
| gen_match_expr.rs:9:5:12:5 | match x { ... } | gen_match_expr.rs:9:11:9:11 | x |
|
||||
@@ -4,4 +4,4 @@ import TestUtils
|
||||
|
||||
from MatchExpr x
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
select x, x.getExpr()
|
||||
select x, x.getMatchedExpr()
|
||||
@@ -289,6 +289,7 @@ class _:
|
||||
}
|
||||
```
|
||||
"""
|
||||
expr: _ | ql.name("matched_expr")
|
||||
|
||||
|
||||
@annotate(ContinueExpr, cfg = True)
|
||||
|
||||
Reference in New Issue
Block a user