From 9aec5c4130e875a58d8a0a78b2a9488ae096f89d Mon Sep 17 00:00:00 2001 From: msojocs Date: Sun, 30 Jul 2023 20:39:42 +0800 Subject: [PATCH] feat: ast_if --- src/night/night.cpp | 5 +++- src/night/ns_ast_parse.cpp | 50 +++++++++++++++++++++++++++++------ src/night/ns_compile_js.cpp | 3 ++- src/night/str/str.cpp | 1 - src/wcc.cpp | 10 +++---- src/wxa/wxa.cpp | 2 +- src/wxml/compiler.cpp | 16 ++++++----- src/wxml/dom_lib/machine.cpp | 2 +- src/wxml/dom_lib/wxml_dom.cpp | 21 +++++++++++---- 9 files changed, 80 insertions(+), 30 deletions(-) diff --git a/src/night/night.cpp b/src/night/night.cpp index 356902a..fa3e65b 100644 --- a/src/night/night.cpp +++ b/src/night/night.cpp @@ -104,16 +104,19 @@ namespace night std::string& ) { - + + throw "not implement"; } void readfile(char const*, std::string &) { + throw "not implement"; } void writefile(char const*, std::string &) { + throw "not implement"; } } \ No newline at end of file diff --git a/src/night/ns_ast_parse.cpp b/src/night/ns_ast_parse.cpp index 786ad8d..2a75ca8 100644 --- a/src/night/ns_ast_parse.cpp +++ b/src/night/ns_ast_parse.cpp @@ -231,7 +231,31 @@ namespace night } night::ns_node *NSASTParse::ast_if() { - throw "not implement"; + this->ignore_buildin_kw("if"); + auto v2 = this->ast_expression_no_comma(); + auto v3 = this->ast_expression_no_comma(); + auto v7 = this->offset_24->gen_son(night::NS_TYPE_IF); + v7->offset_204 = v2; + v7->offset_208 = v3; + v7->offset_212 = nullptr; + + if (night::NS_TYPE_PROG_NO_SEM != v3->offset_0) + { + if (!this->offset_28->eof()) + { + if (this->is_punctuation(";")) + { + this->offset_28->next(); + } + } + v7->offset_108 = ";"; + } + if (this->is_buildin_keywords("else")) + { + this->offset_28->next(); + v7->offset_212 = this->ast_expression_no_comma(); + } + return v7; } night::ns_node *NSASTParse::ast_for() { @@ -392,7 +416,7 @@ namespace night auto v11 = this->ast_switch(); return this->make_call_or_just_expression(v11); } - bool v21 = false; + bool v21 = true; if (this->is_buildin_keywords("true")) { } @@ -461,6 +485,7 @@ namespace night v21 = this->is_buildin_keywords("continue") != 0; } } + // goto LABEL_62; } else { @@ -476,7 +501,7 @@ namespace night } } } // end check for "true" - // v21 = false; + // LABEL_62: if (v21) { auto v11 = this->ast_trans_kw(); @@ -795,10 +820,10 @@ namespace night } return a2; } - // int ast_expression_i = 0; + int ast_expression_i = 0; night::ns_node *NSASTParse::ast_expression() { - // int inner_ast_expression_i = ast_expression_i++; + int inner_ast_expression_i = ++ast_expression_i; auto v1 = this->ast_dispatch(false); auto binary_or_just_value = this->make_binary_or_just_value(v1, false); auto result = this->make_call_or_just_expression(binary_or_just_value); @@ -1082,20 +1107,20 @@ namespace night auto v25 = this->offset_24->gen_girl(night::std_v_v_n); night::ns_node * lt = this->offset_24->gen_son(night::NS_TYPE_CALL); lt->offset_220 = v21; - // lt->offset_224 = v25; // TODO... + lt->offset_224 = v25.vecVec; auto v5 = this->offset_28->peek(); std::vector * v44; if (v5 && v5->offset_84.find('\n') == -1) { v44 = this->offset_24->gen_girl(night::std_v_n).vec; - auto v45 = this->ast_expression(); // TODO...待确认 + auto v45 = this->ast_expression(); v44->emplace_back(v45); } else { v44 = this->offset_24->gen_girl(night::std_v_n).vec; } - // v25->push_back(v44); + v25.vecVec->push_back(v44); return lt; } if ("typeof" == v43) @@ -1504,4 +1529,13 @@ namespace night } this->offset_28->next(); } + void NSASTParse::ignore_buildin_kw(std::string const& a2) + { + if (!this->is_buildin_keywords(a2)) + { + std::string msg = "Expected `" + a2 + "`"; + this->offset_28->err(msg, 0, 0, false); + } + this->offset_28->next(); + } } \ No newline at end of file diff --git a/src/night/ns_compile_js.cpp b/src/night/ns_compile_js.cpp index 498a44f..0bda24f 100644 --- a/src/night/ns_compile_js.cpp +++ b/src/night/ns_compile_js.cpp @@ -314,7 +314,6 @@ namespace night } std::string NSCompileJs::compile_obj_property(night::ns_node *) { - // TODO... throw "not implement"; } std::string NSCompileJs::compile_obj_self_op(night::ns_node *a3) @@ -492,8 +491,10 @@ namespace night return result; } + int compile_i = 0; std::string NSCompileJs::compile(night::ns_node * a3) { + int inner_compile_i = ++compile_i; if (this->offset_0.size() == 0) { std::string v9 = a3->offset_0; diff --git a/src/night/str/str.cpp b/src/night/str/str.cpp index 3e14aa4..882b24a 100644 --- a/src/night/str/str.cpp +++ b/src/night/str/str.cpp @@ -26,7 +26,6 @@ namespace night } /** - * todo... */ int path_combine(std::string const& a1, std::string const& a2, std::string& a3) { diff --git a/src/wcc.cpp b/src/wcc.cpp index a880f7d..40bcb2b 100644 --- a/src/wcc.cpp +++ b/src/wcc.cpp @@ -387,11 +387,11 @@ int main(int argc, const char **argv) string helperCode; WXML::Compiler::WXMLHelperCode(helperCode); string data = "var __wxAppData=__wxAppData||{};var __wxAppCode__=__wxAppCode__||{};var global=global||{};var __WXML_GLOBAL__=" - "__WXML_GLOBAL__||{entrys:{},defines:{},modules:{},ops:[],wxs_nf_init:undefined,total_ops:0};var Component=Comp" - "onent||function(){};var definePlugin=definePlugin||function(){};var requirePlugin=requirePlugin||function(){};" - "var Behavior=Behavior||function(){};var __vd_version_info__=__vd_version_info__||{};var __GWX_GLOBAL__=__GWX_G" - "LOBAL__||{};var __globalThis=(typeof __vd_version_info__!=='undefined'&&typeof __vd_version_info__.globalThis!" - "=='undefined')?__vd_version_info__.globalThis:(typeof window!=='undefined'?window:globalThis);"; + "__WXML_GLOBAL__||{entrys:{},defines:{},modules:{},ops:[],wxs_nf_init:undefined,total_ops:0};var Component=Comp" + "onent||function(){};var definePlugin=definePlugin||function(){};var requirePlugin=requirePlugin||function(){};" + "var Behavior=Behavior||function(){};var __vd_version_info__=__vd_version_info__||{};var __GWX_GLOBAL__=__GWX_G" + "LOBAL__||{};var __globalThis=(typeof __vd_version_info__!=='undefined'&&typeof __vd_version_info__.globalThis!" + "=='undefined')?__vd_version_info__.globalThis:(typeof window!=='undefined'?window:globalThis);"; data = data + helperCode; outputContentMap["__COMMON__"] = data; } diff --git a/src/wxa/wxa.cpp b/src/wxa/wxa.cpp index c5b6a61..06ba0ce 100644 --- a/src/wxa/wxa.cpp +++ b/src/wxa/wxa.cpp @@ -54,7 +54,7 @@ namespace MMBizWxaAppComm dirList.pop_back(); } } - else if (v15[i] == ".") + else if (v15[i].compare(".")) { dirList.push_back(v15[i]); } diff --git a/src/wxml/compiler.cpp b/src/wxml/compiler.cpp index 1a8f9af..ecb26ca 100644 --- a/src/wxml/compiler.cpp +++ b/src/wxml/compiler.cpp @@ -26,6 +26,7 @@ namespace WXML{ bool b1, // mark指定运算结果是否非0 a12 bool b2) // mark指定运算结果是否非0 a13 { + // ParseSource - 0 int pResult = 0; bool isWxml = filePath.substr(filePath.length() - 5) == ".wxml"; if (isWxml) @@ -38,6 +39,7 @@ namespace WXML{ if (parseResult) { + // ParseSource - 5 // GetParsed std::shared_ptr parseDom = v50.GetParsed(); result[filePath] = parseDom; @@ -49,9 +51,9 @@ namespace WXML{ ss << "']={};"; ss << lineEndMark; } + // ParseSource - 10 for (int i = 0; i < tokenList.size(); i++) { - /* code */ int dealResult = 0; std::string v74, v76, v79; int v65; @@ -141,6 +143,7 @@ namespace WXML{ ss << lineEndMark; } } + // ParseSource - 15 auto v69 = ss.str(); if (v69.length() > 0) { @@ -149,18 +152,17 @@ namespace WXML{ } // LABEL_24: } + // ParseSource - 20 else if(filePath.substr(filePath.length() - 4) == ".wxs") { - std::string v84; + std::string v84; // errorMessage std::string p = "p_" + filePath; auto v86 = WXML::Compiler::GetFuncId(a11, p); int compilerResultCode = 0; - - // TODO: compile_ns - + compilerResultCode = night::compile_ns(filePath, v86, content, 1, v84, false); + pResult = compilerResultCode; if (compilerResultCode) { - errorMessage.assign("error..."); - throw compilerResultCode; + errorMessage.assign(v84); } else { diff --git a/src/wxml/dom_lib/machine.cpp b/src/wxml/dom_lib/machine.cpp index 183f203..cfafa0f 100644 --- a/src/wxml/dom_lib/machine.cpp +++ b/src/wxml/dom_lib/machine.cpp @@ -367,7 +367,7 @@ namespace WXML } if (bittest(&v46, 0x16u)) // 0x16 -> 22 { - // TODO: + throw "not implement"; // WXML::DOMLib::Token token(*(a5.end() - 1)); a5.pop_back(); diff --git a/src/wxml/dom_lib/wxml_dom.cpp b/src/wxml/dom_lib/wxml_dom.cpp index ff47282..5e4c8ae 100644 --- a/src/wxml/dom_lib/wxml_dom.cpp +++ b/src/wxml/dom_lib/wxml_dom.cpp @@ -452,7 +452,8 @@ namespace WXML { auto cur = this->offset_72[i]; if (cur->offset_0 == "block") { - // TODO... + // this->offset_72[i] + // throw "not implement"; } } @@ -810,6 +811,10 @@ namespace WXML { for (int i = 0; i < v142.size(); i++) { a6 << v142[i].first << ".wxXCkey=" << v142[i].second << a12; + // if (v142[i].first == "oVD") + // { + // printf("\n"); + // } } // RenderChildren - 20 @@ -829,6 +834,7 @@ namespace WXML { } + // int emplace_back_i = 0; void WXMLDom::RenderNonDefine( std::string const& a2, std::string const& a3, @@ -1278,7 +1284,11 @@ namespace WXML { || v161 != "wx:scope-data") { // pos: 搜索 -> !__stricmp((const char *)v161, "wx:scope-data") - + // ++emplace_back_i; + // if (emplace_back_i == 139) + // { + // printf("\n"); + // } // WXML::DOMLib::Token token = this.; v324.emplace_back(j->first, j->second); } @@ -1305,7 +1315,7 @@ namespace WXML { // { // /* code */ // } - // TODO... + throw "not implement"; } } @@ -1332,11 +1342,12 @@ namespace WXML { } if (!strncmp(&i->first[0], "data-", 5u) || i->first.find(':') != -1) { + str.assign(i->first); if (!strncmp(&i->first[0], "generic:", 8u)) { a6 << "var $tmp="; // if (i->second.) - // TODO... + throw "not implement"; } } else @@ -1786,7 +1797,7 @@ namespace WXML { // 0x48 -> 72 this->offset_72[v4]->MarkIfHasDescendant(a2); auto v6 = this->offset_72[v4]; - this->offset_256 = v6->offset_256; + this->offset_256 |= v6->offset_256; auto ret = std::find(a2.begin(), a2.end(), v6->offset_0); if (ret != a2.end()) {