Skip to content

Commit 2d3cecb

Browse files
committed
unified: Declare with default implementation
1 parent 5d6da8e commit 2d3cecb

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

  • shared/tree-sitter-extractor/src/generator
  • unified/ql/lib/codeql/unified/internal

shared/tree-sitter-extractor/src/generator/ql_gen.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -997,8 +997,9 @@ pub fn convert_nodes(nodes: &node_types::NodeTypeMap) -> Vec<ql::TopLevel<'_>> {
997997
}
998998
node_types::EntryKind::Union { .. } => {
999999
// It's a tree-sitter supertype node, so we're wrapping a dbscheme
1000-
// union type. Fields declared on the supertype become abstract
1001-
// predicates here.
1000+
// union type. Fields declared on the supertype get an empty
1001+
// default implementation so members without the field can
1002+
// inherit it.
10021003
let predicates = exposed_predicates
10031004
.get(node.ql_class_name.as_str())
10041005
.cloned()
@@ -1013,7 +1014,7 @@ pub fn convert_nodes(nodes: &node_types::NodeTypeMap) -> Vec<ql::TopLevel<'_>> {
10131014
),
10141015
is_private: false,
10151016
is_final: false,
1016-
body: None,
1017+
body: Some(ql::Expression::Pred("none", vec![])),
10171018
..predicate
10181019
})
10191020
.collect();
@@ -1053,8 +1054,7 @@ pub fn convert_nodes(nodes: &node_types::NodeTypeMap) -> Vec<ql::TopLevel<'_>> {
10531054

10541055
// A field getter that's identically defined (in signature) by
10551056
// every member of one of this node's direct supertypes is an
1056-
// override of the corresponding `abstract` predicate declared
1057-
// there.
1057+
// override of the corresponding predicate declared there.
10581058
main_class.predicates.extend(
10591059
field_predicates
10601060
.get(type_name)
@@ -1272,7 +1272,10 @@ mod tests {
12721272
container
12731273
.predicates
12741274
.iter()
1275-
.all(|predicate| predicate.body.is_none() && !predicate.is_final)
1275+
.all(|predicate| {
1276+
predicate.body == Some(ql::Expression::Pred("none", vec![]))
1277+
&& !predicate.is_final
1278+
})
12761279
);
12771280

12781281
let alpha = classes

unified/ql/lib/codeql/unified/internal/Ast.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,13 @@ module Unified {
375375

376376
class Callable extends @unified_callable, F::AstNode {
377377
/** Gets the node corresponding to the field `body`. */
378-
abstract F::Block getBody();
378+
F::Block getBody() { none() }
379379

380380
/** Gets the node corresponding to the field `parameter`. */
381-
abstract F::Parameter getParameter(int i);
381+
F::Parameter getParameter(int i) { none() }
382382

383383
/** Gets the node corresponding to the field `parameter`. */
384-
abstract F::Parameter getAParameter();
384+
F::Parameter getAParameter() { none() }
385385
}
386386

387387
/** A class representing `catch_clause` nodes. */

0 commit comments

Comments
 (0)