summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/env.h
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2009-05-16 00:19:13 +0000
committerKarl Berry <karl@freefriends.org>2009-05-16 00:19:13 +0000
commitbab45528d65eaafe68a705dbb2a57075c7b7cbd8 (patch)
tree10b4ae2b5195c8dede153ab89359ec00f55f325f /Build/source/utils/asymptote/env.h
parent8643d90372e9c31e0f461c15c596b60a545bd7d3 (diff)
asymptote 1.72 sources (not integrated into build yet)
git-svn-id: svn://tug.org/texlive/trunk@13110 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/env.h')
-rw-r--r--Build/source/utils/asymptote/env.h175
1 files changed, 175 insertions, 0 deletions
diff --git a/Build/source/utils/asymptote/env.h b/Build/source/utils/asymptote/env.h
new file mode 100644
index 00000000000..221ff98df81
--- /dev/null
+++ b/Build/source/utils/asymptote/env.h
@@ -0,0 +1,175 @@
+/*****
+ * env.h
+ * Andy Hammerlindl 2002/6/20
+ *
+ * Keeps track of the namespaces of variables and types when traversing
+ * the abstract syntax.
+ *****/
+
+#ifndef ENV_H
+#define ENV_H
+
+#include "errormsg.h"
+#include "entry.h"
+#include "types.h"
+#include "util.h"
+
+namespace types {
+class record;
+}
+
+namespace trans {
+
+using sym::symbol;
+using types::ty;
+using types::function;
+using types::record;
+
+class genv;
+
+// Keeps track of the name bindings of variables and types. This is used for
+// the fields of a record, whereas the derived class env is used for unqualified
+// names in translation.
+class protoenv {
+//protected:
+public:
+ // These tables keep track of type and variable definitions.
+ tenv te;
+ venv ve;
+
+ access *baseLookupCast(ty *target, ty *source, symbol *name);
+
+public:
+ // Start an environment for a file-level module.
+ protoenv() {}
+
+ protoenv(venv::file_env_tag tag)
+ : ve(tag) {}
+
+ protoenv(const protoenv&);
+
+ void beginScope()
+ {
+ te.beginScope(); ve.beginScope();
+ }
+ void endScope()
+ {
+ te.endScope(); ve.endScope();
+ }
+ void collapseScope()
+ {
+ te.collapseScope(); ve.collapseScope();
+ }
+
+ tyEntry *lookupTyEntry(symbol *s)
+ {
+ return te.look(s);
+ }
+
+ ty *lookupType(symbol *s)
+ {
+ tyEntry *ent=lookupTyEntry(s);
+ return ent ? ent->t : 0;
+ }
+
+ varEntry *lookupVarByType(symbol *name, ty *t)
+ {
+ // Search in local vars.
+ return ve.lookByType(name, t);
+ }
+
+ access *lookupInitializer(ty *t)
+ {
+ // The initializer's type is a function returning the desired type.
+ function *it=new function(t);
+ varEntry *v=lookupVarByType(symbol::initsym,it);
+
+ // If not in the environment, try the type itself.
+ return v ? v->getLocation() : t->initializer();
+ }
+
+ // Find the function that handles casting between the types.
+ // The name is "operator cast" for implicitCasting and "operator ecast" for
+ // explicit.
+ access *lookupCast(ty *target, ty *source, symbol *name);
+ bool castable(ty *target, ty *source, symbol *name);
+
+ // Given overloaded types, this resolves which types should be the target and
+ // the source of the cast.
+ ty *castTarget(ty *target, ty *source, symbol *name);
+ ty *castSource(ty *target, ty *source, symbol *name);
+
+ ty *varGetType(symbol *name)
+ {
+ return ve.getType(name);
+ }
+
+ void addType(symbol *name, tyEntry *desc)
+ {
+ te.enter(name, desc);
+ }
+
+ void addVar(symbol *name, varEntry *desc)
+ {
+ // Don't check for multiple variables, as this makes adding casts
+ // and initializers harder.
+ ve.enter(name, desc);
+ }
+
+ // Add another environment, say from a record.
+ void add(protoenv &source, varEntry *qualifier, coder &c)
+ {
+ te.add(source.te, qualifier, c);
+ ve.add(source.ve, qualifier, c);
+ }
+
+ // Add variables and types of name src from another environment under the
+ // name dest in this environment.
+ bool add(symbol *src, symbol *dest,
+ protoenv &source, varEntry *qualifier, coder &c)
+ {
+ return te.add(src, dest, source.te, qualifier, c) |
+ ve.add(src, dest, source.ve, qualifier, c);
+ }
+
+ // Add the standard functions for a new type.
+ void addArrayOps(types::array *t);
+ void addRecordOps(types::record *r);
+ void addFunctionOps(types::function *f);
+
+ void list(record *r=0)
+ {
+ ve.list(r);
+ }
+
+ // Adds to a list the keywords in the environment that start with the given
+ // prefix. Used for automatic completion at the interactive prompt.
+ typedef mem::list<symbol *> symbol_list;
+ void completions(symbol_list &l, string start)
+ {
+ te.completions(l, start);
+ ve.completions(l, start);
+ }
+
+private: // Non-copyable
+ void operator=(const protoenv&);
+};
+
+// Environment used in translating statements and expressions at all scopes. As
+// opposed to protoenv which is suitable for keeping track of the fields of
+// records, this also keeps track of the global env, for loading modules.
+class env : public protoenv {
+ // The global environment - keeps track of modules.
+ genv &ge;
+public:
+ // Start an environment for a file-level module.
+ env(genv &ge);
+
+ ~env();
+
+ record *getModule(symbol *id, string filename);
+};
+
+} // namespace trans
+
+#endif