diff options
author | Karl Berry <karl@freefriends.org> | 2009-05-16 00:19:13 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2009-05-16 00:19:13 +0000 |
commit | bab45528d65eaafe68a705dbb2a57075c7b7cbd8 (patch) | |
tree | 10b4ae2b5195c8dede153ab89359ec00f55f325f /Build/source/utils/asymptote/fundec.h | |
parent | 8643d90372e9c31e0f461c15c596b60a545bd7d3 (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/fundec.h')
-rw-r--r-- | Build/source/utils/asymptote/fundec.h | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/Build/source/utils/asymptote/fundec.h b/Build/source/utils/asymptote/fundec.h new file mode 100644 index 00000000000..058bd95e366 --- /dev/null +++ b/Build/source/utils/asymptote/fundec.h @@ -0,0 +1,138 @@ +/***** + * fundec.h + * Andy Hammerlindl 2002/8/29 + * + * Defines the semantics for defining functions. Both the newexp syntax, and + * the abbreviated C-style function definition. + *****/ + +#ifndef FUNDEC_H +#define FUNDEC_H + +#include "dec.h" +#include "exp.h" + +namespace absyntax { + +class formal : public absyn { + ty *base; + decidstart *start; + bool Explicit; + varinit *defval; + +public: + formal(position pos, ty *base, decidstart *start=0, varinit *defval=0, + bool Explicit= false) + : absyn(pos), base(base), start(start), Explicit(Explicit), + defval(defval) {} + + virtual void prettyprint(ostream &out, Int indent); + + // Build the corresponding types::formal to put into a signature. + types::formal trans(coenv &e, bool encodeDefVal, bool tacit=false); + + // Add the formal parameter to the environment to prepare for the + // function body's translation. + virtual void transAsVar(coenv &e, Int index); + + types::ty *getType(coenv &e, bool tacit=false); + + virtual void addOps(coenv &e, record *r); + + varinit *getDefaultValue() { + return defval; + } + + symbol *getName() { + return start ? start->getName() : 0; + } + + bool getExplicit() { + return Explicit; + } +}; + +class formals : public absyn { + //friend class funheader; + + mem::list<formal *> fields; + formal *rest; + + void addToSignature(types::signature& sig, + coenv &e, bool encodeDefVal, bool tacit); +public: + formals(position pos) + : absyn(pos), rest(0) {} + + virtual ~formals() {} + + virtual void prettyprint(ostream &out, Int indent); + + virtual void add(formal *f) { + fields.push_back(f); + } + + virtual void addRest(formal *f) { + rest = f; + } + + // Returns the types of each parameter as a signature. + // encodeDefVal means that it will also encode information regarding + // the default values into the signature + types::signature *getSignature(coenv &e, + bool encodeDefVal = false, + bool tacit = false); + + // Returns the corresponding function type, assuming it has a return + // value of "result." + types::function *getType(types::ty *result, coenv &e, + bool encodeDefVal = false, + bool tacit = false); + + virtual void addOps(coenv &e, record *r); + + // Add the formal parameters to the environment to prepare for the + // function body's translation. + virtual void trans(coenv &e); +}; + +class fundef : public exp { + ty *result; + formals *params; + stm *body; + +public: + fundef(position pos, ty *result, formals *params, stm *body) + : exp(pos), result(result), params(params), body(body) {} + + virtual void prettyprint(ostream &out, Int indent); + + varinit *makeVarInit(types::function *ft); + virtual void baseTrans(coenv &e, types::function *ft); + virtual types::ty *trans(coenv &e); + + virtual types::function *transType(coenv &e, bool tacit); + virtual types::function *transTypeAndAddOps(coenv &e, record *r, bool tacit); + virtual types::ty *getType(coenv &e) { + return transType(e, true); + } +}; + +class fundec : public dec { + symbol *id; + fundef fun; + +public: + fundec(position pos, ty *result, symbol *id, formals *params, stm *body) + : dec(pos), id(id), fun(pos, result, params, body) {} + + void prettyprint(ostream &out, Int indent); + + void trans(coenv &e); + + void transAsField(coenv &e, record *r); +}; + +} // namespace absyntax + +#endif |