Beautified Javascript module.
This commit is contained in:
parent
b5bc87667d
commit
89610e984e
1 changed files with 266 additions and 308 deletions
|
|
@ -303,9 +303,8 @@ class JAVASCRIPT:public Language {
|
|||
|
||||
public:
|
||||
|
||||
JAVASCRIPT(): emitter(NULL) {}
|
||||
|
||||
~JAVASCRIPT() {
|
||||
JAVASCRIPT():emitter(NULL) {
|
||||
} ~JAVASCRIPT() {
|
||||
delete emitter;
|
||||
}
|
||||
|
||||
|
|
@ -591,12 +590,7 @@ extern "C" Language *swig_javascript(void) {
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
JSEmitter::JSEmitter()
|
||||
: templates(NewHash()),
|
||||
namespaces(NULL),
|
||||
current_namespace(NULL),
|
||||
defaultResultName(NewString("result")),
|
||||
f_wrappers(NULL)
|
||||
{
|
||||
: templates(NewHash()), namespaces(NULL), current_namespace(NULL), defaultResultName(NewString("result")), f_wrappers(NULL) {
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
@ -810,7 +804,6 @@ int JSEmitter::enterVariable(Node *n) {
|
|||
if (!Language::instance()->is_assignable(n)) {
|
||||
SetFlag(state.variable(), IS_IMMUTABLE);
|
||||
}
|
||||
|
||||
// FIXME: test "arrays_global" does not compile with that as it is not allowed to assign to char[]
|
||||
if (Equal(Getattr(n, "type"), "a().char")) {
|
||||
SetFlag(state.variable(), IS_IMMUTABLE);
|
||||
|
|
@ -933,7 +926,6 @@ int JSEmitter::emitDtor(Node *n) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// HACK: this is only for the v8 emitter. maybe set an attribute wrap:action of node
|
||||
// TODO: generate dtors more similar to other wrappers
|
||||
// EW: I think this is wrong. delete should only be used when new was used to create. If malloc was used, free needs to be used.
|
||||
|
|
@ -995,8 +987,7 @@ int JSEmitter::emitDtor(Node *n) {
|
|||
|
||||
t_dtor.replace("${destructor_action}", destructor_action);
|
||||
Wrapper_pretty_print(t_dtor.str(), f_wrappers);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Template t_dtor = getTemplate("js_dtor");
|
||||
state.clazz(DTOR, wrap_name);
|
||||
t_dtor.replace("$jsmangledname", state.clazz(NAME_MANGLED))
|
||||
|
|
@ -1197,8 +1188,7 @@ int JSEmitter::emitFunctionDispatcher(Node *n, bool /*is_member */ ) {
|
|||
do {
|
||||
String *siblname = Getattr(sibl, "wrap:name");
|
||||
|
||||
if (siblname)
|
||||
{
|
||||
if (siblname) {
|
||||
// handle function overloading
|
||||
Template t_dispatch_case = getTemplate("js_function_dispatch_case");
|
||||
t_dispatch_case.replace("$jswrapper", siblname)
|
||||
|
|
@ -1267,9 +1257,11 @@ void JSEmitter::marshalOutput(Node *n, ParmList *params, Wrapper *wrapper, Strin
|
|||
Parm *p;
|
||||
|
||||
// adds a declaration for the result variable
|
||||
if(emitReturnVariable) emit_return_variable(n, type, wrapper);
|
||||
if (emitReturnVariable)
|
||||
emit_return_variable(n, type, wrapper);
|
||||
// if not given, use default result identifier ('result') for output typemap
|
||||
if(cresult == 0) cresult = defaultResultName;
|
||||
if (cresult == 0)
|
||||
cresult = defaultResultName;
|
||||
|
||||
tm = Swig_typemap_lookup_out("out", n, cresult, wrapper, actioncode);
|
||||
bool should_own = GetFlag(n, "feature:new");
|
||||
|
|
@ -1457,14 +1449,7 @@ private:
|
|||
};
|
||||
|
||||
JSCEmitter::JSCEmitter()
|
||||
: JSEmitter(),
|
||||
NULL_STR(NewString("NULL")),
|
||||
VETO_SET(NewString("JS_veto_set_variable")),
|
||||
f_wrap_cpp(NULL),
|
||||
f_runtime(NULL),
|
||||
f_header(NULL),
|
||||
f_init(NULL)
|
||||
{
|
||||
: JSEmitter(), NULL_STR(NewString("NULL")), VETO_SET(NewString("JS_veto_set_variable")), f_wrap_cpp(NULL), f_runtime(NULL), f_header(NULL), f_init(NULL) {
|
||||
}
|
||||
|
||||
JSCEmitter::~JSCEmitter() {
|
||||
|
|
@ -1491,7 +1476,6 @@ void JSCEmitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Ma
|
|||
if (is_member && !is_static && mode != Ctor) {
|
||||
startIdx = 1;
|
||||
}
|
||||
|
||||
// store number of arguments for argument checks
|
||||
int num_args = emit_num_arguments(parms) - startIdx;
|
||||
String *argcount = NewString("");
|
||||
|
|
@ -1860,20 +1844,15 @@ private:
|
|||
};
|
||||
|
||||
V8Emitter::V8Emitter()
|
||||
: JSEmitter(),
|
||||
NULL_STR(NewString("0")),
|
||||
VETO_SET(NewString("JS_veto_set_variable"))
|
||||
{
|
||||
: JSEmitter(), NULL_STR(NewString("0")), VETO_SET(NewString("JS_veto_set_variable")) {
|
||||
}
|
||||
|
||||
V8Emitter::~V8Emitter()
|
||||
{
|
||||
V8Emitter::~V8Emitter() {
|
||||
Delete(NULL_STR);
|
||||
Delete(VETO_SET);
|
||||
}
|
||||
|
||||
int V8Emitter::initialize(Node *n)
|
||||
{
|
||||
int V8Emitter::initialize(Node *n) {
|
||||
JSEmitter::initialize(n);
|
||||
|
||||
moduleName = Getattr(n, "name");
|
||||
|
|
@ -1912,8 +1891,7 @@ int V8Emitter::initialize(Node *n)
|
|||
return SWIG_OK;
|
||||
}
|
||||
|
||||
int V8Emitter::dump(Node *n)
|
||||
{
|
||||
int V8Emitter::dump(Node *n) {
|
||||
/* Get the module name */
|
||||
String *module = Getattr(n, "name");
|
||||
|
||||
|
|
@ -1953,8 +1931,7 @@ int V8Emitter::dump(Node *n)
|
|||
return SWIG_OK;
|
||||
}
|
||||
|
||||
int V8Emitter::close()
|
||||
{
|
||||
int V8Emitter::close() {
|
||||
Delete(f_runtime);
|
||||
Delete(f_header);
|
||||
Delete(f_class_templates);
|
||||
|
|
@ -1972,8 +1949,7 @@ int V8Emitter::close()
|
|||
return SWIG_OK;
|
||||
}
|
||||
|
||||
int V8Emitter::enterClass(Node *n)
|
||||
{
|
||||
int V8Emitter::enterClass(Node *n) {
|
||||
JSEmitter::enterClass(n);
|
||||
|
||||
// emit declaration of a v8 class template
|
||||
|
|
@ -1985,8 +1961,7 @@ int V8Emitter::enterClass(Node *n)
|
|||
return SWIG_OK;
|
||||
}
|
||||
|
||||
int V8Emitter::exitClass(Node *n)
|
||||
{
|
||||
int V8Emitter::exitClass(Node *n) {
|
||||
if (GetFlag(state.clazz(), IS_ABSTRACT)) {
|
||||
Template t_veto_ctor(getTemplate("js_veto_ctor"));
|
||||
t_veto_ctor.replace("$jswrapper", state.clazz(CTOR))
|
||||
|
|
@ -2031,7 +2006,6 @@ int V8Emitter::exitClass(Node *n)
|
|||
.pretty_print(f_init_inheritance);
|
||||
Delete(base_name_mangled);
|
||||
}
|
||||
|
||||
// emit registeration of class template
|
||||
Template t_register = getTemplate("jsv8_register_class");
|
||||
t_register.replace("$jsmangledname", state.clazz(NAME_MANGLED))
|
||||
|
|
@ -2043,8 +2017,7 @@ int V8Emitter::exitClass(Node *n)
|
|||
return SWIG_OK;
|
||||
}
|
||||
|
||||
int V8Emitter::enterVariable(Node* n)
|
||||
{
|
||||
int V8Emitter::enterVariable(Node *n) {
|
||||
JSEmitter::enterVariable(n);
|
||||
|
||||
state.variable(GETTER, NULL_STR);
|
||||
|
|
@ -2053,8 +2026,7 @@ int V8Emitter::enterVariable(Node* n)
|
|||
return SWIG_OK;
|
||||
}
|
||||
|
||||
int V8Emitter::exitVariable(Node* n)
|
||||
{
|
||||
int V8Emitter::exitVariable(Node *n) {
|
||||
if (GetFlag(n, "ismember")) {
|
||||
if (GetFlag(state.variable(), IS_STATIC) || Equal(Getattr(n, "nodeType"), "enumitem")) {
|
||||
Template t_register = getTemplate("jsv8_register_static_variable");
|
||||
|
|
@ -2062,8 +2034,7 @@ int V8Emitter::exitVariable(Node* n)
|
|||
.replace("$jsname", state.variable(NAME))
|
||||
.replace("$jsgetter", state.variable(GETTER))
|
||||
.replace("$jssetter", state.variable(SETTER))
|
||||
.trim().
|
||||
print(f_init_static_wrappers);
|
||||
.trim().print(f_init_static_wrappers);
|
||||
} else {
|
||||
Template t_register = getTemplate("jsv8_register_member_variable");
|
||||
t_register.replace("$jsmangledname", state.clazz(NAME_MANGLED))
|
||||
|
|
@ -2088,8 +2059,7 @@ int V8Emitter::exitVariable(Node* n)
|
|||
return SWIG_OK;
|
||||
}
|
||||
|
||||
int V8Emitter::exitFunction(Node* n)
|
||||
{
|
||||
int V8Emitter::exitFunction(Node *n) {
|
||||
bool is_member = GetFlag(n, "ismember") | GetFlag(n, "feature:extend");
|
||||
|
||||
// create a dispatcher for overloaded functions
|
||||
|
|
@ -2103,7 +2073,6 @@ int V8Emitter::exitFunction(Node* n)
|
|||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// register the function at the specific context
|
||||
if (is_member) {
|
||||
if (GetFlag(state.function(), IS_STATIC)) {
|
||||
|
|
@ -2143,7 +2112,6 @@ void V8Emitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, Mar
|
|||
if (is_member && !is_static && mode != Ctor) {
|
||||
startIdx = 1;
|
||||
}
|
||||
|
||||
// store number of arguments for argument checks
|
||||
int num_args = emit_num_arguments(parms) - startIdx;
|
||||
String *argcount = NewString("");
|
||||
|
|
@ -2214,7 +2182,6 @@ int V8Emitter::emitNamespaces() {
|
|||
if (Equal(parent, "")) {
|
||||
do_register = false;
|
||||
}
|
||||
|
||||
// Note: 'exports' is by convention the name of the object where
|
||||
// globals are stored into
|
||||
if (Equal(name, "exports")) {
|
||||
|
|
@ -2254,21 +2221,18 @@ JSEmitter *swig_javascript_create_V8Emitter() {
|
|||
**********************************************************************/
|
||||
|
||||
JSEmitterState::JSEmitterState()
|
||||
: _global(NewHash())
|
||||
{
|
||||
: _global(NewHash()) {
|
||||
// initialize sub-hashes
|
||||
Setattr(_global, "class", NewHash());
|
||||
Setattr(_global, "function", NewHash());
|
||||
Setattr(_global, "variable", NewHash());
|
||||
}
|
||||
|
||||
JSEmitterState::~JSEmitterState()
|
||||
{
|
||||
JSEmitterState::~JSEmitterState() {
|
||||
Delete(_global);
|
||||
}
|
||||
|
||||
DOH *JSEmitterState::getState(const char* key, bool _new)
|
||||
{
|
||||
DOH *JSEmitterState::getState(const char *key, bool _new) {
|
||||
if (_new) {
|
||||
Hash *hash = NewHash();
|
||||
Setattr(_global, key, hash);
|
||||
|
|
@ -2280,21 +2244,18 @@ DOH *JSEmitterState::global() {
|
|||
return _global;
|
||||
}
|
||||
|
||||
DOH *JSEmitterState::global(const char* key, DOH *initial)
|
||||
{
|
||||
DOH *JSEmitterState::global (const char *key, DOH *initial) {
|
||||
if (initial != 0) {
|
||||
Setattr(_global, key, initial);
|
||||
}
|
||||
return Getattr(_global, key);
|
||||
}
|
||||
|
||||
DOH *JSEmitterState::clazz(bool _new)
|
||||
{
|
||||
DOH *JSEmitterState::clazz(bool _new) {
|
||||
return getState("class", _new);
|
||||
}
|
||||
|
||||
DOH *JSEmitterState::clazz(const char* key, DOH *initial)
|
||||
{
|
||||
DOH *JSEmitterState::clazz(const char *key, DOH *initial) {
|
||||
DOH *c = clazz();
|
||||
if (initial != 0) {
|
||||
Setattr(c, key, initial);
|
||||
|
|
@ -2302,13 +2263,11 @@ DOH *JSEmitterState::clazz(const char* key, DOH *initial)
|
|||
return Getattr(c, key);
|
||||
}
|
||||
|
||||
DOH *JSEmitterState::function(bool _new)
|
||||
{
|
||||
DOH *JSEmitterState::function(bool _new) {
|
||||
return getState("function", _new);
|
||||
}
|
||||
|
||||
DOH *JSEmitterState::function(const char* key, DOH *initial)
|
||||
{
|
||||
DOH *JSEmitterState::function(const char *key, DOH *initial) {
|
||||
DOH *f = function();
|
||||
if (initial != 0) {
|
||||
Setattr(f, key, initial);
|
||||
|
|
@ -2316,13 +2275,11 @@ DOH *JSEmitterState::function(const char* key, DOH *initial)
|
|||
return Getattr(f, key);
|
||||
}
|
||||
|
||||
DOH *JSEmitterState::variable(bool _new)
|
||||
{
|
||||
DOH *JSEmitterState::variable(bool _new) {
|
||||
return getState("variable", _new);
|
||||
}
|
||||
|
||||
DOH *JSEmitterState::variable(const char* key, DOH *initial)
|
||||
{
|
||||
DOH *JSEmitterState::variable(const char *key, DOH *initial) {
|
||||
DOH *v = variable();
|
||||
if (initial != 0) {
|
||||
Setattr(v, key, initial);
|
||||
|
|
@ -2331,8 +2288,7 @@ DOH *JSEmitterState::variable(const char* key, DOH *initial)
|
|||
}
|
||||
|
||||
/*static*/
|
||||
int JSEmitterState::IsSet(DOH *val)
|
||||
{
|
||||
int JSEmitterState::IsSet(DOH *val) {
|
||||
if (!val) {
|
||||
return 0;
|
||||
} else {
|
||||
|
|
@ -2402,10 +2358,12 @@ String *Template::str() {
|
|||
|
||||
Template & Template::trim() {
|
||||
const char *str = Char(code);
|
||||
if (str == 0) return *this;
|
||||
if (str == 0)
|
||||
return *this;
|
||||
|
||||
int length = Len(code);
|
||||
if (length == 0) return *this;
|
||||
if (length == 0)
|
||||
return *this;
|
||||
|
||||
int idx;
|
||||
for (idx = 0; idx < length; ++idx) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue