added basic Modula-3 support

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5776 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Henning Thielemann 2004-03-19 11:45:29 +00:00
commit 483d8b4367
57 changed files with 6645 additions and 380 deletions

View file

@ -0,0 +1,18 @@
*.class
*.java
*_wrap.*
*_const*
*.i3
*.m3
m3makefile
src
LINUXLIBC6
*.dll
*.dsw
*.exp
*.lib
*.ncb
*.opt
*.plg
Release
Debug

View file

@ -0,0 +1,26 @@
TOP = ../..
SWIG = $(TOP)/../swig
SRCS =
TARGET = example
INTERFACE = example.i
CONSTNUMERIC = example_const
SWIGOPT = -c++
MODULA3SRCS = *.[im]3
all:: modula3
modula3::
$(SWIG) -modula3 $(SWIGOPT) -module Example -generateconst $(CONSTNUMERIC) $(TARGET).h
$(CXX) -Wall $(CONSTNUMERIC).c -o $(CONSTNUMERIC)
$(CONSTNUMERIC) >$(CONSTNUMERIC).i
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3
m3ppinplace $(MODULA3SRCS)
mv m3makefile $(MODULA3SRCS) src/
cm3
clean::
$(MAKE) -f $(TOP)/Makefile modula3_clean
check: all

View file

@ -0,0 +1,32 @@
/* File : example.cxx */
#include "example.h"
#include <stdio.h>
void Foo::enum_test(speed s) {
if (s == IMPULSE) {
printf("IMPULSE speed\n");
} else if (s == WARP) {
printf("WARP speed\n");
} else if (s == LUDICROUS) {
printf("LUDICROUS speed\n");
} else if (s == HYPER) {
printf("HYPER speed\n");
} else {
printf("Unknown speed\n");
}
}
void enum_test(color c, Foo::speed s) {
if (c == RED) {
printf("color = RED, ");
} else if (c == BLUE) {
printf("color = BLUE, ");
} else if (c == GREEN) {
printf("color = GREEN, ");
} else {
printf("color = Unknown color!, ");
}
Foo obj;
obj.enum_test(s);
}

View file

@ -0,0 +1,83 @@
/* File : example.h */
#define PI 3.141
#define DAY_MONDAY 0
#define DAY_TUESDAY 1
#define DAY_WEDNESDAY 2
#define DAY_THURSDAY 3
#define DAY_FRIDAY 4
#define DAY_SATURDAY 5
#define DAY_SUNDAY 6
enum color { BLUE, RED, GREEN };
#define CLB_BLACK 0
#define CLB_BLUE 1
#define CLB_RED 2
#define CLB_MAGENTA 3
#define CLB_GREEN 4
#define CLB_CYAN 5
#define CLB_YELLOW 6
#define CLB_WHITE 7
/* Using this would be good style
which cannot be expected for general C header files.
Instead I want to demonstrate how to live without it.
enum month {
MTHF_JANUARY,
MTHF_FEBRUARY,
MTHF_MARCH,
MTHF_APRIL,
MTHF_MAY,
MTHF_JUNE,
MTHF_JULY,
MTHF_AUGUST,
MTHF_SEPTEMBER,
MTHF_OCTOBER,
MTHF_NOVEMBER,
MTHF_DECEMBER,
}
*/
/* Since there are no compile time constants in C / C++
it is a common abuse
to declare bit set (flag) constants
as enumerations. */
enum calendar {
MTHB_JANUARY = 1 << 0, /* 1 << MTHF_JANUARY, */
MTHB_FEBRUARY = 1 << 1, /* 1 << MTHF_FEBRUARY, */
MTHB_MARCH = 1 << 2, /* 1 << MTHF_MARCH, */
MTHB_APRIL = 1 << 3, /* 1 << MTHF_APRIL, */
MTHB_MAY = 1 << 4, /* 1 << MTHF_MAY, */
MTHB_JUNE = 1 << 5, /* 1 << MTHF_JUNE, */
MTHB_JULY = 1 << 6, /* 1 << MTHF_JULY, */
MTHB_AUGUST = 1 << 7, /* 1 << MTHF_AUGUST, */
MTHB_SEPTEMBER = 1 << 8, /* 1 << MTHF_SEPTEMBER, */
MTHB_OCTOBER = 1 << 9, /* 1 << MTHF_OCTOBER, */
MTHB_NOVEMBER = 1 << 10, /* 1 << MTHF_NOVEMBER, */
MTHB_DECEMBER = 1 << 11, /* 1 << MTHF_DECEMBER, */
MTHB_SPRING = MTHB_MARCH | MTHB_APRIL | MTHB_MAY,
MTHB_SUMMER = MTHB_JUNE | MTHB_JULY | MTHB_AUGUST,
MTHB_AUTUMN = MTHB_SEPTEMBER | MTHB_OCTOBER | MTHB_NOVEMBER,
MTHB_WINTER = MTHB_DECEMBER | MTHB_JANUARY | MTHB_FEBRUARY,
};
namespace Answer {
enum {
UNIVERSE_AND_EVERYTHING = 42,
SEVENTEEN_AND_FOUR = 21,
TWOHUNDRED_PERCENT_OF_NOTHING = 0,
};
class Foo {
public:
Foo() { }
enum speed { IMPULSE = -2, WARP = 0, HYPER, LUDICROUS = 3};
void enum_test(speed s);
};
};
void enum_test(color c, Answer::Foo::speed s);

View file

@ -0,0 +1,72 @@
/* File : example.i */
%module Example
%{
#include "example.h"
%}
%include "example_const.i"
// such features are generated by the following pragmas
#if 0
%feature("modula3:enumitem:enum","Days") DAY_MONDAY;
%feature("modula3:enumitem:name","monday") DAY_MONDAY;
%feature("modula3:enumitem:conv","int:int") DAY_MONDAY;
%feature("modula3:enumitem:enum","Month") MTHB_JANUARY;
%feature("modula3:enumitem:name","january") MTHB_JANUARY;
%feature("modula3:enumitem:conv","set:int") MTHB_JANUARY;
//%feature("modula3:constset:type","MonthSet") MTHB_JANUARY; /*type in the constant definition*/
%feature("modula3:constset:set", "MonthSet") MTHB_JANUARY; /*remarks that the 'type' is a set type*/
%feature("modula3:constset:base","Month") MTHB_JANUARY;
%feature("modula3:constset:name","monthsJanuary") MTHB_JANUARY;
%feature("modula3:constset:conv","set:set") MTHB_JANUARY; /*conversion of the bit pattern: no change*/
%feature("modula3:enumitem:enum","Color") BLUE;
%feature("modula3:enumitem:name","blue") BLUE;
%feature("modula3:enumitem:conv","int:int") BLUE;
%feature("modula3:constint:type","INTEGER") Foo::IMPULSE;
%feature("modula3:constint:name","impulse") Foo::IMPULSE;
%feature("modula3:constint:conv","int:int") Foo::IMPULSE;
#endif
%rename(pi) PI;
%pragma(modula3) enumitem="prefix=DAY_;int;srcstyle=underscore;Day";
%pragma(modula3) enumitem="enum=color;int;srcstyle=underscore;Color";
%pragma(modula3) makesetofenum="Color";
%pragma(modula3) constset="prefix=CLB_;set;srcstyle=underscore,prefix=clb;ColorSet,Color";
%pragma(modula3) enumitem="prefix=MTHB_,enum=calendar;set;srcstyle=underscore;Month";
%pragma(modula3) makesetofenum="Month";
%pragma(modula3) constset="prefix=MTHB_,enum=calendar;set;srcstyle=underscore,prefix=monthset;MonthSet,Month";
%pragma(modula3) constint="prefix=Answer::Foo::,enum=Answer::Foo::speed;int;srcstyle=underscore,prefix=speed;INTEGER";
%pragma(modula3) constint="prefix=Answer::,enum=Answer::;int;srcstyle=underscore,prefix=answer;CARDINAL";
%rename(AnswerFoo) Answer::Foo;
%typemap("m3rawrettype") Answer::Foo * %{AnswerFoo%}
%typemap("m3rawintype") Answer::Foo * %{AnswerFoo%}
%typemap("m3rawinmode") Answer::Foo * %{%}
%typemap("m3wraprettype") Answer::Foo * %{AnswerFoo%}
%typemap("m3wrapintype") Answer::Foo * %{AnswerFoo%}
%typemap("m3wrapinmode") Answer::Foo * %{%}
%typemap("m3wrapargraw") Answer::Foo * %{self.cxxObj%}
%typemap("m3wrapretvar") Answer::Foo * %{cxxObj : ExampleRaw.AnswerFoo;%}
%typemap("m3wrapretraw") Answer::Foo * %{cxxObj%}
%typemap("m3wrapretconv") Answer::Foo * %{NEW(AnswerFoo,cxxObj:=cxxObj)%}
%typemap("m3rawintype") Answer::Foo::speed %{C.int%};
%typemap("m3rawintype:import") Answer::Foo::speed %{Ctypes AS C%};
%typemap("m3wrapintype") Answer::Foo::speed %{[-2..3]%};
%typemap("m3wrapintype") color %{Color%};
%typemap("m3wrapargraw") color %{ORD($1_name)%};
/* Let's just grab the original header file here */
%include "example.h"