about summary refs log tree commit diff stats
path: root/030container.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-09-12 00:47:44 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-09-12 00:47:44 -0700
commite2b367dc2548ab80fc3e0949ee4f327c1c447758 (patch)
treee5562a63b46356cd1757a2ac24ebe0e07fce597c /030container.cc
parentea19d0dc2c11f48ca384fb087b4e44ef400bfaa2 (diff)
downloadmu-e2b367dc2548ab80fc3e0949ee4f327c1c447758.tar.gz
3338
Process type abbreviations in container definitions.
Diffstat (limited to '030container.cc')
-rw-r--r--030container.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/030container.cc b/030container.cc
index 986e9581..4ef56d74 100644
--- a/030container.cc
+++ b/030container.cc
@@ -781,6 +781,31 @@ container foo [
 ]
 +error: container 'foo' contains multiple elements on a single line. Containers and exclusive containers must only contain elements, one to a line, no code.
 
+//: support type abbreviations in container definitions
+
+:(scenario type_abbreviations_in_containers)
+type foo = number
+container bar [
+  x:foo
+]
+def main [
+  1:number <- copy 34
+  2:foo <- get 1:bar/unsafe, 0:offset
+]
++mem: storing 34 in location 2
+
+:(after "Transform.push_back(expand_type_abbreviations)")
+Transform.push_back(expand_type_abbreviations_in_containers);
+:(code)
+// extremely inefficient; we process all types over and over again, once for every single recipe
+// but it doesn't seem to cause any noticeable slowdown
+void expand_type_abbreviations_in_containers(unused const recipe_ordinal r) {
+  for (map<type_ordinal, type_info>::iterator p = Type.begin(); p != Type.end(); ++p) {
+    for (int i = 0; i < SIZE(p->second.elements); ++i)
+      expand_type_abbreviations(p->second.elements.at(i).type);
+  }
+}
+
 //: ensure scenarios are consistent by always starting new container
 //: declarations at the same type number
 :(before "End Setup")  //: for tests