diff --git a/src/include/night.h b/src/include/night.h index 6b2f636..9ef6da3 100644 --- a/src/include/night.h +++ b/src/include/night.h @@ -154,13 +154,13 @@ namespace night int offset_52 = 0; // 当前行数 int offset_56 = 0; // 当前行第几个字符位置 NSStream(/* args */); - NSStream(std::string const&,std::string const&,uint); + NSStream(std::string const&, std::string const&, uint); ~NSStream(); NSStream(NSStream const&); NSStream& operator=(NSStream const&); bool eof(void); bool eof_2(void); - void err(std::string const&,int,int,bool); + void err(std::string const&, int, int, bool); PeekData next(void); PeekData peek(void); PeekData peek_2(void); diff --git a/src/night/night.cpp b/src/night/night.cpp index c54a391..c29626d 100644 --- a/src/night/night.cpp +++ b/src/night/night.cpp @@ -94,26 +94,84 @@ namespace night return 0; } + /** + * 此函数只有定义实现,没有调用 + * 所以,没有必要实现 + * + */ void compile_ns_with_sourcemap( - std::string const&, - std::string const&, - std::string const&, - std::string const&, - uint, - std::string&, - std::string& + std::string const& a1, + std::string const& a2, + std::string const& a3, + std::string const& a4, + uint a5, + std::string& a6, + std::string& a7 ) { - + int retcode = 0; + a6 = ""; + night::NSStream v80(a1, a4, a5); + night::NSToken v69; + night::NSGod v36; + night::NSASTParse v81(a1, &v69, &v36); + + night::NSCompileJs v71; + v71.offset_24 = &v81; + + std::string v41; + std::vector v37; + std::string v43 = v71.compile_once(v41, &v37, false); + v36.hamlet(); + + // if (v43.length()) + // { + // a6.assign(v43); + // retcode = 121; + // } + // else + // { + // std::string ret = ""; + // std::string v51 = ";return " + night::nsv_; + // v51.append("module."); + // v51.append(night::nsv_); + // v51.append("exports;"); + + // std::string v57 = "function " + a3 + "(){"; + // a6 = v57; + + // std::string v45 = "var " + night::nsv_ + "module={" + night::nsv_ + "exports:{}};"; + // ret += v45; + + // std::string v63 = v41 + v51; + // ret += v63; + + // ret += "}"; + // v63 = "\n//# sourceMappingURL=" + a2; + // ret += v63; + + // // ... + // } + throw "not implement"; } + /** + * 此函数只有定义实现,没有调用 + * 所以,没有必要实现 + * + */ void readfile(char const*, std::string &) { throw "not implement"; } + /** + * 此函数只有定义实现,没有调用 + * 所以,没有必要实现 + * + */ void writefile(char const*, std::string &) { diff --git a/src/night/ns_ast_parse.cpp b/src/night/ns_ast_parse.cpp index 984cfaa..ae0fa7c 100644 --- a/src/night/ns_ast_parse.cpp +++ b/src/night/ns_ast_parse.cpp @@ -139,8 +139,6 @@ namespace night } auto v8 = this->ast_obj_op(v25); return this->make_call_or_just_expression(v8); - - // throw "not implement"; } night::ns_node *NSASTParse::ast_code_block() { @@ -326,11 +324,42 @@ namespace night } night::ns_node *NSASTParse::ast_while() { - throw "not implement"; + this->offset_28->next(); + night::ns_node * v7 = this->offset_24->gen_son(night::NS_TYPE_WHILE); + v7->offset_204 = nullptr; + v7->offset_216 = nullptr; + this->ignore_punc("("); + v7->offset_204 = this->ast_expression(); + this->ignore_punc(")"); + this->offset_36++; + this->offset_40++; + v7->offset_216 = this->ast_expression(); + this->offset_36--; + this->offset_40--; + return v7; } night::ns_node *NSASTParse::ast_do_while() { - throw "not implement"; + this->offset_28->next(); + auto v1 = this->offset_28->offset_4; + night::ns_node * v12 = this->offset_24->gen_son(night::NS_TYPE_DO_WHILE); + if (!this->is_punctuation("{")) + { + this->offset_28->err("Expected `{`", v1->offset_52, v1->offset_56, true); + } + this->offset_36++; + this->offset_40++; + v12->offset_216 = this->ast_expression(); + this->offset_36--; + this->offset_40--; + + this->ignore_buildin_kw("while"); + this->ignore_punc("("); + + v12->offset_204 = this->ast_expression(); + this->ignore_punc(")"); + + return v12; } night::ns_node *NSASTParse::ast_switch() { diff --git a/src/night/ns_node.cpp b/src/night/ns_node.cpp index ae32cc9..93c4801 100644 --- a/src/night/ns_node.cpp +++ b/src/night/ns_node.cpp @@ -1,4 +1,5 @@ #include "../include/night.h" +#include namespace night { @@ -11,8 +12,71 @@ namespace night { } + /** + * 调用处:night::NSCompileJs::compile_once + * 其它均为自身递归调用 + * 在源码级判断做了false处理,所以实际生成二进制文件上不会调用此函数; + * 没有实现必要。 + */ std::string ns_node::debug_no_space() { + // debug_no_space - 0 + char str[1024]; + memset(str, 0, sizeof(str)); + if ("skip" == this->offset_0) + { + sprintf(str, "type[%s]", this->offset_0.data()); + } + if ("bool" == this->offset_0) + { + if (this->offset_24.length()) + { + sprintf(str, "(%d,%d)type[%s] value[%s]", this->offset_48, this->offset_52, this->offset_0, this->offset_60); + } + else + { + sprintf(str, "type[%s] value[%s]", this->offset_0, this->offset_60); + } + } + if ( + "num" == this->offset_0 + || "builtin_type" == this->offset_0 + || "kw" == this->offset_0 + || "var" == this->offset_0 + || "punc" == this->offset_0 + || "op" == this->offset_0 + ) + { + if (this->offset_24.length()) + { + sprintf(str, "(%d,%d)type[%s] value[%s]", this->offset_48, this->offset_52, this->offset_0, this->offset_60); + } + else + { + sprintf(str, "type[%s] value[%s]", this->offset_0, this->offset_60); + } + } + if ("var" == this->offset_0) + { + if (this->offset_24.length()) + { + sprintf(str, "(%d,%d)type[%s] value[%s] flag[%d]", this->offset_48, this->offset_52, this->offset_0, this->offset_60, this->offset_56); + } + else + { + sprintf(str, "type[%s] value[%s] flag[%d]", this->offset_0, this->offset_60, this->offset_56); + } + } + // debug_no_space - 5 + // debug_no_space - 10 + // debug_no_space - 15 + // debug_no_space - 20 + // debug_no_space - 25 + // debug_no_space - 30 + // debug_no_space - 35 + // debug_no_space - 40 + // debug_no_space - 45 + throw "not implement"; } diff --git a/src/wxml/dom_lib/wxml_dom.cpp b/src/wxml/dom_lib/wxml_dom.cpp index 15be56e..ae98bed 100644 --- a/src/wxml/dom_lib/wxml_dom.cpp +++ b/src/wxml/dom_lib/wxml_dom.cpp @@ -467,15 +467,16 @@ namespace WXML { } // RewriteTree - 15 - for (int i = 0; i < this->offset_72.size(); i++) - { - auto cur = this->offset_72[i]; - if (cur->offset_0 == "block") - { - // this->offset_72[i] - // throw "not implement"; - } - } + // 看起来似乎是多余的代码 + // for (int i = 0; i < this->offset_72.size(); i++) + // { + // auto cur = this->offset_72[i]; + // if (cur->offset_0 == "block") + // { + // // this->offset_72[i] + // // throw "not implement"; + // } + // } // RewriteTree - 20 for (int i = 0; i < this->offset_72.size(); i++) @@ -1384,8 +1385,23 @@ namespace WXML { if (!strncmp(&i->first[0], "generic:", 8u)) { a6 << "var $tmp="; - // if (i->second.) - throw "not implement"; + if (i->second.offset_0.length()) + { + a6 << "grb(z["; + a6 << i->second.offset_0; + a6 << "]," << a8 << "," << a9 << "," << a10 << ")" << a12; + a6 << "if ($tmp!=\"\") $tmp=\"wx-\"+$tmp"; + } + else + { + a6 << "\"\""; + } + a6 << a12; + a6 << a5 << ".generics['" << "wx-"; + a6 << i->first; + a6 << "']=$tmp"; + a6 << a12; + continue; } } else diff --git a/src/wxss/css_tree_lib/lexical_checker.cpp b/src/wxss/css_tree_lib/lexical_checker.cpp index 868fcf1..b8017dc 100644 --- a/src/wxss/css_tree_lib/lexical_checker.cpp +++ b/src/wxss/css_tree_lib/lexical_checker.cpp @@ -612,7 +612,8 @@ namespace WXSS } int off_519B9C(std::shared_ptr& a1, std::shared_ptr &a2) { - throw "not implement"; + a2->offset_116 = 0; + return 0; } int off_519BB4_i = 0; diff --git a/src/wxss/x_compiler.cpp b/src/wxss/x_compiler.cpp index 1e2e299..194f8e7 100644 --- a/src/wxss/x_compiler.cpp +++ b/src/wxss/x_compiler.cpp @@ -203,14 +203,56 @@ namespace WXSS } return 0; } - int XCompiler::GetCompiled(std::string const&, std::string&) + int XCompiler::GetCompiled(std::string const& a2, std::string& a3) { if (this->offset_0) { return 6; } + int v14 = this->offset_0; + auto v15 = this->offset_104.find(a2); + if (v15 == this->offset_104.end()) + { + if (this->offset_32.find(a2) == this->offset_32.end()) + { + v14 = 1; + a3 = ""; + } + else + { + a3 = ""; + auto v7 = this->offset_32[a2]; + auto vec = v7->offset_120; + for (int i = 0; i < vec.size(); i++) + { + auto cur = vec[i]; + if ( + cur->offset_0 == "DIRECTIVE" + && cur->offset_120.size() > 0 + && cur->offset_120[0]->offset_0 == "@import" + && cur->offset_140.get() != nullptr + ) + { + std::string v21(*cur->offset_140); + std::string v22; + this->GetCompiled(v21, v22); + a3 = v22; + } + else + { + cur->RenderCode(a3, true); + } + } + this->offset_104[a2].assign(a3); + + } + } + else + { + a3.assign(this->offset_104[a2]); + } - throw "not implement"; + return v14; } int XCompiler::GetJSCompiled(std::string const& a2, std::string& a3) { diff --git a/test/wcc.disassembly.cpp b/test/wcc.disassembly.cpp index 8a4296b..795409d 100644 --- a/test/wcc.disassembly.cpp +++ b/test/wcc.disassembly.cpp @@ -20661,6 +20661,10 @@ _DWORD *__thiscall night::NSCompileJs::compile_prog_no_sem[abi:cxx11](_DWORD *th // 41995C: using guessed type _DWORD __stdcall night::NSCompileJs::compile[abi:cxx11](_DWORD, _DWORD); //----- (0041C7CC) -------------------------------------------------------- +/** + * @param this result + * @param a2 this +*/ char *__thiscall night::NSCompileJs::compile_once(char *this, int a2, unsigned int *a3, int a4, char a5) { const char **v5; // eax @@ -20910,19 +20914,23 @@ int __cdecl night::compile_ns_with_sourcemap( memset(&v69[2], 0, 16); std::string::basic_string((char *)v71, (int)a1); night::NSASTParse::NSASTParse((int)v81, (int)v71, (int)v69, (int)v36); + // 销毁清空v71 std::string::_M_dispose(v71); - v71[0] = &v72; - v73 = v81; - v41[0] = &v42; - v71[1] = 0; - v72 = 0; - v76 = 0; - v77 = 0; - v78 = 0; - v74 = 0; - v75 = 0; + v71[0] = &v72; // v71.offset_0 + v71[1] = 0; // v71.offset_4 + + v72 = 0; // v71.offset_8 + v73 = v81; // v71.offset_12 + v74 = 0; // v71.offset_16 + v75 = 0; // v71.offset_20 + v76 = 0; // v71.offset_24 + v77 = 0; // v71.offset_28 + v78 = 0; // v71.offset_32 v79 = 1; + + v41[0] = &v42; v41[1] = 0; + v42 = 0; memset(v37, 0, sizeof(v37)); night::NSCompileJs::compile_once((char *)v43, (int)v71, (unsigned int *)v41, (int)v37, 0); @@ -20944,12 +20952,15 @@ int __cdecl night::compile_ns_with_sourcemap( std::string::_M_dispose((void **)&v63); std::string::_M_dispose((void **)&v57); std::string::_M_dispose((void **)&v51); + std::operator+((int)&v57, "function ", a3); v10 = std::string::append(&v57, "(){"); std::string::basic_string(&v63, v10); std::string::operator=((unsigned __int8 **)a6, (int)&v63); + std::string::_M_dispose((void **)&v63); std::string::_M_dispose((void **)&v57); + std::operator+((int)&v45, "var ", (int)&night::nsv_); v11 = std::string::append(&v45, "module={"); std::string::basic_string(&v51, v11); @@ -20962,10 +20973,12 @@ int __cdecl night::compile_ns_with_sourcemap( std::string::_M_dispose((void **)&v57); std::string::_M_dispose((void **)&v51); std::string::_M_dispose((void **)&v45); + v32 = a6[1]; std::operator+((char *)&v63, (int)v41, (int)v44); std::string::operator+=(&v63); std::string::_M_dispose((void **)&v63); + std::string::operator+=("}"); std::operator+((int)&v63, "\n//# sourceMappingURL=", a2); std::string::operator+=(&v63); @@ -20973,6 +20986,7 @@ int __cdecl night::compile_ns_with_sourcemap( Block = 0; v39 = 0; v40 = 0; + // v71.offset28 - v71.offset_24 lpuexcpta = (struct _Unwind_Exception *)(v77 - v76); if ( v77 == v76 ) { @@ -54356,6 +54370,7 @@ void **__thiscall night::ns_node::debug_no_space[abi:cxx11](void **this, const c char Str[4]; // [esp+120h] [ebp-418h] BYREF char v105[1020]; // [esp+124h] [ebp-414h] BYREF + // debug_no_space - 0 *(_DWORD *)Str = 0; memset(v105, 0, sizeof(v105)); if ( std::operator==("skip", (int)a2) ) @@ -54381,6 +54396,8 @@ void **__thiscall night::ns_node::debug_no_space[abi:cxx11](void **this, const c else sprintf(Str, "type[%s] value[%s]", v3, a2[15]); } + + // var if ( std::operator==((char *)off_551FFE, (int)a2) ) { v4 = a2[15]; @@ -54390,6 +54407,7 @@ void **__thiscall night::ns_node::debug_no_space[abi:cxx11](void **this, const c else sprintf(Str, "type[%s] value[%s] flag[%d]", v5, v4, *((unsigned __int8 *)a2 + 56)); } + // debug_no_space - 5 if ( std::operator==("op_self", (int)a2) ) { v97 = 0; @@ -54419,6 +54437,7 @@ void **__thiscall night::ns_node::debug_no_space[abi:cxx11](void **this, const c else sprintf(Str, "type[%s] value[%s%s%s]", v10, v11, v9, a2[27]); } + // debug_no_space - 10 if ( std::operator==((char *)off_5520BF, (int)a2) ) { v97 = 0; @@ -54474,6 +54493,7 @@ void **__thiscall night::ns_node::debug_no_space[abi:cxx11](void **this, const c } std::string::_M_dispose((void **)v103); } + // debug_no_space - 15 if ( std::operator==("obj_dot", (int)a2) || std::operator==("obj_property", (int)a2) ) { v93[0] = 0; @@ -54520,6 +54540,7 @@ void **__thiscall night::ns_node::debug_no_space[abi:cxx11](void **this, const c v22 = v92; goto LABEL_131; } + // debug_no_space - 20 if ( std::operator==("if", (int)a2) ) { v97 = 0; @@ -54565,6 +54586,8 @@ LABEL_130: v22 = &v96; goto LABEL_131; } + + // debug_no_space - 25 if ( std::operator==((char *)off_552210, (int)a2) ) { v98[0] = 0; @@ -54598,6 +54621,7 @@ LABEL_130: std::string::operator+=(v103); goto LABEL_73; } + // debug_no_space - 30 if ( std::operator==("while", (int)a2) || std::operator==("do_while", (int)a2) ) { v97 = 0; @@ -54625,6 +54649,7 @@ LABEL_130: std::string::operator+=(v103); goto LABEL_73; } + // debug_no_space - 35 if ( std::operator==("switch", (int)a2) ) { v91[0] = 0; @@ -54716,6 +54741,7 @@ LABEL_130: } std::string::operator+=("\ndefault<="); } + // debug_no_space - 40 else { if ( std::operator==("binary", (int)a2) @@ -54880,6 +54906,7 @@ LABEL_130: } std::string::operator+=("\ncall<="); } + // debug_no_space - 45 std::string::basic_string(this, &v89); v22 = (int *)&v89; LABEL_131: