/trunk/Source/Modules/modula3.cxx
C++ | 1989 lines | 1329 code | 217 blank | 443 comment | 410 complexity | 77bcef6f2edb8e97a88f2d4725146fc0 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
- /* -----------------------------------------------------------------------------
- * This file is part of SWIG, which is licensed as a whole under version 3
- * (or any later version) of the GNU General Public License. Some additional
- * terms also apply to certain portions of SWIG. The full details of the SWIG
- * license and copyrights can be found in the LICENSE and COPYRIGHT files
- * included with the SWIG source code as distributed by the SWIG developers
- * and at http://www.swig.org/legal.html.
- *
- * modula3.cxx
- *
- * Modula3 language module for SWIG.
- * ----------------------------------------------------------------------------- */
- char cvsroot_modula3_cxx[] = "$Id: modula3.cxx 12830 2011-10-30 21:51:50Z wsfulton $";
- /*
- Text formatted with
- indent -sob -br -ce -nut -npsl
- */
- /*
- Report:
- - It's not a good concept to use member variables or global variables
- for passing parameters to functions.
- It's not a good concept to use functions of superclasses for specific services.
- E.g. For SWIG this means: Generating accessor functions for member variables
- is the most common but no general task to be processed in membervariableHandler.
- Better provide a service function which generates accessor function code
- and equip this service function with all parameters needed for input (parse node)
- and output (generated code).
- - How can I make globalvariableHandler not to generate
- interface functions to two accessor functions
- (that don't exist) ?
- - How can I generate a typemap that turns every C reference argument into
- its Modula 3 counterpart, that is
- void test(Complex &z);
- PROCEDURE test(VAR z:Complex);
- - neither $*n_mangle nor $*n_type nor $*n_ltype return the type without
- pointer converted to Modula3 equivalent,
- $*n_mangle is the variant closest to what I expect
- - using a typemap like
- typemap(m3wrapintype) int * %{VAR $1_name: INTEGER%}
- has the advantages:
- - one C parameter can be turned into multiple M3 parameters
- - the argument can be renamed
- - using typemaps like
- typemap(m3wrapinmode) int * "VAR"
- typemap(m3wrapintype) int * "INTEGER"
- has the advantages:
- - multiple parameters with same type and default value can be bundled
- - more conform to the other language modules
- - Where takes the reduction of multi-typemaps place?
- How can I preserve all parameters for functions of the intermediary class?
- The answer is Getattrs(n,"tmap:m3rawintype:next")
- - Char() can be used to transform a String to (char *)
- which can be used for output with printf
- - What is the while (checkAttribute()) loop in functionWrapper good for?
- Appearently for skipping (numinputs=0) typemaps.
- - SWIGTYPE const * - typemap is ignored, whereas
- SWIGTYPE * - typemap is invoked, why?
- Had it been (const SWIGTYPE *) instead?
- - enumeration items should definitely be equipped
- with its plain numerical value
- One could add tag 'numvalue' in CParse/parser.y,
- but it is still possible that someone declares an
- enumeration using a symbolic constant.
- I have quickly hacked
- that the successive number is assigned
- if "enumvalue" has suffix "+1".
- The ultimate solution would be to generate a C program
- which includes the header and outputs all constants.
- This program might be compiled and run
- by 'make' or by SWIG and the resulting output is fed back to SWIG.
- - It's a bad idea to interpret feature value ""
- 'disable feature' because the value ""
- might be sensible in case of feature:modula3:oldprefix.
- - What's the difference between "sym:name" and "name" ?
- "name" is the original name and
- "sym:name" is probably modified by the user using %rename
- - Is it possible for 'configure' to find out if m3pp is installed
- and to invoke it for generated Modula3 files?
- - It would be better to separate an arguments purpose and its name,
- because an output variable with name "OUTPUT" is not very descriptive.
- In case of PLPlot this could be solved by typedefs
- that assign special purposes to the array types.
- - Can one interpret $n_basetype as the identifier matched with SWIGTYPE ?
- SWIG's odds:
- - arguments of type (Node *) for SWIG functions
- should be most often better (const Node *):
- Swig_symbol_qualified, Getattr, nodeType, parentNode
- - unique identifier style instead of
- NewString, Getattr, firstChild
- - 'class'.name is qualified,
- 'enum'.name and 'enumitem'.name is not
- - Swig_symbol_qualified() returns NIL for enumeration nodes
- - Is there a function that creates a C representation of a SWIG type string?
- ToDo:
- - create WeakRefs only for resources returned by function marked with %newobject
- -> part of output conversion
- - clean typemap conception
- - should a multi-typemap for m3wrapouttype skip the corresponding input parameters?
- when yes - How to handle inout-arguments? In this case like in-argument.
- - C++ classes
- - C++ exceptions
- - allow for moving RECORD and OBJECT definitions
- to separate files, with the main type called T
- - call-back functions
- - special option: fast access to class members by pointer arithmetic,
- member offsets can be determined by a C++ program that print them.
- - emit enumeration definitions when its first item is declared,
- currently enumerations are emitted at the beginning of the file
- Done:
- - addThrow should convert the typemap by itself
- - not possible because routine for attaching mapped types to parameter nodes
- won't work for the function node
- - turning error codes into exceptions
- -> part of output value checking
- - create WeakRefs for resources allocated by the library
- -> part of output conversion
- - TRY..FINALLY..END; can be omitted
- - if there is no m3wrapfreearg
- - no exception can be raised in the body (empty RAISES) list
- */
- #include "swigmod.h"
- #include <limits.h> // for INT_MAX
- #include <ctype.h>
- #define USAGE_ARG_DIR "m3wrapargdir typemap expect values: in, out, inout\n"
- class MODULA3:public Language {
- public:
- enum block_type { no_block, constant, variable, blocktype, revelation };
- private:
- struct M3File {
- String *f;
- Hash *import;
- block_type bt;
- /* VC++ 6 doesn't allow the access to 'no_block'
- if it is a private member of MODULA3 class */
- M3File():f(NewString("")), import(NewHash()), bt(no_block) {
- }
- ~M3File() {
- Delete(f);
- Delete(import);
- }
- /* -----------------------------------------------------------------------------
- * enterBlock()
- *
- * Make sure that a given declaration is written to the right declaration block,
- * that is constants are written after "CONST" and so on ...
- * ----------------------------------------------------------------------------- */
- void enterBlock(block_type newbt) {
- static const char *ident[] = { "", "\nCONST\n", "\nVAR\n", "\nTYPE\n", "\nREVEAL\n" };
- #ifdef DEBUG
- if ((bt < 0) || (4 < bt)) {
- printf("bt %d out of range\n", bt);
- }
- #endif
- if (newbt != bt) {
- Append(f, ident[newbt]);
- bt = newbt;
- }
- }
- };
- static const char *usage;
- const String *empty_string;
- Hash *swig_types_hash;
- File *f_begin;
- File *f_runtime;
- File *f_header;
- File *f_wrappers;
- File *f_init;
- bool proxy_flag; // Flag for generating proxy classes
- bool have_default_constructor_flag;
- 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 unsafe_module;
- String *m3raw_name; // raw interface name
- M3File m3raw_intf; // raw interface
- M3File m3raw_impl; // raw implementation (usually empty)
- String *m3wrap_name; // wrapper module
- M3File m3wrap_intf;
- M3File m3wrap_impl;
- String *m3makefile;
- String *targetlibrary;
- String *proxy_class_def;
- String *proxy_class_code;
- String *proxy_class_name;
- String *variable_name; //Name of a variable being wrapped
- String *variable_type; //Type of this variable
- String *enumeration_name; //Name of the current enumeration type
- Hash *enumeration_items; //and its members
- int enumeration_max;
- Hash *enumeration_coll; //Collection of all enumerations.
- /* The items are nodes with members:
- "items" - hash of with key 'itemname' and content 'itemvalue'
- "max" - maximum value in item list
- */
- String *constant_values;
- String *constantfilename;
- String *renamefilename;
- String *typemapfilename;
- String *m3raw_imports; //intermediary class imports from %pragma
- String *module_imports; //module imports from %pragma
- String *m3raw_baseclass; //inheritance for intermediary class class from %pragma
- String *module_baseclass; //inheritance for module class from %pragma
- String *m3raw_interfaces; //interfaces for intermediary class class from %pragma
- String *module_interfaces; //interfaces for module class from %pragma
- String *m3raw_class_modifiers; //class modifiers for intermediary class overriden by %pragma
- String *m3wrap_modifiers; //class modifiers for module class overriden by %pragma
- String *upcasts_code; //C++ casts for inheritance hierarchies C++ code
- String *m3raw_cppcasts_code; //C++ casts up inheritance hierarchies intermediary class code
- String *destructor_call; //C++ destructor call if any
- String *outfile;
- enum type_additions { none, pointer, reference };
- public:
- /* -----------------------------------------------------------------------------
- * MODULA3()
- * ----------------------------------------------------------------------------- */
- MODULA3():
- empty_string(NewString("")),
- swig_types_hash(NULL),
- f_begin(NULL),
- f_runtime(NULL),
- f_header(NULL),
- f_wrappers(NULL),
- f_init(NULL),
- proxy_flag(true),
- have_default_constructor_flag(false),
- 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),
- unsafe_module(false),
- m3raw_name(NULL),
- m3raw_intf(),
- m3raw_impl(),
- m3wrap_name(NULL),
- m3wrap_intf(),
- m3wrap_impl(),
- m3makefile(NULL),
- targetlibrary(NULL),
- proxy_class_def(NULL),
- proxy_class_code(NULL),
- proxy_class_name(NULL),
- variable_name(NULL),
- variable_type(NULL),
- enumeration_name(NULL),
- enumeration_items(NULL),
- enumeration_max(0),
- enumeration_coll(NULL),
- constant_values(NULL),
- constantfilename(NULL),
- renamefilename(NULL),
- typemapfilename(NULL),
- m3raw_imports(NULL),
- module_imports(NULL),
- m3raw_baseclass(NULL),
- module_baseclass(NULL),
- m3raw_interfaces(NULL),
- module_interfaces(NULL),
- m3raw_class_modifiers(NULL),
- m3wrap_modifiers(NULL),
- upcasts_code(NULL),
- m3raw_cppcasts_code(NULL),
- destructor_call(NULL),
- outfile(NULL) {
- }
- /************** some utility functions ***************/
- /* -----------------------------------------------------------------------------
- * getMappedType()
- *
- * Return the type of 'p' mapped by 'map'.
- * Print a standard warning if 'p' can't be mapped.
- * ----------------------------------------------------------------------------- */
- String *getMappedType(Node *p, const char *map) {
- String *mapattr = NewString("tmap:");
- Append(mapattr, map);
- String *tm = Getattr(p, mapattr);
- if (tm == NIL) {
- Swig_warning(WARN_MODULA3_TYPEMAP_TYPE_UNDEF, input_file, line_number,
- "No '%s' typemap defined for type '%s'\n", map, SwigType_str(Getattr(p, "type"), 0));
- }
- Delete(mapattr);
- return tm;
- }
- /* -----------------------------------------------------------------------------
- * getMappedTypeNew()
- *
- * Similar to getMappedType but uses Swig_type_lookup_new.
- * ----------------------------------------------------------------------------- */
- String *getMappedTypeNew(Node *n, const char *map, const char *lname = "", bool warn = true) {
- String *tm = Swig_typemap_lookup(map, n, lname, 0);
- if ((tm == NIL) && warn) {
- Swig_warning(WARN_MODULA3_TYPEMAP_TYPE_UNDEF, input_file, line_number,
- "No '%s' typemap defined for type '%s'\n", map, SwigType_str(Getattr(n, "type"), 0));
- }
- return tm;
- }
- /* -----------------------------------------------------------------------------
- * attachMappedType()
- *
- * Obtain the type mapped by 'map' and attach it to the node
- * ----------------------------------------------------------------------------- */
- void attachMappedType(Node *n, const char *map, const char *lname = "") {
- String *tm = Swig_typemap_lookup(map, n, lname, 0);
- if (tm != NIL) {
- String *attr = NewStringf("tmap:%s", map);
- Setattr(n, attr, tm);
- Delete(attr);
- }
- }
- /* -----------------------------------------------------------------------------
- * skipIgnored()
- *
- * Skip all parameters that have 'numinputs=0'
- * with respect to a given typemap.
- * ----------------------------------------------------------------------------- */
- Node *skipIgnored(Node *p, const char *map) {
- String *niattr = NewStringf("tmap:%s:numinputs", map);
- String *nextattr = NewStringf("tmap:%s:next", map);
- while ((p != NIL) && checkAttribute(p, niattr, "0")) {
- p = Getattr(p, nextattr);
- }
- Delete(nextattr);
- Delete(niattr);
- return p;
- }
- /* -----------------------------------------------------------------------------
- * isInParam()
- * isOutParam()
- *
- * Check if the parameter is intended for input or for output.
- * ----------------------------------------------------------------------------- */
- bool isInParam(Node *p) {
- String *dir = Getattr(p, "tmap:m3wrapargdir");
- //printf("dir for %s: %s\n", Char(Getattr(p,"name")), Char(dir));
- if ((dir == NIL) || (Strcmp(dir, "in") == 0)
- || (Strcmp(dir, "inout") == 0)) {
- return true;
- } else if (Strcmp(dir, "out") == 0) {
- return false;
- } else {
- printf("%s", USAGE_ARG_DIR);
- return false;
- }
- }
- bool isOutParam(Node *p) {
- String *dir = Getattr(p, "tmap:m3wrapargdir");
- if ((dir == NIL) || (Strcmp(dir, "in") == 0)) {
- return false;
- } else if ((Strcmp(dir, "out") == 0) || (Strcmp(dir, "inout") == 0)) {
- return true;
- } else {
- printf("%s", USAGE_ARG_DIR);
- return false;
- }
- }
- /* -----------------------------------------------------------------------------
- * printAttrs()
- *
- * For debugging: Show all attributes of a node and their values.
- * ----------------------------------------------------------------------------- */
- void printAttrs(Node *n) {
- Iterator it;
- for (it = First(n); it.key != NIL; it = Next(it)) {
- printf("%s = %s\n", Char(it.key), Char(Getattr(n, it.key)));
- }
- }
- /* -----------------------------------------------------------------------------
- * hasPrefix()
- *
- * Check if a string have a given prefix.
- * ----------------------------------------------------------------------------- */
- bool hasPrefix(const String *str, const String *prefix) {
- int len_prefix = Len(prefix);
- return (Len(str) > len_prefix)
- && (Strncmp(str, prefix, len_prefix) == 0);
- }
- /* -----------------------------------------------------------------------------
- * getQualifiedName()
- *
- * Return fully qualified identifier of n.
- * ----------------------------------------------------------------------------- */
- #if 0
- // Swig_symbol_qualified returns NIL for enumeration nodes
- String *getQualifiedName(Node *n) {
- String *qual = Swig_symbol_qualified(n);
- String *name = Getattr(n, "name");
- if (hasContent(qual)) {
- return NewStringf("%s::%s", qual, name);
- } else {
- return name;
- }
- }
- #else
- String *getQualifiedName(Node *n) {
- String *name = Copy(Getattr(n, "name"));
- n = parentNode(n);
- while (n != NIL) {
- const String *type = nodeType(n);
- if ((Strcmp(type, "class") == 0) || (Strcmp(type, "struct") == 0) || (Strcmp(type, "namespace") == 0)) {
- String *newname = NewStringf("%s::%s", Getattr(n, "name"), name);
- Delete(name);
- //name = newname;
- // Hmpf, the class name is already qualified.
- return newname;
- }
- n = parentNode(n);
- }
- //printf("qualified name: %s\n", Char(name));
- return name;
- }
- #endif
- /* -----------------------------------------------------------------------------
- * nameToModula3()
- *
- * Turn usual C identifiers like "this_is_an_identifier"
- * into usual Modula 3 identifier like "thisIsAnIdentifier"
- * ----------------------------------------------------------------------------- */
- String *nameToModula3(const String *sym, bool leadingCap) {
- int len_sym = Len(sym);
- char *csym = Char(sym);
- char *m3sym = new char[len_sym + 1];
- int i, j;
- bool cap = leadingCap;
- for (i = 0, j = 0; j < len_sym; j++) {
- char c = csym[j];
- if ((c == '_') || (c == ':')) {
- cap = true;
- } else {
- if (isdigit(c)) {
- m3sym[i] = c;
- cap = true;
- } else {
- if (cap) {
- m3sym[i] = (char)toupper(c);
- } else {
- m3sym[i] = (char)tolower(c);
- }
- cap = false;
- }
- i++;
- }
- }
- m3sym[i] = 0;
- String *result = NewString(m3sym);
- delete[]m3sym;
- return result;
- }
- /* -----------------------------------------------------------------------------
- * capitalizeFirst()
- *
- * Make the first character upper case.
- * ----------------------------------------------------------------------------- */
- String *capitalizeFirst(const String *str) {
- return NewStringf("%c%s", toupper(*Char(str)), Char(str) + 1);
- }
- /* -----------------------------------------------------------------------------
- * prefixedNameToModula3()
- *
- * If feature modula3:oldprefix and modula3:newprefix is present
- * and the C identifier has leading 'oldprefix'
- * then it is replaced by the 'newprefix'.
- * The rest is converted to Modula style.
- * ----------------------------------------------------------------------------- */
- String *prefixedNameToModula3(Node *n, const String *sym, bool leadingCap) {
- String *oldPrefix = Getattr(n, "feature:modula3:oldprefix");
- String *newPrefix = Getattr(n, "feature:modula3:newprefix");
- String *result = NewString("");
- char *short_sym = Char(sym);
- // if at least one prefix feature is present
- // the replacement takes place
- if ((oldPrefix != NIL) || (newPrefix != NIL)) {
- if ((oldPrefix == NIL) || hasPrefix(sym, oldPrefix)) {
- short_sym += Len(oldPrefix);
- if (newPrefix != NIL) {
- Append(result, newPrefix);
- }
- }
- }
- String *suffix = nameToModula3(short_sym, leadingCap || hasContent(newPrefix));
- Append(result, suffix);
- Delete(suffix);
- return result;
- }
- /* -----------------------------------------------------------------------------
- * hasContent()
- *
- * Check if the string exists and contains something.
- * ----------------------------------------------------------------------------- */
- bool hasContent(const String *str) {
- return (str != NIL) && (Strcmp(str, "") != 0);
- }
- /* -----------------------------------------------------------------------------
- * openWriteFile()
- *
- * Caution: The file must be freshly allocated and will be destroyed
- * by this routine.
- * ----------------------------------------------------------------------------- */
- File *openWriteFile(String *name) {
- File *file = NewFile(name, "w", SWIG_output_files());
- if (!file) {
- FileErrorDisplay(name);
- SWIG_exit(EXIT_FAILURE);
- }
- Delete(name);
- return file;
- }
- /* -----------------------------------------------------------------------------
- * aToL()
- *
- * like atol but with additional user warning
- * ----------------------------------------------------------------------------- */
- long aToL(const String *value) {
- char *endptr;
- long numvalue = strtol(Char(value), &endptr, 0);
- if (*endptr != 0) {
- Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "The string <%s> does not denote a numeric value.\n", value);
- }
- return numvalue;
- }
- /* -----------------------------------------------------------------------------
- * strToL()
- *
- * like strtol but returns if the conversion was successful
- * ----------------------------------------------------------------------------- */
- bool strToL(const String *value, long &numvalue) {
- char *endptr;
- numvalue = strtol(Char(value), &endptr, 0);
- return (*endptr == 0);
- }
- /* -----------------------------------------------------------------------------
- * evalExpr()
- *
- * Evaluate simple expression as they may occur in "enumvalue" attributes.
- * ----------------------------------------------------------------------------- */
- bool evalExpr(String *value, long &numvalue) {
- // Split changes file status of String and thus cannot receive 'const' strings
- //printf("evaluate <%s>\n", Char(value));
- List *summands = Split(value, '+', INT_MAX);
- Iterator sm = First(summands);
- numvalue = 0;
- for (; sm.item != NIL; sm = Next(sm)) {
- String *smvalue = Getattr(constant_values, sm.item);
- long smnumvalue;
- if (smvalue != NIL) {
- if (!strToL(smvalue, smnumvalue)) {
- //printf("evaluation: abort 0 <%s>\n", Char(smvalue));
- return false;
- }
- } else {
- if (!strToL(sm.item, smnumvalue)) {
- //printf("evaluation: abort 1 <%s>\n", Char(sm));
- return false;
- }
- }
- numvalue += smnumvalue;
- }
- //printf("evaluation: return %ld\n", numvalue);
- return true;
- }
- /* -----------------------------------------------------------------------------
- * log2()
- *
- * Determine the position of the single bit of a power of two.
- * Returns true if the given number is a power of two.
- * ----------------------------------------------------------------------------- */
- bool log2(long n, long &exp) {
- exp = 0;
- while (n > 0) {
- if ((n & 1) != 0) {
- return n == 1;
- }
- exp++;
- n >>= 1;
- }
- return false;
- }
- /* -----------------------------------------------------------------------------
- * writeArg
- *
- * Write a function argument or RECORD entry definition.
- * Bundles arguments of same type and default value.
- * 'name.next==NIL' denotes the end of the entry or argument list.
- * ----------------------------------------------------------------------------- */
- bool equalNilStr(const String *str0, const String *str1) {
- if (str0 == NIL) {
- return (str1 == NIL);
- //return (str0==NIL) == (str1==NIL);
- } else {
- return (str1 != NIL) && (Cmp(str0, str1) == 0);
- //return Cmp(str0,str1)==0;
- }
- }
- struct writeArgState {
- String *mode, *name, *type, *value;
- bool hold;
- writeArgState():mode(NIL), name(NIL), type(NIL), value(NIL), hold(false) {
- }
- };
- void writeArg(File *f, writeArgState & state, String *mode, String *name, String *type, String *value) {
- /* skip the first argument,
- only store the information for the next call in this case */
- if (state.name != NIL) {
- if ((!state.hold) && (state.mode != NIL)) {
- Printf(f, "%s ", state.mode);
- }
- if ((name != NIL) && equalNilStr(state.mode, mode) && equalNilStr(state.type, type) && (state.value == NIL) && (value == NIL)
- /* the same expression may have different values
- due to side effects of the called function */
- /*equalNilStr(state.value,value) */
- ) {
- Printf(f, "%s, ", state.name);
- state.hold = true;
- } else {
- Append(f, state.name);
- if (state.type != NIL) {
- Printf(f, ": %s", state.type);
- }
- if (state.value != NIL) {
- Printf(f, ":= %s", state.value);
- }
- Append(f, ";\n");
- state.hold = false;
- }
- }
- /* at the next call the current argument will be the previous one */
- state.mode = mode;
- state.name = name;
- state.type = type;
- state.value = value;
- }
- /* -----------------------------------------------------------------------------
- * 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;
- }
- /*************** language processing ********************/
- /* ------------------------------------------------------------
- * main()
- * ------------------------------------------------------------ */
- virtual void main(int argc, char *argv[]) {
- SWIG_library_directory("modula3");
- // Look for certain command line options
- for (int i = 1; i < argc; i++) {
- if (argv[i]) {
- if (strcmp(argv[i], "-generateconst") == 0) {
- if (argv[i + 1]) {
- constantfilename = NewString(argv[i + 1]);
- Swig_mark_arg(i);
- Swig_mark_arg(i + 1);
- i++;
- } else {
- Swig_arg_error();
- }
- } else if (strcmp(argv[i], "-generaterename") == 0) {
- if (argv[i + 1]) {
- renamefilename = NewString(argv[i + 1]);
- Swig_mark_arg(i);
- Swig_mark_arg(i + 1);
- i++;
- } else {
- Swig_arg_error();
- }
- } else if (strcmp(argv[i], "-generatetypemap") == 0) {
- if (argv[i + 1]) {
- typemapfilename = NewString(argv[i + 1]);
- Swig_mark_arg(i);
- Swig_mark_arg(i + 1);
- i++;
- } else {
- Swig_arg_error();
- }
- } 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], "-help") == 0) {
- Printf(stdout, "%s\n", usage);
- }
- }
- }
- // Add a symbol to the parser for conditional compilation
- Preprocessor_define("SWIGMODULA3 1", 0);
- // Add typemap definitions
- SWIG_typemap_lang("modula3");
- SWIG_config_file("modula3.swg");
- allow_overloading();
- }
- /* ---------------------------------------------------------------------
- * top()
- * --------------------------------------------------------------------- */
- virtual int top(Node *n) {
- if (hasContent(constantfilename) || hasContent(renamefilename) || hasContent(typemapfilename)) {
- int result = SWIG_OK;
- if (hasContent(constantfilename)) {
- result = generateConstantTop(n) && result;
- }
- if (hasContent(renamefilename)) {
- result = generateRenameTop(n) && result;
- }
- if (hasContent(typemapfilename)) {
- result = generateTypemapTop(n) && result;
- }
- return result;
- } else {
- return generateM3Top(n);
- }
- }
- void scanConstant(File *file, Node *n) {
- Node *child = firstChild(n);
- while (child != NIL) {
- String *constname = NIL;
- String *type = nodeType(child);
- if ((Strcmp(type, "enumitem") == 0)
- || (Strcmp(type, "constant") == 0)) {
- #if 1
- constname = getQualifiedName(child);
- #else
- constname = Getattr(child, "value");
- if ((!hasContent(constname))
- || (('0' <= *Char(constname)) && (*Char(constname) <= '9'))) {
- constname = Getattr(child, "name");
- }
- #endif
- }
- if (constname != NIL) {
- Printf(file, " printf(\"%%%%constnumeric(%%Lg) %s;\\n\", (long double)%s);\n", constname, constname);
- }
- scanConstant(file, child);
- child = nextSibling(child);
- }
- }
- int generateConstantTop(Node *n) {
- File *file = openWriteFile(NewStringf("%s.c", constantfilename));
- if (CPlusPlus) {
- Printf(file, "#include <cstdio>\n");
- } else {
- Printf(file, "#include <stdio.h>\n");
- }
- Printf(file, "#include \"%s\"\n", input_file);
- Printf(file, "\n");
- Printf(file, "int main (int argc, char *argv[]) {\n");
- Printf(file, "\
- /*This progam must work for floating point numbers and integers.\n\
- Thus all numbers are converted to double precision floating point format.*/\n");
- scanConstant(file, n);
- Printf(file, " return 0;\n");
- Printf(file, "}\n");
- Close(file);
- return SWIG_OK;
- }
- void scanRename(File *file, Node *n) {
- Node *child = firstChild(n);
- while (child != NIL) {
- String *type = nodeType(child);
- if (Strcmp(type, "cdecl") == 0) {
- ParmList *p = Getattr(child, "parms");
- if (p != NIL) {
- String *name = getQualifiedName(child);
- String *m3name = nameToModula3(name, true);
- /*don't know how to get the original C type identifiers */
- //String *arguments = createCSignature (child);
- Printf(file, "%%rename(\"%s\") %s;\n", m3name, name);
- /*Printf(file, "%%rename(\"%s\") %s %s(%s);\n",
- m3name, Getattr(n,"type"), name, arguments); */
- Delete(name);
- Delete(m3name);
- //Delete (arguments);
- }
- }
- scanRename(file, child);
- child = nextSibling(child);
- }
- }
- int generateRenameTop(Node *n) {
- File *file = openWriteFile(NewStringf("%s.i", renamefilename));
- Printf(file, "\
- /* This file was generated from %s\n\
- by SWIG with option -generaterename. */\n\
- \n", input_file);
- scanRename(file, n);
- Close(file);
- return SWIG_OK;
- }
- void scanTypemap(File *file, Node *n) {
- Node *child = firstChild(n);
- while (child != NIL) {
- String *type = nodeType(child);
- //printf("nodetype %s\n", Char(type));
- String *storage = Getattr(child, "storage");
- if ((Strcmp(type, "class") == 0) || ((Strcmp(type, "cdecl") == 0) && (storage != NIL)
- && (Strcmp(storage, "typedef") == 0))) {
- String *name = getQualifiedName(child);
- String *m3name = nameToModula3(name, true);
- Printf(file, "%%typemap(\"m3wrapintype\") %s %%{%s%%}\n", name, m3name);
- Printf(file, "%%typemap(\"m3rawintype\") %s %%{%s%%}\n", name, m3name);
- Printf(file, "\n");
- }
- scanTypemap(file, child);
- child = nextSibling(child);
- }
- }
- int generateTypemapTop(Node *n) {
- File *file = openWriteFile(NewStringf("%s.i", typemapfilename));
- Printf(file, "\
- /* This file was generated from %s\n\
- by SWIG with option -generatetypemap. */\n\
- \n", input_file);
- scanTypemap(file, n);
- Close(file);
- return SWIG_OK;
- }
- int generateM3Top(Node *n) {
- /* Initialize all of the output files */
- outfile = Getattr(n, "outfile");
- f_begin = NewFile(outfile, "w", SWIG_output_files());
- if (!f_begin) {
- FileErrorDisplay(outfile);
- SWIG_exit(EXIT_FAILURE);
- }
- f_runtime = NewString("");
- f_init = NewString("");
- f_header = NewString("");
- f_wrappers = NewString("");
- m3makefile = NewString("");
- /* Register file targets with the SWIG file handler */
- Swig_register_filebyname("header", f_header);
- Swig_register_filebyname("wrapper", f_wrappers);
- Swig_register_filebyname("begin", f_begin);
- Swig_register_filebyname("runtime", f_runtime);
- Swig_register_filebyname("init", f_init);
- Swig_register_filebyname("m3rawintf", m3raw_intf.f);
- Swig_register_filebyname("m3rawimpl", m3raw_impl.f);
- Swig_register_filebyname("m3wrapintf", m3wrap_intf.f);
- Swig_register_filebyname("m3wrapimpl", m3wrap_impl.f);
- Swig_register_filebyname("m3makefile", m3makefile);
- swig_types_hash = NewHash();
- String *name = Getattr(n, "name");
- // Make the intermediary class and module class names. The intermediary class name can be set in the module directive.
- Node *optionsnode = Getattr(Getattr(n, "module"), "options");
- if (optionsnode != NIL) {
- String *m3raw_name_tmp = Getattr(optionsnode, "m3rawname");
- if (m3raw_name_tmp != NIL) {
- m3raw_name = Copy(m3raw_name_tmp);
- }
- }
- if (m3raw_name == NIL) {
- m3raw_name = NewStringf("%sRaw", name);
- }
- Setattr(m3wrap_impl.import, m3raw_name, "");
- m3wrap_name = Copy(name);
- proxy_class_def = NewString("");
- proxy_class_code = NewString("");
- m3raw_baseclass = NewString("");
- m3raw_interfaces = NewString("");
- m3raw_class_modifiers = NewString(""); // package access only to the intermediary class by default
- m3raw_imports = NewString("");
- m3raw_cppcasts_code = NewString("");
- m3wrap_modifiers = NewString("public");
- module_baseclass = NewString("");
- module_interfaces = NewString("");
- module_imports = NewString("");
- upcasts_code = NewString("");
- Swig_banner(f_begin);
- Printf(f_runtime, "\n");
- Printf(f_runtime, "#define SWIGMODULA3\n");
- Printf(f_runtime, "\n");
- Swig_name_register("wrapper", "Modula3_%f");
- if (old_variable_names) {
- Swig_name_register("set", "set_%n%v");
- Swig_name_register("get", "get_%n%v");
- }
- Printf(f_wrappers, "\n#ifdef __cplusplus\n");
- Printf(f_wrappers, "extern \"C\" {\n");
- Printf(f_wrappers, "#endif\n\n");
- constant_values = NewHash();
- scanForConstPragmas(n);
- enumeration_coll = NewHash();
- collectEnumerations(enumeration_coll, n);
- /* Emit code */
- Language::top(n);
- // Generate m3makefile
- // This will be unnecessary if SWIG is invoked from Quake.
- {
- File *file = openWriteFile(NewStringf("%sm3makefile", Swig_file_dirname(outfile)));
- Printf(file, "%% automatically generated quake file for %s\n\n", name);
- /* Write the fragments written by '%insert'
- collected while 'top' processed the parse tree */
- Printv(file, m3makefile, NIL);
- Printf(file, "import(\"libm3\")\n");
- //Printf(file, "import_lib(\"%s\",\"/usr/lib\")\n", name);
- Printf(file, "module(\"%s\")\n", m3raw_name);
- Printf(file, "module(\"%s\")\n\n", m3wrap_name);
- if (targetlibrary != NIL) {
- Printf(file, "library(\"%s\")\n", targetlibrary);
- } else {
- Printf(file, "library(\"m3%s\")\n", name);
- }
- Close(file);
- }
- // Generate the raw interface
- {
- File *file = openWriteFile(NewStringf("%s%s.i3", Swig_file_dirname(outfile), m3raw_name));
- emitBanner(file);
- Printf(file, "INTERFACE %s;\n\n", m3raw_name);
- emitImportStatements(m3raw_intf.import, file);
- Printf(file, "\n");
- // Write the interface generated within 'top'
- Printv(file, m3raw_intf.f, NIL);
- Printf(file, "\nEND %s.\n", m3raw_name);
- Close(file);
- }
- // Generate the raw module
- {
- File *file = openWriteFile(NewStringf("%s%s.m3", Swig_file_dirname(outfile), m3raw_name));
- emitBanner(file);
- Printf(file, "MODULE %s;\n\n", m3raw_name);
- emitImportStatements(m3raw_impl.import, file);
- Printf(file, "\n");
- // will be empty usually
- Printv(file, m3raw_impl.f, NIL);
- Printf(file, "BEGIN\nEND %s.\n", m3raw_name);
- Close(file);
- }
- // Generate the interface for the comfort wrappers
- {
- File *file = openWriteFile(NewStringf("%s%s.i3", Swig_file_dirname(outfile), m3wrap_name));
- emitBanner(file);
- Printf(file, "INTERFACE %s;\n", m3wrap_name);
- emitImportStatements(m3wrap_intf.import, file);
- Printf(file, "\n");
- {
- Iterator it = First(enumeration_coll);
- if (it.key != NIL) {
- Printf(file, "TYPE\n");
- }
- for (; it.key != NIL; it = Next(it)) {
- Printf(file, "\n");
- emitEnumeration(file, it.key, it.item);
- }
- }
- // Add the wrapper methods
- Printv(file, m3wrap_intf.f, NIL);
- // Finish off the class
- Printf(file, "\nEND %s.\n", m3wrap_name);
- Close(file);
- }
- // Generate the wrapper routines implemented in Modula 3
- {
- File *file = openWriteFile(NewStringf("%s%s.m3", Swig_file_dirname(outfile), m3wrap_name));
- emitBanner(file);
- if (unsafe_module) {
- Printf(file, "UNSAFE ");
- }
- Printf(file, "MODULE %s;\n\n", m3wrap_name);
- emitImportStatements(m3wrap_impl.import, file);
- Printf(file, "\n");
- // Add the wrapper methods
- Printv(file, m3wrap_impl.f, NIL);
- Printf(file, "\nBEGIN\nEND %s.\n", m3wrap_name);
- Close(file);
- }
- if (upcasts_code)
- Printv(f_wrappers, upcasts_code, NIL);
- Printf(f_wrappers, "#ifdef __cplusplus\n");
- Printf(f_wrappers, "}\n");
- Printf(f_wrappers, "#endif\n");
- // Output a Modula 3 type wrapper class for each SWIG type
- for (Iterator swig_type = First(swig_types_hash); swig_type.item != NIL; swig_type = Next(swig_type)) {
- emitTypeWrapperClass(swig_type.key, swig_type.item);
- }
- Delete(swig_types_hash);
- swig_types_hash = NULL;
- Delete(constant_values);
- constant_values = NULL;
- Delete(enumeration_coll);
- enumeration_coll = NULL;
- Delete(m3raw_name);
- m3raw_name = NULL;
- Delete(m3raw_baseclass);
- m3raw_baseclass = NULL;
- Delete(m3raw_interfaces);
- m3raw_interfaces = NULL;
- Delete(m3raw_class_modifiers);
- m3raw_class_modifiers = NULL;
- Delete(m3raw_imports);
- m3raw_imports = NULL;
- Delete(m3raw_cppcasts_code);
- m3raw_cppcasts_code = NULL;
- Delete(proxy_class_def);
- proxy_class_def = NULL;
- Delete(proxy_class_code);
- proxy_class_code = NULL;
- Delete(m3wrap_name);
- m3wrap_name = NULL;
- Delete(m3wrap_modifiers);
- m3wrap_modifiers = NULL;
- Delete(targetlibrary);
- targetlibrary = NULL;
- Delete(module_baseclass);
- module_baseclass = NULL;
- Delete(module_interfaces);
- module_interfaces = NULL;
- Delete(module_imports);
- module_imports = NULL;
- Delete(upcasts_code);
- upcasts_code = NULL;
- Delete(constantfilename);
- constantfilename = NULL;
- Delete(renamefilename);
- renamefilename = NULL;
- Delete(typemapfilename);
- typemapfilename = NULL;
- /* Close all of the files */
- Dump(f_runtime, f_begin);
- Dump(f_header, f_begin);
- Dump(f_wrappers, f_begin);
- Wrapper_pretty_print(f_init, f_begin);
- Delete(f_header);
- Delete(f_wrappers);
- Delete(f_init);
- Close(f_begin);
- Delete(f_runtime);
- Delete(f_begin);
- return SWIG_OK;
- }
- /* -----------------------------------------------------------------------------
- * emitBanner()
- * ----------------------------------------------------------------------------- */
- void emitBanner(File *f) {
- Printf(f, "(*******************************************************************************\n");
- Swig_banner_target_lang(f, " *");
- Printf(f, "*******************************************************************************)\n\n");
- }
- /* ----------------------------------------------------------------------
- * nativeWrapper()
- * ---------------------------------------------------------------------- */
- virtual int nativeWrapper(Node *n) {
- String *wrapname = Getattr(n, "wrap:name");
- if (!addSymbol(wrapname, n))
- return SWIG_ERROR;
- if (Getattr(n, "type")) {
- Swig_save("nativeWrapper", n, "name", NIL);
- Setattr(n, "name", wrapname);
- native_function_flag = true;
- functionWrapper(n);
- Swig_restore(n);
- native_function_flag = false;
- } else {
- Swig_error(input_file, line_number, "No return type for %%native method %s.\n", Getattr(n, "wrap:name"));
- }
- return SWIG_OK;
- }
- /* ----------------------------------------------------------------------
- * functionWrapper()
- * ---------------------------------------------------------------------- */
- virtual int functionWrapper(Node *n) {
- String *type = nodeType(n);
- String *funcType = Getattr(n, "modula3:functype");
- String *rawname = Getattr(n, "name");
- String *symname = Getattr(n, "sym:name");
- String *capname = capitalizeFirst(symname);
- //String *wname = Swig_name_wrapper(symname);
- //printf("function: %s\n", Char(symname));
- //printf(" purpose: %s\n", Char(funcType));
- if (Strcmp(type, "cdecl") == 0) {
- if (funcType == NIL) {
- // no wrapper needed for plain functions
- emitM3RawPrototype(n, rawname, symname);
- emitM3Wrapper(n, symname);
- } else if (Strcmp(funcType, "method") == 0) {
- Setattr(n, "modula3:funcname", capname);
- emitCWrapper(n, capname);
- emitM3RawPrototype(n, capname, capname);
- emitM3Wrapper(n, capname);
- } else if (Strcmp(funcType, "accessor") == 0) {
- /*
- * Generate the proxy class properties for public member variables.
- * Not for enums and constants.
- */
- if (proxy_flag && wrapping_member_flag && !enum_constant_flag) {
- // Capitalize the first letter in the function name
- Setattr(n, "proxyfuncname", capname);
- Setattr(n, "imfuncname", symname);
- if (hasPrefix(capname, "Set")) {
- Setattr(n, "modula3:setname", capname);
- } else {
- Setattr(n, "modula3:getname", capname);
- }
- emitCWrapper(n, capname);
- emitM3RawPrototype(n, capname, capname);
- emitM3Wrapper(n, capname);
- //proxyClassFunctionHandler(n);
- }
- #ifdef DEBUG
- } else {
- Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "Function type <%s> unknown.\n", Char(funcType));
- #endif
- }
- } else if ((Strcmp(type, "constructor") == 0) || (Strcmp(type, "destructor") == 0)) {
- emitCWrapper(n, capname);
- emitM3RawPrototype(n, capname, capname);
- emitM3Wrapper(n, capname);
- }
- // a Java relict
- #if 0
- if (!(proxy_flag && is_wrapping_class()) && !enum_constant_flag) {
- emitM3Wrapper(n, capname);
- }
- #endif
- Delete(capname);
- return SWIG_OK;
- }
- /* ----------------------------------------------------------------------
- * emitCWrapper()
- *
- * Generate the wrapper in C which calls C++ methods.
- * ---------------------------------------------------------------------- */
- virtual int emitCWrapper(Node *n, const String *wname) {
- String *rawname = Getattr(n, "name");
- String *c_return_type = NewString("");
- String *cleanup = NewString("");
- String *outarg = NewString("");
- String *body = NewString("");
- Hash *throws_hash = NewHash();
- ParmList *l = Getattr(n, "parms");
- SwigType *t = Getattr(n, "type");
- String *symname = Getattr(n, "sym:name");
- if (!Getattr(n, "sym:overloaded")) {
- if (!addSymbol(wname, n)) {
- return SWIG_ERROR;
- }
- }
- // A new wrapper function object
- Wrapper *f = NewWrapper();
- /* Attach the non-standard typemaps to the parameter list. */
- Swig_typemap_attach_parms("ctype", l, f);
- /* Get return types */
- {
- String *tm = getMappedTypeNew(n, "ctype", "");
- if (tm != NIL) {
- Printf(c_return_type, "%s", tm);
- }
- }
- bool is_void_return = (Cmp(c_return_type, "void") == 0);
- if (!is_void_return) {
- Wrapper_add_localv(f, "cresult", c_return_type, "cresult = 0", NIL);
- }
- Printv(f->def, " SWIGEXPORT ", c_return_type, " ", wname, "(", NIL);
- // Emit all of the local variables for holding arguments.
- emit_parameter_variables(l, f);
- /* Attach the standard typemaps */
- emit_attach_parmmaps(l, f);
- Setattr(n, "wrap:parms", l);
- // Generate signature and argument conversion for C wrapper
- {
- Parm *p;
- attachParameterNames(n, "tmap:name", "c:wrapname", "m3arg%d");
- bool gencomma = false;
- for (p = skipIgnored(l, "in"); p; p = skipIgnored(p, "in")) {
- String *arg = Getattr(p, "c:wrapname");
- {
- /* Get the ctype types of the parameter */
- String *c_param_type = getMappedType(p, "ctype");
- // Add parameter to C function
- Printv(f->def, gencomma ? ", " : "", c_param_type, " ", arg, NIL);
- Delete(c_param_type);
- gencomma = true;
- }
- // Get typemap for this argument
- String *tm = getMappedType(p, "in");
- if (tm != NIL) {
- addThrows(throws_hash, "in", p);
- Replaceall(tm, "$input", arg);
- Setattr(p, "emit:input", arg); /*??? */
- Printf(f->code, "%s\n", tm);
- p = Getattr(p, "tmap:in:next");
- } else {
- p = nextSibling(p);
- }
- }
- }
- /* Insert constraint checking code */
- {
- Parm *p;
- for (p = l; p;) {
- String *tm = Getattr(p, "tmap:check");
- if (tm != NIL) {
- addThrows(throws_hash, "check", p);
- Replaceall(tm, "$target", Getattr(p, "lname")); /* deprecated */
- Replaceall(tm, "$arg", Getattr(p, "emit:input")); /* deprecated? */
- Replaceall(tm, "$input", Getattr(p, "emit:input"));
- Printv(f->code, tm, "\n", NIL);
- p = Getattr(p, "tmap:check:next");
- } else {
- p = nextSibling(p);
- }
- }
- }
- /* Insert cleanup code */
- {
- Parm *p;
- for (p = l; p;) {
- String *tm = Getattr(p, "tmap:freearg");
- if (tm != NIL) {
- addThrows(throws_hash, "freearg", p);
- Replaceall(tm, "$source", Getattr(p, "emit:input")); /* deprecated */
- Replaceall(tm, "$arg", Getattr(p, "emit:input")); /* deprecated? */
- Replaceall(tm, "$input", Getattr(p, "emit:input"));
- Printv(cleanup, tm, "\n", NIL);
- p = Getattr(p, "tmap:freearg:next");
- } else {
- p = nextSibling(p);
- }
- }
- }
- /* Insert argument output code */
- {
- Parm *p;
- for (p = l; p;) {
- String *tm = Getattr(p, "tmap:argout");
- if (tm != NIL) {
- addThrows(throws_hash, "argout", p);
- Replaceall(tm, "$source", Getattr(p, "emit:input")); /* deprecated */
- Replaceall(tm, "$target", Getattr(p, "lname")); /* deprecated */
- Replaceall(tm, "$arg", Getattr(p, "emit:input")); /* deprecated? */
- Replaceall(tm, "$result", "cresult");
- Replaceall(tm, "$input", Getattr(p, "emit:input"));
- Printv(outarg, tm, "\n", NIL);
- p = Getattr(p, "tmap:argout:next");
- } else {
- p = nextSibling(p);
- }
- }
- }
- // Get any Modula 3 exception classes in the throws typemap
- ParmList *throw_parm_list = NULL;
- if ((throw_parm_list = Getattr(n, "catchlist"))) {
- Swig_typemap_attach_parms("throws", throw_parm_list, f);
- Parm *p;
- for (p = throw_parm_list; p; p = nextSibling(p)) {
- addThrows(throws_hash, "throws", p);
- }
- }
- if (Cmp(nodeType(n), "constant") == 0) {
- // Wrapping a constant hack
- Swig_save("functionWrapper", n, "wrap:action", NIL);
- // below based on Swig_VargetToFunction()
- SwigType *ty = Swig_wrapped_var_type(Getattr(n, "type"), use_naturalvar_mode(n));
- Setattr(n, "wrap:action", NewStringf("%s = (%s)(%s);", Swig_cresult_name(), SwigType_lstr(ty, 0), Getattr(n, "value")));
- }
- Setattr(n, "wrap:name", wname);
- // Now write code to make the function call
- if (!native_function_flag) {
- String *actioncode = emit_action(n);
- if (Cmp(nodeType(n), "constant") == 0) {
- Swig_restore(n);
- }
- /* Return value if necessary */
- String *tm;
- if ((tm = Swig_typemap_lookup_out("out", n, Swig_cresult_name(), f, actioncode))) {
- addThrows(throws_hash, "out", n);
- Replaceall(tm, "$source", Swig_cresult_name()); /* deprecated */
- Replaceall(tm, "$target", "cresult"); /* deprecated */
- Replaceall(tm, "$result", "cresult");
- Printf(f->code, "%s", tm);
- if (hasContent(tm))
- Printf(f->code, "\n");
- } else {
- Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(t, 0), rawname);
- }
- emit_return_variable(n, t, f);
- }
- /* Output argument output code */
- Printv(f->code, outarg, NIL);
- /* Output cleanup code */
- Printv(f->code, cleanup, NIL);
- /* Look to see if there is any newfree cleanup code */
- if (GetFlag(n, "feature:new")) {
- String *tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0);
- if (tm != NIL) {
- addThrows(throws_hash, "newfree", n);
- Replaceall(tm, "$source", Swig_cresult_name()); /* deprecated */
- Printf(f->code, "%s\n", tm);
- }
- }
- /* See if there is any return cleanup code */
- if (!native_function_flag) {
- String *tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0);
- if (tm != NIL) {
- Replaceall(tm, "$source", Swig_cresult_name()); /* deprecated */
- Printf(f->code, "%s\n", tm);
- }
- }
- /* Finish C wrapper */
- Printf(f->def, ") {");
- if (!is_void_return)
- Printv(f->code, " return cresult;\n", NIL);
- Printf(f->code, "}\n");
- /* Substitute the cleanup code */
- Replaceall(f->code, "$cleanup", cleanup);
- /* Substitute the function name */
- Replaceall(f->code, "$symname", symname);
- if (!is_void_return) {
- Replaceall(f->code, "$null", "0");
- } else {
- Replaceall(f->code, "$null", "");
- }
- /* Dump the function out */
- if (!native_function_flag) {
- Wrapper_print(f, f_wrappers);
- }
- Delete(c_return_type);
- Delete(cleanup);
- Delete(outarg);
- Delete(body);
- Delete(throws_hash);
- DelWrapper(f);
- return SWIG_OK;
- }
- /* ----------------------------------------------------------------------
- * emitM3RawPrototype()
- *
- * Generate an EXTERNAL procedure declaration in Modula 3
- * which is the interface to an existing C routine or a C wrapper.
- * ---------------------------------------------------------------------- */
- virtual int emitM3RawPrototype(Node *n, const String *cname, const String *m3name) {
- String *im_return_type = NewString("");
- //String *symname = Getattr(n,"sym:name");
- ParmList *l = Getattr(n, "parms");
- /* Attach the non-standard typemaps to the parameter list. */
- Swig_typemap_attach_parms("m3rawinmode", l, NULL);
- Swig_typemap_attach_parms("m3rawintype", l, NULL);
- /* Get return types */
- bool has_return;
- {
- String *tm = getMappedTypeNew(n, "m3rawrettype", "");
- if (tm != NIL) {
- Printf(im_return_type, "%s", tm);
- …
Large files files are truncated, but you can click here to view the full file