diff options
Diffstat (limited to 'Build/source/utils/asymptote/entry.h')
-rw-r--r-- | Build/source/utils/asymptote/entry.h | 95 |
1 files changed, 50 insertions, 45 deletions
diff --git a/Build/source/utils/asymptote/entry.h b/Build/source/utils/asymptote/entry.h index 66d98628d05..d465046961c 100644 --- a/Build/source/utils/asymptote/entry.h +++ b/Build/source/utils/asymptote/entry.h @@ -165,7 +165,7 @@ inline tyEntry *qualifyTyEntry(varEntry *qv, tyEntry *ent) { // The type environment. class tenv : public sym::table<tyEntry *> { - bool add(symbol *dest, names_t::value_type &x, varEntry *qualifier, + bool add(symbol dest, names_t::value_type &x, varEntry *qualifier, coder &c); public: // Add the entries in one environment to another, if qualifier is @@ -175,46 +175,38 @@ public: // Adds entries of the name src in source as the name dest, returning true if // any were added. - bool add(symbol *src, symbol *dest, + bool add(symbol src, symbol dest, tenv& source, varEntry *qualifier, coder &c); }; #ifdef NOHASH //{{{ class venv : public sym::table<varEntry*> { + /* This version of venv is provided for compiling on systems which do not + * have some form of STL hash table. It will eventually be removed. + * See the hash version below for documentation on the functions. + */ public: venv() {} - // This is an optimization in the hashtable version that is duplicated here - // for compatibility. It is identical to venv(). struct file_env_tag {}; venv(file_env_tag) {} -#if 0 - // Look for a function that exactly matches the signature given. - varEntry *lookExact(symbol *name, signature *key); -#endif - - // Add the entries in one environment to another, if qualifier is - // non-null, it is a record and the source environment are its fields. - // The coder is necessary to check which variables are accessible and - // should be added. void add(venv& source, varEntry *qualifier, coder &c); - // Add all unshadowed variables from source of the name src as variables - // named dest. Returns true if at least one was added. - bool add(symbol *src, symbol *dest, + bool add(symbol src, symbol dest, venv& source, varEntry *qualifier, coder &c); - // Look for a function that exactly matches the type given. - varEntry *lookByType(symbol *name, ty *t); + varEntry *lookByType(symbol name, ty *t); - // Return the type of the variable, if name is overloaded, return an - // overloaded type. - ty *getType(symbol *name); + varEntry *lookBySignature(symbol name, signature *sig) { + // This optimization is not implemented for the NOHASH version. + return 0; + } + + ty *getType(symbol name); friend std::ostream& operator<< (std::ostream& out, const venv& ve); - // Prints a list of the variables to the standard output. void list(record *module=0); }; @@ -224,20 +216,20 @@ public: // venv implemented with a hash table. class venv { struct key : public gc { - symbol *name; + symbol name; ty *t; - key(symbol *name, ty *t) + key(symbol name, ty *t) : name(name), t(t) {} /* A fake key used for searching just based on a signature. */ - key(symbol *name, signature *sig) + key(symbol name, signature *sig) : name(name), t(new types::function(types::primError(), sig)) { - assert(!name->special); + assert(!name.special()); } - key(symbol *name, varEntry *v) + key(symbol name, varEntry *v) : name(name), t(v->getType()) {} }; friend ostream& operator<< (ostream& out, const venv::key &k); @@ -247,16 +239,22 @@ class venv { bool shadowed; value *next; // The entry (of the same key) that this one shadows. +#ifdef CALLEE_SEARCH + // The maximum number of formals in any of the overloaded functions of + // this name (at the time this value was entered). + size_t maxFormals; +#endif + value(varEntry *v) : v(v), shadowed(false), next(0) {} }; struct namehash { - size_t operator()(const symbol *name) const { - return (size_t)name; + size_t operator()(const symbol name) const { + return name.hash(); } }; struct nameeq { - bool operator()(const symbol *s, const symbol *t) const { + bool operator()(const symbol s, const symbol t) const { return s==t; } }; @@ -266,8 +264,8 @@ class venv { return sig ? sig->hash() : 0; } size_t operator()(const key k) const { - return (size_t)(k.name) * 107 + - (k.name->special ? k.t->hash() : hashSig(k.t)); + return k.name.hash() * 107 + + (k.name.special() ? k.t->hash() : hashSig(k.t)); } }; struct keyeq { @@ -275,7 +273,7 @@ class venv { #if TEST_COLLISION bool base(const key k, const key l) const { return k.name==l.name && - (k.name->special ? equivalent(k.t, l.t) : + (k.name->special() ? equivalent(k.t, l.t) : equivalent(k.t->getSignature(), l.t->getSignature())); } @@ -300,10 +298,10 @@ class venv { // all values of that name. Used to get the (possibly overloaded) type // of the name. typedef mem::list<value *> values; - typedef mem::unordered_map<symbol *, values, namehash, nameeq> namemap; + typedef mem::unordered_map<symbol, values, namehash, nameeq> namemap; namemap names; - void listValues(symbol *name, values &vals, record *module); + void listValues(symbol name, values &vals, record *module); // Helper function for endScope. void remove(key k); @@ -326,7 +324,7 @@ public: beginScope(); } - void enter(symbol *name, varEntry *v); + void enter(symbol name, varEntry *v); // Add the entries in one environment to another, if qualifier is // non-null, it is a record and entries of the source environment are its @@ -336,7 +334,7 @@ public: // Add all unshadowed variables from source of the name src as variables // named dest. Returns true if at least one was added. - bool add(symbol *src, symbol *dest, + bool add(symbol src, symbol dest, venv& source, varEntry *qualifier, coder &c); varEntry *lookByType(key k) { @@ -345,18 +343,25 @@ public: } // Look for a function that exactly matches the type given. - varEntry *lookByType(symbol *name, ty *t) { + varEntry *lookByType(symbol name, ty *t) { return lookByType(key(name, t)); } // An optimization heuristic. Try to guess the signature of a variable and // look it up. This is allowed to return 0 even if the appropriate variable - // exists. - varEntry *lookBySignature(symbol *name, signature *sig) { - return name->special ? 0 : lookByType(key(name, sig)); - } - - ty *getType(symbol *name); + // exists. If it returns a varEntry from an overloaded number of choices, + // the returned function must be the one which would be called with + // arguments given by sig, and its signature must be equivalent to sig. + // For instance, in + // int f(int a, int b); + // int f(int a, int b, int c = 1); + // f(a,b); + // looking up the signature of 'f' with arguments (int, int) must return 0 + // as there is an ambiguity. The maxFormals field is used to ensure we + // avoid such ambiguities. + varEntry *lookBySignature(symbol name, signature *sig); + + ty *getType(symbol name); void beginScope() { scopes.push(keymultimap()); @@ -384,7 +389,7 @@ public: void list(record *module=0); // Adds to l, all names prefixed by start. - void completions(mem::list<symbol *>& l, string start); + void completions(mem::list<symbol>& l, string start); }; #endif |