@@ -134,7 +134,6 @@ fn create_top_class() -> ql::Class {
134134 is_abstract : false ,
135135 supertypes : vec ! [ ql:: Type :: AtType ( "top" . to_owned( ) ) ] ,
136136 characteristic_predicate : None ,
137- fields : vec ! [ ] ,
138137 predicates : vec ! [ to_string, get_location, get_a_field_or_child] ,
139138 }
140139}
@@ -151,7 +150,7 @@ fn create_none_predicate(
151150 overridden,
152151 return_type,
153152 formal_parameters,
154- body : ql:: Term :: Expr ( ql :: Expression :: Pred ( "none" . to_owned ( ) , vec ! [ ] ) ) ,
153+ body : ql:: Expression :: Pred ( "none" . to_owned ( ) , vec ! [ ] ) ,
155154 }
156155}
157156
@@ -162,9 +161,9 @@ fn create_location_class() -> ql::Class {
162161 overridden : false ,
163162 return_type : Some ( ql:: Type :: String ) ,
164163 formal_parameters : vec ! [ ] ,
165- body : ql:: Term :: Equals (
166- ql:: Expression :: Var ( "result" . to_owned ( ) ) ,
167- ql:: Expression :: String ( "Location" . to_owned ( ) ) ,
164+ body : ql:: Expression :: Equals (
165+ Box :: new ( ql:: Expression :: Var ( "result" . to_owned ( ) ) ) ,
166+ Box :: new ( ql:: Expression :: String ( "Location" . to_owned ( ) ) ) ,
168167 ) ,
169168 } ;
170169 let has_location_info = ql:: Predicate {
@@ -193,7 +192,7 @@ fn create_location_class() -> ql::Class {
193192 r#type: ql:: Type :: Int ,
194193 } ,
195194 ] ,
196- body : ql:: Term :: Expr ( ql :: Expression :: Pred (
195+ body : ql:: Expression :: Pred (
197196 "location" . to_owned ( ) ,
198197 vec ! [
199198 ql:: Expression :: Var ( "this" . to_owned( ) ) ,
@@ -203,13 +202,12 @@ fn create_location_class() -> ql::Class {
203202 ql:: Expression :: Var ( "endLine" . to_owned( ) ) ,
204203 ql:: Expression :: Var ( "endColumn" . to_owned( ) ) ,
205204 ] ,
206- ) ) ,
205+ ) ,
207206 } ;
208207 ql:: Class {
209208 name : "Location" . to_owned ( ) ,
210209 supertypes : vec ! [ ql:: Type :: AtType ( "location" . to_owned( ) ) ] ,
211210 is_abstract : false ,
212- fields : vec ! [ ] ,
213211 characteristic_predicate : None ,
214212 predicates : vec ! [ to_string, has_location_info] ,
215213 }
@@ -250,7 +248,6 @@ fn create_field_class(
250248 get_base_classes ( & class_name, & supertype_map) ,
251249 ]
252250 . concat ( ) ,
253- fields : vec ! [ ] ,
254251 characteristic_predicate : None ,
255252 predicates : vec ! [ ] ,
256253 } ) ;
@@ -288,9 +285,9 @@ fn create_to_string_predicate(text: &str) -> ql::Predicate {
288285 overridden : true ,
289286 return_type : Some ( ql:: Type :: String ) ,
290287 formal_parameters : vec ! [ ] ,
291- body : ql:: Term :: Equals (
292- ql:: Expression :: Var ( "result" . to_owned ( ) ) ,
293- ql:: Expression :: String ( text. to_owned ( ) ) ,
288+ body : ql:: Expression :: Equals (
289+ Box :: new ( ql:: Expression :: Var ( "result" . to_owned ( ) ) ) ,
290+ Box :: new ( ql:: Expression :: String ( text. to_owned ( ) ) ) ,
294291 ) ,
295292 }
296293}
@@ -308,15 +305,15 @@ fn create_get_location_predicate(def_table: &str, arity: usize) -> ql::Predicate
308305 return_type : Some ( ql:: Type :: Normal ( "Location" . to_owned ( ) ) ) ,
309306 formal_parameters : vec ! [ ] ,
310307 // body of the form: foo_bar_def(_, _, ..., result)
311- body : ql:: Term :: Expr ( ql :: Expression :: Pred (
308+ body : ql:: Expression :: Pred (
312309 def_table. to_owned ( ) ,
313310 [
314311 vec ! [ ql:: Expression :: Var ( "this" . to_owned( ) ) ] ,
315312 vec ! [ ql:: Expression :: Var ( "_" . to_owned( ) ) ; arity - 2 ] ,
316313 vec ! [ ql:: Expression :: Var ( "result" . to_owned( ) ) ] ,
317314 ]
318315 . concat ( ) ,
319- ) ) ,
316+ ) ,
320317 }
321318}
322319
@@ -331,14 +328,14 @@ fn create_get_text_predicate(def_table: &str) -> ql::Predicate {
331328 overridden : false ,
332329 return_type : Some ( ql:: Type :: String ) ,
333330 formal_parameters : vec ! [ ] ,
334- body : ql:: Term :: Expr ( ql :: Expression :: Pred (
331+ body : ql:: Expression :: Pred (
335332 def_table. to_owned ( ) ,
336333 vec ! [
337334 ql:: Expression :: Var ( "this" . to_owned( ) ) ,
338335 ql:: Expression :: Var ( "result" . to_owned( ) ) ,
339336 ql:: Expression :: Var ( "_" . to_owned( ) ) ,
340337 ] ,
341- ) ) ,
338+ ) ,
342339 }
343340}
344341
@@ -407,7 +404,7 @@ fn create_field_getters(
407404 parent_name : & str ,
408405 field : & node_types:: Field ,
409406 field_type : & str ,
410- ) -> ( ql:: Predicate , ql:: Term ) {
407+ ) -> ( ql:: Predicate , ql:: Expression ) {
411408 let field_name = match & field. name {
412409 Some ( name) => & name,
413410 None => "child" ,
@@ -423,17 +420,17 @@ fn create_field_getters(
423420 overridden : false ,
424421 return_type : Some ( ql:: Type :: Normal ( dbscheme_name_to_class_name ( field_type) ) ) ,
425422 formal_parameters : vec ! [ ] ,
426- body : ql :: Term :: Expr ( create_get_field_expr_for_column_storage (
423+ body : create_get_field_expr_for_column_storage (
427424 & main_table_name,
428425 * main_table_column_index,
429426 main_table_arity,
430- ) ) ,
427+ ) ,
431428 } ,
432- ql :: Term :: Expr ( create_get_field_expr_for_column_storage (
429+ create_get_field_expr_for_column_storage (
433430 & main_table_name,
434431 * main_table_column_index,
435432 main_table_arity,
436- ) ) ,
433+ ) ,
437434 ) ;
438435 * main_table_column_index += 1 ;
439436 result
@@ -459,32 +456,14 @@ fn create_field_getters(
459456 name: "i" . to_owned( ) ,
460457 r#type: ql:: Type :: Int ,
461458 } ] ,
462- body : ql:: Term :: Expr ( create_get_field_expr_for_table_storage (
463- & field_table_name,
464- "i" ,
465- ) ) ,
459+ body : create_get_field_expr_for_table_storage ( & field_table_name, "i" ) ,
466460 } ,
467- ql:: Term :: Expr ( create_get_field_expr_for_table_storage (
468- & field_table_name,
469- "_" ,
470- ) ) ,
461+ create_get_field_expr_for_table_storage ( & field_table_name, "_" ) ,
471462 )
472463 }
473464 }
474465}
475466
476- /// Returns a QL disjunction of the given (non-empty) vector of terms.
477- fn disjunction ( disjuncts : & [ ql:: Term ] ) -> ql:: Term {
478- match disjuncts. len ( ) {
479- 0 => panic ! ( "unexpected empty disjunction" ) , //ql::Term::Expr(ql::Expression::Pred("none".to_owned(), vec![])),
480- 1 => disjuncts[ 0 ] . clone ( ) ,
481- _ => ql:: Term :: Or (
482- Box :: new ( disjuncts[ 0 ] . clone ( ) ) ,
483- Box :: new ( disjunction ( & disjuncts[ 1 ..] ) ) ,
484- ) ,
485- }
486- }
487-
488467/// Converts the given node types into CodeQL classes wrapping the dbscheme.
489468pub fn convert_nodes ( nodes : & Vec < node_types:: Entry > ) -> Vec < ql:: Class > {
490469 let supertype_map = create_supertype_map ( nodes) ;
@@ -511,7 +490,6 @@ pub fn convert_nodes(nodes: &Vec<node_types::Entry>) -> Vec<ql::Class> {
511490 get_base_classes ( & class_name, & supertype_map) ,
512491 ]
513492 . concat ( ) ,
514- fields : vec ! [ ] ,
515493 characteristic_predicate : None ,
516494 predicates : vec ! [ ] ,
517495 } ) ;
@@ -545,7 +523,6 @@ pub fn convert_nodes(nodes: &Vec<node_types::Entry>) -> Vec<ql::Class> {
545523 get_base_classes ( & main_class_name, & supertype_map) ,
546524 ]
547525 . concat ( ) ,
548- fields : vec ! [ ] ,
549526 characteristic_predicate : None ,
550527 predicates : vec ! [
551528 create_to_string_predicate( & main_class_name) ,
@@ -559,7 +536,7 @@ pub fn convert_nodes(nodes: &Vec<node_types::Entry>) -> Vec<ql::Class> {
559536 . push ( create_get_text_predicate ( & main_table_name) ) ;
560537 } else {
561538 let mut main_table_column_index: usize = 1 ;
562- let mut get_child_exprs: Vec < ql:: Term > = Vec :: new ( ) ;
539+ let mut get_child_exprs: Vec < ql:: Expression > = Vec :: new ( ) ;
563540
564541 // Iterate through the fields, creating:
565542 // - classes to wrap union types if fields need them,
@@ -585,7 +562,7 @@ pub fn convert_nodes(nodes: &Vec<node_types::Entry>) -> Vec<ql::Class> {
585562 overridden : true ,
586563 return_type : Some ( ql:: Type :: Normal ( "Top" . to_owned ( ) ) ) ,
587564 formal_parameters : vec ! [ ] ,
588- body : disjunction ( & get_child_exprs) ,
565+ body : ql :: Expression :: Or ( get_child_exprs) ,
589566 } ) ;
590567 }
591568
0 commit comments