about summary refs log tree commit diff stats
path: root/018type_abbreviations.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-09-11 19:10:59 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-09-11 19:10:59 -0700
commit2224e41fd7416ebd00820e07ad23a7d6d419a70b (patch)
treec90b6379f7abf03f3ac9a3e79000254cb93b080c /018type_abbreviations.cc
parentb7a38a1dd4dedbb4c83dcc61801aa588420543b4 (diff)
downloadmu-2224e41fd7416ebd00820e07ad23a7d6d419a70b.tar.gz
3331
Diffstat (limited to '018type_abbreviations.cc')
-rw-r--r--018type_abbreviations.cc49
1 files changed, 26 insertions, 23 deletions
diff --git a/018type_abbreviations.cc b/018type_abbreviations.cc
index 99491d79..d3e84050 100644
--- a/018type_abbreviations.cc
+++ b/018type_abbreviations.cc
@@ -1,4 +1,4 @@
-//: For convenience, make some common types shorter.
+//: For convenience, allow Mu types to be abbreviated.
 
 :(scenarios transform)
 :(scenario type_abbreviations)
@@ -8,30 +8,10 @@ def main [
 ]
 +transform: product type after expanding abbreviations: "number"
 
-//:: Allow type abbreviations to be defined in mu code.
-
 :(before "End Globals")
 map<string, type_tree*> Type_abbreviations, Type_abbreviations_snapshot;
-:(before "End save_snapshots")
-Type_abbreviations_snapshot = Type_abbreviations;
-:(before "End restore_snapshots")
-restore_type_abbreviations();
-:(before "End One-time Setup")
-atexit(clear_type_abbreviations);
-:(code)
-void restore_type_abbreviations() {
-  for (map<string, type_tree*>::iterator p = Type_abbreviations.begin(); p != Type_abbreviations.end(); ++p) {
-    if (!contains_key(Type_abbreviations_snapshot, p->first))
-      delete p->second;
-  }
-  Type_abbreviations.clear();
-  Type_abbreviations = Type_abbreviations_snapshot;
-}
-void clear_type_abbreviations() {
-  for (map<string, type_tree*>::iterator p = Type_abbreviations.begin(); p != Type_abbreviations.end(); ++p)
-    delete p->second;
-  Type_abbreviations.clear();
-}
+
+//:: Defining type abbreviations.
 
 :(before "End Command Handlers")
 else if (command == "type") {
@@ -117,6 +97,29 @@ def main [
 ]
 +transform: product type after expanding abbreviations: ("address" "number")
 
+//: cleaning up type abbreviations between tests and before exiting
+
+:(before "End save_snapshots")
+Type_abbreviations_snapshot = Type_abbreviations;
+:(before "End restore_snapshots")
+restore_type_abbreviations();
+:(before "End One-time Setup")
+atexit(clear_type_abbreviations);
+:(code)
+void restore_type_abbreviations() {
+  for (map<string, type_tree*>::iterator p = Type_abbreviations.begin(); p != Type_abbreviations.end(); ++p) {
+    if (!contains_key(Type_abbreviations_snapshot, p->first))
+      delete p->second;
+  }
+  Type_abbreviations.clear();
+  Type_abbreviations = Type_abbreviations_snapshot;
+}
+void clear_type_abbreviations() {
+  for (map<string, type_tree*>::iterator p = Type_abbreviations.begin(); p != Type_abbreviations.end(); ++p)
+    delete p->second;
+  Type_abbreviations.clear();
+}
+
 //:: A few default abbreviations.
 
 :(before "End Mu Types Initialization")