@@ -3301,6 +3301,27 @@ warn_is_equal_type(struct lysc_type *type1, struct lysc_type *type2)
33013301 return 0 ;
33023302}
33033303
3304+ /**
3305+ * @brief Print warning with information about the XPath subexpression that caused previous warning.
3306+ *
3307+ * @param[in] ctx Context for logging.
3308+ * @param[in] tok_pos Index of the subexpression in the whole expression.
3309+ * @param[in] subexpr Subexpression start.
3310+ * @param[in] subexpr_len Length of @p subexpr to print.
3311+ * @param[in] cur_scnode Expression context node.
3312+ */
3313+ static void
3314+ warn_subexpr_log (const struct ly_ctx * ctx , uint16_t tok_pos , const char * subexpr , int subexpr_len ,
3315+ const struct lysc_node * cur_scnode )
3316+ {
3317+ char * path ;
3318+
3319+ path = lysc_path (cur_scnode , LYSC_PATH_LOG , NULL , 0 );
3320+ LOGWRN (ctx , "Previous warning generated by XPath subexpression[%" PRIu16 "] \"%.*s\" with context node \"%s\"." ,
3321+ tok_pos , subexpr_len , subexpr , path );
3322+ free (path );
3323+ }
3324+
33043325/**
33053326 * @brief Check both operands of comparison operators.
33063327 *
@@ -3312,7 +3333,8 @@ warn_is_equal_type(struct lysc_type *type1, struct lysc_type *type2)
33123333 * @param[in] tok_pos Token position.
33133334 */
33143335static void
3315- warn_operands (struct ly_ctx * ctx , struct lyxp_set * set1 , struct lyxp_set * set2 , ly_bool numbers_only , const char * expr , uint16_t tok_pos )
3336+ warn_operands (struct ly_ctx * ctx , struct lyxp_set * set1 , struct lyxp_set * set2 , ly_bool numbers_only , const char * expr ,
3337+ uint16_t tok_pos )
33163338{
33173339 struct lysc_node_leaf * node1 , * node2 ;
33183340 ly_bool leaves = 1 , warning = 0 ;
@@ -3358,7 +3380,7 @@ warn_operands(struct ly_ctx *ctx, struct lyxp_set *set1, struct lyxp_set *set2,
33583380 }
33593381
33603382 if (warning ) {
3361- LOGWRN (ctx , "Previous warning generated by XPath subexpression[%u] \"%.20s\"." , tok_pos , expr + tok_pos );
3383+ warn_subexpr_log (ctx , tok_pos , expr + tok_pos , 20 , set1 -> cur_scnode );
33623384 }
33633385}
33643386
@@ -3398,9 +3420,9 @@ warn_equality_value(const struct lyxp_expr *exp, struct lyxp_set *set, uint16_t
33983420 if ((((struct lysc_node_leaf * )scnode )-> type -> basetype == LY_TYPE_IDENT ) && !strchr (value , ':' )) {
33993421 LOGWRN (set -> ctx , "Identityref \"%s\" comparison with identity \"%s\" without prefix, consider adding"
34003422 " a prefix or best using \"derived-from(-or-self)()\" functions." , scnode -> name , value );
3401- LOGWRN (set -> ctx , "Previous warning generated by XPath subexpression[%u] \"%.*s\"." , exp -> tok_pos [equal_exp ],
3423+ warn_subexpr_log (set -> ctx , exp -> tok_pos [ equal_exp ], exp -> expr + exp -> tok_pos [equal_exp ],
34023424 (exp -> tok_pos [last_equal_exp ] - exp -> tok_pos [equal_exp ]) + exp -> tok_len [last_equal_exp ],
3403- exp -> expr + exp -> tok_pos [ equal_exp ] );
3425+ set -> cur_scnode );
34043426 }
34053427
34063428 type = ((struct lysc_node_leaf * )scnode )-> type ;
@@ -3418,9 +3440,9 @@ warn_equality_value(const struct lyxp_expr *exp, struct lyxp_set *set, uint16_t
34183440 LOGWRN (set -> ctx , "Invalid value \"%s\" which does not fit the type." , value );
34193441 }
34203442 if (rc != LY_SUCCESS ) {
3421- LOGWRN (set -> ctx , "Previous warning generated by XPath subexpression[%u] \"%.*s\"." , exp -> tok_pos [equal_exp ],
3443+ warn_subexpr_log (set -> ctx , exp -> tok_pos [ equal_exp ], exp -> expr + exp -> tok_pos [equal_exp ],
34223444 (exp -> tok_pos [last_equal_exp ] - exp -> tok_pos [equal_exp ]) + exp -> tok_len [last_equal_exp ],
3423- exp -> expr + exp -> tok_pos [ equal_exp ] );
3445+ set -> cur_scnode );
34243446 } else {
34253447 type -> plugin -> free (set -> ctx , & storage );
34263448 }
0 commit comments