diff options
author | Kartik Agaram <vc@akkartik.com> | 2018-06-09 08:59:33 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2018-06-09 09:50:35 -0700 |
commit | 3f34ac9369978b396d00a4fd02c9fb06b8eea621 (patch) | |
tree | eb1899f86308c712e54ef94a1c85243c26621c45 /033exclusive_container.cc | |
parent | 46b6e2a34915a6d5cf7b1b15b3d2c28f54e02622 (diff) | |
download | mu-3f34ac9369978b396d00a4fd02c9fb06b8eea621.tar.gz |
4256 - get rid of container metadata entirely
We have some ugly duplication in computing size_of on containers between layers 30/33 and 55.
Diffstat (limited to '033exclusive_container.cc')
-rw-r--r-- | 033exclusive_container.cc | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/033exclusive_container.cc b/033exclusive_container.cc index 29a524c9..44161d7c 100644 --- a/033exclusive_container.cc +++ b/033exclusive_container.cc @@ -15,9 +15,9 @@ get(Type, tmp).elements.push_back(reagent("i:number")); get(Type, tmp).elements.push_back(reagent("p:point")); } -//: Tests in this layer often explicitly set up memory before reading it as an -//: array. Don't do this in general. I'm tagging exceptions with /raw to keep -//: checks in future layers from flagging them. +//: Tests in this layer often explicitly set up memory before reading it as a +//: container. Don't do this in general. I'm tagging such cases with /unsafe; +//: they'll be exceptions to later checks. :(scenario copy_exclusive_container) # Copying exclusive containers copies all their contents and an extra location for the tag. def main [ @@ -32,30 +32,17 @@ def main [ :(before "End size_of(type) Special-cases") if (t.kind == EXCLUSIVE_CONTAINER) { - // Compute size_of Exclusive Container - return get(Container_metadata, type).size; -} -:(before "End compute_container_sizes Atom Special-cases") -if (info.kind == EXCLUSIVE_CONTAINER) { - compute_exclusive_container_sizes(info, type, pending_metadata, location_for_error_messages); -} - -:(code) -void compute_exclusive_container_sizes(const type_info& exclusive_container_info, const type_tree* full_type, set<type_tree>& pending_metadata, const string& location_for_error_messages) { // size of an exclusive container is the size of its largest variant - // (So, like containers, it can only contain arrays if they're static and - // include their length in the type.) - container_metadata metadata; - for (int i = 0; i < SIZE(exclusive_container_info.elements); ++i) { - reagent/*copy*/ element = exclusive_container_info.elements.at(i); - // Compute Exclusive Container Size(element, full_type) - compute_container_sizes(element.type, pending_metadata, location_for_error_messages); - int variant_size = size_of(element); - if (variant_size > metadata.size) metadata.size = variant_size; + // (So like containers, it can't contain arrays.) + int result = 0; + for (int i = 0; i < SIZE(t.elements); ++i) { + reagent tmp; + tmp.type = new type_tree(*type); + int size = size_of(variant_type(tmp, i)); + if (size > result) result = size; } // ...+1 for its tag. - ++metadata.size; - Container_metadata.push_back(pair<type_tree*, container_metadata>(new type_tree(*full_type), metadata)); + return result+1; } //:: To access variants of an exclusive container, use 'maybe-convert'. |