Skip to content

Commit

Permalink
tools, feat: refactor gen_code.js, support Class having static meth…
Browse files Browse the repository at this point in the history
…ods/instance methods with same name. (#531)
  • Loading branch information
richardo2016 authored and xicilion committed Nov 4, 2019
1 parent f1104fb commit 5b99e7f
Show file tree
Hide file tree
Showing 64 changed files with 2,866 additions and 2,659 deletions.
7 changes: 4 additions & 3 deletions fibjs/fibjs.vcxproj
Expand Up @@ -34,6 +34,7 @@
<ClInclude Include="include\DgramSocket.h" />
<ClInclude Include="include\Digest.h" />
<ClInclude Include="include\Event.h" />
<ClInclude Include="include\EventEmitter.h" />
<ClInclude Include="include\EventInfo.h" />
<ClInclude Include="include\Fiber.h" />
<ClInclude Include="include\File.h" />
Expand Down Expand Up @@ -95,7 +96,6 @@
<ClInclude Include="include\TcpServer.h" />
<ClInclude Include="include\TextColor.h" />
<ClInclude Include="include\Timer.h" />
<ClInclude Include="include\Trigger.h" />
<ClInclude Include="include\Url.h" />
<ClInclude Include="include\Variant.h" />
<ClInclude Include="include\WebSocket.h" />
Expand Down Expand Up @@ -272,17 +272,19 @@
<ClInclude Include="include\utils.h" />
<ClInclude Include="include\v8_api.h" />
<ClInclude Include="include\version.h" />
<ClInclude Include="src\db\sql\trans.h" />
<ClInclude Include="src\db\sql\db_api.h" />
<ClInclude Include="src\gui\windows\WebView.h" />
<ClInclude Include="src\process\process_win.h" />
<ClInclude Include="src\sandbox\loaders\loaders.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\base\EventEmitter.cpp" />
<ClCompile Include="src\base\Runtime.cpp" />
<ClCompile Include="src\base\Variant.cpp" />
<ClCompile Include="src\base\acPool.cpp" />
<ClCompile Include="src\base\date.cpp" />
<ClCompile Include="src\base\date_cache.cpp" />
<ClCompile Include="src\base\events.cpp" />
<ClCompile Include="src\base\fibjs_main.cpp" />
<ClCompile Include="src\base\fuck_sym.cpp" />
<ClCompile Include="src\base\opt_tools.cpp" />
Expand All @@ -308,7 +310,6 @@
<ClCompile Include="src\coroutine\Fiber.cpp" />
<ClCompile Include="src\coroutine\Lock.cpp" />
<ClCompile Include="src\coroutine\Semaphore.cpp" />
<ClCompile Include="src\coroutine\Trigger.cpp" />
<ClCompile Include="src\coroutine\Worker.cpp" />
<ClCompile Include="src\coroutine\WorkerMessage.cpp" />
<ClCompile Include="src\coroutine\coroutine.cpp" />
Expand Down
17 changes: 10 additions & 7 deletions fibjs/fibjs.vcxproj.filters
Expand Up @@ -162,6 +162,9 @@
<ClInclude Include="include\Event.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\EventEmitter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\EventInfo.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -345,9 +348,6 @@
<ClInclude Include="include\Timer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Trigger.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\Url.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -876,7 +876,7 @@
<ClInclude Include="include\version.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\db\sql\trans.h">
<ClInclude Include="src\db\sql\db_api.h">
<Filter>Source Files\db\sql</Filter>
</ClInclude>
<ClInclude Include="src\gui\windows\WebView.h">
Expand All @@ -890,6 +890,9 @@
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\base\EventEmitter.cpp">
<Filter>Source Files\base</Filter>
</ClCompile>
<ClCompile Include="src\base\Runtime.cpp">
<Filter>Source Files\base</Filter>
</ClCompile>
Expand All @@ -905,6 +908,9 @@
<ClCompile Include="src\base\date_cache.cpp">
<Filter>Source Files\base</Filter>
</ClCompile>
<ClCompile Include="src\base\events.cpp">
<Filter>Source Files\base</Filter>
</ClCompile>
<ClCompile Include="src\base\fibjs_main.cpp">
<Filter>Source Files\base</Filter>
</ClCompile>
Expand Down Expand Up @@ -980,9 +986,6 @@
<ClCompile Include="src\coroutine\Semaphore.cpp">
<Filter>Source Files\coroutine</Filter>
</ClCompile>
<ClCompile Include="src\coroutine\Trigger.cpp">
<Filter>Source Files\coroutine</Filter>
</ClCompile>
<ClCompile Include="src\coroutine\Worker.cpp">
<Filter>Source Files\coroutine</Filter>
</ClCompile>
Expand Down
12 changes: 7 additions & 5 deletions fibjs/include/ClassInfo.h
Expand Up @@ -336,8 +336,9 @@ class ClassInfo {
int32_t i;

for (i = 0; i < m_cd.mc; i++)
pt->Set(isolate->NewString(m_cd.cms[i].name),
v8::FunctionTemplate::New(isolate->m_isolate, m_cd.cms[i].invoker));
if (!m_cd.cms[i].is_static)
pt->Set(isolate->NewString(m_cd.cms[i].name),
v8::FunctionTemplate::New(isolate->m_isolate, m_cd.cms[i].invoker));

for (i = 0; i < m_cd.oc; i++) {
cache* _cache1 = m_cd.cos[i].invoker()._init(isolate);
Expand All @@ -346,9 +347,10 @@ class ClassInfo {
}

for (i = 0; i < m_cd.pc; i++)
pt->SetAccessor(isolate->NewString(m_cd.cps[i].name),
m_cd.cps[i].getter, m_cd.cps[i].setter,
v8::Local<v8::Value>(), v8::DEFAULT, v8::DontDelete);
if (!m_cd.cps[i].is_static)
pt->SetAccessor(isolate->NewString(m_cd.cps[i].name),
m_cd.cps[i].getter, m_cd.cps[i].setter,
v8::Local<v8::Value>(), v8::DEFAULT, v8::DontDelete);

for (i = 0; i < m_cd.cc; i++) {
pt->Set(isolate->NewString(m_cd.ccs[i].name),
Expand Down
3 changes: 3 additions & 0 deletions fibjs/include/Trigger.h → fibjs/include/EventEmitter.h
Expand Up @@ -9,6 +9,9 @@
#define EVENT_H_

#include "ifs/EventEmitter.h"
#include "Fiber.h"
#include "ifs/coroutine.h"
#include "QuickArray.h"

namespace fibjs {

Expand Down
108 changes: 64 additions & 44 deletions fibjs/include/ifs/Buffer.h
Expand Up @@ -42,6 +42,8 @@ class Buffer_base : public object_base {
static result_t byteLength(v8::Local<v8::ArrayBuffer> str, exlib::string codec, int32_t& retVal);
static result_t byteLength(v8::Local<v8::ArrayBufferView> str, exlib::string codec, int32_t& retVal);
static result_t byteLength(Buffer_base* str, exlib::string codec, int32_t& retVal);
static result_t compare(Buffer_base* buf1, Buffer_base* buf2, int32_t& retVal);
virtual result_t compare(Buffer_base* buf, int32_t& retVal) = 0;
static result_t isEncoding(exlib::string codec, bool& retVal);
virtual result_t _indexed_getter(uint32_t index, int32_t& retVal) = 0;
virtual result_t _indexed_setter(uint32_t index, int32_t newVal) = 0;
Expand All @@ -58,7 +60,6 @@ class Buffer_base : public object_base {
virtual result_t indexOf(int32_t v, int32_t offset, int32_t& retVal) = 0;
virtual result_t indexOf(Buffer_base* v, int32_t offset, int32_t& retVal) = 0;
virtual result_t indexOf(exlib::string v, int32_t offset, int32_t& retVal) = 0;
virtual result_t compare(Buffer_base* buf, int32_t& retVal) = 0;
virtual result_t copy(Buffer_base* targetBuffer, int32_t targetStart, int32_t sourceStart, int32_t sourceEnd, int32_t& retVal) = 0;
virtual result_t readUInt8(int32_t offset, bool noAssert, int32_t& retVal) = 0;
virtual result_t readUInt16LE(int32_t offset, bool noAssert, int32_t& retVal) = 0;
Expand Down Expand Up @@ -121,14 +122,16 @@ class Buffer_base : public object_base {

public:
static void s__new(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_isBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_from(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_concat(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_alloc(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_allocUnsafe(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_allocUnsafeSlow(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_byteLength(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_isEncoding(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_static_isBuffer(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_static_from(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_static_concat(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_static_alloc(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_static_allocUnsafe(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_static_allocUnsafeSlow(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_static_byteLength(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_static_compare(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_compare(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_static_isEncoding(const v8::FunctionCallbackInfo<v8::Value>& args);
static void i_IndexedGetter(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& args);
static void i_IndexedSetter(uint32_t index, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_length(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args);
Expand All @@ -137,7 +140,6 @@ class Buffer_base : public object_base {
static void s_write(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_fill(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_indexOf(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_compare(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_copy(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_readUInt8(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_readUInt16LE(const v8::FunctionCallbackInfo<v8::Value>& args);
Expand Down Expand Up @@ -197,20 +199,21 @@ namespace fibjs {
inline ClassInfo& Buffer_base::class_info()
{
static ClassData::ClassMethod s_method[] = {
{ "isBuffer", s_isBuffer, true },
{ "from", s_from, true },
{ "concat", s_concat, true },
{ "alloc", s_alloc, true },
{ "allocUnsafe", s_allocUnsafe, true },
{ "allocUnsafeSlow", s_allocUnsafeSlow, true },
{ "byteLength", s_byteLength, true },
{ "isEncoding", s_isEncoding, true },
{ "isBuffer", s_static_isBuffer, true },
{ "from", s_static_from, true },
{ "concat", s_static_concat, true },
{ "alloc", s_static_alloc, true },
{ "allocUnsafe", s_static_allocUnsafe, true },
{ "allocUnsafeSlow", s_static_allocUnsafeSlow, true },
{ "byteLength", s_static_byteLength, true },
{ "compare", s_compare, false },
{ "compare", s_static_compare, true },
{ "isEncoding", s_static_isEncoding, true },
{ "resize", s_resize, false },
{ "append", s_append, false },
{ "write", s_write, false },
{ "fill", s_fill, false },
{ "indexOf", s_indexOf, false },
{ "compare", s_compare, false },
{ "copy", s_copy, false },
{ "readUInt8", s_readUInt8, false },
{ "readUInt16LE", s_readUInt16LE, false },
Expand Down Expand Up @@ -343,7 +346,7 @@ void Buffer_base::__new(const T& args)
CONSTRUCT_RETURN();
}

inline void Buffer_base::s_isBuffer(const v8::FunctionCallbackInfo<v8::Value>& args)
inline void Buffer_base::s_static_isBuffer(const v8::FunctionCallbackInfo<v8::Value>& args)
{
bool vr;

Expand All @@ -359,7 +362,7 @@ inline void Buffer_base::s_isBuffer(const v8::FunctionCallbackInfo<v8::Value>& a
METHOD_RETURN();
}

inline void Buffer_base::s_from(const v8::FunctionCallbackInfo<v8::Value>& args)
inline void Buffer_base::s_static_from(const v8::FunctionCallbackInfo<v8::Value>& args)
{
obj_ptr<Buffer_base> vr;

Expand Down Expand Up @@ -392,7 +395,7 @@ inline void Buffer_base::s_from(const v8::FunctionCallbackInfo<v8::Value>& args)
METHOD_RETURN();
}

inline void Buffer_base::s_concat(const v8::FunctionCallbackInfo<v8::Value>& args)
inline void Buffer_base::s_static_concat(const v8::FunctionCallbackInfo<v8::Value>& args)
{
obj_ptr<Buffer_base> vr;

Expand All @@ -409,7 +412,7 @@ inline void Buffer_base::s_concat(const v8::FunctionCallbackInfo<v8::Value>& arg
METHOD_RETURN();
}

inline void Buffer_base::s_alloc(const v8::FunctionCallbackInfo<v8::Value>& args)
inline void Buffer_base::s_static_alloc(const v8::FunctionCallbackInfo<v8::Value>& args)
{
obj_ptr<Buffer_base> vr;

Expand Down Expand Up @@ -443,7 +446,7 @@ inline void Buffer_base::s_alloc(const v8::FunctionCallbackInfo<v8::Value>& args
METHOD_RETURN();
}

inline void Buffer_base::s_allocUnsafe(const v8::FunctionCallbackInfo<v8::Value>& args)
inline void Buffer_base::s_static_allocUnsafe(const v8::FunctionCallbackInfo<v8::Value>& args)
{
obj_ptr<Buffer_base> vr;

Expand All @@ -459,7 +462,7 @@ inline void Buffer_base::s_allocUnsafe(const v8::FunctionCallbackInfo<v8::Value>
METHOD_RETURN();
}

inline void Buffer_base::s_allocUnsafeSlow(const v8::FunctionCallbackInfo<v8::Value>& args)
inline void Buffer_base::s_static_allocUnsafeSlow(const v8::FunctionCallbackInfo<v8::Value>& args)
{
obj_ptr<Buffer_base> vr;

Expand All @@ -475,7 +478,7 @@ inline void Buffer_base::s_allocUnsafeSlow(const v8::FunctionCallbackInfo<v8::Va
METHOD_RETURN();
}

inline void Buffer_base::s_byteLength(const v8::FunctionCallbackInfo<v8::Value>& args)
inline void Buffer_base::s_static_byteLength(const v8::FunctionCallbackInfo<v8::Value>& args)
{
int32_t vr;

Expand Down Expand Up @@ -513,7 +516,41 @@ inline void Buffer_base::s_byteLength(const v8::FunctionCallbackInfo<v8::Value>&
METHOD_RETURN();
}

inline void Buffer_base::s_isEncoding(const v8::FunctionCallbackInfo<v8::Value>& args)
inline void Buffer_base::s_static_compare(const v8::FunctionCallbackInfo<v8::Value>& args)
{
int32_t vr;

METHOD_NAME("Buffer.compare");
METHOD_ENTER();

METHOD_OVER(2, 2);

ARG(obj_ptr<Buffer_base>, 0);
ARG(obj_ptr<Buffer_base>, 1);

hr = compare(v0, v1, vr);

METHOD_RETURN();
}

inline void Buffer_base::s_compare(const v8::FunctionCallbackInfo<v8::Value>& args)
{
int32_t vr;

METHOD_NAME("Buffer.compare");
METHOD_INSTANCE(Buffer_base);
METHOD_ENTER();

METHOD_OVER(1, 1);

ARG(obj_ptr<Buffer_base>, 0);

hr = pInst->compare(v0, vr);

METHOD_RETURN();
}

inline void Buffer_base::s_static_isEncoding(const v8::FunctionCallbackInfo<v8::Value>& args)
{
bool vr;

Expand Down Expand Up @@ -708,23 +745,6 @@ inline void Buffer_base::s_indexOf(const v8::FunctionCallbackInfo<v8::Value>& ar
METHOD_RETURN();
}

inline void Buffer_base::s_compare(const v8::FunctionCallbackInfo<v8::Value>& args)
{
int32_t vr;

METHOD_NAME("Buffer.compare");
METHOD_INSTANCE(Buffer_base);
METHOD_ENTER();

METHOD_OVER(1, 1);

ARG(obj_ptr<Buffer_base>, 0);

hr = pInst->compare(v0, vr);

METHOD_RETURN();
}

inline void Buffer_base::s_copy(const v8::FunctionCallbackInfo<v8::Value>& args)
{
int32_t vr;
Expand Down
10 changes: 5 additions & 5 deletions fibjs/include/ifs/EventEmitter.h
Expand Up @@ -54,8 +54,8 @@ class EventEmitter_base : public object_base {

public:
static void s__new(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_get_defaultMaxListeners(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_set_defaultMaxListeners(v8::Local<v8::Name> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args);
static void s_static_get_defaultMaxListeners(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_static_set_defaultMaxListeners(v8::Local<v8::Name> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args);
static void s_on(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_addListener(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_prependListener(const v8::FunctionCallbackInfo<v8::Value>& args);
Expand Down Expand Up @@ -94,7 +94,7 @@ inline ClassInfo& EventEmitter_base::class_info()
};

static ClassData::ClassProperty s_property[] = {
{ "defaultMaxListeners", s_get_defaultMaxListeners, s_set_defaultMaxListeners, true }
{ "defaultMaxListeners", s_static_get_defaultMaxListeners, s_static_set_defaultMaxListeners, true }
};

static ClassData s_cd = {
Expand Down Expand Up @@ -128,7 +128,7 @@ void EventEmitter_base::__new(const T& args)
CONSTRUCT_RETURN();
}

inline void EventEmitter_base::s_get_defaultMaxListeners(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args)
inline void EventEmitter_base::s_static_get_defaultMaxListeners(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
int32_t vr;

Expand All @@ -140,7 +140,7 @@ inline void EventEmitter_base::s_get_defaultMaxListeners(v8::Local<v8::Name> pro
METHOD_RETURN();
}

inline void EventEmitter_base::s_set_defaultMaxListeners(v8::Local<v8::Name> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args)
inline void EventEmitter_base::s_static_set_defaultMaxListeners(v8::Local<v8::Name> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args)
{
METHOD_NAME("EventEmitter.defaultMaxListeners");
PROPERTY_ENTER();
Expand Down

0 comments on commit 5b99e7f

Please sign in to comment.