feat: 添加实现 XCompiler::GetCompiled

This commit is contained in:
msojocs 2023-11-25 22:26:57 +08:00
parent 83c7df85cf
commit 3df049373a
8 changed files with 275 additions and 38 deletions

View File

@ -154,13 +154,13 @@ namespace night
int offset_52 = 0; // 当前行数 int offset_52 = 0; // 当前行数
int offset_56 = 0; // 当前行第几个字符位置 int offset_56 = 0; // 当前行第几个字符位置
NSStream(/* args */); NSStream(/* args */);
NSStream(std::string const&,std::string const&,uint); NSStream(std::string const&, std::string const&, uint);
~NSStream(); ~NSStream();
NSStream(NSStream const&); NSStream(NSStream const&);
NSStream& operator=(NSStream const&); NSStream& operator=(NSStream const&);
bool eof(void); bool eof(void);
bool eof_2(void); bool eof_2(void);
void err(std::string const&,int,int,bool); void err(std::string const&, int, int, bool);
PeekData next(void); PeekData next(void);
PeekData peek(void); PeekData peek(void);
PeekData peek_2(void); PeekData peek_2(void);

View File

@ -94,26 +94,84 @@ namespace night
return 0; return 0;
} }
/**
*
*
*
*/
void compile_ns_with_sourcemap( void compile_ns_with_sourcemap(
std::string const&, std::string const& a1,
std::string const&, std::string const& a2,
std::string const&, std::string const& a3,
std::string const&, std::string const& a4,
uint, uint a5,
std::string&, std::string& a6,
std::string& std::string& a7
) )
{ {
int retcode = 0;
a6 = "";
night::NSStream v80(a1, a4, a5);
night::NSToken v69;
night::NSGod v36;
night::NSASTParse v81(a1, &v69, &v36);
night::NSCompileJs v71;
v71.offset_24 = &v81;
std::string v41;
std::vector<std::string> v37;
std::string v43 = v71.compile_once(v41, &v37, false);
v36.hamlet();
// if (v43.length())
// {
// a6.assign(v43);
// retcode = 121;
// }
// else
// {
// std::string ret = "";
// std::string v51 = ";return " + night::nsv_;
// v51.append("module.");
// v51.append(night::nsv_);
// v51.append("exports;");
// std::string v57 = "function " + a3 + "(){";
// a6 = v57;
// std::string v45 = "var " + night::nsv_ + "module={" + night::nsv_ + "exports:{}};";
// ret += v45;
// std::string v63 = v41 + v51;
// ret += v63;
// ret += "}";
// v63 = "\n//# sourceMappingURL=" + a2;
// ret += v63;
// // ...
// }
throw "not implement"; throw "not implement";
} }
/**
*
*
*
*/
void readfile(char const*, std::string &) void readfile(char const*, std::string &)
{ {
throw "not implement"; throw "not implement";
} }
/**
*
*
*
*/
void writefile(char const*, std::string &) void writefile(char const*, std::string &)
{ {

View File

@ -139,8 +139,6 @@ namespace night
} }
auto v8 = this->ast_obj_op(v25); auto v8 = this->ast_obj_op(v25);
return this->make_call_or_just_expression(v8); return this->make_call_or_just_expression(v8);
// throw "not implement";
} }
night::ns_node *NSASTParse::ast_code_block() night::ns_node *NSASTParse::ast_code_block()
{ {
@ -326,11 +324,42 @@ namespace night
} }
night::ns_node *NSASTParse::ast_while() night::ns_node *NSASTParse::ast_while()
{ {
throw "not implement"; this->offset_28->next();
night::ns_node * v7 = this->offset_24->gen_son(night::NS_TYPE_WHILE);
v7->offset_204 = nullptr;
v7->offset_216 = nullptr;
this->ignore_punc("(");
v7->offset_204 = this->ast_expression();
this->ignore_punc(")");
this->offset_36++;
this->offset_40++;
v7->offset_216 = this->ast_expression();
this->offset_36--;
this->offset_40--;
return v7;
} }
night::ns_node *NSASTParse::ast_do_while() night::ns_node *NSASTParse::ast_do_while()
{ {
throw "not implement"; this->offset_28->next();
auto v1 = this->offset_28->offset_4;
night::ns_node * v12 = this->offset_24->gen_son(night::NS_TYPE_DO_WHILE);
if (!this->is_punctuation("{"))
{
this->offset_28->err("Expected `{`", v1->offset_52, v1->offset_56, true);
}
this->offset_36++;
this->offset_40++;
v12->offset_216 = this->ast_expression();
this->offset_36--;
this->offset_40--;
this->ignore_buildin_kw("while");
this->ignore_punc("(");
v12->offset_204 = this->ast_expression();
this->ignore_punc(")");
return v12;
} }
night::ns_node *NSASTParse::ast_switch() night::ns_node *NSASTParse::ast_switch()
{ {

View File

@ -1,4 +1,5 @@
#include "../include/night.h" #include "../include/night.h"
#include <cstring>
namespace night namespace night
{ {
@ -11,8 +12,71 @@ namespace night
{ {
} }
/**
* night::NSCompileJs::compile_once
*
* false处理
*
*/
std::string ns_node::debug_no_space() std::string ns_node::debug_no_space()
{ {
// debug_no_space - 0
char str[1024];
memset(str, 0, sizeof(str));
if ("skip" == this->offset_0)
{
sprintf(str, "type[%s]", this->offset_0.data());
}
if ("bool" == this->offset_0)
{
if (this->offset_24.length())
{
sprintf(str, "(%d,%d)type[%s] value[%s]", this->offset_48, this->offset_52, this->offset_0, this->offset_60);
}
else
{
sprintf(str, "type[%s] value[%s]", this->offset_0, this->offset_60);
}
}
if (
"num" == this->offset_0
|| "builtin_type" == this->offset_0
|| "kw" == this->offset_0
|| "var" == this->offset_0
|| "punc" == this->offset_0
|| "op" == this->offset_0
)
{
if (this->offset_24.length())
{
sprintf(str, "(%d,%d)type[%s] value[%s]", this->offset_48, this->offset_52, this->offset_0, this->offset_60);
}
else
{
sprintf(str, "type[%s] value[%s]", this->offset_0, this->offset_60);
}
}
if ("var" == this->offset_0)
{
if (this->offset_24.length())
{
sprintf(str, "(%d,%d)type[%s] value[%s] flag[%d]", this->offset_48, this->offset_52, this->offset_0, this->offset_60, this->offset_56);
}
else
{
sprintf(str, "type[%s] value[%s] flag[%d]", this->offset_0, this->offset_60, this->offset_56);
}
}
// debug_no_space - 5
// debug_no_space - 10
// debug_no_space - 15
// debug_no_space - 20
// debug_no_space - 25
// debug_no_space - 30
// debug_no_space - 35
// debug_no_space - 40
// debug_no_space - 45
throw "not implement"; throw "not implement";
} }

View File

@ -467,15 +467,16 @@ namespace WXML {
} }
// RewriteTree - 15 // RewriteTree - 15
for (int i = 0; i < this->offset_72.size(); i++) // 看起来似乎是多余的代码
{ // for (int i = 0; i < this->offset_72.size(); i++)
auto cur = this->offset_72[i]; // {
if (cur->offset_0 == "block") // auto cur = this->offset_72[i];
{ // if (cur->offset_0 == "block")
// this->offset_72[i] // {
// throw "not implement"; // // this->offset_72[i]
} // // throw "not implement";
} // }
// }
// RewriteTree - 20 // RewriteTree - 20
for (int i = 0; i < this->offset_72.size(); i++) for (int i = 0; i < this->offset_72.size(); i++)
@ -1384,8 +1385,23 @@ namespace WXML {
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.offset_0.length())
throw "not implement"; {
a6 << "grb(z[";
a6 << i->second.offset_0;
a6 << "]," << a8 << "," << a9 << "," << a10 << ")" << a12;
a6 << "if ($tmp!=\"\") $tmp=\"wx-\"+$tmp";
}
else
{
a6 << "\"\"";
}
a6 << a12;
a6 << a5 << ".generics['" << "wx-";
a6 << i->first;
a6 << "']=$tmp";
a6 << a12;
continue;
} }
} }
else else

View File

@ -612,7 +612,8 @@ namespace WXSS
} }
int off_519B9C(std::shared_ptr<WXSS::CSSTreeLib::Rule>& a1, std::shared_ptr<WXSS::CSSTreeLib::CSSSyntaxTree> &a2) int off_519B9C(std::shared_ptr<WXSS::CSSTreeLib::Rule>& a1, std::shared_ptr<WXSS::CSSTreeLib::CSSSyntaxTree> &a2)
{ {
throw "not implement"; a2->offset_116 = 0;
return 0;
} }
int off_519BB4_i = 0; int off_519BB4_i = 0;

View File

@ -203,14 +203,56 @@ namespace WXSS
} }
return 0; return 0;
} }
int XCompiler::GetCompiled(std::string const&, std::string&) int XCompiler::GetCompiled(std::string const& a2, std::string& a3)
{ {
if (this->offset_0) if (this->offset_0)
{ {
return 6; return 6;
} }
int v14 = this->offset_0;
auto v15 = this->offset_104.find(a2);
if (v15 == this->offset_104.end())
{
if (this->offset_32.find(a2) == this->offset_32.end())
{
v14 = 1;
a3 = "";
}
else
{
a3 = "";
auto v7 = this->offset_32[a2];
auto vec = v7->offset_120;
for (int i = 0; i < vec.size(); i++)
{
auto cur = vec[i];
if (
cur->offset_0 == "DIRECTIVE"
&& cur->offset_120.size() > 0
&& cur->offset_120[0]->offset_0 == "@import"
&& cur->offset_140.get() != nullptr
)
{
std::string v21(*cur->offset_140);
std::string v22;
this->GetCompiled(v21, v22);
a3 = v22;
}
else
{
cur->RenderCode(a3, true);
}
}
this->offset_104[a2].assign(a3);
}
}
else
{
a3.assign(this->offset_104[a2]);
}
throw "not implement"; return v14;
} }
int XCompiler::GetJSCompiled(std::string const& a2, std::string& a3) int XCompiler::GetJSCompiled(std::string const& a2, std::string& a3)
{ {

View File

@ -20661,6 +20661,10 @@ _DWORD *__thiscall night::NSCompileJs::compile_prog_no_sem[abi:cxx11](_DWORD *th
// 41995C: using guessed type _DWORD __stdcall night::NSCompileJs::compile[abi:cxx11](_DWORD, _DWORD); // 41995C: using guessed type _DWORD __stdcall night::NSCompileJs::compile[abi:cxx11](_DWORD, _DWORD);
//----- (0041C7CC) -------------------------------------------------------- //----- (0041C7CC) --------------------------------------------------------
/**
* @param this result
* @param a2 this
*/
char *__thiscall night::NSCompileJs::compile_once(char *this, int a2, unsigned int *a3, int a4, char a5) char *__thiscall night::NSCompileJs::compile_once(char *this, int a2, unsigned int *a3, int a4, char a5)
{ {
const char **v5; // eax const char **v5; // eax
@ -20910,19 +20914,23 @@ int __cdecl night::compile_ns_with_sourcemap(
memset(&v69[2], 0, 16); memset(&v69[2], 0, 16);
std::string::basic_string((char *)v71, (int)a1); std::string::basic_string((char *)v71, (int)a1);
night::NSASTParse::NSASTParse((int)v81, (int)v71, (int)v69, (int)v36); night::NSASTParse::NSASTParse((int)v81, (int)v71, (int)v69, (int)v36);
// 销毁清空v71
std::string::_M_dispose(v71); std::string::_M_dispose(v71);
v71[0] = &v72; v71[0] = &v72; // v71.offset_0
v73 = v81; v71[1] = 0; // v71.offset_4
v41[0] = &v42;
v71[1] = 0; v72 = 0; // v71.offset_8
v72 = 0; v73 = v81; // v71.offset_12
v76 = 0; v74 = 0; // v71.offset_16
v77 = 0; v75 = 0; // v71.offset_20
v78 = 0; v76 = 0; // v71.offset_24
v74 = 0; v77 = 0; // v71.offset_28
v75 = 0; v78 = 0; // v71.offset_32
v79 = 1; v79 = 1;
v41[0] = &v42;
v41[1] = 0; v41[1] = 0;
v42 = 0; v42 = 0;
memset(v37, 0, sizeof(v37)); memset(v37, 0, sizeof(v37));
night::NSCompileJs::compile_once((char *)v43, (int)v71, (unsigned int *)v41, (int)v37, 0); night::NSCompileJs::compile_once((char *)v43, (int)v71, (unsigned int *)v41, (int)v37, 0);
@ -20944,12 +20952,15 @@ int __cdecl night::compile_ns_with_sourcemap(
std::string::_M_dispose((void **)&v63); std::string::_M_dispose((void **)&v63);
std::string::_M_dispose((void **)&v57); std::string::_M_dispose((void **)&v57);
std::string::_M_dispose((void **)&v51); std::string::_M_dispose((void **)&v51);
std::operator+<char>((int)&v57, "function ", a3); std::operator+<char>((int)&v57, "function ", a3);
v10 = std::string::append(&v57, "(){"); v10 = std::string::append(&v57, "(){");
std::string::basic_string(&v63, v10); std::string::basic_string(&v63, v10);
std::string::operator=((unsigned __int8 **)a6, (int)&v63); std::string::operator=((unsigned __int8 **)a6, (int)&v63);
std::string::_M_dispose((void **)&v63); std::string::_M_dispose((void **)&v63);
std::string::_M_dispose((void **)&v57); std::string::_M_dispose((void **)&v57);
std::operator+<char>((int)&v45, "var ", (int)&night::nsv_); std::operator+<char>((int)&v45, "var ", (int)&night::nsv_);
v11 = std::string::append(&v45, "module={"); v11 = std::string::append(&v45, "module={");
std::string::basic_string(&v51, v11); std::string::basic_string(&v51, v11);
@ -20962,10 +20973,12 @@ int __cdecl night::compile_ns_with_sourcemap(
std::string::_M_dispose((void **)&v57); std::string::_M_dispose((void **)&v57);
std::string::_M_dispose((void **)&v51); std::string::_M_dispose((void **)&v51);
std::string::_M_dispose((void **)&v45); std::string::_M_dispose((void **)&v45);
v32 = a6[1]; v32 = a6[1];
std::operator+<char>((char *)&v63, (int)v41, (int)v44); std::operator+<char>((char *)&v63, (int)v41, (int)v44);
std::string::operator+=(&v63); std::string::operator+=(&v63);
std::string::_M_dispose((void **)&v63); std::string::_M_dispose((void **)&v63);
std::string::operator+=("}"); std::string::operator+=("}");
std::operator+<char>((int)&v63, "\n//# sourceMappingURL=", a2); std::operator+<char>((int)&v63, "\n//# sourceMappingURL=", a2);
std::string::operator+=(&v63); std::string::operator+=(&v63);
@ -20973,6 +20986,7 @@ int __cdecl night::compile_ns_with_sourcemap(
Block = 0; Block = 0;
v39 = 0; v39 = 0;
v40 = 0; v40 = 0;
// v71.offset28 - v71.offset_24
lpuexcpta = (struct _Unwind_Exception *)(v77 - v76); lpuexcpta = (struct _Unwind_Exception *)(v77 - v76);
if ( v77 == v76 ) if ( v77 == v76 )
{ {
@ -54356,6 +54370,7 @@ void **__thiscall night::ns_node::debug_no_space[abi:cxx11](void **this, const c
char Str[4]; // [esp+120h] [ebp-418h] BYREF char Str[4]; // [esp+120h] [ebp-418h] BYREF
char v105[1020]; // [esp+124h] [ebp-414h] BYREF char v105[1020]; // [esp+124h] [ebp-414h] BYREF
// debug_no_space - 0
*(_DWORD *)Str = 0; *(_DWORD *)Str = 0;
memset(v105, 0, sizeof(v105)); memset(v105, 0, sizeof(v105));
if ( std::operator==<char>("skip", (int)a2) ) if ( std::operator==<char>("skip", (int)a2) )
@ -54381,6 +54396,8 @@ void **__thiscall night::ns_node::debug_no_space[abi:cxx11](void **this, const c
else else
sprintf(Str, "type[%s] value[%s]", v3, a2[15]); sprintf(Str, "type[%s] value[%s]", v3, a2[15]);
} }
// var
if ( std::operator==<char>((char *)off_551FFE, (int)a2) ) if ( std::operator==<char>((char *)off_551FFE, (int)a2) )
{ {
v4 = a2[15]; v4 = a2[15];
@ -54390,6 +54407,7 @@ void **__thiscall night::ns_node::debug_no_space[abi:cxx11](void **this, const c
else else
sprintf(Str, "type[%s] value[%s] flag[%d]", v5, v4, *((unsigned __int8 *)a2 + 56)); sprintf(Str, "type[%s] value[%s] flag[%d]", v5, v4, *((unsigned __int8 *)a2 + 56));
} }
// debug_no_space - 5
if ( std::operator==<char>("op_self", (int)a2) ) if ( std::operator==<char>("op_self", (int)a2) )
{ {
v97 = 0; v97 = 0;
@ -54419,6 +54437,7 @@ void **__thiscall night::ns_node::debug_no_space[abi:cxx11](void **this, const c
else else
sprintf(Str, "type[%s] value[%s%s%s]", v10, v11, v9, a2[27]); sprintf(Str, "type[%s] value[%s%s%s]", v10, v11, v9, a2[27]);
} }
// debug_no_space - 10
if ( std::operator==<char>((char *)off_5520BF, (int)a2) ) if ( std::operator==<char>((char *)off_5520BF, (int)a2) )
{ {
v97 = 0; v97 = 0;
@ -54474,6 +54493,7 @@ void **__thiscall night::ns_node::debug_no_space[abi:cxx11](void **this, const c
} }
std::string::_M_dispose((void **)v103); std::string::_M_dispose((void **)v103);
} }
// debug_no_space - 15
if ( std::operator==<char>("obj_dot", (int)a2) || std::operator==<char>("obj_property", (int)a2) ) if ( std::operator==<char>("obj_dot", (int)a2) || std::operator==<char>("obj_property", (int)a2) )
{ {
v93[0] = 0; v93[0] = 0;
@ -54520,6 +54540,7 @@ void **__thiscall night::ns_node::debug_no_space[abi:cxx11](void **this, const c
v22 = v92; v22 = v92;
goto LABEL_131; goto LABEL_131;
} }
// debug_no_space - 20
if ( std::operator==<char>("if", (int)a2) ) if ( std::operator==<char>("if", (int)a2) )
{ {
v97 = 0; v97 = 0;
@ -54565,6 +54586,8 @@ LABEL_130:
v22 = &v96; v22 = &v96;
goto LABEL_131; goto LABEL_131;
} }
// debug_no_space - 25
if ( std::operator==<char>((char *)off_552210, (int)a2) ) if ( std::operator==<char>((char *)off_552210, (int)a2) )
{ {
v98[0] = 0; v98[0] = 0;
@ -54598,6 +54621,7 @@ LABEL_130:
std::string::operator+=(v103); std::string::operator+=(v103);
goto LABEL_73; goto LABEL_73;
} }
// debug_no_space - 30
if ( std::operator==<char>("while", (int)a2) || std::operator==<char>("do_while", (int)a2) ) if ( std::operator==<char>("while", (int)a2) || std::operator==<char>("do_while", (int)a2) )
{ {
v97 = 0; v97 = 0;
@ -54625,6 +54649,7 @@ LABEL_130:
std::string::operator+=(v103); std::string::operator+=(v103);
goto LABEL_73; goto LABEL_73;
} }
// debug_no_space - 35
if ( std::operator==<char>("switch", (int)a2) ) if ( std::operator==<char>("switch", (int)a2) )
{ {
v91[0] = 0; v91[0] = 0;
@ -54716,6 +54741,7 @@ LABEL_130:
} }
std::string::operator+=("\ndefault<="); std::string::operator+=("\ndefault<=");
} }
// debug_no_space - 40
else else
{ {
if ( std::operator==<char>("binary", (int)a2) if ( std::operator==<char>("binary", (int)a2)
@ -54880,6 +54906,7 @@ LABEL_130:
} }
std::string::operator+=("\ncall<="); std::string::operator+=("\ncall<=");
} }
// debug_no_space - 45
std::string::basic_string(this, &v89); std::string::basic_string(this, &v89);
v22 = (int *)&v89; v22 = (int *)&v89;
LABEL_131: LABEL_131: