summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/dec.cc
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2010-06-08 13:46:05 +0000
committerKarl Berry <karl@freefriends.org>2010-06-08 13:46:05 +0000
commita960e44eb527236f39aec81babc0474911a86078 (patch)
tree9950eca71791d90820a80a521a7cc252c0955db5 /Build/source/utils/asymptote/dec.cc
parent6443467452320c296faa1f43f0606a9457bd4463 (diff)
asy 1.96
git-svn-id: svn://tug.org/texlive/trunk@18817 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/dec.cc')
-rw-r--r--Build/source/utils/asymptote/dec.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/Build/source/utils/asymptote/dec.cc b/Build/source/utils/asymptote/dec.cc
index 07e1711107c..bc2be656e70 100644
--- a/Build/source/utils/asymptote/dec.cc
+++ b/Build/source/utils/asymptote/dec.cc
@@ -437,9 +437,32 @@ void initializeVar(position pos, coenv &e, varEntry *v, varinit *init)
e.c.encode(inst::pop);
}
+types::ty *inferType(position pos, coenv &e, varinit *init)
+{
+ if (!init) {
+ em.error(pos);
+ em << "inferred variable declaration without initializer";
+ return primError();
+ }
+
+ exp *base = dynamic_cast<exp *>(init);
+ if (base) {
+ types::ty *t = base->cgetType(e);
+ if (t->kind != ty_overloaded)
+ return t;
+ }
+
+ em.error(pos);
+ em << "could not infer type of initializer";
+ return primError();
+}
+
void createVar(position pos, coenv &e, record *r,
symbol *id, types::ty *t, varinit *init)
{
+ // I'm not sure how to handle inferred types in these cases.
+ assert(t->kind != types::ty_inferred);
+
varEntry *v=makeVarEntry(pos, e, r, t);
addVar(e, r, v, id);
initializeVar(pos, e, v, init);
@@ -448,6 +471,12 @@ void createVar(position pos, coenv &e, record *r,
void createVarOutOfOrder(position pos, coenv &e, record *r,
symbol *id, types::ty *t, varinit *init)
{
+ /* For declarations such as "var x = 5;", infer the type from the
+ * initializer.
+ */
+ if (t->kind == types::ty_inferred)
+ t = inferType(pos, e, init);
+
varEntry *v=makeVarEntry(pos, e, r, t);
initializeVar(pos, e, v, init);
addVar(e, r, v, id);
@@ -544,6 +573,10 @@ public:
loadModuleExp(position pos, record *imp)
: exp(pos), imp(imp), ft(new function(imp,primString())) {}
+ void prettyprint(ostream &out, Int indent) {
+ prettyname(out, "loadModuleExp", indent);
+ }
+
types::ty *trans(coenv &) {
em.compiler(getPos());
em << "trans called for loadModuleExp";