Add module for Javascript target.
This module comes with a design that allows different code emitter implementations. For the the phase of development the module is split into multiple files which will be merged together when development converges. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/oliverb-javascript-v8@13737 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
c86ce942c2
commit
d71a5f483a
7 changed files with 642 additions and 0 deletions
139
Source/Modules/javascript_emitter.h
Normal file
139
Source/Modules/javascript_emitter.h
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
#ifndef JAVASCRIPT_EMITTER_H
|
||||
#define JAVASCRIPT_EMITTER_H
|
||||
|
||||
#include "swigmod.h"
|
||||
|
||||
/**
|
||||
* A class that wraps a code snippet used as template for code generation.
|
||||
*/
|
||||
class Template {
|
||||
|
||||
public:
|
||||
Template(const String* code);
|
||||
|
||||
~Template();
|
||||
|
||||
String* str();
|
||||
|
||||
Template& Replace(const String* pattern, const String* repl);
|
||||
|
||||
private:
|
||||
String* m_code;
|
||||
};
|
||||
|
||||
class JSEmitter {
|
||||
|
||||
public:
|
||||
|
||||
enum JSEmitterType {
|
||||
JavascriptCore,
|
||||
V8,
|
||||
QtScript
|
||||
};
|
||||
|
||||
JSEmitter();
|
||||
|
||||
virtual ~JSEmitter();
|
||||
|
||||
/**
|
||||
* Opens output files and temporary output DOHs.
|
||||
*/
|
||||
virtual int Initialize(Node *n) = 0;
|
||||
|
||||
/**
|
||||
* Writes all collected code into the output file(s).
|
||||
*/
|
||||
virtual int Dump(Node *n) = 0;
|
||||
|
||||
/**
|
||||
* Cleans up all open output DOHs.
|
||||
*/
|
||||
virtual int Close() = 0;
|
||||
|
||||
/**
|
||||
* Switches the context for code generation.
|
||||
*
|
||||
* Classes, global variables and global functions may need to
|
||||
* be registered in certain static tables.
|
||||
* This method should be used to switch output DOHs correspondingly.
|
||||
*/
|
||||
virtual int SwitchContext(Node *n) { return SWIG_OK; };
|
||||
|
||||
/**
|
||||
* Invoked at the beginning of the classHandler.
|
||||
*/
|
||||
virtual int EnterClass(Node *n) { return SWIG_OK; };
|
||||
|
||||
/**
|
||||
* Invoked at the end of the classHandler.
|
||||
*/
|
||||
virtual int ExitClass(Node *n) { return SWIG_OK; };
|
||||
|
||||
/**
|
||||
* Invoked at the beginning of the variableHandler.
|
||||
*/
|
||||
virtual int EnterVariable(Node *n) { return SWIG_OK; };
|
||||
|
||||
/**
|
||||
* Invoked at the end of the variableHandler.
|
||||
*/
|
||||
virtual int ExitVariable(Node *n) { return SWIG_OK; };
|
||||
|
||||
/**
|
||||
* Invoked at the beginning of the functionHandler.
|
||||
*/
|
||||
virtual int EnterFunction(Node *n) { return SWIG_OK; };
|
||||
|
||||
/**
|
||||
* Invoked at the end of the functionHandler.
|
||||
*/
|
||||
virtual int ExitFunction(Node *n) { return SWIG_OK; };
|
||||
|
||||
/**
|
||||
* Invoked by functionWrapper callback after call to Language::functionWrapper.
|
||||
*/
|
||||
virtual int EmitWrapperFunction(Node *n);
|
||||
|
||||
/**
|
||||
* Registers a given code snippet for a given key name.
|
||||
*
|
||||
* This method is called by the fragmentDirective handler
|
||||
* of the JAVASCRIPT language module.
|
||||
*/
|
||||
int RegisterTemplate(const String *name, const String *code);
|
||||
|
||||
/**
|
||||
* Retrieve the code template registered for a given name.
|
||||
*/
|
||||
const String* GetTemplate(const String *name);
|
||||
|
||||
protected:
|
||||
|
||||
virtual int EmitCtor(Node *n) = 0;
|
||||
|
||||
virtual int EmitDtor(Node *n) = 0;
|
||||
|
||||
virtual int EmitFunction(Node *n, bool is_member) = 0;
|
||||
|
||||
virtual int EmitGetter(Node *n, bool is_member) = 0;
|
||||
|
||||
virtual int EmitSetter(Node *n, bool is_member) = 0;
|
||||
|
||||
bool IsSetterMethod(Node *n);
|
||||
|
||||
Node* GetBaseClass(Node *n);
|
||||
|
||||
const String* typemapLookup(Node *n, const_String_or_char_ptr tmap_method,
|
||||
SwigType *type, int warning, Node *typemap_attributes = 0);
|
||||
|
||||
protected:
|
||||
|
||||
// empty string used at different places in the code
|
||||
String *empty_string;
|
||||
|
||||
Hash *templates;
|
||||
|
||||
Wrapper* current_wrapper;
|
||||
};
|
||||
|
||||
#endif // JAVASCRIPT_EMITTER_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue