summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/exp.h
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/utils/asymptote/exp.h')
-rw-r--r--Build/source/utils/asymptote/exp.h100
1 files changed, 66 insertions, 34 deletions
diff --git a/Build/source/utils/asymptote/exp.h b/Build/source/utils/asymptote/exp.h
index 425bcc91788..f3d086dcba3 100644
--- a/Build/source/utils/asymptote/exp.h
+++ b/Build/source/utils/asymptote/exp.h
@@ -45,9 +45,9 @@ public:
// function f(int)" instead of "no function matching signature
// (int)." Hence, this method returns the name of the expression if
// there is one.
- virtual symbol *getName()
+ virtual symbol getName()
{
- return 0;
+ return symbol::nullsym;
}
// Checks if the expression can be used as the right side of a scale
@@ -101,12 +101,21 @@ public:
// error.
virtual types::ty *getType(coenv &) = 0;
- // TODO: Explain what this is!
+ // This is an optimization which works in some cases to by-pass the slow
+ // overloaded function resolution provided by the application class.
+ //
+ // If an expression is called with arguments given by sig, getCallee must
+ // either return 0 (the default), or if it returns a varEntry, the varEntry
+ // must correspond to the function which would be called after normal
+ // function resolution.
+ //
+ // The callee must produce no side effects as there are no guarantees when
+ // the varEntry will be translated.
virtual trans::varEntry *getCallee(coenv &e, types::signature *sig) {
//#define DEBUG_GETAPP
#if DEBUG_GETAPP
cout << "exp fail" << endl;
- cout << "at " << getPos() << endl;
+ cout << "exp fail at " << getPos() << endl;
prettyprint(cout, 2);
#endif
return 0;
@@ -177,6 +186,7 @@ public:
};
// Wrap a varEntry so that it can be used as an expression.
+// Translating the varEntry must cause no side-effects.
class varEntryExp : public exp {
trans::varEntry *v;
public:
@@ -189,6 +199,7 @@ public:
types::ty *getType(coenv &);
types::ty *trans(coenv &e);
+ trans::varEntry *getCallee(coenv &e, types::signature *sig);
void transAct(action act, coenv &e, types::ty *target);
void transAsType(coenv &e, types::ty *target);
@@ -203,7 +214,7 @@ public:
nameExp(position pos, name *value)
: exp(pos), value(value) {}
- nameExp(position pos, symbol *id)
+ nameExp(position pos, symbol id)
: exp(pos), value(new simpleName(pos, id)) {}
nameExp(position pos, string s)
@@ -211,7 +222,7 @@ public:
void prettyprint(ostream &out, Int indent);
- symbol *getName()
+ symbol getName()
{
return value->getName();
}
@@ -278,7 +289,7 @@ public:
// like f().x or (new t).x, a separate expression is needed.
class fieldExp : public nameExp {
exp *object;
- symbol *field;
+ symbol field;
// fieldExp has a lot of common functionality with qualifiedName, so we
// essentially hack qualifiedName, by making our object expression look
@@ -334,7 +345,7 @@ class fieldExp : public nameExp {
void print(ostream& out) const {
out << "<exp>";
}
- symbol *getName() {
+ symbol getName() {
return object->getName();
}
};
@@ -343,7 +354,7 @@ class fieldExp : public nameExp {
types::ty *getObject(coenv &e);
public:
- fieldExp(position pos, exp *object, symbol *field)
+ fieldExp(position pos, exp *object, symbol field)
: nameExp(pos, new qualifiedName(pos,
new pseudoName(object),
field)),
@@ -351,7 +362,7 @@ public:
void prettyprint(ostream &out, Int indent);
- symbol *getName()
+ symbol getName()
{
return field;
}
@@ -512,6 +523,8 @@ public:
types::ty *trans(coenv &e);
types::ty *getType(coenv &) { return types::primString(); }
+
+ const string& getString() { return str; }
};
class booleanExp : public literalExp {
@@ -616,10 +629,11 @@ public:
struct argument {
exp *val;
- symbol *name;
+ symbol name;
+ // No constructor due to the union in camp.y
#if 0
- argument(exp *val=0, symbol *name=0)
+ argument(exp *val=0, symbol name=0)
: val(val), name(name) {}
#endif
@@ -641,7 +655,7 @@ public:
args.insert(args.begin(), a);
}
- virtual void addFront(exp *val, symbol *name=0) {
+ virtual void addFront(exp *val, symbol name=symbol::nullsym) {
argument a; a.val=val; a.name=name;
addFront(a);
}
@@ -650,7 +664,7 @@ public:
args.push_back(a);
}
- virtual void add(exp *val, symbol *name=0) {
+ virtual void add(exp *val, symbol name=symbol::nullsym) {
argument a; a.val=val; a.name=name;
add(a);
}
@@ -703,8 +717,8 @@ private:
void reportNonFunction();
// Caches either the application object used to apply the function to the
- // arguments, or in special cases where the arguments match the function
- // perfectly, the varEntry of the callee.
+ // arguments, or in cases where the arguments match the function perfectly,
+ // the varEntry of the callee.
void cacheAppOrVarEntry(coenv &e, bool tacit);
types::ty *transPerfectMatch(coenv &e);
@@ -742,6 +756,10 @@ public:
types::ty *trans(coenv &e);
types::ty *getType(coenv &e);
+
+ // Returns true if the function call resolves uniquely without error. Used
+ // in implementing the special == and != operators for functions.
+ virtual bool resolved(coenv &e);
};
@@ -795,7 +813,7 @@ class castExp : public exp {
exp *castee;
types::ty *tryCast(coenv &e, types::ty *t, types::ty *s,
- symbol *csym);
+ symbol csym);
public:
castExp(position pos, ty *target, exp *castee)
: exp(pos), target(target), castee(castee) {}
@@ -808,22 +826,36 @@ public:
class nullaryExp : public callExp {
public:
- nullaryExp(position pos, symbol *op)
+ nullaryExp(position pos, symbol op)
: callExp(pos, new nameExp(pos, op)) {}
};
class unaryExp : public callExp {
public:
- unaryExp(position pos, exp *base, symbol *op)
+ unaryExp(position pos, exp *base, symbol op)
: callExp(pos, new nameExp(pos, op), base) {}
};
class binaryExp : public callExp {
public:
- binaryExp(position pos, exp *left, symbol *op, exp *right)
+ binaryExp(position pos, exp *left, symbol op, exp *right)
+ : callExp(pos, new nameExp(pos, op), left, right) {}
+};
+
+class equalityExp : public callExp {
+public:
+ equalityExp(position pos, exp *left, symbol op, exp *right)
: callExp(pos, new nameExp(pos, op), left, right) {}
+
+ void prettyprint(ostream &out, Int indent);
+
+#ifdef NO_FUNC_OPS
+ types::ty *trans(coenv &e);
+ types::ty *getType(coenv &e);
+#endif
};
+
// Scaling expressions such as 3sin(x).
class scaleExp : public binaryExp {
exp *getLeft() {
@@ -848,7 +880,7 @@ public:
// is a tension atleast case.
class ternaryExp : public callExp {
public:
- ternaryExp(position pos, exp *left, symbol *op, exp *right, exp *last)
+ ternaryExp(position pos, exp *left, symbol op, exp *right, exp *last)
: callExp(pos, new nameExp(pos, op), left, right, last) {}
};
@@ -875,11 +907,11 @@ public:
class andOrExp : public exp {
protected:
exp *left;
- symbol *op;
+ symbol op;
exp *right;
public:
- andOrExp(position pos, exp *left, symbol *op, exp *right)
+ andOrExp(position pos, exp *left, symbol op, exp *right)
: exp(pos), left(left), op(op), right(right) {}
virtual types::ty *trans(coenv &e) = 0;
@@ -890,7 +922,7 @@ public:
class orExp : public andOrExp {
public:
- orExp(position pos, exp *left, symbol *op, exp *right)
+ orExp(position pos, exp *left, symbol op, exp *right)
: andOrExp(pos, left, op, right) {}
void prettyprint(ostream &out, Int indent);
@@ -900,7 +932,7 @@ public:
class andExp : public andOrExp {
public:
- andExp(position pos, exp *left, symbol *op, exp *right)
+ andExp(position pos, exp *left, symbol op, exp *right)
: andOrExp(pos, left, op, right) {}
void prettyprint(ostream &out, Int indent);
@@ -910,7 +942,7 @@ public:
class joinExp : public callExp {
public:
- joinExp(position pos, symbol *op)
+ joinExp(position pos, symbol op)
: callExp(pos, new nameExp(pos, op)) {}
void pushFront(exp *e) {
@@ -924,12 +956,12 @@ public:
};
class specExp : public exp {
- symbol *op;
+ symbol op;
exp *arg;
camp::side s;
public:
- specExp(position pos, symbol *op, exp *arg, camp::side s=camp::OUT)
+ specExp(position pos, symbol op, exp *arg, camp::side s=camp::OUT)
: exp(pos), op(op), arg(arg), s(s) {}
void setSide(camp::side ss) {
@@ -969,14 +1001,14 @@ public:
};
class selfExp : public assignExp {
- symbol *op;
+ symbol op;
exp *ultimateValue(exp *dest) {
return new binaryExp(getPos(), dest, op, value);
}
public:
- selfExp(position pos, exp *dest, symbol *op, exp *value)
+ selfExp(position pos, exp *dest, symbol op, exp *value)
: assignExp(pos, dest, value), op(op) {}
void prettyprint(ostream &out, Int indent);
@@ -984,10 +1016,10 @@ public:
class prefixExp : public exp {
exp *dest;
- symbol *op;
+ symbol op;
public:
- prefixExp(position pos, exp *dest, symbol *op)
+ prefixExp(position pos, exp *dest, symbol op)
: exp(pos), dest(dest), op(op) {}
void prettyprint(ostream &out, Int indent);
@@ -1006,10 +1038,10 @@ public:
// error."
class postfixExp : public exp {
exp *dest;
- symbol *op;
+ symbol op;
public:
- postfixExp(position pos, exp *dest, symbol *op)
+ postfixExp(position pos, exp *dest, symbol op)
: exp(pos), dest(dest), op(op) {}
void prettyprint(ostream &out, Int indent);