multiy module import ok, cmodule not ok

This commit is contained in:
pikastech 2022-10-20 13:57:28 +08:00
parent 7c6267bfd9
commit ffe0565638
5 changed files with 46 additions and 10 deletions

View File

@ -11,7 +11,7 @@
"program": "${workspaceFolder}/build/test/pikascript_test",
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
"args": [
"--gtest_filter=parser.multi_from_import_as"
"--gtest_filter=parser.multi_import"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",

View File

@ -4,8 +4,7 @@ import PikaStdDevice
import ctypes
import GTestTask
import PikaMath
import test_module1
import test_cmodule
import test_module1, test_cmodule
import TempDevTest
import cjson_test
import test_module4

View File

@ -2229,10 +2229,39 @@ exit:
return line_out;
}
static char* Suger_import(Args* buffs_p, char* line) {
line = Suger_import_as(buffs_p, line);
line = Suger_from_import_as(buffs_p, line);
return line;
static char* Suger_import(Args* outbuffs, char* line) {
line = Suger_import_as(outbuffs, line);
line = Suger_from_import_as(outbuffs, line);
Arg* line_buff = arg_newStr("");
while (1) {
char* single_line = strPopFirstToken(&line, '\n');
if (single_line[0] == '\0') {
break;
}
if (strIsStartWith(single_line, "import ")) {
if (strIsContain(single_line, ',')) {
single_line = single_line + 7;
while (1) {
char* single_import = strPopFirstToken(&single_line, ',');
if (single_import[0] == '\0') {
break;
}
line_buff = arg_strAppend(line_buff, "import ");
line_buff = arg_strAppend(line_buff, single_import);
line_buff = arg_strAppend(line_buff, "\n");
}
char* line_after = arg_getStr(line_buff);
line_after[strlen(line_after) - 1] = '\0';
}
}
line_buff = arg_strAppend(line_buff, single_line);
line_buff = arg_strAppend(line_buff, "\n");
}
char* line_after = arg_getStr(line_buff);
line_after[strlen(line_after) - 1] = '\0';
line_after = strsCopy(outbuffs, line_after);
arg_deinit(line_buff);
return line_after;
}
static char* Parser_linePreProcess(Args* outbuffs, char* line) {

View File

@ -321,7 +321,7 @@
#endif
#ifndef PIKA_ARG_CACHE_SIZE
#define PIKA_ARG_CACHE_SIZE sizeof(Arg) + 8
#define PIKA_ARG_CACHE_SIZE sizeof(Arg) + 16
#endif
/* configuration validation */

View File

@ -4848,9 +4848,17 @@ TEST(parser, multi_import) {
printf("%s", pikaAsm);
EXPECT_STREQ(pikaAsm,
"B0\n"
"0 IMP a,b,c\n"
"0 IMP a\n"
"B0\n"
"0 IMP a,b,c\n"
"0 IMP b\n"
"B0\n"
"0 IMP c\n"
"B0\n"
"0 IMP a\n"
"B0\n"
"0 IMP b\n"
"B0\n"
"0 IMP c\n"
"B0\n"
"1 REF a\n"
"1 REF b\n"