Resolve a nested if-block bug in ext/wasm/c-pp.c which caused output after a nested block to be unduly elided. Remove a kludge, added in the previous check-in, which worked around that bug.

FossilOrigin-Name: 7a026a4b24d57c1b0970923b972dd42c3f1bb5b282f908079075468b2e1bf601
This commit is contained in:
stephan 2023-01-27 02:21:16 +00:00
parent 0cd38cd2b9
commit 67bfea4ea6
4 changed files with 34 additions and 35 deletions

View File

@ -10,6 +10,7 @@ const sqlite3InitModuleState = self.sqlite3InitModuleState || Object.create(null
delete self.sqlite3InitModuleState;
sqlite3InitModuleState.debugModule('self.location =',self.location);
//#ifnot target=es6-bundler-friendly
/**
This custom locateFile() tries to figure out where to load `path`
from. The intent is to provide a way for foo/bar/X.js loaded from a
@ -29,12 +30,7 @@ sqlite3InitModuleState.debugModule('self.location =',self.location);
4) If none of the above apply, (prefix+path) is returned.
*/
Module['locateFile'] = function(path, prefix) {
//#if target=es6-bundler-friendly
// TEMPORARY KLUDGE to work around a c-pp nested blocks bug which is
// currently eluding a fix. We really should have (#ifnot
// target=es6-bundler-friendly) around this whole function.
return new URL('sqlite3.wasm', import.meta.url).href;
//#elif target=es6-module
//#if target=es6-module
return new URL(path, import.meta.url).href;
//#else
'use strict';
@ -58,6 +54,7 @@ Module['locateFile'] = function(path, prefix) {
return theFile;
//#endif //target=es6-module
}.bind(sqlite3InitModuleState);
//#endif //ifnot target=es6-bundler-friendly
/**
Bug warning: a custom Module.instantiateWasm() does not work
@ -107,4 +104,4 @@ Module[xNameOfInstantiateWasm] = function callee(imports,onSuccess){
Module[xNameOfInstantiateWasm].uri = 'sqlite3.wasm';
/* END FILE: api/pre-js.js, noting that the build process may add a
line after this one to change the above .uri to a build-specific
one. *//* END FILE: api/pre-js.js */
one. */

View File

@ -51,10 +51,10 @@
**
** Design note: this code makes use of sqlite3. Though not _strictly_
** needed in order to implement it, this tool was specifically created
** for potential use with the sqlite3 project's own JavaScript code,
** so there's no reason not to make use of it to do some of the heavy
** lifting. It does not require any cutting-edge sqlite3 features and
** should be usable with any version which supports `WITHOUT ROWID`.
** for use with the sqlite3 project's own JavaScript code, so there's
** no reason not to make use of it to do some of the heavy lifting. It
** does not require any cutting-edge sqlite3 features and should be
** usable with any version which supports `WITHOUT ROWID`.
**
** Author(s):
**
@ -603,18 +603,9 @@ void g_stderr(char const *zFmt, ...){
va_end(va);
}
#if 0
void cmpp_t_outf(CmppTokenizer * t, char const *zFmt, ...){
if(!CT_skip(t)){
va_list va;
va_start(va, zFmt);
vfprintf(g.out.pFile, zFmt, va);
va_end(va);
}
}
#endif
void cmpp_t_out(CmppTokenizer * t, void const *z, unsigned int n){
g_debug(3,("CT_skipLevel() ?= %d\n",CT_skipLevel(t)));
g_debug(3,("CT_skip() ?= %d\n",CT_skip(t)));
if(!CT_skip(t)){
if(1!=fwrite(z, n, 1, g.out.pFile)){
int const err = errno;
@ -631,18 +622,28 @@ void CmppLevel_push(CmppTokenizer * const t){
g.zDelim, CmppLevel_Max);
}
pPrev = &CT_level(t);
g_debug(3,("push from tokenizer level=%u flags=%04x\n", t->level.ndx, pPrev->flags));
p = &t->level.stack[++t->level.ndx];
*p = CmppLevel_empty;
p->token = t->token;
p->flags = (CmppLevel_F_INHERIT_MASK & pPrev->flags);
if(CLvl_skip(pPrev)) p->flags |= CmppLevel_F_ELIDE;
g_debug(3,("push to tokenizer level=%u flags=%04x\n", t->level.ndx, p->flags));
}
void CmppLevel_pop(CmppTokenizer * const t){
if(!t->level.ndx){
fatal("Internal error: CmppLevel_pop() at the top of the stack");
}
g_debug(3,("pop from tokenizer level=%u, flags=%04x skipLevel?=%d\n", t->level.ndx,
t->level.stack[t->level.ndx].flags, CT_skipLevel(t)));
g_debug(3,("CT_skipLevel() ?= %d\n",CT_skipLevel(t)));
g_debug(3,("CT_skip() ?= %d\n",CT_skip(t)));
t->level.stack[t->level.ndx--] = CmppLevel_empty;
g_debug(3,("pop to tokenizer level=%u, flags=%04x\n", t->level.ndx,
t->level.stack[t->level.ndx].flags));
g_debug(3,("CT_skipLevel() ?= %d\n",CT_skipLevel(t)));
g_debug(3,("CT_skip() ?= %d\n",CT_skip(t)));
}
CmppLevel * CmppLevel_get(CmppTokenizer * const t){
@ -776,7 +777,7 @@ int db_define_has(const char * zName){
assert(SQLITE_DONE==rc);
rc = 0;
}
g_debug(1,("define has [%s] = %d\n",zName, rc));
g_debug(1,("defined [%s] ?= %d\n",zName, rc));
sqlite3_clear_bindings(g.stmt.defHas);
sqlite3_reset(g.stmt.defHas);
return rc;
@ -1220,10 +1221,11 @@ static void cmpp_kwd_if(CmppKeyword const * pKw, CmppTokenizer *t){
if(TT_IfNot==pKw->ttype || TT_ElifNot==pKw->ttype) buul = !buul;
if(buul){
CT_pstate(t) = tmpState = TS_IfPassed;
CT_skipLevel(t) = 0;
CT_skipLevel(t) = 0;
}else{
CT_pstate(t) = TS_If /* also for TT_IfNot, TT_Elif, TT_ElifNot */;
CT_skipLevel(t) = 1;
g_debug(3,("setting CT_skipLevel = 1 @ level %d\n", t->level.ndx));
}
if(TT_If==pKw->ttype || TT_IfNot==pKw->ttype){
unsigned const lvlIf = t->level.ndx;
@ -1234,10 +1236,13 @@ static void cmpp_kwd_if(CmppKeyword const * pKw, CmppTokenizer *t){
assert(TT_EndIf == t->token.ttype);
break;
}
#if 0
if(TS_IfPassed==tmpState){
tmpState = TS_Start;
t->level.stack[lvlIf].flags |= CmppLevel_F_ELIDE;
g_debug(1,("Setting ELIDE for TS_IfPassed @ lv %d (lvlIf=%d)\n", t->level.ndx, lvlIf));
}
#endif
}
if(lvlIf <= t->level.ndx){
cmpp_kwd__err_prefix(pKw, t, NULL);

View File

@ -1,5 +1,5 @@
C Beginnings\sof\sa\sbundler-friendly\sbuild\sof\ssqlite3.mjs.\sNot\syet\sready\sfor\sdownstream\stesting.
D 2023-01-27T01:33:12.220
C Resolve\sa\snested\sif-block\sbug\sin\sext/wasm/c-pp.c\swhich\scaused\soutput\safter\sa\snested\sblock\sto\sbe\sunduly\selided.\sRemove\sa\skludge,\sadded\sin\sthe\sprevious\scheck-in,\swhich\sworked\saround\sthat\sbug.
D 2023-01-27T02:21:16.305
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -476,7 +476,7 @@ F ext/wasm/api/extern-post-js.c-pp.js 9c1f67c368660cb14b6ddee0ed7c87c70594a41c2a
F ext/wasm/api/extern-pre-js.js cc61c09c7a24a07dbecb4c352453c3985170cec12b4e7e7e7a4d11d43c5c8f41
F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08902f15c34720ee4a1
F ext/wasm/api/post-js-header.js 47b6b281f39ad59fa6e8b658308cd98ea292c286a68407b35ff3ed9cfd281a62
F ext/wasm/api/pre-js.c-pp.js 26be645141fe11e614acb1bca777c2e6374680d503a276d96afb9df7939ba5d3
F ext/wasm/api/pre-js.c-pp.js 109d3afcdf6203a39fe79a2d7e0e1e5f93ea672ae00578fd4ec4f6fe19b484cc
F ext/wasm/api/sqlite3-api-cleanup.js 680d5ccfff54459db136a49b2199d9f879c8405d9c99af1dda0cc5e7c29056f4
F ext/wasm/api/sqlite3-api-glue.js 0a93e58aabf52b32ddccbb107a1fd4552f2505e103ab63396c4d0a0743704785
F ext/wasm/api/sqlite3-api-oo1.js e9fba119e9b1716b3f731838ed1ab18741401bcf4c51d2a4a6e9d1d23cf9d771
@ -492,7 +492,7 @@ F ext/wasm/api/sqlite3-worker1-promiser.js 0c7a9826dbf82a5ed4e4f7bf7816e825a52af
F ext/wasm/api/sqlite3-worker1.js 9d3d3dfc70bff8998c1d8ff6d881cf1c3d52468d635417f02796151fe6b31cd7
F ext/wasm/batch-runner.html 4deeed44fe41496dc6898d9fb17938ea3291f40f4bfb977e29d0cef96fbbe4c8
F ext/wasm/batch-runner.js 0dad6a02ad796f1003d3b7048947d275c4d6277f63767b8e685c27df8fdac93e
F ext/wasm/c-pp.c 92285f7bce67ed7b7020b40fde8ed0982c442b63dc33df9dfd4b658d4a6c0779
F ext/wasm/c-pp.c 6d80d8569d85713effe8b0818a3cf51dc779e3f0bf8dc88771b8998552ee25b4
F ext/wasm/common/SqliteTestUtil.js d8bf97ecb0705a2299765c8fc9e11b1a5ac7f10988bbf375a6558b7ca287067b
F ext/wasm/common/emscripten.css 11bd104b6c0d597c67d40cc8ecc0a60dae2b965151e3b6a37fa5708bac3acd15
F ext/wasm/common/testing.css 0ff15602a3ab2bad8aef2c3bd120c7ee3fd1c2054ad2ace7e214187ae68d926f
@ -2044,11 +2044,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P bdfd72a083fadd724030c4c89adae71426e1ddd402c6bc5abf40801ecf3253cf
R 1d25c63e8015d3a2077316f9c5633e5e
T *branch * js-bundler-friendly
T *sym-js-bundler-friendly *
T -sym-trunk * Cancelled\sby\sbranch.
P 4271bf5f41df091696f1dcfc4ffe7a60d24066fc75c896941e0b56de95fe5f89
R 94f2cf8a092efa28759f003587a957ce
U stephan
Z da3be54ec4b55cd9837defeb06176624
Z 16fc9ca50b1409b7eeea4546395ed5b7
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
4271bf5f41df091696f1dcfc4ffe7a60d24066fc75c896941e0b56de95fe5f89
7a026a4b24d57c1b0970923b972dd42c3f1bb5b282f908079075468b2e1bf601