mirror of
https://github.com/msojocs/wx-compiler.git
synced 2025-07-19 00:00:04 +08:00
feat: 开始添加wxs相关处理
This commit is contained in:
parent
d18694c8df
commit
a94787ce7e
@ -40,23 +40,14 @@ namespace night
|
||||
extern std::string std_v_n;
|
||||
extern std::string std_v_v_n;
|
||||
|
||||
extern std::string nsv_;
|
||||
extern std::string nst_;
|
||||
|
||||
int compile_ns(std::string const&,std::string const&,std::string const&,uint,std::string&,bool);
|
||||
void compile_ns_with_sourcemap(std::string const&,std::string const&,std::string const&,std::string const&,uint,std::string&,std::string&);
|
||||
void readfile(char const*, std::string &);
|
||||
void writefile(char const*, std::string &);
|
||||
|
||||
class NSGod
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
NSGod(/* args */);
|
||||
~NSGod();
|
||||
void gen_girl(std::string);
|
||||
void gen_son(std::string);
|
||||
void hamlet(void);
|
||||
};
|
||||
|
||||
class ns_node
|
||||
{
|
||||
private:
|
||||
@ -65,6 +56,7 @@ namespace night
|
||||
std::string offset_0;
|
||||
std::string offset_24;
|
||||
std::string offset_60;
|
||||
std::string offset_84;
|
||||
std::string offset_108;
|
||||
std::string offset_156;
|
||||
night::ns_node * offset_180;
|
||||
@ -77,17 +69,31 @@ namespace night
|
||||
std::string debug_no_space(void);
|
||||
};
|
||||
|
||||
class NSGod
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
std::vector<night::ns_node *> offset_0;
|
||||
NSGod(/* args */);
|
||||
~NSGod();
|
||||
std::vector<night::ns_node *> gen_girl(std::string a2);
|
||||
night::ns_node* gen_son(std::string);
|
||||
void hamlet(void);
|
||||
};
|
||||
|
||||
class NSToken
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
int offset_4;
|
||||
NSToken(/* args */);
|
||||
~NSToken();
|
||||
bool eof(void);
|
||||
void err(std::string const&,int,int,bool);
|
||||
void err(std::string const&, int, int, bool);
|
||||
void get_tokens_for_sourcemap(std::map<std::string, uint> &, std::map<uint,std::string> &);
|
||||
void next(void);
|
||||
night::ns_node* next(void);
|
||||
void pass(void);
|
||||
void peek(void);
|
||||
void push(night::ns_node *);
|
||||
@ -95,7 +101,7 @@ namespace night
|
||||
void read_comment_method_2(void);
|
||||
void read_next(void);
|
||||
void read_number(std::string const&);
|
||||
void read_string(char,std::string const&);
|
||||
void read_string(char, std::string const&);
|
||||
void read_var(std::string const&);
|
||||
std::string read_while(bool (*)(char,void *),void *);
|
||||
void rw_cb_number(char,void *);
|
||||
@ -127,7 +133,7 @@ namespace night
|
||||
void ast_code_block(void);
|
||||
void ast_dispatch(bool);
|
||||
void ast_do_while(void);
|
||||
void ast_expression(void);
|
||||
night::ns_node * ast_expression(void);
|
||||
void ast_expression_no_binary(void);
|
||||
void ast_expression_no_comma(void);
|
||||
void ast_for(void);
|
||||
@ -166,7 +172,7 @@ namespace night
|
||||
/**
|
||||
* 是否是标点符号(punctuation)
|
||||
*/
|
||||
void is_punctuation(std::string const&);
|
||||
bool is_punctuation(std::string const&);
|
||||
void is_save_for_division(night::ns_node *);
|
||||
void make_binary_or_just_value(night::ns_node *,bool);
|
||||
void make_call_or_just_expression(night::ns_node *);
|
||||
@ -179,7 +185,7 @@ namespace night
|
||||
int,
|
||||
std::string
|
||||
);
|
||||
void top_down(void);
|
||||
night::ns_node* top_down(void);
|
||||
};
|
||||
|
||||
class ns_sourcemap
|
||||
@ -216,7 +222,7 @@ namespace night
|
||||
std::string compile_obj_dot(night::ns_node *);
|
||||
std::string compile_obj_property(night::ns_node *);
|
||||
std::string compile_obj_self_op(night::ns_node *);
|
||||
void compile_once(std::string &, std::vector<std::string> *, bool);
|
||||
std::string compile_once(std::string &, std::vector<std::string> *, bool);
|
||||
std::string compile_op_self(night::ns_node *);
|
||||
std::string compile_prog(night::ns_node *);
|
||||
std::string compile_prog_no_sem(night::ns_node *);
|
||||
|
@ -2,39 +2,47 @@
|
||||
|
||||
namespace night
|
||||
{
|
||||
std::string NS_TYPE_BOOL;
|
||||
std::string NS_TYPE_VAR;
|
||||
std::string NS_TYPE_NUM;
|
||||
std::string NS_TYPE_B_TYPE;
|
||||
std::string NS_TYPE_OP_SELF;
|
||||
std::string NS_TYPE_BINARY;
|
||||
std::string NS_TYPE_ASSIGN;
|
||||
std::string NS_TYPE_TERNARY;
|
||||
std::string NS_TYPE_OBJ_DOT;
|
||||
std::string NS_TYPE_OBJ_PROPERTY;
|
||||
std::string NS_TYPE_OBJ_SELF_OP;
|
||||
std::string NS_TYPE_OBJ_BLOCK;
|
||||
std::string NS_TYPE_BRACKET;
|
||||
std::string NS_TYPE_CALL;
|
||||
std::string NS_TYPE_KW;
|
||||
std::string NS_TYPE_SKIP;
|
||||
std::string NS_TYPE_STR;
|
||||
std::string NS_TYPE_PUNC;
|
||||
std::string NS_TYPE_FUNC;
|
||||
std::string NS_TYPE_PROG;
|
||||
std::string NS_TYPE_PROG_NO_SEM;
|
||||
std::string NS_TYPE_PROG_NO_SEM_REQUIRE;
|
||||
std::string NS_TYPE_ARRAY;
|
||||
std::string NS_TYPE_SWITCH;
|
||||
std::string NS_TYPE_DO_WHILE;
|
||||
std::string NS_TYPE_WHILE;
|
||||
std::string NS_TYPE_FOR;
|
||||
std::string NS_TYPE_IF;
|
||||
std::string NS_TYPE_K_V;
|
||||
std::string NS_TYPE_BOOL = "bool";
|
||||
std::string NS_TYPE_VAR = "var";
|
||||
std::string NS_TYPE_NUM = "num";
|
||||
std::string NS_TYPE_B_TYPE = "builtin_type";
|
||||
std::string NS_TYPE_OP_SELF = "op_self";
|
||||
std::string NS_TYPE_BINARY = "binary";
|
||||
std::string NS_TYPE_ASSIGN = "assign";
|
||||
std::string NS_TYPE_TERNARY = "ternary";
|
||||
std::string NS_TYPE_OBJ_DOT = "obj_dot";
|
||||
std::string NS_TYPE_OBJ_PROPERTY = "obj_property";
|
||||
std::string NS_TYPE_OBJ_SELF_OP = "obj_self_op";
|
||||
std::string NS_TYPE_OBJ_BLOCK = "obj_block";
|
||||
std::string NS_TYPE_ARRAY = "array";
|
||||
std::string NS_TYPE_BRACKET = "bracket";
|
||||
std::string NS_TYPE_CALL = "call";
|
||||
std::string NS_TYPE_KW = "kw";
|
||||
std::string NS_TYPE_SKIP = "skip";
|
||||
std::string NS_TYPE_STR = "str";
|
||||
std::string NS_TYPE_PUNC = "punc";
|
||||
std::string NS_TYPE_FUNC = "function";
|
||||
std::string NS_TYPE_PROG = "prog";
|
||||
std::string NS_TYPE_PROG_NO_SEM = "prog_no_sem";
|
||||
std::string NS_TYPE_PROG_NO_SEM_REQUIRE = "prog_no_sem_require";
|
||||
std::string NS_TYPE_SWITCH = "switch";
|
||||
std::string NS_TYPE_DO_WHILE = "do_while";
|
||||
std::string NS_TYPE_WHILE = "while";
|
||||
std::string NS_TYPE_FOR = "for";
|
||||
std::string NS_TYPE_IF = "if";
|
||||
std::string NS_TYPE_K_V = "k-v";
|
||||
std::string NS_TYPE_OP = "op";
|
||||
|
||||
std::string NS_BUILTIN_OP = "+-*/%=&^|<>~!?";
|
||||
std::string NS_BUILTIN_OP_SELF = "~!";
|
||||
std::string NS_BUILTIN_ALL_OP = " = ? + - * / % ++ -- + - ~ ! << >> >>> & ^ | < > <= >= == != === !== *= /= %= += -= <<= >>= >>>= &= ^= |= && || ";
|
||||
std::string NS_BUILTIN_PUNC = ".,;(){}[]:";
|
||||
|
||||
std::string std_v_n = "";
|
||||
std::string std_v_v_n = "";
|
||||
std::string std_v_n = "new std::vector<ns_node*>";
|
||||
std::string std_v_v_n = "new std::vector<std::vector<ns_node*>*>";
|
||||
|
||||
std::string nsv_ = "nv_";
|
||||
std::string nst_ = "nt_";
|
||||
|
||||
int compile_ns(
|
||||
std::string const& a1,
|
||||
@ -49,8 +57,32 @@ namespace night
|
||||
night::NSToken v27;
|
||||
night::NSGod v17;
|
||||
night::NSASTParse v39(a1, &v27, &v17);
|
||||
|
||||
NSCompileJs cjs;
|
||||
std::string v19;
|
||||
std::vector<std::string> v18;
|
||||
std::string v21 = cjs.compile_once(v19, &v18, a6);
|
||||
v17.hamlet();
|
||||
if (v21.length())
|
||||
{
|
||||
a5.assign(v21);
|
||||
return 121;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string v24 = ";return " + night::nsv_;
|
||||
v24.append("module.").append(night::nsv_);
|
||||
v24.append("exports;");
|
||||
std::string v25 = "function " + a2;
|
||||
v25.append("(){");
|
||||
a5 = v25;
|
||||
std::string v23 = "var " + night::nsv_;
|
||||
v23.append("module={").append(night::nsv_);
|
||||
v23.append("exports:{}};");
|
||||
a5.append(v23);
|
||||
std::string v26 = v19 + v24;
|
||||
a5.append(v26);
|
||||
a5.append("}");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -23,19 +23,110 @@ namespace night
|
||||
{
|
||||
}
|
||||
|
||||
void NSASTParse::is_op(std::string const& a2)
|
||||
{
|
||||
// std::string v2 = this->offset_28->peek();
|
||||
// if (v2.length())
|
||||
// {
|
||||
// if (night::NS_TYPE_OP == v2)
|
||||
// {
|
||||
// if (a2.length() && a2 != v2->offset_60)
|
||||
// return 0;
|
||||
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return 0;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
void NSASTParse::is_op_or_comma(std::string const&)
|
||||
{
|
||||
|
||||
// bool result = this->is_punctuation(",");
|
||||
// if (!result)
|
||||
// {
|
||||
// return this->is_op(result);
|
||||
// }
|
||||
}
|
||||
|
||||
void NSASTParse::is_punctuation(std::string const&)
|
||||
night::ns_node * NSASTParse::ast_expression()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool NSASTParse::is_punctuation(std::string const&)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
night::ns_node* NSASTParse::top_down()
|
||||
{
|
||||
auto v6 = this->offset_24->gen_girl(night::std_v_n);
|
||||
night::ns_node ret;
|
||||
while (!this->offset_28->eof())
|
||||
{
|
||||
auto v16 = this->ast_expression();
|
||||
v6.push_back(v16);
|
||||
auto v7 = this->offset_28;
|
||||
// v7->offset_4;
|
||||
// auto v5 = v1.offset_56;
|
||||
// auto v4 = v1.offset_52;
|
||||
if (
|
||||
night::NS_TYPE_BOOL == v16->offset_0
|
||||
|| night::NS_TYPE_VAR == v16->offset_0
|
||||
|| night::NS_TYPE_STR == v16->offset_0
|
||||
|| night::NS_TYPE_NUM == v16->offset_0
|
||||
|| night::NS_TYPE_B_TYPE == v16->offset_0
|
||||
|| night::NS_TYPE_KW == v16->offset_0
|
||||
|| night::NS_TYPE_OP_SELF == v16->offset_0
|
||||
|| night::NS_TYPE_BINARY == v16->offset_0
|
||||
|| night::NS_TYPE_ASSIGN == v16->offset_0
|
||||
|| night::NS_TYPE_TERNARY == v16->offset_0
|
||||
|| night::NS_TYPE_OBJ_DOT == v16->offset_0
|
||||
|| night::NS_TYPE_OBJ_PROPERTY == v16->offset_0
|
||||
|| night::NS_TYPE_OBJ_SELF_OP == v16->offset_0
|
||||
|| night::NS_TYPE_ARRAY == v16->offset_0
|
||||
|| night::NS_TYPE_BRACKET == v16->offset_0
|
||||
|| night::NS_TYPE_CALL == v16->offset_0
|
||||
)
|
||||
{
|
||||
// night::ns_node* v2 = v7->peek();
|
||||
// if(v2)
|
||||
// {
|
||||
// if (";" != v2->offset_60 && v2->offset_84.find(10, 0) == -1)
|
||||
// {
|
||||
// // this->offset_28->err("Expected LineFeed", , , true);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
while (!this->offset_28->eof())
|
||||
{
|
||||
if(!this->is_punctuation(";"))
|
||||
{
|
||||
break;
|
||||
}
|
||||
this->offset_28->next();
|
||||
}
|
||||
|
||||
}
|
||||
auto son = this->offset_24->gen_son(night::NS_TYPE_PROG);
|
||||
son->offset_108 = "";
|
||||
|
||||
return son;
|
||||
}
|
||||
|
||||
void NSASTParse::top_down()
|
||||
void NSASTParse::ast_require()
|
||||
{
|
||||
|
||||
auto v17 = this->offset_24->gen_girl(night::std_v_n);
|
||||
auto v22 = this->offset_28->next();
|
||||
v22->offset_60 = night::nsv_ + v22->offset_60;
|
||||
v17.push_back(v22);
|
||||
|
||||
v22 = this->offset_24->gen_son(night::NS_TYPE_PUNC);
|
||||
v22->offset_60 = "(\000)\000{";
|
||||
v17.push_back(v22);
|
||||
this->offset_28->next();
|
||||
auto v3 = this->offset_28->next();
|
||||
}
|
||||
|
||||
}
|
@ -267,19 +267,19 @@ namespace night
|
||||
return "";
|
||||
}
|
||||
|
||||
void NSCompileJs::compile_once(std::string &a3, std::vector<std::string> *a4, bool a5)
|
||||
std::string NSCompileJs::compile_once(std::string &a3, std::vector<std::string> *a4, bool a5)
|
||||
{
|
||||
this->offset_28 = a4;
|
||||
a3 = "";
|
||||
this->offset_24->top_down();
|
||||
night::ns_node v5;
|
||||
night::ns_node* v5 = this->offset_24->top_down();
|
||||
if (a5)
|
||||
{
|
||||
std::string ret = v5.debug_no_space();
|
||||
std::string ret = v5->debug_no_space();
|
||||
printf("ast :%s\n", ret.data());
|
||||
}
|
||||
std::string v9 = this->compile(&v5);
|
||||
std::string v9 = this->compile(v5);
|
||||
a3 = v9;
|
||||
return this->offset_0;
|
||||
}
|
||||
|
||||
}
|
@ -10,7 +10,7 @@ namespace night
|
||||
{
|
||||
}
|
||||
|
||||
void NSGod::gen_girl(std::string a2)
|
||||
std::vector<night::ns_node *> NSGod::gen_girl(std::string a2)
|
||||
{
|
||||
if (night::std_v_n == a2)
|
||||
{
|
||||
@ -20,9 +20,10 @@ namespace night
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void NSGod::gen_son(std::string)
|
||||
night::ns_node* NSGod::gen_son(std::string)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -11,10 +11,21 @@ namespace night
|
||||
}
|
||||
void NSToken::peek(void)
|
||||
{
|
||||
// this->offset_8;
|
||||
|
||||
}
|
||||
void NSToken::read_next(void)
|
||||
{
|
||||
|
||||
}
|
||||
night::ns_node* NSToken::next(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool NSToken::eof(void)
|
||||
{
|
||||
// return this->peek() == 0;
|
||||
}
|
||||
|
||||
}
|
@ -832,10 +832,6 @@ namespace WXML{
|
||||
std::string data = "<fak";
|
||||
data = data.append(sub);
|
||||
data = data.append("/>");
|
||||
/*
|
||||
....<fak module=
|
||||
"refresh"/>.....
|
||||
*/
|
||||
// DealWxsTag - 5
|
||||
for (int i = 1; i < a2.offset_8; i++)
|
||||
{
|
||||
@ -1053,7 +1049,7 @@ namespace WXML{
|
||||
a2.insert({a3, a2.size()});
|
||||
}
|
||||
auto v5 = a2[a3];
|
||||
sprintf(&result[0], "np_%d", v5);
|
||||
result = "np_" + std::to_string(v5);
|
||||
return result;
|
||||
}
|
||||
} // namespace Compiler
|
||||
|
@ -15845,13 +15845,17 @@ unsigned int __fastcall night::NSGod::hamlet(_DWORD *a1)
|
||||
|
||||
for ( i = 0; ; ++i )
|
||||
{
|
||||
// this->offset_0.size()
|
||||
result = (a1[1] - *a1) >> 2;
|
||||
if ( i >= result )
|
||||
break;
|
||||
// v3 = this->offset_0[i]
|
||||
v3 = *(_DWORD *)(*a1 + 4 * i);
|
||||
std::string::basic_string((char *)v7, v3);
|
||||
// v3->offset_0 == night::std_v_n
|
||||
if ( std::operator==<char>((int)v7, (int)&night::std_v_n) )
|
||||
{
|
||||
// v3->offset_24
|
||||
v4 = *(void ***)(v3 + 24);
|
||||
LABEL_6:
|
||||
if ( !v4 )
|
||||
@ -18492,15 +18496,18 @@ struct _Unwind_Exception *__fastcall night::NSASTParse::top_down(int *a1)
|
||||
struct _Unwind_Exception *v16; // [esp+64h] [ebp-24h] BYREF
|
||||
void *v17[8]; // [esp+68h] [ebp-20h] BYREF
|
||||
|
||||
// this->offset_24
|
||||
lpuexcptb = (struct _Unwind_Exception *)a1[6];
|
||||
std::string::basic_string((char *)v17, (int)&night::std_v_n);
|
||||
v6 = (void **)night::NSGod::gen_girl(lpuexcptb, (int)v17);
|
||||
std::string::_M_dispose(v17);
|
||||
// this->offset_28
|
||||
while ( !night::NSToken::eof(a1[7]) )
|
||||
{
|
||||
v16 = (struct _Unwind_Exception *)night::NSASTParse::ast_expression(a1);
|
||||
std::vector<night::ns_node *>::push_back(v6, (char **)&v16);
|
||||
v7 = a1[7];
|
||||
// int v7
|
||||
v1 = *(_DWORD *)(v7 + 4);
|
||||
v5 = *(_DWORD *)(v1 + 56);
|
||||
v4 = *(_DWORD *)(v1 + 52);
|
||||
@ -18526,6 +18533,7 @@ struct _Unwind_Exception *__fastcall night::NSASTParse::top_down(int *a1)
|
||||
lpuexcpta = (struct _Unwind_Exception *)v2;
|
||||
if ( v2 )
|
||||
{
|
||||
// v2->offset_60
|
||||
if ( (unsigned __int8)std::operator!=<char>(";", (int)(v2 + 15))
|
||||
&& std::string::find((int *)lpuexcpta + 21, 10, 0) == (char *)-1 )
|
||||
{
|
||||
@ -18545,6 +18553,7 @@ struct _Unwind_Exception *__fastcall night::NSASTParse::top_down(int *a1)
|
||||
night::NSToken::next(a1[7]);
|
||||
}
|
||||
}
|
||||
// this->offset_24
|
||||
lpuexcpte = (struct _Unwind_Exception *)a1[6];
|
||||
std::string::basic_string((char *)v17, (int)&night::NS_TYPE_PROG);
|
||||
lpuexcptf = (struct _Unwind_Exception *)night::NSGod::gen_son(lpuexcpte, (int)v17);
|
||||
@ -18582,15 +18591,19 @@ unsigned __int8 **__fastcall night::NSASTParse::ast_require(int *a1)
|
||||
char v25; // [esp+78h] [ebp-30h] BYREF
|
||||
int v26[8]; // [esp+88h] [ebp-20h] BYREF
|
||||
|
||||
// this->offset_24
|
||||
v16 = (void *)a1[6];
|
||||
std::string::basic_string((char *)v26, (int)&night::std_v_n);
|
||||
v17 = (void **)night::NSGod::gen_girl(v16, (int)v26);
|
||||
std::string::_M_dispose((void **)v26);
|
||||
// this->offset_28
|
||||
v22 = night::NSToken::next(a1[7]);
|
||||
std::operator+<char>((char *)v26, (int)&night::nsv_, (int)(v22 + 15));
|
||||
std::string::operator=(v22 + 15, (int)v26);
|
||||
std::string::_M_dispose((void **)v26);
|
||||
std::vector<night::ns_node *>::push_back(v17, (char **)&v22);
|
||||
|
||||
// this->offset_24
|
||||
v10 = (void *)a1[6];
|
||||
std::string::basic_string((char *)v26, (int)&night::NS_TYPE_PUNC);
|
||||
v22 = (unsigned __int8 **)night::NSGod::gen_son(v10, (int)v26);
|
||||
@ -20575,17 +20588,17 @@ int __cdecl night::compile_ns(int a1, int a2, int a3, int a4, unsigned int *a5,
|
||||
std::string::basic_string((char *)v29, a1);
|
||||
night::NSASTParse::NSASTParse((int)v39, (int)v29, (int)v27, (int)v17);
|
||||
std::string::_M_dispose(v29);
|
||||
v29[1] = 0;
|
||||
v29[0] = &v30;
|
||||
v31 = v39;
|
||||
v29[1] = 0; // v29.offset_4
|
||||
v29[0] = &v30; // v29.offset_0 std::string缓冲区
|
||||
v31 = v39; // v29.offset_12
|
||||
v19[0] = &v20;
|
||||
v30 = 0;
|
||||
v34 = 0;
|
||||
v35 = 0;
|
||||
v36 = 0;
|
||||
v32 = 0;
|
||||
v33 = 0;
|
||||
v37 = 1;
|
||||
v30 = 0; // v29.offset_8
|
||||
v34 = 0; // v29.offset_24
|
||||
v35 = 0; // v29.offset_28
|
||||
v36 = 0; // v29.offset_32
|
||||
v32 = 0; // v29.offset_16
|
||||
v33 = 0; // v29.offset_20
|
||||
v37 = 1; // v29.offset_36
|
||||
v19[1] = 0;
|
||||
v20 = 0;
|
||||
memset(v18, 0, sizeof(v18));
|
||||
|
Loading…
x
Reference in New Issue
Block a user