Kaynağa Gözat

multiy module import ok, cmodule not ok

pikastech 3 yıl önce
ebeveyn
işleme
ffe0565638

+ 1 - 1
port/linux/.vscode/launch.json

@@ -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}",

+ 1 - 2
port/linux/package/pikascript/main.py

@@ -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

+ 33 - 4
src/PikaParser.c

@@ -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) {

+ 1 - 1
src/pika_config_valid.h

@@ -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 */

+ 10 - 2
test/parse-test.cpp

@@ -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 b\n"
+                 "B0\n"
+                 "0 IMP c\n"
+                 "B0\n"
+                 "0 IMP a\n"
+                 "B0\n"
+                 "0 IMP b\n"
                  "B0\n"
-                 "0 IMP a,b,c\n"
+                 "0 IMP c\n"
                  "B0\n"
                  "1 REF a\n"
                  "1 REF b\n"