int leaf;
};
-struct ctables_section_value
+struct ctables_occurrence
{
struct hmap_node node;
union value value;
msg_at (SE, pc_cat->location,
_("Computed category &%s references a category not included "
"in the category list."),
- cat->pc->name);
+ pc_cat->pc->name);
msg_at (SN, e->location, _("This is the missing category."));
msg_at (SN, cats_location,
_("To fix the problem, add the missing category to the "
int width = var_get_width (var);
unsigned int hash = value_hash (value, width, 0);
- struct ctables_section_value *sv;
- HMAP_FOR_EACH_WITH_HASH (sv, struct ctables_section_value, node, hash,
+ struct ctables_occurrence *o;
+ HMAP_FOR_EACH_WITH_HASH (o, struct ctables_occurrence, node, hash,
occurrences)
- if (value_equal (value, &sv->value, width))
+ if (value_equal (value, &o->value, width))
return;
- sv = xmalloc (sizeof *sv);
- value_clone (&sv->value, value, width);
- hmap_insert (occurrences, &sv->node, hash);
+ o = xmalloc (sizeof *o);
+ value_clone (&o->value, value, width);
+ hmap_insert (occurrences, &o->node, hash);
}
static void
static double
ctables_pcexpr_evaluate_category (const struct ctables_pcexpr_evaluate_ctx *ctx,
- const struct ctables_category *cat)
+ const struct ctables_cell_value *pc_cv)
{
const struct ctables_section *s = ctx->section;
{
const struct ctables_nest *nest = s->nests[a];
for (size_t i = 0; i < nest->n; i++)
- if (a == ctx->pc_a && i == ctx->pc_a_idx)
- {
- /* XXX anything other than just a constant.... need a higher level
- loop to go through occurrences */
- hash = hash_pointer (cat, hash);
- hash = hash_double (cat->number, hash);
- }
- else if (i != nest->scale_idx)
+ if (i != nest->scale_idx)
{
- const struct ctables_cell_value *cv = &ctx->cell->axes[a].cvs[i];
+ const struct ctables_cell_value *cv
+ = (a == ctx->pc_a && i == ctx->pc_a_idx ? pc_cv
+ : &ctx->cell->axes[a].cvs[i]);
hash = hash_pointer (cv->category, hash);
if (cv->category->type != CCT_TOTAL
&& cv->category->type != CCT_SUBTOTAL
{
const struct ctables_nest *nest = s->nests[a];
for (size_t i = 0; i < nest->n; i++)
- {
- const struct ctables_cell_value *p_cv = &ctx->cell->axes[a].cvs[i];
- const struct ctables_cell_value *t_cv = &tc->axes[a].cvs[i];
-
- if (i == nest->scale_idx)
- {
- /* Nothing to do. */
- }
- else if (a == ctx->pc_a && i == ctx->pc_a_idx)
- {
- /* XXX anything other than a constant.... */
- if (t_cv->category != cat || t_cv->value.f != cat->number)
- goto not_equal;
- }
- else if (p_cv->category != t_cv->category
- || (p_cv->category->type != CCT_TOTAL
- && p_cv->category->type != CCT_SUBTOTAL
- && p_cv->category->type != CCT_POSTCOMPUTE
- && !value_equal (&p_cv->value,
- &t_cv->value,
- var_get_width (nest->vars[i]))))
- goto not_equal;
- }
+ if (i != nest->scale_idx)
+ {
+ const struct ctables_cell_value *p_cv
+ = (a == ctx->pc_a && i == ctx->pc_a_idx ? pc_cv
+ : &ctx->cell->axes[a].cvs[i]);
+ const struct ctables_cell_value *t_cv = &tc->axes[a].cvs[i];
+ if (p_cv->category != t_cv->category
+ || (p_cv->category->type != CCT_TOTAL
+ && p_cv->category->type != CCT_SUBTOTAL
+ && p_cv->category->type != CCT_POSTCOMPUTE
+ && !value_equal (&p_cv->value,
+ &t_cv->value,
+ var_get_width (nest->vars[i]))))
+ goto not_equal;
+ }
}
goto found;
case CTPO_CONSTANT:
return e->number;
+ case CTPO_CAT_RANGE:
+ {
+ struct ctables_cell_value cv = {
+ .category = ctables_find_category_for_postcompute (ctx->cats, e)
+ };
+ assert (cv.category != NULL);
+
+ struct hmap *occurrences = &ctx->section->occurrences[ctx->pc_a][ctx->pc_a_idx];
+ const struct ctables_occurrence *o;
+
+ double sum = 0.0;
+ const struct variable *var = ctx->section->nests[ctx->pc_a]->vars[ctx->pc_a_idx];
+ HMAP_FOR_EACH (o, struct ctables_occurrence, node, occurrences)
+ if (ctables_categories_match (ctx->cats, &o->value, var) == cv.category)
+ {
+ cv.value = o->value;
+ sum += ctables_pcexpr_evaluate_category (ctx, &cv);
+ }
+ return sum;
+ }
+
case CTPO_CAT_NUMBER:
case CTPO_CAT_STRING:
- case CTPO_CAT_RANGE:
case CTPO_CAT_MISSING:
case CTPO_CAT_OTHERNM:
case CTPO_CAT_SUBTOTAL:
case CTPO_CAT_TOTAL:
{
- struct ctables_category *cat = ctables_find_category_for_postcompute (
- ctx->cats, e);
- assert (cat != NULL);
-
- return ctables_pcexpr_evaluate_category (ctx, cat);
+ struct ctables_cell_value cv = {
+ .category = ctables_find_category_for_postcompute (ctx->cats, e),
+ .value = { .f = e->number },
+ };
+ assert (cv.category != NULL);
+ return ctables_pcexpr_evaluate_category (ctx, &cv);
}
case CTPO_ADD:
var_get_dict_index (var)];
int width = var_get_width (var);
const struct hmap *occurrences = &s->occurrences[a][a_idx];
- const struct ctables_section_value *sv;
- HMAP_FOR_EACH (sv, struct ctables_section_value, node, occurrences)
+ const struct ctables_occurrence *o;
+ HMAP_FOR_EACH (o, struct ctables_occurrence, node, occurrences)
{
union value *value = case_data_rw (c, var);
value_destroy (value, width);
- value_clone (value, &sv->value, width);
+ value_clone (value, &o->value, width);
cats[a][a_idx] = ctables_categories_match (categories, value, var);
assert (cats[a][a_idx] != NULL);
ctables_section_recurse_add_empty_categories (s, cats, c, a, a_idx + 1);
const struct ctables_category *cat = &categories->cats[i];
if (cat->type == CCT_POSTCOMPUTE)
{
- printf ("%s:%d\n", __FILE__, __LINE__);
cats[a][a_idx] = cat;
ctables_section_recurse_add_empty_categories (s, cats, c, a, a_idx + 1);
}