From 6b28f547f3428e29d01fc0f51b4c0532db45f859 Mon Sep 17 00:00:00 2001 From: Dave Beazley Date: Mon, 18 Dec 2000 02:51:11 +0000 Subject: [PATCH] SWIG1.1 directory destroyed git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@956 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/SWIG1.1/Makefile.in | 73 - Source/SWIG1.1/README | 7 - Source/SWIG1.1/cplus.cxx | 2129 ----------------------- Source/SWIG1.1/emit.cxx | 257 --- Source/SWIG1.1/internal.h | 64 - Source/SWIG1.1/lang.cxx | 418 ----- Source/SWIG1.1/main.cxx | 534 ------ Source/SWIG1.1/parser.yxx | 3343 ------------------------------------ Source/SWIG1.1/scanner.cxx | 1119 ------------ Source/SWIG1.1/swig11.h | 171 -- 10 files changed, 8115 deletions(-) delete mode 100644 Source/SWIG1.1/Makefile.in delete mode 100644 Source/SWIG1.1/README delete mode 100644 Source/SWIG1.1/cplus.cxx delete mode 100644 Source/SWIG1.1/emit.cxx delete mode 100644 Source/SWIG1.1/internal.h delete mode 100644 Source/SWIG1.1/lang.cxx delete mode 100644 Source/SWIG1.1/main.cxx delete mode 100644 Source/SWIG1.1/parser.yxx delete mode 100644 Source/SWIG1.1/scanner.cxx delete mode 100644 Source/SWIG1.1/swig11.h diff --git a/Source/SWIG1.1/Makefile.in b/Source/SWIG1.1/Makefile.in deleted file mode 100644 index 4a2e8620d..000000000 --- a/Source/SWIG1.1/Makefile.in +++ /dev/null @@ -1,73 +0,0 @@ -####################################################################### -# $Header$ -####################################################################### - -srcdir = @srcdir@ -VPATH = @srcdir@ - -SHELL = /bin/sh -CXX = @CXX@ -CFLAGS = @CFLAGS@ -YACC = @YACC@ -AR = @AR@ -RANLIB = @RANLIB@ - -TARGET = libswig11.a - -OBJS = parser.o main.o scanner.o \ - emit.o cplus.o lang.o - -SRCS = main.cxx scanner.cxx \ - emit.cxx cplus.cxx lang.cxx - -PARSER = $(srcdir)/parser.yxx -INCLUDE = -I$(srcdir)/../Include \ - -I$(srcdir)/. \ - -I$(srcdir)/../Swig \ - -I$(srcdir)/../Preprocessor \ - -I$(srcdir)/../DOH/Include \ - -I../Include \ - -I. - -# Rules for creation of a .o file from .cxx -.SUFFIXES: .cxx -.cxx.o: - $(CXX) $(INCLUDE) $(CFLAGS) -c -o $*.o $< - -swig: $(TARGET) - -$(TARGET): $(OBJS) - $(AR) cr $(TARGET) $(OBJS) - $(RANLIB) $(TARGET) - -parser.o: parser.cxx - $(CXX) $(INCLUDE) $(CFLAGS) $< -c -o parser.o - -parser.cxx parser.h: $(PARSER) - $(YACC) @YFLAGS@ $(PARSER) - @cp y.tab.h parser.h - @cp y.tab.c parser.cxx - -scanner.o: parser.h - -parser:: - @cp y.tab.c.bison parser.cxx - @cp y.tab.h.bison parser.h - @cp y.tab.h.bison y.tab.h - $(CXX) $(CFLAGS) parser.cxx -c -o parser.o - -clean:: - rm -f *.o $(TARGET) y.tab.c y.tab.h - -nuke:: - rm -f Makefile *~ #* core a.out - - - - - - - - - - diff --git a/Source/SWIG1.1/README b/Source/SWIG1.1/README deleted file mode 100644 index 8afca3823..000000000 --- a/Source/SWIG1.1/README +++ /dev/null @@ -1,7 +0,0 @@ -2/10/00 - -This is the old SWIG1.1 core written in C++. This is a real mess -and in the process of being deprecated. Please bear with us. - --- Dave - diff --git a/Source/SWIG1.1/cplus.cxx b/Source/SWIG1.1/cplus.cxx deleted file mode 100644 index 0d9bdafc7..000000000 --- a/Source/SWIG1.1/cplus.cxx +++ /dev/null @@ -1,2129 +0,0 @@ -/* ----------------------------------------------------------------------------- - * cplus.cxx - * - * This file contains code for C++ support in SWIG1.1. Beware! - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 1998-2000. The University of Chicago - * Copyright (C) 1995-1998. The University of Utah and The Regents of the - * University of California. - * - * See the file LICENSE for information on usage and redistribution. - * ----------------------------------------------------------------------------- */ - -#include "internal.h" -extern "C" { -#include "swig.h" -} - -static char cvstag[] = "$Header$"; - -/******************************************************************************* - * Note: - * - * The control flow in this module is completely insane. But here's the - * rough outline. - * - * Stage 1 : SWIG Parsing - * cplus_open_class() - Open up a new class - * cplus_* - Add members to class - * cplus_inherit() - Inherit from base classes - * cplus_class_close() - Close class - * - * ... - * cplus_open_class() - * ... - * cplus_class_close() - * - * ... and so on, until the end of the file - * - * After stage 1, all classes have been read, but nothing has been - * sent to the language module yet. - * - * Stage 2 : Code generation - * For each class we've saved, do this : - * lang->cpp_open_class() - Open class - * lang->cpp_* - Emit members - * lang->cpp_inherit() - Inherit - * lang->cpp_close_class() - Close class - * - * This two-stage approach solves a number of problems related to working - * with multiple files, mutually referenced classes, add adding methods. - * Just keep in mind that all C++ code is emitted *after* an entire SWIG - * file has been parsed. - * - * Improved code generation and inheritance of added methods (2/18/97): - * - * Each C++ declaration now has an associated function name attached to it. - * For example : - * - * class Foo { - * void bar(); - * } - * - * Generates a member function "bar()" with a accessor function named - * "Foo_bar()". We will use this recorded accessor function to generate - * better code for inheritance. For example : - * - * class Foo2 : public Foo { - * - * ... - * } - * - * Will create a function called "Foo2_bar()" that is really mapped - * onto the base-class method "Foo_bar()". This should improve - * code generation substantially. - * - * Tricky stuff : - * - Each target language is responsible for naming wrapper - * functions. - * - *******************************************************************************/ - - -// Some status variables - -static int Inherit_mode = 0; // Set if we're inheriting members -static char *ccode = 0; // Set to optional C code (if available) -static DOHHash *localtypes = 0; // Localtype hash -static int abstract =0; // Status bit set during code generation -int IsVirtual = 0; - -static int cpp_id = 0; - -// Forward references - -void cplus_member_func(char *, char *, SwigType *, ParmList *, int); -void cplus_constructor(char *, char *, ParmList *); -void cplus_destructor(char *, char *); -void cplus_variable(char *, char *, SwigType *); -void cplus_static_func(char *, char *, SwigType *, ParmList *); -void cplus_declare_const(char *, char *, SwigType *, char *); -void cplus_static_var(char *, char *, SwigType *); -void cplus_inherit_decl(char **); - -// ----------------------------------------------------------------------------- -// void add_local_type(char *type, char *classname) -// void add_local_type(SwigType *type, char *classname) -// -// Adds a new datatype to the local datatype hash. This is used to handle -// datatypes defined within a class. -// ----------------------------------------------------------------------------- - -static void add_local_type(char *type, char *classname) { - char str[1024]; - if (!localtypes) return; // No hash table initialized, ignore this - sprintf(str,"%s::%s",classname,type); - Setattr(localtypes,type,str); -} - -void add_local_type(SwigType *type, char *classname) { - add_local_type(Char(type),classname); -} - -// ----------------------------------------------------------------------------- -// void update_local_type(SwigType *type) -// -// Checks to see whether this datatype is part of a class definition. If so, -// we update the type-name by appending the class prefix to it. Uses the -// name stored in current_class unless unavailable. -// ----------------------------------------------------------------------------- - -static void update_local_type(SwigType *type) { - - char *newname = 0; - - // Lookup the datatype in the hash table - - if (!localtypes) return; - - newname = GetChar(localtypes,SwigType_base(type)); - if (newname) { - SwigType_setbase(type,newname); - } -} - -// ----------------------------------------------------------------------------- -// void update_parms(ParmList *l) -// -// Updates all of the parameters in a parameter list with the proper C++ prefix -// (if neccessary). -// ----------------------------------------------------------------------------- - -static void update_parms(ParmList *p) { - while (p) { - SwigType *pt = Gettype(p); - DOHString *pvalue = Getvalue(p); - - update_local_type(pt); - - // Check for default arguments - - if ((pvalue) && (localtypes)) { - char *s; - s = (char *) GetChar(localtypes,pvalue); - if (s) { - Setvalue(p,s); - } - } - p = Getnext(p); - } -} - -// ----------------------------------------------------------------------- -// class CPP_member -// -// Base class for various kinds of C++ members -// ----------------------------------------------------------------------- -class CPP_member { -public: - char *name; // Name of the member - char *iname; // Name of member in the interpreter - int is_static; // Is this a static member? - int is_virtual; // Is this virtual? - int new_method; // Is this a new method (added by SWIG)? - int line; // What line number was this member on - char *file; // What file was this in? - char *code; // Was there any supplied code? - char *base; // Base class where this was defined - int inherited; // Was this member inherited? - CPP_member *next; // Next member (for building linked lists) - String *signature; - - CPP_member() { - signature = 0; - is_static = 0; - is_virtual = 0; - base = 0; - code = 0; - file = 0; - next = 0; - } - virtual void inherit(int) { }; // Inheritance rule (optional) - virtual void emit() = 0; // Emit rule -}; - -// ---------------------------------------------------------------------- -// class CPP_function : public CPP_member -// -// Structure for handling a C++ member function -// ---------------------------------------------------------------------- - -class CPP_function : public CPP_member { -public: - SwigType *ret_type; - ParmList *parms; - int new_object; - - CPP_function(char *n, char *i, SwigType *t, ParmList *l, int s, int v = 0) { - name = Swig_copy_string(n); - iname = Swig_copy_string(i); - ret_type = Copy(t); - parms = CopyParmList(l); - is_static = s; - is_virtual = v; - new_method = AddMethods; - new_object = NewObject; - inherited = Inherit_mode; - next = 0; - line = line_number; - file = input_file; - signature = NewStringf("%s(%s)", n, ParmList_str(l)); - if (AddMethods) { - if (strlen(Char(CCode))) - code = Swig_copy_string(Char(CCode)); - else - code = 0; - } else { - code = 0; - } - } - void inherit(int mode) { - if (mode & INHERIT_FUNC) { - // Set up the proper addmethods mode and provide C code (if provided) - int oldaddmethods = AddMethods; - int oldnewobject = NewObject; - AddMethods = new_method; - NewObject = new_object; - Clear(CCode); - Append(CCode,code); - if (is_static) { - cplus_static_func(name, iname, ret_type, parms); - } else { - cplus_member_func(name, iname, ret_type, parms, is_virtual); - } - AddMethods = oldaddmethods; - NewObject = oldnewobject; - Clear(CCode); - } - } - void emit() { - ParmList *l; - SwigType *t; - AddMethods = new_method; - NewObject = new_object; - line_number = line; // Restore line and file - input_file = file; - ccode = code; - IsVirtual = is_virtual; - - // Make a copy of the parameter list and upgrade its types - - l = CopyParmList(parms); - t = Copy(ret_type); - update_parms(l); - update_local_type(t); - if (is_static) { - DOH *node = NewHash(); - Setattr(node,"name",name); - Setattr(node,"scriptname",iname); - Setattr(node,"type",t); - Setattr(node,"parms",l); - lang->cpp_staticfunction(node); - Delete(node); - } else { - DOH *node = NewHash(); - Setattr(node,"name",name); - Setattr(node,"scriptname",iname); - Setattr(node,"type",t); - Setattr(node,"parms",l); - lang->cpp_memberfunction(node); - Delete(node); - } - Delete(l); - Delete(t); - IsVirtual = 0; - } -}; - -// -------------------------------------------------------------------------- -// class CPP_constructor : public CPP_member -// -// Class for holding a C++ constructor definition. -// -------------------------------------------------------------------------- - -class CPP_constructor : public CPP_member { -public: - ParmList *parms; - CPP_constructor(char *n, char *i, ParmList *l) { - name = Swig_copy_string(n); - iname = Swig_copy_string(i); - parms = CopyParmList(l); - new_method = AddMethods; - inherited = 0; - next = 0; - line = line_number; - file = input_file; - if (AddMethods) { - if (strlen(Char(CCode))) - code = Swig_copy_string(Char(CCode)); - else - code = 0; - } else { - code = 0; - } - } - void emit() { - if (1) { - ParmList *l; - AddMethods = new_method; - line_number = line; - input_file = file; - ccode = code; - - if (abstract) return; - // Make a copy of the parameter list and upgrade its types - - l = CopyParmList(parms); - update_parms(l); - Hash *node = NewHash(); - Setattr(node,"name",name); - Setattr(node,"scriptname",iname); - Setattr(node,"parms",l); - lang->cpp_constructor(node); - Delete(node); - Delete(l); - } - } -}; - - -// -------------------------------------------------------------------------- -// class CPP_destructor : public CPP_member -// -// Class for holding a destructor definition -// -------------------------------------------------------------------------- - -class CPP_destructor : public CPP_member { -public: - - CPP_destructor(char *n, char *i) { - name = Swig_copy_string(n); - iname = Swig_copy_string(i); - new_method = AddMethods; - next = 0; - inherited = 0; - line = line_number; - file = input_file; - if (AddMethods) { - if (strlen(Char(CCode))) - code = Swig_copy_string(Char(CCode)); - else - code = 0; - } else { - code = 0; - } - - } - - void inherit(int mode) { - // Set up the proper addmethods mode and provide C code (if provided) - int oldaddmethods = AddMethods; - AddMethods = new_method; - Clear(CCode); - Append(CCode,code); - cplus_destructor(name,iname); - AddMethods = oldaddmethods; - Clear(CCode); - } - - void emit() { - AddMethods = new_method; - line_number = line; - input_file = file; - ccode = code; - Hash *node = NewHash(); - Setattr(node,"name",name); - Setattr(node,"scriptname",iname); - lang->cpp_destructor(node); - Delete(node); - } -}; - -// ------------------------------------------------------------------------- -// class CPP_variable : public CPP_member -// -// Class for a managing a data member -// ------------------------------------------------------------------------- - -class CPP_variable : public CPP_member { -public: - SwigType *type; - int status; - CPP_variable(char *n, char *i, SwigType *t, int s) { - name = Swig_copy_string(n); - iname = Swig_copy_string(i); - type = Copy(t); - is_static = s; - status = Status; - next = 0; - new_method = AddMethods; - line = line_number; - file = input_file; - code = 0; - inherited = 0; - } - - // Emit code for this - - void emit() { - SwigType *t; - int old_status = Status; - AddMethods = new_method; - Status = status; - line_number = line; - input_file = file; - ccode = code; - - t = Copy(type); - update_local_type(t); - /* Check to see if it's read-only */ - if (SwigType_isarray(t) || SwigType_isconst(t)) { - if (!(Swig_typemap_search("memberin",t,name))) - Status = Status | STAT_READONLY; - } - - if (!is_static) { - DOH *node = NewHash(); - Setattr(node,"name",name); - Setattr(node,"scriptname",iname); - Setattr(node,"type",t); - lang->cpp_variable(node); - Delete(node); - } else { - DOH *node = NewHash(); - Setattr(node,"name",name); - Setattr(node,"scriptname",iname); - Setattr(node,"type",t); - lang->cpp_staticvariable(node); - Delete(node); - } - Status = old_status; - Delete(t); - } - - // Inherit into another class - - void inherit(int mode) { - int oldstatus = Status; - Status = status; - if (mode & INHERIT_VAR) { - if (!is_static) { - int oldaddmethods = AddMethods; - AddMethods = new_method; - Clear(CCode); - Append(CCode,code); - cplus_variable(name,iname,type); - AddMethods = oldaddmethods; - Clear(CCode); - } else { - cplus_static_var(name,iname,type); - } - } - Status = oldstatus; - } -}; - -// ------------------------------------------------------------------------- -// class CPP_constant : public CPP_member -// -// Class for managing constant values -// ------------------------------------------------------------------------- - -class CPP_constant : public CPP_member { -public: - char *value; - SwigType *type; - CPP_constant(char *n, char *i, SwigType *t, char *v) { - name = Swig_copy_string(n); - iname = Swig_copy_string(i); - type = Copy(t); - value = Swig_copy_string(v); - new_method = AddMethods; - next = 0; - line = line_number; - file = input_file; - code = 0; - inherited = 0; - } - - void emit() { - AddMethods = new_method; - line_number = line; - input_file = file; - ccode = code; - DOH *node = NewHash(); - Setattr(node,"name",name); - Setattr(node,"scriptname", iname); - Setattr(node,"type",type); - Setattr(node,"value",value); - lang->cpp_constant(node); - Delete(node); - } - - void inherit(int mode) { - if (mode & INHERIT_CONST) - cplus_declare_const(name, iname, type, value); - } -}; - -// ---------------------------------------------------------------------- -// class CPP_class -// -// Class for managing class members (internally) -// ---------------------------------------------------------------------- - -static char *inherit_base_class = 0; - -class CPP_class { -public: - char *classname; // Real class name - char *classrename; // New name of class (if applicable) - char *classtype; // class type (struct, union, class) - int strip; // Strip off class declarator - int wextern; // Value of extern wrapper variable for this class - int have_constructor; // Status bit indicating if we've seen a constructor - int have_destructor; // Status bit indicating if a destructor has been seen - int is_abstract; // Status bit indicating if this is an abstract class - int generate_default; // Generate default constructors - int objective_c; // Set if this is an objective C class - int error; // Set if this class can't be generated - int line; // Line number - char **baseclass; // Base classes (if any) - DOHHash *local; // Hash table for local types - void *scope; // Local scope hash table - CPP_member *members; // Linked list of members - CPP_class *next; // Next class - static CPP_class *classlist; // List of all classes stored - Pragma *pragmas; // Class pragmas - - CPP_class(char *name, char *ctype) { - CPP_class *c; - classname = Swig_copy_string(name); - classtype = Swig_copy_string(ctype); - classrename = 0; - baseclass = 0; - local = NewHash(); // Create hash table for storing local datatypes - scope = 0; - error = 0; - pragmas = 0; - line = line_number; - - // Walk down class list and add to end - - c = classlist; - if (c) { - while (c->next) { - c = c->next; - } - c->next = this; - } else { - classlist = this; - } - next = 0; - members = 0; - strip = 0; - wextern = WrapExtern; - have_constructor = 0; - have_destructor = 0; - is_abstract = 0; - generate_default = GenerateDefault; - objective_c = ObjCClass; - } - - // ------------------------------------------------------------------------------ - // Add a new C++ member to this class - // ------------------------------------------------------------------------------ - - void add_member(CPP_member *m) { - CPP_member *cm; - - // Set base class where this was defined - if (inherit_base_class) - m->base = inherit_base_class; - else - m->base = classname; - if (!members) { - members = m; - return; - } - cm = members; - while (cm->next) { - cm = cm->next; - } - cm->next = m; - } - // ------------------------------------------------------------------------------ - // Search for a member with the given name. Returns the member on success, 0 on failure - // ------------------------------------------------------------------------------ - - CPP_member *search_member(char *name) { - CPP_member *m; - char *c; - m = members; - while (m) { - c = m->iname ? m->iname : m->name; - if (strcmp(c,name) == 0) return m; - m = m->next; - } - return 0; - } - - // ------------------------------------------------------------------------------ - // Inherit. Put all the declarations associated with this class into the current - // ------------------------------------------------------------------------------ - - void inherit_decls(int mode) { - CPP_member *m; - m = members; - while (m) { - inherit_base_class = m->base; - m->inherit(mode); - m = m->next; - } - inherit_base_class = 0; - } - - // ------------------------------------------------------------------------------ - // Emit all of the declarations associated with this class - // ------------------------------------------------------------------------------ - - void emit_decls() { - CPP_member *m = members; - abstract = is_abstract; - /* Printf(stdout,"class %s. Abstract = %d\n", classname, is_abstract); */ - while (m) { - m->emit(); - m = m->next; - } - } - - // ------------------------------------------------------------------------------ - // Search for a given class in the list - // ------------------------------------------------------------------------------ - - static CPP_class *search(char *name) { - CPP_class *c; - c = classlist; - if (!name) return 0; - while (c) { - if (strcmp(name,c->classname) == 0) return c; - c = c->next; - } - return 0; - } - - // ------------------------------------------------------------------------------ - // Add default constructors and destructors - // - // ------------------------------------------------------------------------------ - - void create_default() { - if (!generate_default) return; - - // Try to generate a constructor if not available. - Clear(CCode); - AddMethods = 0; - if ((!have_constructor) && (1)) { - cplus_constructor(classname,0,0); - }; - - if (!have_destructor) { - cplus_destructor(classname,0); - } - } - - // ------------------------------------------------------------------------------ - // Dump *all* of the classes saved out to the various - // language modules (this does what cplus_close_class used to do) - // ------------------------------------------------------------------------------ - static void create_all(); -}; - -CPP_class *CPP_class::classlist = 0; -static CPP_class *current_class; - -void CPP_class::create_all() { - CPP_class *c; - c = classlist; - while (c) { - if (!c->error) { - current_class = c; - localtypes = c->local; - if ((!c->wextern) && (c->classtype)) { - ObjCClass = c->objective_c; - lang->cpp_open_class(c->classname,c->classrename,c->classtype,c->strip); - lang->cpp_pragma(c->pragmas); - c->create_default(); - if (c->baseclass) - cplus_inherit_decl(c->baseclass); - c->emit_decls(); - lang->cpp_close_class(); - } - } - c = c->next; - } -} - -// ----------------------------------------------------------------------------- -// char *cplus_base_class(char *name) -// -// Given a member name, return the base class that it belongs to. -// ----------------------------------------------------------------------------- - -char *cplus_base_class(char *name) { - CPP_member *m = current_class->search_member(name); - if (m) { - return m->base; - } - return 0; -} - -// ----------------------------------------------------------------------------- -// void cplus_open_class(char *name, char *rname, char *ctype) -// -// Opens up a new C++ class. If rname is given, we'll be renaming the -// class. This also sets up some basic type equivalence for the -// type checker. -// -// Inputs : -// name = Name of the class -// rname = New name of the class (using %name() directive) -// ctype = Class type ("class","struct", or "union") -// -// Side Effects : -// Creates a new class obect internally. -// Added type-mappings to the SWIG type-checker module. -// Sets a number of internal state variables for later use. -// -// ----------------------------------------------------------------------------- - -void cplus_open_class(char *name, char *rname, char *ctype) { - - char temp[256]; - CPP_class *c; - - // Add some symbol table management here - - // Search for a previous class definition - - c = CPP_class::search(name); - if (c) { - if (c->classtype) { - // Hmmm. We already seem to have defined this class so we'll - // create a new class object for whatever reason - current_class = new CPP_class(name, ctype); - } else { - // Looks like a reference was made to this class earlier - // somehow, but no other information is known. We'll - // make it our current class and fix it up a bit - current_class = c; - c->classtype = Swig_copy_string(ctype); - } - } else { - // Create a new class - current_class = new CPP_class(name, ctype); - } - - // Set localtypes hash to our current class - - localtypes = current_class->local; - - // If renaming the class, set the new name - - if (rname) { - current_class->classrename = Swig_copy_string(rname); - } - - // Make a typedef for both long and short versions of this datatype - - if (name) { - if (strlen(name)) { - if (strlen(ctype) > 0) { - sprintf(temp,"%s %s", ctype, name); - // typeeq_derived(temp,name,0); // Map "struct foo" to "foo" - //typeeq_derived(name,temp,0); // Map "foo" to "struct foo" - } - } - } - - AddMethods = 0; // Reset add methods flag - -} - -// ----------------------------------------------------------------------------- -// void cplus_set_class(char *name) -// -// This function sets the current class to a given name. If the class -// doesn't exist, this function will create one. If it already exists, -// we'll just use that. -// -// This function is used primarily to add or manipulate an already -// existing class, but in a different location. For example : -// -// %include "class.h" // Grab some classes -// ... -// %addmethods MyClass { // Add some members for shadow classes -// ... members ... -// } -// -// ----------------------------------------------------------------------------- - -void cplus_set_class(char *name) { - - CPP_class *c; - - // Look for a previous class definition - - c = CPP_class::search(name); - if (c) { - current_class = c; - localtypes = c->local; - } else { - Printf(stderr,"%s:%d: Warning class %s undefined.\n",input_file,line_number,name); - current_class = new CPP_class(name,0); - localtypes = current_class->local; - } -}; - -// This function closes a class open with cplus_set_class() - -void cplus_unset_class() { - current_class = 0; -} - -// ----------------------------------------------------------------------------- -// void cplus_class_close(char *name) -// -// Close a C++ class definition. Up to this point, we've only been collecting -// member definitions. This function merely closes the class object and -// stores it in a list. All classes are dumped after processing has completed. -// -// If name is non-null, it means that the name of the class has actually been -// set after all of the definitions. For example : -// -// typedef struct { -// double x,y,z -// } Vector; -// -// If this is the case, we'll use that as our classname and datatype. -// Otherwise, we'll just go with the classname and classtype set earlier. -// -// Inputs : name = optional "new name" for the class. -// -// Output : None -// -// Side Effects : Resets internal variables. Saves class in internal list. -// Registers the class with the language module, but doesn't -// emit any code. -// ----------------------------------------------------------------------------- - -void cplus_class_close(char *name) { - - if (name) { - // The name of our class suddenly changed by typedef. Fix things up - current_class->classname = Swig_copy_string(name); - - // This flag indicates that the class needs to have it's type stripped off - current_class->strip = 1; - } - - // If we're in C++ or Objective-C mode. We're going to drop the class specifier - - if ((CPlusPlus) || (ObjCClass)) { - current_class->strip = 1; - } - - // Register our class with the target language module, but otherwise - // don't do anything yet. - - char *iname; - if (current_class->classrename) iname = current_class->classrename; - else iname = current_class->classname; - - lang->cpp_class_decl(current_class->classname, iname, current_class->classtype); - - // Clear current class variable and reset - current_class = 0; - localtypes = 0; - -} - -// ----------------------------------------------------------------------------- -// void cplus_abort(void) -// -// Voids the current class--some kind of unrecoverable parsing error occurred. -// ----------------------------------------------------------------------------- - -void cplus_abort(void) { - current_class->error = 1; - current_class = 0; - localtypes = 0; -} - -// ----------------------------------------------------------------------------- -// void cplus_cleanup(void) -// -// This function is called after all parsing has been completed. It dumps all -// of the stored classes out to the language module. -// -// Inputs : None -// -// Output : None -// -// Side Effects : Emits all C++ wrapper code. -// ----------------------------------------------------------------------------- - -void cplus_cleanup(void) { - - // Dump all classes created at once (yikes!) - - CPP_class::create_all(); - lang->cpp_cleanup(); -} - -// ----------------------------------------------------------------------------- -// void cplus_inherit(int count, char **baseclass) -// -// Inherit from a baseclass. This function only really registers -// the inheritance, but doesn't do anything with it yet. -// -// Inputs : baseclass = A NULL terminated array of strings with the names -// of baseclasses. For multiple inheritance, there -// will be multiple entries in this list. -// -// Output : None -// -// Side Effects : Sets the baseclass variable of the current class. -// ----------------------------------------------------------------------------- - -void cplus_inherit(int count, char **baseclass) { - int i; - - // printf("Inheriting : count = %d, baseclass = %x\n",count,baseclass); - // If there are baseclasses, make copy of them - if (count) { - current_class->baseclass = (char **) new char*[count+1]; - for (i = 0; i < count; i++) - current_class->baseclass[i] = Swig_copy_string(baseclass[i]); - current_class->baseclass[i] = 0; - } else { - baseclass = 0; - } -} - -// ----------------------------------------------------------------------------- -// cplus_generate_types(char **baseclass) -// -// Generates the type-mappings between the current class and any associated -// base classes. This is done by performing a depth first search of the -// class hierarchy. Functions for performing correct type-casting are -// generated for each base-derived class pair. -// -// Inputs : baseclass = NULL terminated list of base classes -// -// Output : None -// -// Side Effects : Emits pointer conversion functions. Registers type-mappings -// with the type checking module. -// -// ----------------------------------------------------------------------------- - -static DOHHash *convert = 0; // Hash table of conversion functions - -void cplus_generate_types(char **baseclass) { - CPP_class *bc; - int i; - DOHString *cfunc; - DOHString *temp3; - char temp1[512], temp2[512]; - - if (!baseclass) { - return; - } - - if (!convert) convert = NewHash(); - - // Generate type-conversion functions and type-equivalence - cfunc = NewString(""); - temp3 = NewString(""); - i = 0; - while(baseclass[i]) { - Clear(cfunc); - - bc = CPP_class::search(baseclass[i]); - if (bc) { - // Generate a conversion function (but only for C++) - - if (!current_class->objective_c) { - Clear(temp3); - Printv(temp3, "Swig", current_class->classname, "To", bc->classname,0); - - if (!Getattr(convert,temp3)) { - SetVoid(convert,temp3,(void*) 1); - - // Write a function for casting derived type to parent class - -#ifdef OLD - Printv(cfunc, - "static void *Swig", current_class->classname, "To", bc->classname, - "(void *ptr) {\n", - tab4, current_class->classname, " *src;\n", - tab4, bc->classname, " *dest;\n", - tab4, "src = (", current_class->classname, " *) ptr;\n", - tab4, "dest = (", bc->classname, " *) src;\n", - tab4, "return (void *) dest;\n", - "}\n", - 0); - Printf(f_wrappers,"%s\n",Char(cfunc)); -#endif - } - } else { - Clear(temp3); - Printf(temp3,"0"); - } - - // Make a type-equivalence allowing derived classes to be used in functions of the - - if (strlen(current_class->classtype) > 0) { - sprintf(temp1,"%s %s", current_class->classtype, current_class->classname); - sprintf(temp2,"%s %s", bc->classtype, bc->classname); - - // Add various equivalences to the pointer table - - // typeeq_derived(bc->classname, current_class->classname,Char(temp3)); - // typeeq_derived(temp2, current_class->classname,Char(temp3)); - // typeeq_derived(temp2, temp1,Char(temp3)); - // typeeq_derived(bc->classname, temp1,Char(temp3)); - } else { - // typeeq_derived(bc->classname, current_class->classname,Char(temp3)); - } - // DataType_record_base(current_class->classname, bc->classname); - SwigType_inherit(current_class->classname, bc->classname); - // Now traverse the hierarchy some more - cplus_generate_types(bc->baseclass); - } - i++; - } - Delete(temp3); - Delete(cfunc); -} - -// ----------------------------------------------------------------------------- -// void cplus_inherit_decl(char **baseclass) -// -// This function is called internally to handle inheritance between classes. -// Basically, we're going to generate type-checking information and call -// out to the target language to handle the inheritance. -// -// This function is only called when emitting classes to the language modules -// (after all parsing has been complete). -// -// Inputs : baseclass = NULL terminated list of base-class names. -// -// Output : None -// -// Side Effects : Generates type-mappings. Calls the language-specific -// inheritance function. -// ----------------------------------------------------------------------------- - -void cplus_inherit_decl(char **baseclass) { - - // If not base-classes, bail out - - if (!baseclass) return; - - Inherit_mode = 1; - lang->cpp_inherit(baseclass); // Pass inheritance onto the various languages - Inherit_mode = 0; - - // Create type-information for class hierarchy - - cplus_generate_types(baseclass); -} -// ----------------------------------------------------------------------------- -// void cplus_inherit_members(char *baseclass, int mode) -// -// Inherits members from a class. This is called by specific language modules -// to bring in members from base classes. It may or may not be called. -// -// This function is called with a *single* base-class, not multiple classes -// like other functions. To do multiple inheritance, simply call this -// with each of the associated base classes. -// -// Inputs : -// baseclass = Name of baseclass -// mode = Inheritance handling flags -// INHERIT_FUNC - Import functions in base class -// INHERIT_VAR - Import variables in base class -// INHERIT_CONST - Inherit constants -// INHERIT_ALL - Inherit everything (grossly inefficient) -// -// Output : None -// -// Side Effects : Imports methods from base-classes into derived classes. -// -// ----------------------------------------------------------------------------- - -void cplus_inherit_members(char *baseclass, int mode) { - CPP_class *bc; - - bc = CPP_class::search(baseclass); - if (bc) { - bc->inherit_decls(mode); - } else { - Printf(stderr,"%s:%d: Warning. Base class %s undefined (ignored).\n", input_file, current_class->line, baseclass); - } -} - -// ----------------------------------------------------------------------------- -// void cplus_member_func(char *name, char *iname, DataType *type, ParmList *, is_virtual) -// -// Parser entry point to creating a C++ member function. This function primarily -// just records the function and does a few symbol table checks. -// -// Inputs : -// name = Real name of the member function -// iname = Renamed version (may be NULL) -// type = Return datatype -// l = Parameter list -// is_virtual = Set if this is a pure virtual function (ignored) -// -// Output : None -// -// Side Effects : -// Adds member function to current class. -// ----------------------------------------------------------------------------- - -void cplus_member_func(char *name, char *iname, SwigType *type, ParmList *l, - int is_virtual) { - - CPP_function *f; - char *temp_iname; - - // First, figure out if we're renaming this function or not - - if (!iname) - temp_iname = name; - else - temp_iname = iname; - - // If we're in inherit mode, we need to check for duplicates. - // Issue a warning. - - if (Inherit_mode) { - CPP_member *m = current_class->search_member(temp_iname); - if (m) { - /* The current member is already part of the class. However, we might be - able to make some "optimizations" if it's virtual */ - - if ((is_virtual) && (m->is_virtual)) { - if (m->signature) { - /* Printf(stdout,"Member : %s, %d, '%s'\n", m->name, m->is_virtual, m->signature); */ - String *ns = NewStringf("%s(%s)", name, ParmList_str(l)); - if (Cmp(ns,m->signature) == 0) { - m->base = Swig_copy_string(inherit_base_class); - } - } - } - return; - } - } - - // Add it to our C++ class list - - f = new CPP_function(name,temp_iname,type,l,0,is_virtual); - current_class->add_member(f); - - // If this is a pure virtual function, the class is abstract - - if (is_virtual == PURE_VIRTUAL) - current_class->is_abstract = 1; - -} - -// ----------------------------------------------------------------------------- -// void cplus_constructor(char *name, char *iname, ParmList *l) -// -// Parser entry point for creating a constructor. -// -// Inputs : -// name = Real name of the constructor (usually the same as the class) -// iname = Renamed version (may be NULL) -// l = Parameter list -// -// Output : None -// -// Side Effects : -// Adds a constructor to the current class. -// ----------------------------------------------------------------------------- - -void cplus_constructor(char *name, char *iname, ParmList *l) { - - CPP_constructor *c; - - // May want to check the naming scheme here - - c = new CPP_constructor(name,iname,l); - current_class->add_member(c); - current_class->have_constructor = 1; - -} - -// ----------------------------------------------------------------------------- -// void cplus_destructor(char *name, char *iname) -// -// Parser entry point for adding a destructor. -// -// Inputs : -// name = Real name of the destructor (usually same as class name) -// iname = Renamed version (may be NULL) -// -// Output : None -// -// Side Effects : -// Adds a destructor to the current class -// -// ----------------------------------------------------------------------------- - -void cplus_destructor(char *name, char *iname) { - - CPP_destructor *d; - - if (current_class->have_destructor) return; - d = new CPP_destructor(name,iname); - current_class->add_member(d); - current_class->have_destructor = 1; -} - -// ----------------------------------------------------------------------------- -// void cplus_variable(char *name, char *iname, SwigType *t) -// -// Parser entry point for creating a new member variable. -// -// Inputs : -// name = name of the variable -// iname = Renamed version (may be NULL) -// t = SwigType -// -// Output : None -// -// Side Effects : -// Adds a member variable to the current class -// ----------------------------------------------------------------------------- - -void cplus_variable(char *name, char *iname, SwigType *t) { - - CPP_variable *v; - char *temp_iname; - - // If we're in inherit mode, we need to check for duplicates. - - if (iname) - temp_iname = iname; - else - temp_iname = name; - - if (Inherit_mode) { - if (current_class->search_member(temp_iname)) { - return; - } - } - - v = new CPP_variable(name,iname,t,0); - current_class->add_member(v); -} - -// ----------------------------------------------------------------------------- -// void cplus_static_func(char *name, char *iname, SwigType *type, ParmList *l) -// -// Parser entry point for creating a new static member function. -// -// Inputs : -// name = Real name of the function -// iname = Renamed version (may be NULL) -// type = Return SwigType -// l = Parameter list -// -// Output : None -// -// Side Effects : -// Adds a static function to the current class. -// -// ----------------------------------------------------------------------------- - -void cplus_static_func(char *name, char *iname, SwigType *type, ParmList *l) { - - char *temp_iname; - - // If we're in inherit mode, we need to check for duplicates. - - if (iname) temp_iname = iname; - else temp_iname = name; - - if (Inherit_mode) { - if (current_class->search_member(iname)) { - // Have a duplication - return; - } - } - - CPP_function *f = new CPP_function(name, temp_iname, type, l, 1); - current_class->add_member(f); -} - -// ----------------------------------------------------------------------------- -// void cplus_declare_const(char *name, char *iname, SwigType *type, char *value) -// -// Parser entry point for creating a C++ constant (usually contained in an -// enum). -// -// Inputs : -// name = Real name of the constant -// iname = Renamed constant (may be NULL) -// type = Datatype of the constant -// value = String representation of the value -// -// Output : None -// -// Side Effects : -// Adds a constant to the current class. -// ----------------------------------------------------------------------------- - -void cplus_declare_const(char *name, char *iname, SwigType *type, char *value) { - - char *temp_iname; - - if (iname) temp_iname = iname; - else temp_iname = name; - - // If we're in inherit mode, we need to check for duplicates. - // Possibly issue a warning or perhaps a remapping - - if (Inherit_mode) { - if (current_class->search_member(temp_iname)) { - return; - } - } - - CPP_constant *c = new CPP_constant(name, temp_iname, type, value); - current_class->add_member(c); - - // Add this symbol to local scope of a class - add_local_type(name, current_class->classname); -} - -// ----------------------------------------------------------------------------- -// void cplus_static_var(char *name, char *iname, SwigType *type) -// -// Parser entry point for adding a static variable -// -// Inputs : -// name = Name of the member -// iname = Renamed version (may be NULL) -// type = Datatype -// -// Output : None -// -// Side Effects : -// Adds a static variable to the current class. -// ----------------------------------------------------------------------------- - -void cplus_static_var(char *name, char *iname, SwigType *type) { - - char *temp_iname; - - if (iname) temp_iname = iname; - else temp_iname = name; - - // If we're in inherit mode, we need to check for duplicates. - // Possibly issue a warning or perhaps a remapping - - if (Inherit_mode) { - if (current_class->search_member(temp_iname)) { - return; - } - } - - CPP_variable *v = new CPP_variable(name, temp_iname, type, 1); - current_class->add_member(v); -} - -// ----------------------------------------------------------------------------- -// cplus_add_pragma(char *lang, char *name, char *value) -// -// Add a pragma to a class -// ----------------------------------------------------------------------------- - -void cplus_add_pragma(char *lang, char *name, char *value) -{ - Pragma *pp; - Pragma *p = new Pragma; - p->filename = NewString(input_file); - p->lang = NewString(lang); - p->name = NewString(name); - p->value = NewString(value); - p->next = 0; - p->lineno = line_number; - - if (!current_class->pragmas) { - current_class->pragmas = p; - return; - } - pp = current_class->pragmas; - while (pp->next) { - pp = pp->next; - } - pp->next = p; -} - -// ------------------------------------------------------------------------------ -// C++/Objective-C code generation functions -// -// The following functions are responsible for generating the wrapper functions -// for C++ and Objective-C methods and variables. These functions are usually -// called by specific language modules, but individual language modules can -// choose to do something else. -// -// The C++ module sets a number of internal state variables before emitting various -// pieces of code. These variables are often checked implicitly by these -// procedures even though nothing is passed on the command line. -// -// The code generator tries to be somewhat intelligent about what its doing. -// The member_hash Hash table keeps track of wrapped members and is used for -// sharing code between base and derived classes. -// ----------------------------------------------------------------------------- - -static DOHHash *member_hash = 0; // Hash wrapping member function wrappers to scripting wrappers - -// ----------------------------------------------------------------------------- -// void cplus_emit_member_func(char *classname, char *classtype, char *classrename, -// char *mname, char *mrename, SwigType *type, -// ParmList *l, int mode) -// -// This is a generic function to produce a C wrapper around a C++ member function. -// This function does the following : -// -// 1. Create a C wrapper function -// 2. Wrap the C wrapper function like a normal C function in SWIG -// 3. Add the function to the scripting language -// 4. Fill in the documentation entry -// -// Specific languages can choose to provide a different mechanism, but this -// function is used to provide a low-level C++ interface. -// -// The mode variable determines whether to create a new function or only to -// add it to the interpreter. This is used to support the %addmethods directive -// -// mode = 0 : Create a wrapper and add it (the normal mode) -// mode = 1 : Assume wrapper was already made and add it to the -// interpreter (%addmethods mode) -// -// Wrapper functions are usually created as follows : -// -// class Foo { -// int bar(args) -// } -// -// becomes .... -// Foo_bar(Foo *obj, args) { -// obj->bar(args); -// } -// -// if %addmethods mode is set AND there is supporting C code detected, make -// a function from it. The object is always called 'obj'. -// -// Then we wrap Foo_bar(). The name "Foo_bar" is actually contained in the parameter -// cname. This is so language modules can provide their own names (possibly for -// function overloading). -// -// This function makes no internal checks of the SWIG symbol table. This is -// up to the caller. -// -// Objective-C support (added 5/24/97) : -// -// If the class member function is part of an objective-C interface, everything -// works the same except that we change the calling mechanism to issue an -// Objective-C message. -// -// Optimizations (added 12/31/97) : -// -// For automatically generated wrapper functions. We now generate macros such -// as -// #define Foo_bar(a,b,c) (a->bar(b,c)) -// -// This should make the wrappers a little faster as well as reducing the amount -// of wrapper code. -// -// Inputs : -// classname = Name of C++ class -// classtype = Type of class (struct, union, class) -// classrename = Renamed class (if any) -// mname = Member name -// mrename = Renamed member -// type = Return type of the function -// l = Parameter list -// mode = addmethods mode -// -// Output : None -// -// Side Effects : -// Creates C accessor function in the wrapper file. -// Calls the language module to create a wrapper function. -// ----------------------------------------------------------------------------- - -void cplus_emit_member_func(char *classname, char *classtype, char *classrename, - char *mname, char *mrename, SwigType *type, ParmList *l, - int mode) { - - Wrapper *w; - char iname[512]; - char fullname[512]; - DOHString *key; - char *prev_wrap = 0; - - key = NewString(""); - - if (classtype) { - sprintf(fullname,"%s%s", classtype, classname); - } else { - strcpy(fullname, classname); - } - - w = Swig_cmethod_wrapper(fullname, mname, type, l, ccode); - - if (!classrename) classrename = classname; - if (!mrename) mrename = mname; - - strcpy(iname, Char(Swig_name_member(classrename, mrename))); - - if (!member_hash) member_hash = NewHash(); - - char *bc = cplus_base_class(mrename); - if (!bc || (strlen(bc) == 0)) { - bc = classname; - } - - /* Printf(key,"%s+%s",Getname(w), ParmList_protostr(l));*/ - Printf(key,"%s+%s", Swig_name_member(bc,mrename), ParmList_protostr(l)); - /* Printf(stdout,"virtual = %d, bc = %s, mkey = %s\n", IsVirtual, bc, key); */ - - if (Getattr(member_hash,key)) { - prev_wrap = GetChar(member_hash,key); - } else { - Setattr(member_hash,key,iname); - } - - if (!prev_wrap) { - if (mode && ccode) { - /* Produce an actual C wrapper */ - Printf(f_wrappers,"%s",w); - } else if (!mode) { - /* Nah. Just produce a string that does the work for us */ - emit_set_action(Swig_cmethod_call(mname, Getparms(w))); - } - Setattr(w,"scriptname",iname); - lang->function(w); - Delete(w); - } else { - lang->create_command(prev_wrap, iname); - } - Delete(key); -} - -// ----------------------------------------------------------------------------- -// void cplus_emit_static_func(char *classname, char *classtype, char *classrename, -// char *mname, char *mrename, SwigType *type, -// ParmList *l, int mode) -// -// This is a generic function to produce a wrapper for a C++ static member function -// or an Objective-C class method. -// -// Specific languages can choose to provide a different mechanism, but this -// function is used to provide a low-level C++ interface. -// -// The mode variable determines whether to create a new function or only to -// add it to the interpreter. This is used to support the %addmethods directive -// -// mode = 0 : Create a wrapper and add it (the normal mode) -// mode = 1 : Assume wrapper was already made and add it to the -// interpreter (%addmethods mode) -// -// Wrapper functions are usually created as follows : -// -// class Foo { -// static int bar(args) -// } -// -// becomes a command called Foo_bar() -// -// if %addmethods mode is set AND there is supporting C code detected, make -// a function from it. -// -// Then we wrap Foo_bar(). The name "Foo_bar" is actually contained in the parameter -// cname. This is so language modules can provide their own names (possibly for -// function overloading). -// -// This function makes no internal checks of the SWIG symbol table. This is -// up to the caller. -// -// Inputs : -// classname = Name of C++ class -// classtype = Type of class (struct, union, class) -// classrename = Renamed version of class (optional) -// mname = Member name -// mrename = Renamed member (optional) -// type = Return type of the function -// l = Parameter list -// mode = addmethods mode -// -// Output : None -// -// ----------------------------------------------------------------------------- - -void cplus_emit_static_func(char *classname, char *, char *classrename, - char *mname, char *mrename, SwigType *type, ParmList *l, - int mode) { - - char cname[512], iname[512]; - DOHString *key; - char *prev_wrap = 0; - - key = NewString(""); - - // Generate a function name for the member function - - if (!mrename) mrename = mname; - char *bc = cplus_base_class(mname); - - if (!bc) bc = classname; - if (strlen(bc) == 0) bc = classname; - - // Generate the name of the C wrapper function - if ((!mode) && (!ObjCClass)) { - sprintf(cname,"%s::%s", bc, mname); - } else { - strcpy(cname,Char(Swig_name_member(bc,mname))); - } - - // Generate the scripting name of this function - if (!classrename) classrename = classname; - strcpy(iname,Char(Swig_name_member(classrename, mrename))); - - // Perform a hash table lookup to see if we've wrapped anything like this before - Printf(key,"%s+%s",cname, ParmList_str(l)); - if (!member_hash) member_hash = NewHash(); - if (Getattr(member_hash,key)) { - prev_wrap = GetChar(member_hash,key); - } else { - Setattr(member_hash,key,iname); - } - - if (!prev_wrap) { - if (!mode) { - // Not an added method and not objective C, just wrap it - new_create_function(cname,iname, type, l); - } else { - if (!ccode) { - strcpy(cname, Char(Swig_name_member(classname,mname))); - new_create_function(cname,iname, type, l); - } else { - Wrapper *w = Swig_cfunction_wrapper(cname, type, l, ccode); - Printf(f_wrappers,"%s", w); - Setattr(w,"scriptname",iname); - lang->function(w); - Delete(w); - } - } - } else { - // Already wrapped this function. Just hook up to it. - lang->create_command(prev_wrap, iname); - } - Delete(key); -} - -// ----------------------------------------------------------------------------- -// void cplus_emit_destructor(char *classname, char *classtype, char *classrename, -// char *mname, char *mrename, int mode) -// -// Emit a C wrapper around a C++ destructor. -// -// Usually this function is used to do the following : -// class Foo { -// ... -// ~Foo(); -// } -// -// becomes .... -// void delete_Foo(Foo *f) { -// delete f; -// } -// -// Then we wrap delete_Foo(). -// -// Inputs : -// classname = Name of the C++ class -// classtype = Type of class (struct,class,union) -// classrename = Renamed class (optional) -// mname = Name of the destructor -// mrename = Name of the function in the interpreter -// mode = addmethods mode (0 or 1) -// -// Output : None -// -// Side Effects : -// Creates a destructor function and wraps it. -// ----------------------------------------------------------------------------- - -void cplus_emit_destructor(char *classname, char *classtype, char *classrename, - char *mname, char *mrename, int mode) -{ - Wrapper *w; - char cname[512],iname[512]; - char fclassname[512]; - - if (!classrename) classrename = classname; - - strcpy(cname,Char(Swig_name_destroy(classname))); - if (mrename) - strcpy(iname, Char(Swig_name_destroy(mrename))); - else - strcpy(iname, Char(Swig_name_destroy(classrename))); - - sprintf(fclassname,"%s%s", classtype, classname); - if (CPlusPlus) { - w = Swig_cppdestructor_wrapper(fclassname,ccode); - } else { - w = Swig_cdestructor_wrapper(fclassname, ccode); - } - Setattr(w,"scriptname",iname); - if (mode && ccode) { - Printf(f_wrappers,"%s",w); - lang->function(w); - } else if (mode) { - lang->function(w); - } else { - if (CPlusPlus) - emit_set_action(Swig_cppdestructor_call()); - else - emit_set_action(Swig_cdestructor_call()); - lang->function(w); - } - Delete(w); -} - -// ----------------------------------------------------------------------------- -// void cplus_emit_constructor(char *classname, char *classtype, char *classrename, -// char *mname, char *mrename, ParmList *l, int mode) -// -// Creates a C wrapper around a C++ constructor -// -// Inputs : -// classname = name of class -// classtype = type of class (struct,class,union) -// classrename = Renamed class (optional) -// mname = Name of constructor -// mrename = Renamed constructor (optional) -// l = Parameter list -// mode = addmethods mode -// -// Output : None -// -// Side Effects : -// Creates a C wrapper and calls the language module to wrap it. -// ----------------------------------------------------------------------------- - -void cplus_emit_constructor(char *classname, char *classtype, char *classrename, - char *mname, char *mrename, ParmList *l, int mode) -{ - char cname[512],iname[512]; - char fclassname[512]; - Wrapper *w; - // Construct names for the function - - if (!classrename) classrename = classname; - strcpy(cname,Char(Swig_name_construct(classname))); - if (mrename) - strcpy(iname, Char(Swig_name_construct(mrename))); - else - strcpy(iname, Char(Swig_name_construct(classrename))); - - sprintf(fclassname,"%s%s", classtype, classname); - - if (CPlusPlus) { - w = Swig_cppconstructor_wrapper(fclassname, l, ccode); - } else { - w = Swig_cconstructor_wrapper(fclassname, l, ccode); - } - Setattr(w,"scriptname",iname); - if (!mode) { - if (CPlusPlus) { - emit_set_action(Swig_cppconstructor_call(fclassname, l)); - } else { - emit_set_action(Swig_cconstructor_call(fclassname)); - } - } else { - if (ccode) { - Printf(f_wrappers,"%s", w); - } - } - lang->function(w); - Delete(w); -} - -// ----------------------------------------------------------------------------- -// void cplus_emit_variable_get(char *classname, char *classtype, char *classrename, -// char *mname, char *mrename, SwigType *type, int mode) -// -// Writes a C wrapper to extract a data member -// -// Usually this function works as follows : -// -// class Foo { -// double x; -// } -// -// becomes : -// -// double Foo_x_get(Foo *obj) { -// return obj->x; -// } -// -// Optimization : 12/31/97 -// -// Now emits a macro like this : -// -// #define Foo_x_get(obj) (obj->x) -// -// Inputs : -// classname = name of C++ class -// classtype = type of class (struct, class, union) -// classrename = Renamed class -// mname = Member name -// mrename = Renamed member -// type = Datatype of the member -// mode = Addmethods mode -// -// Output : None -// -// Side Effects : -// Creates a C accessor function and calls the language module -// to make a wrapper around it. -// ----------------------------------------------------------------------------- - -void cplus_emit_variable_get(char *classname, char *classtype, char *classrename, - char *mname, char *mrename, SwigType *type, int mode) { - - char cname[512],iname[512], fclassname[512]; - char key[512]; - char *prev_wrap = 0; - Wrapper *w; - - // First generate a proper name for the get function - - // Get the base class of this member - if (!mrename) mrename = mname; - - char *bc = cplus_base_class(mrename); - if (!bc) bc = classname; - if (strlen(bc) == 0) bc = classname; - - // Generate the name of the C wrapper function (is always the same, regardless - // of renaming). - - strcpy(cname, Char(Swig_name_get(Swig_name_member(bc,mname)))); - - // Generate the scripting name of this function - if (!classrename) classrename = classname; - strcpy(iname, Char(Swig_name_get(Swig_name_member(classrename,mrename)))); - - // Now check to see if we have already wrapped a variable like this. - - strcpy(key,cname); - if (!member_hash) member_hash = NewHash(); - if (Getattr(member_hash,key)) { - prev_wrap = GetChar(member_hash,key); - } else { - Setattr(member_hash,key,iname); - } - - sprintf(fclassname,"%s%s", classtype, classname); - w = Swig_cmemberget_wrapper(fclassname,mname,type,ccode); - Setattr(w,"scriptname",iname); - // Only generate code if already existing wrapper doesn't exist - if (!prev_wrap) { - if ((mode) && (ccode)) { - Printf(f_wrappers,"%s", w); - } else if (!mode) { - emit_set_action(Swig_cmemberget_call(mname, type)); - } - lang->function(w); - } else { - // Already wrapped this function. Just patch it up - lang->create_command(prev_wrap,iname); - } - Delete(w); -} - -// ----------------------------------------------------------------------------- -// void cplus_emit_variable_set(char *classname, char *classtype, char *mname, -// char *cname, char *iname, SwigType *type, int mode) -// -// Writes a C wrapper to set a data member -// -// Usually this function works as follows : -// -// class Foo { -// double x; -// } -// -// becomes : -// -// double Foo_x_set(Foo *obj, double value) { -// return (obj->x = value); -// } -// -// Need to handle special cases for char * and for user defined types. -// -// 1. char * -// -// Will free previous contents (if any) and allocate -// new storage. Could be risky, but it's a reasonably -// natural thing to do. -// -// 2. User_Defined -// Will assign value from a pointer. -// Will return a pointer to current value. -// -// -// Optimization, now defined as a C preprocessor macro -// -// Inputs : -// classname = name of C++ class -// classtype = type of class (struct, class, union) -// mname = Member name -// cname = Name of the C function for this (ie. Foo_bar_get) -// iname = Interpreter name of ths function -// type = Datatype of the member -// mode = Addmethods mode -// -// Output : None -// -// Side Effects : -// Creates a C accessor function and calls the language module -// to wrap it. -// ----------------------------------------------------------------------------- - -void cplus_emit_variable_set(char *classname, char *classtype, char *classrename, - char *mname, char *mrename, SwigType *type, int mode) { - - char cname[512], iname[512]; - char key[512]; - char fclassname[512]; - char *prev_wrap = 0; - Wrapper *w; - // Get the base class of this member - if (!mrename) mrename = mname; - - char *bc = cplus_base_class(mrename); - if (!bc) bc = classname; - if (strlen(bc) == 0) bc = classname; - - // Generate the name of the C wrapper function (is always the same, regardless - // of renaming). - - strcpy(cname, Char(Swig_name_set(Swig_name_member(bc,mname)))); - - if (!classrename) classrename = classname; - strcpy(iname, Char(Swig_name_set(Swig_name_member(classrename, mrename)))); - - - // Now check to see if we have already wrapped a variable like this. - - strcpy(key,cname); - if (!member_hash) member_hash = NewHash(); - if (Getattr(member_hash,key)) { - prev_wrap = GetChar(member_hash,key); - } else { - Setattr(member_hash,key,iname); - } - - sprintf(fclassname,"%s%s",classtype,classname); - w = Swig_cmemberset_wrapper(fclassname,mname,type,ccode); - - Setattr(w,"scriptname",iname); - // Only generate code if already existing wrapper doesn't exist - - if (!prev_wrap) { - if ((mode) && (ccode)) { - Printf(f_wrappers,"%s",w); - } else if (!mode) { - /* Check for a member in typemap here */ - String *target = NewStringf("%s->%s", Swig_cparm_name(0,0),mname); - char *tm = Swig_typemap_lookup("memberin",type,mname,Swig_cparm_name(0,1),target,0); - if (!tm) - emit_set_action(Swig_cmemberset_call(mname,type)); - else - emit_set_action(tm); - Delete(target); - } - lang->function(w); - } else { - lang->create_command(prev_wrap,iname); - } - Delete(w); -} - -// ----------------------------------------------------------------------------- -// void cplus_register_type(char *typename) -// -// Registers a datatype name to be associated with the current class. This -// typename is placed into a local hash table for later use. For example : -// -// class foo { -// public: -// enum ENUM { ... }; -// typedef double Real; -// void bar(ENUM a, Real b); -// } -// -// Then we need to access bar using fully qualified type names such as -// -// void wrap_bar(foo::ENUM a, foo::Real b) { -// bar(a,b); -// } -// -// Inputs : name of the datatype. -// -// Output : None -// -// Side Effects : Adds datatype to localtypes. -// ----------------------------------------------------------------------------- - -void cplus_register_type(char *tname) { - if (current_class) - add_local_type(tname, current_class->classname); -}; - -// ----------------------------------------------------------------------------- -// void cplus_register_scope(void *h) -// -// Saves the scope associated with a particular class. It will be needed -// later if anything inherits from us. -// -// Inputs : Hash table h containing the scope -// -// Output : None -// -// Side Effects : Saves h with current class -// ----------------------------------------------------------------------------- - -void cplus_register_scope(void *h) { - if (current_class) { - current_class->scope = h; - } -} - -// ----------------------------------------------------------------------------- -// void cplus_inherit_scope(int count, char **baseclass) -// -// Given a list of base classes, this function extracts their former scopes -// and merges them with the current scope. This is needed to properly handle -// inheritance. -// -// Inputs : baseclass = NULL terminated array of base-class names -// -// Output : None -// -// Side Effects : Updates current scope with new symbols. -// -// Copies any special symbols if needed. -// ----------------------------------------------------------------------------- - -void cplus_inherit_scope(int count, char **baseclass) { - CPP_class *bc; - int i; - char *val; - DOH *key; - if (count && current_class) { - for (i = 0; i < count; i++) { - bc = CPP_class::search(baseclass[i]); - if (bc) { - if (bc->scope) { - SwigType_merge_scope(bc->scope,0); - } - if (bc->local) { - // Copy local symbol table - key = Firstkey(bc->local); - while (key) { - val = GetChar(bc->local,key); - Setattr(localtypes,key,val); - key = Nextkey(bc->local); - } - } - } - } - } -} - diff --git a/Source/SWIG1.1/emit.cxx b/Source/SWIG1.1/emit.cxx deleted file mode 100644 index a08102ffc..000000000 --- a/Source/SWIG1.1/emit.cxx +++ /dev/null @@ -1,257 +0,0 @@ -/* ----------------------------------------------------------------------------- - * emit.cxx - * - * Useful functions for emitting various pieces of code. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 1998-2000. The University of Chicago - * Copyright (C) 1995-1998. The University of Utah and The Regents of the - * University of California. - * - * See the file LICENSE for information on usage and redistribution. - * ----------------------------------------------------------------------------- */ - -#include "internal.h" -extern "C" { -#include "swig.h" -} - -static char cvsroot[] = "$Header$"; - -/* ----------------------------------------------------------------------------- - * new_create_function() - * - * Create a new function - * ----------------------------------------------------------------------------- */ - -void new_create_function(char *name, char *iname, SwigType *type, ParmList *l) { - Hash *h; - h = NewHash(); - Setattr(h,"name",name); - Setattr(h,"scriptname",iname); - Setattr(h,"type",type); - Setattr(h,"parms",l); - lang->function(h); - Delete(h); -} - -/* ----------------------------------------------------------------------------- - * emit_args() - * - * Creates a list of variable declarations for both the return value - * and function parameters. - * - * The return value is always called result and arguments arg0, arg1, arg2, etc... - * Returns the number of parameters associated with a function. - * ----------------------------------------------------------------------------- */ - -int emit_args(DOH *node, Wrapper *f) { - - SwigType *rt; - ParmList *l; - Parm *p; - int i; - char *tm; - SwigType *pt; - DOHString *pvalue; - DOHString *pname; - DOHString *lname; - - rt = Getattr(node,"type"); - l = Getattr(node,"parms"); - - /* Emit function arguments */ - Swig_cargs(f, l); - - i = 0; - p = l; - while (p != 0) { - lname = Getlname(p); - pt = Gettype(p); - pname = Getname(p); - pvalue = Getvalue(p); - - tm = Swig_typemap_lookup((char*)"arginit",pt,pname,(char*)"",lname,f); - if (tm) { - Printv(f,tm,"\n",0); - } - /* Check for ignore or default typemaps */ - tm = Swig_typemap_lookup((char*)"default",pt,pname,(char*)"",lname,f); - if (tm) { - Printv(f,tm,"\n",0); - } - tm = Swig_typemap_lookup((char*)"ignore",pt,pname,(char*)"",lname,f); - if (tm) { - Printv(f,tm,"\n",0); - Setignore(p,1); - } - i++; - p = Getnext(p); - } - return(i); -} - -/* ----------------------------------------------------------------------------- - * int emit_func_call(char *decl, DataType *t, ParmList *l, Wrapper*f) - * - * Emits code for a function call (new version). - * - * Exception handling support : - * - * - This function checks to see if any sort of exception mechanism - * has been defined. If so, we emit the function call in an exception - * handling block. - * ----------------------------------------------------------------------------- */ - -static DOH *fcall = 0; - -void emit_set_action(DOHString_or_char *decl) { - if (fcall) Delete (fcall); - fcall = NewString(decl); -} - -void emit_func_call(DOH *node, Wrapper *f) { - char *decl; - SwigType *t; - ParmList *l; - char *tm; - - decl = GetChar(node,"name"); - t = Getattr(node,"type"); - l = Getattr(node,"parms"); - - if ((tm = Swig_typemap_lookup((char*)"except",t,decl,(char*)"result",(char*)"",0))) { - Printv(f,tm,0); - Replace(f,"$name",decl,DOH_REPLACE_ANY); - } else if ((tm = Swig_except_lookup())) { - Printv(f,tm,0); - Replace(f,"$name",decl,DOH_REPLACE_ANY); - } else { - Printv(f,"$function",0); - } - - if (!fcall) fcall = NewString(Swig_cfunction_call(decl,l)); - - if (CPlusPlus) { - Swig_cppresult(f, t, (char*)"result", Char(fcall)); - } else { - Swig_cresult(f, t, (char*)"result", Char(fcall)); - } - Delete(fcall); - fcall = 0; -} - -/* ----------------------------------------------------------------------------- - * void emit_set_get() - * - * Emits a pair of functions to set/get the value of a variable. This is - * only used in the event the target language can't provide variable linking - * on its own. - * - * double foo; - * - * Gets translated into the following : - * - * double foo_set(double x) { - * return foo = x; - * } - * - * double foo_get() { - * return foo; - * } - * ----------------------------------------------------------------------------- */ - -/* How to assign a C allocated string */ - -static char *c_str = (char *)"\ -if ($target) free($target);\n\ -$target = ($rtype) malloc(strlen($source)+1);\n\ -strcpy((char *)$target,$source);\n\ -return $ltype $target;\n"; - -/* How to assign a C allocated string */ - -static char *cpp_str = (char *)"\ -if ($target) delete [] $target;\n\ -$target = ($rtype) (new char[strlen($source)+1]);\n\ -strcpy((char *)$target,$source);\n\ -return ($ltype) $target;\n;"; - - -void emit_set_get(DOH *node) { - char *name, *iname; - SwigType *t; - Wrapper *w; - DOHString *new_iname; - char *code = 0; - - name = GetChar(node,"name"); - iname = GetChar(node,"iname"); - t = Getattr(node,"type"); - - /* First write a function to set the variable of the variable */ - if (!(Status & STAT_READONLY)) { - - if (SwigType_type(t) == T_STRING) { - if (CPlusPlus) - code = cpp_str; - else - code = c_str; - } - w = Swig_cvarset_wrapper(name, t, code); - Printf(f_header,"%s", w); - new_iname = Swig_name_set(iname); - DohIncref(new_iname); - new_create_function(GetChar(w,"name"), Char(new_iname), Gettype(w), Getparms(w)); - Delete(new_iname); - Delete(w); - } - - w = Swig_cvarget_wrapper(name,t,0); - Printf(f_header,"%s", w); - new_iname = Swig_name_get(iname); - DohIncref(new_iname); - new_create_function(GetChar(w,"name"), Char(new_iname), Gettype(w), Getparms(w)); - Delete(new_iname); - Delete(w); -} - -/* ------------------------------------------------------------------ - * int check_numopt() - * - * Gets the number of optional arguments for a ParmList. - * ------------------------------------------------------------------ */ - -int check_numopt(ParmList *p) { - int n = 0; - int i = 0; - int state = 0; - - for (;p; p = Getnext(p),i++) { - SwigType *pt = Gettype(p); - String *pn = Getname(p); - if (Getvalue(p)) { - n++; - state = 1; - } else if (Swig_typemap_search((char*)"default",pt,pn)) { - n++; - state = 1; - } else if (Swig_typemap_search((char*)"ignore",pt,pn)) { - n++; - } else { - if (state) { - Printf(stderr,"%s : Line %d. Argument %d must have a default value!\n", input_file,line_number,i+1); - } - } - } - return n; -} - - - - - - - - diff --git a/Source/SWIG1.1/internal.h b/Source/SWIG1.1/internal.h deleted file mode 100644 index 484ef91f5..000000000 --- a/Source/SWIG1.1/internal.h +++ /dev/null @@ -1,64 +0,0 @@ -/* ----------------------------------------------------------------------------- - * internal.h - * - * Internal declarations used by the SWIG core - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 1998-2000. The University of Chicago - * Copyright (C) 1995-1998. The University of Utah and The Regents of the - * University of California. - * - * See the file LICENSE for information on usage and redistribution. - * - * $Header$ - * ----------------------------------------------------------------------------- */ - -#include "swig11.h" - -extern Language *lang; -extern int ForceExtern; -extern int WrapExtern; -extern void *CCode; -extern int GenerateDefault; -extern char *objc_construct; -extern char *objc_destruct; - -// Structure for holding typemap parameters - -struct TMParm { - Parm *p; - ParmList *args; - TMParm *next; - TMParm() { - next = 0; - } -}; - -/* Number of initialization names that can be used */ - -#define NI_NAMES 512 - -// Some functions for emitting some C++ helper code -extern void cplus_emit_member_func(char *classname, char *classtype, char *classrename, - char *mname, char *mrename, SwigType *type, ParmList *l, - int mode); - -extern void cplus_emit_static_func(char *classname, char *classtype, char *classrename, - char *mname, char *mrename, SwigType *type, ParmList *l, - int mode); - -extern void cplus_emit_destructor(char *classname, char *classtype, char *classrename, - char *name, char *iname, int mode); - -extern void cplus_emit_constructor(char *classname, char *classtype, char *classrename, - char *name, char *iname, ParmList *l, int mode); - -extern void cplus_emit_variable_get(char *classname, char *classtype, char *classrename, - char *name, char *iname, SwigType *type, int mode); - -extern void cplus_emit_variable_set(char *classname, char *classtype, char *classrename, - char *name, char *iname, SwigType *type, int mode); - -extern char *cplus_base_class(char *name); - diff --git a/Source/SWIG1.1/lang.cxx b/Source/SWIG1.1/lang.cxx deleted file mode 100644 index cb9f2b555..000000000 --- a/Source/SWIG1.1/lang.cxx +++ /dev/null @@ -1,418 +0,0 @@ -/* ----------------------------------------------------------------------------- - * lang.cxx - * - * Language base class functions. Default C++ handling is also implemented here. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 1998-2000. The University of Chicago - * Copyright (C) 1995-1998. The University of Utah and The Regents of the - * University of California. - * - * See the file LICENSE for information on usage and redistribution. - * ----------------------------------------------------------------------------- */ - -static char cvsroot[] = "$Header$"; - -#include "internal.h" -#include - -extern "C" { -#include "swig.h" -} - -extern int add_symbol(char *name); - -/* ----------------------------------------------------------------- - * Language::create_command() - * ----------------------------------------------------------------- */ - -void Language::create_command(char *, char *) { - Printf(stderr,"SWIG Warning. No command creation procedure defined.\n"); - Printf(stderr,"C++ inheritance may not work correctly.\n"); -} - -/* ----------------------------------------------------------------- - * Language::nativefunction() - * ----------------------------------------------------------------- */ - -void -Language::nativefunction(DOH *node) { - Printf(stderr,"%s : Line %d. Adding native function %s not supported (ignored).\n", input_file, line_number, Getattr(node,"scriptname")); -} - -static String *ClassName = 0; /* This is the real name of the current class */ -static String *ClassRename = 0; /* This is non-NULL if the class has been renamed */ -static String *ClassType = 0; /* Type of class (ie. union, struct, class) */ -static String *ClassFullname = 0; /* Full name of the class */ -static String *ClassPrefix = 0; /* Prefix used on wrappers */ - -/* ----------------------------------------------------------------------------- - * Language::cpp_open_class() - * ----------------------------------------------------------------------------- */ - -void Language::cpp_open_class(char *classname, char *classrename, char *ctype, int strip) { - - /* Copy the class name */ - - if (ClassName) Delete(ClassName); - ClassName = NewString(classname); - - /* Copy the class renaming */ - - if (ClassRename) Delete(ClassRename); - if (classrename) { - ClassRename = NewString(classrename); - } else { - ClassRename = 0; /* No renaming */ - } - - /* Make the class type*/ - - if (ClassType) Delete(ClassType); - if (strip) ClassType = NewString(""); - else ClassType = NewStringf("%s ", ctype); - - if (ClassFullname) Delete(ClassFullname); - ClassFullname = NewStringf("%s%s", ClassType, ClassName); - - if (ClassRename) { - ClassPrefix = ClassRename; - } else { - ClassPrefix = ClassName; - } -} - -/* ----------------------------------------------------------------------------- - * Language::cpp_close_class() - * ----------------------------------------------------------------------------- */ - -void Language::cpp_close_class() { - - - /* Doesn't really do anything */ -} - -/* ----------------------------------------------------------------------------- - * Language::cpp_memberfunction() - * ----------------------------------------------------------------------------- */ - -void Language::cpp_memberfunction(DOH *node) { - String *name; - String *iname; - String *ccode; - String *script_name; - SwigType *type; - ParmList *parms; - Wrapper *w; - - name = Getattr(node,"name"); - iname = Getattr(node,"scriptname"); - type = Getattr(node,"type"); - parms = Getattr(node,"parms"); - ccode = Getattr(node,"ccode"); - - /* Generate the C wrapper function name and interpreter name of this function*/ - /* Create the actual function name */ - - script_name = Swig_name_member(ClassPrefix, iname ? iname : name); - - /* Now do a symbol table lookup on it : */ - if (add_symbol(Char(script_name))) { - Printf(stderr,"%s : Line %d. Function %s (member %s) multiply defined (2nd definition ignored).\n", - input_file, line_number, iname, name); - return; - } - - /* Create the C wrapper function for this */ - w = Swig_cmethod_wrapper(ClassFullname, name, type, parms, ccode); - if (AddMethods && ccode) { - /* Dump the C wrappers */ - Printf(f_wrappers,"%s",w); - } else if (!AddMethods) { - /* Just create a string that does what we want */ - emit_set_action(Swig_cmethod_call(name, Getparms(w))); - } - Setattr(w,"scriptname",script_name); - lang->function(w); - Delete(w); -} - -/* ----------------------------------------------------------------------------- - * Language::cpp_constructor() - * ----------------------------------------------------------------------------- */ - -void Language::cpp_constructor(DOH *node) { - char *name, *iname; - ParmList *l; - char *cname; - - name = GetChar(node,"name"); - iname = GetChar(node,"scriptname"); - l = Getattr(node,"parms"); - - if ((strcmp(name,Char(ClassName))) && (!ObjCClass)) { - Printf(stderr,"%s : Line %d. Function %s must have a return type.\n", - input_file, line_number, name); - return; - } - - cname = Char(Swig_name_construct(iname ? iname : ClassPrefix)); - - /* Add this function to the SWIG symbol table */ - if (add_symbol(cname)) { - Printf(stderr,"%s : Line %d. Constructor %s multiply defined (2nd definition ignored).\n", - input_file, line_number, cname); - return; - } - - /* Call our default method */ - cplus_emit_constructor(Char(ClassName), Char(ClassType), Char(ClassRename), name, iname, l, AddMethods); - -} - -/* ----------------------------------------------------------------------------- - * Language::cpp_destructor() - * ----------------------------------------------------------------------------- */ - -void Language::cpp_destructor(DOH *node) { - char *name, *iname; - char *cname; - - name = GetChar(node,"name"); - iname = GetChar(node,"scriptname"); - cname = Char(Swig_name_destroy(ClassRename ? ClassRename : ClassName)); - - /* Add this function to the SWIG symbol table */ - - if (add_symbol(cname)) { - Printf(stderr,"%s : Line %d. Destructor %s multiply defined (2nd definition ignored).\n", - input_file, line_number, cname); - return; - } - - - /* Call our default method */ - - cplus_emit_destructor(Char(ClassName), Char(ClassType), Char(ClassRename), name, iname, AddMethods); - -} - -/* ----------------------------------------------------------------------------- - * Language::cleanup() - * ----------------------------------------------------------------------------- */ - -void Language::cpp_cleanup() { - - /* This doesn't do anything (well, not be default) */ - -} - -/* ----------------------------------------------------------------------------- - * Language::cpp_inherit() - * ----------------------------------------------------------------------------- */ - -void Language::cpp_inherit(char **baseclass, int mode) { - - extern void cplus_inherit_members(char *, int); - int i = 0; - - if (!baseclass) return; - while (baseclass[i]) { - cplus_inherit_members(baseclass[i],mode); - i++; - } -} - -/* ----------------------------------------------------------------------------- - * Language::cpp_variable() - * ----------------------------------------------------------------------------- */ - -void Language::cpp_variable(DOH *node) { - char *name, *iname; - SwigType *t; - char *cname; - - name = GetChar(node,"name"); - iname = GetChar(node,"scriptname"); - t = Getattr(node,"type"); - - /* Set the class prefix */ - - cname = Char(Swig_name_get(Swig_name_member(ClassPrefix, iname ? iname : name))); - - /* Check the symbol table */ - if (add_symbol(cname)) { - Printf(stderr,"%s : Line %d. Variable %s multiply defined (2nd definition ignored).\n", input_file, line_number, cname); - return; - } - - /* Create a function to set the value of the variable */ - if (!(Status & STAT_READONLY)) { - cplus_emit_variable_set(Char(ClassName), Char(ClassType), Char(ClassRename), name, iname, t, AddMethods); - } - - /* Create a function to get the value of a variable */ - cplus_emit_variable_get(Char(ClassName),Char(ClassType), Char(ClassRename), name, iname, t, AddMethods); - -} - -/* ----------------------------------------------------------------------------- - * Language::cpp_static_func() - * ----------------------------------------------------------------------------- */ - -void Language::cpp_staticfunction(DOH *node) { - char *name, *iname; - SwigType *t; - ParmList *l; - char *cname; - - name = GetChar(node,"name"); - iname = GetChar(node,"scriptname"); - t = Getattr(node,"type"); - l = Getattr(node,"parms"); - - /* Set the member function name */ - - cname = Char(Swig_name_member(ClassPrefix,iname ? iname : name)); - - /* Now do a symbol table lookup on it : */ - - if (add_symbol(cname)) { - if (ObjCClass) - Printf(stderr,"%s : Line %d. class function %s multiply defined (2nd definition ignored).\n", - input_file, line_number, cname); - else - Printf(stderr,"%s : Line %d. static function %s multiply defined (2nd definition ignored).\n", - input_file, line_number, cname); - return; - } - cplus_emit_static_func(Char(ClassName),Char(ClassType), Char(ClassRename), name, iname, t, l, AddMethods); -} - -/* ----------------------------------------------------------------------------- - * Language::cpp_constant() - * ----------------------------------------------------------------------------- */ - -void Language::cpp_constant(DOH *node) -{ - char *name, *iname, *value; - SwigType *type; - - char *cname; - char mname[256]; - String *new_value; - - name = GetChar(node,"name"); - iname = GetChar(node,"scriptname"); - value = GetChar(node,"value"); - type = Getattr(node,"type"); - - /* Set the constant name */ - - cname = Char(Swig_name_member(ClassPrefix, iname ? iname : name)); - - /* Now do a symbol table lookup on it : */ - if (add_symbol(cname)) { - Printf(stderr,"%s : Line %d. Constant %s (member %s) multiply defined (2nd definition ignored).\n", - input_file, line_number, cname, name); - return; - } - - /* Form correct C++ name */ - sprintf(mname,"%s::%s",ClassName,name); - - /* Declare a constant */ - if (!value) { - new_value = NewStringf("%s::%s", ClassName, name); - } else { - new_value = NewString(value); - } - Hash *n; - n = NewHash(); - Setattr(n,"name",cname); - Setattr(n,"scriptname",cname); - Setattr(n,"type",type); - Setattr(n,"value",new_value); - lang->constant(n); - Delete(n); - Delete(new_value); -} - -/* ----------------------------------------------------------------------------- - * Language::cpp_staticvariable() - * ----------------------------------------------------------------------------- */ - -void Language::cpp_staticvariable(DOH *node) { - char *name, *iname; - SwigType *t; - char *cname; - char mname[256]; - - name = GetChar(node,"name"); - iname = GetChar(node,"scriptname"); - t = Getattr(node,"type"); - - /* Create the variable name */ - - cname = Char(Swig_name_member(ClassPrefix, iname ? iname : name)); - - /* Now do a symbol table lookup on it : */ - if (add_symbol(cname)) { - Printf(stderr,"%s : Line %d. Variable %s (member %s) multiply defined (2nd definition ignored).\n", - input_file, line_number, cname, name); - return; - } - - /* Form correct C++ name */ - sprintf(mname,"%s::%s",Char(ClassName),name); - - /* Link with this variable */ - - Hash *n = NewHash(); - Setattr(n,"name",mname); - Setattr(n,"scriptname", cname); - Setattr(n,"type",t); - lang->variable(n); - Delete(n); -} - -/* ----------------------------------------------------------------------------- - * Language::cpp_class_decl() - * ----------------------------------------------------------------------------- */ - -void Language::cpp_class_decl(char *, char *, char *) { - /* Does nothing by default */ -} - -/* ----------------------------------------------------------------------------- - * Language::cpp_pragma() - * ----------------------------------------------------------------------------- */ - -void Language::cpp_pragma(Pragma *) { - /* Does nothing by default */ -} - -/* ----------------------------------------------------------------------------- - * Language::add_typedef() - * ----------------------------------------------------------------------------- */ - -void Language::add_typedef(SwigType *, char *) { - /* Does nothing by default */ -} - -/* ----------------------------------------------------------------------------- - * Language::pragma() - * ----------------------------------------------------------------------------- */ - -void Language::pragma(char *, char *, char *) { - /* Does nothing by default */ -} - -/* ----------------------------------------------------------------------------- - * Language::import() - * ----------------------------------------------------------------------------- */ - -void Language::import(char *) { - /* Does nothing by default */ -} diff --git a/Source/SWIG1.1/main.cxx b/Source/SWIG1.1/main.cxx deleted file mode 100644 index 15dab50f7..000000000 --- a/Source/SWIG1.1/main.cxx +++ /dev/null @@ -1,534 +0,0 @@ -/* ----------------------------------------------------------------------------- - * main.cxx - * - * Main entry point to the SWIG core. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 1998-2000. The University of Chicago - * Copyright (C) 1995-1998. The University of Utah and The Regents of the - * University of California. - * - * See the file LICENSE for information on usage and redistribution. - * ----------------------------------------------------------------------------- */ - -static char cvsroot[] = "$Header$"; - -#include "internal.h" -#ifndef MACSWIG -#include "swigconfig.h" -#endif - -#include -#include -#include -#include -extern "C" { -#include "preprocessor.h" -} - -#ifndef SWIG_LIB -#define SWIG_LIB "/usr/local/lib/swig1.3" -#endif - -#ifndef SWIG_CC -#define SWIG_CC "CC" -#endif - -// Global variables - - FILE *f_runtime; - DOH *f_header; // Some commonly used - DOH *f_wrappers; // FILE pointers - DOH *f_init; - FILE *f_input; - char LibDir[512]; // Library directory - int Status; - Language *lang; // Language method - int CPlusPlus = 0; - int ObjC = 0; - int ObjCClass = 0; - int AddMethods = 0; // AddMethods flag - int NewObject = 0; // NewObject flag - int Inline = 0; // Inline mode - int ForceExtern = 0; // Force extern mode - int WrapExtern = 0; - int GenerateDefault = 0; // Generate default constructors - char *Config = 0; - int NoInclude = 0; - - int error_count = 0; // Error count - int Verbose = 0; - -class SwigException {}; - -static char *usage = (char*)"\ -\nGeneral Options\n\ - -c - Produce raw wrapper code (omit support code)\n\ - -c++ - Enable C++ processing\n\ - -co - Check a file out of the SWIG library\n\ - -Dsymbol - Define a symbol (for conditional compilation)\n\ - -I - Look for SWIG files in \n\ - -includeall - Follow all #include statements\n\ - -l - Include SWIG library file.\n\ - -make_default - Create default constructors/destructors\n\ - -o outfile - Set name of the output file.\n\ - -objc - Enable Objective C processing\n\ - -swiglib - Report location of SWIG library and exit\n\ - -v - Run in verbose mode\n\ - -version - Print SWIG version number\n\ - -help - This output.\n\n"; - - - -// ----------------------------------------------------------------------------- -// check_suffix(char *name) -// -// Checks the suffix of a file to see if we should emit extern declarations. -// ----------------------------------------------------------------------------- - -int -check_suffix(char *name) { - char *c; - if (!name) return 0; - if (strlen(name) == 0) return 0; - c = name+strlen(name)-1; - while (c != name) { - if (*c == '.') break; - c--; - } - if (c == name) return 0; - if ((strcmp(c,".c") == 0) || - (strcmp(c,".C") == 0) || - (strcmp(c,".cc") == 0) || - (strcmp(c,".cxx") == 0) || - (strcmp(c,".c++") == 0) || - (strcmp(c,".cpp") == 0)) { - return 1; - } - return 0; -} - -//----------------------------------------------------------------- -// main() -// -// Main program. Initializes the files and starts the parser. -//----------------------------------------------------------------- - -char infilename[256]; -char filename[256]; -char output_dir[512]; -char fn_runtime[256]; - -#ifdef MACSWIG -FILE *swig_log; -#endif - -char *SwigLib; -static int freeze = 0; - -static String *lang_config = 0; - -/* This function sets the name of the configuration file */ - -void SWIG_config_file(const String_or_char *filename) { - lang_config = NewString(filename); -} - -int SWIG_main(int argc, char *argv[], Language *l) { - int i; - char *c; - char temp[512]; - char infile[512]; - char *outfile_name = 0; - int help = 0; - int checkout = 0; - int cpp_only = 0; - int tm_debug = 0; - char *includefiles[256]; - int includecount = 0; - extern int check_suffix(char *); - extern void scanner_file(DOHFile *); - extern void parser_init(void); - DOH *libfiles = 0; - - /* Initialize the SWIG core */ - Swig_init(); - -#ifdef MACSWIG - try { -#endif - - // Initialize the preprocessor - Preprocessor_init(); - - f_wrappers = 0; - f_init = 0; - f_header = 0; - - lang = l; - Status = 0; - - // Set up some default symbols (available in both SWIG interface files - // and C files) - - Preprocessor_define((DOH *) "SWIG 1", 0); - Preprocessor_define((DOH *) "__STDC__", 0); -#ifdef MACSWIG - Preprocessor_define((DOH *) "SWIGMAC 1", 0); -#endif -#ifdef SWIGWIN32 - Preprocessor_define((DOH *) "SWIGWIN32 1", 0); -#endif - - // Check for SWIG_LIB environment variable - - if ((c = getenv("SWIG_LIB")) == (char *) 0) { - sprintf(LibDir,"%s",SWIG_LIB); // Build up search paths - } else { - strcpy(LibDir,c); - } - - SwigLib = Swig_copy_string(LibDir); // Make a copy of the real library location - -#ifdef MACSWIG - sprintf(temp,"%s:config", LibDir); - Swig_add_directory((DOH *) ":swig_lib:config"); - Swig_add_directory((DOH *) ":swig_lib"); -#else - sprintf(temp,"%s/config", LibDir); - Swig_add_directory((DOH *) "./swig_lib/config"); - Swig_add_directory((DOH *) "./swig_lib"); -#endif - Swig_add_directory((DOH *) temp); - Swig_add_directory((DOH *) LibDir); - - libfiles = NewList(); - - // Get options - for (i = 1; i < argc; i++) { - if (argv[i]) { - if (strncmp(argv[i],"-I",2) == 0) { - // Add a new directory search path - includefiles[includecount++] = Swig_copy_string(argv[i]+2); - Swig_mark_arg(i); - } else if (strncmp(argv[i],"-D",2) == 0) { - DOH *d = NewString(argv[i]+2); - Replace(d,(char*)"=",(char*)" ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST); - Preprocessor_define((DOH *) d,0); - // Create a symbol - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-E") == 0) { - cpp_only = 1; - Swig_mark_arg(i); - } else if ((strcmp(argv[i],"-verbose") == 0) || - (strcmp(argv[i],"-v") == 0)) { - Verbose = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-c++") == 0) { - CPlusPlus=1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-objc") == 0) { - ObjC = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-c") == 0) { - NoInclude=1; - Preprocessor_define((DOH *) "SWIG_NOINCLUDE 1", 0); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-make_default") == 0) { - GenerateDefault = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-swiglib") == 0) { - printf("%s\n", LibDir); - SWIG_exit (EXIT_SUCCESS); - } else if (strcmp(argv[i],"-o") == 0) { - Swig_mark_arg(i); - if (argv[i+1]) { - outfile_name = Swig_copy_string(argv[i+1]); - Swig_mark_arg(i+1); - i++; - } else { - Swig_arg_error(); - } - } else if (strcmp(argv[i],"-version") == 0) { - fprintf(stderr,"\nSWIG Version %s %s\n", - SWIG_VERSION, SWIG_SPIN); - fprintf(stderr,"Copyright (c) 1995-98\n"); - fprintf(stderr,"University of Utah and the Regents of the University of California\n"); - fprintf(stderr,"\nCompiled with %s\n", SWIG_CC); - SWIG_exit (EXIT_SUCCESS); - } else if (strncmp(argv[i],"-l",2) == 0) { - // Add a new directory search path - Append(libfiles,argv[i]+2); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-co") == 0) { - checkout = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-freeze") == 0) { - freeze = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-includeall") == 0) { - Preprocessor_include_all(1); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-tm_debug") == 0) { - tm_debug = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-help") == 0) { - fputs(usage,stderr); - Swig_mark_arg(i); - help = 1; - } - } - } - if (Verbose) - printf ("LibDir: %s\n", LibDir); - - while (includecount > 0) { - Swig_add_directory((DOH *) includefiles[--includecount]); - } - - // Parse language dependent options - lang->parse_args(argc,argv); - - if (help) SWIG_exit (EXIT_SUCCESS); // Exit if we're in help mode - - // Check all of the options to make sure we're cool. - Swig_check_options(); - - // Add language dependent directory to the search path - { - DOH *rl = NewString(""); -#ifdef MACSWIG - Printf(r1,"%s:%s", SwigLib,LibDir); -#else - Printf(rl,"%s/%s", SwigLib,LibDir); -#endif - Swig_add_directory(rl); - } - - // If we made it this far, looks good. go for it.... - // Create names of temporary files that are created - - sprintf(infilename,"%s", argv[argc-1]); - input_file = new char[strlen(infilename)+1]; - strcpy(input_file, infilename); - - // If the user has requested to check out a file, handle that - if (checkout) { - DOH *s; - char *outfile = input_file; - if (outfile_name) - outfile = outfile_name; - - if (Verbose) - printf ("Handling checkout...\n"); - - s = Swig_include(input_file); - if (!s) { - fprintf(stderr,"Unable to locate '%s' in the SWIG library.\n", input_file); - } else { - FILE *f = fopen(outfile,"r"); - if (f) { - fclose(f); - fprintf(stderr,"File '%s' already exists. Checkout aborted.\n", outfile); - } else { - f = fopen(outfile,"w"); - if (!f) { - fprintf(stderr,"Unable to create file '%s'\n", outfile); - } else { - fprintf(stderr,"'%s' checked out from the SWIG library.\n", input_file); - fputs(Char(s),f); - fclose(f); - } - } - } - } else { - // Check the suffix for a .c file. If so, we're going to - // declare everything we see as "extern" - - ForceExtern = check_suffix(infilename); - // Strip off suffix - - c = infilename + strlen(infilename); - while (c != infilename) { - if (*c == '.') { - *c = 0; - break; - } else { - c--; - } - } - - if (!outfile_name) { - char *cc = infilename + strlen(infilename); - while (cc != infilename) { - if (*cc == '/') { - cc++; - break; - } - cc--; - } - sprintf(fn_runtime,"%s_wrap.c",infilename); - strcpy(infile,infilename); - outfile_name = fn_runtime; - } else { - sprintf(fn_runtime,"%s",outfile_name); - } - { - // Try to identify the output directory - char *cc = outfile_name; - char *lastc = outfile_name; - while (*cc) { - if (*cc == '/') lastc = cc+1; - cc++; - } - cc = outfile_name; - char *dd = output_dir; - while (cc != lastc) { - *dd = *cc; - dd++; - cc++; - } - *dd = 0; - // Patch up the input filename - cc = infilename + strlen(infilename); - while (cc != infilename) { - if (*cc == '/') { - cc++; - break; - } - cc--; - } - strcpy(infile,cc); - } - - // Define the __cplusplus symbol - if (CPlusPlus) - Preprocessor_define((DOH *) "__cplusplus 1", 0); - - // Run the preprocessor - if (Verbose) - printf ("Preprocessing...\n"); - { - DOH *cpps; - int i; - String *fs = NewString(""); - String *ds = Swig_include(input_file); - if (!ds) { - Printf(stderr,"Unable to find '%s'\n", input_file); - SWIG_exit (EXIT_FAILURE); - } - if (lang_config) { - Printf(fs,"\n%%include \"%s\"\n", lang_config); - } - Printf(fs,"\n%%file(\"include\") \"%s\" {\n", Swig_last_file()); - Append(fs, ds); - Append(fs,"\n}\n"); - Delete(ds); - for (i = 0; i < Len(libfiles); i++) { - Printf(fs,"\n%%include \"%s\"\n", Getitem(libfiles,i)); - } - Seek(fs,0,SEEK_SET); - cpps = Preprocessor_parse(fs); - if (cpp_only) { - Printf(stdout,"%s", cpps); - while (freeze); - SWIG_exit (EXIT_SUCCESS); - } - - // Initialize the scanner - Seek(cpps, 0, SEEK_SET); - scanner_file(cpps); - } - if ((f_runtime = fopen(fn_runtime,"w")) == 0) { - fprintf(stderr,"Unable to open %s\n", fn_runtime); - exit(0); - } - f_header = NewString(""); - f_wrappers = NewString(""); - f_init = NewString(""); - - // Set up the typemap for handling new return strings - { - if (CPlusPlus) - Swig_typemap_register((char*)"newfree",(char*)"p.char",(char*)"",(char*)"delete [] $source;\n",0); - else - Swig_typemap_register((char*)"newfree",(char*)"p.char",(char*)"",(char*)"free($source);\n",0); - } - - // If in Objective-C mode. Load in a configuration file - - if (ObjC) { - // Add the 'id' object type as a void * - /* DataType *t = new DataType(T_VOID); - t->is_pointer = 1; - t->implicit_ptr = 0; - t->typedef_add("id"); - delete t; - */ - } - - // Pass control over to the specific language interpreter - - if (Verbose) { - fprintf (stdout, "Starting language-specific parse...\n"); - fflush (stdout); - } - parser_init(); - lang->parse(); - if (Verbose) { - fprintf (stdout, "Finished language-specific parse.\n"); - fflush (stdout); - } - - Dump(f_header,f_runtime); - Dump(f_wrappers, f_runtime); - Wrapper_pretty_print(f_init,f_runtime); - fclose(f_runtime); - if (checkout) { - // File was checked out from the SWIG library. Remove it now - remove(input_file); - } - } - if (tm_debug) Swig_typemap_debug(); - while (freeze); - return error_count; -} - -// -------------------------------------------------------------------------- -// SWIG_exit(int exit_code) -// -// Cleanup and either freeze or exit -// -------------------------------------------------------------------------- - -void SWIG_exit(int exit_code) { - if (f_runtime) { - fclose(f_runtime); - remove(fn_runtime); - } - while (freeze); - exit (exit_code); -} - - -// -------------------------------------------------------------------------- -// swig_pragma(char *name, char *value) -// -// Handle pragma directives. Not many supported right now -// -------------------------------------------------------------------------- - -void swig_pragma(char *name, char *value) { - - if (strcmp(name,"make_default") == 0) { - GenerateDefault = 1; - } - if (strcmp(name,"no_default") == 0) { - GenerateDefault = 0; - } - if (strcmp(name,"objc_new") == 0) { - objc_construct = Swig_copy_string(value); - } - if (strcmp(name,"objc_delete") == 0) { - objc_destruct = Swig_copy_string(value); - } -} diff --git a/Source/SWIG1.1/parser.yxx b/Source/SWIG1.1/parser.yxx deleted file mode 100644 index 5b3ed1f13..000000000 --- a/Source/SWIG1.1/parser.yxx +++ /dev/null @@ -1,3343 +0,0 @@ -%{ -/* ----------------------------------------------------------------------------- - * parser.yxx - * - * YACC parser for SWIG1.1. This grammar is a broken subset of C/C++. - * This file is in the process of being deprecated. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 1998-2000. The University of Chicago - * Copyright (C) 1995-1998. The University of Utah and The Regents of the - * University of California. - * - * See the file LICENSE for information on usage and redistribution. - * ----------------------------------------------------------------------------- */ - -#define yylex yylex - -static char cvsroot[] = "$Header$"; - -extern "C" int yylex(); -void yyerror (char *s); - -extern int line_number; -extern int start_line; -extern void skip_brace(void); -extern void skip_define(void); -extern void skip_decl(void); -extern int skip_cond(int); -extern void skip_to_end(void); -extern void skip_template(void); -extern void scanner_check_typedef(void); -extern void scanner_ignore_typedef(void); -extern void scanner_clear_start(void); -extern void start_inline(char *, int); -extern void swig_pragma(char *, char *); - char *typemap_lang = 0; - -#include "internal.h" -extern "C" { -#include "preprocessor.h" -} - -#ifdef NEED_ALLOC -void *alloca(unsigned n) { - return((void *) malloc(n)); -} -#else -// This redefinition is apparently needed on a number of machines, -// particularly HPUX -#undef alloca -#define alloca malloc -#endif - -// Initialization flags. These indicate whether or not certain -// features have been initialized. These were added to allow -// interface files without the block (required in previous -// versions). - -static int module_init = 0; /* Indicates whether the %module name was given */ -static int lang_init = 0; /* Indicates if the language has been initialized */ - -static int i; - int Error = 0; -static char temp_name[128]; -static SwigType *temp_typeptr, *temp_type = 0; -static char yy_rename[256]; -static int Rename_true = 0; -static SwigType *Active_type = 0; // Used to support variable lists -static int Active_extern = 0; // Whether or not list is external -static int Active_static = 0; -static SwigType *Active_typedef = 0; // Used for typedef lists -static int InArray = 0; // Used when an array declaration is found -static DOHString *ArrayString = 0; // Array type attached to parameter names -static DOHString *ArrayBackup = 0; -static char *DefArg = 0; // Default argument hack -static String *ConstChar = 0; // Used to store raw character constants -static ParmList *tm_parm = 0; // Parameter list used to hold typemap parameters -static DOHHash *name_hash = 0; // Hash table containing renamings - char *objc_construct = (char *) "new"; // Objective-C constructor - char *objc_destruct = (char *) "free"; // Objective-C destructor - -static DOHHash *symbols = 0; - -/* Some macros for building constants */ - -#define E_BINARY(TARGET, SRC1, SRC2, OP) \ - TARGET = (char *) malloc(strlen(SRC1) + strlen(SRC2) +strlen(OP)+1);\ - sprintf(TARGET,"%s%s%s",SRC1,OP,SRC2); - -/* C++ modes */ - -#define CPLUS_PUBLIC 1 -#define CPLUS_PRIVATE 2 -#define CPLUS_PROTECTED 3 - -int cplus_mode; - -// Declarations of some functions for handling C++ - -extern void cplus_open_class(char *name, char *rname, char *ctype); -extern void cplus_member_func(char *, char *, SwigType *, ParmList *, int); -extern void cplus_constructor(char *, char *, ParmList *); -extern void cplus_destructor(char *, char *); -extern void cplus_variable(char *, char *, SwigType *); -extern void cplus_static_func(char *, char *, SwigType *, ParmList *); -extern void cplus_declare_const(char *, char *, SwigType *, char *); -extern void cplus_class_close(char *); -extern void cplus_inherit(int, char **); -extern void cplus_cleanup(void); -extern void cplus_static_var(char *, char *, SwigType *); -extern void cplus_register_type(char *); -extern void cplus_register_scope(void *); -extern void cplus_inherit_scope(int, char **); -extern void cplus_add_pragma(char *, char *, char *); -extern void cplus_set_class(char *); -extern void cplus_unset_class(); -extern void cplus_abort(); - -void parser_init() { - ArrayString = NewString(""); - temp_type = NewString(""); -} - -static void my_cplus_declare_const(char *name, char *iname, SwigType *type, char *value) { - String *tval; - if (value) { - tval = NewStringf("%(escape)s",value); - cplus_declare_const(name,iname,type,Char(tval)); - Delete(tval); - } else { - cplus_declare_const(name,iname,type,value); - } -} - -static DOHList *typelist(Parm *p) { - DOHList *l = NewList(); - while (p) { - Append(l,Gettype(p)); - p = Getnext(p); - } - return l; -} - -static TMParm *NewTMParm() { - TMParm *tmp = (TMParm *) malloc(sizeof(TMParm)); - tmp->next = 0; - return tmp; -} - -static void add_pointers(SwigType *t, int npointer) { - int i; - for (i = 0; i < npointer; i++) { - SwigType_add_pointer(t); - } -} - -// Emit an external function declaration - -static void emit_extern_func(char *decl, SwigType *t, ParmList *L, int extern_type, DOHFile *f) { - - List *tl; - SwigType *tc; - - switch(extern_type) { - case 0: - Printf(f,"%s", SwigType_str(t,0)); - Printf(f,"%s(%s);\n", decl, ParmList_protostr(L)); - break; - case 1: - tl = typelist(L); - tc = Copy(t); - SwigType_add_function(tc,tl); - Printf(f,"extern %s;\n", SwigType_str(tc,decl)); - /* Printf(f,"%s(%s);\n", decl, ParmList_protostr(L)); */ - Delete(tc); - Delete(tl); - break; - case 2: - /* A C++ --- > C Extern */ - Printf(f,"extern \"C\" %s", SwigType_str(t,0)); - Printf(f,"%s(%s);\n", decl, ParmList_protostr(L)); - break; - case 3: - Printf(f,"%s", SwigType_str(t,0)); - Printf(f,"%s(%s)\n", decl, ParmList_str(L)); - break; - default: - break; - } -} - -// ---------------------------------------------------------------------- -// static init_language() -// -// Initialize the target language. -// Does nothing if this function has already been called. -// ---------------------------------------------------------------------- - -static void init_language() { - if (!lang_init) { - lang->initialize(); - } - lang_init = 1; -} - -/* Add a symbol to the symbol table. Return -1 if it already exists */ -int add_symbol(char *name) { - if (!symbols) symbols = NewHash(); - if (Getattr(symbols,name)) return -1; - Setattr(symbols,name,name); - return 0; -} - -// ---------------------------------------------------------------------- -// int promote(int t1, int t2) -// -// Promote types (for constant expressions) -// ---------------------------------------------------------------------- - -int promote(int t1, int t2) { - - if ((t1 == T_ERROR) || (t2 == T_ERROR)) return T_ERROR; - if ((t1 == T_DOUBLE) || (t2 == T_DOUBLE)) return T_DOUBLE; - if ((t1 == T_FLOAT) || (t2 == T_FLOAT)) return T_FLOAT; - if ((t1 == T_ULONG) || (t2 == T_ULONG)) return T_ULONG; - if ((t1 == T_LONG) || (t2 == T_LONG)) return T_LONG; - if ((t1 == T_UINT) || (t2 == T_UINT)) return T_UINT; - if ((t1 == T_INT) || (t2 == T_INT)) return T_INT; - if ((t1 == T_USHORT) || (t2 == T_USHORT)) return T_SHORT; - if ((t1 == T_SHORT) || (t2 == T_SHORT)) return T_SHORT; - if ((t1 == T_UCHAR) || (t2 == T_UCHAR)) return T_UCHAR; - if (t1 != t2) { - Printf(stderr,"%s : Line %d. Type mismatch in constant expression\n", - input_file, line_number); - FatalError(); - } - return t1; -} - -/* Generate the scripting name of an object. Takes %name directive into - account among other things */ - -static char *make_name(char *name) { - // Check to see if the name is in the hash - if (!name_hash) name_hash = NewHash(); - char *nn = GetChar(name_hash,name); - - if (nn) return nn; // Yep, return it. - - if (Rename_true) { - Rename_true = 0; - return yy_rename; - } else { - // Now check to see if the name contains a $ - if (strchr(name,'$')) { - static DOHString *temp = 0; - if (!temp) temp= NewString(""); - Clear(temp); - Append(temp,name); - Replace(temp,"$","_S_",DOH_REPLACE_ANY); - return Char(temp); - } else { - return name; - } - } -} - -// ---------------------------------------------------------------------- -// create_function(int ext, char *name, DataType *t, ParmList *l) -// -// Creates a function and manages documentation creation. Really -// only used internally to the parser. -// ---------------------------------------------------------------------- - -void create_function(int ext, char *name, SwigType *t, ParmList *l) { - DOH *n; - if (Active_static) return; // Static declaration. Ignore - - init_language(); - if (WrapExtern) return; // External wrapper file. Ignore - - char *iname = make_name(name); - - // Check if symbol already exists - - if (add_symbol(iname)) { - Printf(stderr,"%s : Line %d. Function %s multiply defined (2nd definition ignored).\n", - input_file, line_number, iname); - } else { - - // If extern, make an extern declaration in the SWIG wrapper file - - if (ext) - emit_extern_func(name, t, l, ext, f_header); - else if (ForceExtern) { - emit_extern_func(name, t, l, 1, f_header); - } - - n = NewHash(); - Setattr(n,"name", name); - Setattr(n,"scriptname", iname); - Setattr(n,"type", t); - Setattr(n,"parms", l); - lang->function(n); - Delete(n); - } - scanner_clear_start(); -} - -// ------------------------------------------------------------------- -// create_variable(int ext, char *name, DataType *t) -// -// Create a link to a global variable. -// ------------------------------------------------------------------- - -void create_variable(int ext, char *name, SwigType *t) { - - if (WrapExtern) return; // External wrapper file. Ignore - if (Active_static) return; // If static ignore - - init_language(); - - char *iname = make_name(name); - if (add_symbol(iname)) { - Printf(stderr,"%s : Line %d. Variable %s multiply defined (2nd definition ignored).\n", - input_file, line_number, iname); - } else { - - // If externed, output an external declaration - - if (ext || ForceExtern) { - Printf(f_header,"extern %s;\n", SwigType_str(t,name)); - } - - // Now dump it out - Hash *n; - n = NewHash(); - Setattr(n,"name",name); - Setattr(n,"scriptname", iname); - Setattr(n,"type",t); - lang->variable(n); - Delete(n); - } - scanner_clear_start(); -} - -// ------------------------------------------------------------------ -// create_constant(char *name, DataType *type, char *value) -// -// Creates a new constant. -// ------------------------------------------------------------------- - -void create_constant(char *name, SwigType *type, char *value) { - - if (Active_static) return; - if (WrapExtern) return; // External wrapper file. Ignore - init_language(); - - if (Rename_true) { - Printf(stderr,"%s : Line %d. %%name directive ignored with #define\n", - input_file, line_number); - Rename_true = 0; - } - - if (SwigType_type(type) == T_CHAR) { - SwigType_add_pointer(type); - } - if (!value) value = Swig_copy_string(name); - sprintf(temp_name,"const:%s", name); - if (add_symbol(temp_name)) { - Printf(stderr,"%s : Line %d. Constant %s multiply defined. (2nd definition ignored)\n", - input_file, line_number, name); - } else { - if (!WrapExtern) { // Only wrap the constant if not in %extern mode - String *tval = NewStringf("%(escape)s",value); - Hash *n; - n = NewHash(); - Setattr(n,"name",name); - Setattr(n,"scriptname",name); - Setattr(n,"type",type); - Setattr(n,"value",tval); - lang->constant(n); - Delete(n); - Delete(tval); - } - } - scanner_clear_start(); -} - - -/* Print out array brackets */ -void print_array() { - int i; - for (i = 0; i < InArray; i++) - Printf(stderr,"[]"); -} - -// Structures for handling code fragments built for nested classes - -struct Nested { - DOHString *code; // Associated code fragment - int line; // line number where it starts - char *name; // Name associated with this nested class - SwigType *type; // Datatype associated with the name - Nested *next; // Next code fragment in list -}; - -// Some internal variables for saving nested class information - -static Nested *nested_list = 0; - -// Add a function to the nested list - -static void add_nested(Nested *n) { - Nested *n1; - if (!nested_list) nested_list = n; - else { - n1 = nested_list; - while (n1->next) n1 = n1->next; - n1->next = n; - } -} - -// Dump all of the nested class declarations to the inline processor -// However. We need to do a few name replacements and other munging -// first. This function must be called before closing a class! - -static void dump_nested(char *parent) { - Nested *n,*n1; - n = nested_list; - int oldstatus = Status; - - Status = STAT_READONLY; - while (n) { - char temp[256]; - // Token replace the name of the parent class - Replace(n->code, "$classname", parent, DOH_REPLACE_ANY); - - // Fix up the name of the datatype (for building typedefs and other stuff) - sprintf(temp,"%s_%s", parent,n->name); - - Append(n->type,parent); - Append(n->type,"_"); - Append(n->type,n->name); - - // Add the appropriate declaration to the C++ processor - cplus_variable(n->name,(char *) 0, n->type); - - // Dump the code to the scanner - - Printf(f_header,"\n%s\n", Char(n->code)); - start_inline(Char(n->code),n->line); - - n1 = n->next; - Delete(n->code); - free(n); - n = n1; - } - nested_list = 0; - Status = oldstatus; -} - -%} - -/* The type of each node in the parse tree - must be one of the elements of the union - given below. This is used to derive the - C++ declaration for "yylval" that appears - in parser.tab.h. */ - -%union { - char *id; - struct Declaration { - char *id; - int is_pointer; - int is_reference; - } decl; - struct InitList { - char **names; - int count; - } ilist; - struct DocList { - char **names; - char **values; - int count; - } dlist; - struct Define { - char *id; - int type; - } dtype; - struct { - char *filename; - int line; - int flag; - } loc; - SwigType *type; - Parm *p; - TMParm *tmparm; - ParmList *pl; - int ivalue; -}; - -%token ID -%token HBLOCK WRAPPER POUND RUNTIME HEADER -%token STRING -%token INCLUDE SWIGMACRO INSERT -%token NUM_INT NUM_FLOAT CHARCONST NUM_UNSIGNED NUM_LONG NUM_ULONG -%token TYPEDEF -%token TYPE_INT TYPE_UNSIGNED TYPE_SHORT TYPE_LONG TYPE_FLOAT TYPE_DOUBLE TYPE_CHAR TYPE_VOID TYPE_SIGNED TYPE_BOOL TYPE_TYPEDEF TYPE_RAW -%token LPAREN RPAREN COMMA SEMI EXTERN INIT LBRACE RBRACE PERIOD -%token CONST STRUCT UNION EQUAL SIZEOF MODULE LBRACKET RBRACKET -%token ILLEGAL CONSTANT -%token READONLY READWRITE NAME RENAME ADDMETHODS PRAGMA -%token ENUM -%token CLASS PRIVATE PUBLIC PROTECTED COLON STATIC VIRTUAL FRIEND OPERATOR THROW TEMPLATE -%token NATIVE INLINE -%token TEXT DOC_DISABLE DOC_ENABLE STYLE LOCALSTYLE -%token TYPEMAP EXCEPT ECHO NEW APPLY CLEAR DOCONLY -%token TITLE SECTION SUBSECTION SUBSUBSECTION -%token LESSTHAN GREATERTHAN -%token TYPES - -/* Objective C tokens */ - -%token OC_INTERFACE OC_END OC_PUBLIC OC_PRIVATE OC_PROTECTED OC_CLASS OC_IMPLEMENT OC_PROTOCOL - -%left OR -%left XOR -%left AND -%left LSHIFT RSHIFT -%left PLUS MINUS -%left STAR SLASH -%left UMINUS NOT LNOT -%left DCOLON - -%type extern array array2; -%type parms ptail; -%type

parm parm_type; -%type typemap_parm tm_list tm_tail; -%type pname cpptype base_specifier access_specifier typemap_name tm_method; -%type type opt_signed opt_unsigned strict_type; -%type declaration nested_decl; -%type stars cpp_vend; -%type initlist base_list inherit; -%type definetype def_args; -%type etype; -%type expr; -%type ename stylearg objc_inherit; -%type stylelist styletail; -%type objc_ret_type objc_arg_type; -%type objc_protolist objc_separator; -%type objc_args; - -%% - -/* The productions of the grammar with their - associated semantic actions. */ - -program : command { - cplus_cleanup(); - if (lang_init) { - lang->close(); - } - } - ; - -command : command statement { - scanner_clear_start(); - Error = 0; - } - | empty { - } - ; - -statement : INCLUDE LPAREN STRING RPAREN STRING LBRACE { - $1.filename = Swig_copy_string(input_file); - $1.line = line_number; - input_file = Swig_copy_string($5); - $1.flag = WrapExtern; - if (strcmp($3,"extern") == 0) { - WrapExtern = 1; - } - if (strcmp($3,"import") == 0) { - WrapExtern = 1; - lang->import($5); - } - line_number = 0; - } command RBRACE { - input_file = $1.filename; - line_number = $1.line; - WrapExtern = $1.flag; - } - - | SWIGMACRO ID COMMA STRING COMMA NUM_INT LBRACE { - $1.filename = Swig_copy_string(input_file); - $1.line = line_number; - input_file = Swig_copy_string($4); - line_number = atoi($6) - 1; - } command RBRACE { - input_file = $1.filename; - line_number = $1.line; - } - -/* An unknown C preprocessor statement. Just throw it away */ - - | POUND { - } - -/* A variable declaration */ - - | extern type declaration array2 def_args { - init_language(); - if (Active_type) Delete(Active_type); - Active_type = Copy($2); - Active_extern = $1; - add_pointers($2,$3.is_pointer); - if ($4 > 0) { - SwigType_push($2,ArrayString); - } - if ($3.is_reference) { - Printf(stderr,"%s : Line %d. Error. Linkage to C++ reference not allowed.\n", input_file, line_number); - FatalError(); - } else { - if (SwigType_isconst($2)) { - create_constant($3.id, $2, $5.id); - } else { - create_variable($1,$3.id,$2); - } - } - Delete($2); - } stail { } - -/* Global variable that smells like a function pointer */ - - | extern strict_type LPAREN STAR { - skip_decl(); - Printf(stderr,"%s : Line %d. Function pointers not currently supported.\n", - input_file, line_number); - } - -/* A static variable declaration (Ignored) */ - - | STATIC type declaration array2 def_args { - Active_static = 1; - Delete($2); - } stail { - Active_static = 0; - } - -/* Global variable that smells like a function pointer */ - - | STATIC strict_type LPAREN STAR { - skip_decl(); - Printf(stderr,"%s : Line %d. Function pointers not currently supported.\n", - input_file, line_number); - } - - -/* A function declaration */ - - | extern type declaration LPAREN parms RPAREN cpp_const { - init_language(); - if (Active_type) Delete(Active_type); - Active_type = Copy($2); - Active_extern = $1; - add_pointers($2,$3.is_pointer); - if ($3.is_reference) SwigType_add_reference($2); - create_function($1, $3.id, $2, $5); - Delete($2); - Delete($5); - } stail { } - -/* A function declaration with code after it */ - - | extern type declaration LPAREN parms RPAREN func_end { - init_language(); - add_pointers($2,$3.is_pointer); - if ($3.is_reference) SwigType_add_reference($2); - create_function($1, $3.id, $2, $5); - Delete($2); - Delete($5); - }; - -/* A function declared without any return datatype */ - - | extern declaration LPAREN parms RPAREN cpp_const { - init_language(); - SwigType *t = NewString("int"); - add_pointers(t,$2.is_pointer); - if ($2.is_reference) SwigType_add_reference(t); - create_function($1,$2.id,t,$4); - Delete(t); - } stail { }; - -/* A static function declaration code after it */ - - | STATIC type declaration LPAREN parms RPAREN func_end { - if (Inline) { - if (strlen(Char(CCode))) { - init_language(); - add_pointers($2, $3.is_pointer); - if ($3.is_reference) SwigType_add_reference($2); - create_function(0, $3.id, $2, $5); - } - } - Delete($2); - Delete($5); - }; - -/* A function with an explicit inline directive. Not safe to use inside a %inline block */ - - | INLINE type declaration LPAREN parms RPAREN func_end { - init_language(); - add_pointers($2,$3.is_pointer); - if ($3.is_reference) SwigType_add_reference($2); - if (Inline) { - Printf(stderr,"%s : Line %d. Repeated %%inline directive.\n",input_file,line_number); - FatalError(); - } else { - if (strlen(Char(CCode))) { - Printf(f_header,"static "); - emit_extern_func($3.id,$2,$5,3,f_header); - Printf(f_header,"%s\n",Char(CCode)); - } - create_function(0, $3.id, $2, $5); - } - Delete($2); - Delete($5); - }; - -/* A static function declaration (ignored) */ - - | STATIC type declaration LPAREN parms RPAREN cpp_const { - Active_static = 1; - Delete($2); - Delete($5); - } stail { - Active_static = 0; - } - -/* Enable Read-only mode */ - - | READONLY { - Status = Status | STAT_READONLY; - } - -/* Enable Read-write mode */ - - | READWRITE { - Status = Status & ~STAT_READONLY; - } - -/* New %name directive */ - | NAME LPAREN ID RPAREN { - strcpy(yy_rename,$3); - Rename_true = 1; - } - -/* %rename directive */ - | RENAME ID ID SEMI { - if (!name_hash) name_hash = NewHash(); - Setattr(name_hash,$2,$3); - } - -/* %new directive */ - - | NEW { - NewObject = 1; - } statement { - NewObject = 0; - } - -/* Empty name directive. No longer allowed */ - - | NAME LPAREN RPAREN { - Printf(stderr,"%s : Lind %d. Empty %%name() is no longer supported.\n", - input_file, line_number); - FatalError(); - } cpp { - Rename_true = 0; - } - -/* A native wrapper function */ - - | NATIVE LPAREN ID RPAREN extern ID SEMI { - if (!WrapExtern) { - init_language(); - if (add_symbol($3)) { - Printf(stderr,"%s : Line %d. Name of native function %s conflicts with previous declaration (ignored)\n", - input_file, line_number, $3); - } else { - DOH *node = NewHash(); - Setattr(node,"scriptname",$3); - Setattr(node,"name",$6); - lang->nativefunction(node); - Delete(node); - } - } - } - | NATIVE LPAREN ID RPAREN extern type declaration LPAREN parms RPAREN SEMI { - if (!WrapExtern) { - init_language(); - add_pointers($6,$7.is_pointer); - if (add_symbol($3)) { - Printf(stderr,"%s : Line %d. Name of native function %s conflicts with previous declaration (ignored)\n", - input_file, line_number, $3); - } else { - if ($5) { - emit_extern_func($7.id, $6, $9, $5, f_header); - } - DOH *node = NewHash(); - Setattr(node,"name",$7.id); - Setattr(node,"scriptname",$3); - Setattr(node,"type",$6); - Setattr(node,"parms",$9); - lang->nativefunction(node); - Delete(node); - } - } - Delete($6); - Delete($9); - } - -/* %title directive */ - - | TITLE STRING styletail { - } - - -/* %section directive */ - - | SECTION STRING styletail { - } - -/* %subsection directive */ - | SUBSECTION STRING styletail { - } - -/* %subsubsection directive */ - | SUBSUBSECTION STRING styletail { - } - - | doc_enable { } - -/* %text directive */ - - | TEXT HBLOCK { - } - - - | typedef_decl { } - -/* Code insertion block */ - - | HBLOCK { - if (!WrapExtern) { - $1[strlen($1) - 1] = 0; - Printf(f_header, "%s\n", $1); - } - } - - | HEADER HBLOCK { - if (!WrapExtern) { - $2[strlen($1) - 2] = 0; - Printf(f_header, "%s\n", $2); - } - } - -/* Super-secret undocumented for people who really know what's going on feature */ - - | WRAPPER HBLOCK { - if (!WrapExtern) { - $2[strlen($2) - 1] = 0; - Printf(f_wrappers,"%s\n",$2); - } - } - - | RUNTIME HBLOCK { - if (!WrapExtern) { - $2[strlen($2) - 1] = 0; - Printf(f_runtime,"%s\n", $2); - } - } - -/* Initialization code */ - - | INIT HBLOCK { - if (!WrapExtern) { - $2[strlen($2) -1] = 0; - Printf(f_init,"%s\n", $2); - } - } - - | INSERT LPAREN ID RPAREN STRING { - if (!WrapExtern) { - File *f = 0; - if (strcmp($3,"headers") == 0) { - f = f_header; - } else if (strcmp($3,"runtime") == 0) { - f = f_runtime; - } else if (strcmp($3,"wrappers") == 0) { - f = f_wrappers; - } else if (strcmp($3,"init") == 0) { - f = f_init; - } - if (!f) { - Printf(stderr,"%s:%d: Unknown target '%s' for %%insert directive.\n", input_file, line_number, $3); - } else { - if (Swig_insert_file($5,f) < 0) { - Printf(stderr,"%s:%d: Couldn't find '%s'. Possible installation problem.\n", input_file, line_number, $5); - SWIG_exit (EXIT_FAILURE); - } - } - } - } -/* Inline block */ - | INLINE HBLOCK { - if (!WrapExtern) { - init_language(); - $2[strlen($2) - 1] = 0; - Printf(f_header, "%s\n", $2); - { - /* Need to run through the preprocessor */ - DOH *cpps; - DOH *s = NewString($2); - Setline(s,start_line); - Setfile(s,input_file); - Seek(s,0,SEEK_SET); - cpps = Preprocessor_parse(s); - start_inline(Char(cpps), start_line); - Delete(s); - Delete(cpps); - } - } - } - -/* Echo mode */ - | ECHO HBLOCK { - if (!WrapExtern) { - Printf(stderr,"%s\n", $2); - } - } - - | ECHO STRING { - if (!WrapExtern) { - Printf(stderr,"%s\n", $2); - } - } - -/* Disable code generation */ - | DOCONLY { - } - -/* Init directive--to avoid errors in other modules */ - - | INIT ID initlist { - Printf(stderr,"%s : Line %d. Warning. %%init directive is deprecated (ignored).\n", input_file,line_number); - for (i = 0; i < $3.count; i++) - if ($3.names[i]) free($3.names[i]); - free($3.names); - } -/* Module directive */ - - | MODULE ID initlist { - lang->set_module($2); - module_init = 1; - init_language(); - for (i = 0; i < $3.count; i++) - if ($3.names[i]) free($3.names[i]); - free($3.names); - } - -/* constant directive */ - - | CONSTANT ID definetype SEMI { - if (($3.type != T_ERROR) && ($3.type != T_SYMBOL)) { - init_language(); - temp_typeptr = NewSwigType($3.type); - create_constant($2, temp_typeptr, $3.id); - Delete(temp_typeptr); - } else if ($3.type == T_SYMBOL) { - // Add a symbol to the SWIG symbol table - if (add_symbol($2)) { - Printf(stderr,"%s : Line %d. Warning. Symbol %s already defined.\n", - input_file,line_number, $2); - } - } - } - - | CONSTANT LPAREN parm RPAREN ID def_args SEMI { - if (($6.type != T_ERROR) && ($6.type != T_SYMBOL)) { - init_language(); - create_constant($5,Gettype($3), $6.id); - Delete($3); - } - } - -/* Enumerations */ - - | extern ENUM ename LBRACE { scanner_clear_start(); } enumlist RBRACE SEMI { - init_language(); - if ($3) { - if (temp_type) Delete(temp_type); - temp_type = NewStringf("enum %s", $3); - /* String *ts = NewSwigType(T_INT); */ - SwigType_typedef(temp_type,$3); - lang->add_typedef(temp_type,$3); - } - } - -/* A typdef'd enum. Pretty common in C headers */ - - | TYPEDEF ENUM ename LBRACE { scanner_clear_start(); } enumlist RBRACE ID { - init_language(); - if (temp_type) Delete(temp_type); - temp_type = NewStringf("enum %s", $3); - /* temp_type= NewSwigType(T_INT);*/ - Active_typedef = Copy(temp_type); - if ($3) { - SwigType_typedef(temp_type,$3); - lang->add_typedef(temp_type,$3); - } - if ($8) { - SwigType_typedef(temp_type,$8); - lang->add_typedef(temp_type,$8); - } - } typedeflist { } - -/* ----------------------------------------------------------------- - typemap support. - - These constructs are used to support type-maps. - ----------------------------------------------------------------- */ - -/* Create a new typemap */ - - | TYPEMAP LPAREN ID COMMA tm_method RPAREN tm_list LBRACE { - TMParm *p; - skip_brace(); - p = $7; - while (p) { - if (strcmp($3,typemap_lang) == 0) - Swig_typemap_register($5,Gettype(p->p),Getname(p->p), CCode, p->args); - p = p->next; - } - free($3); - free($5); - } - -/* Create a new typemap in current language */ - | TYPEMAP LPAREN tm_method RPAREN tm_list LBRACE { - if (!typemap_lang) { - Printf(stderr,"SWIG internal error. No typemap_lang specified.\n"); - Printf(stderr,"typemap on %s : Line %d. will be ignored.\n",input_file,line_number); - FatalError(); - } else { - TMParm *p; - skip_brace(); - p = $5; - while (p) { - Swig_typemap_register($3,Gettype(p->p),Getname(p->p), CCode, p->args); - p = p->next; - } - } - free($3); - } - -/* Create a new typemap */ - - | TYPEMAP LPAREN ID COMMA tm_method RPAREN tm_list STRING { - TMParm *p; - p = $7; - while (p) { - if (strcmp($3,typemap_lang) == 0) - Swig_typemap_register($5,Gettype(p->p),Getname(p->p), $8, p->args); - p = p->next; - } - free($3); - free($5); - } - -/* Create a new typemap in current language */ - | TYPEMAP LPAREN tm_method RPAREN tm_list STRING { - if (!typemap_lang) { - Printf(stderr,"SWIG internal error. No typemap_lang specified.\n"); - Printf(stderr,"typemap on %s : Line %d. will be ignored.\n",input_file,line_number); - FatalError(); - } else { - TMParm *p; - p = $5; - while (p) { - Swig_typemap_register($3,Gettype(p->p),Getname(p->p), $6, p->args); - p = p->next; - } - } - free($3); - } - -/* Clear a typemap */ - - | TYPEMAP LPAREN ID COMMA tm_method RPAREN tm_list SEMI { - TMParm *p; - p = $7; - while (p) { - if (strcmp($3,typemap_lang) == 0) { - Printf(stderr,"%s:%d. Warning. Typemap deletion is temporary disabled in this release.\n", input_file, line_number); -/* Swig_typemap_clear($5,Gettype(p->p),Getname(p->p)); */ - } - p = p->next; - } - free($3); - free($5); - } -/* Clear a typemap in current language */ - - | TYPEMAP LPAREN tm_method RPAREN tm_list SEMI { - if (!typemap_lang) { - Printf(stderr,"SWIG internal error. No typemap_lang specified.\n"); - Printf(stderr,"typemap on %s : Line %d. will be ignored.\n",input_file,line_number); - FatalError(); - } else { - TMParm *p; - p = $5; - while (p) { - Printf(stderr,"%s:%d. Warning. Typemap deletion is temporary disabled in this release.\n", input_file, line_number); -/* Swig_typemap_clear($3,Gettype(p->p),Getname(p->p)); */ - p = p->next; - } - } - free($3); - } - -/* Copy a typemap */ - - | TYPEMAP LPAREN ID COMMA tm_method RPAREN tm_list EQUAL typemap_parm SEMI { - TMParm *p; - p = $7; - while (p) { - if (strcmp($3,typemap_lang) == 0) { - Swig_typemap_copy($5,Gettype($9->p),Getname($9->p),Gettype(p->p),Getname(p->p)); - } - p = p->next; - } - free($3); - free($5); - Delete($9->p); - free($9); - } - -/* Copy typemap in current language */ - - | TYPEMAP LPAREN tm_method RPAREN tm_list EQUAL typemap_parm SEMI { - if (!typemap_lang) { - Printf(stderr,"SWIG internal error. No typemap_lang specified.\n"); - Printf(stderr,"typemap on %s : Line %d. will be ignored.\n",input_file,line_number); - FatalError(); - } else { - TMParm *p; - p = $5; - while (p) { - Swig_typemap_copy($3,Gettype($7->p),Getname($7->p),Gettype(p->p),Getname(p->p)); - p = p->next; - } - } - free($3); - Delete($7->p); - free($7); - } -/* ----------------------------------------------------------------- - apply and clear support (for typemaps) - ----------------------------------------------------------------- */ - - | APPLY typemap_parm LBRACE tm_list RBRACE { - TMParm *p; - p = $4; - while(p) { - Swig_typemap_apply(Gettype($2->p),Getname($2->p),Gettype(p->p),Getname(p->p)); - p = p->next; - } - free($4); - Delete($2->args); - free($2); - } - | CLEAR tm_list SEMI { - TMParm *p; - p = $2; - while (p) { - Printf(stderr,"%s:%d. Warning. %%clear directive is temporarily disabled in this release. Ignored.\n", input_file, line_number); -/* Swig_typemap_clear_apply(Gettype(p->p), Getname(p->p)); */ - p = p->next; - } - } - - -/* ----------------------------------------------------------------- - exception support - - These constructs are used to define exceptions - ----------------------------------------------------------------- */ - -/* An exception definition */ - | EXCEPT LPAREN ID RPAREN LBRACE { - skip_brace(); - if (strcmp($3,typemap_lang) == 0) { - Swig_except_register(CCode); - } - free($3); - } - -/* A Generic Exception (no language specified */ - | EXCEPT LBRACE { - skip_brace(); - Swig_except_register(CCode); - } - -/* Clear an exception */ - - | EXCEPT LPAREN ID RPAREN SEMI { - Swig_except_clear(); - } - -/* Generic clear */ - | EXCEPT SEMI { - Swig_except_clear(); - } - -/* Miscellaenous stuff */ - - | SEMI { } - | cpp { } - | objective_c { } - | error { - if (!Error) { - { - static int last_error_line = -1; - if (last_error_line != line_number) { - Printf(stderr,"%s : Line %d. Syntax error in input.\n", input_file, line_number); - FatalError(); - last_error_line = line_number; - // Try to make some kind of recovery. - skip_decl(); - } - Error = 1; - } - } - } - -/* A an extern C type declaration. Does nothing, but is ignored */ - - | EXTERN STRING LBRACE command RBRACE { } - -/* Officially, this directive doesn't exist yet */ - - | pragma { } - -/* %style directive. This applies to all current styles */ - - | STYLE stylelist { - } - -/* %localstyle directive. This applies only to the current style */ - - | LOCALSTYLE stylelist { - } - -/* %types directive. Used to register types with the type-checker */ - | TYPES LPAREN parms RPAREN SEMI { - Parm *p = $3; - while (p) { - SwigType *t = Gettype(p); - SwigType_remember(t); - p = Getnext(p); - } - Delete($3); - } - -/* Dcumentation disable/enable */ - -doc_enable : DOC_DISABLE { - } -/* %enabledoc directive */ - | DOC_ENABLE { - } - ; - -/* Note : This really needs to be re-done */ - -/* A typedef with pointers */ -typedef_decl : TYPEDEF type declaration { - init_language(); - /* Add a new typedef */ - Active_typedef = Copy($2); - add_pointers($2,$3.is_pointer); - SwigType_typedef($2, $3.id); - lang->add_typedef($2,$3.id); - cplus_register_type($3.id); - } typedeflist { }; - -/* A rudimentary typedef involving function pointers */ - - | TYPEDEF type LPAREN STAR pname RPAREN LPAREN parms RPAREN SEMI { - init_language(); - /* Typedef'd pointer */ - DOHList *l = typelist($8); - SwigType_add_function($2,l); - SwigType_add_pointer($2); - SwigType_typedef($2,$5); - lang->add_typedef($2,$5); - cplus_register_type($5); - Delete($2); - free($5); - Delete($8); - Delete(l); - } - -/* A typedef involving function pointers again */ - - | TYPEDEF type stars LPAREN STAR pname RPAREN LPAREN parms RPAREN SEMI { - init_language(); - add_pointers($2,$3); - DOHList *l = typelist($9); - SwigType_add_function($2,l); - SwigType_add_pointer($2); - SwigType_typedef($2,$6); - lang->add_typedef($2,$6); - cplus_register_type($6); - Delete($2); - free($6); - Delete($9); - Delete(l); - } - -/* A typedef involving arrays */ - - | TYPEDEF type declaration array { - init_language(); - Active_typedef = Copy($2); - // This datatype is going to be readonly - - add_pointers($2,$3.is_pointer); - SwigType_push($2,ArrayString); - SwigType_typedef($2,$3.id); - lang->add_typedef($2,$3.id); - cplus_register_type($3.id); - - } typedeflist { } - ; - -/* ------------------------------------------------------------------------ - Typedef list - - The following rules are used to manage typedef lists. Only a temporary - hack until the SWIG 2.0 parser gets online. - - Active_typedef contains the datatype of the last typedef (if applicable) - ------------------------------------------------------------------------ */ - - -typedeflist : COMMA declaration typedeflist { - if (Active_typedef) { - SwigType *t; - t = Copy(Active_typedef); - add_pointers(t,$2.is_pointer); - SwigType_typedef(t,$2.id); - lang->add_typedef(t,$2.id); - cplus_register_type($2.id); - Delete(t); - } - } - | COMMA declaration array { - SwigType *t; - t = Copy(Active_typedef); - add_pointers(t, $2.is_pointer); - SwigType_push(t,ArrayString); - SwigType_typedef(t,$2.id); - lang->add_typedef(t,$2.id); - cplus_register_type($2.id); - Delete(t); - Printf(stderr,"%s : Line %d. Warning. Array type %s will be read-only without a typemap.\n",input_file,line_number, $2.id); - } - | empty { } - ; - -pragma : PRAGMA LPAREN ID COMMA ID stylearg RPAREN { - if (!WrapExtern) - lang->pragma($3,$5,$6); - Printf(stderr,"%s : Line %d. Warning. '%%pragma(lang,opt=value)' syntax is obsolete.\n", - input_file,line_number); - Printf(stderr," Use '%%pragma(lang) opt=value' instead.\n"); - } - - | PRAGMA ID stylearg { - if (!WrapExtern) - swig_pragma($2,$3); - } - | PRAGMA LPAREN ID RPAREN ID stylearg { - if (!WrapExtern) - lang->pragma($3,$5,$6); - } - ; - -/* Allow lists of variables and functions to be built up */ - -stail : SEMI { } - | COMMA declaration array2 def_args { - init_language(); - temp_typeptr = Copy(Active_type); - add_pointers(temp_typeptr, $2.is_pointer); - if ($3 > 0) { - SwigType_push(temp_typeptr, ArrayString); - } - if ($2.is_reference) { - Printf(stderr,"%s : Line %d. Error. Linkage to C++ reference not allowed.\n", input_file, line_number); - FatalError(); - } else { - if (SwigType_isconst(temp_typeptr)) { - create_constant($2.id, temp_typeptr, $4.id); - } else { - create_variable(Active_extern,$2.id, temp_typeptr); - } - } - Delete(temp_typeptr); - } stail { } - | COMMA declaration LPAREN parms RPAREN cpp_const { - init_language(); - temp_typeptr = Copy(Active_type); - add_pointers(temp_typeptr, $2.is_pointer); - if ($2.is_reference) SwigType_add_reference(temp_typeptr); - create_function(Active_extern, $2.id, temp_typeptr, $4); - Delete(temp_typeptr); - Delete($4); - } stail { } - ; - -extern : EXTERN { $$ = 1; } - | empty {$$ = 0; } - | EXTERN STRING { - if (strcmp($2,"C") == 0) { - $$ = 2; - } else { - Printf(stderr,"%s : Line %d. Unrecognized extern type \"%s\" (ignored).\n", input_file, line_number, $2); - FatalError(); - } - } - ; - -/* End of a function declaration. Allows C++ "const" directive and inline code */ - -func_end : cpp_const LBRACE { skip_brace(); } -/* | LBRACE { skip_brace(); } */ - ; - -/* ------------------------------------------------------------------------------ - Function parameter lists - - ------------------------------------------------------------------------------ */ - -parms : parm ptail { - SwigType *pt = Gettype($1); - if (SwigType_type(pt) != T_VOID) { - Setnext($1,$2); - $$ = $1; - } else { - $$ = $2; - } - } - | empty { $$ = 0; } - ; - -ptail : COMMA parm ptail { - Setnext($2,$3); - $$ = $2; - } - | empty { $$ = 0; } - ; - -parm : parm_type { - $$ = $1; - } - -parm_type : type pname { - if (InArray) { - // Add array string to the type - SwigType_push($1, ArrayString); - } - $$ = NewParm($1,$2); - Setvalue($$,DefArg); - Delete($1); - free($2); - } - - | type stars pname { - $$ = NewParm($1,$3); - add_pointers(Gettype($$), $2); - Setvalue($$,DefArg); - if (InArray) { - // Add array string to the type - SwigType_push(Gettype($$), ArrayString); - } - Delete($1); - free($3); - } - - | type AND pname { - $$ = NewParm($1,$3); - SwigType *pt = Gettype($$); - SwigType_add_reference(pt); - Setvalue($$,DefArg); - if (!CPlusPlus) { - Printf(stderr,"%s : Line %d. Warning. Use of C++ Reference detected. Use the -c++ option.\n", input_file, line_number); - } - Delete($1); - free($3); - } - | type LPAREN stars pname RPAREN LPAREN parms RPAREN { - $$ = NewParm($1,$4); - SwigType *pt = Gettype($$); - DOHList *l = typelist($7); - SwigType_add_function(pt,l); - add_pointers(pt,$3); - Setname($$,$4); - Delete($1); - free($4); - Delete($7); - Delete(l); - } - | PERIOD PERIOD PERIOD { - Printf(stderr,"%s : Line %d. Variable length arguments not supported (ignored).\n", input_file, line_number); - $$ = NewParm(NewSwigType(T_INT),(char *) "varargs"); - FatalError(); - } - ; - -pname : ID def_args { - $$ = $1; - InArray = 0; - if ($2.type == T_CHAR) - DefArg = Swig_copy_string(Char(ConstChar)); - else - DefArg = Swig_copy_string($2.id); - if ($2.id) free($2.id); - } - | ID array { - $$ = $1; - InArray = $2; - DefArg = 0; - } - | array { - $$ = (char *) malloc(1); - $$[0] = 0; - InArray = $1; - DefArg = 0; - } - | empty { $$ = (char *) malloc(1); - $$[0] = 0; - InArray = 0; - DefArg = 0; - } - ; - -def_args : EQUAL definetype { $$ = $2; } - | EQUAL AND ID { - $$.id = (char *) malloc(strlen($3)+2); - $$.id[0] = '&'; - strcpy(&$$.id[1], $3); - $$.type = T_USER; - } - | EQUAL LBRACE { - skip_brace(); - $$.id = 0; $$.type = T_INT; - } - | COLON NUM_INT { - } - | empty {$$.id = 0; $$.type = T_INT;} - ; - -/* Declaration must be an identifier, possibly preceded by a * for pointer types */ - -declaration : ID { $$.id = $1; - $$.is_pointer = 0; - $$.is_reference = 0; - } - | stars ID { - $$.id = $2; - $$.is_pointer = $1; - $$.is_reference = 0; - } - | AND ID { - $$.id = $2; - $$.is_pointer = 0; - $$.is_reference = 1; - if (!CPlusPlus) { - Printf(stderr,"%s : Line %d. Warning. Use of C++ Reference detected. Use the -c++ option.\n", input_file, line_number); - } - } - ; - -stars : STAR empty { $$ = 1; } - | STAR stars { $$ = $2 + 1;} - ; - - -array : LBRACKET RBRACKET array2 { - $$ = $3 + 1; - SwigType_add_array(ArrayString,(char*)""); - } - | LBRACKET expr RBRACKET array2 { - $$ = $4 + 1; - SwigType_add_array(ArrayString,$2.id); - } - ; -array2 : array { - $$ = $1; - } - | empty { - $$ = 0; - Clear(ArrayString); - } - ; - -/* Data type must be a built in type or an identifier for user-defined types - This type can be preceded by a modifier. */ - -type : TYPE_INT { - $$ = $1; - } - | TYPE_SHORT opt_int { - $$ = $1; - } - | TYPE_LONG opt_int { - $$ = $1; - } - | TYPE_CHAR { - $$ = $1; - } - | TYPE_BOOL { - $$ = $1; - } - | TYPE_FLOAT { - $$ = $1; - } - | TYPE_DOUBLE { - $$ = $1; - } - | TYPE_VOID { - $$ = $1; - } - | TYPE_SIGNED opt_signed { - if ($2) $$ = $2; - else $$ = $1; - } - | TYPE_UNSIGNED opt_unsigned { - if ($2) $$ = $2; - else $$ = $1; - } - | TYPE_TYPEDEF objc_protolist { - $$ = $1; - $$ = NewStringf("%s%s",$1,$2); - Delete($1); - } - | ID objc_protolist { - $$ = NewStringf("%s%s",$1,$2); - free($1); - } - | CONST type { - $$ = $2; - SwigType_add_qualifier($$,(char*)"const"); - } - | cpptype ID { - $$ = NewStringf("%s %s",$1,$2); - } - | ID DCOLON ID { - $$ = NewStringf("%s::%s", $1,$3); - } -/* This declaration causes a shift-reduce conflict. Unresolved for now */ - - - | DCOLON ID { - $$ = NewString($2); - } - | ENUM ID { - $$ = NewStringf("enum %s", $2); - } - | TYPE_RAW { - $$ = $1; - } - ; - -/* type specification without ID symbol. Used in some cases to prevent shift-reduce conflicts */ - -strict_type : TYPE_INT { - $$ = $1; - } - | TYPE_SHORT opt_int { - $$ = $1; - } - | TYPE_LONG opt_int { - $$ = $1; - } - | TYPE_CHAR { - $$ = $1; - } - | TYPE_BOOL { - $$ = $1; - } - | TYPE_FLOAT { - $$ = $1; - } - | TYPE_DOUBLE { - $$ = $1; - } - | TYPE_VOID { - $$ = $1; - } - | TYPE_SIGNED opt_signed { - if ($2) $$ = $2; - else $$ = $1; - } - | TYPE_UNSIGNED opt_unsigned { - if ($2) $$ = $2; - else $$ = $1; - } - | TYPE_TYPEDEF objc_protolist { - $$ = NewStringf("%s%s", $1,$2); - } - | CONST type { - $$ = $2; - SwigType_add_qualifier($$,(char*)"const"); - } - | cpptype ID { - $$ = NewStringf("%s %s", $1, $2); - } - | TYPE_RAW { - $$ = $1; - } - ; - -/* Optional signed types */ - -opt_signed : empty { - $$ = 0; - } - | TYPE_INT { - $$ = $1; - } - | TYPE_SHORT opt_int { - $$ = $1; - } - | TYPE_LONG opt_int { - $$ = $1; - } - | TYPE_CHAR { - $$ = NewString("signed char"); - } - ; - -/* Optional unsigned types */ - -opt_unsigned : empty { - $$ = 0; - } - | TYPE_INT { - $$ = NewString("unsigned int"); - } - | TYPE_SHORT opt_int { - $$ = NewString("unsigned short"); - } - | TYPE_LONG opt_int { - $$ = NewString("unsigned long"); - } - | TYPE_CHAR { - $$ = NewString("unsigned char"); - } - ; - -opt_int : TYPE_INT { } - | empty { } - ; - -definetype : { scanner_check_typedef(); } expr { - $$ = $2; - scanner_ignore_typedef(); - if (ConstChar) Delete(ConstChar); - ConstChar = 0; - } - | STRING { - $$.id = $1; - $$.type = T_CHAR; - if (ConstChar) Delete(ConstChar); - ConstChar = NewStringf("\"%(escape)s\"",$1); - } - | CHARCONST { - $$.id = $1; - $$.type = T_CHAR; - if (ConstChar) Delete(ConstChar); - ConstChar = NewStringf("'%(escape)s'", $1); - } - ; - - -/* Initialization function links */ - -initlist : initlist COMMA ID { - $$ = $1; - $$.names[$$.count] = Swig_copy_string($3); - $$.count++; - $$.names[$$.count] = (char *) 0; - } - | empty { - $$.names = (char **) malloc(NI_NAMES*sizeof(char*)); - $$.count = 0; - for (i = 0; i < NI_NAMES; i++) - $$.names[i] = (char *) 0; - } - ; - -/* Some stuff for handling enums */ - -ename : ID { $$ = $1; } - | empty { $$ = (char *) 0;} - ; - -/* SWIG enum list. -*/ - -enumlist : enumlist COMMA edecl {} - | edecl {} - ; - - -edecl : ID { - temp_typeptr = NewSwigType(T_INT); - create_constant($1, temp_typeptr, $1); - Delete(temp_typeptr); - } - | ID EQUAL { scanner_check_typedef();} etype { - temp_typeptr = NewSwigType($4.type); -// Use enum name instead of value -// OLD create_constant($1, temp_typeptr, $4.id); - if ($4.type == T_CHAR) - create_constant($1,temp_typeptr, $4.id); - else - create_constant($1, temp_typeptr, $1); - Delete(temp_typeptr); - scanner_ignore_typedef(); - } - | empty { } - ; - -etype : expr { - $$ = $1; - if (($$.type != T_INT) && ($$.type != T_UINT) && - ($$.type != T_LONG) && ($$.type != T_ULONG) && - ($$.type != T_SHORT) && ($$.type != T_USHORT) && - ($$.type != T_SCHAR) && ($$.type != T_UCHAR)) { - Printf(stderr,"%s : Lind %d. Type error. Expecting an int\n", - input_file, line_number); - FatalError(); - } - - } - | CHARCONST { - $$.id = $1; - $$.type = T_INT; - } - ; - -/* Arithmetic expressions. Used for constants and other cool stuff. - Really, we're not doing anything except string concatenation, but - this does allow us to parse many constant declarations. - */ - -expr : NUM_INT { - $$.id = $1; - $$.type = T_INT; - } - | NUM_FLOAT { - $$.id = $1; - $$.type = T_DOUBLE; - } - | NUM_UNSIGNED { - $$.id = $1; - $$.type = T_UINT; - } - | NUM_LONG { - $$.id = $1; - $$.type = T_LONG; - } - | NUM_ULONG { - $$.id = $1; - $$.type = T_ULONG; - } - | SIZEOF LPAREN type RPAREN { - $$.id = (char *) malloc(Len($3)+9); - sprintf($$.id,"sizeof(%s)", Char($3)); - $$.type = T_INT; - } - | LPAREN strict_type RPAREN expr %prec UMINUS { - $$.id = (char *) malloc(strlen($4.id)+Len($2)+3); - sprintf($$.id,"(%s)%s",Char($2),$4.id); - $$.type = SwigType_type($2); - } - | ID { - $$.id = $1; - $$.type = T_INT; - } - | ID DCOLON ID { - $$.id = (char *) malloc(strlen($1)+strlen($3)+3); - sprintf($$.id,"%s::%s",$1,$3); - $$.type = T_INT; - free($1); - free($3); - } - | expr PLUS expr { - E_BINARY($$.id,$1.id,$3.id,"+"); - $$.type = promote($1.type,$3.type); - free($1.id); - free($3.id); - } - | expr MINUS expr { - E_BINARY($$.id,$1.id,$3.id,"-"); - $$.type = promote($1.type,$3.type); - free($1.id); - free($3.id); - } - | expr STAR expr { - E_BINARY($$.id,$1.id,$3.id,"*"); - $$.type = promote($1.type,$3.type); - free($1.id); - free($3.id); - - } - | expr SLASH expr { - E_BINARY($$.id,$1.id,$3.id,"/"); - $$.type = promote($1.type,$3.type); - free($1.id); - free($3.id); - - } - | expr AND expr { - E_BINARY($$.id,$1.id,$3.id,"&"); - $$.type = promote($1.type,$3.type); - if (($1.type == T_DOUBLE) || ($3.type == T_DOUBLE)) { - Printf(stderr,"%s : Line %d. Type error in constant expression (expecting integers).\n", input_file, line_number); - FatalError(); - } - free($1.id); - free($3.id); - - } - | expr OR expr { - E_BINARY($$.id,$1.id,$3.id,"|"); - $$.type = promote($1.type,$3.type); - if (($1.type == T_DOUBLE) || ($3.type == T_DOUBLE)) { - Printf(stderr,"%s : Line %d. Type error in constant expression (expecting integers).\n", input_file, line_number); - FatalError(); - } - $$.type = T_INT; - free($1.id); - free($3.id); - - } - | expr XOR expr { - E_BINARY($$.id,$1.id,$3.id,"^"); - $$.type = promote($1.type,$3.type); - if (($1.type == T_DOUBLE) || ($3.type == T_DOUBLE)) { - Printf(stderr,"%s : Line %d. Type error in constant expression (expecting integers).\n", input_file, line_number); - FatalError(); - } - $$.type = T_INT; - free($1.id); - free($3.id); - - } - | expr LSHIFT expr { - E_BINARY($$.id,$1.id,$3.id,"<<"); - $$.type = promote($1.type,$3.type); - if (($1.type == T_DOUBLE) || ($3.type == T_DOUBLE)) { - Printf(stderr,"%s : Line %d. Type error in constant expression (expecting integers).\n", input_file, line_number); - FatalError(); - } - $$.type = T_INT; - free($1.id); - free($3.id); - - } - | expr RSHIFT expr { - E_BINARY($$.id,$1.id,$3.id,">>"); - $$.type = promote($1.type,$3.type); - if (($1.type == T_DOUBLE) || ($3.type == T_DOUBLE)) { - Printf(stderr,"%s : Line %d. Type error in constant expression (expecting integers).\n", input_file, line_number); - FatalError(); - } - $$.type = T_INT; - free($1.id); - free($3.id); - - } - | MINUS expr %prec UMINUS { - $$.id = (char *) malloc(strlen($2.id)+2); - sprintf($$.id,"-%s",$2.id); - $$.type = $2.type; - free($2.id); - - } - | NOT expr { - $$.id = (char *) malloc(strlen($2.id)+2); - sprintf($$.id,"~%s",$2.id); - if ($2.type == T_DOUBLE) { - Printf(stderr,"%s : Line %d. Type error in constant expression (expecting integers).\n", input_file, line_number); - FatalError(); - } - $$.type = $2.type; - free($2.id); - } - | LPAREN expr RPAREN { - $$.id = (char *) malloc(strlen($2.id)+3); - sprintf($$.id,"(%s)", $2.id); - $$.type = $2.type; - free($2.id); - } - ; -/****************************************************************/ -/* C++ Support */ -/****************************************************************/ - -cpp : cpp_class { } - | cpp_other {} - ; - -cpp_class : - -/* A class/struct/union definition */ - extern cpptype ID inherit LBRACE { - char *iname; - init_language(); - SwigType_new_scope(); - - sprintf(temp_name,"CPP_CLASS:%s\n",$3); - if (add_symbol(temp_name)) { - Printf(stderr,"%s : Line %d. Error. %s %s is multiply defined.\n", input_file, line_number, $2, $3); - FatalError(); - } - if ((!CPlusPlus) && (strcmp($2,"class") == 0)) - Printf(stderr,"%s : Line %d. *** WARNING ***. C++ mode is disabled (enable using -c++)\n", input_file, line_number); - - iname = make_name($3); - if (iname == $3) - cplus_open_class($3, 0, $2); - else - cplus_open_class($3, iname, $2); - if (strcmp($2,"class") == 0) - cplus_mode = CPLUS_PRIVATE; - else - cplus_mode = CPLUS_PUBLIC; - scanner_clear_start(); - nested_list = 0; - // Merge in scope from base classes - cplus_inherit_scope($4.count,$4.names); - } cpp_members RBRACE { - if ($4.names) { - if (strcmp($2,"union") != 0) - cplus_inherit($4.count, $4.names); - else { - Printf(stderr,"%s : Line %d. Inheritance not allowed for unions.\n",input_file, line_number); - FatalError(); - } - } - // Clean up the inheritance list - if ($4.names) { - int j; - for (j = 0; j < $4.count; j++) { - if ($4.names[j]) free($4.names[j]); - } - free($4.names); - } - - // Dumped nested declarations (if applicable) - dump_nested($3); - - // Save and collapse current scope - SwigType_set_scope_name($3); - cplus_register_scope(SwigType_pop_scope()); - - cplus_class_close((char *) 0); - cplus_mode = CPLUS_PUBLIC; - } - -/* Class with a typedef */ - - | TYPEDEF cpptype ID inherit LBRACE { - char *iname; - init_language(); - SwigType_new_scope(); - - sprintf(temp_name,"CPP_CLASS:%s\n",$3); - if (add_symbol(temp_name)) { - Printf(stderr,"%s : Line %d. Error. %s %s is multiply defined.\n", input_file, line_number, $2, $3); - FatalError(); - } - if ((!CPlusPlus) && (strcmp($2,"class") == 0)) - Printf(stderr,"%s : Line %d. *** WARNING ***. C++ mode is disabled (enable using -c++)\n", input_file, line_number); - - iname = make_name($3); - if ($3 == iname) - cplus_open_class($3, 0, $2); - else - cplus_open_class($3, iname, $2); - if (strcmp($2,"class") == 0) - cplus_mode = CPLUS_PRIVATE; - else - cplus_mode = CPLUS_PUBLIC; - scanner_clear_start(); - nested_list = 0; - - // Merge in scope from base classes - cplus_inherit_scope($4.count,$4.names); - - } cpp_members RBRACE declaration { - if ($4.names) { - if (strcmp($2,"union") != 0) - cplus_inherit($4.count, $4.names); - else { - Printf(stderr,"%s : Line %d. Inheritance not allowed for unions.\n",input_file, line_number); - FatalError(); - } - } - // Create a datatype for correctly processing the typedef - Active_typedef = NewStringf("%s %s", $2, $3); - // Clean up the inheritance list - if ($4.names) { - int j; - for (j = 0; j < $4.count; j++) { - if ($4.names[j]) free($4.names[j]); - } - free($4.names); - } - - if ($9.is_pointer > 0) { - Printf(stderr,"%s : Line %d. typedef struct { } *id not supported properly. Winging it...\n", input_file, line_number); - - } - // Create dump nested class code - if ($9.is_pointer > 0) { - dump_nested($3); - } else { - dump_nested($9.id); - } - - // Collapse any datatypes created in the the class - - SwigType_set_scope_name($3); - cplus_register_scope(SwigType_pop_scope()); - if ($9.is_pointer > 0) { - cplus_class_close($3); - } else { - cplus_class_close($9.id); - } - // Create a typedef in global scope - if ($9.is_pointer == 0) { - SwigType_typedef(Active_typedef,$9.id); - lang->add_typedef(Active_typedef,$9.id); - } else { - SwigType *t = Copy(Active_typedef); - add_pointers(t,$9.is_pointer); - SwigType_typedef(t,$9.id); - lang->add_typedef(t,$9.id); - cplus_register_type($9.id); - Delete(t); - } - cplus_mode = CPLUS_PUBLIC; - } typedeflist { }; - -/* An unnamed struct with a typedef */ - - | TYPEDEF cpptype LBRACE { - char *iname; - init_language(); - SwigType_new_scope(); - if ((!CPlusPlus) && (strcmp($2,"class") == 0)) - Printf(stderr,"%s : Line %d. *** WARNING ***. C++ mode is disabled (enable using -c++)\n", input_file, line_number); - - iname = make_name((char*)""); - if (strlen(iname)) - cplus_open_class((char *)"", iname, $2); - else - cplus_open_class((char *) "",0,$2); - if (strcmp($2,"class") == 0) - cplus_mode = CPLUS_PRIVATE; - else - cplus_mode = CPLUS_PUBLIC; - scanner_clear_start(); - nested_list = 0; - } cpp_members RBRACE declaration { - if ($7.is_pointer > 0) { - Printf(stderr,"%s : Line %d. typedef %s {} *%s not supported correctly. Will be ignored.\n", input_file, line_number, $2, $7.id); - cplus_abort(); - } else { - sprintf(temp_name,"CPP_CLASS:%s\n",$7.id); - if (add_symbol(temp_name)) { - Printf(stderr,"%s : Line %d. Error. %s %s is multiply defined.\n", input_file, line_number, $2, $7.id); - FatalError(); - } - } - // Create a datatype for correctly processing the typedef - Active_typedef = NewString($7.id); - - // Dump nested classes - if ($7.is_pointer == 0) - dump_nested($7.id); - - // Go back to previous scope - - cplus_register_scope(SwigType_pop_scope()); - if ($7.is_pointer == 0) - cplus_class_close($7.id); - cplus_mode = CPLUS_PUBLIC; - } typedeflist { } - ; - -cpp_other :/* A dummy class name */ - - extern cpptype ID SEMI { - char *iname; - init_language(); - iname = make_name($3); - lang->cpp_class_decl($3,iname,$2); - } - -/* A static C++ member function (declared out of scope) */ - - | extern type declaration DCOLON ID LPAREN parms RPAREN SEMI { - init_language(); - if (!CPlusPlus) - Printf(stderr,"%s : Line %d. *** WARNING ***. C++ mode is disabled (enable using -c++)\n", input_file, line_number); - - add_pointers($2,$3.is_pointer); - if ($3.is_reference) SwigType_add_reference($2); - // Fix up the function name - sprintf(temp_name,"%s::%s",$3.id,$5); - if (!Rename_true) { - Rename_true = 1; - sprintf(yy_rename,"%s_%s",$3.id,$5); - } - create_function($1, temp_name, $2, $7); - Delete($2); - Delete($7); - } - -/* A static C++ member data */ - | extern type declaration DCOLON ID SEMI { - init_language(); - if (!CPlusPlus) - Printf(stderr,"%s : Line %d. *** WARNING ***. C++ mode is disabled (enable using -c++)\n", input_file, line_number); - - add_pointers($2,$3.is_pointer); - // Fix up the function name - sprintf(temp_name,"%s::%s",$3.id,$5); - if (!Rename_true) { - Rename_true = 1; - sprintf(yy_rename,"%s_%s",$3.id,$5); - } - create_variable($1,temp_name, $2); - Delete($2); - } - -/* Operator overloading catch */ - - | extern type declaration DCOLON OPERATOR { - Printf(stderr,"%s : Line %d. Operator overloading not supported (ignored).\n", input_file, line_number); - skip_decl(); - Delete($2); - } - - -/* Template catch */ - | TEMPLATE { - Printf(stderr,"%s : Line %d. Templates not currently supported (ignored).\n", - input_file, line_number); - skip_decl(); - } - -/* %addmethods directive used outside of a class definition */ - - | ADDMETHODS ID LBRACE { - cplus_mode = CPLUS_PUBLIC; - cplus_set_class($2); - scanner_clear_start(); - AddMethods = 1; - } added_members RBRACE { - cplus_unset_class(); - AddMethods = 0; - } - ; - -added_members : cpp_member cpp_members { } - | objc_method objc_methods { } - | empty { } - ; - -cpp_members : cpp_member cpp_members {} - | ADDMETHODS LBRACE { - AddMethods = 1; - } cpp_members RBRACE { - AddMethods = 0; - } cpp_members { } - | error { - skip_decl(); - { - static int last_error_line = -1; - if (last_error_line != line_number) { - Printf(stderr,"%s : Line %d. Syntax error in input.\n", input_file, line_number); - FatalError(); - last_error_line = line_number; - } - } - } cpp_members { } - | empty { } - ; - -cpp_member : type declaration LPAREN parms RPAREN cpp_end { - char *iname; - init_language(); - if (cplus_mode == CPLUS_PUBLIC) { - add_pointers($1,$2.is_pointer); - if ($2.is_reference) SwigType_add_reference($1); - iname = make_name($2.id); - if (iname == $2.id) iname = 0; - cplus_member_func($2.id, iname, $1,$4,0); - } - scanner_clear_start(); - Delete($1); - Delete($4); - } - -/* Virtual member function */ - - | VIRTUAL type declaration LPAREN parms RPAREN cpp_vend { - char *iname; - init_language(); - if (cplus_mode == CPLUS_PUBLIC) { - add_pointers($2,$3.is_pointer); - if ($3.is_reference) SwigType_add_reference($2); - iname = make_name($3.id); - if (iname == $3.id) iname = 0; - cplus_member_func($3.id,iname,$2,$5,$7 ? PURE_VIRTUAL : PLAIN_VIRTUAL); - } - scanner_clear_start(); - Delete($2); - Delete($5); - } - -/* Possibly a constructor */ - | ID LPAREN parms RPAREN ctor_end { - char *iname; - init_language(); - if (cplus_mode == CPLUS_PUBLIC) { - iname = make_name($1); - if (iname == $1) iname = 0; - cplus_constructor($1,iname, $3); - } - scanner_clear_start(); - Delete($3); - } - -/* A destructor (hopefully) */ - - | NOT ID LPAREN parms RPAREN cpp_end { - char *iname; - init_language(); - if (cplus_mode == CPLUS_PUBLIC) { - iname = make_name($2); - if (iname == $2) iname = 0; - cplus_destructor($2,iname); - } - scanner_clear_start(); - Delete($4); - } - -/* A virtual destructor */ - - | VIRTUAL NOT ID LPAREN RPAREN cpp_end { - char *iname; - init_language(); - if (cplus_mode == CPLUS_PUBLIC) { - iname = make_name($3); - if (iname == $3) iname = 0; - cplus_destructor($3,iname); - } - scanner_clear_start(); - } - -/* Member data */ - - | type declaration def_args { - char *iname; - init_language(); - if (cplus_mode == CPLUS_PUBLIC) { - if (Active_type) Delete(Active_type); - Active_type = Copy($1); - add_pointers($1,$2.is_pointer); - if ($2.is_reference) SwigType_add_reference($1); - if (SwigType_isconst($1)) { - iname = make_name($2.id); - if (iname == $2.id) iname = 0; - my_cplus_declare_const($2.id,iname, $1, $3.id); - } else { - iname = make_name($2.id); - if (iname == $2.id) iname = 0; - cplus_variable($2.id,iname,$1); - } - } - scanner_clear_start(); - Delete($1); - } cpp_tail { } - - | type declaration array def_args { - char *iname; - init_language(); - if (cplus_mode == CPLUS_PUBLIC) { - if (Active_type) Delete(Active_type); - Active_type = Copy($1); - add_pointers($1, $2.is_pointer); - if ($2.is_reference) SwigType_add_reference($1); - SwigType_push($1,ArrayString); - iname = make_name($2.id); - if (iname == $2.id) iname = 0; - cplus_variable($2.id,iname,$1); - } - scanner_clear_start(); - Delete($1); - } - - -/* Static Member data */ - - | STATIC type declaration { - char *iname; - init_language(); - if (cplus_mode == CPLUS_PUBLIC) { - add_pointers($2,$3.is_pointer); - iname = make_name($3.id); - if (iname == $3.id) iname = 0; - cplus_static_var($3.id,iname,$2); - if (Active_type) Delete(Active_type); - Active_type = Copy($2); - } - scanner_clear_start(); - Delete($2); - } cpp_tail { } - -/* Static member function */ - - | STATIC type declaration LPAREN parms RPAREN cpp_end { - char *iname; - add_pointers($2,$3.is_pointer); - if ($3.is_reference) SwigType_add_reference($2); - if (cplus_mode == CPLUS_PUBLIC) { - iname = make_name($3.id); - if (iname == $3.id) iname = 0; - cplus_static_func($3.id, iname, $2, $5); - } - scanner_clear_start(); - Delete($2); - Delete($5); - } -/* Turn on public: mode */ - - | PUBLIC COLON { - cplus_mode = CPLUS_PUBLIC; - scanner_clear_start(); - } - -/* Turn on private: mode */ - - | PRIVATE COLON { - cplus_mode = CPLUS_PRIVATE; - scanner_clear_start(); - } - -/* Turn on protected mode */ - - | PROTECTED COLON { - cplus_mode = CPLUS_PROTECTED; - scanner_clear_start(); - } - -/* This is the new style rename */ - - | NAME LPAREN ID RPAREN { - strcpy(yy_rename,$3); - Rename_true = 1; - } - -/* New mode */ - | NEW { - NewObject = 1; - } cpp_member { - NewObject = 0; - } - -/* C++ Enum */ - | ENUM ename LBRACE {scanner_clear_start();} cpp_enumlist RBRACE SEMI { - - // if ename was supplied. Install it as a new integer datatype. - init_language(); - if (cplus_mode == CPLUS_PUBLIC) { - if ($2) { - cplus_register_type($2); - if (temp_type) Delete(temp_type); - /* temp_type = NewSwigType(T_INT); */ - temp_type = NewStringf("enum %s",$2); - SwigType_typedef(temp_type,$2); - lang->add_typedef(temp_type,$2); - } - } - } - | READONLY { - Status = Status | STAT_READONLY; - scanner_clear_start(); - } - | READWRITE { - Status = Status & ~(STAT_READONLY); - scanner_clear_start(); - } -/* A friend : Illegal */ - | FRIEND { - Printf(stderr,"%s : Line %d. Friends are not allowed--members only! (ignored)\n", input_file, line_number); - skip_decl(); - scanner_clear_start(); - } - -/* An operator: Illegal */ - | type type_extra OPERATOR { - Printf(stderr,"%s : Line %d. Operator overloading not supported (ignored).\n", input_file, line_number); - skip_decl(); - scanner_clear_start(); - } - -/* A typedef inside a class */ - | typedef_decl { } - -/* Pragma directive */ - - | cpp_pragma { - scanner_clear_start(); - } - - -cpp_pragma : PRAGMA ID stylearg { - if (!WrapExtern) { } - } - | PRAGMA LPAREN ID RPAREN ID stylearg { - if (!WrapExtern) - cplus_add_pragma($3,$5,$6); - } - ; - - - -/* ---------------------------------------------------------------------- - Nested structure. This is a big ugly "hack". If we encounter - a nested structure, we're going to grab the text of its definition and - feed it back into the scanner. In the meantime, we need to grab - variable declaration information and generate the associated wrapper - code later. Yikes! - - This really only works in a limited sense. Since we use the - code attached to the nested class to generate both C/C++ code, - it can't have any SWIG directives in it. It also needs to be parsable - by SWIG or this whole thing is going to puke. - ---------------------------------------------------------------------- */ - -/* A struct sname { } id; declaration */ - - | cpptype ID LBRACE { start_line = line_number; skip_brace(); - } nested_decl SEMI { - - if (cplus_mode == CPLUS_PUBLIC) { - cplus_register_type($2); - if ($5.id) { - if (strcmp($1,"class") == 0) { - Printf(stderr,"%s : Line %d. Warning. Nested classes not currently supported (ignored).\n", input_file, line_number); - /* Generate some code for a new class */ - } else { - Nested *n = (Nested *) malloc(sizeof(Nested)); - n->code = NewString(""); - Printv(n->code, "typedef ", $1, " ", - Char(CCode), " $classname_", $5.id, ";\n", 0); - n->name = Swig_copy_string($5.id); - n->line = start_line; - n->type = NewString(""); - add_pointers(n->type, $5.is_pointer); - if ($5.is_reference) SwigType_add_reference(n->type); - n->next = 0; - add_nested(n); - } - } - } - } -/* An unnamed structure definition */ - | cpptype LBRACE { start_line = line_number; skip_brace(); - } declaration SEMI { - if (cplus_mode == CPLUS_PUBLIC) { - if (strcmp($1,"class") == 0) { - Printf(stderr,"%s : Line %d. Warning. Nested classes not currently supported (ignored)\n", input_file, line_number); - /* Generate some code for a new class */ - } else { - /* Generate some code for a new class */ - - Nested *n = (Nested *) malloc(sizeof(Nested)); - n->code = NewString(""); - Printv(n->code, "typedef ", $1, " " , - Char(CCode), " $classname_", $4.id, ";\n",0); - n->name = Swig_copy_string($4.id); - n->line = start_line; - n->type = NewString(""); - add_pointers(n->type, $4.is_pointer); - if ($4.is_reference) SwigType_add_reference(n->type); - n->next = 0; - add_nested(n); - - } - } - } -/* An empty class declaration */ - | cpptype ID SEMI { - if (cplus_mode == CPLUS_PUBLIC) { - cplus_register_type($2); - } - } - -/* Other miscellaneous errors */ - | type stars LPAREN { - skip_decl(); - Printf(stderr,"%s : Line %d. Function pointers not currently supported (ignored).\n", input_file, line_number); - - } - | strict_type LPAREN STAR { - skip_decl(); - Printf(stderr,"%s : Line %d. Function pointers not currently supported (ignored).\n", input_file, line_number); - - } - | ID LPAREN STAR { - skip_decl(); - Printf(stderr,"%s : Line %d. Function pointers not currently supported (ignored).\n", input_file, line_number); - - } - | doc_enable { } - | SEMI { } - ; - -nested_decl : declaration { $$ = $1;} - | empty { $$.id = 0; } - ; - -type_extra : stars {} - | AND {} - | empty {} - ; - -cpp_tail : SEMI { } - | COMMA declaration def_args { - init_language(); - if (cplus_mode == CPLUS_PUBLIC) { - temp_typeptr = Copy(Active_type); - add_pointers(temp_typeptr, $2.is_pointer); - cplus_variable($2.id,(char *) 0,temp_typeptr); - Delete(temp_typeptr); - } - scanner_clear_start(); - } cpp_tail { } - | COMMA declaration array def_args { - init_language(); - if (cplus_mode == CPLUS_PUBLIC) { - temp_typeptr = Copy(Active_type); - add_pointers(temp_typeptr, $2.is_pointer); - cplus_variable($2.id,(char *) 0,temp_typeptr); - Delete(temp_typeptr); - } - scanner_clear_start(); - } cpp_tail { } - ; - -cpp_end : cpp_const SEMI { - Clear(CCode); - } - | cpp_const LBRACE { skip_brace(); } - ; - -cpp_vend : cpp_const SEMI { Clear(CCode); $$ = 0; } - | cpp_const EQUAL definetype SEMI { Clear(CCode); $$ = 1; } - | cpp_const LBRACE { skip_brace(); $$ = 0; } - ; - -cpp_enumlist : cpp_enumlist COMMA cpp_edecl {} - | cpp_edecl {} - ; - -cpp_edecl : ID { - if (cplus_mode == CPLUS_PUBLIC) { - temp_typeptr = NewSwigType(T_INT); - my_cplus_declare_const($1, (char *) 0, temp_typeptr, (char *) 0); - Delete(temp_typeptr); - scanner_clear_start(); - } -} - | ID EQUAL etype { - if (cplus_mode == CPLUS_PUBLIC) { - temp_typeptr = NewSwigType(T_INT); - my_cplus_declare_const($1,(char *) 0, temp_typeptr,(char *) 0); - // OLD : Bug with value my_cplus_declare_const($1,(char *) 0, temp_typeptr,$3.id); - Delete(temp_typeptr); - scanner_clear_start(); - } - } - | NAME LPAREN ID RPAREN ID { - if (cplus_mode == CPLUS_PUBLIC) { - temp_typeptr = NewSwigType(T_INT); - my_cplus_declare_const($5, $3, temp_typeptr, (char *) 0); - Delete(temp_typeptr); - scanner_clear_start(); - } - } - | NAME LPAREN ID RPAREN ID EQUAL etype { - if (cplus_mode == CPLUS_PUBLIC) { - temp_typeptr = NewSwigType(T_INT); - my_cplus_declare_const($5,$3, temp_typeptr, (char *) 0); - Delete(temp_typeptr); - scanner_clear_start(); - } - } - | empty { } - ; - -inherit : COLON base_list { - $$ = $2; - } - | empty { - $$.names = (char **) 0; - $$.count = 0; - } - ; - -base_list : base_specifier { - int i; - $$.names = (char **) malloc(NI_NAMES*sizeof(char *)); - $$.count = 0; - for (i = 0; i < NI_NAMES; i++){ - $$.names[i] = (char *) 0; - } - if ($1) { - $$.names[$$.count] = Swig_copy_string($1); - $$.count++; - } - } - - | base_list COMMA base_specifier { - $$ = $1; - if ($3) { - $$.names[$$.count] = Swig_copy_string($3); - $$.count++; - } - } - ; - -base_specifier : ID { - Printf(stderr,"%s : Line %d. No access specifier given for base class %s (ignored).\n", - input_file,line_number,$1); - $$ = (char *) 0; - } - | VIRTUAL ID { - Printf(stderr,"%s : Line %d. No access specifier given for base class %s (ignored).\n", - input_file,line_number,$2); - $$ = (char *) 0; - } - | VIRTUAL access_specifier ID { - if (strcmp($2,"public") == 0) { - $$ = $3; - } else { - Printf(stderr,"%s : Line %d. %s inheritance not supported (ignored).\n", - input_file,line_number,$2); - $$ = (char *) 0; - } - } - | access_specifier ID { - if (strcmp($1,"public") == 0) { - $$ = $2; - } else { - Printf(stderr,"%s : Line %d. %s inheritance not supported (ignored).\n", - input_file,line_number,$1); - $$ = (char *) 0; - } - } - | access_specifier VIRTUAL ID { - if (strcmp($1,"public") == 0) { - $$ = $3; - } else { - Printf(stderr,"%s : Line %d. %s inheritance not supported (ignored).\n", - input_file,line_number,$1); - $$ = (char *) 0; - } - } - ; - -access_specifier : PUBLIC { $$ = (char*)"public"; } - | PRIVATE { $$ = (char*)"private"; } - | PROTECTED { $$ = (char*)"protected"; } - ; - - -cpptype : CLASS { $$ = (char*)"class"; } - | STRUCT { $$ = (char*)"struct"; } - | UNION {$$ = (char*)"union"; } - ; - -cpp_const : CONST {} - | THROW LPAREN parms RPAREN { Delete($3);} - | empty {} - ; - -/* Constructor initializer */ - -ctor_end : cpp_const ctor_initializer SEMI { - Clear(CCode); - } - | cpp_const ctor_initializer LBRACE { skip_brace(); } - ; - -ctor_initializer : COLON mem_initializer_list {} - | empty {} - ; - -mem_initializer_list : mem_initializer { } - | mem_initializer_list COMMA mem_initializer { } - ; - -mem_initializer : ID LPAREN expr_list RPAREN { } - | ID LPAREN RPAREN { } - ; - -expr_list : expr { } - | expr_list COMMA expr { } - ; - - -/**************************************************************/ -/* Objective-C parsing */ -/**************************************************************/ - -objective_c : OC_INTERFACE ID objc_inherit { - ObjCClass = 1; - init_language(); - cplus_mode = CPLUS_PROTECTED; - sprintf(temp_name,"CPP_CLASS:%s\n",$2); - if (add_symbol(temp_name)) { - Printf(stderr,"%s : Line %d. @interface %s is multiple defined.\n", - input_file,line_number,$2); - FatalError(); - } - scanner_clear_start(); - cplus_open_class($2, (char *) 0, (char*)""); // Open up a new C++ class - } LBRACE objc_data RBRACE objc_methods OC_END { - if ($3) { - char *inames[1]; - inames[0] = $3; - cplus_inherit(1,inames); - } - cplus_class_close($2); - cplus_mode = CPLUS_PUBLIC; - ObjCClass = 0; - free($2); - free($3); - } -/* An obj-c category declaration */ - | OC_INTERFACE ID LPAREN ID RPAREN objc_protolist { - ObjCClass = 1; - init_language(); - cplus_mode = CPLUS_PROTECTED; - cplus_set_class($2); - scanner_clear_start(); - } objc_methods OC_END { - cplus_unset_class(); - } - | OC_IMPLEMENT { skip_to_end(); } - | OC_PROTOCOL { skip_to_end(); } - | OC_CLASS ID initlist SEMI { - char *iname = make_name($2); - init_language(); - lang->cpp_class_decl($2,iname,(char*)""); - for (int i = 0; i <$3.count; i++) { - if ($3.names[i]) { - iname = make_name($3.names[i]); - lang->cpp_class_decl($3.names[i],iname,(char*)""); - free($3.names[i]); - } - } - free($3.names); - } - ; - -objc_inherit : COLON ID objc_protolist { $$ = $2;} - | objc_protolist empty { $$ = 0; } - ; - - -objc_protolist : LESSTHAN { skip_template(); -/* CCode.strip(); // Strip whitespace - CCode.replace("<","< "); - CCode.replace(">"," >"); */ - $$ = Char(CCode); - } - | empty { - $$ = (char*)""; - } - ; - -objc_data : objc_vars objc_data { } - | OC_PUBLIC { - cplus_mode = CPLUS_PUBLIC; - } objc_data { } - | OC_PRIVATE { - cplus_mode = CPLUS_PRIVATE; - } objc_data { } - | OC_PROTECTED { - cplus_mode = CPLUS_PROTECTED; - } objc_data { } - | error { - if (!Error) { - skip_decl(); - { - static int last_error_line = -1; - if (last_error_line != line_number) { - Printf(stderr,"%s : Line %d. Syntax error in input.\n", input_file, line_number); - FatalError(); - last_error_line = line_number; - } - Error = 1; - } - } - } objc_data { } - | empty { } - ; - -objc_vars : objc_var objc_vartail SEMI { - - } - ; - -/* An objective-C member variable */ - -objc_var : type declaration { - if (cplus_mode == CPLUS_PUBLIC) { - int oldstatus = Status; - char *iname; - if (Active_type) Delete(Active_type); - Active_type = Copy($1); - add_pointers($1,$2.is_pointer); - if ($2.is_reference) SwigType_add_reference($1); - iname = make_name($2.id); - if (iname == $2.id) iname = 0; - cplus_variable($2.id,iname,$1); - Status = oldstatus; - } - scanner_clear_start(); - Delete($1); - } - | type declaration array { - if (cplus_mode == CPLUS_PUBLIC) { - int oldstatus = Status; - char *iname; - if (Active_type) Delete(Active_type); - Active_type = Copy($1); - add_pointers($1,$2.is_pointer); - if ($2.is_reference) SwigType_add_reference($1); - SwigType_push($1,ArrayString); - iname = make_name($2.id); - if (iname == $2.id) iname = 0; - cplus_variable($2.id,iname,$1); - Status = oldstatus; - } - scanner_clear_start(); - Delete($1); - } - | NAME LPAREN ID RPAREN { - strcpy(yy_rename,$3); - Rename_true = 1; - } objc_var { }; - -objc_vartail : COMMA declaration objc_vartail { - if (cplus_mode == CPLUS_PUBLIC) { - int oldstatus = Status; - char *iname; - SwigType *t = Copy(Active_type); - add_pointers(t,$2.is_pointer); - if ($2.is_reference) SwigType_add_reference(t); - iname = make_name($2.id); - if (iname == $2.id) iname = 0; - cplus_variable($2.id,iname,t); - Status = oldstatus; - Delete(t); - } - scanner_clear_start(); - } - | COMMA declaration array objc_vartail { - char *iname; - if (cplus_mode == CPLUS_PUBLIC) { - int oldstatus = Status; - SwigType *t = Copy(Active_type); - add_pointers(t,$2.is_pointer); - if ($2.is_reference) SwigType_add_reference(t); - SwigType_push(t,ArrayString); - iname = make_name($2.id); - if (iname == $2.id) iname = 0; - cplus_variable($2.id,iname,t); - Status = oldstatus; - Delete(t); - } - scanner_clear_start(); - } - | empty { } - ; - -objc_methods : objc_method objc_methods { }; - | ADDMETHODS LBRACE { - AddMethods = 1; - } objc_methods RBRACE { - AddMethods = 0; - } - | NAME LPAREN ID RPAREN { - strcpy(yy_rename,$3); - Rename_true = 1; - } objc_methods { } - | error { - skip_decl(); - if (!Error) { - { - static int last_error_line = -1; - if (last_error_line != line_number) { - Printf(stderr,"%s : Line %d. Syntax error in input.\n", input_file, line_number); - FatalError(); - last_error_line = line_number; - } - Error = 1; - } - } - } objc_methods { } - | empty { } - ; - -objc_method : MINUS objc_ret_type ID objc_args objc_end { - char *iname; - // An objective-C instance function - // This is like a C++ member function - - if (strcmp($3,objc_destruct) == 0) { - // This is an objective C destructor - cplus_destructor($3,(char *) 0); - } else { - iname = make_name($3); - if (iname == $3) iname = 0; - cplus_member_func($3,iname,$2,$4,0); - scanner_clear_start(); - Delete($2); - free($3); - Delete($4); - } - } - | PLUS objc_ret_type ID objc_args objc_end { - char *iname; - // An objective-C class function - // This is like a c++ static member function - if (strcmp($3,objc_construct) == 0) { - // This is an objective C constructor - cplus_constructor($3,0,$4); - } else { - iname = make_name($3); - if (iname == $3) iname = 0; - cplus_static_func($3,iname,$2,$4); - } - scanner_clear_start(); - Delete($2); - free($3); - Delete($4); - } - ; - -objc_end : SEMI { Clear(CCode); } - | LBRACE { skip_brace(); } - ; - -objc_ret_type : LPAREN type RPAREN { - $$ = $2; - } - | LPAREN type stars RPAREN { - $$ = $2; - add_pointers($$,$3); - } - | empty { /* Empty type means "id" type */ - $$ = NewString("id"); - } - ; - -objc_arg_type : LPAREN parm RPAREN { - $$ = Copy(Gettype($2)); - Delete($2); - } - | empty { - $$ = NewString("id"); - } - ; - -objc_args : objc_args objc_separator objc_arg_type ID { - Parm *p= NewParm($3,$4); - /* p->objc_separator = $2; */ - $$ = $1; - if (!$$) { - $$ = p; - } else { - Parm *np, *pp; - np = $$; - while(np) { - pp = np; - np = Getnext(np); - } - Setnext(pp,p); - } - } - | empty { - $$ = 0; - } - ; - -objc_separator : COLON { $$ = Swig_copy_string((char*)":"); } - | ID COLON { $$ = (char *) malloc(strlen($1)+2); - strcpy($$,$1); - strcat($$,":"); - free($1); - } - ; - -/* Miscellaneous stuff */ - -/* Documentation style list */ - -stylelist : ID stylearg styletail { - $$ = $3; - $$.names[$$.count] = Swig_copy_string($1); - $$.values[$$.count] = Swig_copy_string($2); - $$.count++; - } - ; - - -styletail : styletail COMMA ID stylearg { - $$ = $1; - $$.names[$$.count] = Swig_copy_string($3); - $$.values[$$.count] = Swig_copy_string($4); - $$.count++; - } - | empty { - $$.names = (char **) malloc(NI_NAMES*sizeof(char *)); - $$.values = (char **) malloc(NI_NAMES*sizeof(char *)); - $$.count = 0; - } - ; - -stylearg : EQUAL NUM_INT { - $$ = $2; - } - | EQUAL STRING { - $$ = $2; - } - | empty { - $$ = 0; - } - ; - - -/* -------------------------------------------------------------- - * Type-map parameters - * -------------------------------------------------------------- */ - -tm_method : ID { - $$ = $1; - } - | CONST { - $$ = Swig_copy_string((char*)"const"); - } - ; - -tm_list : typemap_parm tm_tail { - $$ = $1; - $$->next = $2; - } - ; - -tm_tail : COMMA typemap_parm tm_tail { - $$ = $2; - $$->next = $3; - } - | empty { $$ = 0;} - ; - -typemap_parm : type typemap_name { - if (InArray) { - SwigType_push($1,ArrayString); - } - $$ = NewTMParm(); - $$->p = NewParm($1,$2); - $$->args = tm_parm; - Delete($1); - free($2); - } - - | type stars typemap_name { - $$ = NewTMParm(); - $$->p = NewParm($1,$3); - SwigType *pt = Gettype($$->p); - add_pointers(pt,$2); - if (InArray) { - SwigType_push(pt,ArrayString); - } - $$->args = tm_parm; - Delete($1); - free($3); - } - - | type AND typemap_name { - $$ = NewTMParm(); - $$->p = NewParm($1,$3); - SwigType *pt = Gettype($$->p); - SwigType_add_reference(pt); - if (!CPlusPlus) { - Printf(stderr,"%s : Line %d. Warning. Use of C++ Reference detected. Use the -c++ option.\n", input_file, line_number); - } - $$->args = tm_parm; - Delete($1); - free($3); - } - | type LPAREN stars typemap_name RPAREN LPAREN parms RPAREN { - Printf(stderr,"%s : Line %d. Error. Function pointer not allowed (remap with typedef).\n", input_file, line_number); - FatalError(); - $$ = NewTMParm(); - $$->p = NewParm($1,$4); - SwigType *pt = Gettype($$->p); - DOHList *l = typelist($7); - SwigType_add_function(pt,l); - add_pointers(pt,$3); - $$->args = tm_parm; - Delete($1); - free($4); - Delete($7); - } - ; - -typemap_name : ID typemap_args { - $$ = $1; - InArray = 0; - } - | ID array { - ArrayBackup = Copy(ArrayString); - } typemap_args { - $$ = $1; - InArray = $2; - Clear(ArrayString); - Append(ArrayString,ArrayBackup); - Delete(ArrayBackup); - } - | array { - ArrayBackup = Copy(ArrayString); - } typemap_args { - $$ = (char *) malloc(1); - $$[0] = 0; - InArray = $1; - Clear(ArrayString); - Append(ArrayString,ArrayBackup); - Delete(ArrayBackup); - } - | typemap_args { $$ = (char *) malloc(1); - $$[0] = 0; - InArray = 0; - } - ; - -typemap_args : LPAREN parms RPAREN { - tm_parm = $2; - } - | empty { - tm_parm = 0; - } - ; - - -/* Parsing of expressions, but only for throw away code */ - -/* Might need someday -dummyexpr : NUM_INT { } - | NUM_FLOAT { } - | NUM_UNSIGNED { } - | NUM_LONG { } - | NUM_ULONG { } - | SIZEOF LPAREN type RPAREN { } - | ID { } - | dummyexpr PLUS dummyexpr { } - | dummyexpr MINUS dummyexpr { } - | dummyexpr STAR dummyexpr { } - | dummyexpr SLASH dummyexpr { } - | dummyexpr AND dummyexpr { } - | dummyexpr OR dummyexpr { } - | dummyexpr XOR dummyexpr { } - | dummyexpr LSHIFT dummyexpr { } - | dummyexpr RSHIFT dummyexpr { } - | MINUS dummyexpr %prec UMINUS { } - | NOT dummyexpr { } - | LPAREN dummyexpr RPAREN { } - ; - - */ - - -empty : ; - -%% - -void error_recover() { - int c; - c = yylex(); - while ((c > 0) && (c != SEMI)) - c = yylex(); -} - -/* Called by the parser (yyparse) when an error is found.*/ -void yyerror (char *) { - // Printf(stderr,"%s : Line %d. Syntax error.\n", input_file, line_number); - // error_recover(); -} - - - - - diff --git a/Source/SWIG1.1/scanner.cxx b/Source/SWIG1.1/scanner.cxx deleted file mode 100644 index 2322ec0e5..000000000 --- a/Source/SWIG1.1/scanner.cxx +++ /dev/null @@ -1,1119 +0,0 @@ -/* ----------------------------------------------------------------------------- - * scanner.cxx - * - * SWIG1.1 tokenizer. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 1998-2000. The University of Chicago - * Copyright (C) 1995-1998. The University of Utah and The Regents of the - * University of California. - * - * See the file LICENSE for information on usage and redistribution. - * ----------------------------------------------------------------------------- */ - -static char cvsroot[] = "$Header$"; - -#include "internal.h" -#include "parser.h" -#include -#include - -extern "C" { - #include "swig.h" -} - -#define YYBSIZE 8192 - -struct InFile { - DOHFile *f; - int line_number; - char *in_file; - int extern_mode; - int force_extern; - int inline_mode; - struct InFile *prev; -}; - -InFile *in_head; - -DOHFile *LEX_in = 0; -static DOHString *header = 0; -static DOHString *comment = 0; - DOHString *CCode = 0; // String containing C code -static char *yybuffer = 0; - -static char yytext[YYBSIZE]; -static int yylen = 0; -int line_number = 1; -char *input_file; -int start_line = 0; -static int comment_start; -static int scan_init = 0; -static int num_brace = 0; -static int last_brace = 0; -extern int Error; - - -/************************************************************** - * scanner_init() - * - * Initialize buffers - **************************************************************/ - -void scanner_init() { - yybuffer = (char *) malloc(YYBSIZE); - scan_init = 1; - header = NewString(""); - comment = NewString(""); - CCode = NewString(""); -} - -/************************************************************** - * scanner_file(FILE *f) - * - * Start reading from new file - **************************************************************/ -void scanner_file(DOHFile *f) { - InFile *in; - - in = (InFile *) malloc(sizeof(InFile)); - in->f = f; - in->in_file = input_file; - in->line_number = 1; - in->extern_mode = WrapExtern; - in->force_extern = ForceExtern; - in->inline_mode = 0; - if (!in_head) in->prev = 0; - else in->prev = in_head; - in_head = in; - LEX_in = f; - line_number = 1; -} - -/************************************************************** - * scanner_close() - * - * Close current input file and go to next - **************************************************************/ - -void scanner_close() { - InFile *p; - if (!in_head) return; - if (in_head->inline_mode) { - Delete(LEX_in); - } - p = in_head->prev; - if (p != 0) { - LEX_in = p->f; - line_number = p->line_number; - input_file = p->in_file; - WrapExtern = p->extern_mode; - ForceExtern = p->force_extern; - Inline = p->inline_mode; - } else { - LEX_in = 0; - } - free(in_head); - in_head = p; -} - -/************************************************************** - * char nextchar() - * - * gets next character from input. - * If we're in inlining mode, we actually retrieve a character - * from inline_yybuffer instead. - **************************************************************/ - -char nextchar() { - int c = 0; - - while (LEX_in) { - c = Getc(LEX_in); - if (c == EOF) { - scanner_close(); - } else { - break; - } - } - if (!LEX_in) return 0; - if (yylen >= YYBSIZE) { - Printf(stderr,"** FATAL ERROR. Buffer overflow in scanner.cxx.\nReport this to swig-dev@cs.uchicago.edu.\n"); - SWIG_exit (EXIT_FAILURE); - } - yytext[yylen] = c; - yylen++; - if (c == '\n') { - line_number++; - } - return(c); -} - -void retract(int n) { - int i; - for (i = 0; i < n; i++) { - yylen--; - if (yylen >= 0) { - Ungetc(yytext[yylen],LEX_in); - if (yytext[yylen] == '\n') { - line_number--; - } - } - } - if (yylen < 0) yylen = 0; -} - -/************************************************************** - * start_inline(char *text, int line) - * - * This grabs a chunk of text and tries to inline it into - * the current file. (This is kind of wild, but cool when - * it works). - * - * If we're already in inlining mode, we will save the code - * as a new fragment. - **************************************************************/ - -void start_inline(char *text, int line) { - InFile *in; - - in_head->line_number = line_number; - in = (InFile *) malloc(sizeof(InFile)); - in->f = NewString(text); - Seek(in->f,0,SEEK_SET); - in->in_file = Swig_copy_string(input_file); - in->line_number = line; - in->extern_mode = WrapExtern; - in->force_extern = ForceExtern; - in->inline_mode = 1; - in->prev = in_head; - in_head = in; - LEX_in = in->f; - line_number = line; - Inline = 1; -} - -/************************************************************** - * yycomment(char *, int line) - * - * Inserts a comment into a documentation entry. - **************************************************************/ - -void yycomment(char *, int, int) { -} - -/************************************************************** - * void skip_brace(void) - * - * Found a {. - * Skip all characters until we find a matching closed }. - * - * This function is used to skip over inlined C code and other - * garbage found in interface files. - ***************************************************************/ - -void skip_brace(void) { - - char c; - Clear(CCode); - Putc('{',CCode); - while (num_brace > last_brace) { - if ((c = nextchar()) == 0) { - Printf(stderr,"%s : Line %d. Missing '}'. Reached end of input.\n", - input_file, line_number); - FatalError(); - return; - } - Putc(c,CCode); - if (c == '{') num_brace++; - if (c == '}') num_brace--; - yylen = 0; - } -} - - -/************************************************************** - * void skip_template(void) - * - * Found a <. - * Skip all characters until we find a matching closed >. - * - * This function is used to skip over C++ templated types - * and objective-C protocols. - ***************************************************************/ - -void skip_template(void) { - - char c; - Clear(CCode); - Putc('<',CCode); - int num_lt = 1; - while (num_lt > 0) { - if ((c = nextchar()) == 0) { - Printf(stderr,"%s : Line %d. Missing '>'. Reached end of input.\n", - input_file, line_number); - FatalError(); - return; - } - Putc(c,CCode); - if (c == '<') num_lt++; - if (c == '>') num_lt--; - yylen = 0; - } -} - -/************************************************************** - * void skip_to_end(void) - * - * Skips to the @end directive in a Objective-C definition - **************************************************************/ - -void skip_to_end(void) { - char c; - int state = 0; - yylen = 0; - while ((c = nextchar())){ - switch(state) { - case 0: - if (c == '@') state = 1; - else yylen = 0; - break; - case 1: - if (isspace(c)) { - if (strncmp(yytext,"@end",4) == 0) return; - else { - yylen = 0; - state = 0; - } - } else { - state = 1; - } - break; - } - } - Printf(stderr,"%s : EOF. Missing @end. Reached end of input.\n", - input_file); - FatalError(); - return; -} - -/************************************************************** - * void skip_decl(void) - * - * This tries to skip over an entire declaration. For example - * - * friend ostream& operator<<(ostream&, const char *s); - * - * or - * friend ostream& operator<<(ostream&, const char *s) { }; - * - **************************************************************/ - -void skip_decl(void) { - char c; - int done = 0; - while (!done) { - if ((c = nextchar()) == 0) { - Printf(stderr,"%s : Line %d. Missing semicolon. Reached end of input.\n", - input_file, line_number); - FatalError(); - return; - } - if (c == '{') { - last_brace = num_brace; - num_brace++; - break; - } - yylen = 0; - if (c == ';') done = 1; - } - if (!done) { - while (num_brace > last_brace) { - if ((c = nextchar()) == 0) { - Printf(stderr,"%s : Line %d. Missing '}'. Reached end of input.\n", - input_file, line_number); - FatalError(); - return; - } - if (c == '{') num_brace++; - if (c == '}') num_brace--; - yylen = 0; - } - } -} - -/* This function is called when a backslash is found in a string */ -static void get_escape() { - int result = 0; - int state = 0; - char c; - - while(1) { - c = nextchar(); - if (c == 0) break; - switch(state) { - case 0: - if (c == 'n') { - yytext[yylen-1] = '\n'; - return; - } - if (c == 'r') { - yytext[yylen-1] = '\r'; - return; - } - if (c == 't') { - yytext[yylen-1] = '\t'; - return; - } - if (c == 'a') { - yytext[yylen-1] = '\a'; - return; - } - if (c == 'b') { - yytext[yylen-1] = '\b'; - return; - } - if (c == 'f') { - yytext[yylen-1] = '\f'; - return; - } - if (c == '\\') { - yytext[yylen-1] = '\\'; - return; - } - if (c == 'v') { - yytext[yylen-1] = '\v'; - return; - } - if (c == 'e') { - yytext[yylen-1] = '\033'; - return; - } - if (c == '\'') { - yytext[yylen-1] = '\''; - return; - } - if (c == '\"') { - yytext[yylen-1] = '\"'; - return; - } - if (c == '\n') { - yylen--; - return; - } - if (c == '0') { - state = 10; - } - else if (c == 'x') { - state = 20; - } else { - yytext[yylen-1] = '\\'; - yytext[yylen] = c; - yylen++; - return; - } - break; - case 10: - if (!isdigit(c)) { - retract(1); - yytext[yylen-1] = (char) result; - return; - } - result = (result << 3) + (c - '0'); - yylen--; - break; - case 20: - if (!isxdigit(c)) { - retract(1); - yytext[yylen-1] = (char) result; - return; - } - if (isdigit(c)) - result = (result << 4) + (c - '0'); - else - result = (result << 4) + (10 + tolower(c) - 'a'); - yylen--; - break; - } - } - return; -} - -/************************************************************** - * int yylook() - * - * Lexical scanner. - * See Aho,Sethi, and Ullman, pg. 106 - **************************************************************/ - -int yylook(void) { - - int state; - char c = 0; - - state = 0; - yylen = 0; - while(1) { - -/* printf("State = %d\n", state); */ - switch(state) { - - case 0 : - if((c = nextchar()) == 0) return (0); - - /* Process delimeters */ - - if (c == '\n') { - state = 0; - yylen = 0; - } else if (isspace(c)) { - state = 0; - yylen = 0; - } - - else if ((isalpha(c)) || (c == '_') || (c == '$')) state = 7; - - /* Look for single character symbols */ - - else if (c == '(') return (LPAREN); - else if (c == ')') return (RPAREN); - else if (c == ';') return (SEMI); - else if (c == ',') return (COMMA); - else if (c == '*') return (STAR); - else if (c == '}') { - num_brace--; - if (num_brace < 0) { - Printf(stderr,"%s : Line %d. Error. Extraneous '}' (Ignored)\n", - input_file, line_number); - state = 0; - num_brace = 0; - } else { - return (RBRACE); - } - } - else if (c == '{') { - last_brace = num_brace; - num_brace++; - return (LBRACE); - } - else if (c == '=') return (EQUAL); - else if (c == '+') return (PLUS); - else if (c == '-') return (MINUS); - else if (c == '&') return (AND); - else if (c == '|') return (OR); - else if (c == '^') return (XOR); - else if (c == '<') state = 60; - else if (c == '>') state = 61; - else if (c == '~') return (NOT); - else if (c == '!') return (LNOT); - else if (c == '\\') { - state = 99; - } - else if (c == '[') return (LBRACKET); - else if (c == ']') return (RBRACKET); - - /* Look for multi-character sequences */ - - else if (c == '/') state = 1; // Comment (maybe) - else if (c == '\"') state = 2; // Possibly a string - else if (c == '#') state = 3; // CPP - else if (c == '%') state = 4; // Directive - else if (c == '@') state = 4; // Objective C keyword - else if (c == ':') state = 5; // maybe double colon - else if (c == '0') state = 83; // An octal or hex value - else if (c == '\'') state = 9; // A character constant - else if (c == '.') state = 100; // Maybe a number, maybe just a period - else if (c == '`') { - state = 200; // Back-tick type - yylen = 0; - } - else if (isdigit(c)) state = 8; // A numerical value - - else state = 99; - break; - case 1: /* Comment block */ - if ((c = nextchar()) == 0) return(0); - if (c == '/') { - comment_start = line_number; - Clear(comment); - Printf(comment," "); - state = 10; // C++ style comment - } else if (c == '*') { - comment_start = line_number; - Clear(comment); - Printf(comment," "); - state = 11; // C style comment - } else { - retract(1); - return(SLASH); - } - break; - case 10: /* C++ style comment */ - if ((c = nextchar()) == 0) { - Printf(stderr,"%s : EOF. Unterminated comment detected.\n",input_file); - FatalError(); - return 0; - } - if (c == '\n') { - Putc(c,comment); - // Add the comment to documentation - // yycomment(Char(comment),comment_start, column_start); - yylen = 0; - state = 0; - } else { - state = 10; - Putc(c,comment); - yylen = 0; - } - break; - case 11: /* C style comment block */ - if ((c = nextchar()) == 0) { - Printf(stderr,"%s : EOF. Unterminated comment detected.\n", input_file); - FatalError(); - return 0; - } - if (c == '*') { - state = 12; - } else { - Putc(c,comment); - yylen = 0; - state = 11; - } - break; - case 12: /* Still in C style comment */ - if ((c = nextchar()) == 0) { - Printf(stderr,"%s : EOF. Unterminated comment detected.\n", input_file); - FatalError(); - return 0; - } - if (c == '*') { - Putc(c,comment); - state = 12; - } else if (c == '/') { - Printf(comment," \n"); - // yycomment(Char(comment),comment_start,column_start); - yylen = 0; - state = 0; - } else { - Putc('*',comment); - Putc(c,comment); - yylen = 0; - state = 11; - } - break; - - case 2: /* Processing a string */ - if ((c = nextchar()) == 0) { - Printf(stderr,"%s : EOF. Unterminated string detected.\n", input_file); - FatalError(); - return 0; - } - if (c == '\"') { - yytext[yylen-1] = 0; - yylval.id = Swig_copy_string(yytext+1); - return(STRING); - } else if (c == '\\') { - yylen--; - get_escape(); - break; - } else state = 2; - break; - - case 3: /* a CPP directive */ - if (( c= nextchar()) == 0) return 0; - if (c == '\n') { - retract(1); - yytext[yylen] = 0; - yylval.id = yytext; - return(POUND); - } - break; - - case 4: /* A wrapper generator directive (maybe) */ - if (( c= nextchar()) == 0) return 0; - if (c == '{') { - state = 40; /* Include block */ - Clear(header); - start_line = line_number; - } - else if ((isalpha(c)) || (c == '_')) state = 7; - else { - retract(1); - state = 99; - } - break; - - case 40: /* Process an include block */ - if ((c = nextchar()) == 0) { - Printf(stderr,"%s : EOF. Unterminated include block detected.\n", input_file); - FatalError(); - return 0; - } - yylen = 0; - if (c == '%') state = 41; - else { - Putc(c,header); - yylen = 0; - state = 40; - } - break; - case 41: /* Still processing include block */ - if ((c = nextchar()) == 0) { - Printf(stderr,"%s : EOF. Unterminated include block detected.\n", input_file); - FatalError(); - return 0; - } - if (c == '}') { - yylval.id = Char(header); - return(HBLOCK); - } else { - Putc('%',header); - Putc(c,header); - yylen = 0; - state = 40; - } - break; - - case 5: /* Maybe a double colon */ - - if (( c= nextchar()) == 0) return 0; - if ( c == ':') return DCOLON; - else { - retract(1); - return COLON; - } - - - case 60: /* shift operators */ - if ((c = nextchar()) == 0) return (0); - if (c == '<') return LSHIFT; - else { - retract(1); - return LESSTHAN; - } - break; - case 61: - if ((c = nextchar()) == 0) return (0); - if (c == '>') return RSHIFT; - else { - retract(1); - return GREATERTHAN; - } - break; - case 7: /* Identifier */ - if ((c = nextchar()) == 0) return(0); - if (isalnum(c) || (c == '_') || (c == '.') || (c == '$')) { - state = 7; - } else { - retract(1); - return(ID); - } - break; - case 8: /* A numerical digit */ - if ((c = nextchar()) == 0) return(0); - if (c == '.') {state = 81;} - else if ((c == 'e') || (c == 'E')) {state = 86;} - else if ((c == 'f') || (c == 'F')) { - yytext[yylen] = 0; - yylval.id = Swig_copy_string(yytext); - return(NUM_FLOAT); - } - else if (isdigit(c)) { state = 8;} - else if ((c == 'l') || (c == 'L')) { - state = 87; - } else if ((c == 'u') || (c == 'U')) { - state = 88; - } else { - retract(1); - yytext[yylen] = 0; - yylval.id = Swig_copy_string(yytext); - return(NUM_INT); - } - break; - case 81: /* A floating pointer number of some sort */ - if ((c = nextchar()) == 0) return(0); - if (isdigit(c)) state = 81; - else if ((c == 'e') || (c == 'E')) state = 82; - else if ((c == 'f') || (c == 'F') || (c == 'l') || (c == 'L')) { - yytext[yylen] = 0; - yylval.id = Swig_copy_string(yytext); - return(NUM_FLOAT); - } else { - retract(1); - yytext[yylen] = 0; - yylval.id = Swig_copy_string(yytext); - return(NUM_FLOAT); - } - break; - case 82: - if ((c = nextchar()) == 0) return(0); - if ((isdigit(c)) || (c == '-') || (c == '+')) state = 86; - else { - retract(2); - yytext[yylen-1] = 0; - yylval.id = Swig_copy_string(yytext); - return(NUM_INT); - } - break; - case 83: - /* Might be a hexidecimal or octal number */ - if ((c = nextchar()) == 0) return(0); - if (isdigit(c)) state = 84; - else if ((c == 'x') || (c == 'X')) state = 85; - else if (c == '.') state = 81; - else if ((c == 'l') || (c == 'L')) { - state = 87; - } else if ((c == 'u') || (c == 'U')) { - state = 88; - } else { - retract(1); - yytext[yylen] = 0; - yylval.id = Swig_copy_string(yytext); - return(NUM_INT); - } - break; - case 84: - /* This is an octal number */ - if ((c = nextchar()) == 0) return (0); - if (isdigit(c)) state = 84; - else if ((c == 'l') || (c == 'L')) { - state = 87; - } else if ((c == 'u') || (c == 'U')) { - state = 88; - } else { - retract(1); - yytext[yylen] = 0; - yylval.id = Swig_copy_string(yytext); - return(NUM_INT); - } - break; - case 85: - /* This is an hex number */ - if ((c = nextchar()) == 0) return (0); - if ((isdigit(c)) || (c=='a') || (c=='b') || (c=='c') || - (c=='d') || (c=='e') || (c=='f') || (c=='A') || - (c=='B') || (c=='C') || (c=='D') || (c=='E') || - (c=='F')) - state = 85; - else if ((c == 'l') || (c == 'L')) { - state = 87; - } else if ((c == 'u') || (c == 'U')) { - state = 88; - } else { - retract(1); - yytext[yylen] = 0; - yylval.id = Swig_copy_string(yytext); - return(NUM_INT); - } - break; - - case 86: - /* Rest of floating point number */ - - if ((c = nextchar()) == 0) return (0); - if (isdigit(c)) state = 86; - else if ((c == 'f') || (c == 'F') || (c == 'l') || (c == 'L')) { - yytext[yylen] = 0; - yylval.id = Swig_copy_string(yytext); - return(NUM_FLOAT); - } else { - retract(1); - yytext[yylen] = 0; - yylval.id = Swig_copy_string(yytext); - return(NUM_FLOAT); - } - /* Parse a character constant. ie. 'a' */ - break; - - case 87 : - /* A long integer of some sort */ - if ((c = nextchar()) == 0) return (0); - if ((c == 'u') || (c == 'U')) { - yytext[yylen] = 0; - yylval.id = Swig_copy_string(yytext); - return(NUM_ULONG); - } else { - retract(1); - yytext[yylen] = 0; - yylval.id = Swig_copy_string(yytext); - return(NUM_LONG); - } - - case 88: - /* An unsigned integer of some sort */ - if ((c = nextchar()) == 0) return (0); - if ((c == 'l') || (c == 'L')) { - yytext[yylen] = 0; - yylval.id = Swig_copy_string(yytext); - return(NUM_ULONG); - } else { - retract(1); - yytext[yylen] = 0; - yylval.id = Swig_copy_string(yytext); - return(NUM_UNSIGNED); - } - - case 9: - if ((c = nextchar()) == 0) return (0); - if (c == '\\') { - yylen--; - get_escape(); - } else if (c == '\'') { - yytext[yylen-1] = 0; - yylval.id = Swig_copy_string(yytext+1); - return(CHARCONST); - } - break; - - case 100: - if ((c = nextchar()) == 0) return (0); - if (isdigit(c)) state = 81; - else { - retract(1); - return(PERIOD); - } - break; - case 200: - if ((c = nextchar()) == 0) return (0); - if (c == '`') { - yytext[yylen-1] = 0; - yylval.type = NewString(yytext); - return(TYPE_RAW); - } - break; - - default: - if (!Error) { - Printf(stderr,"%s : Line %d ::Illegal character '%c'=%d.\n",input_file, line_number,c,c); - FatalError(); - } - state = 0; - Error = 1; - return(ILLEGAL); - } - } -} - -static int check_typedef = 0; - -void scanner_check_typedef() { - check_typedef = 1; -} - -void scanner_ignore_typedef() { - check_typedef = 0; -} - - -/************************************************************** - * int yylex() - * - * Gets the lexene and returns tokens. - *************************************************************/ - -extern "C" int yylex(void) { - - int l; - - if (!scan_init) { - scanner_init(); - // if (LEX_in == NULL) LEX_in = stdin; - // scanner_file(LEX_in); - } - - l = yylook(); - - /* We got some sort of non-white space object. We set the start_line - variable unless it has already been set */ - - if (!start_line) { - start_line = line_number; - } - - /* Copy the lexene */ - - yytext[yylen] = 0; - - switch(l) { - - case ID: - - if (yytext[0] != '%') { - /* Look for keywords now */ - - if (strcmp(yytext,"int") == 0) { - yylval.type = NewSwigType(T_INT); - return(TYPE_INT); - } - if (strcmp(yytext,"double") == 0) { - yylval.type = NewSwigType(T_DOUBLE); - return(TYPE_DOUBLE); - } - if (strcmp(yytext,"void") == 0) { - yylval.type = NewSwigType(T_VOID); - return(TYPE_VOID); - } - if (strcmp(yytext,"char") == 0) { - yylval.type = NewSwigType(T_CHAR); - return(TYPE_CHAR); - } - if (strcmp(yytext,"short") == 0) { - yylval.type = NewSwigType(T_SHORT); - return(TYPE_SHORT); - } - if (strcmp(yytext,"long") == 0) { - yylval.type = NewSwigType(T_LONG); - return(TYPE_LONG); - } - if (strcmp(yytext,"float") == 0) { - yylval.type = NewSwigType(T_FLOAT); - return(TYPE_FLOAT); - } - if (strcmp(yytext,"signed") == 0) { - yylval.type = NewSwigType(T_INT); - return(TYPE_SIGNED); - } - if (strcmp(yytext,"unsigned") == 0) { - yylval.type = NewSwigType(T_UINT); - return(TYPE_UNSIGNED); - } - if (strcmp(yytext,"bool") == 0) { - yylval.type = NewSwigType(T_BOOL); - return(TYPE_BOOL); - } - // C++ keywords - - if (CPlusPlus) { - if (strcmp(yytext,"class") == 0) return(CLASS); - if (strcmp(yytext,"private") == 0) return(PRIVATE); - if (strcmp(yytext,"public") == 0) return(PUBLIC); - if (strcmp(yytext,"protected") == 0) return(PROTECTED); - if (strcmp(yytext,"friend") == 0) return(FRIEND); - if (strcmp(yytext,"virtual") == 0) return(VIRTUAL); - if (strcmp(yytext,"operator") == 0) return(OPERATOR); - if (strcmp(yytext,"throw") == 0) return(THROW); - if (strcmp(yytext,"inline") == 0) return(yylex()); - if (strcmp(yytext,"mutable") == 0) return(yylex()); - if (strcmp(yytext,"template") == 0) return(TEMPLATE); - } - - // Objective-C keywords - if ((ObjC) && (yytext[0] == '@')) { - if (strcmp(yytext,"@interface") == 0) return (OC_INTERFACE); - if (strcmp(yytext,"@end") == 0) return (OC_END); - if (strcmp(yytext,"@public") == 0) return (OC_PUBLIC); - if (strcmp(yytext,"@private") == 0) return (OC_PRIVATE); - if (strcmp(yytext,"@protected") == 0) return (OC_PROTECTED); - if (strcmp(yytext,"@class") == 0) return(OC_CLASS); - if (strcmp(yytext,"@implementation") == 0) return(OC_IMPLEMENT); - if (strcmp(yytext,"@protocol") == 0) return(OC_PROTOCOL); - } - - // Misc keywords - - if (strcmp(yytext,"extern") == 0) return(EXTERN); - if (strcmp(yytext,"const") == 0) return(CONST); - if (strcmp(yytext,"static") == 0) return(STATIC); - if (strcmp(yytext,"struct") == 0) return(STRUCT); - if (strcmp(yytext,"union") == 0) return(UNION); - if (strcmp(yytext,"enum") == 0) return(ENUM); - if (strcmp(yytext,"sizeof") == 0) return(SIZEOF); - - if (strcmp(yytext,"typedef") == 0) { - yylval.ivalue = 0; - return(TYPEDEF); - } - - // Ignored keywords - - if (strcmp(yytext,"volatile") == 0) return(yylex()); - - // SWIG directives - } else { - if (strcmp(yytext,"%module") == 0) return(MODULE); - if (strcmp(yytext,"%init") == 0) return(INIT); - if (strcmp(yytext,"%wrapper") == 0) return(WRAPPER); - if (strcmp(yytext,"%runtime") == 0) return(RUNTIME); - if (strcmp(yytext,"%header") == 0) return(HEADER); - if (strcmp(yytext,"%insert") == 0) return(INSERT); - if (strcmp(yytext,"%readonly") == 0) return(READONLY); - if (strcmp(yytext,"%readwrite") == 0) return(READWRITE); - if (strcmp(yytext,"%name") == 0) return(NAME); - if (strcmp(yytext,"%rename") == 0) return(RENAME); - if (strcmp(yytext,"%file") == 0) return(INCLUDE); - if (strcmp(yytext,"%val") == 0) { - Printf(stderr,"%s:%d %%val directive deprecated (ignored).\n", input_file, line_number); - return (yylex()); - } - if (strcmp(yytext,"%out") == 0) { - Printf(stderr,"%s:%d %%out directive deprecated (ignored).\n", input_file, line_number); - return(yylex()); - } - if (strcmp(yytext,"%constant") == 0) return(CONSTANT); - if (strcmp(yytext,"%macro") == 0) return(SWIGMACRO); - - if (strcmp(yytext,"%section") == 0) { - yylval.ivalue = line_number; - return(SECTION); - } - if (strcmp(yytext,"%subsection") == 0) { - yylval.ivalue = line_number; - return(SUBSECTION); - } - if (strcmp(yytext,"%subsubsection") == 0) { - yylval.ivalue = line_number; - return (SUBSUBSECTION); - } - if (strcmp(yytext,"%title") == 0) { - yylval.ivalue = line_number; - return(TITLE); - } - if (strcmp(yytext,"%style") == 0) return(STYLE); - if (strcmp(yytext,"%localstyle") == 0) return(LOCALSTYLE); - if (strcmp(yytext,"%typedef") == 0) { - yylval.ivalue = 1; - return(TYPEDEF); - } - if (strcmp(yytext,"%text") == 0) return(TEXT); - if (strcmp(yytext,"%native") == 0) return(NATIVE); - if (strcmp(yytext,"%disabledoc") == 0) return(DOC_DISABLE); - if (strcmp(yytext,"%enabledoc") == 0) return(DOC_ENABLE); - if (strcmp(yytext,"%pragma") == 0) return(PRAGMA); - if (strcmp(yytext,"%addmethods") == 0) return(ADDMETHODS); - if (strcmp(yytext,"%inline") == 0) return(INLINE); - if (strcmp(yytext,"%typemap") == 0) return(TYPEMAP); - if (strcmp(yytext,"%except") == 0) return(EXCEPT); - if (strcmp(yytext,"%echo") == 0) return(ECHO); - if (strcmp(yytext,"%new") == 0) return(NEW); - if (strcmp(yytext,"%apply") == 0) return(APPLY); - if (strcmp(yytext,"%clear") == 0) return(CLEAR); - if (strcmp(yytext,"%doconly") == 0) return(DOCONLY); - if (strcmp(yytext,"%types") == 0) return(TYPES); - } - // Have an unknown identifier, as a last step, we'll - // do a typedef lookup on it. - - if (check_typedef) { - if (SwigType_istypedef(yytext)) { - yylval.type = NewString(yytext); - return(TYPE_TYPEDEF); - } - } - - yylval.id = Swig_copy_string(yytext); - return(ID); - default: - return(l); - } -} - -// -------------------------------------------------------------- -// scanner_clear_start() -// -// Clears the start of a declaration -// -------------------------------------------------------------- - -void scanner_clear_start() { - start_line = 0; -} diff --git a/Source/SWIG1.1/swig11.h b/Source/SWIG1.1/swig11.h deleted file mode 100644 index 06a01fe67..000000000 --- a/Source/SWIG1.1/swig11.h +++ /dev/null @@ -1,171 +0,0 @@ -/* ----------------------------------------------------------------------------- - * swig11.h - * - * Main header file for the SWIG1.1 core. - * - * Author(s) : David Beazley (beazley@cs.uchicago.edu) - * - * Copyright (C) 1998-2000. The University of Chicago - * Copyright (C) 1995-1998. The University of Utah and The Regents of the - * University of California. - * - * See the file LICENSE for information on usage and redistribution. - * - * $Header$ - * ----------------------------------------------------------------------------- */ - -#include -#include -#include - -#include "swigver.h" - -extern "C" { -#include "swig.h" -} - -/* Global variables. Needs to be cleaned up */ - -#ifdef MACSWIG -#define Status Swig_Status -#endif - -#define PLAIN_VIRTUAL 1 -#define PURE_VIRTUAL 2 -#define SUPER_VIRTUAL 3 - -extern FILE *f_runtime; // Runtime code -extern DOH *f_header; // Headers -extern DOH *f_wrappers; // Wrappers -extern DOH *f_init; // Initialization code -extern FILE *f_input; -extern char LibDir[512]; // Library directory -extern int Status; // Variable creation status -extern int yyparse(); -extern int line_number; -extern int start_line; -extern char *input_file; // Current input file -extern int CPlusPlus; // C++ mode -extern int ObjC; // Objective-C mode -extern int ObjCClass; // Objective-C style class -extern int AddMethods; // AddMethods mode -extern int NewObject; // NewObject mode -extern int Inline; // Inline mode -extern int NoInclude; // NoInclude flag -extern char *typemap_lang; // Current language name -extern int error_count; -extern char output_dir[512]; // Output directory -extern int Verbose; -extern int IsVirtual; - -#define FatalError() if ((error_count++) > 20) { fprintf(stderr,"Confused by earlier errors. Bailing out\n"); SWIG_exit (EXIT_FAILURE); } - -/* Miscellaneous stuff */ - -#define STAT_READONLY 1 -#define MAXSCOPE 16 - -#define tab2 " " -#define tab4 " " -#define tab8 " " - -// Modes for different types of inheritance - -#define INHERIT_FUNC 0x1 -#define INHERIT_VAR 0x2 -#define INHERIT_CONST 0x4 -#define INHERIT_ALL (INHERIT_FUNC | INHERIT_VAR | INHERIT_CONST) - -struct Pragma { - void *filename; - int lineno; - void *lang; - void *name; - void *value; - Pragma *next; -}; - -/* Language Class */ -class Language { -public: - virtual void parse_args(int argc, char *argv[]) = 0; - virtual void parse() = 0; - - /* NEW API */ - virtual void function(DOH *node) = 0; - virtual void variable(DOH *node) = 0; - virtual void constant(DOH *node) = 0; - virtual void nativefunction(DOH *node); - - /* C++ handling */ - virtual void cpp_memberfunction(DOH *node); - virtual void cpp_constructor(DOH *node); - virtual void cpp_destructor(DOH *node); - virtual void cpp_variable(DOH *node); - virtual void cpp_staticfunction(DOH *node); - virtual void cpp_constant(DOH *node); - virtual void cpp_staticvariable(DOH *node); - - /* OLD API */ - - virtual void initialize(void) = 0; - virtual void close(void) = 0; - virtual void set_module(char *mod_name) = 0; - virtual void add_typedef(SwigType *t, char *name); - virtual void create_command(char *cname, char *iname); - - virtual void cpp_open_class(char *name, char *rename, char *ctype, int strip); - virtual void cpp_close_class(); - virtual void cpp_cleanup(); - virtual void cpp_inherit(char **baseclass, int mode = INHERIT_ALL); - virtual void cpp_pragma(Pragma *plist); - virtual void pragma(char *, char *, char *); - - // Declaration of a class, but not a full definition - - virtual void cpp_class_decl(char *, char *, char *); - - // Import directive - virtual void import(char *filename); - -}; - -/* Emit functions */ - -extern void new_create_function(char *, char *, SwigType *, ParmList *); -extern void emit_set_get(DOH *node); -extern void emit_set_action(DOHString_or_char *decl); - -extern int SWIG_main(int, char **, Language *); - -/* These are in the new core */ - -extern "C" { - /* Option processing */ - extern void Swig_init_args(int argc, char **); - extern void Swig_mark_arg(int n); - extern void Swig_check_options(); - extern void Swig_arg_error(); - extern void *Preprocessor_define(void *, int); - extern int Swig_insert_file(const void *filename, void *outfile); - extern FILE *Swig_open(const void *filename); - extern char *Swig_copy_string(const char *s); -} - -// Misc - -extern int emit_args(DOH *node, Wrapper *f); -extern void emit_func_call(DOH *node, Wrapper *f); -extern void SWIG_exit(int); /* use EXIT_{SUCCESS,FAILURE} */ -extern int check_numopt(ParmList *); -extern void SWIG_config_file(const String_or_char *); - -/* swig11.h ends here */ - - - - - - - -