feat: 添加函数

This commit is contained in:
msojocs 2023-06-22 20:46:57 +08:00
parent 838a6c8937
commit 7d592a8e61
7 changed files with 226 additions and 55 deletions

View File

@ -99,12 +99,19 @@ namespace WXML
bool offset_84; // hasCache attrContent bool offset_84; // hasCache attrContent
std::string offset_88; // chcheData attrContent std::string offset_88; // chcheData attrContent
public: public:
int offset_8; // ???
int offset_12; // ???
int offset_56; // ???
std::string offset_60; // ???
Token(); Token();
Token(std::string &); Token(std::string &);
Token(WXML::DOMLib::Token&&); Token(WXML::DOMLib::Token&&);
Token(WXML::DOMLib::Token const&); Token(WXML::DOMLib::Token const&);
~Token(); ~Token();
void SetContent(std::string &content); void SetContent(std::string &content);
std::string& GetContent();
int GetPos();
int GetSize();
std::string ToString(); std::string ToString();
/** /**
@ -204,14 +211,18 @@ namespace WXML
private: private:
/* data */ /* data */
bool offset_28; bool offset_28;
int offset_92; // pos1 std::map<std::string, WXML::DOMLib::Token> offset_48;
// std::string offset_52;
WXML::DOMLib::Token offset_84; // token WXML::DOMLib::Token offset_84; // token
int offset_92; // pos1
int offset_96; // pos2 int offset_96; // pos2
int offset_104; // len int offset_104; // len
StrCache offset_62; int offset_140;
std::string offset_144;
StrCache offset_248;
public: public:
std::string tag;
std::map<std::string, WXML::DOMLib::Token> offset_12; std::map<std::string, WXML::DOMLib::Token> offset_12;
std::string offset_0; // type
WXMLDom(/* args */); WXMLDom(/* args */);
~WXMLDom(); ~WXMLDom();
std::string Error( std::string Error(
@ -394,13 +405,13 @@ namespace WXML
std::string const& fMark); std::string const& fMark);
int DealWxsTag( int DealWxsTag(
std::string const&, std::string const& a1,
std::string &, WXML::DOMLib::Token & a2,
std::string&, std::string& a3,
std::string&, std::string& a4,
std::string&, std::string& a5,
int &, int & a6,
std::string& std::string& a7
); );
// void GetFuncId(); // void GetFuncId();

View File

@ -44,7 +44,7 @@ namespace WXML{
if (a != b) if (a != b)
{ {
ss << "f_['"; ss << "f_['";
// ss << ToStringCode(fileName); ss << WXML::Rewrite::ToStringCode(filePath);
ss << "']={};"; ss << "']={};";
ss << lineEndMark; ss << lineEndMark;
} }
@ -53,7 +53,7 @@ namespace WXML{
/* code */ /* code */
int dealResult = 0; int dealResult = 0;
std::string t; std::string t;
// dealResult = DealWxsTag(fileName, , t); // dealResult = WXML::Compiler::DealWxsTag(filePath, , t);
if (dealResult) if (dealResult)
{ {
// 非0 // 非0
@ -277,38 +277,73 @@ namespace WXML{
int DealWxsTag( int DealWxsTag(
std::string const& a1, std::string const& filePath,
std::string &a2, WXML::DOMLib::Token & a2,
std::string& a3, std::string& a3,
std::string& a4, std::string& a4,
std::string& a5, std::string& a5,
int & a6, int * a6,
std::string& a7) 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; 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 else
{ {
sub = a2.substr(a2[4] + 1, pos + 1 - a2[4] - 5); sub = content.substr(tokenPos + 1, pos + 1 - tokenPos - 5);
} }
std::string data = "<fak"; std::string data = "<fak";
data = data.append(sub); data = data.append(sub);
data = data.append("/>"); data = data.append("/>");
for (int i = 1; i < a2[2]; i++) for (int i = 1; i < a2.offset_8; i++)
{ {
data = "\n" + data; data = "\n" + data;
} }
for (int i = 1; i < a2[3]; i++) for (int i = 1; i < a2.offset_12; i++)
{ {
data = " " + data; data = " " + data;
} }
// WXML::DOMLib::Parser::Parser(data); WXML::DOMLib::Parser p;
// TODO... std::vector<WXML::DOMLib::Token> 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; return 0;
} }
@ -358,7 +393,7 @@ namespace WXML{
auto it = a1.offset_12.find("name"); auto it = a1.offset_12.find("name");
if (it != a1.offset_12.end()) 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") if (a1 == "wx-define")

View File

@ -346,7 +346,7 @@ namespace WXML
return; return;
} }
this->offset_24 = v46; this->offset_24 = v46;
if (bittest(&v46, 0x15u)) if (bittest(&v46, 0x15u)) // 0x15 -> 21
{ {
// TODO: // TODO:
if (this->fileLength > this->offset_4) if (this->fileLength > this->offset_4)
@ -358,20 +358,20 @@ namespace WXML
a3.push_back(token); a3.push_back(token);
} }
} }
if (bittest(&v46, 0x16u)) if (bittest(&v46, 0x16u)) // 0x16 -> 22
{ {
// TODO: // TODO:
WXML::DOMLib::Token token(a5[0]); // WXML::DOMLib::Token token(*(a5.end() - 1));
// this->offset_4 = this->offset_4 - 112; a5.pop_back();
// ---- // ----
// this->offset_4 = // this->offset_4 =
// this->offset_5 = // 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) if (this->offset_4 < this->fileLength)
{ {
@ -395,7 +395,7 @@ namespace WXML
this->fileLength++; this->fileLength++;
this->lineLength++; this->lineLength++;
if (bittest(&v46, 0x12u)) if (bittest(&v46, 0x12u)) // 0x12 -> 18
{ {
this->offset_4 = this->fileLength; this->offset_4 = this->fileLength;
this->offset_20 = this->lineLength; this->offset_20 = this->lineLength;

View File

@ -93,7 +93,7 @@ namespace WXML
if (!ret) if (!ret)
{ {
std::shared_ptr<WXML::DOMLib::WXMLDom> domPtr; std::shared_ptr<WXML::DOMLib::WXMLDom> domPtr;
domPtr->tag = "root"; domPtr->offset_0 = "root";
this->dom = domPtr; this->dom = domPtr;
dequeDom.push_back(domPtr); dequeDom.push_back(domPtr);
// DOMS // DOMS

View File

@ -38,6 +38,18 @@ namespace WXML
{ {
this->offset_0 = content; 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) int Token::GetTemplateContent(std::string const& templateStr, std::string& result)
{ {

View File

@ -32,7 +32,6 @@ namespace WXML
} }
this->machine.Feed(0, a2, errorMessage, a4, 0); this->machine.Feed(0, a2, errorMessage, a4, 0);
// TODO: 少了
// 猜测将fileContent地址赋值给a2,a4中所有的元素 // 猜测将fileContent地址赋值给a2,a4中所有的元素
for (int i = 0; i < a2.size(); i++) for (int i = 0; i < a2.size(); i++)
{ {

View File

@ -42,7 +42,7 @@ namespace WXML {
if (a15) if (a15)
{ {
a6 << a12 << off_553FDC; a6 << a12 << off_553FDC;
int id = offset_62.GetStrID(a2); int id = offset_248.GetStrID(a2);
a6 << id; a6 << id;
a6 << "]][\""; a6 << "]][\"";
WXML::Rewrite::ToStringCode(a5, a6); WXML::Rewrite::ToStringCode(a5, a6);
@ -66,7 +66,7 @@ namespace WXML {
{ {
a6 << "var " << name; a6 << "var " << name;
a6 << "=x["; a6 << "=x[";
int id = this->offset_62.GetStrID(a2); int id = this->offset_248.GetStrID(a2);
a6 << id << "]"; a6 << id << "]";
a6 << "+':"; a6 << "+':";
WXML::Rewrite::ToStringCode(a5, a6); WXML::Rewrite::ToStringCode(a5, a6);
@ -77,7 +77,7 @@ namespace WXML {
a6 << a13; a6 << a13;
a6 << "if(" << a14 << "[" << name << "]{_wl("; a6 << "if(" << a14 << "[" << name << "]{_wl(";
a6 << name << ",x["; a6 << name << ",x[";
id = this->offset_62.GetStrID(a2); id = this->offset_248.GetStrID(a2);
a6 << id << "]);return}" << a13; a6 << id << "]);return}" << a13;
a6 << a14 << "[" << name << "]=true"; a6 << a14 << "[" << name << "]=true";
@ -156,32 +156,146 @@ namespace WXML {
{ {
a6 << "cs.push(\""; a6 << "cs.push(\"";
std::string sc = WXML::Rewrite::ToStringCode(a2); 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->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->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->offset_0 == "block")
{ {
} }
if (this->tag == "wx-define" if (this->offset_0 == "include")
||this->tag == "wx-import"
||this->tag == "import"
||this->tag == "template")
{ {
} }
if (this->tag == "wx-repeat") if (this->offset_0 == "wx-template")
{
}
if (this->tag == "block")
{
}
if (this->tag == "include")
{
}
if (this->tag == "wx-template")
{ {
} }
@ -202,7 +316,7 @@ namespace WXML {
} }
void WXMLDom::RecordAllPath(void) void WXMLDom::RecordAllPath(void)
{ {
if(this->tag == "import" || this->tag == "include") if(this->offset_0 == "import" || this->offset_0 == "include")
{ {
std::string v13 = "src"; std::string v13 = "src";
int v8 = this->offset_12.count(v13); int v8 = this->offset_12.count(v13);
@ -252,14 +366,14 @@ namespace WXML {
} }
if (v4->tellp()) 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 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) if (v4->tellp() != 0)
{ {
@ -338,7 +452,7 @@ namespace WXML {
} }
bool WXMLDom::operator==(std::string tag) 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 WXMLDom::Error(
std::string const& a2, std::string const& a2,