fx.serial: toml: update array and hashtable usage
This commit is contained in:
+135
-182
@@ -1,8 +1,8 @@
|
||||
#include <fx/bool.h>
|
||||
#include <fx/collections/array.h>
|
||||
#include <fx/collections/datetime.h>
|
||||
#include <fx/collections/hashmap.h>
|
||||
#include <fx/collections/hashtable.h>
|
||||
#include <fx/datetime.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/float.h>
|
||||
#include <fx/int.h>
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <fx/status.h>
|
||||
#include <fx/string.h>
|
||||
#include <fx/stringstream.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -116,9 +117,9 @@ struct ctx {
|
||||
fx_stream *ctx_src;
|
||||
fx_string *ctx_wordbuf;
|
||||
fx_string *ctx_linebuf;
|
||||
fx_iterator *ctx_linebuf_ptr;
|
||||
const fx_iterator *ctx_linebuf_ptr;
|
||||
fx_result ctx_result;
|
||||
fx_hashmap *ctx_objects_flags;
|
||||
fx_hashtable *ctx_objects_flags;
|
||||
|
||||
fx_queue ctx_tokens;
|
||||
};
|
||||
@@ -132,29 +133,18 @@ static void ctx_set_object_flags(
|
||||
return;
|
||||
}
|
||||
|
||||
fx_hashmap_key key = {
|
||||
.key_data = obj,
|
||||
.key_size = sizeof(fx_object *),
|
||||
.key_flags = FX_HASHMAP_KEY_F_INTVALUE,
|
||||
};
|
||||
|
||||
const fx_hashmap_value *old_value = fx_hashmap_get(
|
||||
ctx->ctx_objects_flags,
|
||||
&key);
|
||||
fx_value ptr = FX_POINTER(obj);
|
||||
const fx_value *old_value
|
||||
= fx_hashtable_get(ctx->ctx_objects_flags, &ptr);
|
||||
|
||||
enum object_flags new_flags = 0;
|
||||
if (old_value) {
|
||||
new_flags = (enum object_flags)(uintptr_t)old_value->value_data;
|
||||
new_flags = (enum object_flags)old_value->v_i32;
|
||||
}
|
||||
|
||||
new_flags |= flags;
|
||||
|
||||
fx_hashmap_value value = {
|
||||
.value_data = (void *)new_flags,
|
||||
.value_size = sizeof new_flags,
|
||||
};
|
||||
|
||||
fx_hashmap_put(ctx->ctx_objects_flags, &key, &value);
|
||||
fx_hashtable_put(ctx->ctx_objects_flags, &ptr, &FX_I32(new_flags));
|
||||
}
|
||||
|
||||
static void ctx_clear_object_flags(
|
||||
@@ -166,29 +156,18 @@ static void ctx_clear_object_flags(
|
||||
return;
|
||||
}
|
||||
|
||||
fx_hashmap_key key = {
|
||||
.key_data = obj,
|
||||
.key_size = sizeof(fx_object *),
|
||||
.key_flags = FX_HASHMAP_KEY_F_INTVALUE,
|
||||
};
|
||||
|
||||
const fx_hashmap_value *old_value = fx_hashmap_get(
|
||||
ctx->ctx_objects_flags,
|
||||
&key);
|
||||
fx_value ptr = FX_POINTER(obj);
|
||||
const fx_value *old_value
|
||||
= fx_hashtable_get(ctx->ctx_objects_flags, &ptr);
|
||||
|
||||
enum object_flags new_flags = 0;
|
||||
if (old_value) {
|
||||
new_flags = (enum object_flags)(uintptr_t)old_value->value_data;
|
||||
new_flags = (enum object_flags)old_value->v_i32;
|
||||
}
|
||||
|
||||
new_flags &= ~mask;
|
||||
|
||||
fx_hashmap_value value = {
|
||||
.value_data = (void *)new_flags,
|
||||
.value_size = sizeof new_flags,
|
||||
};
|
||||
|
||||
fx_hashmap_put(ctx->ctx_objects_flags, &key, &value);
|
||||
fx_hashtable_put(ctx->ctx_objects_flags, &ptr, &FX_I32(new_flags));
|
||||
}
|
||||
|
||||
static enum object_flags ctx_get_object_flags(struct ctx *ctx, fx_object *obj)
|
||||
@@ -197,17 +176,13 @@ static enum object_flags ctx_get_object_flags(struct ctx *ctx, fx_object *obj)
|
||||
return 0;
|
||||
}
|
||||
|
||||
fx_hashmap_key key = {
|
||||
.key_data = obj,
|
||||
.key_size = sizeof(fx_object *),
|
||||
.key_flags = FX_HASHMAP_KEY_F_INTVALUE,
|
||||
};
|
||||
fx_value ptr = FX_POINTER(obj);
|
||||
const fx_value *old_value
|
||||
= fx_hashtable_get(ctx->ctx_objects_flags, &ptr);
|
||||
|
||||
const fx_hashmap_value *value = fx_hashmap_get(
|
||||
ctx->ctx_objects_flags,
|
||||
&key);
|
||||
if (value) {
|
||||
return (enum object_flags)(uintptr_t)value->value_data;
|
||||
enum object_flags new_flags = 0;
|
||||
if (old_value) {
|
||||
return (enum object_flags)old_value->v_i32;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -297,7 +272,7 @@ static fx_wchar advance_char(struct ctx *ctx)
|
||||
|
||||
const char *s = fx_string_get_cstr(ctx->ctx_linebuf);
|
||||
|
||||
fx_wchar c = fx_iterator_get_value(ctx->ctx_linebuf_ptr).v_int;
|
||||
fx_wchar c = fx_iterator_get_value(ctx->ctx_linebuf_ptr)->v_wchar;
|
||||
|
||||
if (!is_valid_char(c)) {
|
||||
ctx->ctx_result = FX_RESULT_ERR(BAD_FORMAT);
|
||||
@@ -330,7 +305,7 @@ static fx_wchar peek_char(struct ctx *ctx)
|
||||
|
||||
const char *s = fx_string_get_cstr(ctx->ctx_linebuf);
|
||||
|
||||
fx_wchar c = fx_iterator_get_value(ctx->ctx_linebuf_ptr).v_int;
|
||||
fx_wchar c = fx_iterator_get_value(ctx->ctx_linebuf_ptr)->v_wchar;
|
||||
|
||||
if (!is_valid_char(c)) {
|
||||
ctx->ctx_result = FX_RESULT_ERR(BAD_FORMAT);
|
||||
@@ -929,7 +904,7 @@ static void split_word(struct ctx *ctx, fx_string *wordbuf)
|
||||
fx_foreach(tokv, it)
|
||||
{
|
||||
const char *tok = NULL;
|
||||
fx_value_get_cstr(&tokv, &tok);
|
||||
fx_value_get_cstr(tokv, &tok);
|
||||
|
||||
if (i > 0) {
|
||||
enqueue_token(ctx, TOK_DOT);
|
||||
@@ -1032,11 +1007,11 @@ static void read_word(struct ctx *ctx)
|
||||
return;
|
||||
}
|
||||
|
||||
fx_iterator *it = fx_iterator_begin(wordbuf);
|
||||
const fx_iterator *it = fx_iterator_begin(wordbuf);
|
||||
fx_foreach(cv, it)
|
||||
{
|
||||
fx_wchar c = FX_WCHAR_INVALID;
|
||||
fx_value_get_wchar(&cv, &c);
|
||||
fx_value_get_wchar(cv, &c);
|
||||
/* only allow ASCII numbers/letters here */
|
||||
bool ok = isalnum(c) || c == '_' || c == '-' || c == '.';
|
||||
if (!ok) {
|
||||
@@ -1184,8 +1159,8 @@ static void read_string(struct ctx *ctx, bool squote)
|
||||
}
|
||||
|
||||
if (c != '\n') {
|
||||
ctx->ctx_result = FX_RESULT_ERR(
|
||||
BAD_FORMAT);
|
||||
ctx->ctx_result
|
||||
= FX_RESULT_ERR(BAD_FORMAT);
|
||||
fail = true;
|
||||
break;
|
||||
}
|
||||
@@ -1230,18 +1205,16 @@ static void read_string(struct ctx *ctx, bool squote)
|
||||
case 'U':
|
||||
c = read_unicode_sequence(ctx);
|
||||
if (c == FX_WCHAR_INVALID) {
|
||||
ctx->ctx_result = FX_RESULT_ERR(
|
||||
BAD_FORMAT);
|
||||
ctx->ctx_result
|
||||
= FX_RESULT_ERR(BAD_FORMAT);
|
||||
fail = true;
|
||||
break;
|
||||
}
|
||||
|
||||
ctx->ctx_result = FX_OK(fx_string_append_wc(
|
||||
str,
|
||||
c))
|
||||
? FX_SUCCESS
|
||||
: FX_RESULT_ERR(
|
||||
BAD_FORMAT);
|
||||
ctx->ctx_result
|
||||
= FX_OK(fx_string_append_wc(str, c))
|
||||
? FX_SUCCESS
|
||||
: FX_RESULT_ERR(BAD_FORMAT);
|
||||
fail = !FX_OK(ctx->ctx_result);
|
||||
break;
|
||||
default:
|
||||
@@ -1482,14 +1455,24 @@ static fx_result advance_token(struct ctx *ctx)
|
||||
|
||||
start:
|
||||
c = peek_char(ctx);
|
||||
while (isspace(c) && c != '\n' && c != '\r') {
|
||||
advance_char(ctx);
|
||||
c = peek_char(ctx);
|
||||
|
||||
if (c <= 0) {
|
||||
if (fx_error_get_status_code(ctx->ctx_result)
|
||||
== FX_ERR_NO_DATA) {
|
||||
ctx->ctx_flags |= CTX_EOF;
|
||||
}
|
||||
|
||||
return ctx->ctx_result;
|
||||
}
|
||||
|
||||
if (c == -1) {
|
||||
ctx->ctx_flags |= CTX_EOF;
|
||||
return FX_RESULT_ERR(NO_DATA);
|
||||
if (c <= 31 && c != '\n' && c != '\r' && c != '\t') {
|
||||
ctx->ctx_result = FX_RESULT_ERR(BAD_FORMAT);
|
||||
return ctx->ctx_result;
|
||||
}
|
||||
|
||||
while (fx_wchar_is_space(c) && c != '\n' && c != '\r') {
|
||||
advance_char(ctx);
|
||||
c = peek_char(ctx);
|
||||
}
|
||||
|
||||
#if 1
|
||||
@@ -1559,7 +1542,7 @@ static void ctx_cleanup(struct ctx *ctx)
|
||||
}
|
||||
|
||||
if (ctx->ctx_objects_flags) {
|
||||
fx_hashmap_unref(ctx->ctx_objects_flags);
|
||||
fx_hashtable_unref(ctx->ctx_objects_flags);
|
||||
ctx->ctx_objects_flags = NULL;
|
||||
}
|
||||
}
|
||||
@@ -1571,14 +1554,14 @@ static fx_result ctx_init(struct ctx *ctx)
|
||||
ctx->ctx_linebuf = fx_string_create();
|
||||
ctx->ctx_wordbuf = fx_string_create();
|
||||
|
||||
ctx->ctx_objects_flags = fx_hashmap_create(NULL, NULL);
|
||||
ctx->ctx_objects_flags = fx_hashtable_create();
|
||||
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_result toml_serialise(
|
||||
fx_serial_ctx *serial,
|
||||
fx_object *src,
|
||||
const fx_value *src,
|
||||
fx_stream *dest,
|
||||
enum fx_serial_flags flags)
|
||||
{
|
||||
@@ -1672,20 +1655,20 @@ static void print_token(struct token *tok)
|
||||
}
|
||||
}
|
||||
|
||||
static fx_result parse_value(struct ctx *ctx, fx_object **result);
|
||||
static fx_result parse_value(struct ctx *ctx, fx_value *result);
|
||||
static fx_result parse_key_value_pair(struct ctx *ctx, fx_hashtable *container);
|
||||
|
||||
static fx_result parse_timestamp(struct ctx *ctx, fx_object **result)
|
||||
static fx_result parse_timestamp(struct ctx *ctx, fx_value *result)
|
||||
{
|
||||
struct token *tok = peek_token(ctx);
|
||||
fx_datetime *dt = tok->tok_value.time;
|
||||
tok->tok_value.time = NULL;
|
||||
|
||||
*result = (dt);
|
||||
*result = FX_VALUE_OBJECT(dt);
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_result parse_string(struct ctx *ctx, fx_object **result)
|
||||
static fx_result parse_string(struct ctx *ctx, fx_value *result)
|
||||
{
|
||||
struct token *tok = peek_token(ctx);
|
||||
fx_string *str = fx_string_duplicate(tok->tok_str);
|
||||
@@ -1693,81 +1676,48 @@ static fx_result parse_string(struct ctx *ctx, fx_object **result)
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
*result = (str);
|
||||
*result = FX_VALUE_OBJECT(str);
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_result parse_int(struct ctx *ctx, fx_object **result)
|
||||
static fx_result parse_int(struct ctx *ctx, fx_value *result)
|
||||
{
|
||||
#if 0
|
||||
struct token *tok = peek_token(ctx);
|
||||
fx_int *val = fx_int_create(tok->tok_value.i.v);
|
||||
if (!val) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
if (tok->tok_value.i.inf) {
|
||||
if (tok->tok_value.i.v >= 0) {
|
||||
fx_int_set_value_inf(val);
|
||||
} else {
|
||||
fx_int_set_value_inf_negative(val);
|
||||
}
|
||||
} else if (tok->tok_value.i.nan) {
|
||||
if (tok->tok_value.i.v >= 0) {
|
||||
fx_int_set_value_nan(val);
|
||||
} else {
|
||||
fx_int_set_value_nan_negative(val);
|
||||
}
|
||||
}
|
||||
|
||||
*result = (val);
|
||||
#endif
|
||||
*result = FX_I64(tok->tok_value.i.v);
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_result parse_float(struct ctx *ctx, fx_object **result)
|
||||
static fx_result parse_float(struct ctx *ctx, fx_value *result)
|
||||
{
|
||||
#if 0
|
||||
struct token *tok = peek_token(ctx);
|
||||
fx_double *val = fx_double_create(tok->tok_value.f.v);
|
||||
if (!val) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
if (tok->tok_value.f.inf) {
|
||||
if (tok->tok_value.f.v >= 0) {
|
||||
fx_double_set_value_inf(val);
|
||||
*result = FX_DOUBLE(INFINITY);
|
||||
} else {
|
||||
fx_double_set_value_inf_negative(val);
|
||||
*result = FX_DOUBLE(-INFINITY);
|
||||
}
|
||||
} else if (tok->tok_value.f.nan) {
|
||||
if (tok->tok_value.f.v >= 0) {
|
||||
fx_double_set_value_nan(val);
|
||||
*result = FX_DOUBLE(NAN);
|
||||
} else {
|
||||
fx_double_set_value_nan_negative(val);
|
||||
*result = FX_DOUBLE(-NAN);
|
||||
}
|
||||
} else {
|
||||
*result = FX_DOUBLE(tok->tok_value.f.v);
|
||||
}
|
||||
|
||||
*result = (val);
|
||||
#endif
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_result parse_bool(struct ctx *ctx, fx_object **result)
|
||||
static fx_result parse_bool(struct ctx *ctx, fx_value *result)
|
||||
{
|
||||
#if 0
|
||||
struct token *tok = peek_token(ctx);
|
||||
fx_bool *val = fx_bool_create(tok->tok_value.b);
|
||||
if (!val) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
*result = (val);
|
||||
#endif
|
||||
*result = FX_BOOL(tok->tok_value.b);
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_result parse_table_inline(struct ctx *ctx, fx_object **result)
|
||||
static fx_result parse_table_inline(struct ctx *ctx, fx_value *result)
|
||||
{
|
||||
DISABLE_EXTENDED_LEXING(ctx);
|
||||
|
||||
@@ -1780,7 +1730,7 @@ static fx_result parse_table_inline(struct ctx *ctx, fx_object **result)
|
||||
|
||||
struct token *tok = peek_token(ctx);
|
||||
if (tok && tok->tok_type == TOK_RIGHT_BRACE) {
|
||||
*result = (table);
|
||||
*result = FX_VALUE_OBJECT(table);
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1814,7 +1764,7 @@ static fx_result parse_table_inline(struct ctx *ctx, fx_object **result)
|
||||
}
|
||||
}
|
||||
|
||||
*result = (table);
|
||||
*result = FX_VALUE_OBJECT(table);
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1828,7 +1778,7 @@ static void skip_newlines(struct ctx *ctx)
|
||||
}
|
||||
}
|
||||
|
||||
static fx_result parse_array_inline(struct ctx *ctx, fx_object **result)
|
||||
static fx_result parse_array_inline(struct ctx *ctx, fx_value *result)
|
||||
{
|
||||
bool done = false;
|
||||
ENABLE_EXTENDED_LEXING(ctx);
|
||||
@@ -1865,16 +1815,15 @@ static fx_result parse_array_inline(struct ctx *ctx, fx_object **result)
|
||||
break;
|
||||
}
|
||||
|
||||
fx_object *value;
|
||||
fx_value value;
|
||||
fx_result status = parse_value(ctx, &value);
|
||||
if (!FX_OK(status)) {
|
||||
fx_array_unref(array);
|
||||
return status;
|
||||
}
|
||||
|
||||
#if 0
|
||||
fx_array_append(array, FX_RV(value));
|
||||
#endif
|
||||
fx_array_push_back(array, value);
|
||||
fx_value_unset(&value);
|
||||
ENABLE_EXTENDED_LEXING(ctx);
|
||||
|
||||
advance_token(ctx);
|
||||
@@ -1897,11 +1846,11 @@ static fx_result parse_array_inline(struct ctx *ctx, fx_object **result)
|
||||
}
|
||||
|
||||
DISABLE_EXTENDED_LEXING(ctx);
|
||||
*result = (array);
|
||||
*result = FX_VALUE_OBJECT(array);
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_result parse_value(struct ctx *ctx, fx_object **result)
|
||||
static fx_result parse_value(struct ctx *ctx, fx_value *result)
|
||||
{
|
||||
|
||||
struct token *tok = peek_token(ctx);
|
||||
@@ -1948,9 +1897,13 @@ static fx_result parse_key_value_pair(struct ctx *ctx, fx_hashtable *container)
|
||||
}
|
||||
|
||||
while (tok && tok->tok_type == TOK_DOT) {
|
||||
const fx_value *child = fx_hashtable_get(
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key));
|
||||
const fx_value *child
|
||||
= fx_hashtable_get(container, &FX_VALUE_OBJECT(key));
|
||||
if (child && !fx_value_is_type(child, FX_TYPE_HASHTABLE)) {
|
||||
fx_string_unref(key);
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
fx_hashmap *subtable = NULL;
|
||||
fx_value_get_object(child, &subtable);
|
||||
if (!subtable) {
|
||||
@@ -1959,18 +1912,13 @@ static fx_result parse_key_value_pair(struct ctx *ctx, fx_hashtable *container)
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key),
|
||||
&FX_VALUE_OBJECT(subtable));
|
||||
} else if (
|
||||
subtable
|
||||
&& !fx_object_is_type(subtable, FX_TYPE_HASHTABLE)) {
|
||||
free(key);
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
#if 1
|
||||
enum object_flags flags = ctx_get_object_flags(ctx, subtable);
|
||||
if (flags
|
||||
& (OBJECT_KV_END_DEFINED | OBJECT_HEADER_END_DEFINED)) {
|
||||
free(key);
|
||||
fx_string_unref(key);
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
#endif
|
||||
@@ -1980,7 +1928,7 @@ static fx_result parse_key_value_pair(struct ctx *ctx, fx_hashtable *container)
|
||||
advance_token(ctx);
|
||||
tok = peek_token(ctx);
|
||||
if (!IS_VALID_KEY_COMPONENT(tok)) {
|
||||
free(key);
|
||||
fx_string_unref(key);
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
@@ -2010,7 +1958,7 @@ static fx_result parse_key_value_pair(struct ctx *ctx, fx_hashtable *container)
|
||||
ENABLE_EXTENDED_LEXING(ctx);
|
||||
advance_token(ctx);
|
||||
|
||||
fx_object *value = NULL;
|
||||
fx_value value = FX_VALUE_EMPTY;
|
||||
fx_result result = parse_value(ctx, &value);
|
||||
|
||||
DISABLE_EXTENDED_LEXING(ctx);
|
||||
@@ -2025,17 +1973,17 @@ static fx_result parse_key_value_pair(struct ctx *ctx, fx_hashtable *container)
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
fx_hashtable_put(
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key),
|
||||
&FX_VALUE_OBJECT(value));
|
||||
fx_object_unref(value);
|
||||
fx_hashtable_put(container, &FX_VALUE_OBJECT(key), &value);
|
||||
|
||||
if (fx_object_is_type(value, FX_TYPE_HASHTABLE)
|
||||
|| fx_object_is_type(value, FX_TYPE_ARRAY)) {
|
||||
ctx_set_object_flags(ctx, value, OBJECT_KV_END_DEFINED);
|
||||
if (fx_value_is_type(&value, FX_TYPE_HASHTABLE)
|
||||
|| fx_value_is_type(&value, FX_TYPE_ARRAY)) {
|
||||
ctx_set_object_flags(
|
||||
ctx,
|
||||
value.v_object,
|
||||
OBJECT_KV_END_DEFINED);
|
||||
}
|
||||
|
||||
fx_value_unset(&value);
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -2062,26 +2010,24 @@ static fx_result parse_table_header(
|
||||
}
|
||||
|
||||
while (tok && tok->tok_type == TOK_DOT) {
|
||||
const fx_value *value = fx_hashtable_get(
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key));
|
||||
const fx_value *value
|
||||
= fx_hashtable_get(container, &FX_VALUE_OBJECT(key));
|
||||
fx_object *subtable = NULL;
|
||||
fx_value_get_object(value, &subtable);
|
||||
enum object_flags flags = ctx_get_object_flags(ctx, subtable);
|
||||
if (!subtable) {
|
||||
if (!value) {
|
||||
subtable = (fx_hashtable_create());
|
||||
fx_hashtable_put(
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key),
|
||||
&FX_VALUE_OBJECT(subtable));
|
||||
fx_object_unref(subtable);
|
||||
} else if (fx_object_is_type(subtable, FX_TYPE_ARRAY)) {
|
||||
#if 0
|
||||
subtable = fx_array_at(
|
||||
} else if (fx_value_is_type(value, FX_TYPE_ARRAY)) {
|
||||
value = fx_array_get_ref(
|
||||
subtable,
|
||||
fx_array_size(subtable) - 1);
|
||||
#endif
|
||||
} else if (!fx_object_is_type(subtable, FX_TYPE_HASHTABLE)) {
|
||||
fx_array_get_size(subtable) - 1);
|
||||
fx_value_get_object(value, &subtable);
|
||||
} else if (!fx_value_is_type(value, FX_TYPE_HASHTABLE)) {
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
@@ -2112,9 +2058,12 @@ static fx_result parse_table_header(
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
const fx_value *child = fx_hashtable_get(
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key));
|
||||
const fx_value *child
|
||||
= fx_hashtable_get(container, &FX_VALUE_OBJECT(key));
|
||||
if (child && !fx_value_is_type(child, FX_TYPE_HASHTABLE)) {
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
fx_hashtable *new_table = NULL;
|
||||
fx_value_get_object(child, &new_table);
|
||||
|
||||
@@ -2122,7 +2071,7 @@ static fx_result parse_table_header(
|
||||
new_table = fx_hashtable_create();
|
||||
|
||||
if (!new_table) {
|
||||
free(key);
|
||||
fx_string_unref(key);
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
@@ -2175,26 +2124,29 @@ static fx_result parse_array_header(
|
||||
}
|
||||
|
||||
while (tok && tok->tok_type == TOK_DOT) {
|
||||
const fx_value *child = fx_hashtable_get(
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key));
|
||||
const fx_value *child
|
||||
= fx_hashtable_get(container, &FX_VALUE_OBJECT(key));
|
||||
fx_object *sub_dict = NULL;
|
||||
fx_value_get_object(child, &sub_dict);
|
||||
|
||||
if (!sub_dict) {
|
||||
enum object_flags flags = ctx_get_object_flags(ctx, (sub_dict));
|
||||
if (flags & OBJECT_KV_END_DEFINED) {
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
if (!child) {
|
||||
sub_dict = (fx_hashtable_create());
|
||||
fx_hashtable_put(
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key),
|
||||
&FX_VALUE_OBJECT(sub_dict));
|
||||
fx_hashtable_unref(sub_dict);
|
||||
} else if (fx_object_is_type(sub_dict, FX_TYPE_ARRAY)) {
|
||||
#if 0
|
||||
sub_dict = fx_array_at(
|
||||
} else if (fx_value_is_type(child, FX_TYPE_ARRAY)) {
|
||||
child = fx_array_get_ref(
|
||||
sub_dict,
|
||||
fx_array_size(sub_dict) - 1);
|
||||
#endif
|
||||
} else if (!fx_object_is_type(sub_dict, FX_TYPE_HASHTABLE)) {
|
||||
fx_array_get_size(sub_dict) - 1);
|
||||
sub_dict = child->v_object;
|
||||
} else if (!fx_value_is_type(child, FX_TYPE_HASHTABLE)) {
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
@@ -2219,9 +2171,12 @@ static fx_result parse_array_header(
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
const fx_value *child = fx_hashtable_get(
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key));
|
||||
const fx_value *child
|
||||
= fx_hashtable_get(container, &FX_VALUE_OBJECT(key));
|
||||
if (child && !fx_value_is_type(child, FX_TYPE_ARRAY)) {
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
fx_array *array = NULL;
|
||||
fx_value_get_object(child, &array);
|
||||
|
||||
@@ -2234,11 +2189,11 @@ static fx_result parse_array_header(
|
||||
} else if (!fx_object_is_type(array, FX_TYPE_ARRAY)) {
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
free(key);
|
||||
fx_string_unref(key);
|
||||
|
||||
enum object_flags flags = ctx_get_object_flags(ctx, (array));
|
||||
if (flags & OBJECT_KV_END_DEFINED) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
fx_hashtable *new_table = fx_hashtable_create();
|
||||
@@ -2246,9 +2201,7 @@ static fx_result parse_array_header(
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
#if 0
|
||||
fx_array_append(array, FX_RV(new_table));
|
||||
#endif
|
||||
fx_array_push_back(array, FX_VALUE_OBJECT(new_table));
|
||||
|
||||
advance_token(ctx);
|
||||
*new_container = new_table;
|
||||
@@ -2330,7 +2283,7 @@ static fx_result parse_root(struct ctx *ctx, fx_hashtable **out)
|
||||
static fx_result toml_deserialise(
|
||||
fx_serial_ctx *serial,
|
||||
fx_stream *src,
|
||||
fx_object **dest,
|
||||
fx_value *dest,
|
||||
enum fx_serial_flags flags)
|
||||
{
|
||||
struct ctx ctx = {0};
|
||||
@@ -2351,7 +2304,7 @@ static fx_result toml_deserialise(
|
||||
}
|
||||
|
||||
if (ctx.ctx_flags & CTX_EOF) {
|
||||
*dest = (fx_hashtable_create());
|
||||
*dest = FX_VALUE_OBJECT(fx_hashtable_create());
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -2361,7 +2314,7 @@ static fx_result toml_deserialise(
|
||||
return fx_result_propagate(ctx.ctx_result);
|
||||
}
|
||||
|
||||
*dest = (data);
|
||||
*dest = FX_VALUE_OBJECT(data);
|
||||
#if 0
|
||||
ctx.ctx_flags
|
||||
= CTX_ENABLE_NUMBERS | CTX_ENABLE_TIMESTAMPS | CTX_ENABLE_BOOLS;
|
||||
|
||||
Reference in New Issue
Block a user