diff options
author | Karl Berry <karl@freefriends.org> | 2022-01-08 18:39:01 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-01-08 18:39:01 +0000 |
commit | bedc9a5694f7c40a2645919601638d2dbef4145b (patch) | |
tree | 22548fd073b3f2f5a287c2487d69bfc656125ef6 /Build/source/utils/asymptote/stm.cc | |
parent | c2c4540ab1d27a23c085ce5081f6366cfabb31f6 (diff) |
asy 2.75 sources
git-svn-id: svn://tug.org/texlive/trunk@61532 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/stm.cc')
-rw-r--r-- | Build/source/utils/asymptote/stm.cc | 131 |
1 files changed, 118 insertions, 13 deletions
diff --git a/Build/source/utils/asymptote/stm.cc b/Build/source/utils/asymptote/stm.cc index 8cd74a0c346..17461a01d27 100644 --- a/Build/source/utils/asymptote/stm.cc +++ b/Build/source/utils/asymptote/stm.cc @@ -25,27 +25,33 @@ using namespace types; void stm::prettyprint(ostream &out, Int indent) { - prettyname(out,"stm",indent); + prettyname(out,"stm",indent, getPos()); } void emptyStm::prettyprint(ostream &out, Int indent) { - prettyname(out,"emptyStm",indent); + prettyname(out,"emptyStm",indent, getPos()); } void blockStm::prettyprint(ostream &out, Int indent) { - prettyname(out,"blockStm",indent); + prettyname(out,"blockStm",indent, getPos()); base->prettyprint(out, indent+1); } +void blockStm::createSymMap(AsymptoteLsp::SymbolContext* symContext) +{ +#ifdef HAVE_LSP + base->createSymMap(symContext->newContext(getPos().LineColumn())); +#endif +} void expStm::prettyprint(ostream &out, Int indent) { - prettyname(out,"expStm",indent); + prettyname(out,"expStm",indent, getPos()); body->prettyprint(out, indent+1); } @@ -170,10 +176,16 @@ void expStm::interactiveTrans(coenv &e) baseExpTrans(e, body); } +void expStm::createSymMap(AsymptoteLsp::SymbolContext* symContext) { +#ifdef HAVE_LSP + body->createSymMap(symContext); +#endif +} + void ifStm::prettyprint(ostream &out, Int indent) { - prettyname(out,"ifStm",indent); + prettyname(out,"ifStm",indent, getPos()); test->prettyprint(out, indent+1); onTrue->prettyprint(out, indent+1); @@ -204,6 +216,19 @@ void ifStm::trans(coenv &e) e.c.defLabel(end); } + void ifStm::createSymMap(AsymptoteLsp::SymbolContext* symContext) + { +#ifdef HAVE_LSP + test->createSymMap(symContext); + onTrue->createSymMap(symContext); + + if (onFalse) + { + onFalse->createSymMap(symContext); + } +#endif + } + void transLoopBody(coenv &e, stm *body) { // The semantics of the language are defined so that any variable declared @@ -251,7 +276,7 @@ void transLoopBody(coenv &e, stm *body) { void whileStm::prettyprint(ostream &out, Int indent) { - prettyname(out,"whileStm",indent); + prettyname(out,"whileStm",indent, getPos()); test->prettyprint(out, indent+1); body->prettyprint(out, indent+1); @@ -273,10 +298,29 @@ void whileStm::trans(coenv &e) e.c.popLoop(); } +void whileStm::createSymMap(AsymptoteLsp::SymbolContext* symContext) +{ +#ifdef HAVE_LSP + // while (<xyz>) { <body> } + // the <xyz> part belongs in the main context as the while statement, + // as it cannot declare new variables and only knows the symbols from that context. -void doStm::prettyprint(ostream &out, Int indent) + test->createSymMap(symContext); + + // for the body part, { <body> } are encapsulated in + // the blockStm, while <body> are direct statements. + // If the while block does not use { <body> }, then the body + // can be considered the same context as it cannot declare new variables and again, can + // only uses the variable already known before this while statement. + + body->createSymMap(symContext); +#endif +} + + + void doStm::prettyprint(ostream &out, Int indent) { - prettyname(out,"doStm",indent); + prettyname(out,"doStm",indent, getPos()); body->prettyprint(out, indent+1); test->prettyprint(out, indent+1); @@ -301,10 +345,18 @@ void doStm::trans(coenv &e) e.c.popLoop(); } +void doStm::createSymMap(AsymptoteLsp::SymbolContext* symContext) +{ +#ifdef HAVE_LSP + body->createSymMap(symContext); + test->createSymMap(symContext); +#endif +} + void forStm::prettyprint(ostream &out, Int indent) { - prettyname(out,"forStm",indent); + prettyname(out,"forStm",indent, getPos()); if (init) init->prettyprint(out, indent+1); if (test) test->prettyprint(out, indent+1); @@ -343,6 +395,28 @@ void forStm::trans(coenv &e) e.e.endScope(); } +void forStm::createSymMap(AsymptoteLsp::SymbolContext* symContext) +{ +#ifdef HAVE_LSP + AsymptoteLsp::SymbolContext* ctx(symContext); + if (init) + { + auto* declCtx(symContext->newContext(getPos().LineColumn())); + init->createSymMap(declCtx); + ctx = declCtx; + } + if (test) + { + test->createSymMap(ctx); + } + if (update) + { + update->createSymMap(ctx); + } + body->createSymMap(ctx); +#endif +} + void extendedForStm::prettyprint(ostream &out, Int indent) { prettyindent(out, indent); @@ -421,10 +495,31 @@ void extendedForStm::trans(coenv &e) { new blockStm(pos, &b)).trans(e); } +void extendedForStm::createSymMap(AsymptoteLsp::SymbolContext* symContext) +{ +#ifdef HAVE_LSP + auto* declCtx(symContext->newContext(getPos().LineColumn())); + + std::string varName(var); + + // FIXME: How do we get the position of the actual variable name? + // Right now, we only get the starting position of the type declaration + declCtx->symMap.varDec.emplace(std::piecewise_construct, + std::forward_as_tuple(varName), + std::forward_as_tuple( + varName, + static_cast<std::string>(*start), + start->getPos().LineColumn() + )); + set->createSymMap(symContext); + body->createSymMap(declCtx); +#endif +} + void breakStm::prettyprint(ostream &out, Int indent) { - prettyname(out,"breakStm",indent); + prettyname(out,"breakStm",indent, getPos()); } void breakStm::trans(coenv &e) @@ -438,7 +533,7 @@ void breakStm::trans(coenv &e) void continueStm::prettyprint(ostream &out, Int indent) { - prettyname(out,"continueStm",indent); + prettyname(out,"continueStm",indent, getPos()); } void continueStm::trans(coenv &e) @@ -452,7 +547,7 @@ void continueStm::trans(coenv &e) void returnStm::prettyprint(ostream &out, Int indent) { - prettyname(out, "returnStm",indent); + prettyname(out, "returnStm",indent, getPos()); if (value) value->prettyprint(out, indent+1); @@ -485,10 +580,20 @@ void returnStm::trans(coenv &e) e.c.encode(inst::ret); } +void returnStm::createSymMap(AsymptoteLsp::SymbolContext* symContext) +{ +#ifdef HAVE_LSP + if (value) + { + value->createSymMap(symContext); + } +#endif +} + void stmExpList::prettyprint(ostream &out, Int indent) { - prettyname(out, "stmExpList",indent); + prettyname(out, "stmExpList",indent, getPos()); for (mem::list<stm *>::iterator p = stms.begin(); p != stms.end(); ++p) (*p)->prettyprint(out, indent+1); |