@@ -46,31 +46,8 @@ fn create_ast_node_class<'a>() -> ql::Class<'a> {
4646 create_none_predicate ( "getLocation" , false , Some ( ql:: Type :: Normal ( "Location" ) ) ) ;
4747 let get_a_field_or_child =
4848 create_none_predicate ( "getAFieldOrChild" , false , Some ( ql:: Type :: Normal ( "AstNode" ) ) ) ;
49- let get_parent = ql:: Predicate {
50- name : "getParent" ,
51- overridden : false ,
52- return_type : Some ( ql:: Type :: Normal ( "AstNode" ) ) ,
53- formal_parameters : vec ! [ ] ,
54- body : ql:: Expression :: Equals (
55- Box :: new ( ql:: Expression :: Var ( "result" ) ) ,
56- Box :: new ( ql:: Expression :: Aggregate (
57- "unique" ,
58- vec ! [ ql:: FormalParameter {
59- name: "parent" ,
60- param_type: ql:: Type :: Normal ( "AstNode" ) ,
61- } ] ,
62- Box :: new ( ql:: Expression :: Equals (
63- Box :: new ( ql:: Expression :: Var ( "this" ) ) ,
64- Box :: new ( ql:: Expression :: Dot (
65- Box :: new ( ql:: Expression :: Var ( "parent" ) ) ,
66- "getAFieldOrChild" ,
67- vec ! [ ] ,
68- ) ) ,
69- ) ) ,
70- Box :: new ( ql:: Expression :: Var ( "parent" ) ) ,
71- ) ) ,
72- ) ,
73- } ;
49+ let get_parent = create_none_predicate ( "getParent" , false , Some ( ql:: Type :: Normal ( "AstNode" ) ) ) ;
50+ let get_parent_index = create_none_predicate ( "getParentIndex" , false , Some ( ql:: Type :: Int ) ) ;
7451 let describe_ql_class = ql:: Predicate {
7552 name : "describeQlClass" ,
7653 overridden : false ,
@@ -90,46 +67,41 @@ fn create_ast_node_class<'a>() -> ql::Class<'a> {
9067 to_string,
9168 get_location,
9269 get_parent,
70+ get_parent_index,
9371 get_a_field_or_child,
9472 describe_ql_class,
9573 ] ,
9674 }
9775}
9876
9977fn create_token_class < ' a > ( ) -> ql:: Class < ' a > {
78+ let get_parent = ql:: Predicate {
79+ name : "getParent" ,
80+ overridden : true ,
81+ return_type : Some ( ql:: Type :: Normal ( "AstNode" ) ) ,
82+ formal_parameters : vec ! [ ] ,
83+ body : create_get_field_expr_for_column_storage ( "tokeninfo" , 0 , 8 ) ,
84+ } ;
85+ let get_parent_index = ql:: Predicate {
86+ name : "getParentIndex" ,
87+ overridden : true ,
88+ return_type : Some ( ql:: Type :: Int ) ,
89+ formal_parameters : vec ! [ ] ,
90+ body : create_get_field_expr_for_column_storage ( "tokeninfo" , 1 , 8 ) ,
91+ } ;
10092 let get_value = ql:: Predicate {
10193 name : "getValue" ,
10294 overridden : false ,
10395 return_type : Some ( ql:: Type :: String ) ,
10496 formal_parameters : vec ! [ ] ,
105- body : ql:: Expression :: Pred (
106- "tokeninfo" ,
107- vec ! [
108- ql:: Expression :: Var ( "this" ) ,
109- ql:: Expression :: Var ( "_" ) ,
110- ql:: Expression :: Var ( "_" ) ,
111- ql:: Expression :: Var ( "_" ) ,
112- ql:: Expression :: Var ( "result" ) ,
113- ql:: Expression :: Var ( "_" ) ,
114- ] ,
115- ) ,
97+ body : create_get_field_expr_for_column_storage ( "tokeninfo" , 5 , 8 ) ,
11698 } ;
11799 let get_location = ql:: Predicate {
118100 name : "getLocation" ,
119101 overridden : true ,
120102 return_type : Some ( ql:: Type :: Normal ( "Location" ) ) ,
121103 formal_parameters : vec ! [ ] ,
122- body : ql:: Expression :: Pred (
123- "tokeninfo" ,
124- vec ! [
125- ql:: Expression :: Var ( "this" ) ,
126- ql:: Expression :: Var ( "_" ) ,
127- ql:: Expression :: Var ( "_" ) ,
128- ql:: Expression :: Var ( "_" ) ,
129- ql:: Expression :: Var ( "_" ) ,
130- ql:: Expression :: Var ( "result" ) ,
131- ] ,
132- ) ,
104+ body : create_get_field_expr_for_column_storage ( "tokeninfo" , 6 , 8 ) ,
133105 } ;
134106 let to_string = ql:: Predicate {
135107 name : "toString" ,
@@ -149,6 +121,8 @@ fn create_token_class<'a>() -> ql::Class<'a> {
149121 . collect ( ) ,
150122 characteristic_predicate : None ,
151123 predicates : vec ! [
124+ get_parent,
125+ get_parent_index,
152126 get_value,
153127 get_location,
154128 to_string,
@@ -262,7 +236,7 @@ fn create_get_field_expr_for_column_storage<'a>(
262236 column_index : usize ,
263237 arity : usize ,
264238) -> ql:: Expression < ' a > {
265- let num_underscores_before = column_index - 1 ;
239+ let num_underscores_before = column_index;
266240 let num_underscores_after = arity - 2 - num_underscores_before;
267241 ql:: Expression :: Pred (
268242 table_name,
@@ -436,10 +410,12 @@ pub fn convert_nodes<'a>(nodes: &'a node_types::NodeTypeMap) -> Vec<ql::TopLevel
436410 // Count how many columns there will be in the main table.
437411 // There will be:
438412 // - one for the id
413+ // - one for the parent
414+ // - one for the parent index
439415 // - one for the location
440416 // - one for each field that's stored as a column
441417 // - if there are no fields, one for the text column.
442- let main_table_arity = 2 + if fields. is_empty ( ) {
418+ let main_table_arity = 4 + if fields. is_empty ( ) {
443419 1
444420 } else {
445421 fields
@@ -470,7 +446,7 @@ pub fn convert_nodes<'a>(nodes: &'a node_types::NodeTypeMap) -> Vec<ql::TopLevel
470446 . predicates
471447 . push ( create_get_text_predicate ( & main_table_name) ) ;
472448 } else {
473- let mut main_table_column_index: usize = 1 ;
449+ let mut main_table_column_index: usize = 2 ;
474450 let mut get_child_exprs: Vec < ql:: Expression > = Vec :: new ( ) ;
475451
476452 // Iterate through the fields, creating:
@@ -489,6 +465,30 @@ pub fn convert_nodes<'a>(nodes: &'a node_types::NodeTypeMap) -> Vec<ql::TopLevel
489465 get_child_exprs. push ( get_child_expr) ;
490466 }
491467
468+ main_class. predicates . push ( ql:: Predicate {
469+ name : "getParent" ,
470+ overridden : true ,
471+ return_type : Some ( ql:: Type :: Normal ( "AstNode" ) ) ,
472+ formal_parameters : vec ! [ ] ,
473+ body : create_get_field_expr_for_column_storage (
474+ & main_table_name,
475+ 0 ,
476+ main_table_arity,
477+ ) ,
478+ } ) ;
479+
480+ main_class. predicates . push ( ql:: Predicate {
481+ name : "getParentIndex" ,
482+ overridden : true ,
483+ return_type : Some ( ql:: Type :: Int ) ,
484+ formal_parameters : vec ! [ ] ,
485+ body : create_get_field_expr_for_column_storage (
486+ & main_table_name,
487+ 1 ,
488+ main_table_arity,
489+ ) ,
490+ } ) ;
491+
492492 main_class. predicates . push ( ql:: Predicate {
493493 name : "getAFieldOrChild" ,
494494 overridden : true ,
0 commit comments