@@ -3840,64 +3840,24 @@ pt_print_groupings(struct pt_tree_ctx *tc)
38403840/**
38413841 * @brief Read extension and get schema pointer.
38423842 * @param[in] ext Extension to read.
3843- * @param[in] compiled Set to 1 if @p ext is from lysc tree .
3844- * @return pointer to lysp or lysc node.
3843+ * @param[in] stmt_mask First stmt which match will be returned .
3844+ * @return pointer to lysp node.
38453845 */
38463846static void *
3847- pt_ext_read_storage ( void * ext , ly_bool compiled )
3847+ pt_ext_parsed_read_storage ( struct lysp_ext_instance * ext , int stmt_mask )
38483848{
38493849 LY_ARRAY_COUNT_TYPE i ;
38503850 enum ly_stmt stmt ;
3851- void * substmts ;
3852- void * * storage_p ;
3853- void * node = NULL , * child ;
3851+ void * substmts , * * storage_p , * node = NULL ;
38543852
3855- substmts = compiled ? (void * )((struct lysc_ext_instance * )ext )-> substmts :
3856- (void * )((struct lysp_ext_instance * )ext )-> substmts ;
3853+ substmts = (void * )((struct lysp_ext_instance * )ext )-> substmts ;
38573854
38583855 LY_ARRAY_FOR (substmts , i ) {
3859- if (compiled ) {
3860- stmt = ((struct lysc_ext_instance * )ext )-> substmts [i ].stmt ;
3861- storage_p = ((struct lysc_ext_instance * )ext )-> substmts [i ].storage_p ;
3862- } else {
3863- stmt = ((struct lysp_ext_instance * )ext )-> substmts [i ].stmt ;
3864- storage_p = ((struct lysp_ext_instance * )ext )-> substmts [i ].storage_p ;
3865- }
3866-
3867- if (!storage_p ) {
3868- continue ;
3869- }
3856+ stmt = ((struct lysp_ext_instance * )ext )-> substmts [i ].stmt ;
3857+ storage_p = ((struct lysp_ext_instance * )ext )-> substmts [i ].storage_p ;
38703858
3871- /* find some data node */
3872- switch (stmt ) {
3873- case LY_STMT_NOTIFICATION :
3874- case LY_STMT_INPUT :
3875- case LY_STMT_OUTPUT :
3876- case LY_STMT_ACTION :
3877- case LY_STMT_RPC :
3878- case LY_STMT_ANYDATA :
3879- case LY_STMT_ANYXML :
3880- case LY_STMT_CASE :
3881- case LY_STMT_CHOICE :
3882- case LY_STMT_CONTAINER :
3883- case LY_STMT_LEAF :
3884- case LY_STMT_LEAF_LIST :
3885- case LY_STMT_LIST :
3886- node = !node && * storage_p ? * storage_p : node ;
3887- break ;
3888- case LY_STMT_AUGMENT :
3889- if (compiled ) {
3890- continue ;
3891- } else if (!* storage_p ) {
3892- continue ;
3893- } else {
3894- /* for augment-structure */
3895- child = (* ((struct lysp_node_augment * * )storage_p ))-> child ;
3896- node = child ? child : node ;
3897- }
3898- break ;
3899- default :
3900- break ;
3859+ if (storage_p && (stmt & stmt_mask )) {
3860+ return * storage_p ;
39013861 }
39023862 }
39033863
@@ -3915,44 +3875,45 @@ pt_ext_read_storage(void *ext, ly_bool compiled)
39153875static void *
39163876pt_ext_read (void * ext , ly_bool * compiled , struct pt_keyword_stmt * ks )
39173877{
3918- LY_ARRAY_COUNT_TYPE i ;
3919- const char * name ;
39203878 struct lysc_ext_instance * ext_comp ;
39213879 struct lysp_ext_instance * ext_pars ;
3880+ const char * name ;
39223881 void * schema ;
39233882
3924- if (* compiled ) {
3925- ext_comp = ext ;
3926- ks -> argument = ext_comp -> argument ;
3927- ks -> section_name = ext_comp -> def -> name ;
3928- /* search in lysc_ext_instance */
3929- schema = pt_ext_read_storage (ext_comp , 1 );
3930- * compiled = 1 ;
3931- if (schema ) {
3932- return schema ;
3933- }
3934- /* search in lysp_ext_instance */
3935- * compiled = 0 ;
3936- if (!ext_comp -> module -> parsed ) {
3937- return NULL ;
3938- }
3939- /* find lysp_ext_instance by lysc_ext_instance */
3940- ext_pars = ext_comp -> module -> parsed -> exts ;
3941- LY_ARRAY_FOR (ext_pars , i ) {
3942- name = strchr (ext_pars -> name , ':' ) + 1 ;
3943- if (!strcmp (name , ext_comp -> def -> name ) && !strcmp (ext_pars [i ].argument , ext_comp -> argument )) {
3944- break ;
3945- }
3946- }
3947- assert (ext_pars );
3948- schema = pt_ext_read_storage (ext_pars , 0 );
3949- } else {
3883+ if (!* compiled ) {
39503884 ext_pars = ext ;
39513885 ks -> argument = ext_pars -> argument ;
39523886 name = strchr (ext_pars -> name , ':' ) + 1 ;
39533887 ks -> section_name = name ;
3954- schema = pt_ext_read_storage (ext_pars , 0 );
3888+ if (!strcmp (ks -> section_name , "augment-structure" )) {
3889+ schema = pt_ext_parsed_read_storage (ext_pars , LY_STMT_AUGMENT );
3890+ schema = ((struct lysp_node_augment * )schema )-> child ;
3891+ } else {
3892+ schema = pt_ext_parsed_read_storage (ext_pars , LY_STMT_DATA_NODE_MASK );
3893+ }
39553894 * compiled = 0 ;
3895+ return schema ;
3896+ }
3897+
3898+ /* for compiled extension instance */
3899+ ext_comp = ext ;
3900+ ks -> argument = ext_comp -> argument ;
3901+ ks -> section_name = ext_comp -> def -> name ;
3902+
3903+ /* search in lysc_ext_instance */
3904+ lyplg_ext_get_storage (ext , LY_STMT_DATA_NODE_MASK , sizeof schema , (const void * * )& schema );
3905+ * compiled = 1 ;
3906+ if (schema ) {
3907+ return schema ;
3908+ }
3909+
3910+ /* no data nodes lysc_ext_instance, so search in lysp_ext_instance */
3911+ * compiled = 0 ;
3912+ if (!strcmp (ks -> section_name , "augment-structure" )) {
3913+ lyplg_ext_parsed_get_storage (ext_comp , LY_STMT_AUGMENT , sizeof schema , (const void * * )& schema );
3914+ schema = ((struct lysp_node_augment * )schema )-> child ;
3915+ } else {
3916+ lyplg_ext_parsed_get_storage (ext_comp , LY_STMT_DATA_NODE_MASK , sizeof schema , (const void * * )& schema );
39563917 }
39573918
39583919 return schema ;
0 commit comments