This example both shows the new enum literal facility, and is a regression
test against the enum scoping problem I had. Ocaml.cxx: Accidentally reintroduced the enum scoping problem, so I added an example that will fail if this is ever broken again. I encountered the actual problem in avifile.h git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5478 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
fbb9c8481d
commit
87f4bcef2e
6 changed files with 67 additions and 6 deletions
33
SWIG/Examples/ocaml/scoped_enum/Makefile
Normal file
33
SWIG/Examples/ocaml/scoped_enum/Makefile
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../swig
|
||||
SRCS =
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
MLFILE = example.ml
|
||||
PROGFILE = example_prog.ml
|
||||
OBJS =
|
||||
|
||||
all:: static
|
||||
|
||||
dynamic::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
|
||||
PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
|
||||
ocaml_dynamic_cpp
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
|
||||
PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
|
||||
ocaml_static_cpp
|
||||
|
||||
toplevel::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
|
||||
PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
|
||||
ocaml_static_cpp_toplevel
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean
|
||||
|
||||
check: all
|
||||
1
SWIG/Examples/ocaml/scoped_enum/README
Normal file
1
SWIG/Examples/ocaml/scoped_enum/README
Normal file
|
|
@ -0,0 +1 @@
|
|||
This tests our handling of scoped enums. Run with argument Tag1 or Tag2.
|
||||
7
SWIG/Examples/ocaml/scoped_enum/example.i
Normal file
7
SWIG/Examples/ocaml/scoped_enum/example.i
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
%module example
|
||||
|
||||
%{
|
||||
#include "foo.h"
|
||||
%}
|
||||
|
||||
%include "foo.h"
|
||||
4
SWIG/Examples/ocaml/scoped_enum/example_prog.ml
Normal file
4
SWIG/Examples/ocaml/scoped_enum/example_prog.ml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
open Swig
|
||||
open Example
|
||||
|
||||
let _ = _f (match Sys.argv.(1) with "Tag1" -> ``Tag1 | "Tag2" -> ``Tag2)
|
||||
5
SWIG/Examples/ocaml/scoped_enum/foo.h
Normal file
5
SWIG/Examples/ocaml/scoped_enum/foo.h
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
namespace foo {
|
||||
enum Bar { Tag1, Tag2 };
|
||||
static void f( Bar b ) { printf( "b = %d\n", (int)b ); }
|
||||
}
|
||||
|
||||
|
|
@ -1280,8 +1280,10 @@ public:
|
|||
|
||||
String *fully_qualify_enum_name( Node *n, String *name ) {
|
||||
Node *parent = 0;
|
||||
String *qualification = NewString("");
|
||||
String *fully_qualified_name = NewString("");
|
||||
String *parent_type = 0;
|
||||
String *normalized_name;
|
||||
|
||||
parent = parentNode(n);
|
||||
while( parent ) {
|
||||
|
|
@ -1291,16 +1293,21 @@ public:
|
|||
NewStringf("%s::",Getattr(parent,"name"));
|
||||
if( !Cmp(parent_type,"class") ||
|
||||
!Cmp(parent_type,"namespace") )
|
||||
Insert(fully_qualified_name,0,parent_copy);
|
||||
Insert(qualification,0,parent_copy);
|
||||
Delete(parent_copy);
|
||||
}
|
||||
if( !Cmp( parent_type, "class" ) ) break;
|
||||
parent = parentNode(parent);
|
||||
}
|
||||
|
||||
Printf( fully_qualified_name, "%s", name );
|
||||
Printf( fully_qualified_name, "%s%s", qualification, name );
|
||||
|
||||
return normalizeTemplatedClassName(fully_qualified_name);
|
||||
normalized_name = normalizeTemplatedClassName(fully_qualified_name);
|
||||
if( !strncmp(Char(normalized_name),"enum ",5) ) {
|
||||
Insert(normalized_name,5,qualification);
|
||||
}
|
||||
|
||||
return normalized_name;
|
||||
}
|
||||
|
||||
/* Benedikt Grundmann inspired --> Enum wrap styles */
|
||||
|
|
@ -1370,10 +1377,14 @@ public:
|
|||
* This would make one of the cases below unnecessary.
|
||||
* * * */
|
||||
Printf( f_mlbody,
|
||||
"let _ = Callback.register \"%s_marker\" (`%s)\n"
|
||||
"let _ = Callback.register \"enum %s_marker\" (`%s)\n",
|
||||
fully_qualified_name, name,
|
||||
"let _ = Callback.register \"%s_marker\" (`%s)\n",
|
||||
fully_qualified_name, name );
|
||||
if( !strncmp(Char(fully_qualified_name),"enum ",5) ) {
|
||||
String *fq_noenum = NewString(Char(fully_qualified_name) + 5);
|
||||
Printf( f_mlbody,
|
||||
"let _ = Callback.register \"%s_marker\" (`%s)\n",
|
||||
fq_noenum, name );
|
||||
}
|
||||
|
||||
Printf( f_enumtypes_type,"| `%s\n", name );
|
||||
Insert(fully_qualified_name,0,"enum ");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue