1+ // generated by { {generator} }, do not edit
2+ /**
3+ * This module provides generated wrappers around the `CfgNode` type.
4+ *
5+ * INTERNAL: Do not import directly.
6+ */
7+
8+ private import codeql.util.Location
9+ private import { {include_file_import} }
10+
11+ /** Provides the input to `MakeCfgNodes` */
12+ signature module InputSig<LocationSig Loc > {
13+ class CfgNode {
14+ AstNode getAstNode();
15+
16+ string toString();
17+
18+ Loc getLocation();
19+ }
20+
21+ AstNode getDesugared(AstNode n);
22+
23+ predicate normalEvaluation(AstNode n);
24+ }
25+
26+ /**
27+ * Given a `CfgNode` implementation, provides the module `Nodes` that
28+ * contains wrappers around `CfgNode` for relevant classes.
29+ */
30+ module MakeCfgNodes<LocationSig Loc, InputSig <Loc > Input> {
31+ private import Input
32+
33+ final private class AstNodeFinal = AstNode;
34+
35+ final private class CfgNodeFinal = CfgNode;
36+
37+ /**
38+ * INTERNAL: Do not expose.
39+ */
40+ abstract class ChildMapping extends AstNodeFinal {
41+ /**
42+ * Holds if `child` is a (possibly nested) child of this AST node
43+ * for which we would like to find a matching CFG child.
44+ */
45+ abstract predicate relevantChild(AstNode child);
46+
47+ /**
48+ * Holds if there is a control-flow path from `cfn` to `cfnChild`, where `cfn`
49+ * is a control-flow node for this AST node, and `cfnChild` is a control-flow
50+ * node for `child`.
51+ *
52+ * This predicate should be implemented at the place where `MakeCfgNodes` is
53+ * invoked.
54+ */
55+ cached
56+ predicate hasCfgChild(AstNode child, CfgNode cfn, CfgNode cfnChild) { none() }
57+ }
58+
59+ /** Provides sub classes of `CfgNode`. */
60+ module Nodes {
61+ {{#classes} }
62+ private final class { {name} }ChildMapping extends ChildMapping, { {name} } {
63+ override predicate relevantChild(AstNode child) {
64+ none()
65+ {{#properties} }
66+ { {#cfg} }
67+ or
68+ child = this.{ {getter} }({ {#is_indexed} }_{ {/is_indexed} })
69+ { {/cfg} }
70+ { {/properties} }
71+ }
72+ }
73+
74+ /**
75+ { {#doc} }
76+ * { {.} }
77+ { {/doc} }
78+ */
79+ final class { {name} }CfgNode extends CfgNodeFinal{ {#bases} }, { {.} }CfgNode{ {/bases} } {
80+ private {{name} }ChildMapping node;
81+
82+ { {name} }CfgNode() {
83+ node = this.getAstNode()
84+ }
85+
86+ /** Gets the underlying `{ {name} }`. */
87+ { {name} } get{ {name} }() { result = node }
88+
89+ { {#properties} }
90+ /**
91+ * { {> ql_property_doc} } *
92+ { {#description} }
93+ * { {.} }
94+ { {/description} }
95+ { {#internal} }
96+ * INTERNAL: Do not use.
97+ { {/internal} }
98+ */
99+ { {type} }{ {#cfg} }CfgNode{ {/cfg} } { {getter} }({ {#is_indexed} }int index{ {/is_indexed} }) {
100+ {{#cfg} }
101+ node.hasCfgChild(node.{ {getter} }({ {#is_indexed} }index{ {/is_indexed} }), this, result)
102+ { {/cfg} }
103+ { {^cfg} }
104+ { {^is_predicate} }result = { {/is_predicate} }node.{ {getter} }({ {#is_indexed} }index{ {/is_indexed} })
105+ { {/cfg} }
106+ }
107+
108+ { {#is_optional} }
109+ /**
110+ * Holds if `{ {getter} }({ {#is_repeated} }index{ {/is_repeated} })` exists.
111+ { {#internal} }
112+ * INTERNAL: Do not use.
113+ { {/internal} }
114+ */
115+ predicate has{ {singular} }({ {#is_repeated} }int index{ {/is_repeated} }) {
116+ exists(this.{{getter} }({ {#is_repeated} }index{ {/is_repeated} }))
117+ }
118+ { {/is_optional} }
119+ { {#is_indexed} }
120+
121+ /**
122+ * Gets any of the { {doc_plural} }.
123+ { {#internal} }
124+ * INTERNAL: Do not use.
125+ { {/internal} }
126+ */
127+ { {type} }{ {#cfg} }CfgNode{ {/cfg} } { {indefinite_getter} }() {
128+ result = this.{{getter} }(_)
129+ }
130+ { {^is_optional} }
131+
132+ /**
133+ * Gets the number of { {doc_plural} }.
134+ { {#internal} }
135+ * INTERNAL: Do not use.
136+ { {/internal} }
137+ */
138+ int getNumberOf{ {plural} }() {
139+ result = count(int i | exists(this.{{getter} }(i)))
140+ }
141+ { {/is_optional} }
142+ { {/is_indexed} }
143+ { {#is_unordered} }
144+ /**
145+ * Gets the number of { {doc_plural} }.
146+ { {#internal} }
147+ * INTERNAL: Do not use.
148+ { {/internal} }
149+ */
150+ int getNumberOf{ {plural} }() {
151+ result = count(this.{{getter} }())
152+ }
153+ { {/is_unordered} }
154+ { {/properties} }
155+ }
156+ { {/classes} }
157+ }
158+
159+ module Consistency {
160+ query predicate missingCfgChild(CfgNode parent, string pred, int child) {
161+ none()
162+ {{#classes} }
163+ { {#properties} }
164+ { {#cfg} }
165+ or
166+ pred = "{ {getter} }" and
167+ parent = any(Nodes::{ {name} }CfgNode cfgNode, { {name} } astNode, { {type} } res |
168+ astNode = cfgNode.get{ {name} }() and
169+ res = getDesugared(astNode.{ {getter} }({ {#is_indexed} }child{ {/is_indexed} }))
170+ { {^is_indexed} }and child = -1{ {/is_indexed} } and
171+ normalEvaluation(res) and
172+ not res = cfgNode.{ {getter} }({ {#is_indexed} }child{ {/is_indexed} }).getAstNode()
173+ |
174+ cfgNode
175+ )
176+ { {/cfg} }
177+ { {/properties} }
178+ { {/classes} }
179+ }
180+ }
181+ }
0 commit comments