feat: ast_if

This commit is contained in:
msojocs 2023-07-30 20:39:42 +08:00
parent 16bcfacd79
commit 9aec5c4130
9 changed files with 80 additions and 30 deletions

View File

@ -105,15 +105,18 @@ namespace night
) )
{ {
throw "not implement";
} }
void readfile(char const*, std::string &) void readfile(char const*, std::string &)
{ {
throw "not implement";
} }
void writefile(char const*, std::string &) void writefile(char const*, std::string &)
{ {
throw "not implement";
} }
} }

View File

@ -231,7 +231,31 @@ namespace night
} }
night::ns_node *NSASTParse::ast_if() night::ns_node *NSASTParse::ast_if()
{ {
throw "not implement"; this->ignore_buildin_kw("if");
auto v2 = this->ast_expression_no_comma();
auto v3 = this->ast_expression_no_comma();
auto v7 = this->offset_24->gen_son(night::NS_TYPE_IF);
v7->offset_204 = v2;
v7->offset_208 = v3;
v7->offset_212 = nullptr;
if (night::NS_TYPE_PROG_NO_SEM != v3->offset_0)
{
if (!this->offset_28->eof())
{
if (this->is_punctuation(";"))
{
this->offset_28->next();
}
}
v7->offset_108 = ";";
}
if (this->is_buildin_keywords("else"))
{
this->offset_28->next();
v7->offset_212 = this->ast_expression_no_comma();
}
return v7;
} }
night::ns_node *NSASTParse::ast_for() night::ns_node *NSASTParse::ast_for()
{ {
@ -392,7 +416,7 @@ namespace night
auto v11 = this->ast_switch(); auto v11 = this->ast_switch();
return this->make_call_or_just_expression(v11); return this->make_call_or_just_expression(v11);
} }
bool v21 = false; bool v21 = true;
if (this->is_buildin_keywords("true")) if (this->is_buildin_keywords("true"))
{ {
} }
@ -461,6 +485,7 @@ namespace night
v21 = this->is_buildin_keywords("continue") != 0; v21 = this->is_buildin_keywords("continue") != 0;
} }
} }
// goto LABEL_62;
} }
else else
{ {
@ -476,7 +501,7 @@ namespace night
} }
} }
} // end check for "true" } // end check for "true"
// v21 = false; // LABEL_62:
if (v21) if (v21)
{ {
auto v11 = this->ast_trans_kw(); auto v11 = this->ast_trans_kw();
@ -795,10 +820,10 @@ namespace night
} }
return a2; return a2;
} }
// int ast_expression_i = 0; int ast_expression_i = 0;
night::ns_node *NSASTParse::ast_expression() night::ns_node *NSASTParse::ast_expression()
{ {
// int inner_ast_expression_i = ast_expression_i++; int inner_ast_expression_i = ++ast_expression_i;
auto v1 = this->ast_dispatch(false); auto v1 = this->ast_dispatch(false);
auto binary_or_just_value = this->make_binary_or_just_value(v1, false); auto binary_or_just_value = this->make_binary_or_just_value(v1, false);
auto result = this->make_call_or_just_expression(binary_or_just_value); auto result = this->make_call_or_just_expression(binary_or_just_value);
@ -1082,20 +1107,20 @@ namespace night
auto v25 = this->offset_24->gen_girl(night::std_v_v_n); auto v25 = this->offset_24->gen_girl(night::std_v_v_n);
night::ns_node * lt = this->offset_24->gen_son(night::NS_TYPE_CALL); night::ns_node * lt = this->offset_24->gen_son(night::NS_TYPE_CALL);
lt->offset_220 = v21; lt->offset_220 = v21;
// lt->offset_224 = v25; // TODO... lt->offset_224 = v25.vecVec;
auto v5 = this->offset_28->peek(); auto v5 = this->offset_28->peek();
std::vector<night::ns_node *> * v44; std::vector<night::ns_node *> * v44;
if (v5 && v5->offset_84.find('\n') == -1) if (v5 && v5->offset_84.find('\n') == -1)
{ {
v44 = this->offset_24->gen_girl(night::std_v_n).vec; v44 = this->offset_24->gen_girl(night::std_v_n).vec;
auto v45 = this->ast_expression(); // TODO...待确认 auto v45 = this->ast_expression();
v44->emplace_back(v45); v44->emplace_back(v45);
} }
else else
{ {
v44 = this->offset_24->gen_girl(night::std_v_n).vec; v44 = this->offset_24->gen_girl(night::std_v_n).vec;
} }
// v25->push_back(v44); v25.vecVec->push_back(v44);
return lt; return lt;
} }
if ("typeof" == v43) if ("typeof" == v43)
@ -1504,4 +1529,13 @@ namespace night
} }
this->offset_28->next(); this->offset_28->next();
} }
void NSASTParse::ignore_buildin_kw(std::string const& a2)
{
if (!this->is_buildin_keywords(a2))
{
std::string msg = "Expected `" + a2 + "`";
this->offset_28->err(msg, 0, 0, false);
}
this->offset_28->next();
}
} }

View File

@ -314,7 +314,6 @@ namespace night
} }
std::string NSCompileJs::compile_obj_property(night::ns_node *) std::string NSCompileJs::compile_obj_property(night::ns_node *)
{ {
// TODO...
throw "not implement"; throw "not implement";
} }
std::string NSCompileJs::compile_obj_self_op(night::ns_node *a3) std::string NSCompileJs::compile_obj_self_op(night::ns_node *a3)
@ -492,8 +491,10 @@ namespace night
return result; return result;
} }
int compile_i = 0;
std::string NSCompileJs::compile(night::ns_node * a3) std::string NSCompileJs::compile(night::ns_node * a3)
{ {
int inner_compile_i = ++compile_i;
if (this->offset_0.size() == 0) if (this->offset_0.size() == 0)
{ {
std::string v9 = a3->offset_0; std::string v9 = a3->offset_0;

View File

@ -26,7 +26,6 @@ namespace night
} }
/** /**
* todo...
*/ */
int path_combine(std::string const& a1, std::string const& a2, std::string& a3) int path_combine(std::string const& a1, std::string const& a2, std::string& a3)
{ {

View File

@ -387,11 +387,11 @@ int main(int argc, const char **argv)
string helperCode; string helperCode;
WXML::Compiler::WXMLHelperCode(helperCode); WXML::Compiler::WXMLHelperCode(helperCode);
string data = "var __wxAppData=__wxAppData||{};var __wxAppCode__=__wxAppCode__||{};var global=global||{};var __WXML_GLOBAL__=" 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" "__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(){};" "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" "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!" "LOBAL__||{};var __globalThis=(typeof __vd_version_info__!=='undefined'&&typeof __vd_version_info__.globalThis!"
"=='undefined')?__vd_version_info__.globalThis:(typeof window!=='undefined'?window:globalThis);"; "=='undefined')?__vd_version_info__.globalThis:(typeof window!=='undefined'?window:globalThis);";
data = data + helperCode; data = data + helperCode;
outputContentMap["__COMMON__"] = data; outputContentMap["__COMMON__"] = data;
} }

View File

@ -54,7 +54,7 @@ namespace MMBizWxaAppComm
dirList.pop_back(); dirList.pop_back();
} }
} }
else if (v15[i] == ".") else if (v15[i].compare("."))
{ {
dirList.push_back(v15[i]); dirList.push_back(v15[i]);
} }

View File

@ -26,6 +26,7 @@ namespace WXML{
bool b1, // mark指定运算结果是否非0 a12 bool b1, // mark指定运算结果是否非0 a12
bool b2) // mark指定运算结果是否非0 a13 bool b2) // mark指定运算结果是否非0 a13
{ {
// ParseSource - 0
int pResult = 0; int pResult = 0;
bool isWxml = filePath.substr(filePath.length() - 5) == ".wxml"; bool isWxml = filePath.substr(filePath.length() - 5) == ".wxml";
if (isWxml) if (isWxml)
@ -38,6 +39,7 @@ namespace WXML{
if (parseResult) if (parseResult)
{ {
// ParseSource - 5
// GetParsed // GetParsed
std::shared_ptr<WXML::DOMLib::WXMLDom> parseDom = v50.GetParsed(); std::shared_ptr<WXML::DOMLib::WXMLDom> parseDom = v50.GetParsed();
result[filePath] = parseDom; result[filePath] = parseDom;
@ -49,9 +51,9 @@ namespace WXML{
ss << "']={};"; ss << "']={};";
ss << lineEndMark; ss << lineEndMark;
} }
// ParseSource - 10
for (int i = 0; i < tokenList.size(); i++) for (int i = 0; i < tokenList.size(); i++)
{ {
/* code */
int dealResult = 0; int dealResult = 0;
std::string v74, v76, v79; std::string v74, v76, v79;
int v65; int v65;
@ -141,6 +143,7 @@ namespace WXML{
ss << lineEndMark; ss << lineEndMark;
} }
} }
// ParseSource - 15
auto v69 = ss.str(); auto v69 = ss.str();
if (v69.length() > 0) if (v69.length() > 0)
{ {
@ -149,18 +152,17 @@ namespace WXML{
} }
// LABEL_24: // LABEL_24:
} }
// ParseSource - 20
else if(filePath.substr(filePath.length() - 4) == ".wxs") else if(filePath.substr(filePath.length() - 4) == ".wxs")
{ {
std::string v84; std::string v84; // errorMessage
std::string p = "p_" + filePath; std::string p = "p_" + filePath;
auto v86 = WXML::Compiler::GetFuncId(a11, p); auto v86 = WXML::Compiler::GetFuncId(a11, p);
int compilerResultCode = 0; int compilerResultCode = 0;
compilerResultCode = night::compile_ns(filePath, v86, content, 1, v84, false);
// TODO: compile_ns pResult = compilerResultCode;
if (compilerResultCode) { if (compilerResultCode) {
errorMessage.assign("error..."); errorMessage.assign(v84);
throw compilerResultCode;
} }
else else
{ {

View File

@ -367,7 +367,7 @@ namespace WXML
} }
if (bittest(&v46, 0x16u)) // 0x16 -> 22 if (bittest(&v46, 0x16u)) // 0x16 -> 22
{ {
// TODO: throw "not implement";
// WXML::DOMLib::Token token(*(a5.end() - 1)); // WXML::DOMLib::Token token(*(a5.end() - 1));
a5.pop_back(); a5.pop_back();

View File

@ -452,7 +452,8 @@ namespace WXML {
auto cur = this->offset_72[i]; auto cur = this->offset_72[i];
if (cur->offset_0 == "block") if (cur->offset_0 == "block")
{ {
// TODO... // this->offset_72[i]
// throw "not implement";
} }
} }
@ -810,6 +811,10 @@ namespace WXML {
for (int i = 0; i < v142.size(); i++) for (int i = 0; i < v142.size(); i++)
{ {
a6 << v142[i].first << ".wxXCkey=" << v142[i].second << a12; a6 << v142[i].first << ".wxXCkey=" << v142[i].second << a12;
// if (v142[i].first == "oVD")
// {
// printf("\n");
// }
} }
// RenderChildren - 20 // RenderChildren - 20
@ -829,6 +834,7 @@ namespace WXML {
} }
// int emplace_back_i = 0;
void WXMLDom::RenderNonDefine( void WXMLDom::RenderNonDefine(
std::string const& a2, std::string const& a2,
std::string const& a3, std::string const& a3,
@ -1278,7 +1284,11 @@ namespace WXML {
|| v161 != "wx:scope-data") || v161 != "wx:scope-data")
{ {
// pos: 搜索 -> !__stricmp((const char *)v161, "wx:scope-data") // pos: 搜索 -> !__stricmp((const char *)v161, "wx:scope-data")
// ++emplace_back_i;
// if (emplace_back_i == 139)
// {
// printf("\n");
// }
// WXML::DOMLib::Token token = this.; // WXML::DOMLib::Token token = this.;
v324.emplace_back(j->first, j->second); v324.emplace_back(j->first, j->second);
} }
@ -1305,7 +1315,7 @@ namespace WXML {
// { // {
// /* code */ // /* code */
// } // }
// TODO... throw "not implement";
} }
} }
@ -1332,11 +1342,12 @@ namespace WXML {
} }
if (!strncmp(&i->first[0], "data-", 5u) || i->first.find(':') != -1) if (!strncmp(&i->first[0], "data-", 5u) || i->first.find(':') != -1)
{ {
str.assign(i->first);
if (!strncmp(&i->first[0], "generic:", 8u)) if (!strncmp(&i->first[0], "generic:", 8u))
{ {
a6 << "var $tmp="; a6 << "var $tmp=";
// if (i->second.) // if (i->second.)
// TODO... throw "not implement";
} }
} }
else else
@ -1786,7 +1797,7 @@ namespace WXML {
// 0x48 -> 72 // 0x48 -> 72
this->offset_72[v4]->MarkIfHasDescendant(a2); this->offset_72[v4]->MarkIfHasDescendant(a2);
auto v6 = this->offset_72[v4]; auto v6 = this->offset_72[v4];
this->offset_256 = v6->offset_256; this->offset_256 |= v6->offset_256;
auto ret = std::find(a2.begin(), a2.end(), v6->offset_0); auto ret = std::find(a2.begin(), a2.end(), v6->offset_0);
if (ret != a2.end()) if (ret != a2.end())
{ {