Cosmetic code changes in javascript.cxx

This commit is contained in:
William S Fulton 2014-04-24 20:54:16 +01:00
commit a5e91f26a1

View file

@ -17,7 +17,7 @@
/** /**
* Enables extra debugging information in typemaps. * Enables extra debugging information in typemaps.
*/ */
bool js_template_enable_debug = false; static bool js_template_enable_debug = false;
// keywords used for state variables // keywords used for state variables
#define NAME "name" #define NAME "name"
@ -54,39 +54,26 @@ bool js_template_enable_debug = false;
/** /**
* A convenience class to manage state variables for emitters. * A convenience class to manage state variables for emitters.
* The implementation delegates to swig Hash DOHs and provides * The implementation delegates to SWIG Hash DOHs and provides
* named sub-hashes for class, variable, and function states. * named sub-hashes for class, variable, and function states.
*/ */
class JSEmitterState { class JSEmitterState {
public: public:
JSEmitterState(); JSEmitterState();
~JSEmitterState(); ~JSEmitterState();
DOH *global(); DOH *global();
DOH *global(const char *key, DOH *initial = 0); DOH *global(const char *key, DOH *initial = 0);
DOH *clazz(bool reset = false); DOH *clazz(bool reset = false);
DOH *clazz(const char *key, DOH *initial = 0); DOH *clazz(const char *key, DOH *initial = 0);
DOH *function(bool reset = false); DOH *function(bool reset = false);
DOH *function(const char *key, DOH *initial = 0); DOH *function(const char *key, DOH *initial = 0);
DOH *variable(bool reset = false); DOH *variable(bool reset = false);
DOH *variable(const char *key, DOH *initial = 0); DOH *variable(const char *key, DOH *initial = 0);
static int IsSet(DOH *val); static int IsSet(DOH *val);
private: private:
DOH *getState(const char *key, bool reset = false); DOH *getState(const char *key, bool reset = false);
Hash *_global; Hash *_global;
}; };
@ -98,30 +85,19 @@ class Template {
public: public:
Template(const String *code); Template(const String *code);
Template(const String *code, const String *templateName); Template(const String *code, const String *templateName);
Template(const Template & other); Template(const Template & other);
~Template(); ~Template();
String *str(); String *str();
Template & replace(const String *pattern, const String *repl); Template & replace(const String *pattern, const String *repl);
Template & print(DOH *doh); Template & print(DOH *doh);
Template & pretty_print(DOH *doh); Template & pretty_print(DOH *doh);
void operator=(const Template & t); void operator=(const Template & t);
Template & trim(); Template & trim();
private: private:
String *code; String *code;
String *templateName; String *templateName;
}; };
/** /**
@ -311,7 +287,7 @@ JSEmitter *swig_javascript_create_JSCEmitter();
JSEmitter *swig_javascript_create_V8Emitter(); JSEmitter *swig_javascript_create_V8Emitter();
/********************************************************************** /**********************************************************************
* JAVASCRIPT: swig module implementation * JAVASCRIPT: SWIG module implementation
**********************************************************************/ **********************************************************************/
class JAVASCRIPT:public Language { class JAVASCRIPT:public Language {
@ -319,7 +295,8 @@ class JAVASCRIPT:public Language {
public: public:
JAVASCRIPT():emitter(NULL) { JAVASCRIPT():emitter(NULL) {
} ~JAVASCRIPT() { }
~JAVASCRIPT() {
delete emitter; delete emitter;
} }
@ -511,7 +488,7 @@ Javascript Options (available with -javascript)\n\
-jsc - creates a JavascriptCore extension \n\ -jsc - creates a JavascriptCore extension \n\
-v8 - creates a v8 extension \n\ -v8 - creates a v8 extension \n\
-node - creates a node.js extension \n\ -node - creates a node.js extension \n\
-debug-codetemplates - generates information about the origin of code templates.\n"; -debug-codetemplates - generates information about the origin of code templates\n";
/* --------------------------------------------------------------------- /* ---------------------------------------------------------------------
@ -910,7 +887,7 @@ int JSEmitter::emitDtor(Node *n) {
// (Taken from JSCore implementation.) // (Taken from JSCore implementation.)
/* The if (Extend) block was taken from the Ruby implementation. /* The if (Extend) block was taken from the Ruby implementation.
* The problem is that in the case of an %extend to create a destructor for a struct to coordinate automatic memory cleanup with the Javascript collector, * The problem is that in the case of an %extend to create a destructor for a struct to coordinate automatic memory cleanup with the Javascript collector,
* the swig function was not being generated. More specifically: * the SWIG function was not being generated. More specifically:
struct MyData { struct MyData {
%extend { %extend {
~MyData() { ~MyData() {
@ -1427,36 +1404,21 @@ Hash *JSEmitter::createNamespaceEntry(const char *_name, const char *parent) {
class JSCEmitter:public JSEmitter { class JSCEmitter:public JSEmitter {
public: public:
JSCEmitter(); JSCEmitter();
virtual ~ JSCEmitter(); virtual ~ JSCEmitter();
virtual int initialize(Node *n); virtual int initialize(Node *n);
virtual int dump(Node *n); virtual int dump(Node *n);
virtual int close(); virtual int close();
protected: protected:
virtual int enterVariable(Node *n); virtual int enterVariable(Node *n);
virtual int exitVariable(Node *n); virtual int exitVariable(Node *n);
virtual int enterFunction(Node *n); virtual int enterFunction(Node *n);
virtual int exitFunction(Node *n); virtual int exitFunction(Node *n);
virtual int enterClass(Node *n); virtual int enterClass(Node *n);
virtual int exitClass(Node *n); virtual int exitClass(Node *n);
virtual void marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, MarshallingMode mode, bool is_member, bool is_static); virtual void marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, MarshallingMode mode, bool is_member, bool is_static);
virtual Hash *createNamespaceEntry(const char *name, const char *parent); virtual Hash *createNamespaceEntry(const char *name, const char *parent);
virtual int emitNamespaces(); virtual int emitNamespaces();
private: private:
@ -1585,7 +1547,7 @@ int JSCEmitter::dump(Node *n) {
/* Get the module name */ /* Get the module name */
String *module = Getattr(n, "name"); String *module = Getattr(n, "name");
// write the swig banner // write the SWIG banner
Swig_banner(f_wrap_cpp); Swig_banner(f_wrap_cpp);
Template initializer_define(getTemplate("js_initializer_define")); Template initializer_define(getTemplate("js_initializer_define"));
@ -1670,7 +1632,6 @@ int JSCEmitter::enterVariable(Node *n) {
return SWIG_OK; return SWIG_OK;
} }
int JSCEmitter::exitVariable(Node *n) { int JSCEmitter::exitVariable(Node *n) {
Template t_variable(getTemplate("jsc_variable_declaration")); Template t_variable(getTemplate("jsc_variable_declaration"));
t_variable.replace("$jsname", state.variable(NAME)) t_variable.replace("$jsname", state.variable(NAME))
@ -1802,7 +1763,6 @@ int JSCEmitter::emitNamespaces() {
.replace("$jsparent", parent_mangled); .replace("$jsparent", parent_mangled);
Append(state.global(REGISTER_NAMESPACES), t_registerNamespace.str()); Append(state.global(REGISTER_NAMESPACES), t_registerNamespace.str());
} }
} }
return SWIG_OK; return SWIG_OK;
@ -1819,7 +1779,6 @@ JSEmitter *swig_javascript_create_JSCEmitter() {
class V8Emitter:public JSEmitter { class V8Emitter:public JSEmitter {
public: public:
V8Emitter(); V8Emitter();
virtual ~ V8Emitter(); virtual ~ V8Emitter();
@ -1833,12 +1792,10 @@ public:
virtual int exitFunction(Node *n); virtual int exitFunction(Node *n);
protected: protected:
virtual void marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, MarshallingMode mode, bool is_member, bool is_static); virtual void marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, MarshallingMode mode, bool is_member, bool is_static);
virtual int emitNamespaces(); virtual int emitNamespaces();
private: private:
/* built-in parts */ /* built-in parts */
String *f_runtime; String *f_runtime;
String *f_header; String *f_header;
@ -1904,7 +1861,7 @@ int V8Emitter::initialize(Node *n) {
f_init_register_classes = NewString(""); f_init_register_classes = NewString("");
f_init_register_namespaces = NewString(""); f_init_register_namespaces = NewString("");
// note: this is necessary for built-in generation of swig runtime code // note: this is necessary for built-in generation of SWIG runtime code
Swig_register_filebyname("begin", f_wrap_cpp); Swig_register_filebyname("begin", f_wrap_cpp);
Swig_register_filebyname("runtime", f_runtime); Swig_register_filebyname("runtime", f_runtime);
Swig_register_filebyname("header", f_header); Swig_register_filebyname("header", f_header);
@ -1921,7 +1878,7 @@ int V8Emitter::dump(Node *n) {
/* Get the module name */ /* Get the module name */
String *module = Getattr(n, "name"); String *module = Getattr(n, "name");
// write the swig banner // write the SWIG banner
Swig_banner(f_wrap_cpp); Swig_banner(f_wrap_cpp);
Template initializer_define(getTemplate("js_initializer_define")); Template initializer_define(getTemplate("js_initializer_define"));