Frank Buss's fix for anon enums.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8593 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
0c18f47955
commit
dafc4dbdfc
2 changed files with 40 additions and 11 deletions
|
|
@ -95,3 +95,17 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
%insert("lisphead") %{
|
||||||
|
;;;SWIG wrapper code starts here
|
||||||
|
|
||||||
|
(defmacro defanonenum (&body enums)
|
||||||
|
"Converts anonymous enums to defconstants."
|
||||||
|
`(progn ,@(loop for value in enums
|
||||||
|
for index = 0 then (1+ index)
|
||||||
|
when (listp value) do (setf index (second value)
|
||||||
|
value (first value))
|
||||||
|
collect `(defconstant ,value ,index))))
|
||||||
|
|
||||||
|
;;;SWIG wrapper code ends here
|
||||||
|
%}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ public:
|
||||||
File *f_cl;
|
File *f_cl;
|
||||||
String *f_clhead;
|
String *f_clhead;
|
||||||
String *f_clwrap;
|
String *f_clwrap;
|
||||||
|
bool CWrap; // generate wrapper file for C code?
|
||||||
File *f_cxx;
|
File *f_cxx;
|
||||||
File *f_cxx_header;
|
File *f_cxx_header;
|
||||||
File *f_cxx_wrapper;
|
File *f_cxx_wrapper;
|
||||||
|
|
@ -59,7 +59,7 @@ void CFFI :: main(int argc, char *argv[]) {
|
||||||
SWIG_config_file("cffi.swg");
|
SWIG_config_file("cffi.swg");
|
||||||
generate_typedef_flag = 0;
|
generate_typedef_flag = 0;
|
||||||
extern_all_flag=0;
|
extern_all_flag=0;
|
||||||
|
CWrap = false;
|
||||||
for(i=1; i<argc; i++) {
|
for(i=1; i<argc; i++) {
|
||||||
if (!Strcmp(argv[i], "-help")) {
|
if (!Strcmp(argv[i], "-help")) {
|
||||||
Printf(stdout, "cffi Options (available with -cffi)\n");
|
Printf(stdout, "cffi Options (available with -cffi)\n");
|
||||||
|
|
@ -71,19 +71,27 @@ void CFFI :: main(int argc, char *argv[]) {
|
||||||
" -generate-typedef\n"
|
" -generate-typedef\n"
|
||||||
"\t If this option is given then defctype will be used to generate shortcuts\n"
|
"\t If this option is given then defctype will be used to generate shortcuts\n"
|
||||||
"according to the typedefs in the input.\n"
|
"according to the typedefs in the input.\n"
|
||||||
" -lispify-identifiers\n"
|
" -[no]cwrap\n"
|
||||||
"\t If this option is given then while converting C identified to symbols they"
|
"\tTurn on or turn off generation of an intermediate C file when\n"
|
||||||
"will be lispified.\n"
|
"\tcreating a C interface. By default this is only done for C++ code.\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if ( (Strcmp(argv[i],"-extern-all") == 0)) {
|
else if ( (Strcmp(argv[i],"-extern-all") == 0)) {
|
||||||
extern_all_flag = 1;
|
extern_all_flag = 1;
|
||||||
Swig_mark_arg(i);
|
Swig_mark_arg(i);
|
||||||
}
|
}
|
||||||
|
else if (!strcmp(argv[i], "-cwrap")) {
|
||||||
|
CWrap = true;
|
||||||
|
Swig_mark_arg(i);
|
||||||
|
}
|
||||||
else if ( (Strcmp(argv[i],"-generate-typedef") == 0)) {
|
else if ( (Strcmp(argv[i],"-generate-typedef") == 0)) {
|
||||||
generate_typedef_flag = 1;
|
generate_typedef_flag = 1;
|
||||||
Swig_mark_arg(i);
|
Swig_mark_arg(i);
|
||||||
}
|
}
|
||||||
|
else if (!strcmp(argv[i], "-nocwrap")) {
|
||||||
|
CWrap = false;
|
||||||
|
Swig_mark_arg(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
f_clhead = NewString("");
|
f_clhead = NewString("");
|
||||||
f_clwrap = NewString("");
|
f_clwrap = NewString("");
|
||||||
|
|
@ -102,15 +110,14 @@ int CFFI :: top(Node *n) {
|
||||||
SWIG_exit(EXIT_FAILURE);
|
SWIG_exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CPlusPlus)
|
if (CPlusPlus || CWrap) {
|
||||||
{
|
|
||||||
f_cxx=NewFile(cxx_filename, "w");
|
f_cxx=NewFile(cxx_filename, "w");
|
||||||
if (!f_cxx) {
|
if (!f_cxx) {
|
||||||
Close(f_cl); Delete(f_cl);
|
Close(f_cl); Delete(f_cl);
|
||||||
Printf(stderr, "Unable to open %s for writing\n", cxx_filename);
|
Printf(stderr, "Unable to open %s for writing\n", cxx_filename);
|
||||||
SWIG_exit(EXIT_FAILURE);
|
SWIG_exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
f_cxx=NewString("");
|
f_cxx=NewString("");
|
||||||
|
|
||||||
|
|
@ -418,8 +425,16 @@ int CFFI :: typedefHandler(Node *n) {
|
||||||
|
|
||||||
int CFFI :: enumDeclaration(Node *n) {
|
int CFFI :: enumDeclaration(Node *n) {
|
||||||
String *name=Getattr(n, "sym:name");
|
String *name=Getattr(n, "sym:name");
|
||||||
|
const char* slot_name_prefix;
|
||||||
|
|
||||||
Printf(f_cl,"\n(defcenum %s",name);
|
if(name && Len(name)!=0) {
|
||||||
|
Printf(f_cl,"\n(defcenum %s",name);
|
||||||
|
slot_name_prefix = ":";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Printf(f_cl,"\n(defanonenum %s",name);
|
||||||
|
slot_name_prefix = "";
|
||||||
|
}
|
||||||
|
|
||||||
for (Node *c=firstChild(n); c; c=nextSibling(c)) {
|
for (Node *c=firstChild(n); c; c=nextSibling(c)) {
|
||||||
|
|
||||||
|
|
@ -427,9 +442,9 @@ int CFFI :: enumDeclaration(Node *n) {
|
||||||
String *value = Getattr(c, "enumvalue");
|
String *value = Getattr(c, "enumvalue");
|
||||||
|
|
||||||
if(!value)
|
if(!value)
|
||||||
Printf(f_cl,"\n\t:%s",slot_name,value);
|
Printf(f_cl,"\n\t%s%s",slot_name_prefix, slot_name);
|
||||||
else
|
else
|
||||||
Printf(f_cl,"\n\t(:%s %s)",slot_name,value);
|
Printf(f_cl,"\n\t(%s%s %s)",slot_name_prefix, slot_name,value);
|
||||||
|
|
||||||
Delete(value);
|
Delete(value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue