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/rewrite.cpp
src/wxml/name_allocator.cpp src/wxml/name_allocator.cpp
src/wxml/dom_lib/token.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/compiler.cpp
src/wxml/dom_lib/str_cache.cpp src/wxml/dom_lib/str_cache.cpp
src/wxml/dom_lib/wxml_dom.cpp src/wxml/dom_lib/wxml_dom.cpp
src/wxml/dom_lib/machine.cpp src/wxml/dom_lib/machine.cpp
src/wxml/dom_lib/parser.cpp
src/utils/string_utils.cpp src/utils/string_utils.cpp
src/utils/file.cpp src/utils/file.cpp
) )
@ -27,9 +28,8 @@ add_executable(
test/resolve_path.cpp test/resolve_path.cpp
src/wxml/dom_lib/common.cpp src/wxml/dom_lib/common.cpp
) )
add_test( add_executable(test1
resolve_test test/test.cpp
resolve_path
) )
set(CPACK_PROJECT_NAME ${PROJECT_NAME}) set(CPACK_PROJECT_NAME ${PROJECT_NAME})

View File

@ -6,6 +6,19 @@ v
| 操作 | 数据 | 备注 | | 操作 | 数据 | 备注 |
|---|---|---- | |---|---|---- |
| v + 0 | data | 字符串内容 | | 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 <set>
#include <vector> #include <vector>
#include <cstring> #include <cstring>
#include <memory>
#include <deque>
namespace WXML namespace WXML
{ {
@ -71,7 +73,10 @@ namespace WXML
{ {
private: private:
/* data */ /* data */
std::string str1; int offset_16;
int offset_20;
bool offset_28;
std::string offset_32;
std::string str2; std::string str2;
std::string str3; std::string str3;
public: public:
@ -91,6 +96,21 @@ namespace WXML
~Token(); ~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: private:
/* data */ /* data */
std::string type;
bool offset_28; bool offset_28;
int offset_92; int offset_92; // pos1
int offset_96; WXML::DOMLib::Token offset_84; // token
int offset_96; // pos2
int offset_104; // len
StrCache offset_62; StrCache offset_62;
public: public:
std::string tag; std::string tag;
@ -178,6 +199,9 @@ namespace WXML
uint a14, uint a14,
std::map<std::string,std::string> * a15 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); bool operator==(std::string tag);
}; };
@ -188,6 +212,12 @@ namespace WXML
{ {
private: private:
/* data */ /* 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: public:
Parser(/* args */); Parser(/* args */);
~Parser(); ~Parser();
@ -206,7 +236,7 @@ namespace WXML
); );
int Error(char const*, WXML::DOMLib::Token &); int Error(char const*, WXML::DOMLib::Token &);
std::string GetParsed(); WXML::DOMLib::WXMLDom GetParsed();
std::string DOM(); std::string DOM();
std::string DOMS(); std::string DOMS();
std::vector<std::string> ATTR_LIST(); std::vector<std::string> ATTR_LIST();
@ -308,20 +338,20 @@ namespace WXML
// void GetFuncId(); // void GetFuncId();
void GetVersionInfo(std::string &a1, std::string a2); void GetVersionInfo(std::string &a1, std::string a2);
WXML::DOMLib::Parser ParseSource( WXML::DOMLib::Parser ParseSource(
std::string const& content, // 源码? std::string const& content, // 源码a2
std::string const& fileName, // 文件名? std::string const& fileName, // 文件名? a3
std::string const& , // char lineEndMark, // '\n' a4
char lineEndMark, // '\n' std::string const& gwxMark, // gwxMark a5
std::string const& gwxMark, // gwxMark std::string const& fMark, // "f_" a6
std::string & fMark, // "f_" std::map<std::string,std::string> const&, // fileData a7
std::map<std::string,std::string> const&, // fileData std::string&, // 错误信息 a8
std::string&, // 错误信息 std::map<std::string, WXML::DOMLib::WXMLDom &>,// map<string, ?> a9
std::map<std::string, WXML::DOMLib::WXMLDom>,// map<string, ?> std::map<std::string,std::string>&,// ??? a10
std::map<std::string,std::string>&,// ??? std::map<std::string,int>, // ??? a11
std::map<std::string,int>, // ??? bool, // mark指定运算结果是否非0 a12
bool, // mark指定运算结果是否非0 bool); // mark指定运算结果是否非0 a13
bool); // mark指定运算结果是否非0
int RenderDefine( int RenderDefine(
WXML::DOMLib::WXMLDom &, WXML::DOMLib::WXMLDom &,
std::string const&, std::string const&,

View File

@ -10,445 +10,503 @@
using namespace std; using namespace std;
int main(int argc, const char **argv) { int main(int argc, const char **argv)
{
string gwxMark = "$gwx"; try
string splitMarkStr = " ";
bool hasConfigParam = false;
string configPathLocation;
vector<string> paramList;
string configData;
// 第一个参数是程序路径,忽略
for (int i = 1; i < argc; i++)
{ {
if (!string("--config-path").compare(argv[i])) { string gwxMark = "$gwx";
hasConfigParam = i + 1 < argc; string splitMarkStr = " ";
} bool hasConfigParam = false;
if (hasConfigParam) { string configPathLocation;
// 有--config-path参数下一个参数是路径跳过 vector<string> paramList;
i++; string configData;
configPathLocation = argv[i];
}else {
paramList.emplace_back(argv[i]);
}
} // 第一个参数是程序路径,忽略
for (int i = 1; i < argc; i++)
// 有配置文件,从配置文件解析
if (hasConfigParam) {
int ret = readFile(configPathLocation.c_str(), configData);
string line;
if (0 == ret) {
while ((line = getNextArg(configData, "\n")).size() > 0)
{
paramList.emplace_back(line);
}
}
}
int mark = 0;
bool isReadFromStdin = false;
bool version = false;
bool hasXCParam = false;
bool hasCompleteCodeParam = false;
bool isLLA = false;
bool hasLL = false;
string xc_Or_completeCode_Param;
string outputFileName;
vector<string> fileList;
vector<string> splitedData;
map<string, string> mapData1;
map<string, string> fileContentMap;
map<string, vector<string>> vecFileContentMap;
for (int i = 0; i < paramList.size(); i++)
{
string param = paramList[i];
if (param[0] != '-') {
// 不是参数名,跳过
fileList.push_back(param);
continue;
}
// 是参数名-xxx
switch (param[1])
{ {
case 'd':
// output code for debug if (!string("--config-path").compare(argv[i]))
/* code */ {
if(!param[2]){ hasConfigParam = i + 1 < argc;
mark |= 2u;
continue;
} }
if(param[2] == 's') { if (hasConfigParam)
mark |= 4u; {
continue; // 有--config-path参数下一个参数是路径跳过
i++;
configPathLocation = argv[i];
} }
break;
case 's':
// read from stdin
/* code */
if(param[2] == 't') {
mark |= 8u;
continue;
}
if (i + 1 < paramList.size()) {
fileList.push_back(paramList[i + 1]);
isReadFromStdin = true;
continue;
}
break;
case 'v':
// 版本信息
/* code */
if (param[2] == 'b')
mark |= 0x10u;
else else
version = true; {
continue; paramList.emplace_back(argv[i]);
break; }
case 'x': }
// -xc output simplified code for custom component
/* code */ // 有配置文件,从配置文件解析
if(param[2] == 'c' && i + 1 < paramList.size()) { if (hasConfigParam)
hasXCParam = true; {
if(paramList[i + 1][0] != '-') { int ret = readFile(configPathLocation.c_str(), configData);
xc_Or_completeCode_Param.assign(paramList[i + 1]); string line;
i++; if (0 == ret)
{
while ((line = getNextArg(configData, "\n")).size() > 0)
{
paramList.emplace_back(line);
} }
}
}
int mark = 0;
bool isReadFromStdin = false;
bool version = false;
bool hasXCParam = false;
bool hasCompleteCodeParam = false;
bool isLLA = false;
bool hasLL = false;
string xc_Or_completeCode_Param;
string outputFileName;
vector<string> fileList;
vector<string> splitedData;
map<string, string> mapData1;
map<string, string> fileContentMap;
map<string, vector<string>> vecFileContentMap;
for (int i = 0; i < paramList.size(); i++)
{
string param = paramList[i];
if (param[0] != '-')
{
// 不是参数名,跳过
fileList.push_back(param);
continue; continue;
} }
break;
case 'c': // 是参数名-xxx
// -cc: output compelete code for custom component switch (param[1])
/* code */ {
if(param[2] == 'c' && i + 1 < paramList.size()) { case 'd':
hasCompleteCodeParam = true; // output code for debug
if(paramList[i + 1][0] != '-') { /* code */
xc_Or_completeCode_Param.assign(paramList[i + 1]); if (!param[2])
i++; {
mark |= 2u;
continue;
} }
if (param[2] == 's')
{
mark |= 4u;
continue;
}
break;
case 's':
// read from stdin
/* code */
if (param[2] == 't')
{
mark |= 8u;
continue;
}
if (i + 1 < paramList.size())
{
fileList.push_back(paramList[i + 1]);
isReadFromStdin = true;
continue;
}
break;
case 'v':
// 版本信息
/* code */
if (param[2] == 'b')
mark |= 0x10u;
else
version = true;
continue; continue;
} break;
break; case 'x':
case 'o': // -xc output simplified code for custom component
// -o: output destination (default stdout) /* code */
// -om XComponentDefine if (param[2] == 'c' && i + 1 < paramList.size())
/* code */ {
if (i + 1 < paramList.size()) { hasXCParam = true;
outputFileName = paramList[i + 1]; if (paramList[i + 1][0] != '-')
i++; {
xc_Or_completeCode_Param.assign(paramList[i + 1]);
i++;
}
continue;
}
break;
case 'c':
// -cc: output compelete code for custom component
/* code */
if (param[2] == 'c' && i + 1 < paramList.size())
{
hasCompleteCodeParam = true;
if (paramList[i + 1][0] != '-')
{
xc_Or_completeCode_Param.assign(paramList[i + 1]);
i++;
}
continue;
}
break;
case 'o':
// -o: output destination (default stdout)
// -om XComponentDefine
/* code */
if (i + 1 < paramList.size())
{
outputFileName = paramList[i + 1];
i++;
continue;
}
break;
case 'g':
// -gn gwxMark
/* code */
if (param[2] == 'n' && i + 1 < paramList.size())
{
gwxMark.assign(paramList[i + 1]);
i++;
continue;
}
break;
case 'p':
/* code */
mark |= 0x20u;
continue; continue;
} break;
break;
case 'g': case 't':
// -gn gwxMark /* code */
/* code */ mark |= 1u;
if (param[2] == 'n' && i + 1 < paramList.size()) {
gwxMark.assign(paramList[i + 1]);
i++;
continue; continue;
} break;
break;
case 'p': case 'i':
/* code */ /* code */
mark |= 0x20u; mark |= 0x40u;
continue;
break;
case 't':
/* code */
mark |= 1u;
continue;
break;
case 'i':
/* code */
mark |= 0x40u;
continue;
break;
default:
break;
}
// switch end
if (param == "--split") {
if (i + 1 < paramList.size()) {
splitMarkStr = paramList[i + 1];
i++;
continue; continue;
} break;
}
// -cb default:
if(param[1] == 'c' && param[2] == 'b') { break;
string callbackFile = paramList[i + 1];
string callbackData;
readFile(callbackFile.c_str(), callbackData);
if (!callbackData.empty()) {
mapData1["life_cycle_callback_content"] = callbackData;
} }
} // switch end
else {
if(!param.compare("--pm")) { if (param == "--split")
// 参数是--pm {
if (i + 1 < paramList.size()) { if (i + 1 < paramList.size())
mapData1["plain_text_marker"] = paramList[i + 1]; {
splitMarkStr = paramList[i + 1];
i++;
continue; continue;
} }
} }
if (param[1] == 'l' && param[2] == 'l') {
// -ll // -cb
if (param[3] != 'w') { if (param[1] == 'c' && param[2] == 'b')
// 不是 -llw {
if (param[3] != 'a') { string callbackFile = paramList[i + 1];
// 不是 -lla string callbackData;
printf("Error: expected -llw or -lla, but got %s\n", param.c_str()); readFile(callbackFile.c_str(), callbackData);
return -1; if (!callbackData.empty())
{
mapData1["life_cycle_callback_content"] = callbackData;
}
}
else
{
if (!param.compare("--pm"))
{
// 参数是--pm
if (i + 1 < paramList.size())
{
mapData1["plain_text_marker"] = paramList[i + 1];
continue;
} }
isLLA = true;
} }
string splitMark; if (param[1] == 'l' && param[2] == 'l')
if (!splitMarkStr.compare(" ")) { {
// 空格 // -ll
splitMark = ","; if (param[3] != 'w')
}else { {
// 不是空格 // 不是 -llw
splitMark = splitMarkStr; if (param[3] != 'a')
{
// 不是 -lla
printf("Error: expected -llw or -lla, but got %s\n", param.c_str());
return -1;
}
isLLA = true;
}
string splitMark;
if (!splitMarkStr.compare(" "))
{
// 空格
splitMark = ",";
}
else
{
// 不是空格
splitMark = splitMarkStr;
}
// 分割 -llw -lla 接下来的一个参数
split(splitedData, paramList[i + 1], splitMark);
i++;
hasLL = true;
} }
// 分割 -llw -lla 接下来的一个参数
split(splitedData, paramList[i + 1], splitMark);
i++;
hasLL = true;
} }
} }
}
if (version) { if (version)
std::string versionInfo; {
WXML::Compiler::GetVersionInfo(versionInfo, "global"); std::string versionInfo;
if (!outputFileName.empty()) { WXML::Compiler::GetVersionInfo(versionInfo, "global");
FILE *f; if (!outputFileName.empty())
f = fopen(outputFileName.c_str(), "w"); {
fprintf(f, "%s\n", versionInfo.c_str()); FILE *f;
fclose(f); f = fopen(outputFileName.c_str(), "w");
fprintf(f, "%s\n", versionInfo.c_str());
fclose(f);
}
} }
}
if (fileList.empty()) { if (fileList.empty())
usage(argc, argv); {
return 0; usage(argc, argv);
} return 0;
}
if (isReadFromStdin) { if (isReadFromStdin)
string content;
readFile(0, content);
fileContentMap[fileList[0]] = content;
}
else {
// 读取文件内容
for (int i = 0; i < fileList.size(); i++)
{ {
string content; string content;
readFile(fileList[i].c_str(), content); readFile(0, content);
fileContentMap[fileList[i]] = content; fileContentMap[fileList[0]] = content;
}
}
// 此if条件x64dbg得出
if (!xc_Or_completeCode_Param.empty())
{
string data;
string arg2;
vector<string> list1;
vector<string> list2;
data = getNextArg(xc_Or_completeCode_Param, splitMarkStr);
unsigned long long count = strtoull(&data[0], 0, 10);
for (unsigned long long i = 0; i < count; i++)
{
string arg1 = getNextArg(xc_Or_completeCode_Param, splitMarkStr);
data = getNextArg(xc_Or_completeCode_Param, splitMarkStr);
unsigned long long jCount = strtoull(&data[0], 0, 10);
for (unsigned long long i = 0; i < jCount; i++)
{
arg2 = getNextArg(xc_Or_completeCode_Param, splitMarkStr);
list1.push_back(arg2);
auto it = vecFileContentMap.find(arg2);
if (it == vecFileContentMap.end())
{
list2.push_back(arg2);
}
}
// TODO: 还有问题
auto it = vecFileContentMap.lower_bound(arg1);
if (it == vecFileContentMap.end() || arg1 < it->first)
{
vector<string> d;
vecFileContentMap.emplace(arg1, d);
}
// list1
it->second = list1;
}
vecFileContentMap["ALL"] = list2;
}
//
if (hasLL)
{
// 处理文件路径
for (int i = 0; i < splitedData.size(); i++)
{
string path = splitedData[i];
if (path[0] == '.' && path[1] == '/')
{
// 以"./"开头,去掉前两个字符
splitedData[i] = path.substr(2);
}
}
map<string, string> outputMap1;
map<string, string> outputMap2;
map<string, vector<string>> vecFileContentMap2;
const char off_5403C3[] = {'s','\0','e','\0'};
int compilerResult = 0;
string errorMessage;
compilerResult = WXML::Compiler::CompileLazy(
fileContentMap,
errorMessage,
outputMap1,
outputMap2, // map<string, string>
vecFileContentMap2, // std::map<std::string,std::vector<std::string>>
vecFileContentMap, // vecFileContentMap
splitedData,
mapData1,
isLLA,
gwxMark,
mark,
10,
&off_5403C3[2],
off_5403C3,
"gg",
"e_",
"d_",
"p_",
"\0",
"boxofchocolate",
"$gdwx",
"f_");
// while()
// if()
if (1)
{
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);";
data = data + helperCode;
outputMap1["__COMMON__"] = data;
} }
else else
{ {
string helperCode;
WXML::Compiler::WXMLHelperCode(helperCode);
string commonData = "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);";
commonData += helperCode;
commonData = commonData.append(outputMap1["__COMMON__"]);
outputMap1["__COMMON__"] = commonData; // 读取文件内容
} for (int i = 0; i < fileList.size(); i++)
string dep = ";var __WXML_DEP__=__WXML_DEP__||{};";
// TODO: 起始并不是0
for (string j = ""; ; )
{
/* code */
if (j == "") break;
if (j[11] != j[10])
{ {
stringstream dep; string content;
dep << "__WXML_DEP__[\""; readFile(fileList[i].c_str(), content);
dep << "\"]=["; fileContentMap[fileList[i]] = content;
}
}
for (int k = 0; k < 10; k++) // 此if条件x64dbg得出
if (!xc_Or_completeCode_Param.empty())
{
string data;
string arg2;
vector<string> list1;
vector<string> list2;
data = getNextArg(xc_Or_completeCode_Param, splitMarkStr);
unsigned long long count = strtoull(&data[0], 0, 10);
for (unsigned long long i = 0; i < count; i++)
{
string arg1 = getNextArg(xc_Or_completeCode_Param, splitMarkStr);
data = getNextArg(xc_Or_completeCode_Param, splitMarkStr);
unsigned long long jCount = strtoull(&data[0], 0, 10);
for (unsigned long long i = 0; i < jCount; i++)
{ {
/* code */ arg2 = getNextArg(xc_Or_completeCode_Param, splitMarkStr);
dep << "\""; list1.push_back(arg2);
dep << "\","; auto it = vecFileContentMap.find(arg2);
if (it == vecFileContentMap.end())
{
list2.push_back(arg2);
}
} }
// TODO: 还有问题
dep << "];"; auto it = vecFileContentMap.lower_bound(arg1);
if (it == vecFileContentMap.end() || arg1 < it->first)
{
vector<string> d;
vecFileContentMap.emplace(arg1, d);
}
// list1
it->second = list1;
} }
} vecFileContentMap["ALL"] = list2;
// ???
outputMap1["__COMMON__"].append("");
if (compilerResult) {
// CompileLazy出现异常
// 标准错误输出
fprintf(stderr, "Error %d: %s\n", 1, "123");
}
else {
FILE *f = stdout;
if (!outputFileName.empty())
f = fopen(outputFileName.c_str(), "w");
// DictToJsonString
// DictToJsonString
fprintf(f, " {\"generateFunctionContent\":%s,\"generateFunctionName\":%s} ", "", "");
fclose(f);
} }
} //
else { if (hasLL)
const char off_5403C3[] = { 's', '\0', 'e', '\0' }; {
int compilerResult = 0; // 处理文件路径
// compilerResult = WXML::Compiler::Compile( for (int i = 0; i < splitedData.size(); i++)
// v3, {
// &v107, string path = splitedData[i];
// (int *)v111, if (path[0] == '.' && path[1] == '/')
// (unsigned __int8 **)v113, {
// v126, // 以"./"开头,去掉前两个字符
// &v105, splitedData[i] = path.substr(2);
// v53, }
// (int *)gwxMark, }
// mark, map<string, string> outputMap1;
// '\n', map<string, string> outputMap2;
// off_5403C3[2], // off_5403C3[2] map<string, vector<string>> vecFileContentMap2;
// off_5403C3, // off_5403C3 const char off_5403C3[] = {'s', '\0', 'e', '\0'};
// "gg", // "gg" int compilerResult = 0;
// "e_", // "e_" string errorMessage;
// "d_", // "d_"
// "p_", // "p_" compilerResult = WXML::Compiler::CompileLazy(
// '\0', // '\0' fileContentMap,
// "boxofchocolate", // "boxofchocolate" errorMessage,
// "$gdwx", // "$gdwx" outputMap1,
// "f_"); // "f_" outputMap2, // map<string, string>
FILE *f; vecFileContentMap2, // std::map<std::string,std::vector<std::string>>
if (compilerResult) { vecFileContentMap, // vecFileContentMap
f = stderr; splitedData,
fprintf(f, "%s\n", "error..."); mapData1,
}else { isLLA,
f = stdout; gwxMark,
if (!outputFileName.empty()) { mark,
f = fopen(outputFileName.c_str(), "w"); 10,
&off_5403C3[2],
off_5403C3,
"gg",
"e_",
"d_",
"p_",
"\0",
"boxofchocolate",
"$gdwx",
"f_");
// while(!outputMap1.empty())
// {
// /**
// * v60可能值 0xF30D70:0xF30DB8:"miniprogram_npm/miniprogram-recycle-view/recycle-view"
// */
// // if(v60 == "__COMMON__")
// // {
// // }
// }
// if()
if (1)
{
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);";
data = data + helperCode;
outputMap1["__COMMON__"] = data;
}
else
{
string helperCode;
WXML::Compiler::WXMLHelperCode(helperCode);
string commonData = "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);";
commonData += helperCode;
commonData = commonData.append(outputMap1["__COMMON__"]);
outputMap1["__COMMON__"] = commonData;
}
string dep = ";var __WXML_DEP__=__WXML_DEP__||{};";
// TODO: 起始并不是0
for (string j = "";;)
{
/* code */
if (j == "")
break;
if (j[11] != j[10])
{
stringstream dep;
dep << "__WXML_DEP__[\"";
dep << "\"]=[";
for (int k = 0; k < 10; k++)
{
/* code */
dep << "\"";
dep << "\",";
}
dep << "];";
}
}
// ???
outputMap1["__COMMON__"].append("");
if (compilerResult)
{
// CompileLazy出现异常
// 标准错误输出
fprintf(stderr, "Error %d: %s\n", 1, "123");
}
else
{
FILE *f = stdout;
if (!outputFileName.empty())
f = fopen(outputFileName.c_str(), "w");
// DictToJsonString
// DictToJsonString
fprintf(f, " {\"generateFunctionContent\":%s,\"generateFunctionName\":%s} ", "", "");
fclose(f);
}
}
else
{
const char off_5403C3[] = {'s', '\0', 'e', '\0'};
int compilerResult = 0;
// compilerResult = WXML::Compiler::Compile(
// v3,
// &v107,
// (int *)v111,
// (unsigned __int8 **)v113,
// v126,
// &v105,
// v53,
// (int *)gwxMark,
// mark,
// '\n',
// off_5403C3[2], // off_5403C3[2]
// off_5403C3, // off_5403C3
// "gg", // "gg"
// "e_", // "e_"
// "d_", // "d_"
// "p_", // "p_"
// '\0', // '\0'
// "boxofchocolate", // "boxofchocolate"
// "$gdwx", // "$gdwx"
// "f_"); // "f_"
FILE *f;
if (compilerResult)
{
f = stderr;
fprintf(f, "%s\n", "error...");
}
else
{
f = stdout;
if (!outputFileName.empty())
{
f = fopen(outputFileName.c_str(), "w");
}
fprintf(f, "%s\n", "result...");
fclose(f);
} }
fprintf(f, "%s\n", "result...");
fclose(f);
} }
} }
catch (const std::exception &e)
{
std::cerr << e.what() << '\n';
}
return 0; return 0;
} }

View File

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

View File

@ -22,12 +22,30 @@ namespace WXML
} }
bool Parser::Parse( bool Parser::Parse(
char const* fileContent, char const* fileContent,
std::string &, std::string & a4,
std::string const&, std::string const& a5,
std::vector<WXML::DOMLib::Token> & 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 ""; 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&) 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); std::string sc = WXML::Rewrite::ToStringCode(a2);
a6 << sc << ":" << this->tag << ":" << this->offset_92 << ":" << this->offset_96 << "\")"; a6 << sc << ":" << this->tag << ":" << this->offset_92 << ":" << this->offset_96 << "\")";
} }
if (this->type == "TEXTNODE") if (this->tag == "TEXTNODE")
{ {
} }
if (this->type == "wx-define" if (this->tag == "wx-define"
||this->type == "wx-import" ||this->tag == "wx-import"
||this->type == "import" ||this->tag == "import"
||this->type == "template") ||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) bool WXMLDom::operator==(std::string tag)
{ {
return this->tag.compare(tag) == 0; 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); WXML::DOMLib::Parser::Error(exception, (WXML::DOMLib::Parser *)a1, "unexpected tag", 0);
__cxa_throw( __cxa_throw(
exception, exception,
(struct type_info *)&`typeinfo for'WXML::DOMLib::ParseException, (struct type_info *)&`typeinfo for WXML::DOMLib::ParseException,
WXML::DOMLib::ParseException::~ParseException); WXML::DOMLib::ParseException::~ParseException);
} }
++a1[25]; ++a1[25];
@ -23056,7 +23056,7 @@ void __usercall WXML::DOMLib::Parser::DOM(_DWORD *a1@<ecx>, WXML::DOMLib::Parser
(WXML::DOMLib::Token *)&v45); (WXML::DOMLib::Token *)&v45);
__cxa_throw( __cxa_throw(
v31, v31,
(struct type_info *)&`typeinfo for'WXML::DOMLib::ParseException, (struct type_info *)&`typeinfo for WXML::DOMLib::ParseException,
WXML::DOMLib::ParseException::~ParseException); WXML::DOMLib::ParseException::~ParseException);
} }
++a1[25]; ++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); WXML::DOMLib::Parser::Error(v30, (WXML::DOMLib::Parser *)a1, v41, 0);
__cxa_throw( __cxa_throw(
v30, v30,
(struct type_info *)&`typeinfo for'WXML::DOMLib::ParseException, (struct type_info *)&`typeinfo for WXML::DOMLib::ParseException,
WXML::DOMLib::ParseException::~ParseException); WXML::DOMLib::ParseException::~ParseException);
} }
++a1[25]; ++a1[25];
@ -23515,7 +23515,7 @@ int __cdecl WXML::DOMLib::WXMLDom::DealSingleTokenToOps(
std::string::_M_dispose(&Block); std::string::_M_dispose(&Block);
__cxa_throw( __cxa_throw(
exception, exception,
(struct type_info *)&`typeinfo for'WXML::DOMLib::RenderException, (struct type_info *)&`typeinfo for WXML::DOMLib::RenderException,
WXML::DOMLib::RenderException::~RenderException); WXML::DOMLib::RenderException::~RenderException);
} }
if ( a8 ) if ( a8 )