@@ -53,32 +53,10 @@ int refda_reporting_ctrl(refda_runctx_t *runctx, const cace_ari_t *target, cace_
5353 return 0 ;
5454}
5555
56- /** Require any literal to be an EXPR and evaluate the expression.
57- */
58- static int refda_reporting_item_lit (refda_runctx_t * parent , cace_ari_t * rpt_item , const cace_ari_t * rptt_item )
59- {
60- int retval = 0 ;
61- if (CACE_AMM_TYPE_MATCH_POSITIVE != cace_amm_type_match (parent -> agent -> expr_type , rptt_item ))
62- {
63- CACE_LOG_WARNING ("Attempted reporting on a non-EXPR literal" );
64- retval = REFDA_REPORTING_ERR_BAD_TYPE ;
65- }
66- else
67- {
68- CACE_LOG_DEBUG ("Reporting on item literal" );
69- if (refda_eval_target (parent , rpt_item , rptt_item ))
70- {
71- cace_ari_reset (rpt_item );
72- retval = REFDA_REPORTING_ERR_EVAL_FAILED ;
73- }
74- }
75- return retval ;
76- }
77-
7856/** Treat any object reference as a value-producing activity, with the
7957 * produced value reported on directly.
8058 */
81- static int refda_reporting_item_ref (refda_runctx_t * runctx , cace_ari_t * rpt_item , const cace_ari_t * rptt_item )
59+ static int refda_reporting_item_ref (refda_runctx_t * runctx , cace_ari_t * prod_val , const cace_ari_t * rptt_item )
8260{
8361 CACE_LOG_DEBUG ("Reporting on item reference" );
8462 int retval = 0 ;
@@ -107,7 +85,7 @@ static int refda_reporting_item_ref(refda_runctx_t *runctx, cace_ari_t *rpt_item
10785 if (!retval )
10886 {
10987 // include the produced value directly
110- cace_ari_set_copy ( rpt_item , & (prodctx .value ));
88+ cace_ari_set_move ( prod_val , & (prodctx .value ));
11189 }
11290 refda_valprod_ctx_deinit (& prodctx );
11391 break ;
@@ -133,37 +111,59 @@ static int refda_reporting_rptt_val(refda_reporting_ctx_t *rptctx, const cace_ar
133111 for (cace_ari_list_it (rptt_it , tgt_ac -> items ); !cace_ari_list_end_p (rptt_it ); cace_ari_list_next (rptt_it ))
134112 {
135113 const cace_ari_t * rptt_item = cace_ari_list_cref (rptt_it );
136- cace_ari_t rpt_item = CACE_ARI_INIT_UNDEFINED ;
137114
138- int res = 0 ;
115+ // intermediate item from the template
116+ cace_ari_t inter_item = CACE_ARI_INIT_UNDEFINED ;
139117 if (rptt_item -> is_ref )
140118 {
141- // item is a reference to be produced
142- res = refda_reporting_item_ref (rptctx -> runctx , & rpt_item , rptt_item );
119+ // item is a reference to be produced, then possibly evaluated
120+ if (refda_reporting_item_ref (rptctx -> runctx , & inter_item , rptt_item ))
121+ {
122+ // failures in individual items result in undefined value
123+ CACE_LOG_WARNING ("failed to dereference item" );
124+ cace_ari_reset (& inter_item );
125+ }
143126 }
144127 else
145128 {
146- // item is an expression to be evaluated
147- res = refda_reporting_item_lit ( rptctx -> runctx , & rpt_item , rptt_item );
129+ // just use the template item
130+ cace_ari_set_copy ( & inter_item , rptt_item );
148131 }
149-
150- if (res )
132+ if (cace_log_is_enabled_for (LOG_DEBUG ))
151133 {
152- // failures in individual items result in undefined value
153- CACE_LOG_WARNING ("reporting failed for a single item with result %d" , res );
154- cace_ari_reset (& rpt_item );
134+ string_t buf ;
135+ string_init (buf );
136+ cace_ari_text_encode (buf , & inter_item , CACE_ARI_TEXT_ENC_OPTS_DEFAULT );
137+ CACE_LOG_DEBUG ("intermediate item %s" , string_get_cstr (buf ));
138+ string_clear (buf );
155139 }
156- else
140+
141+ cace_ari_t rpt_item = CACE_ARI_INIT_UNDEFINED ;
142+ if (CACE_AMM_TYPE_MATCH_POSITIVE == cace_amm_type_match (rptctx -> runctx -> agent -> expr_type , & inter_item ))
157143 {
158- if (cace_log_is_enabled_for (LOG_DEBUG ))
144+ // item is an expression to be evaluated
145+ CACE_LOG_DEBUG ("Reporting on expression" );
146+ if (refda_eval_target (rptctx -> runctx , & rpt_item , & inter_item ))
159147 {
160- string_t buf ;
161- string_init (buf );
162- cace_ari_text_encode (buf , & rpt_item , CACE_ARI_TEXT_ENC_OPTS_DEFAULT );
163- CACE_LOG_DEBUG ("report item result %s" , string_get_cstr (buf ));
164- string_clear (buf );
148+ CACE_LOG_WARNING ("reporting failed to evaluate expression" );
149+ cace_ari_reset (& rpt_item );
165150 }
166151 }
152+ else
153+ {
154+ // intermediate is directly reported
155+ CACE_LOG_DEBUG ("Reporting on literal" );
156+ cace_ari_set_move (& rpt_item , & inter_item );
157+ }
158+ if (cace_log_is_enabled_for (LOG_DEBUG ))
159+ {
160+ string_t buf ;
161+ string_init (buf );
162+ cace_ari_text_encode (buf , & rpt_item , CACE_ARI_TEXT_ENC_OPTS_DEFAULT );
163+ CACE_LOG_DEBUG ("reporting intermediate %s" , string_get_cstr (buf ));
164+ string_clear (buf );
165+ }
166+ cace_ari_deinit (& inter_item );
167167
168168 cace_ari_list_push_back_move (rptctx -> items , & rpt_item );
169169 }
0 commit comments