diff --git a/doxy/sys_defs.html b/doxy/sys_defs.html
index 8ee62e2d..f1c6f1e2 100644
--- a/doxy/sys_defs.html
+++ b/doxy/sys_defs.html
@@ -2955,6 +2955,12 @@
Symbol:
diff --git a/doxy/sys_symbols.html b/doxy/sys_symbols.html
index b83f5395..f4c3e661 100644
--- a/doxy/sys_symbols.html
+++ b/doxy/sys_symbols.html
@@ -299,6 +299,7 @@
CHANNEL | SYMBOL | |
REQUEST_HANDLER | PROCESS | |
RESPONSE_HANDLER | PROCESS | |
+
RESPONSE_HANDLER_PARAMETERS | SYMBOL | |
backnforth | INTERACTION | |
RECOGNIZER | RECEPTOR-ADDRESS | |
RECOGNIZEE | RECEPTOR-ADDRESS | |
diff --git a/spec/protocol_spec.h b/spec/protocol_spec.h
index 31522f16..f3b08cfa 100644
--- a/spec/protocol_spec.h
+++ b/spec/protocol_spec.h
@@ -6,8 +6,8 @@
#include "../src/protocol.h"
void testProtocolRequesting() {
- spec_is_str_equal(t2s(_sem_get_def(G_sem,REQUESTING)),"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:REQUESTING)) (PROTOCOL_SEMANTICS (ROLE:REQUESTER) (ROLE:RESPONDER) (GOAL:RESPONSE_HANDLER) (GOAL:REQUEST_HANDLER) (USAGE:CHANNEL) (USAGE:REQUEST_TYPE) (USAGE:RESPONSE_TYPE)) (backnforth (INITIATE (ROLE:REQUESTER) (DESTINATION (ROLE:RESPONDER)) (ACTION:send_request)) (EXPECT (ROLE:RESPONDER) (SOURCE (ROLE:REQUESTER)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SLOT (USAGE:REQUEST_TYPE) (SLOT_IS_VALUE_OF:SEMTREX_SYMBOL)))) (ACTION:send_response))))");
- spec_is_str_equal(t2s(_sem_get_def(G_sem,send_request)),"(PROCESS_DEFINITION (PROCESS_NAME (ENGLISH_LABEL:send_request)) (PROCESS_INTENTION:send request) (SLOT (GOAL:RESPONSE_HANDLER) (SLOT_CHILDREN (process:REQUEST (SLOT (ROLE:RESPONDER) (SLOT_IS_VALUE_OF:TO_ADDRESS)) (SLOT (USAGE:CHANNEL) (SLOT_IS_VALUE_OF:ASPECT_IDENT)) (CARRIER:backnforth) (SLOT (USAGE:REQUEST_TYPE)) (CARRIER:backnforth)))) (PROCESS_SIGNATURE (OUTPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:response)) (SIGNATURE_ANY)) (TEMPLATE_SIGNATURE (EXPECTED_SLOT (ROLE:RESPONDER) (SLOT_IS_VALUE_OF:TO_ADDRESS)) (EXPECTED_SLOT (USAGE:CHANNEL) (SLOT_IS_VALUE_OF:ASPECT_IDENT)) (EXPECTED_SLOT (USAGE:REQUEST_TYPE)) (EXPECTED_SLOT (GOAL:RESPONSE_HANDLER)))))");
+ spec_is_str_equal(t2s(_sem_get_def(G_sem,REQUESTING)),"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:REQUESTING)) (PROTOCOL_SEMANTICS (ROLE:REQUESTER) (ROLE:RESPONDER) (GOAL:RESPONSE_HANDLER) (GOAL:REQUEST_HANDLER) (USAGE:CHANNEL) (USAGE:REQUEST_TYPE) (USAGE:RESPONSE_TYPE) (USAGE:RESPONSE_HANDLER_PARAMETERS)) (PROTOCOL_DEFAULTS (SEMANTIC_LINK (USAGE:RESPONSE_HANDLER_PARAMETERS) (REPLACEMENT_VALUE (NULL_SYMBOL)))) (backnforth (INITIATE (ROLE:REQUESTER) (DESTINATION (ROLE:RESPONDER)) (ACTION:send_request)) (EXPECT (ROLE:RESPONDER) (SOURCE (ROLE:REQUESTER)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SLOT (USAGE:REQUEST_TYPE) (SLOT_IS_VALUE_OF:SEMTREX_SYMBOL)))) (ACTION:send_response))))");
+ spec_is_str_equal(t2s(_sem_get_def(G_sem,send_request)),"(PROCESS_DEFINITION (PROCESS_NAME (ENGLISH_LABEL:send_request)) (PROCESS_INTENTION:send request) (SLOT (GOAL:RESPONSE_HANDLER) (SLOT_CHILDREN (SLOT (USAGE:RESPONSE_HANDLER_PARAMETERS)) (process:REQUEST (SLOT (ROLE:RESPONDER) (SLOT_IS_VALUE_OF:TO_ADDRESS)) (SLOT (USAGE:CHANNEL) (SLOT_IS_VALUE_OF:ASPECT_IDENT)) (CARRIER:backnforth) (SLOT (USAGE:REQUEST_TYPE)) (CARRIER:backnforth)))) (PROCESS_SIGNATURE (OUTPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:response)) (SIGNATURE_ANY)) (TEMPLATE_SIGNATURE (EXPECTED_SLOT (USAGE:RESPONSE_HANDLER_PARAMETERS)) (EXPECTED_SLOT (ROLE:RESPONDER) (SLOT_IS_VALUE_OF:TO_ADDRESS)) (EXPECTED_SLOT (USAGE:CHANNEL) (SLOT_IS_VALUE_OF:ASPECT_IDENT)) (EXPECTED_SLOT (USAGE:REQUEST_TYPE)) (EXPECTED_SLOT (GOAL:RESPONSE_HANDLER)))))");
spec_is_str_equal(t2s(_sem_get_def(G_sem,send_response)),"(PROCESS_DEFINITION (PROCESS_NAME (ENGLISH_LABEL:send_response)) (PROCESS_INTENTION:send response) (process:RESPOND (SIGNAL_REF:/2/1/4) (SLOT (GOAL:REQUEST_HANDLER))) (PROCESS_SIGNATURE (OUTPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:response id)) (SIGNATURE_SYMBOL:SIGNAL_UUID)) (TEMPLATE_SIGNATURE (EXPECTED_SLOT (GOAL:REQUEST_HANDLER)))))");
@@ -25,7 +25,7 @@ void testProtocolRecognize() {
T *sem_map = _t_new_root(SEMANTIC_MAP);
T *t = _o_unwrap(G_sem,recog,sem_map);
// and also check how it gets unwrapped because it's defined in terms of REQUESTING
- spec_is_str_equal(t2s(t),"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:RECOGNIZE)) (PROTOCOL_SEMANTICS (ROLE:RECOGNIZER) (GOAL:RECOGNITION)) (backnforth (INITIATE (ROLE:RECOGNIZER) (DESTINATION (ROLE:RECOGNIZEE)) (ACTION:send_request)) (EXPECT (ROLE:RECOGNIZEE) (SOURCE (ROLE:RECOGNIZER)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:are_you))) (ACTION:send_response))))");
+ spec_is_str_equal(t2s(t),"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:RECOGNIZE)) (PROTOCOL_SEMANTICS (ROLE:RECOGNIZER) (GOAL:RECOGNITION) (USAGE:RESPONSE_HANDLER_PARAMETERS)) (PROTOCOL_DEFAULTS (SEMANTIC_LINK (USAGE:RESPONSE_HANDLER_PARAMETERS) (REPLACEMENT_VALUE (NULL_SYMBOL)))) (backnforth (INITIATE (ROLE:RECOGNIZER) (DESTINATION (ROLE:RECOGNIZEE)) (ACTION:send_request)) (EXPECT (ROLE:RECOGNIZEE) (SOURCE (ROLE:RECOGNIZER)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:are_you))) (ACTION:send_response))))");
// the unwrapping should build up a semantic map
spec_is_str_equal(t2s(sem_map),"(SEMANTIC_MAP (SEMANTIC_LINK (ROLE:REQUESTER) (REPLACEMENT_VALUE (ROLE:RECOGNIZER))) (SEMANTIC_LINK (ROLE:RESPONDER) (REPLACEMENT_VALUE (ROLE:RECOGNIZEE))) (SEMANTIC_LINK (GOAL:RESPONSE_HANDLER) (REPLACEMENT_VALUE (GOAL:RECOGNITION))) (SEMANTIC_LINK (USAGE:REQUEST_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:are_you))) (SEMANTIC_LINK (USAGE:RESPONSE_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:i_am))) (SEMANTIC_LINK (USAGE:CHANNEL) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:DEFAULT_ASPECT))) (SEMANTIC_LINK (GOAL:REQUEST_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:fill_i_am))))");
@@ -110,6 +110,7 @@ void testProtocolRecognize() {
_p_reduceq(self->q);
debug_disable(D_TREE);
debug_disable(D_PROTOCOL);
+ debug_disable(D_STEP);
debug_disable(D_REDUCE+D_REDUCEV);
spec_is_str_equal(_td(self,self->pending_signals),"(PENDING_SIGNALS (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:backnforth) (IN_RESPONSE_TO_UUID)) (BODY:{(i_am (RECEPTOR_LABEL (ENGLISH_LABEL:super cept)) (RECEPTOR_IDENTIFIER:314159))}))))");
diff --git a/src/base_defs b/src/base_defs
index 22d2f1e5..1c0f6622 100644
--- a/src/base_defs
+++ b/src/base_defs
@@ -530,9 +530,11 @@ Symbol: RESPONSE_TYPE,SYMBOL;
Symbol: CHANNEL,SYMBOL;
Symbol: REQUEST_HANDLER,PROCESS;
Symbol: RESPONSE_HANDLER,PROCESS;
+Symbol: RESPONSE_HANDLER_PARAMETERS,SYMBOL;
Symbol: backnforth,INTERACTION;
-Data: req_code,(SLOT (GOAL:RESPONSE_HANDLER) (SLOT_CHILDREN (REQUEST (SLOT (ROLE:RESPONDER) (SLOT_IS_VALUE_OF:TO_ADDRESS)) (SLOT (USAGE:CHANNEL) (SLOT_IS_VALUE_OF:ASPECT_IDENT)) (CARRIER:backnforth) (SLOT (USAGE:REQUEST_TYPE)) (CARRIER:backnforth)))));
+
+Data: req_code,(SLOT (GOAL:RESPONSE_HANDLER) (SLOT_CHILDREN (SLOT (USAGE:RESPONSE_HANDLER_PARAMETERS)) (REQUEST (SLOT (ROLE:RESPONDER) (SLOT_IS_VALUE_OF:TO_ADDRESS)) (SLOT (USAGE:CHANNEL) (SLOT_IS_VALUE_OF:ASPECT_IDENT)) (CARRIER:backnforth) (SLOT (USAGE:REQUEST_TYPE)) (CARRIER:backnforth)))));
Process: send_request,req_code,"send request","response",SIGNATURE_ANY,NULL_STRUCTURE;
Data: resp_code,(RESPOND (SIGNAL_REF:/2/1/4) (SLOT (GOAL:REQUEST_HANDLER)));
@@ -547,7 +549,8 @@ Data: req_def,(PROTOCOL_DEFINITION
(USAGE:CHANNEL)
(USAGE:REQUEST_TYPE)
(USAGE:RESPONSE_TYPE)
-)
+ (USAGE:RESPONSE_HANDLER_PARAMETERS))
+ (PROTOCOL_DEFAULTS (SEMANTIC_LINK (USAGE:RESPONSE_HANDLER_PARAMETERS) (REPLACEMENT_VALUE (NULL_SYMBOL))))
(backnforth
(INITIATE (ROLE:REQUESTER) (DESTINATION (ROLE:RESPONDER)) (ACTION:send_request))
(EXPECT (ROLE:RESPONDER) (SOURCE (ROLE:REQUESTER)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SLOT (USAGE:REQUEST_TYPE) (SLOT_IS_VALUE_OF:SEMTREX_SYMBOL)))) (ACTION:send_response))));
diff --git a/src/base_defs.c b/src/base_defs.c
index c2f9b649..0c6d4600 100644
--- a/src/base_defs.c
+++ b/src/base_defs.c
@@ -504,6 +504,7 @@ SemanticID RESPONSE_TYPE={0,0,0};
SemanticID CHANNEL={0,0,0};
SemanticID REQUEST_HANDLER={0,0,0};
SemanticID RESPONSE_HANDLER={0,0,0};
+SemanticID RESPONSE_HANDLER_PARAMETERS={0,0,0};
SemanticID backnforth={0,0,0};
SemanticID send_request={0,0,0};
SemanticID send_response={0,0,0};
@@ -1195,12 +1196,13 @@ void base_defs(SemTable *sem) {
sY(DEV_COMPOSITORY_CONTEXT,CHANNEL,SYMBOL);
sY(DEV_COMPOSITORY_CONTEXT,REQUEST_HANDLER,PROCESS);
sY(DEV_COMPOSITORY_CONTEXT,RESPONSE_HANDLER,PROCESS);
+ sY(DEV_COMPOSITORY_CONTEXT,RESPONSE_HANDLER_PARAMETERS,SYMBOL);
sY(DEV_COMPOSITORY_CONTEXT,backnforth,INTERACTION);
- sData(DEV_COMPOSITORY_CONTEXT,req_code,STX_OP,SLOT,STX_OP,GOAL,RESPONSE_HANDLER,STX_CP,STX_OP,SLOT_CHILDREN,STX_OP,REQUEST,STX_OP,SLOT,STX_OP,ROLE,RESPONDER,STX_CP,STX_OP,SLOT_IS_VALUE_OF,TO_ADDRESS,STX_CP,STX_CP,STX_OP,SLOT,STX_OP,USAGE,CHANNEL,STX_CP,STX_OP,SLOT_IS_VALUE_OF,ASPECT_IDENT,STX_CP,STX_CP,STX_OP,CARRIER,backnforth,STX_CP,STX_OP,SLOT,STX_OP,USAGE,REQUEST_TYPE,STX_CP,STX_CP,STX_OP,CARRIER,backnforth,STX_CP,STX_CP,STX_CP,STX_CP,STX_CP);
+ sData(DEV_COMPOSITORY_CONTEXT,req_code,STX_OP,SLOT,STX_OP,GOAL,RESPONSE_HANDLER,STX_CP,STX_OP,SLOT_CHILDREN,STX_OP,SLOT,STX_OP,USAGE,RESPONSE_HANDLER_PARAMETERS,STX_CP,STX_CP,STX_OP,REQUEST,STX_OP,SLOT,STX_OP,ROLE,RESPONDER,STX_CP,STX_OP,SLOT_IS_VALUE_OF,TO_ADDRESS,STX_CP,STX_CP,STX_OP,SLOT,STX_OP,USAGE,CHANNEL,STX_CP,STX_OP,SLOT_IS_VALUE_OF,ASPECT_IDENT,STX_CP,STX_CP,STX_OP,CARRIER,backnforth,STX_CP,STX_OP,SLOT,STX_OP,USAGE,REQUEST_TYPE,STX_CP,STX_CP,STX_OP,CARRIER,backnforth,STX_CP,STX_CP,STX_CP,STX_CP,STX_CP);
sP(DEV_COMPOSITORY_CONTEXT,send_request,req_code,"send request","response",SIGNATURE_ANY,NULL_STRUCTURE,0L);
sData(DEV_COMPOSITORY_CONTEXT,resp_code,STX_OP,RESPOND,STX_OP,SIGNAL_REF,2,1,4,TREE_PATH_TERMINATOR,STX_CP,STX_OP,SLOT,STX_OP,GOAL,REQUEST_HANDLER,STX_CP,STX_CP,STX_CP);
sP(DEV_COMPOSITORY_CONTEXT,send_response,resp_code,"send response","response id",SIGNATURE_SYMBOL,SIGNAL_UUID,0L);
- sData(DEV_COMPOSITORY_CONTEXT,req_def,STX_OP,PROTOCOL_DEFINITION,STX_OP,PROTOCOL_SEMANTICS,STX_OP,ROLE,REQUESTER,STX_CP,STX_OP,ROLE,RESPONDER,STX_CP,STX_OP,GOAL,RESPONSE_HANDLER,STX_CP,STX_OP,GOAL,REQUEST_HANDLER,STX_CP,STX_OP,USAGE,CHANNEL,STX_CP,STX_OP,USAGE,REQUEST_TYPE,STX_CP,STX_OP,USAGE,RESPONSE_TYPE,STX_CP,STX_CP,STX_OP,backnforth,STX_OP,INITIATE,STX_OP,ROLE,REQUESTER,STX_CP,STX_OP,DESTINATION,STX_OP,ROLE,RESPONDER,STX_CP,STX_CP,STX_OP,ACTION,send_request,STX_CP,STX_CP,STX_OP,EXPECT,STX_OP,ROLE,RESPONDER,STX_CP,STX_OP,SOURCE,STX_OP,ROLE,REQUESTER,STX_CP,STX_CP,STX_OP,PATTERN,STX_OP,SEMTREX_SYMBOL_LITERAL,STX_OP,SLOT,STX_OP,USAGE,REQUEST_TYPE,STX_CP,STX_OP,SLOT_IS_VALUE_OF,SEMTREX_SYMBOL,STX_CP,STX_CP,STX_CP,STX_CP,STX_OP,ACTION,send_response,STX_CP,STX_CP,STX_CP,STX_CP);
+ sData(DEV_COMPOSITORY_CONTEXT,req_def,STX_OP,PROTOCOL_DEFINITION,STX_OP,PROTOCOL_SEMANTICS,STX_OP,ROLE,REQUESTER,STX_CP,STX_OP,ROLE,RESPONDER,STX_CP,STX_OP,GOAL,RESPONSE_HANDLER,STX_CP,STX_OP,GOAL,REQUEST_HANDLER,STX_CP,STX_OP,USAGE,CHANNEL,STX_CP,STX_OP,USAGE,REQUEST_TYPE,STX_CP,STX_OP,USAGE,RESPONSE_TYPE,STX_CP,STX_OP,USAGE,RESPONSE_HANDLER_PARAMETERS,STX_CP,STX_CP,STX_OP,PROTOCOL_DEFAULTS,STX_OP,SEMANTIC_LINK,STX_OP,USAGE,RESPONSE_HANDLER_PARAMETERS,STX_CP,STX_OP,REPLACEMENT_VALUE,STX_OP,NULL_SYMBOL,STX_CP,STX_CP,STX_CP,STX_CP,STX_OP,backnforth,STX_OP,INITIATE,STX_OP,ROLE,REQUESTER,STX_CP,STX_OP,DESTINATION,STX_OP,ROLE,RESPONDER,STX_CP,STX_CP,STX_OP,ACTION,send_request,STX_CP,STX_CP,STX_OP,EXPECT,STX_OP,ROLE,RESPONDER,STX_CP,STX_OP,SOURCE,STX_OP,ROLE,REQUESTER,STX_CP,STX_CP,STX_OP,PATTERN,STX_OP,SEMTREX_SYMBOL_LITERAL,STX_OP,SLOT,STX_OP,USAGE,REQUEST_TYPE,STX_CP,STX_OP,SLOT_IS_VALUE_OF,SEMTREX_SYMBOL,STX_CP,STX_CP,STX_CP,STX_CP,STX_OP,ACTION,send_response,STX_CP,STX_CP,STX_CP,STX_CP);
sProt(DEV_COMPOSITORY_CONTEXT,REQUESTING,req_def);
sY(DEV_COMPOSITORY_CONTEXT,RECOGNIZER,RECEPTOR_ADDRESS);
sY(DEV_COMPOSITORY_CONTEXT,RECOGNIZEE,RECEPTOR_ADDRESS);
diff --git a/src/base_defs.h b/src/base_defs.h
index 6b61b715..4dd93ace 100644
--- a/src/base_defs.h
+++ b/src/base_defs.h
@@ -1025,6 +1025,7 @@ enum DEV_COMPOSITORYSymbolIDs {
CHANNEL_ID,
REQUEST_HANDLER_ID,
RESPONSE_HANDLER_ID,
+ RESPONSE_HANDLER_PARAMETERS_ID,
backnforth_ID,
RECOGNIZER_ID,
RECOGNIZEE_ID,
@@ -1071,6 +1072,7 @@ SemanticID RESPONSE_TYPE;
SemanticID CHANNEL;
SemanticID REQUEST_HANDLER;
SemanticID RESPONSE_HANDLER;
+SemanticID RESPONSE_HANDLER_PARAMETERS;
SemanticID backnforth;
SemanticID RECOGNIZER;
SemanticID RECOGNIZEE;
diff --git a/src/protocol.c b/src/protocol.c
index c91d54c3..23b13613 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -262,7 +262,8 @@ T *_o_bindings2sem_map(T *bindings, T *sem_map,T *defaults) {
T * _o_unwrap(SemTable *sem,T *def,T *sem_map) {
T *d = _t_clone(def);
int i;
- for (i=1;i<=_t_children(d);i++) {
+ T *defaults = _t_find(d,PROTOCOL_DEFAULTS);
+ for (i=ProtocolDefOptionalsIdx;i<=_t_children(d);i++) {
T *t = _t_child(d,i);
if (semeq(_t_symbol(t),INCLUSION)) {
Protocol p = *(Protocol *)_t_surface(_t_child(t,InclusionPnameIdx));
@@ -329,15 +330,16 @@ T * _o_unwrap(SemTable *sem,T *def,T *sem_map) {
if (semeq(PROTOCOL_DEFAULTS,_t_symbol(_t_child(p_def,ProtocolDefSemanticsIdx)))) {
x = _t_detach_by_idx(p_def,ProtocolDefSemanticsIdx);
debug(D_PROTOCOL,"merging defaults: %s",_t2s(sem,x));
- T *defaults = _t_find(d,PROTOCOL_DEFAULTS);
// if the including protocol has no defaults we can just insert them
if (!defaults) {
int path[] = {ProtocolDefOptionalsIdx,TREE_PATH_TERMINATOR};
_t_insert_at(d,path,x);
+ defaults = x;
}
else {
// otherwise we have to merge in any that don't already exist
_o_merge_sem_map(x,defaults);
+ _t_free(x);
}
}
diff --git a/src/tree.c b/src/tree.c
index 1ed868dc..e4bea224 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -780,7 +780,8 @@ T *_t_build2(SemTable *sem,T *parent,...) {
param = va_arg(ap,Symbol);
if (semeq(param,STX_OP)) {
node = va_arg(ap,Symbol);
- type = _getBuildType(sem,node,&st,&def);
+ type = NULL_SYMBOL;
+ if (!semeq(node,NULL_SYMBOL)) type = _getBuildType(sem,node,&st,&def);
if (semeq(type,STRUCTURE_SYMBOL) && semeq(*(Symbol *)_t_surface(def),NULL_SYMBOL)) {
debug(D_TREE,"building sys structure %s\n",_sem_get_name(sem,st));
if (semeq(st,PROCESS) || semeq(st,SYMBOL) || semeq(st,STRUCTURE) || semeq(st,PROTOCOL)) {
@@ -1038,13 +1039,14 @@ T *__t_find_actual(T *sem_map,Symbol actual_kind,T *replacement_kind) {
*;
* @param[in,out] template the tree with SLOTs to be filled
* @param[in] sem_map mappings used to fill the template
+ * @returns boolean indicating whether fill resulted in templates removal
*
* @note the template is modified in place, so the caller may need to clone a source template
*
*
Examples (from test suite):
* @snippet spec/tree_spec.h testTreeTemplate
*/
-void __t_fill_template(T *template, T *sem_map,bool as_run_node) {
+bool __t_fill_template(T *template, T *sem_map,bool as_run_node) {
if (!template) return;
debug(D_TREE,"filling template:\n%s\n",__t2s(G_sem,template,INDENT));
debug(D_TREE,"from sem_map:\n%s\n\n",__t2s(G_sem,sem_map,INDENT));
@@ -1175,6 +1177,7 @@ void __t_fill_template(T *template, T *sem_map,bool as_run_node) {
if (!p) raise_error("not expecting a root node!");
_t_detach_by_ptr(p,template);
_t_free(template);
+ template = NULL;
}
break;
}
@@ -1182,9 +1185,15 @@ void __t_fill_template(T *template, T *sem_map,bool as_run_node) {
}
}
else {
- DO_KIDS(template,_t_fill_template(_t_child(template,i),sem_map));
+ int i;
+ for(i=1;i<=_t_children(template);i++) {
+ T *t = _t_child(template,i);
+ // if the fill resulted in deletion we need to decrease the count to not skip a child
+ if (_t_fill_template(t,sem_map)) i--;
+ }
}
- debug(D_TREE,"results in:\n%s\n\n",__t2s(G_sem,template,INDENT));
+ debug(D_TREE,"results in:\n%s\n\n",template ? __t2s(G_sem,template,INDENT) : "
");
+ return template == NULL;
}
/******************** Node data accessors */
diff --git a/src/tree.h b/src/tree.h
index b9b23d73..f350990a 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -73,7 +73,7 @@ T *__t_tokenize(char *s);
T *_t_parse(SemTable *sem,T *parent,char *s,...);
#define _t_fill_template(t,i) __t_fill_template(t,i,false)
-void __t_fill_template(T *template, T *items,bool as_run_node);
+bool __t_fill_template(T *template, T *items,bool as_run_node);
/******************** Node data accessors */
int _t_children(T *t);