feat: 增加一些方法

This commit is contained in:
msojocs 2023-06-14 20:50:18 +08:00
parent d76457d794
commit 4caf9f2581
11 changed files with 751 additions and 480 deletions

View File

@ -11,11 +11,12 @@ add_executable(wcc
src/wxml/rewrite.cpp
src/wxml/name_allocator.cpp
src/wxml/dom_lib/token.cpp
src/wxml/dom_lib/tokenizer.cpp
src/wxml/dom_lib/parser.cpp
src/wxml/compiler.cpp
src/wxml/dom_lib/str_cache.cpp
src/wxml/dom_lib/wxml_dom.cpp
src/wxml/dom_lib/machine.cpp
src/wxml/dom_lib/parser.cpp
src/utils/string_utils.cpp
src/utils/file.cpp
)
@ -27,9 +28,8 @@ add_executable(
test/resolve_path.cpp
src/wxml/dom_lib/common.cpp
)
add_test(
resolve_test
resolve_path
add_executable(test1
test/test.cpp
)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})

View File

@ -6,6 +6,19 @@ v
| 操作 | 数据 | 备注 |
|---|---|---- |
| v + 0 | data | 字符串内容 |
| v + 4 | size() | 字符串长度 |
| *(_DWORD *)(v + 4) | size() | 字符串长度 |
## std::deque
| 操作 | 数据 | 备注 |
|---|---|---- |
| (_DWORD *)(a1 + 8) | data | 内容 |
| (_DWORD *)(a1 + 16) | begin() | 起始 |
| (_DWORD *)(a1 + 32) | end() | 结束 |
## stringstream
osstream::sentry var
var + 16 <

View File

@ -7,6 +7,8 @@
#include <set>
#include <vector>
#include <cstring>
#include <memory>
#include <deque>
namespace WXML
{
@ -71,7 +73,10 @@ namespace WXML
{
private:
/* data */
std::string str1;
int offset_16;
int offset_20;
bool offset_28;
std::string offset_32;
std::string str2;
std::string str3;
public:
@ -91,6 +96,21 @@ namespace WXML
~Token();
};
class Tokenizer
{
private:
/* data */
public:
Tokenizer(char const*,std::string const&);
Tokenizer(/* args */);
~Tokenizer();
int GetTokens(
std::vector<WXML::DOMLib::Token> &,
std::string &,
std::vector<WXML::DOMLib::Token> &
);
};
/**
*
*/
@ -116,10 +136,11 @@ namespace WXML
{
private:
/* data */
std::string type;
bool offset_28;
int offset_92;
int offset_96;
int offset_92; // pos1
WXML::DOMLib::Token offset_84; // token
int offset_96; // pos2
int offset_104; // len
StrCache offset_62;
public:
std::string tag;
@ -178,6 +199,9 @@ namespace WXML
uint a14,
std::map<std::string,std::string> * a15
);
void RecordAllPath(void);
void Print(int,char const*,std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>> *);
void PrintMe(int,char const*,std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>> *);
bool operator==(std::string tag);
};
@ -188,6 +212,12 @@ namespace WXML
{
private:
/* data */
WXML::DOMLib::WXMLDom dom;
std::deque<std::string> dequeStr;
std::vector<WXML::DOMLib::Token> offset_88;
int offset_128;
std::string offset_328;
std::deque<std::shared_ptr<WXML::DOMLib::WXMLDom>> dequeDom;
public:
Parser(/* args */);
~Parser();
@ -206,7 +236,7 @@ namespace WXML
);
int Error(char const*, WXML::DOMLib::Token &);
std::string GetParsed();
WXML::DOMLib::WXMLDom GetParsed();
std::string DOM();
std::string DOMS();
std::vector<std::string> ATTR_LIST();
@ -308,20 +338,20 @@ namespace WXML
// void GetFuncId();
void GetVersionInfo(std::string &a1, std::string a2);
WXML::DOMLib::Parser ParseSource(
std::string const& content, // 源码?
std::string const& fileName, // 文件名?
std::string const& , //
char lineEndMark, // '\n'
std::string const& gwxMark, // gwxMark
std::string & fMark, // "f_"
std::map<std::string,std::string> const&, // fileData
std::string&, // 错误信息
std::map<std::string, WXML::DOMLib::WXMLDom>,// map<string, ?>
std::map<std::string,std::string>&,// ???
std::map<std::string,int>, // ???
bool, // mark指定运算结果是否非0
bool); // mark指定运算结果是否非0
std::string const& content, // 源码a2
std::string const& fileName, // 文件名? a3
char lineEndMark, // '\n' a4
std::string const& gwxMark, // gwxMark a5
std::string const& fMark, // "f_" a6
std::map<std::string,std::string> const&, // fileData a7
std::string&, // 错误信息 a8
std::map<std::string, WXML::DOMLib::WXMLDom &>,// map<string, ?> a9
std::map<std::string,std::string>&,// ??? a10
std::map<std::string,int>, // ??? a11
bool, // mark指定运算结果是否非0 a12
bool); // mark指定运算结果是否非0 a13
int RenderDefine(
WXML::DOMLib::WXMLDom &,
std::string const&,

View File

@ -10,7 +10,11 @@
using namespace std;
int main(int argc, const char **argv) {
int main(int argc, const char **argv)
{
try
{
string gwxMark = "$gwx";
string splitMarkStr = " ";
@ -23,29 +27,33 @@ int main(int argc, const char **argv) {
for (int i = 1; i < argc; i++)
{
if (!string("--config-path").compare(argv[i])) {
if (!string("--config-path").compare(argv[i]))
{
hasConfigParam = i + 1 < argc;
}
if (hasConfigParam) {
if (hasConfigParam)
{
// 有--config-path参数下一个参数是路径跳过
i++;
configPathLocation = argv[i];
}else {
}
else
{
paramList.emplace_back(argv[i]);
}
}
// 有配置文件,从配置文件解析
if (hasConfigParam) {
if (hasConfigParam)
{
int ret = readFile(configPathLocation.c_str(), configData);
string line;
if (0 == ret) {
if (0 == ret)
{
while ((line = getNextArg(configData, "\n")).size() > 0)
{
paramList.emplace_back(line);
}
}
}
int mark = 0;
@ -65,7 +73,8 @@ int main(int argc, const char **argv) {
for (int i = 0; i < paramList.size(); i++)
{
string param = paramList[i];
if (param[0] != '-') {
if (param[0] != '-')
{
// 不是参数名,跳过
fileList.push_back(param);
continue;
@ -77,11 +86,13 @@ int main(int argc, const char **argv) {
case 'd':
// output code for debug
/* code */
if(!param[2]){
if (!param[2])
{
mark |= 2u;
continue;
}
if(param[2] == 's') {
if (param[2] == 's')
{
mark |= 4u;
continue;
}
@ -89,11 +100,13 @@ int main(int argc, const char **argv) {
case 's':
// read from stdin
/* code */
if(param[2] == 't') {
if (param[2] == 't')
{
mark |= 8u;
continue;
}
if (i + 1 < paramList.size()) {
if (i + 1 < paramList.size())
{
fileList.push_back(paramList[i + 1]);
isReadFromStdin = true;
continue;
@ -111,9 +124,11 @@ int main(int argc, const char **argv) {
case 'x':
// -xc output simplified code for custom component
/* code */
if(param[2] == 'c' && i + 1 < paramList.size()) {
if (param[2] == 'c' && i + 1 < paramList.size())
{
hasXCParam = true;
if(paramList[i + 1][0] != '-') {
if (paramList[i + 1][0] != '-')
{
xc_Or_completeCode_Param.assign(paramList[i + 1]);
i++;
}
@ -123,9 +138,11 @@ int main(int argc, const char **argv) {
case 'c':
// -cc: output compelete code for custom component
/* code */
if(param[2] == 'c' && i + 1 < paramList.size()) {
if (param[2] == 'c' && i + 1 < paramList.size())
{
hasCompleteCodeParam = true;
if(paramList[i + 1][0] != '-') {
if (paramList[i + 1][0] != '-')
{
xc_Or_completeCode_Param.assign(paramList[i + 1]);
i++;
}
@ -136,7 +153,8 @@ int main(int argc, const char **argv) {
// -o: output destination (default stdout)
// -om XComponentDefine
/* code */
if (i + 1 < paramList.size()) {
if (i + 1 < paramList.size())
{
outputFileName = paramList[i + 1];
i++;
continue;
@ -145,7 +163,8 @@ int main(int argc, const char **argv) {
case 'g':
// -gn gwxMark
/* code */
if (param[2] == 'n' && i + 1 < paramList.size()) {
if (param[2] == 'n' && i + 1 < paramList.size())
{
gwxMark.assign(paramList[i + 1]);
i++;
continue;
@ -175,8 +194,10 @@ int main(int argc, const char **argv) {
}
// switch end
if (param == "--split") {
if (i + 1 < paramList.size()) {
if (param == "--split")
{
if (i + 1 < paramList.size())
{
splitMarkStr = paramList[i + 1];
i++;
continue;
@ -184,27 +205,35 @@ int main(int argc, const char **argv) {
}
// -cb
if(param[1] == 'c' && param[2] == 'b') {
if (param[1] == 'c' && param[2] == 'b')
{
string callbackFile = paramList[i + 1];
string callbackData;
readFile(callbackFile.c_str(), callbackData);
if (!callbackData.empty()) {
if (!callbackData.empty())
{
mapData1["life_cycle_callback_content"] = callbackData;
}
}
else {
if(!param.compare("--pm")) {
else
{
if (!param.compare("--pm"))
{
// 参数是--pm
if (i + 1 < paramList.size()) {
if (i + 1 < paramList.size())
{
mapData1["plain_text_marker"] = paramList[i + 1];
continue;
}
}
if (param[1] == 'l' && param[2] == 'l') {
if (param[1] == 'l' && param[2] == 'l')
{
// -ll
if (param[3] != 'w') {
if (param[3] != 'w')
{
// 不是 -llw
if (param[3] != 'a') {
if (param[3] != 'a')
{
// 不是 -lla
printf("Error: expected -llw or -lla, but got %s\n", param.c_str());
return -1;
@ -212,10 +241,13 @@ int main(int argc, const char **argv) {
isLLA = true;
}
string splitMark;
if (!splitMarkStr.compare(" ")) {
if (!splitMarkStr.compare(" "))
{
// 空格
splitMark = ",";
}else {
}
else
{
// 不是空格
splitMark = splitMarkStr;
}
@ -227,10 +259,12 @@ int main(int argc, const char **argv) {
}
}
if (version) {
if (version)
{
std::string versionInfo;
WXML::Compiler::GetVersionInfo(versionInfo, "global");
if (!outputFileName.empty()) {
if (!outputFileName.empty())
{
FILE *f;
f = fopen(outputFileName.c_str(), "w");
fprintf(f, "%s\n", versionInfo.c_str());
@ -238,17 +272,20 @@ int main(int argc, const char **argv) {
}
}
if (fileList.empty()) {
if (fileList.empty())
{
usage(argc, argv);
return 0;
}
if (isReadFromStdin) {
if (isReadFromStdin)
{
string content;
readFile(0, content);
fileContentMap[fileList[0]] = content;
}
else {
else
{
// 读取文件内容
for (int i = 0; i < fileList.size(); i++)
@ -257,7 +294,6 @@ int main(int argc, const char **argv) {
readFile(fileList[i].c_str(), content);
fileContentMap[fileList[i]] = content;
}
}
// 此if条件x64dbg得出
@ -340,7 +376,16 @@ int main(int argc, const char **argv) {
"boxofchocolate",
"$gdwx",
"f_");
// while()
// while(!outputMap1.empty())
// {
// /**
// * v60可能值 0xF30D70:0xF30DB8:"miniprogram_npm/miniprogram-recycle-view/recycle-view"
// */
// // if(v60 == "__COMMON__")
// // {
// // }
// }
// if()
if (1)
@ -377,7 +422,8 @@ int main(int argc, const char **argv) {
for (string j = "";;)
{
/* code */
if (j == "") break;
if (j == "")
break;
if (j[11] != j[10])
{
@ -397,12 +443,14 @@ int main(int argc, const char **argv) {
}
// ???
outputMap1["__COMMON__"].append("");
if (compilerResult) {
if (compilerResult)
{
// CompileLazy出现异常
// 标准错误输出
fprintf(stderr, "Error %d: %s\n", 1, "123");
}
else {
else
{
FILE *f = stdout;
if (!outputFileName.empty())
f = fopen(outputFileName.c_str(), "w");
@ -411,9 +459,9 @@ int main(int argc, const char **argv) {
fprintf(f, " {\"generateFunctionContent\":%s,\"generateFunctionName\":%s} ", "", "");
fclose(f);
}
}
else {
else
{
const char off_5403C3[] = {'s', '\0', 'e', '\0'};
int compilerResult = 0;
// compilerResult = WXML::Compiler::Compile(
@ -438,17 +486,27 @@ int main(int argc, const char **argv) {
// "$gdwx", // "$gdwx"
// "f_"); // "f_"
FILE *f;
if (compilerResult) {
if (compilerResult)
{
f = stderr;
fprintf(f, "%s\n", "error...");
}else {
}
else
{
f = stdout;
if (!outputFileName.empty()) {
if (!outputFileName.empty())
{
f = fopen(outputFileName.c_str(), "w");
}
fprintf(f, "%s\n", "result...");
fclose(f);
}
}
}
catch (const std::exception &e)
{
std::cerr << e.what() << '\n';
}
return 0;
}

View File

@ -41,24 +41,22 @@ namespace WXML{
for (auto it = fileContentMap.begin(); it != fileContentMap.end(); it++)
{
/* code */
int parseResult = 0;
// parseResult = WXML::Compiler::ParseSource(
// it->second, // 源码?
// it->first, // 文件名
// "\n",//
// lineEndMark, // '\n'
// gwxMark, // gwxMark
// fMark, // "f_"
// fileContentMap, // fileContentMap
// errorMessage, // 错误信息
// &v304, // map<string, ?>
// &v309, // ???
// &v311, // ???
// (mark & 4) != 0, // a11 -> mark
// (mark & 0x20) != 0);
if (parseResult) {
return parseResult;
}
// WXML::DOMLib::Parser parseResult = ParseSource(
// it->second, // 源码a2
// it->first, // 文件名 a3
// lineEndMark, // '\n' a4
// gwxMark, // gwxMark a5
// fMark, // "f_" a6
// fileContentMap, // fileContentMap a7
// errorMessage, // 错误信息 a8
// &v304, // map<string, WXML::DOMLib::WXMLDom> a9
// &v309, // ??? a10
// &v311, // ??? a11
// (mark & 4) != 0, // a11 -> mark a12
// (mark & 0x20) != 0); // a13
// if (parseResult) {
// return parseResult;
// }
}
std::shared_ptr<std::stringstream> v301_localCommonStream1; // v301
ssDataMap["__COMMON__"] = v301_localCommonStream1;
@ -147,33 +145,34 @@ namespace WXML{
}
WXML::DOMLib::Parser ParseSource(
std::string const& fileName, // 文件名?
std::string const& content, // 源码?
char lineEndMark, // '\n'
std::string const& gwxMark, // gwxMark
std::string const& fMark, // "f_"
std::map<std::string,std::string> const&, // fileContentMap
std::string& errorMessage, // 错误信息
std::map<std::string,WXML::DOMLib::WXMLDom> result,// map<string, ?>
std::map<std::string,std::string>& map1,// ???
std::map<std::string,int> map2, // ???
bool b1, // mark指定运算结果是否非0
bool b2) // mark指定运算结果是否非0
std::string const& fileName, // 文件名?a2
std::string const& content, // 源码?a3
char lineEndMark, // '\n' a4
std::string const& gwxMark, // gwxMark a5
std::string const& fMark, // "f_" a6
std::map<std::string,std::string> const&, // fileContentMap a7
std::string& errorMessage, // 错误信息 a8
std::map<std::string, WXML::DOMLib::WXMLDom> result,// map<string, ?> a9
std::map<std::string,std::string>& map1,// ??? a10
std::map<std::string,int> map2, // ??? a11
bool b1, // mark指定运算结果是否非0 a12
bool b2) // mark指定运算结果是否非0 a13
{
WXML::DOMLib::Parser pResult;
bool isWxml = fileName.substr(fileName.length() - 5) == ".wxml";
if (isWxml)
{
// parse
int parseResult = 0;
// pResult.Parse();
if (parseResult)
throw "";
bool parseResult = false;
WXML::DOMLib::Parser v50;
std::vector<WXML::DOMLib::Token> tokenList; // v102
parseResult = v50.Parse(content.c_str(), errorMessage, fileName, tokenList);
if (!parseResult)
if (parseResult)
{
// GetParsed
// result[fileName] = ""
// WXML::DOMLib::WXMLDom parseDom = v50.GetParsed();
// result[fileName] = parseDom;
int a;
int b;
std::stringstream ss;

View File

@ -22,12 +22,30 @@ namespace WXML
}
bool Parser::Parse(
char const* fileContent,
std::string &,
std::string const&,
std::vector<WXML::DOMLib::Token> &
std::string & a4,
std::string const& a5,
std::vector<WXML::DOMLib::Token> & a6
)
{
return true;
}
this->dequeStr.clear();
this->dequeDom.clear();
this->offset_128 = 4;
this->offset_328.assign(a5);
WXML::DOMLib::Tokenizer v15(fileContent, a5);
int ret = v15.GetTokens(this->offset_88, a4, a6);
if (!ret)
{
std::shared_ptr<WXML::DOMLib::WXMLDom> domPtr;
dom.tag = "root";
domPtr.get()->tag = "root";
dequeDom.push_back(domPtr);
// DOMS
}
return ret == 0;
}
// WXML::DOMLib::WXMLDom Parser::GetParsed()
// {
// return 0;
// }
}
}

View File

@ -24,6 +24,16 @@ namespace WXML
{
return "";
}
std::string Token::ToString()
{
std::string v4 = "";
if (!this->offset_28)
{
v4 = this->offset_32.substr(this->offset_16, this->offset_20);
this->offset_28 = true;
}
return v4;
}
bool Token::IsMatch(char const&)
{

View File

@ -0,0 +1,28 @@
#include "../../include/wxml.h"
namespace WXML
{
namespace DOMLib
{
Tokenizer::Tokenizer(char const*,std::string const&)
{
}
Tokenizer::Tokenizer(/* args */)
{
}
Tokenizer::~Tokenizer()
{
}
int Tokenizer::GetTokens(
std::vector<WXML::DOMLib::Token> &,
std::string &,
std::vector<WXML::DOMLib::Token> &
)
{
return 0;
}
}
}

View File

@ -158,30 +158,30 @@ namespace WXML {
std::string sc = WXML::Rewrite::ToStringCode(a2);
a6 << sc << ":" << this->tag << ":" << this->offset_92 << ":" << this->offset_96 << "\")";
}
if (this->type == "TEXTNODE")
if (this->tag == "TEXTNODE")
{
}
if (this->type == "wx-define"
||this->type == "wx-import"
||this->type == "import"
||this->type == "template")
if (this->tag == "wx-define"
||this->tag == "wx-import"
||this->tag == "import"
||this->tag == "template")
{
}
if (this->type == "wx-repeat")
if (this->tag == "wx-repeat")
{
}
if (this->type == "block")
if (this->tag == "block")
{
}
if (this->type == "include")
if (this->tag == "include")
{
}
if (this->type == "wx-template")
if (this->tag == "wx-template")
{
}
@ -200,6 +200,101 @@ namespace WXML {
// }
}
void WXMLDom::RecordAllPath(void)
{
if(this->tag == "import" || this->tag == "include")
{
std::string v13 = "src";
int v8 = this->offset_12.count(v13);
if (v8)
{
std::string attr = this->offset_12[v13].ToAttrContent();
}
}
}
void WXMLDom::Print(int,char const*,std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>> *)
{
}
void WXMLDom::PrintMe(
int a2,
char const* a3,
std::stringstream* a4)
{
std::stringstream v34;
std::stringstream *v4 = &v34;
if (a4)
{
v4 = a4;
}
if (v4->tellp() != 0)
{
printf("%s", a3);
}
else
{
*v4 << a3;
}
for (int i = 0; ; i++)
{
/* code */
if ( i >= a2)
break;
if (v4->tellp())
{
printf(" ");
}
else
{
*v4 << " ";
}
}
if (v4->tellp())
{
printf("pos: %d, %d, tag: %s, ", this->offset_92, this->offset_96, this->tag.c_str());
}
else
{
*v4 << "pos: " << this->offset_92 << ", " << this->offset_96 << " tag: " << this->tag << ", ";
}
if (this->tag == "TEXTNODE")
{
if (v4->tellp() != 0)
{
printf("attr: ");
}
else
{
*v4 << "attr: ";
}
// TODO: this + 60是什么
// for (size_t i = 0; i < count; i++)
// {
// /* code */
// }
}
else if(v4->tellp() != 0)
{
//TODO: this+84是什么
printf(
"pos: %d, %d, len: %d, %s",
this->offset_92,
this->offset_96,
this->offset_104,
"TODO..."
);
}
else
{
*v4 << "pos: " << this->offset_92
<< ", " << this->offset_96 << ", len: " << this->offset_104
<< ", ";
// *v4 << this->offset_84;
}
}
bool WXMLDom::operator==(std::string tag)
{
return this->tag.compare(tag) == 0;

20
test/test.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <iostream>
#include <deque>
using namespace std;
int main(int argc, char const *argv[])
{
std::deque<std::string> que;
que.push_back("123");
int i = 0;
while (que.begin() != que.end())
{
que.pop_back();
cout << "count: " << ++i << endl;
if (i > 100) break;
}
que.clear();
return 0;
}

View File

@ -23007,7 +23007,7 @@ void __usercall WXML::DOMLib::Parser::DOM(_DWORD *a1@<ecx>, WXML::DOMLib::Parser
WXML::DOMLib::Parser::Error(exception, (WXML::DOMLib::Parser *)a1, "unexpected tag", 0);
__cxa_throw(
exception,
(struct type_info *)&`typeinfo for'WXML::DOMLib::ParseException,
(struct type_info *)&`typeinfo for WXML::DOMLib::ParseException,
WXML::DOMLib::ParseException::~ParseException);
}
++a1[25];
@ -23056,7 +23056,7 @@ void __usercall WXML::DOMLib::Parser::DOM(_DWORD *a1@<ecx>, WXML::DOMLib::Parser
(WXML::DOMLib::Token *)&v45);
__cxa_throw(
v31,
(struct type_info *)&`typeinfo for'WXML::DOMLib::ParseException,
(struct type_info *)&`typeinfo for WXML::DOMLib::ParseException,
WXML::DOMLib::ParseException::~ParseException);
}
++a1[25];
@ -23083,7 +23083,7 @@ void __usercall WXML::DOMLib::Parser::DOM(_DWORD *a1@<ecx>, WXML::DOMLib::Parser
WXML::DOMLib::Parser::Error(v30, (WXML::DOMLib::Parser *)a1, v41, 0);
__cxa_throw(
v30,
(struct type_info *)&`typeinfo for'WXML::DOMLib::ParseException,
(struct type_info *)&`typeinfo for WXML::DOMLib::ParseException,
WXML::DOMLib::ParseException::~ParseException);
}
++a1[25];
@ -23515,7 +23515,7 @@ int __cdecl WXML::DOMLib::WXMLDom::DealSingleTokenToOps(
std::string::_M_dispose(&Block);
__cxa_throw(
exception,
(struct type_info *)&`typeinfo for'WXML::DOMLib::RenderException,
(struct type_info *)&`typeinfo for WXML::DOMLib::RenderException,
WXML::DOMLib::RenderException::~RenderException);
}
if ( a8 )