/tags/Root-branch-php-utl/SWIG/Source/Modules/java.cxx
C++ | 1722 lines | 1227 code | 257 blank | 238 comment | 312 complexity | cbe6a34f208bc5466d9c7f7a53d895e9 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
Large files files are truncated, but you can click here to view the full file
- /* -----------------------------------------------------------------------------
- * See the LICENSE file for information on copyright, usage and redistribution
- * of SWIG, and the README file for authors - http://www.swig.org/release.html.
- *
- * java.cxx
- *
- * Java language module for SWIG.
- * ----------------------------------------------------------------------------- */
- char cvsroot_java_cxx[] = "$Header$";
- #include "swigmod.h"
- #include <limits.h> // for INT_MAX
- #include "cparse.h"
- #include <ctype.h>
- /* Hash type used for upcalls from C/C++ */
- typedef DOH UpcallData;
- class JAVA : public Language {
- static const char *usage;
- const String *empty_string;
- const String *public_string;
- const String *protected_string;
- Hash *swig_types_hash;
- File *f_runtime;
- File *f_runtime_h;
- File *f_header;
- File *f_wrappers;
- File *f_init;
- File *f_directors;
- File *f_directors_h;
- List *filenames_list;
- bool proxy_flag; // Flag for generating proxy classes
- bool native_function_flag; // Flag for when wrapping a native function
- bool enum_constant_flag; // Flag for when wrapping an enum or constant
- bool static_flag; // Flag for when wrapping a static functions or member variables
- bool variable_wrapper_flag; // Flag for when wrapping a nonstatic member variable
- bool wrapping_member_flag; // Flag for when wrapping a member variable/enum/const
- bool global_variable_flag; // Flag for when wrapping a global variable
- bool old_variable_names; // Flag for old style variable names in the intermediary class
- bool member_func_flag; // flag set when wrapping a member function
- String *imclass_name; // intermediary class name
- String *module_class_name; // module class name
- String *imclass_class_code; // intermediary class code
- String *proxy_class_def;
- String *proxy_class_code;
- String *module_class_code;
- String *proxy_class_name;
- String *variable_name; //Name of a variable being wrapped
- String *proxy_class_constants_code;
- String *module_class_constants_code;
- String *enum_code;
- String *package; // Optional package name
- String *jnipackage; // Package name used in the JNI code
- String *package_path; // Package name used internally by JNI (slashes)
- String *imclass_imports; //intermediary class imports from %pragma
- String *module_imports; //module imports from %pragma
- String *imclass_baseclass; //inheritance for intermediary class class from %pragma
- String *module_baseclass; //inheritance for module class from %pragma
- String *imclass_interfaces; //interfaces for intermediary class class from %pragma
- String *module_interfaces; //interfaces for module class from %pragma
- String *imclass_class_modifiers; //class modifiers for intermediary class overriden by %pragma
- String *module_class_modifiers; //class modifiers for module class overriden by %pragma
- String *upcasts_code; //C++ casts for inheritance hierarchies C++ code
- String *imclass_cppcasts_code; //C++ casts up inheritance hierarchies intermediary class code
- String *imclass_directors; // Intermediate class director code
- String *destructor_call; //C++ destructor call if any
- // Director method stuff:
- List *dmethods_seq;
- Hash *dmethods_table;
- int n_dmethods;
- int n_directors;
- int first_class_dmethod;
- int curr_class_dmethod;
- enum EnumFeature { SimpleEnum, TypeunsafeEnum, TypesafeEnum, ProperEnum };
- public:
- /* -----------------------------------------------------------------------------
- * JAVA()
- * ----------------------------------------------------------------------------- */
- JAVA() :
- empty_string(NewString("")),
- public_string(NewString("public")),
- protected_string(NewString("protected")),
- swig_types_hash(NULL),
- f_runtime(NULL),
- f_runtime_h(NULL),
- f_header(NULL),
- f_wrappers(NULL),
- f_init(NULL),
- f_directors(NULL),
- f_directors_h(NULL),
- filenames_list(NULL),
- proxy_flag(true),
- native_function_flag(false),
- enum_constant_flag(false),
- static_flag(false),
- variable_wrapper_flag(false),
- wrapping_member_flag(false),
- global_variable_flag(false),
- old_variable_names (false),
- member_func_flag(false),
- imclass_name(NULL),
- module_class_name(NULL),
- imclass_class_code(NULL),
- proxy_class_def(NULL),
- proxy_class_code(NULL),
- module_class_code(NULL),
- proxy_class_name(NULL),
- variable_name(NULL),
- proxy_class_constants_code(NULL),
- module_class_constants_code(NULL),
- package(NULL),
- jnipackage(NULL),
- package_path(NULL),
- imclass_imports(NULL),
- module_imports(NULL),
- imclass_baseclass(NULL),
- module_baseclass(NULL),
- imclass_interfaces(NULL),
- module_interfaces(NULL),
- imclass_class_modifiers(NULL),
- module_class_modifiers(NULL),
- upcasts_code(NULL),
- imclass_cppcasts_code(NULL),
- imclass_directors(NULL),
- destructor_call(NULL),
- dmethods_seq(NULL),
- dmethods_table(NULL),
- n_dmethods(0),
- n_directors(0)
- {
- /* for now, multiple inheritance in directors is disabled, this
- should be easy to implement though */
- director_multiple_inheritance = 0;
- director_language = 1;
- }
- /* -----------------------------------------------------------------------------
- * getProxyName()
- *
- * Test to see if a type corresponds to something wrapped with a proxy class
- * Return NULL if not otherwise the proxy class name
- * ----------------------------------------------------------------------------- */
- String *getProxyName(SwigType *t) {
- if (proxy_flag) {
- Node *n = classLookup(t);
- if (n) {
- return Getattr(n,"sym:name");
- }
- }
- return NULL;
- }
- /* -----------------------------------------------------------------------------
- * makeValidJniName()
- * ----------------------------------------------------------------------------- */
- String *makeValidJniName(const String *name) {
- String *valid_jni_name = NewString(name);
- Replaceall(valid_jni_name,"_","_1");
- return valid_jni_name;
- }
- /* -----------------------------------------------------------------------------
- * directorClassName()
- * ----------------------------------------------------------------------------- */
- String *directorClassName(Node *n) {
- String *dirclassname;
- const char *attrib = "director:classname";
- if (!(dirclassname = Getattr(n, attrib))) {
- String *classname = Getattr(n, "sym:name");
- dirclassname = NewStringf("SwigDirector_%s", classname);
- Setattr(n, attrib, dirclassname);
- }
- return dirclassname;
- }
- /* ------------------------------------------------------------
- * main()
- * ------------------------------------------------------------ */
- virtual void main(int argc, char *argv[]) {
- SWIG_library_directory("java");
- // Look for certain command line options
- for (int i = 1; i < argc; i++) {
- if (argv[i]) {
- if (strcmp(argv[i],"-package") == 0) {
- if (argv[i+1]) {
- package = NewString("");
- Printf(package, argv[i+1]);
- Swig_mark_arg(i);
- Swig_mark_arg(i+1);
- i++;
- } else {
- Swig_arg_error();
- }
- } else if ((strcmp(argv[i],"-shadow") == 0) || ((strcmp(argv[i],"-proxy") == 0))) {
- Printf(stderr,"Deprecated command line option: %s. Proxy classes are now generated by default.\n", argv[i]);
- Swig_mark_arg(i);
- proxy_flag = true;
- } else if ((strcmp(argv[i],"-noproxy") == 0)) {
- Swig_mark_arg(i);
- proxy_flag = false;
- } else if (strcmp(argv[i],"-oldvarnames") == 0) {
- Swig_mark_arg(i);
- old_variable_names = true;
- } else if (strcmp(argv[i],"-jnic") == 0) {
- Swig_mark_arg(i);
- Printf(stderr,"Deprecated command line option: -jnic. C JNI calling convention now used when -c++ not specified.\n");
- } else if (strcmp(argv[i],"-nofinalize") == 0) {
- Swig_mark_arg(i);
- Printf(stderr,"Deprecated command line option: -nofinalize. Use the new javafinalize typemap instead.\n");
- } else if (strcmp(argv[i],"-jnicpp") == 0) {
- Swig_mark_arg(i);
- Printf(stderr,"Deprecated command line option: -jnicpp. C++ JNI calling convention now used when -c++ specified.\n");
- } else if (strcmp(argv[i],"-help") == 0) {
- Printf(stdout,"%s\n", usage);
- }
- }
- }
- // Add a symbol to the parser for conditional compilation
- Preprocessor_define("SWIGJAVA 1",0);
- // Add typemap definitions
- SWIG_typemap_lang("java");
- SWIG_config_file("java.swg");