mirror of
https://github.com/msojocs/wx-compiler.git
synced 2025-07-19 00:00:04 +08:00
impl: machine
This commit is contained in:
parent
3a5c0992bc
commit
fd6789dd7c
22
.vscode/settings.json
vendored
22
.vscode/settings.json
vendored
@ -51,26 +51,8 @@
|
||||
"cmake.debugConfig": {
|
||||
"cwd": "/mnt/d/Work/WeChatProjects/miniprogram-demo/miniprogram",
|
||||
"args": [
|
||||
"\"-d\"",
|
||||
"\"--split\"",
|
||||
"\">_<109\"",
|
||||
"\"-xc\"",
|
||||
"\"9>_<109./miniprogram_npm/miniprogram-barrage/index.wxml>_<1090>_<109./miniprogram_npm/miniprogram-recycle-view/recycle-item.wxml>_<1090>_<109./miniprogram_npm/miniprogram-recycle-view/recycle-view.wxml>_<1090>_<109./miniprogram_npm/wxml-to-canvas/index.wxml>_<1090>_<109./page/API/index.wxml>_<1091>_<109set-tab-bar>_<109./page/API/components/set-tab-bar/set-tab-bar.wxml>_<1090>_<109./page/cloud/index.wxml>_<1090>_<109./page/component/index.wxml>_<1090>_<109./page/extend/index.wxml>_<1090\"",
|
||||
"\"-lla\"",
|
||||
"\"./miniprogram_npm/miniprogram-barrage/index>_<109./miniprogram_npm/miniprogram-recycle-view/recycle-item>_<109./miniprogram_npm/miniprogram-recycle-view/recycle-view>_<109./miniprogram_npm/wxml-to-canvas/index>_<109./page/API/index>_<109./page/API/components/set-tab-bar/set-tab-bar>_<109./page/cloud/index>_<109./page/component/index>_<109./page/extend/index\"",
|
||||
"\"./miniprogram_npm/miniprogram-barrage/index.wxml\"",
|
||||
"\"./miniprogram_npm/miniprogram-recycle-view/recycle-item.wxml\"",
|
||||
"\"./miniprogram_npm/miniprogram-recycle-view/recycle-view.wxml\"",
|
||||
"\"./miniprogram_npm/wxml-to-canvas/index.wxml\"",
|
||||
"\"./page/API/index.wxml\"",
|
||||
"\"./page/API/components/set-tab-bar/set-tab-bar.wxml\"",
|
||||
"\"./page/cloud/index.wxml\"",
|
||||
"\"./page/common/foot.wxml\"",
|
||||
"\"./page/common/head.wxml\"",
|
||||
"\"./page/component/index.wxml\"",
|
||||
"\"./page/extend/index.wxml\"",
|
||||
"\"-gn\"",
|
||||
"\"\\$gwx1\""
|
||||
"\"--config-path\"",
|
||||
"\"/mnt/d/Work/disassembly/wcc-exec/wcc/cmd1.txt\""
|
||||
]
|
||||
}
|
||||
}
|
@ -6,8 +6,12 @@ enable_testing()
|
||||
|
||||
add_executable(wcc
|
||||
src/wcc.cpp
|
||||
src/include/wxml.h
|
||||
src/wcc/usage.cpp
|
||||
src/wxml/compiler.cpp
|
||||
src/wxml/dom_lib/token.cpp
|
||||
src/wxml/dom_lib/machine.cpp
|
||||
src/wxml/dom_lib/parser.cpp
|
||||
src/utils/string_utils.cpp
|
||||
src/utils/file.cpp
|
||||
)
|
||||
|
11
docs/disammbly.md
Normal file
11
docs/disammbly.md
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
## std::string
|
||||
|
||||
v
|
||||
| 操作 | 数据 | 备注 |
|
||||
|---|---|---- |
|
||||
| v + 0 | data | 字符串内容 |
|
||||
| v + 4 | size() | 字符串长度 |
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace WXML
|
||||
@ -16,12 +17,31 @@ namespace WXML
|
||||
* 参数值可能不是int
|
||||
*/
|
||||
bool AttrsCompartor(int a1, int a2);
|
||||
|
||||
/**
|
||||
* 拼接字符串
|
||||
*
|
||||
* @param data 要拼接的字符串
|
||||
* @param join 拼接字符
|
||||
*
|
||||
*/
|
||||
std::string joinString(std::vector<std::string>& str, char split);
|
||||
std::string joinString(std::vector<std::string>& data, char join);
|
||||
|
||||
/**
|
||||
* 分割字符串
|
||||
*
|
||||
* @param str 要分割的字符串
|
||||
* @param split 分割字符
|
||||
*/
|
||||
std::vector<std::string> splitString(std::string const& str, char split);
|
||||
std::string resolvePath(std::string const&, std::string const&);
|
||||
|
||||
/**
|
||||
* 路径拼接
|
||||
*
|
||||
* @param path1 基础路径
|
||||
* @param path2 目标路径
|
||||
*/
|
||||
std::string resolvePath(std::string const& path1, std::string const& path2);
|
||||
|
||||
class WXMLDom
|
||||
{
|
||||
@ -33,6 +53,9 @@ namespace WXML
|
||||
void Error();
|
||||
};
|
||||
|
||||
|
||||
void recurseDependencies(WXML::DOMLib::WXMLDom const&,std::string const&,std::set<std::string> &);
|
||||
|
||||
|
||||
class Token
|
||||
{
|
||||
@ -46,7 +69,12 @@ namespace WXML
|
||||
Token(WXML::DOMLib::Token&&);
|
||||
Token(WXML::DOMLib::Token const&);
|
||||
std::string ToString();
|
||||
int ToAttrContent();
|
||||
|
||||
/**
|
||||
*
|
||||
* 返回值类型string
|
||||
*/
|
||||
std::string ToAttrContent();
|
||||
bool IsValidVariableName(std::string const&);
|
||||
bool IsMatch(char const&);
|
||||
bool GetTemplateContent(std::string const&, std::string&);
|
||||
@ -68,7 +96,8 @@ namespace WXML
|
||||
*/
|
||||
bool IsValidTag(std::string &);
|
||||
WXML::DOMLib::Token Peek();
|
||||
bool Parse(char const*fileContent, // Str
|
||||
bool Parse(
|
||||
char const*fileContent, // Str
|
||||
std::string &, // a4
|
||||
std::string const&, // a5
|
||||
std::vector<WXML::DOMLib::Token> & // a6
|
||||
@ -82,6 +111,32 @@ namespace WXML
|
||||
std::string ATTR();
|
||||
|
||||
};
|
||||
|
||||
class Machine
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
static bool bInited; // 初始化标志
|
||||
static int * TT; //类型不确定
|
||||
static int * STT;
|
||||
int offset_0; // offset + 0
|
||||
int offset_1; // offset + 1
|
||||
int lineCount;// 当前处理的行数 offset + 2
|
||||
int lineLength; // 正在处理行的长度 offset + 3
|
||||
int offset_4; // offset + 4
|
||||
int offset_5; // offset + 5
|
||||
int offset_6; // offset + 6
|
||||
std::string filePath; // 文件路径 offset + 7
|
||||
|
||||
public:
|
||||
Machine(/* args */);
|
||||
Machine(std::string const& filePath);
|
||||
~Machine();
|
||||
void Reset(void);
|
||||
void InitTransitTable(void);
|
||||
void Feed(char,std::vector<WXML::DOMLib::Token> &,std::string &,std::vector<WXML::DOMLib::Token> &,int);
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
@ -149,7 +204,7 @@ namespace WXML
|
||||
|
||||
// void GetFuncId();
|
||||
void GetVersionInfo(std::string &a1, std::string a2);
|
||||
int ParseSource(
|
||||
WXML::DOMLib::Parser ParseSource(
|
||||
std::string const& content, // 源码?
|
||||
std::string const& fileName, // 文件名?
|
||||
std::string const& , // ?
|
||||
|
81
src/wcc.cpp
81
src/wcc.cpp
@ -23,7 +23,7 @@ int main(int argc, const char **argv) {
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
|
||||
if (!string("--cofig-path").compare(argv[i])) {
|
||||
if (!string("--config-path").compare(argv[i])) {
|
||||
hasConfigParam = i + 1 < argc;
|
||||
}
|
||||
if (hasConfigParam) {
|
||||
@ -41,8 +41,11 @@ int main(int argc, const char **argv) {
|
||||
int ret = readFile(configPathLocation.c_str(), configData);
|
||||
string line;
|
||||
if (0 == ret) {
|
||||
line = getNextArg(configData, "\n");
|
||||
paramList.emplace_back(line);
|
||||
while ((line = getNextArg(configData, "\n")).size() > 0)
|
||||
{
|
||||
paramList.emplace_back(line);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
int mark = 0;
|
||||
@ -262,7 +265,8 @@ int main(int argc, const char **argv) {
|
||||
{
|
||||
string data;
|
||||
string arg2;
|
||||
vector<string> list;
|
||||
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++)
|
||||
@ -270,15 +274,14 @@ int main(int argc, const char **argv) {
|
||||
string arg1 = getNextArg(xc_Or_completeCode_Param, splitMarkStr);
|
||||
data = getNextArg(xc_Or_completeCode_Param, splitMarkStr);
|
||||
unsigned long long jCount = strtoull(&data[0], 0, 10);
|
||||
vector<string> list;
|
||||
for (unsigned long long i = 0; i < jCount; i++)
|
||||
{
|
||||
arg2 = getNextArg(xc_Or_completeCode_Param, splitMarkStr);
|
||||
list.push_back(arg2);
|
||||
list1.push_back(arg2);
|
||||
auto it = vecFileContentMap.find(arg2);
|
||||
if (it == vecFileContentMap.end())
|
||||
{
|
||||
list.push_back(arg2);
|
||||
list2.push_back(arg2);
|
||||
}
|
||||
}
|
||||
// TODO: 还有问题
|
||||
@ -288,9 +291,10 @@ int main(int argc, const char **argv) {
|
||||
vector<string> d;
|
||||
vecFileContentMap.emplace(arg1, d);
|
||||
}
|
||||
|
||||
// list1
|
||||
it->second = list1;
|
||||
}
|
||||
vecFileContentMap["ALL"] = list;
|
||||
vecFileContentMap["ALL"] = list2;
|
||||
}
|
||||
|
||||
//
|
||||
@ -306,33 +310,36 @@ int main(int argc, const char **argv) {
|
||||
splitedData[i] = path.substr(2);
|
||||
}
|
||||
}
|
||||
map<string, string> outputMap;
|
||||
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,
|
||||
// outputMap,
|
||||
// &v101,
|
||||
// &v121,
|
||||
// vecFileContentMap, // vecFileContentMap
|
||||
// splitedData,
|
||||
// mapData1,
|
||||
// isLLA,
|
||||
// gwxMark,
|
||||
// mark,
|
||||
// 10,
|
||||
// &off_5403C3[2],
|
||||
// off_5403C3,
|
||||
// "gg",
|
||||
// "e_",
|
||||
// "d_",
|
||||
// "p_",
|
||||
// "\0",
|
||||
// "boxofchocolate",
|
||||
// "$gdwx",
|
||||
// "f_");
|
||||
|
||||
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()
|
||||
@ -347,7 +354,7 @@ int main(int argc, const char **argv) {
|
||||
"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;
|
||||
outputMap["__COMMON__"] = data;
|
||||
outputMap1["__COMMON__"] = data;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -360,9 +367,9 @@ int main(int argc, const char **argv) {
|
||||
"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(outputMap["__COMMON__"]);
|
||||
commonData = commonData.append(outputMap1["__COMMON__"]);
|
||||
|
||||
outputMap["__COMMON__"] = commonData;
|
||||
outputMap1["__COMMON__"] = commonData;
|
||||
}
|
||||
|
||||
string dep = ";var __WXML_DEP__=__WXML_DEP__||{};";
|
||||
@ -389,7 +396,7 @@ int main(int argc, const char **argv) {
|
||||
}
|
||||
}
|
||||
// ???
|
||||
outputMap["__COMMON__"].append("");
|
||||
outputMap1["__COMMON__"].append("");
|
||||
if (compilerResult) {
|
||||
// CompileLazy出现异常
|
||||
// 标准错误输出
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "../include/wxml.h"
|
||||
#include "../include/define.h"
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
namespace WXML{
|
||||
|
||||
@ -14,47 +15,81 @@ namespace WXML{
|
||||
std::map<std::string,std::string>& dict, // 输出
|
||||
std::map<std::string, std::vector<std::string>>,
|
||||
std::map<std::string, std::vector<std::string>>, // vecFileContentMap
|
||||
std::vector<std::string> const&, // splitedData
|
||||
std::map<std::string,std::string> const&, // mapData1
|
||||
bool, // isLLA
|
||||
std::vector<std::string> const& splitedData, // splitedData
|
||||
std::map<std::string,std::string> const& mapData1, // mapData1
|
||||
bool isLLA, // isLLA
|
||||
std::string const& gwxMark, // gwxMark
|
||||
uint mark, // mark
|
||||
char lineEndMark, // '\n'
|
||||
std::string const&, // 'e'
|
||||
std::string const&, // const char off_5403C3[] = {'s','\0','e','\0'}
|
||||
std::string const&, // "gg"
|
||||
std::string const&, // "e_"
|
||||
std::string const&, // "d_"
|
||||
std::string const&, // "p_"
|
||||
std::string const& , // 'e'
|
||||
std::string const& , // const char off_5403C3[] = {'s','\0','e','\0'}
|
||||
std::string const& ggMark, // "gg"
|
||||
std::string const& eMark, // "e_"
|
||||
std::string const& dMark, // "d_"
|
||||
std::string const& pMark, // "p_"
|
||||
std::string const& strEndMark, // '\0'
|
||||
std::string const& boxMark, // "boxofchocolate"
|
||||
std::string const& gdwxMark, // "$gdwx"
|
||||
std::string const& fMark // "f_"
|
||||
)
|
||||
{
|
||||
for (auto it = fileContentMap.begin(); it != fileContentMap.end(); it++)
|
||||
try
|
||||
{
|
||||
/* 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;
|
||||
std::map<std::string, std::shared_ptr<std::stringstream>> ssDataMap;
|
||||
std::map<std::string,std::vector<std::string>> v307_localVecStrMap1;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::shared_ptr<std::stringstream> v301_localCommonStream1; // v301
|
||||
ssDataMap["__COMMON__"] = v301_localCommonStream1;
|
||||
std::vector<std::string> commonVec;
|
||||
v307_localVecStrMap1["__COMMON__"] = commonVec;
|
||||
|
||||
for (int i = 0; i < splitedData.size(); i++)
|
||||
{
|
||||
std::shared_ptr<std::stringstream> v328_ss;
|
||||
auto it = ssDataMap.lower_bound(splitedData[i]);
|
||||
if (it == ssDataMap.end())
|
||||
{
|
||||
|
||||
}
|
||||
std::string path = "./" + splitedData[i] + ".wxml";
|
||||
std::vector<std::string> j;
|
||||
j.push_back(path);
|
||||
v307_localVecStrMap1[splitedData[i]] = j;
|
||||
}
|
||||
// for (auto it = splitedData.begin(); it != splitedData.end(); it++)
|
||||
// {
|
||||
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -91,6 +126,7 @@ namespace WXML{
|
||||
data = " " + data;
|
||||
}
|
||||
// WXML::DOMLib::Parser::Parser(data);
|
||||
// TODO...
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -110,12 +146,12 @@ namespace WXML{
|
||||
result.str(a1);
|
||||
}
|
||||
|
||||
int ParseSource(
|
||||
std::string const& content, // 源码?
|
||||
WXML::DOMLib::Parser ParseSource(
|
||||
std::string const& fileName, // 文件名?
|
||||
std::string const& content, // 源码?
|
||||
char lineEndMark, // '\n'
|
||||
std::string const& gwxMark, // gwxMark
|
||||
std::string& fMark, // "f_"
|
||||
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, ?>
|
||||
@ -124,13 +160,15 @@ namespace WXML{
|
||||
bool b1, // mark指定运算结果是否非0
|
||||
bool b2) // mark指定运算结果是否非0
|
||||
{
|
||||
WXML::DOMLib::Parser pResult;
|
||||
bool isWxml = fileName.substr(fileName.length() - 5) == ".wxml";
|
||||
if (isWxml)
|
||||
{
|
||||
// parse
|
||||
int parseResult = 0;
|
||||
// pResult.Parse();
|
||||
if (parseResult)
|
||||
return parseResult;
|
||||
throw "";
|
||||
|
||||
if (!parseResult)
|
||||
{
|
||||
@ -155,7 +193,7 @@ namespace WXML{
|
||||
if (dealResult)
|
||||
{
|
||||
// 非0
|
||||
return dealResult;
|
||||
throw dealResult;
|
||||
}
|
||||
ss << fMark;
|
||||
ss << "['";
|
||||
@ -189,7 +227,7 @@ namespace WXML{
|
||||
|
||||
// 清空
|
||||
errs.clear();
|
||||
return 1;
|
||||
throw 1;
|
||||
}
|
||||
ss << "f_['";
|
||||
// ss << ToStringCode(v81);
|
||||
@ -219,7 +257,7 @@ namespace WXML{
|
||||
int compilerResult = 1;
|
||||
if (compilerResult)
|
||||
{
|
||||
return compilerResult;
|
||||
throw compilerResult;
|
||||
}
|
||||
ss << "nv_require(\"";
|
||||
std::string m = "m_" + fileName;
|
||||
@ -251,7 +289,7 @@ namespace WXML{
|
||||
int compilerResultCode = 0;
|
||||
if (compilerResultCode) {
|
||||
errorMessage.assign("error...");
|
||||
return compilerResultCode;
|
||||
throw compilerResultCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -272,7 +310,7 @@ namespace WXML{
|
||||
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return pResult;
|
||||
}
|
||||
void WXMLHelperCode(std::string &result)
|
||||
{
|
||||
|
@ -24,6 +24,7 @@ namespace WXML
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::vector<std::string> splitString(std::string const& str, char split)
|
||||
{
|
||||
int pos = 0;
|
||||
@ -65,7 +66,7 @@ namespace WXML
|
||||
result = "." + path2;
|
||||
}
|
||||
if (
|
||||
// v5 <= 4 ||
|
||||
result.size() <= 4 ||
|
||||
result.substr(result.size() - 5) != ".wxml"
|
||||
)
|
||||
{
|
||||
@ -73,6 +74,31 @@ namespace WXML
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void recurseDependencies(WXML::DOMLib::WXMLDom const& dom, std::string const& filePath, std::set<std::string> & pathSet)
|
||||
{
|
||||
std::string a1;
|
||||
if (a1 == "import" || a1 == "include")
|
||||
{
|
||||
// TODO: map来源
|
||||
std::map<std::string,WXML::DOMLib::Token> map;
|
||||
if(map.count("src"))
|
||||
{
|
||||
std::string relativePath = map["src"].ToAttrContent();
|
||||
std::string depPath = resolvePath(filePath, relativePath);
|
||||
pathSet.insert(depPath);
|
||||
}
|
||||
|
||||
}
|
||||
for (int i = 0; ; i++)
|
||||
{
|
||||
// if (i >= )
|
||||
// break;
|
||||
// recurseDependencies(, filePath, pathSet)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
189
src/wxml/dom_lib/machine.cpp
Normal file
189
src/wxml/dom_lib/machine.cpp
Normal file
@ -0,0 +1,189 @@
|
||||
#include "../../include/wxml.h"
|
||||
#include <cstring>
|
||||
inline
|
||||
unsigned char bittest(std::int32_t const *a, std::int32_t b)
|
||||
{
|
||||
auto const bits{ reinterpret_cast<unsigned char const*>(a) };
|
||||
auto const value{ bits[b >> 3] };
|
||||
auto const mask{ (unsigned char)(1 << (b & 7)) };
|
||||
return (value & mask) != 0;
|
||||
}
|
||||
|
||||
inline
|
||||
unsigned char bittest64(std::int64_t const *a, std::int64_t b)
|
||||
{
|
||||
auto const bits{ reinterpret_cast<unsigned char const*>(a) };
|
||||
auto const value{ bits[b >> 3] };
|
||||
auto const mask{ (unsigned char)(1 << (b & 7)) };
|
||||
return (value & mask) != 0;
|
||||
}
|
||||
namespace WXML
|
||||
{
|
||||
|
||||
namespace DOMLib
|
||||
{
|
||||
|
||||
|
||||
|
||||
Machine::Machine(/* args */)
|
||||
{
|
||||
}
|
||||
|
||||
Machine::Machine(std::string const& filePath)
|
||||
{
|
||||
InitTransitTable();
|
||||
this->filePath. assign(filePath);
|
||||
}
|
||||
|
||||
Machine::~Machine()
|
||||
{
|
||||
}
|
||||
bool Machine::bInited = false;
|
||||
int * Machine::TT = nullptr;
|
||||
int * Machine::STT = nullptr;
|
||||
|
||||
void Machine::InitTransitTable()
|
||||
{
|
||||
// bInited是静态的
|
||||
if (!this->bInited)
|
||||
{
|
||||
this->bInited = true;
|
||||
std::string v0 = "\n\t\r";
|
||||
// memset(&this->TT, 0, 0x101000u);
|
||||
}
|
||||
}
|
||||
int dword_567960[1000] = {0};
|
||||
void Machine::Feed(
|
||||
char c,
|
||||
std::vector<WXML::DOMLib::Token> & a3,
|
||||
std::string &errorMessage,
|
||||
std::vector<WXML::DOMLib::Token> & a5,
|
||||
int
|
||||
)
|
||||
{
|
||||
try
|
||||
{
|
||||
/* code */
|
||||
if (c == '\n')
|
||||
{
|
||||
// 一行结束,行数加一,长度变0
|
||||
this->lineCount++;
|
||||
this->lineLength = 0;
|
||||
}
|
||||
|
||||
int v45 = this->offset_6;
|
||||
int v46 = this->TT[257 * this->offset_6 + c];
|
||||
do{
|
||||
if (!v46)
|
||||
{
|
||||
v46 = dword_567960[257 * v45];
|
||||
if(!v46)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "BAD STATE MACHINE! AT INPUT ";
|
||||
ss << this->offset_6 << " " << c;
|
||||
errorMessage = ss.str();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (v46 < 0)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << this->filePath << ":";
|
||||
ss << this->lineCount << ":";
|
||||
ss << this->lineLength << ":";
|
||||
if (c)
|
||||
{
|
||||
ss << "unexpected character `" << c << "`";
|
||||
}
|
||||
else
|
||||
{
|
||||
ss << "unexpected end";
|
||||
}
|
||||
errorMessage = ss.str();
|
||||
return;
|
||||
}
|
||||
this->offset_6 = v46;
|
||||
if (bittest(&v46, 0x15u))
|
||||
{
|
||||
// TODO:
|
||||
if (this->offset_0 > this->offset_1)
|
||||
{
|
||||
this->offset_1++;
|
||||
this->offset_5++;
|
||||
|
||||
WXML::DOMLib::Token token;
|
||||
a3.push_back(token);
|
||||
}
|
||||
}
|
||||
if (bittest(&v46, 0x16u))
|
||||
{
|
||||
// TODO:
|
||||
WXML::DOMLib::Token token;
|
||||
// this->offset_4 = this->offset_4 - 112;
|
||||
|
||||
// ----
|
||||
// this->offset_4 =
|
||||
// this->offset_5 =
|
||||
|
||||
}
|
||||
}while(bittest(&v46, 0x14u));
|
||||
|
||||
if (bittest(&v46, 0x11u))
|
||||
{
|
||||
if (this->offset_1 < this->offset_0)
|
||||
{
|
||||
this->offset_1 = this->offset_0;
|
||||
this->offset_5 = this->lineLength;
|
||||
this->offset_4 = this->lineCount;
|
||||
|
||||
if(WXML::DOMLib::Machine::STT[v45] == 3)
|
||||
{
|
||||
WXML::DOMLib::Token token;
|
||||
a5.push_back(token);
|
||||
}
|
||||
else
|
||||
{
|
||||
WXML::DOMLib::Token token;
|
||||
a3.push_back(token);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this->offset_0++;
|
||||
this->lineLength++;
|
||||
if (bittest(&v46, 0x12u))
|
||||
{
|
||||
this->offset_1 = this->offset_0;
|
||||
this->offset_5 = this->lineLength;
|
||||
this->offset_4 = this->lineCount;
|
||||
if (WXML::DOMLib::Machine::STT[v45] == 3)
|
||||
{
|
||||
WXML::DOMLib::Token v49;
|
||||
a5.push_back(v49);
|
||||
}
|
||||
else
|
||||
{
|
||||
WXML::DOMLib::Token v49;
|
||||
a3.push_back(v49);
|
||||
}
|
||||
}
|
||||
v46 &= 0x80000u;
|
||||
if (v46)
|
||||
{
|
||||
offset_1 = offset_0;
|
||||
offset_5 = lineLength;
|
||||
}
|
||||
return;
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << '\n';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -20,5 +20,14 @@ namespace WXML
|
||||
{
|
||||
return tag.compare("wx-") != 0;
|
||||
}
|
||||
bool Parser::Parse(
|
||||
char const* fileContent,
|
||||
std::string &,
|
||||
std::string const&,
|
||||
std::vector<WXML::DOMLib::Token> &
|
||||
)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -13,6 +13,9 @@ namespace WXML
|
||||
Token::Token(WXML::DOMLib::Token&& token)
|
||||
{
|
||||
}
|
||||
Token::Token(WXML::DOMLib::Token const& token)
|
||||
{
|
||||
}
|
||||
|
||||
Token::~Token()
|
||||
{
|
||||
|
@ -11177,10 +11177,10 @@ struct _Unwind_Exception *__cdecl WXML::Compiler::RenderDefine(
|
||||
//----- (00405522) --------------------------------------------------------
|
||||
struct _Unwind_Exception *__usercall WXML::Compiler::ParseSource@<eax>(
|
||||
WXML::DOMLib::Parser *a1@<edi>,
|
||||
int *a2,
|
||||
char **a3,
|
||||
char a4,
|
||||
int a5,
|
||||
int *a2, //文件名
|
||||
char **a3, // 源码
|
||||
char a4, // '\n'
|
||||
int a5, // gwxMark
|
||||
int *a6,
|
||||
_DWORD *a7,
|
||||
int *a8,
|
||||
@ -11280,6 +11280,7 @@ struct _Unwind_Exception *__usercall WXML::Compiler::ParseSource@<eax>(
|
||||
std::string::_M_dispose((void **)v95);
|
||||
if ( lpuexcpta )
|
||||
{
|
||||
// 文件名 .wxml 结尾
|
||||
v66 = 0;
|
||||
v67 = 0;
|
||||
v68 = 0;
|
||||
@ -13555,10 +13556,11 @@ struct _Unwind_Exception *__cdecl WXML::Compiler::CompileLazy(
|
||||
v249 = (WXML::DOMLib::Parser *)(a1 + 1);
|
||||
while ( lpuexcpt != v249 )
|
||||
{
|
||||
// 13个参数
|
||||
v258 = WXML::Compiler::ParseSource(
|
||||
v249, // 源码?
|
||||
v249,
|
||||
(int *)lpuexcpt + 4, // 文件名
|
||||
(char **)lpuexcpt + 10,// ?
|
||||
(char **)lpuexcpt + 10, // 源码?
|
||||
a12, // '\n'
|
||||
a10, // gwxMark
|
||||
a22, // "f_"
|
||||
@ -13635,7 +13637,8 @@ struct _Unwind_Exception *__cdecl WXML::Compiler::CompileLazy(
|
||||
zcc::shared_ptr<std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>>::shared_ptr(
|
||||
&v328,
|
||||
(int)v222);
|
||||
lpuexcpta = (struct _Unwind_Exception *)std::_Rb_tree<std::string,std::pair<std::string const,zcc::shared_ptr<std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>>>,std::_Select1st<std::pair<std::string const,zcc::shared_ptr<std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>>>>,std::less<std::string>,std::allocator<std::pair<std::string const,zcc::shared_ptr<std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>>>>>::lower_bound(
|
||||
lpuexcpta = (struct _Unwind_Exception *)std::_Rb_tree<std::string,std::pair<std::string const,zcc::shared_ptr<std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>>>,std::_Select1st<std::pair<std::string const,zcc::shared_ptr<std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>>>>,std::less<std::string>,std::allocator<std::pair<std::string const,zcc::shared_ptr<std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>>>>>
|
||||
::lower_bound(
|
||||
&v301,
|
||||
i);
|
||||
if ( lpuexcpta == (struct _Unwind_Exception *)v302 || (unsigned __int8)std::operator<<char>(i, (int)lpuexcpta + 16) )
|
||||
@ -13644,7 +13647,8 @@ struct _Unwind_Exception *__cdecl WXML::Compiler::CompileLazy(
|
||||
std::string::basic_string((char *)Block + 16, i);
|
||||
Block[10] = 0;
|
||||
Block[11] = 0;
|
||||
lpuexcpta = (struct _Unwind_Exception *)std::_Rb_tree<std::string,std::pair<std::string const,zcc::shared_ptr<std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>>>,std::_Select1st<std::pair<std::string const,zcc::shared_ptr<std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>>>>,std::less<std::string>,std::allocator<std::pair<std::string const,zcc::shared_ptr<std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>>>>>::_M_get_insert_hint_unique_pos(
|
||||
lpuexcpta = (struct _Unwind_Exception *)std::_Rb_tree<std::string,std::pair<std::string const,zcc::shared_ptr<std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>>>,std::_Select1st<std::pair<std::string const,zcc::shared_ptr<std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>>>>,std::less<std::string>,std::allocator<std::pair<std::string const,zcc::shared_ptr<std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>>>>>
|
||||
::_M_get_insert_hint_unique_pos(
|
||||
&v301,
|
||||
lpuexcpta,
|
||||
(int)(Block + 4));
|
||||
@ -13669,6 +13673,7 @@ struct _Unwind_Exception *__cdecl WXML::Compiler::CompileLazy(
|
||||
std::operator+<char>((int)&jj, "./", i);
|
||||
v26 = std::string::append(&jj, ".wxml");
|
||||
std::string::basic_string(&v328, v26);
|
||||
// v328 ./*******.wxml
|
||||
j = 0;
|
||||
v323 = 0;
|
||||
v324 = 0;
|
||||
@ -13679,16 +13684,19 @@ struct _Unwind_Exception *__cdecl WXML::Compiler::CompileLazy(
|
||||
v323 = lpuexcpto;
|
||||
v27 = std::map<std::string,std::vector<std::string>>::operator[](&v307, i);
|
||||
std::vector<std::string>::operator=(v27, (int *)&j);
|
||||
// v307[i] = j
|
||||
std::vector<std::string>::~vector((void ***)&j, v28);
|
||||
std::string::_M_dispose((void **)&v328);
|
||||
std::string::_M_dispose((void **)&jj);
|
||||
}
|
||||
v238 = (WXML::EXPRLib::Parser *)a7[1];
|
||||
v238 = (WXML::EXPRLib::Parser *)a7[1]; // v238 - end?
|
||||
// a7 splitedData
|
||||
lpuexcptb = (struct _Unwind_Exception *)*a7;
|
||||
std::_Rb_tree_header::_Rb_tree_header(v314);
|
||||
while ( v238 != lpuexcptb )
|
||||
{
|
||||
insert_hint_unique_pos = std::_Rb_tree<std::string,std::string,std::_Identity<std::string>,std::less<std::string>,std::allocator<std::string>>::_M_get_insert_hint_unique_pos(
|
||||
insert_hint_unique_pos = std::_Rb_tree<std::string,std::string,std::_Identity<std::string>,std::less<std::string>,std::allocator<std::string>>
|
||||
::_M_get_insert_hint_unique_pos(
|
||||
&v313,
|
||||
v314,
|
||||
(int)lpuexcptb);
|
||||
@ -13731,6 +13739,7 @@ struct _Unwind_Exception *__cdecl WXML::Compiler::CompileLazy(
|
||||
{
|
||||
std::string::basic_string((void **)&v328, "__COMMON__");
|
||||
v34 = std::map<std::string,std::vector<std::string>>::operator[](&v307, &v328);
|
||||
// v307[v328].push_back(v260)
|
||||
std::vector<std::string>::push_back((int)v34, (int)v260);
|
||||
std::string::_M_dispose((void **)&v328);
|
||||
}
|
||||
@ -22899,15 +22908,18 @@ void __cdecl WXML::DOMLib::recurseDependencies(int *a1, int *a2, _DWORD *a3)
|
||||
if ( std::operator==<char>(*a1, "import") || std::operator==<char>(*a1, "include") )
|
||||
{
|
||||
lpuexcpta = (struct _Unwind_Exception *)(*a1 + 48);
|
||||
// const char off_5539C8[] = {'s','r','c','\0'}
|
||||
std::string::basic_string(v10, (char *)off_5539C8);
|
||||
lpuexcptb = (struct _Unwind_Exception *)std::map<std::string,WXML::DOMLib::Token>::count(lpuexcpta, (int)v10);
|
||||
std::string::_M_dispose(v10);
|
||||
if ( lpuexcptb )
|
||||
if ( lpuexcptb ) // 大于0
|
||||
{
|
||||
// const char off_5539C8[] = {'s','r','c','\0'}
|
||||
std::string::basic_string(v9, (char *)off_5539C8);
|
||||
v3 = std::map<std::string,WXML::DOMLib::Token>::operator[]((_DWORD *)(*a1 + 48), v9);
|
||||
v4 = (int *)WXML::DOMLib::Token::ToAttrContent[abi:cxx11]((int)v3);
|
||||
WXML::DOMLib::resolvePath((int)v10, a2, v4);
|
||||
// v10 = resolvePath(a2, a4);
|
||||
std::_Rb_tree<std::string,std::string,std::_Identity<std::string>,std::less<std::string>,std::allocator<std::string>>::_M_insert_unique<std::string>(
|
||||
a3,
|
||||
v10);
|
||||
@ -23205,7 +23217,7 @@ void __usercall WXML::DOMLib::Parser::DOMS(WXML::DOMLib::Parser *a1@<ecx>, WXML:
|
||||
int __userpurge WXML::DOMLib::Parser::Parse@<eax>(
|
||||
int a1@<ecx>,
|
||||
WXML::DOMLib::Parser *a2@<edi>,
|
||||
char *Str, // fileName
|
||||
char *Str, // fileContent
|
||||
int a4,
|
||||
int a5,
|
||||
_DWORD *a6)
|
||||
@ -25193,7 +25205,7 @@ LABEL_84:
|
||||
std::string::_M_dispose((void **)v347);
|
||||
__cxa_throw(
|
||||
v255,
|
||||
(struct type_info *)&`typeinfo for'WXML::DOMLib::RenderException,
|
||||
(struct type_info *)&`typeinfo for WXML::DOMLib::RenderException,
|
||||
WXML::DOMLib::RenderException::~RenderException);
|
||||
}
|
||||
v211 = std::operator<<<std::char_traits<char>>(v305, "_rz(z,");
|
||||
@ -26768,6 +26780,7 @@ int __thiscall WXML::DOMLib::Machine::Feed(
|
||||
++*((_DWORD *)lpuexcpt + 2);
|
||||
*((_DWORD *)v6 + 3) = 0;
|
||||
}
|
||||
// 喂入的字符
|
||||
v44 = (unsigned __int8)v46;
|
||||
do
|
||||
{
|
||||
@ -26796,8 +26809,10 @@ LABEL_12:
|
||||
std::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>::basic_stringstream((int)&v49);
|
||||
v9 = std::operator<<<char>((std::ostream::sentry *)&v51, (int *)lpuexcpt + 7);
|
||||
std::operator<<<std::char_traits<char>>(v9, ":");
|
||||
// inc
|
||||
v10 = (std::ostream::sentry *)std::ostream::operator<<(*((_DWORD *)lpuexcpt + 2));
|
||||
std::operator<<<std::char_traits<char>>(v10, ":");
|
||||
// lineLength
|
||||
v11 = (std::ostream::sentry *)std::ostream::operator<<(*((_DWORD *)lpuexcpt + 3));
|
||||
v12 = std::operator<<<std::char_traits<char>>(v11, ": ");
|
||||
if ( a2 )
|
||||
@ -26850,6 +26865,7 @@ LABEL_12:
|
||||
}
|
||||
if ( _bittest(&v46, 0x16u) )
|
||||
{
|
||||
//112 ascii -> 'p'
|
||||
WXML::DOMLib::Token::Token((int)&v49, (WXML::DOMLib::Token *)(*(_DWORD *)(a5 + 4) - 112), v43);
|
||||
v20 = *(_DWORD *)(a5 + 4) - 112;
|
||||
*(_DWORD *)(a5 + 4) = v20;
|
||||
@ -26866,8 +26882,10 @@ LABEL_12:
|
||||
{
|
||||
v22 = *(_DWORD *)lpuexcpt;
|
||||
v23 = *((_DWORD *)lpuexcpt + 1);
|
||||
// offset_1 < offset_0
|
||||
if ( v23 < *(_DWORD *)lpuexcpt )
|
||||
{
|
||||
// lineLength
|
||||
v24 = *((_DWORD *)lpuexcpt + 3);
|
||||
v49 = 0;
|
||||
v57 = v59;
|
||||
@ -26892,6 +26910,7 @@ LABEL_12:
|
||||
*((_DWORD *)v27 + 5) = v24;
|
||||
*((_DWORD *)v27 + 4) = v28;
|
||||
v64 = 0;
|
||||
// v45 offset_6
|
||||
v29 = WXML::DOMLib::Machine::STT[v45];
|
||||
v53 = v23;
|
||||
v60 = -1;
|
||||
@ -26904,6 +26923,8 @@ LABEL_12:
|
||||
WXML::DOMLib::Token::~Token((int)&v49);
|
||||
}
|
||||
}
|
||||
|
||||
// this
|
||||
v31 = lpuexcpt;
|
||||
v32 = *(_DWORD *)lpuexcpt + 1;
|
||||
v33 = *((_DWORD *)lpuexcpt + 3) + 1;
|
||||
@ -26917,16 +26938,21 @@ LABEL_12:
|
||||
v57 = v59;
|
||||
v61 = v63;
|
||||
v65 = v67;
|
||||
// offset_4
|
||||
v35 = *((_DWORD *)v31 + 4);
|
||||
v49 = 0;
|
||||
v51 = v35;
|
||||
// offset_5
|
||||
v36 = *((_DWORD *)v31 + 5);
|
||||
v50 = 0;
|
||||
v52 = v36;
|
||||
v37 = *((_DWORD *)v31 + 1);
|
||||
// offset_1
|
||||
*((_DWORD *)v31 + 1) = v32;
|
||||
v38 = *((_DWORD *)v31 + 2);
|
||||
// offset_5
|
||||
*((_DWORD *)v31 + 5) = v33;
|
||||
// offset_4
|
||||
*((_DWORD *)v31 + 4) = v38;
|
||||
v58 = 0;
|
||||
v39 = WXML::DOMLib::Machine::STT[v45];
|
||||
|
Loading…
x
Reference in New Issue
Block a user