@@ -184,8 +184,7 @@ struct pt_indent {
184184#define PT_FLAGS_TYPE_USES_OF_GROUPING "-u"
185185#define PT_FLAGS_TYPE_RPC "-x"
186186#define PT_FLAGS_TYPE_NOTIF "-n"
187- #define PT_FLAGS_TYPE_YANG_DATA "--"
188- #define PT_FLAGS_TYPE_STRUCTURE ""
187+ #define PT_FLAGS_TYPE_EXT ""
189188#define PT_FLAGS_TYPE_MOUNT_POINT "mp"
190189#define PT_NODE_NAME_PREFIX_CHOICE "("
191190#define PT_NODE_NAME_PREFIX_CASE ":("
@@ -438,9 +437,7 @@ typedef enum {
438437 * @brief Type of extension to print.
439438 */
440439typedef enum {
441- PT_EXT_STRUCTURE = 0 , /**< Yang Data Structure, RFC 8791 */
442- PT_EXT_AUG_STRUCTURE , /**< Yang Data Structure Augmentation, RFC 8791 */
443- PT_EXT_YANG_DATA , /**< yang-data, RFC 8340 */
440+ PT_EXT_GENERIC ,
444441 PT_EXT_SCHEMA_MOUNT , /**< schema-mount subtree '\<node_name\>/', RFC 8340 */
445442 PT_EXT_SCHEMA_MOUNT_REF /**< schema-mount parent reference subtree '\<node_name\>@' , RFC 8340 */
446443} pt_extension_type ;
@@ -2339,11 +2336,8 @@ pt_pnode_resolve_flags(struct pt_tree_ctx *tc, pt_parent_type ca_ancestor,
23392336 return PT_FLAGS_TYPE_MOUNT_POINT ;
23402337 } else if (pn -> nodetype & LYS_USES ) {
23412338 return PT_FLAGS_TYPE_USES_OF_GROUPING ;
2342- } else if (tc -> plugin_ctx .schema && (tc -> plugin_ctx .schema -> ext == PT_EXT_YANG_DATA )) {
2343- return PT_FLAGS_TYPE_YANG_DATA ;
2344- } else if (tc -> plugin_ctx .schema &&
2345- ((tc -> plugin_ctx .schema -> ext == PT_EXT_STRUCTURE ) || (tc -> plugin_ctx .schema -> ext == PT_EXT_AUG_STRUCTURE ))) {
2346- return PT_FLAGS_TYPE_STRUCTURE ;
2339+ } else if (tc -> plugin_ctx .schema && (tc -> plugin_ctx .schema -> ext == PT_EXT_GENERIC )) {
2340+ return PT_FLAGS_TYPE_EXT ;
23472341 } else if ((pn -> nodetype & LYS_INPUT ) || (ca_ancestor == PT_ANCESTOR_RPC_INPUT )) {
23482342 return PT_FLAGS_TYPE_RPC_INPUT_PARAMS ;
23492343 } else if ((pn -> nodetype & LYS_OUTPUT ) || (ca_ancestor == PT_ANCESTOR_RPC_OUTPUT )) {
@@ -2536,11 +2530,8 @@ pt_cnode_resolve_flags(struct pt_tree_ctx *tc)
25362530
25372531 if (pt_ext_is_present (tc , "mount-point" )) {
25382532 return PT_FLAGS_TYPE_MOUNT_POINT ;
2539- } else if (tc -> plugin_ctx .schema && (tc -> plugin_ctx .schema -> ext == PT_EXT_YANG_DATA )) {
2540- return PT_FLAGS_TYPE_YANG_DATA ;
2541- } else if (tc -> plugin_ctx .schema &&
2542- ((tc -> plugin_ctx .schema -> ext == PT_EXT_STRUCTURE ) || (tc -> plugin_ctx .schema -> ext == PT_EXT_AUG_STRUCTURE ))) {
2543- return PT_FLAGS_TYPE_STRUCTURE ;
2533+ } else if (tc -> plugin_ctx .schema && (tc -> plugin_ctx .schema -> ext == PT_EXT_GENERIC )) {
2534+ return PT_FLAGS_TYPE_EXT ;
25442535 } else if ((cn -> nodetype & LYS_INPUT ) || (cn -> flags & LYS_IS_INPUT )) {
25452536 return PT_FLAGS_TYPE_RPC_INPUT_PARAMS ;
25462537 } else if ((cn -> nodetype & LYS_OUTPUT ) || (cn -> flags & LYS_IS_OUTPUT )) {
@@ -3175,7 +3166,7 @@ pt_ext_iter(const struct pt_tree_ctx *tc, const char *ext_name,
31753166 assert (name );
31763167 }
31773168 }
3178- } while (ext && strcmp (name , ext_name ));
3169+ } while (ext && ext_name && strcmp (name , ext_name ));
31793170
31803171 return ext ;
31813172}
@@ -3847,218 +3838,168 @@ pt_print_groupings(struct pt_tree_ctx *tc)
38473838}
38483839
38493840/**
3850- * @brief Read extension and get storage pointer.
3841+ * @brief Read extension and get schema pointer.
38513842 * @param[in] ext Extension to read.
38523843 * @param[in] compiled Set to 1 if @p ext is from lysc tree.
3853- * @param[in] stmt_op Set to NULL to find data statement or set to one specific statement.
3854- * @return storage_p pointer from lysc_ext_instance or lysp_ext_instance extension.
3844+ * @return pointer to lysp or lysc node.
38553845 */
3856- static void * *
3857- pt_ext_read_storage (void * ext , ly_bool compiled , const enum ly_stmt * stmt_op )
3846+ static void *
3847+ pt_ext_read_storage (void * ext , ly_bool compiled )
38583848{
38593849 LY_ARRAY_COUNT_TYPE i ;
38603850 enum ly_stmt stmt ;
38613851 void * substmts ;
3852+ void * * storage_p ;
3853+ void * node = NULL , * child ;
38623854
38633855 substmts = compiled ? (void * )((struct lysc_ext_instance * )ext )-> substmts :
38643856 (void * )((struct lysp_ext_instance * )ext )-> substmts ;
38653857
38663858 LY_ARRAY_FOR (substmts , i ) {
3867- stmt = compiled ? ((struct lysc_ext_instance * )ext )-> substmts [i ].stmt :
3868- ((struct lysp_ext_instance * )ext )-> substmts [i ].stmt ;
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+ }
38693870
38703871 /* find some data node */
3871- if (!stmt_op ) {
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- break ;
3887- default :
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 ) {
38883890 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 ;
38893897 }
3890- /* find one specific stmt */
3891- } else if ( * stmt_op != stmt ) {
3892- continue ;
3898+ break ;
3899+ default :
3900+ break ;
38933901 }
3894- return compiled ? ((struct lysc_ext_instance * )ext )-> substmts [i ].storage_p :
3895- ((struct lysp_ext_instance * )ext )-> substmts [i ].storage_p ;
38963902 }
38973903
3898- return NULL ;
3904+ return node ;
38993905}
39003906
39013907/**
3902- * @brief Read extension and get storage pointer.
3908+ * @brief Read extension and get pointer to schema .
39033909 * @param[in] ext Extension to read.
3904- * @param[in] compiled Set to 1 if @p ext is from lysc tree.
3905- * @param[in] stmt_op Set to NULL to find data statement or set to one specific statement.
3906- * @param[in] find_parsed Use lysc extension instance to find lysp extension instance
3907- * with the same name and use it.
3910+ * @param[in,out] compiled For input set to 1 if @p ext is compiled instance.
3911+ * For output is set to 1 if returned pointer is from compiled instance.
39083912 * @param[out] ks Section name to fill.
3909- * @return storage_p pointer from lysc_ext_instance or lysp_ext_instance extension .
3913+ * @return pointer to lysp or lysc node .
39103914 */
3911- static void * *
3912- pt_ext_read (void * ext , ly_bool compiled , const enum ly_stmt * stmt_op ,
3913- ly_bool find_parsed , struct pt_keyword_stmt * ks )
3915+ static void *
3916+ pt_ext_read (void * ext , ly_bool * compiled , struct pt_keyword_stmt * ks )
39143917{
39153918 LY_ARRAY_COUNT_TYPE i ;
3919+ const char * name ;
39163920 struct lysc_ext_instance * ext_comp ;
39173921 struct lysp_ext_instance * ext_pars ;
3918- void * * storage ;
3922+ void * schema ;
39193923
3920- if (compiled ) {
3924+ if (* compiled ) {
39213925 ext_comp = ext ;
39223926 ks -> argument = ext_comp -> argument ;
3923- if (!find_parsed ) {
3924- /* search in lysc_ext_instance */
3925- storage = pt_ext_read_storage (ext_comp , 1 , stmt_op );
3926- } else {
3927- if (!ext_comp -> module -> parsed ) {
3928- return NULL ;
3929- }
3930- /* find lysp_ext_instance by lysc_ext_instance */
3931- ext_pars = ext_comp -> module -> parsed -> exts ;
3932- LY_ARRAY_FOR (ext_pars , i ) {
3933- if (!strcmp (ext_pars [i ].argument , ext_comp -> argument )) {
3934- break ;
3935- }
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 ;
39363945 }
3937- assert (ext_pars );
3938- storage = pt_ext_read_storage (ext_pars , 0 , stmt_op );
39393946 }
3947+ assert (ext_pars );
3948+ schema = pt_ext_read_storage (ext_pars , 0 );
39403949 } else {
39413950 ext_pars = ext ;
39423951 ks -> argument = ext_pars -> argument ;
3943- storage = pt_ext_read_storage (ext_pars , 0 , stmt_op );
3952+ name = strchr (ext_pars -> name , ':' ) + 1 ;
3953+ ks -> section_name = name ;
3954+ schema = pt_ext_read_storage (ext_pars , 0 );
3955+ * compiled = 0 ;
39443956 }
39453957
3946- return storage ;
3958+ return schema ;
39473959}
39483960
39493961/**
3950- * @brief Print extension instance .
3962+ * @brief Print top-level extension instances .
39513963 * @param[in] tc Tree context.
3952- * @param[in] ext_name Extension name to print.
3953- * @param[in] ext_type Extension type of @p ext_name.
3954- */
3955- static void
3956- pt_print_ext_instance (struct pt_tree_ctx * tc , const char * ext_name , pt_extension_type ext_type )
3957- {
3958- ly_bool once = 1 ;
3959- LY_ARRAY_COUNT_TYPE i = 0 ;
3960- struct pt_keyword_stmt ks = PT_EMPTY_KEYWORD_STMT ;
3961- struct pt_node node ;
3962- void * * storage ;
3963- void * ext ;
3964-
3965- tc -> plugin_ctx .schema -> compiled = tc -> lysc_tree ;
3966- tc -> plugin_ctx .schema -> ext = ext_type ;
3967- ks .section_name = ext_name ;
3968-
3969- while ((ext = pt_ext_iter (tc , ext_name , 1 , & i ))) {
3970- storage = pt_ext_read (ext , tc -> lysc_tree , NULL , 0 , & ks );
3971- if (!storage ) {
3972- continue ;
3973- }
3974- if (tc -> lysc_tree ) {
3975- tc -> cn = * storage ;
3976- tc -> plugin_ctx .schema -> ctree = tc -> cn ;
3977- ks .has_node = tc -> cn ? 1 : 0 ;
3978- } else {
3979- tc -> pn = * storage ;
3980- tc -> plugin_ctx .schema -> ptree = tc -> pn ;
3981- ks .has_node = tc -> pn ? 1 : 0 ;
3982- }
3983- pt_print_keyword_stmt (& ks , & once , tc -> out );
3984- if (!ks .has_node ) {
3985- /* no subtree to print */
3986- continue ;
3987- }
3988- /* print subtree */
3989- node = pt_modi_first_sibling (PT_EMPTY_PARENT_CACHE , tc );
3990- pt_print_siblings (& node , PT_INIT_WRAPPER_BODY , PT_EMPTY_PARENT_CACHE , tc );
3991- }
3992- }
3993-
3994- /**
3995- * @brief Print yang-data section.
3996- * @param[in,out] tc Tree context.
39973964 */
39983965static void
3999- pt_print_yang_data (struct pt_tree_ctx tc )
3966+ pt_print_extensions (struct pt_tree_ctx tc )
40003967{
4001- struct pt_ext_tree_schema schema = {0 };
4002-
4003- tc .section = PT_SECT_PLUG_DATA ;
4004- tc .plugin_ctx .schema = & schema ;
4005-
4006- pt_print_ext_instance (& tc , "yang-data" , PT_EXT_YANG_DATA );
4007- }
4008-
4009- /**
4010- * @brief Print structure section.
4011- * @param[in,out] tc Tree context.
4012- */
4013- static void
4014- pt_print_structure (struct pt_tree_ctx tc )
4015- {
4016- struct pt_ext_tree_schema schema = {0 };
4017-
4018- tc .section = PT_SECT_PLUG_DATA ;
4019- tc .plugin_ctx .schema = & schema ;
4020-
4021- pt_print_ext_instance (& tc , "structure" , PT_EXT_STRUCTURE );
4022- }
4023-
4024- /**
4025- * @brief Print augment structure section.
4026- * @param[in,out] tc Tree context.
4027- */
4028- static void
4029- pt_print_augment_structure (struct pt_tree_ctx tc )
4030- {
4031- struct pt_ext_tree_schema schema = {0 };
40323968 ly_bool once = 1 ;
40333969 LY_ARRAY_COUNT_TYPE i = 0 ;
40343970 struct pt_keyword_stmt ks = PT_EMPTY_KEYWORD_STMT ;
40353971 struct pt_node node ;
3972+ void * schema ;
40363973 void * ext ;
4037- enum ly_stmt stmt = LY_STMT_AUGMENT ;
4038- void * * storage ;
3974+ struct pt_ext_tree_schema ext_schema ;
40393975 ly_bool origin_lysc_tree = tc .lysc_tree ;
40403976
40413977 tc .section = PT_SECT_PLUG_DATA ;
4042- tc .plugin_ctx .schema = & schema ;
4043- tc .plugin_ctx .schema -> ext = PT_EXT_AUG_STRUCTURE ;
4044- ks .section_name = "augment-structure" ;
3978+ tc .plugin_ctx .schema = & ext_schema ;
3979+ tc .plugin_ctx .schema -> ext = PT_EXT_GENERIC ;
40453980
4046- while ((ext = pt_ext_iter (& tc , ks . section_name , 1 , & i ))) {
3981+ while ((ext = pt_ext_iter (& tc , NULL , 1 , & i ))) {
40473982 tc .lysc_tree = origin_lysc_tree ;
40483983
4049- storage = pt_ext_read (ext , tc .lysc_tree , & stmt , 1 , & ks );
4050- if (!storage ) {
3984+ schema = pt_ext_read (ext , & tc .lysc_tree , & ks );
3985+ if (!strcmp (ks .section_name , "mount-point" ) ||
3986+ !strcmp (ks .section_name , "annotation" )) {
3987+ /* extension ignored */
40513988 continue ;
40523989 }
4053-
4054- tc .lysc_tree = 0 ;
4055-
4056- tc .plugin_ctx .schema -> compiled = 0 ;
4057- tc .pn = (* ((struct lysp_node_augment * * )storage ))-> child ;
4058- tc .plugin_ctx .schema -> ptree = tc .pn ;
4059- ks .has_node = tc .pn ? 1 : 0 ;
3990+ if (tc .lysc_tree ) {
3991+ tc .cn = schema ;
3992+ tc .plugin_ctx .schema -> ctree = tc .cn ;
3993+ tc .plugin_ctx .schema -> compiled = 1 ;
3994+ ks .has_node = tc .cn ? 1 : 0 ;
3995+ } else {
3996+ tc .pn = schema ;
3997+ tc .plugin_ctx .schema -> ptree = tc .pn ;
3998+ tc .plugin_ctx .schema -> compiled = 0 ;
3999+ ks .has_node = tc .pn ? 1 : 0 ;
4000+ }
40604001 pt_print_keyword_stmt (& ks , & once , tc .out );
4061- if (!tc . pn ) {
4002+ if (!ks . has_node ) {
40624003 /* no subtree to print */
40634004 continue ;
40644005 }
@@ -4068,8 +4009,6 @@ pt_print_augment_structure(struct pt_tree_ctx tc)
40684009
40694010 tc .lysc_tree = origin_lysc_tree ;
40704011 }
4071-
4072- return ;
40734012}
40744013
40754014/**
@@ -4085,9 +4024,7 @@ pt_print_sections(struct pt_tree_ctx *tc)
40854024 pt_print_rpcs (tc );
40864025 pt_print_notifications (tc );
40874026 pt_print_groupings (tc );
4088- pt_print_yang_data (* tc );
4089- pt_print_structure (* tc );
4090- pt_print_augment_structure (* tc );
4027+ pt_print_extensions (* tc );
40914028 ly_print_ (tc -> out , "\n" );
40924029}
40934030
0 commit comments