diff options
Diffstat (limited to 'graphics/asymptote/dec.h')
-rw-r--r-- | graphics/asymptote/dec.h | 72 |
1 files changed, 45 insertions, 27 deletions
diff --git a/graphics/asymptote/dec.h b/graphics/asymptote/dec.h index 53fee4bfe0..95b1aef83d 100644 --- a/graphics/asymptote/dec.h +++ b/graphics/asymptote/dec.h @@ -2,7 +2,7 @@ * dec.h * Andy Hammerlindl 2002/8/29 * - * Represents the abstract syntax tree for declatations in the language. + * Represents the abstract syntax tree for declarations in the language. * Also included is abstract syntax for types as they are most often * used with declarations. *****/ @@ -45,6 +45,11 @@ using sym::symbol; class vardec; +enum class AutounravelOption { + Apply, + DoNotApply, +}; + class astType : public absyn { public: astType(position pos) @@ -54,7 +59,9 @@ public: // If we introduced a new type, automatically add corresponding functions for // that type. - virtual void addOps(coenv &, record *) {} + virtual void + addOps(coenv&, record*, AutounravelOption opt= AutounravelOption::Apply) + {} // Returns the internal representation of the type. This method can // be called by exp::getType which does not report errors, so tacit is @@ -83,6 +90,9 @@ public: void prettyprint(ostream &out, Int indent) override; + void + addOps(coenv& e, record* r, + AutounravelOption opt= AutounravelOption::Apply) override; types::ty *trans(coenv &e, bool tacit = false) override; trans::tyEntry *transAsTyEntry(coenv &e, record *where) override; @@ -120,7 +130,9 @@ public: void prettyprint(ostream &out, Int indent) override; - void addOps(coenv &e, record *r) override; + void + addOps(coenv& e, record* r, + AutounravelOption opt= AutounravelOption::Apply) override; types::ty *trans(coenv &e, bool tacit = false) override; @@ -193,7 +205,7 @@ public: virtual bool returns() { return false; } - // Returns true if it is syntatically allowable to modify this + // Returns true if it is syntactically allowable to modify this // runnable by a PUBLIC or PRIVATE modifier. virtual bool allowPermissions() { return false; } @@ -202,15 +214,16 @@ public: // Forward declaration. class formals; -class namedTyEntry : public gc { +class namedTy : public gc { public: symbol dest; - trans::tyEntry *ent; + types::ty *t; position pos; - namedTyEntry(position pos, symbol dest, trans::tyEntry *ent) - : dest(dest), ent(ent), pos(pos) {} + namedTy(position pos, symbol dest, types::ty *t) + : dest(dest), t(t), pos(pos) {} }; +class receiveTypedefDec; class block : public runnable { public: @@ -222,6 +235,11 @@ public: protected: void prettystms(ostream &out, Int indent); +private: + // If the first runnable exists and is a receiveTypedefDec*, return it; + // otherwise return nullptr. + receiveTypedefDec* getTypedefDec(); + public: block(position pos, bool scope=true) : runnable(pos), scope(scope) {} @@ -240,14 +258,7 @@ public: void transAsField(coenv &e, record *r) override; bool transAsTemplatedField( - coenv &e, record *r, mem::vector<absyntax::namedTyEntry*>* args, - trans::frame *caller - ); - - void transAsRecordBody(coenv &e, record *r); - bool transAsTemplatedRecordBody( - coenv &e, record *r, mem::vector<absyntax::namedTyEntry*> *args, - trans::frame *caller + coenv &e, record *r, mem::vector<absyntax::namedTy*>* args ); types::record *transAsFile(genv& ge, symbol id); @@ -255,8 +266,7 @@ public: types::record *transAsTemplatedFile( genv& ge, symbol id, - mem::vector<absyntax::namedTyEntry*> *args, - coenv &e + mem::vector<absyntax::namedTy*> *args ); // If the block can be interpreted as a single vardec, return that vardec @@ -479,7 +489,7 @@ public: void transAsField(coenv &e, record *r) override { - base->addOps(e, r); + base->addOps(e, r, AutounravelOption::DoNotApply); decs->transAsField(e, r, base->trans(e)); } @@ -526,8 +536,8 @@ struct idpair : public absyn { // Translates as: from _ unravel src as dest; // where _ is the qualifier record with source as its fields and types. - void transAsUnravel(coenv &e, record *r, - protoenv &source, varEntry *qualifier); + trans::tyEntry *transAsUnravel(coenv &e, record *r, + protoenv &source, varEntry *qualifier); void createSymMap(AsymptoteLsp::SymbolContext* symContext) override; }; @@ -543,8 +553,9 @@ struct idpairlist : public gc { void transAsAccess(coenv &e, record *r); - void transAsUnravel(coenv &e, record *r, - protoenv &source, varEntry *qualifier); + mem::vector<trans::tyEntry*> transAsUnravel( + coenv &e, record *r, protoenv &source, varEntry *qualifier + ); void createSymMap(AsymptoteLsp::SymbolContext* symContext); @@ -623,7 +634,7 @@ public: typeParam(position pos, symbol paramSym) : absyn(pos), paramSym(paramSym) {} - bool transAsParamMatcher(coenv &e, record *r, namedTyEntry *arg); + bool transAsParamMatcher(coenv &e, record *r, namedTy *arg); void prettyprint(ostream &out, Int indent); }; @@ -637,7 +648,7 @@ public: void add(typeParam *tp); bool transAsParamMatcher(coenv &e, record *r, - mem::vector<namedTyEntry*> *args, trans::frame *caller); + mem::vector<namedTy*> *args); void prettyprint(ostream &out, Int indent); }; @@ -652,7 +663,7 @@ public: void transAsField(coenv& e, record *r) override; bool transAsParamMatcher( - coenv& e, record *r, mem::vector<namedTyEntry*> *args, trans::frame *caller + coenv& e, record *r, mem::vector<namedTy*> *args ); }; @@ -777,7 +788,7 @@ public: void createSymMap(AsymptoteLsp::SymbolContext* symContext) override; }; -// Types defined from others in typedef. +// Types defined from others in `typedef` or `using` statement. class typedec : public dec { vardec *body; @@ -785,6 +796,13 @@ public: typedec(position pos, vardec *body) : dec(pos), body(body) {} + typedec(position pos, decidstart *id_with_signature, astType *return_type) + : dec(pos) + { + decid *di = new decid(id_with_signature->getPos(), id_with_signature); + body = new vardec(return_type->getPos(), return_type, di); + } + void prettyprint(ostream &out, Int indent); void transAsField(coenv &e, record *r) { |