context sensitivity
git-svn-id: https://asn1c.svn.sourceforge.net/svnroot/asn1c/trunk@676 59561ff5-6e30-0410-9f3c-9617f08c8826
diff --git a/skeletons/BOOLEAN.c b/skeletons/BOOLEAN.c
index 7473b62..6a4cdc7 100644
--- a/skeletons/BOOLEAN.c
+++ b/skeletons/BOOLEAN.c
@@ -146,7 +146,7 @@
/* "<false/>" */
*st = 0;
break;
- case XCT_UNEXPECTED:
+ case XCT_UNKNOWN_BO:
if(xer_check_tag(chunk_buf, chunk_size, "true")
!= XCT_BOTH)
return -1;
diff --git a/skeletons/constr_CHOICE.c b/skeletons/constr_CHOICE.c
index 49bd06c..4e90bbd 100644
--- a/skeletons/constr_CHOICE.c
+++ b/skeletons/constr_CHOICE.c
@@ -639,7 +639,7 @@
/*
* Get the next part of the XML stream.
*/
- ch_size = xer_next_token(buf_ptr, size, &ch_type);
+ ch_size = xer_next_token(&ctx->context, buf_ptr, size, &ch_type);
switch(ch_size) {
case -1: RETURN(RC_FAIL);
case 0: RETURN(RC_WMORE);
@@ -667,6 +667,7 @@
continue;
case 1:
ctx->phase = 3;
+ /* Fall through */
case 0:
XER_ADVANCE(ch_size);
continue;
diff --git a/skeletons/constr_SEQUENCE.c b/skeletons/constr_SEQUENCE.c
index 31f0c42..459de4c 100644
--- a/skeletons/constr_SEQUENCE.c
+++ b/skeletons/constr_SEQUENCE.c
@@ -689,7 +689,8 @@
/*
* Get the next part of the XML stream.
*/
- ch_size = xer_next_token(buf_ptr, size, &ch_type);
+ ch_size = xer_next_token(&ctx->context, buf_ptr, size,
+ &ch_type);
switch(ch_size) {
case -1: RETURN(RC_FAIL);
case 0: RETURN(RC_WMORE);
diff --git a/skeletons/constr_SET.c b/skeletons/constr_SET.c
index c5bb201..2ee3b81 100644
--- a/skeletons/constr_SET.c
+++ b/skeletons/constr_SET.c
@@ -671,7 +671,8 @@
/*
* Get the next part of the XML stream.
*/
- ch_size = xer_next_token(buf_ptr, size, &ch_type);
+ ch_size = xer_next_token(&ctx->context,
+ buf_ptr, size, &ch_type);
switch(ch_size) {
case -1: RETURN(RC_FAIL);
case 0: RETURN(RC_WMORE);
@@ -695,13 +696,12 @@
case -1:
ctx->phase = 4;
RETURN(RC_FAIL);
+ case 1:
+ ctx->phase = 1;
+ /* Fall through */
case 0:
XER_ADVANCE(ch_size);
continue;
- case 1:
- XER_ADVANCE(ch_size);
- ctx->phase = 1;
- continue;
case 2:
ctx->phase = 1;
break;
diff --git a/skeletons/constr_SET_OF.c b/skeletons/constr_SET_OF.c
index 7df1e5c..37268dc 100644
--- a/skeletons/constr_SET_OF.c
+++ b/skeletons/constr_SET_OF.c
@@ -536,7 +536,8 @@
/*
* Get the next part of the XML stream.
*/
- ch_size = xer_next_token(buf_ptr, size, &ch_type);
+ ch_size = xer_next_token(&ctx->context,
+ buf_ptr, size, &ch_type);
switch(ch_size) {
case -1: RETURN(RC_FAIL);
case 0: RETURN(RC_WMORE);
diff --git a/skeletons/constr_TYPE.h b/skeletons/constr_TYPE.h
index 79bd0a2..e36f293 100644
--- a/skeletons/constr_TYPE.h
+++ b/skeletons/constr_TYPE.h
@@ -23,10 +23,11 @@
* included into certain target language's structures, such as compound types.
*/
typedef struct asn_struct_ctx_s {
- int phase; /* Decoding phase */
- int step; /* Elementary step of a phase */
- ber_tlv_len_t left; /* Number of bytes left, -1 for indefinite */
+ short phase; /* Decoding phase */
+ short step; /* Elementary step of a phase */
+ int context; /* Other context information */
void *ptr; /* Decoder-specific stuff (stack elements) */
+ ber_tlv_len_t left; /* Number of bytes left, -1 for indefinite */
} asn_struct_ctx_t;
#include <ber_decoder.h> /* Basic Encoding Rules decoder */
diff --git a/skeletons/tests/check-XER.c b/skeletons/tests/check-XER.c
index 5c7e69c..9254dbc 100644
--- a/skeletons/tests/check-XER.c
+++ b/skeletons/tests/check-XER.c
@@ -17,10 +17,11 @@
int xerbuf_len = strlen(xerbuf);
pxer_chunk_type_e ch_type;
ssize_t ch_size;
+ int state = 0;
if(expected_chunk_size == -1)
expected_chunk_size = xerbuf_len;
- ch_size = xer_next_token(xerbuf, xerbuf_len, &ch_type);
+ ch_size = xer_next_token(&state, xerbuf, xerbuf_len, &ch_type);
printf("[%s]:%d\n", xerbuf, xerbuf_len);
printf("chunk sizes: %d vs %d, chunk types: %d vs %d\n",
diff --git a/skeletons/xer_decoder.c b/skeletons/xer_decoder.c
index ed1fff4..9127679 100644
--- a/skeletons/xer_decoder.c
+++ b/skeletons/xer_decoder.c
@@ -51,13 +51,13 @@
* Fetch the next token from the XER/XML stream.
*/
ssize_t
-xer_next_token(void *buffer, size_t size, pxer_chunk_type_e *ch_type) {
+xer_next_token(int *stateContext, void *buffer, size_t size, pxer_chunk_type_e *ch_type) {
struct xer__cb_arg arg;
- int stateContext = 0;
+ int new_stateContext = *stateContext;
ssize_t ret;
arg.callback_not_invoked = 1;
- ret = pxml_parse(&stateContext, buffer, size, xer__token_cb, &arg);
+ ret = pxml_parse(&new_stateContext, buffer, size, xer__token_cb, &arg);
if(ret < 0) return -1;
if(arg.callback_not_invoked) {
assert(ret == 0); /* No data was consumed */
@@ -65,7 +65,6 @@
} else {
assert(arg.chunk_size);
assert(arg.chunk_buf == buffer);
- assert(stateContext == 0);
}
/*
@@ -85,6 +84,7 @@
break;
}
+ *stateContext = new_stateContext;
return arg.chunk_size;
}
@@ -136,13 +136,13 @@
return ct;
}
}
- return (XCT__UNK__MASK | ct);
+ return (xer_check_tag_e)(XCT__UNK__MASK | ct);
}
if(b == 0)
return XCT_BROKEN; /* Embedded 0 in buf?! */
}
if(*need_tag)
- return (XCT__UNK__MASK | ct);
+ return (xer_check_tag_e)(XCT__UNK__MASK | ct);
return ct;
}
@@ -168,7 +168,8 @@
(struct_key, chunk_buf, chunk_size, \
(size_t)chunk_size < size); \
if(converted_size == -1) RETURN(RC_FAIL); \
- if(converted_size == 0 && size == chunk_size) \
+ if(converted_size == 0 \
+ && size == (size_t)chunk_size) \
RETURN(RC_WMORE); \
chunk_size = converted_size; \
} while(0)
@@ -212,7 +213,8 @@
/*
* Get the next part of the XML stream.
*/
- ch_size = xer_next_token(buf_ptr, size, &ch_type);
+ ch_size = xer_next_token(&ctx->context, buf_ptr, size,
+ &ch_type);
switch(ch_size) {
case -1: RETURN(RC_FAIL);
case 0:
diff --git a/skeletons/xer_decoder.h b/skeletons/xer_decoder.h
index c0e23b9..fa8c3c6 100644
--- a/skeletons/xer_decoder.h
+++ b/skeletons/xer_decoder.h
@@ -63,7 +63,8 @@
PXER_TEXT, /* Plain text between XER tags */
PXER_COMMENT, /* A comment, may be part of */
} pxer_chunk_type_e;
-ssize_t xer_next_token(void *buffer, size_t size, pxer_chunk_type_e *_ch_type);
+ssize_t xer_next_token(int *stateContext,
+ void *buffer, size_t size, pxer_chunk_type_e *_ch_type);
/*
* This function checks the buffer against the tag name is expected to occur.