@@ -606,10 +606,11 @@ fn create_get_field_expr_for_table_storage<'a>(
606606 )
607607}
608608
609- /// Creates a pair consisting of a predicate to get the given field, and an
610- /// optional expression that will get the same field. When the field can occur
611- /// multiple times, the predicate will take an index argument, while the
612- /// expression will use the "don't care" expression to hold for all occurrences.
609+ /// Creates a list of predicates to get the given field, and an optional
610+ /// expression that will get the same field. When the field can occur multiple
611+ /// times, this includes an indexed getter and a convenience getter that returns
612+ /// any member; the expression uses the "don't care" expression to hold for all
613+ /// occurrences.
613614///
614615/// # Arguments
615616///
@@ -627,7 +628,7 @@ fn create_field_getters<'a>(
627628 main_table_column_index : & mut usize ,
628629 field : & ' a node_types:: Field ,
629630 nodes : & ' a node_types:: NodeTypeMap ,
630- ) -> ( ql:: Predicate < ' a > , Option < ql:: Expression < ' a > > ) {
631+ ) -> ( Vec < ql:: Predicate < ' a > > , Option < ql:: Expression < ' a > > ) {
631632 let return_type = match & field. type_info {
632633 node_types:: FieldTypeInfo :: Single ( t) => {
633634 Some ( ql:: Type :: Facade ( & nodes. get ( t) . unwrap ( ) . ql_class_name ) )
@@ -751,20 +752,40 @@ fn create_field_getters<'a>(
751752 }
752753 }
753754 } ;
754- (
755- ql:: Predicate {
756- qldoc : Some ( qldoc) ,
757- name : & field. getter_name ,
755+ let mut predicates = vec ! [ ql:: Predicate {
756+ qldoc: Some ( qldoc. clone( ) ) ,
757+ name: & field. getter_name,
758+ overridden: false ,
759+ is_private: false ,
760+ is_final: true ,
761+ return_type: return_type. clone( ) ,
762+ formal_parameters,
763+ body,
764+ overlay: None ,
765+ } ] ;
766+
767+ if let Some ( any_getter_name) = & field. any_getter_name {
768+ predicates. push ( ql:: Predicate {
769+ qldoc : Some ( qldoc. clone ( ) ) ,
770+ name : any_getter_name,
758771 overridden : false ,
759772 is_private : false ,
760773 is_final : true ,
761774 return_type,
762- formal_parameters,
763- body,
775+ formal_parameters : vec ! [ ] ,
776+ body : ql:: Expression :: Equals (
777+ Box :: new ( ql:: Expression :: Var ( "result" ) ) ,
778+ Box :: new ( ql:: Expression :: Dot (
779+ Box :: new ( ql:: Expression :: Var ( "this" ) ) ,
780+ & field. getter_name ,
781+ vec ! [ ql:: Expression :: Var ( "_" ) ] ,
782+ ) ) ,
783+ ) ,
764784 overlay : None ,
765- } ,
766- optional_expr,
767- )
785+ } ) ;
786+ }
787+
788+ ( predicates, optional_expr)
768789}
769790
770791fn compute_direct_supertypes (
@@ -902,14 +923,14 @@ pub fn convert_nodes(nodes: &node_types::NodeTypeMap) -> Vec<ql::TopLevel<'_>> {
902923 // - predicates to access the fields,
903924 // - the QL expressions to access the fields that will be part of getAFieldOrChild.
904925 for field in fields {
905- let ( get_pred , get_child_expr) = create_field_getters (
926+ let ( get_preds , get_child_expr) = create_field_getters (
906927 main_table_name,
907928 main_table_arity,
908929 & mut main_table_column_index,
909930 field,
910931 nodes,
911932 ) ;
912- main_class. predicates . push ( get_pred ) ;
933+ main_class. predicates . extend ( get_preds ) ;
913934 if let Some ( get_child_expr) = get_child_expr {
914935 get_child_exprs. push ( get_child_expr)
915936 }
0 commit comments