From 7d592a8e61f3956f6e9dc00d5af188c6edc9ead4 Mon Sep 17 00:00:00 2001 From: msojocs Date: Thu, 22 Jun 2023 20:46:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/include/wxml.h | 37 +++++--- src/wxml/compiler.cpp | 65 ++++++++++---- src/wxml/dom_lib/machine.cpp | 14 +-- src/wxml/dom_lib/parser.cpp | 2 +- src/wxml/dom_lib/token.cpp | 12 +++ src/wxml/dom_lib/tokenizer.cpp | 1 - src/wxml/dom_lib/wxml_dom.cpp | 150 +++++++++++++++++++++++++++++---- 7 files changed, 226 insertions(+), 55 deletions(-) diff --git a/src/include/wxml.h b/src/include/wxml.h index caef1fd..5121cf2 100644 --- a/src/include/wxml.h +++ b/src/include/wxml.h @@ -99,12 +99,19 @@ namespace WXML bool offset_84; // hasCache attrContent std::string offset_88; // chcheData attrContent public: + int offset_8; // ??? + int offset_12; // ??? + int offset_56; // ??? + std::string offset_60; // ??? Token(); Token(std::string &); Token(WXML::DOMLib::Token&&); Token(WXML::DOMLib::Token const&); ~Token(); void SetContent(std::string &content); + std::string& GetContent(); + int GetPos(); + int GetSize(); std::string ToString(); /** @@ -204,14 +211,18 @@ namespace WXML private: /* data */ bool offset_28; - int offset_92; // pos1 + std::map offset_48; + // std::string offset_52; WXML::DOMLib::Token offset_84; // token + int offset_92; // pos1 int offset_96; // pos2 int offset_104; // len - StrCache offset_62; + int offset_140; + std::string offset_144; + StrCache offset_248; public: - std::string tag; std::map offset_12; + std::string offset_0; // type WXMLDom(/* args */); ~WXMLDom(); std::string Error( @@ -392,17 +403,17 @@ namespace WXML std::string const& boxMark, std::string const& gdwxMark, std::string const& fMark); - + int DealWxsTag( - std::string const&, - std::string &, - std::string&, - std::string&, - std::string&, - int &, - std::string& - ); - + std::string const& a1, + WXML::DOMLib::Token & a2, + std::string& a3, + std::string& a4, + std::string& a5, + int & a6, + std::string& a7 + ); + // void GetFuncId(); void GetVersionInfo(std::string &a1, std::string a2); int RenderDefine( diff --git a/src/wxml/compiler.cpp b/src/wxml/compiler.cpp index 2a181c4..882dc8f 100644 --- a/src/wxml/compiler.cpp +++ b/src/wxml/compiler.cpp @@ -44,7 +44,7 @@ namespace WXML{ if (a != b) { ss << "f_['"; - // ss << ToStringCode(fileName); + ss << WXML::Rewrite::ToStringCode(filePath); ss << "']={};"; ss << lineEndMark; } @@ -53,7 +53,7 @@ namespace WXML{ /* code */ int dealResult = 0; std::string t; - // dealResult = DealWxsTag(fileName, , t); + // dealResult = WXML::Compiler::DealWxsTag(filePath, , t); if (dealResult) { // 非0 @@ -277,38 +277,73 @@ namespace WXML{ int DealWxsTag( - std::string const& a1, - std::string &a2, + std::string const& filePath, + WXML::DOMLib::Token & a2, std::string& a3, std::string& a4, std::string& a5, - int & a6, - std::string& a7) + int * a6, + std::string& errorMessage) { - int pos = a2.find('>', a2[4]); + std::string content = a2.GetContent(); + int pos = content.find('>', content[4]); + int tokenPos = a2.GetPos(); + int tokenSize = a2.GetSize(); std::string sub; - if (a2[pos - 1] == '/') + if (content[pos - 1] == '/') { // 这个尖括号附近是这样的:/> - sub = a2.substr(a2[4] + 1, pos + 1 - a2[4] - 6); + sub = content.substr(tokenPos + 1, pos + 1 - tokenPos - 6); } else { - sub = a2.substr(a2[4] + 1, pos + 1 - a2[4] - 5); + sub = content.substr(tokenPos + 1, pos + 1 - tokenPos - 5); } std::string data = ""); - for (int i = 1; i < a2[2]; i++) + for (int i = 1; i < a2.offset_8; i++) { data = "\n" + data; } - for (int i = 1; i < a2[3]; i++) + for (int i = 1; i < a2.offset_12; i++) { data = " " + data; } - // WXML::DOMLib::Parser::Parser(data); - // TODO... + WXML::DOMLib::Parser p; + std::vector v50; + bool parseResult = p.Parse(&content[0], errorMessage, filePath, v50); + if (!parseResult) + { + auto dom = p.GetParsed(); + *a6 = a2.offset_8; + if (tokenSize + tokenPos - (pos + 1)<= 0) + { + a5 = ""; + } + else{ + a5 = content.substr(pos + 1, tokenSize + tokenPos - (pos + 1)); + } + int v41 = 1; + for (int i = 0; i < a5.length(); i++) + { + /* code */ + int v14 = a5[i] - 9; + if (v14 > 0x17u) + { + v41 = 0; + } + else + { + bool v7 = ((0x800013u >> v14) & 1) == 0; + if (v7) + v41 = 0; + } + } + + // TODO.... + + } return 0; } @@ -358,7 +393,7 @@ namespace WXML{ auto it = a1.offset_12.find("name"); if (it != a1.offset_12.end()) { - a1.tag.replace(0, a1.tag.size(), "wx-define", 9u); + a1.offset_0.replace(0, a1.offset_0.size(), "wx-define", 9u); } } if (a1 == "wx-define") diff --git a/src/wxml/dom_lib/machine.cpp b/src/wxml/dom_lib/machine.cpp index 4ca8d64..131bf88 100644 --- a/src/wxml/dom_lib/machine.cpp +++ b/src/wxml/dom_lib/machine.cpp @@ -346,7 +346,7 @@ namespace WXML return; } this->offset_24 = v46; - if (bittest(&v46, 0x15u)) + if (bittest(&v46, 0x15u)) // 0x15 -> 21 { // TODO: if (this->fileLength > this->offset_4) @@ -358,20 +358,20 @@ namespace WXML a3.push_back(token); } } - if (bittest(&v46, 0x16u)) + if (bittest(&v46, 0x16u)) // 0x16 -> 22 { // TODO: - WXML::DOMLib::Token token(a5[0]); - // this->offset_4 = this->offset_4 - 112; + // WXML::DOMLib::Token token(*(a5.end() - 1)); + a5.pop_back(); // ---- // this->offset_4 = // this->offset_5 = } - }while(bittest(&v46, 0x14u)); + }while(bittest(&v46, 0x14u)); // 0x14 -> 20 - if (bittest(&v46, 0x11u)) + if (bittest(&v46, 0x11u)) // 0x11 -> 17 { if (this->offset_4 < this->fileLength) { @@ -395,7 +395,7 @@ namespace WXML this->fileLength++; this->lineLength++; - if (bittest(&v46, 0x12u)) + if (bittest(&v46, 0x12u)) // 0x12 -> 18 { this->offset_4 = this->fileLength; this->offset_20 = this->lineLength; diff --git a/src/wxml/dom_lib/parser.cpp b/src/wxml/dom_lib/parser.cpp index e318eb2..53cf037 100644 --- a/src/wxml/dom_lib/parser.cpp +++ b/src/wxml/dom_lib/parser.cpp @@ -93,7 +93,7 @@ namespace WXML if (!ret) { std::shared_ptr domPtr; - domPtr->tag = "root"; + domPtr->offset_0 = "root"; this->dom = domPtr; dequeDom.push_back(domPtr); // DOMS diff --git a/src/wxml/dom_lib/token.cpp b/src/wxml/dom_lib/token.cpp index 0210dda..161cc18 100644 --- a/src/wxml/dom_lib/token.cpp +++ b/src/wxml/dom_lib/token.cpp @@ -38,6 +38,18 @@ namespace WXML { this->offset_0 = content; } + std::string & Token::GetContent() + { + return this->offset_0; + } + int Token::GetPos() + { + return this->offset_16; + } + int Token::GetSize() + { + return this->offset_20; + } int Token::GetTemplateContent(std::string const& templateStr, std::string& result) { diff --git a/src/wxml/dom_lib/tokenizer.cpp b/src/wxml/dom_lib/tokenizer.cpp index 9ae1d6a..42128b6 100644 --- a/src/wxml/dom_lib/tokenizer.cpp +++ b/src/wxml/dom_lib/tokenizer.cpp @@ -32,7 +32,6 @@ namespace WXML } this->machine.Feed(0, a2, errorMessage, a4, 0); - // TODO: 少了 // 猜测:将fileContent地址赋值给a2,a4中所有的元素 for (int i = 0; i < a2.size(); i++) { diff --git a/src/wxml/dom_lib/wxml_dom.cpp b/src/wxml/dom_lib/wxml_dom.cpp index a6a50d5..6188ba4 100644 --- a/src/wxml/dom_lib/wxml_dom.cpp +++ b/src/wxml/dom_lib/wxml_dom.cpp @@ -42,7 +42,7 @@ namespace WXML { if (a15) { a6 << a12 << off_553FDC; - int id = offset_62.GetStrID(a2); + int id = offset_248.GetStrID(a2); a6 << id; a6 << "]][\""; WXML::Rewrite::ToStringCode(a5, a6); @@ -66,7 +66,7 @@ namespace WXML { { a6 << "var " << name; a6 << "=x["; - int id = this->offset_62.GetStrID(a2); + int id = this->offset_248.GetStrID(a2); a6 << id << "]"; a6 << "+':"; WXML::Rewrite::ToStringCode(a5, a6); @@ -77,7 +77,7 @@ namespace WXML { a6 << a13; a6 << "if(" << a14 << "[" << name << "]{_wl("; a6 << name << ",x["; - id = this->offset_62.GetStrID(a2); + id = this->offset_248.GetStrID(a2); a6 << id << "]);return}" << a13; a6 << a14 << "[" << name << "]=true"; @@ -156,32 +156,146 @@ namespace WXML { { a6 << "cs.push(\""; std::string sc = WXML::Rewrite::ToStringCode(a2); - a6 << sc << ":" << this->tag << ":" << this->offset_92 << ":" << this->offset_96 << "\")"; + a6 << sc << ":" << this->offset_0 << ":" << this->offset_92 << ":" << this->offset_96 << "\")"; } - if (this->tag == "TEXTNODE") + if (this->offset_0 == "TEXTNODE") { + int code = this->offset_140; + if (code == -3) + { + std::string ret = this->Error(a2, this->offset_84, "", this->offset_144); + throw ret; + } + if (code == -1) + { + std::string ret = this->Error(a2, this->offset_84, "", "value not set"); + throw ret; + } + a6 << "var " << a5 << "=_oz(z," << this->offset_140; + a6 << "," << a8 << "," << a9 << "," << a10 << ")"; + a6 << a12; + + // LABEL_169 + if (a13 && this->offset_28) + { + a6 << "cs.pop()" << a12; + } + return; } - if (this->tag == "wx-define" - ||this->tag == "wx-import" - ||this->tag == "import" - ||this->tag == "template") + if (this->offset_0 == "wx-define" + ||this->offset_0 == "wx-import" + ||this->offset_0 == "import" + ||this->offset_0 == "template") { + if (a13 && this->offset_28) + { + a6 << "cs.pop()" << a12; + } + return; } - if (this->tag == "wx-repeat") + if (this->offset_0 == "wx-repeat") { + std::string target1 = "items"; + if (this->offset_48.end() == this->offset_48.find(target1)) + { + target1 = "wx:for-items"; + } + std::string target2 = "index"; + if (this->offset_48.end() == this->offset_48.find(target2)) + { + target2 = "wx:for-index"; + } + std::string target3 = "item"; + if (this->offset_48.end() == this->offset_48.find(target3)) + { + target3 = "wx:for-item"; + } + if (this->offset_48.end() == this->offset_48.find(target1)) + { + return; + } + std::string target2_1 = ""; + if (this->offset_48.end() == this->offset_48.find(target2)) + { + target2_1 = "index"; + } + else + { + target2_1.assign(this->offset_48[target2].ToAttrContent()); + } + std::string target3_1 = ""; + if (this->offset_48.end() == this->offset_48.find(target3)) + { + target3_1 = "item"; + } + else + { + target3_1.assign(this->offset_48[target3].ToAttrContent()); + } + if (this->offset_48.end() != this->offset_48.find(target2) + && this->offset_48[target2].offset_56 == -3 + && (a14 & 1) == 0) + { + auto token = this->offset_48[target2]; + std::string err = this->Error(a2, token, target2, token.offset_60); + throw "RenderException" + err; + } + + std::string wxKey = "wx:key"; + if (this->offset_48.end() != this->offset_48.find(wxKey) + && this->offset_48[wxKey].offset_56 == -3 + && (a14 & 1) == 0) + { + std::string err = this->Error(a2, this->offset_48[wxKey], wxKey, this->offset_48[wxKey].offset_60); + throw "RenderException" + err; + } + + std::string name1; + a7->GetNextName(name1); + + std::string name2; + a7->GetNextName(name2); + + std::string name3; + a7->GetNextName(name3); + + std::string name4; + a7->GetNextName(name4); + + std::string v347 = ""; + std::string Str = ""; + WXML::DOMLib::WXMLDom::RenderMeAsFunction( + a2, + a3, + a4, + name1, + a6, + a7, + name3, + name2, + a10, + name4, + a11, + a12, + Str, + 0, + a13, + a14, + v347); + } - if (this->tag == "block") + if (this->offset_0 == "block") { } - if (this->tag == "include") + if (this->offset_0 == "include") { } - if (this->tag == "wx-template") + if (this->offset_0 == "wx-template") { } @@ -202,7 +316,7 @@ namespace WXML { } void WXMLDom::RecordAllPath(void) { - if(this->tag == "import" || this->tag == "include") + if(this->offset_0 == "import" || this->offset_0 == "include") { std::string v13 = "src"; int v8 = this->offset_12.count(v13); @@ -252,14 +366,14 @@ namespace WXML { } if (v4->tellp()) { - printf("pos: %d, %d, tag: %s, ", this->offset_92, this->offset_96, this->tag.c_str()); + printf("pos: %d, %d, tag: %s, ", this->offset_92, this->offset_96, this->offset_0.c_str()); } else { - *v4 << "pos: " << this->offset_92 << ", " << this->offset_96 << " tag: " << this->tag << ", "; + *v4 << "pos: " << this->offset_92 << ", " << this->offset_96 << " tag: " << this->offset_0 << ", "; } - if (this->tag == "TEXTNODE") + if (this->offset_0 == "TEXTNODE") { if (v4->tellp() != 0) { @@ -338,7 +452,7 @@ namespace WXML { } bool WXMLDom::operator==(std::string tag) { - return this->tag.compare(tag) == 0; + return this->offset_0.compare(tag) == 0; } std::string WXMLDom::Error( std::string const& a2,