commit a6e1c85ce43dc15dae15a8cd8c7b481e8b5cceca
parent 29b0e0121566096f3a220422f584abd31fd4feb8
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 3 Mar 2017 11:45:00 +0100
Remove the cache of parsed entities
An parsed entity is no more cached, i.e. it is not reused. Among others
things, this ensure that the anchors are unique per entity even though
the entity is "instantiated" several times. Its id can thus be used to
map toward an unique per entity data.
This fix a bug in the solstice_setup_entities function, where an anchor
id was used to map a solstice node while this id was shared between
several entities.
Diffstat:
2 files changed, 27 insertions(+), 32 deletions(-)
diff --git a/src/parser/solparser.c b/src/parser/solparser.c
@@ -206,7 +206,6 @@ struct solparser {
struct solparser_sun sun; /* The loaded sun */
/* Entity */
- struct htable_yaml2sols yaml2entities; /* Cache of entities */
struct htable_str2sols str2entities;
struct darray_entity entities;
@@ -404,7 +403,6 @@ parser_clear(struct solparser* parser)
parser->sun_key = 0;
/* Entities */
- htable_yaml2sols_clear(&parser->yaml2entities);
htable_str2sols_clear(&parser->str2entities);
darray_entity_clear(&parser->entities);
@@ -455,7 +453,6 @@ parser_release(ref_T* ref)
solparser_sun_release(&parser->sun);
/* Entities */
- htable_yaml2sols_release(&parser->yaml2entities);
htable_str2sols_release(&parser->str2entities);
darray_entity_release(&parser->entities);
@@ -2600,7 +2597,6 @@ parse_entity
enum { ANCHORS, CHILDREN, DATA, NAME, TRANSFORM, PRIMARY };
struct solparser_entity solent;
struct solparser_entity* psolent;
- const size_t *pisolent;
size_t isolent = SIZE_MAX;
intptr_t i, n;
int mask = 0; /* Register the parsed attributes */
@@ -2609,14 +2605,6 @@ parse_entity
solparser_entity_init(parser->allocator, &solent);
- pisolent = htable_yaml2sols_find(&parser->yaml2entities, &entity);
- if(pisolent) {
- isolent = *pisolent;
- res = entity_register_name(parser, entity, htable, *pisolent);
- if(res != RES_OK) goto error;
- goto exit;
- }
-
if(entity->type != YAML_MAPPING_NODE) {
log_err(parser, entity, "expect an entity definition.\n");
res = RES_BAD_ARG;
@@ -2738,12 +2726,6 @@ parse_entity
res = entity_register_name(parser, entity, htable, isolent);
if(res != RES_OK) goto error;
- res = htable_yaml2sols_set(&parser->yaml2entities, &entity, &isolent);
- if(res != RES_OK) {
- log_err(parser, entity, "could not register the entity.\n");
- goto error;
- }
-
exit:
solparser_entity_release(&solent);
out_isolent->i = isolent;
@@ -3473,7 +3455,6 @@ solparser_create
solparser_sun_init(mem_allocator, &parser->sun);
/* Entities */
- htable_yaml2sols_init(mem_allocator, &parser->yaml2entities);
htable_str2sols_init(mem_allocator, &parser->str2entities);
darray_entity_init(mem_allocator, &parser->entities);
diff --git a/src/parser/solparser_pivot.h b/src/parser/solparser_pivot.h
@@ -18,15 +18,9 @@
#include <rsys/double3.h>
-enum solparser_target_type {
- SOLPARSER_TARGET_ANCHOR,
- SOLPARSER_TARGET_DIRECTION,
- SOLPARSER_TARGET_POSITION,
- SOLPARSER_TARGET_SUN,
-
- SOLPARSER_TARGET_TYPES_COUNT__
-};
-
+/*******************************************************************************
+ * Anchor
+ ******************************************************************************/
struct solparser_anchor_id { size_t i; };
struct solparser_anchor {
@@ -67,6 +61,18 @@ solparser_anchor_copy_and_release
return str_copy_and_release(&dst->name, &src->name);
}
+/*******************************************************************************
+ * Target
+ ******************************************************************************/
+enum solparser_target_type {
+ SOLPARSER_TARGET_ANCHOR,
+ SOLPARSER_TARGET_DIRECTION,
+ SOLPARSER_TARGET_POSITION,
+ SOLPARSER_TARGET_SUN,
+
+ SOLPARSER_TARGET_TYPES_COUNT__
+};
+
struct solparser_target {
enum solparser_target_type type;
union {
@@ -75,10 +81,14 @@ struct solparser_target {
struct solparser_anchor_id anchor;
} data;
};
-#define SOLPARSER_TARGET_NULL__ { SOLPARSER_TARGET_TYPES_COUNT__, {{0,0,0}} }
+#define SOLPARSER_TARGET_NULL__ { 0 }
static const struct solparser_target SOLPARSER_TARGET_NULL =
SOLPARSER_TARGET_NULL__;
+
+/*******************************************************************************
+ * X pivot
+ ******************************************************************************/
struct solparser_pivot_id { size_t i; };
struct solparser_x_pivot {
@@ -92,12 +102,16 @@ static const struct solparser_x_pivot SOLPARSER_X_PIVOT_NULL =
static INLINE void
solparser_x_pivot_init
-(struct mem_allocator* allocator, struct solparser_x_pivot* x_pivot)
+ (struct mem_allocator* allocator, struct solparser_x_pivot* x_pivot)
{
- (void) allocator;
+ (void)allocator;
ASSERT(x_pivot);
*x_pivot = SOLPARSER_X_PIVOT_NULL;
}
+
+/*******************************************************************************
+ * ZX pivot
+ ******************************************************************************/
struct solparser_zx_pivot {
double spacing;
double ref_point[3];
@@ -112,7 +126,7 @@ static INLINE void
solparser_zx_pivot_init
(struct mem_allocator* allocator, struct solparser_zx_pivot* zx_pivot)
{
- (void) allocator;
+ (void)allocator;
ASSERT(zx_pivot);
*zx_pivot = SOLPARSER_ZX_PIVOT_NULL;
}