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:
@ -90,6 +95,21 @@ namespace WXML
bool GetTemplateContent(std::string const&, std::string&);
~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,445 +10,503 @@
using namespace std;
int main(int argc, const char **argv) {
int main(int argc, const char **argv)
{
string gwxMark = "$gwx";
string splitMarkStr = " ";
bool hasConfigParam = false;
string configPathLocation;
vector<string> paramList;
string configData;
// 第一个参数是程序路径,忽略
for (int i = 1; i < argc; i++)
try
{
if (!string("--config-path").compare(argv[i])) {
hasConfigParam = i + 1 < argc;
}
if (hasConfigParam) {
// 有--config-path参数下一个参数是路径跳过
i++;
configPathLocation = argv[i];
}else {
paramList.emplace_back(argv[i]);
}
}
string gwxMark = "$gwx";
string splitMarkStr = " ";
bool hasConfigParam = false;
string configPathLocation;
vector<string> paramList;
string configData;
// 有配置文件,从配置文件解析
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])
// 第一个参数是程序路径,忽略
for (int i = 1; i < argc; i++)
{
case 'd':
// output code for debug
/* code */
if(!param[2]){
mark |= 2u;
continue;
if (!string("--config-path").compare(argv[i]))
{
hasConfigParam = i + 1 < argc;
}
if(param[2] == 's') {
mark |= 4u;
continue;
if (hasConfigParam)
{
// 有--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
version = true;
continue;
break;
case 'x':
// -xc output simplified code for custom component
/* code */
if(param[2] == 'c' && i + 1 < paramList.size()) {
hasXCParam = true;
if(paramList[i + 1][0] != '-') {
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;
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;
{
paramList.emplace_back(argv[i]);
}
}
// -cb
if(param[1] == 'c' && param[2] == 'b') {
string callbackFile = paramList[i + 1];
string callbackData;
readFile(callbackFile.c_str(), callbackData);
if (!callbackData.empty()) {
mapData1["life_cycle_callback_content"] = callbackData;
// 有配置文件,从配置文件解析
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);
}
}
}
else {
if(!param.compare("--pm")) {
// 参数是--pm
if (i + 1 < paramList.size()) {
mapData1["plain_text_marker"] = paramList[i + 1];
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
/* code */
if (!param[2])
{
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;
break;
case 'x':
// -xc output simplified code for custom component
/* code */
if (param[2] == 'c' && i + 1 < paramList.size())
{
hasXCParam = true;
if (paramList[i + 1][0] != '-')
{
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;
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;
}
}
if (param[1] == 'l' && param[2] == 'l') {
// -ll
if (param[3] != 'w') {
// 不是 -llw
if (param[3] != 'a') {
// 不是 -lla
printf("Error: expected -llw or -lla, but got %s\n", param.c_str());
return -1;
// -cb
if (param[1] == 'c' && param[2] == 'b')
{
string callbackFile = paramList[i + 1];
string callbackData;
readFile(callbackFile.c_str(), callbackData);
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 (!splitMarkStr.compare(" ")) {
// 空格
splitMark = ",";
}else {
// 不是空格
splitMark = splitMarkStr;
if (param[1] == 'l' && param[2] == 'l')
{
// -ll
if (param[3] != 'w')
{
// 不是 -llw
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) {
std::string versionInfo;
WXML::Compiler::GetVersionInfo(versionInfo, "global");
if (!outputFileName.empty()) {
FILE *f;
f = fopen(outputFileName.c_str(), "w");
fprintf(f, "%s\n", versionInfo.c_str());
fclose(f);
if (version)
{
std::string versionInfo;
WXML::Compiler::GetVersionInfo(versionInfo, "global");
if (!outputFileName.empty())
{
FILE *f;
f = fopen(outputFileName.c_str(), "w");
fprintf(f, "%s\n", versionInfo.c_str());
fclose(f);
}
}
}
if (fileList.empty()) {
usage(argc, argv);
return 0;
}
if (fileList.empty())
{
usage(argc, argv);
return 0;
}
if (isReadFromStdin) {
string content;
readFile(0, content);
fileContentMap[fileList[0]] = content;
}
else {
// 读取文件内容
for (int i = 0; i < fileList.size(); i++)
if (isReadFromStdin)
{
string content;
readFile(fileList[i].c_str(), content);
fileContentMap[fileList[i]] = content;
readFile(0, 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++)
else
{
string arg1 = getNextArg(xc_Or_completeCode_Param, splitMarkStr);
// 读取文件内容
for (int i = 0; i < fileList.size(); i++)
{
string content;
readFile(fileList[i].c_str(), content);
fileContentMap[fileList[i]] = 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 jCount = strtoull(&data[0], 0, 10);
for (unsigned long long i = 0; i < jCount; i++)
unsigned long long count = strtoull(&data[0], 0, 10);
for (unsigned long long i = 0; i < count; i++)
{
arg2 = getNextArg(xc_Or_completeCode_Param, splitMarkStr);
list1.push_back(arg2);
auto it = vecFileContentMap.find(arg2);
if (it == vecFileContentMap.end())
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++)
{
list2.push_back(arg2);
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);
}
}
// 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;
}
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;
//
if (hasLL)
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(!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);
}
}
}
catch (const std::exception &e)
{
// 处理文件路径
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
{
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);
}
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 )