allow to use %define inside a %define macro
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7408 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
99ed184f95
commit
c74fd4442a
2 changed files with 126 additions and 103 deletions
|
|
@ -29,15 +29,16 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define Name ## _input_binary(TYPEMAP, SIZE) \
|
%define Name ## _input_binary(TYPEMAP, SIZE)
|
||||||
%typemap(in, fragment=#SWIG_AsCharPtrAndSize) (TYPEMAP, SIZE) \
|
%typemap(in, fragment=#SWIG_AsCharPtrAndSize) (TYPEMAP, SIZE)
|
||||||
(Char *buf, size_t size) \
|
(Char *buf, size_t size)
|
||||||
{ \
|
{
|
||||||
SWIG_AsCharPtrAndSize($input, &buf, &size); \
|
SWIG_AsCharPtrAndSize($input, &buf, &size);
|
||||||
if (SWIG_arg_fail($argnum)) SWIG_fail; \
|
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||||
$1 = ($1_ltype) buf; \
|
$1 = ($1_ltype) buf;
|
||||||
$2 = ($2_ltype) size - 1; \
|
$2 = ($2_ltype) size - 1;
|
||||||
}
|
}
|
||||||
|
%enddef
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -53,13 +54,13 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define Name ## _bounded_output(TYPEMAP,MAX) \
|
%define Name ## _bounded_output(TYPEMAP,MAX)
|
||||||
%typemap(in,numinputs=0) TYPEMAP(Char temp[MAX+1]) \
|
%typemap(in,numinputs=0) TYPEMAP(Char temp[MAX+1])
|
||||||
"$1 = ($1_ltype) temp;"; \
|
"$1 = ($1_ltype) temp;";
|
||||||
\
|
|
||||||
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr ) TYPEMAP \
|
|
||||||
"$1[MAX] = 0; $result = t_output_helper($result, SWIG_FromCharPtr($1));";
|
|
||||||
|
|
||||||
|
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr ) TYPEMAP
|
||||||
|
"$1[MAX] = 0; $result = t_output_helper($result, SWIG_FromCharPtr($1));";
|
||||||
|
%enddef
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -75,12 +76,13 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define Name ## _chunk_output(TYPEMAP,SIZE) \
|
%define Name ## _chunk_output(TYPEMAP,SIZE)
|
||||||
%typemap(in,numinputs=0) TYPEMAP(Char temp[SIZE]) \
|
%typemap(in,numinputs=0) TYPEMAP(Char temp[SIZE])
|
||||||
"$1 = ($1_ltype) temp;"; \
|
"$1 = ($1_ltype) temp;";
|
||||||
\
|
|
||||||
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharArray) TYPEMAP \
|
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharArray) TYPEMAP
|
||||||
"$result = t_output_helper($result, SWIG_FromCharArray($1,SIZE));";
|
"$result = t_output_helper($result, SWIG_FromCharArray($1,SIZE));";
|
||||||
|
%enddef
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -99,19 +101,19 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#define Name ## _bounded_mutable(TYPEMAP,MAX) \
|
%define Name ## _bounded_mutable(TYPEMAP,MAX)
|
||||||
%typemap(in,fragment=#SWIG_AsCharPtrAndSize) TYPEMAP(Char temp[MAX+1]) { \
|
%typemap(in,fragment=#SWIG_AsCharPtrAndSize) TYPEMAP(Char temp[MAX+1]) {
|
||||||
Char *t = 0; size_t n; \
|
Char *t = 0; size_t n;
|
||||||
SWIG_AsCharPtrAndSize($input, &t, &n); \
|
SWIG_AsCharPtrAndSize($input, &t, &n);
|
||||||
if (SWIG_arg_fail($argnum)) SWIG_fail; \
|
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||||
if ( n > (size_t)MAX ) n = (size_t)MAX; \
|
if ( n > (size_t)MAX ) n = (size_t)MAX;
|
||||||
memcpy(temp, t, sizeof(Char)*n); \
|
memcpy(temp, t, sizeof(Char)*n);
|
||||||
temp[n] = 0; \
|
temp[n] = 0;
|
||||||
$1 = ($1_ltype) temp; \
|
$1 = ($1_ltype) temp;
|
||||||
} \
|
}
|
||||||
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) TYPEMAP \
|
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) TYPEMAP
|
||||||
"$1[MAX] = 0; $result = t_output_helper($result, SWIG_FromCharPtr($1));";
|
"$1[MAX] = 0; $result = t_output_helper($result, SWIG_FromCharPtr($1));";
|
||||||
|
%enddef
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -130,22 +132,26 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define Name ## _mutable(TYPEMAP,EXP...) \
|
%define Name ## _mutable(TYPEMAP,EXP...)
|
||||||
%typemap(in,fragment=#SWIG_AsCharPtrAndSize) TYPEMAP { \
|
%typemap(in,fragment=#SWIG_AsCharPtrAndSize) TYPEMAP {
|
||||||
const size_t expansion = strlen(#EXP) ? atoi(#EXP) : 0; \
|
#if #EXP == ""
|
||||||
Char* t = 0; size_t n = 0; \
|
const size_t expansion = 1;
|
||||||
SWIG_AsCharPtrAndSize($input, &t, &n); \
|
#else
|
||||||
if (SWIG_arg_fail($argnum)) SWIG_fail; \
|
const size_t expansion = 1 + EXP;
|
||||||
$1 = SWIG_new_array(n+1+expansion, $*1_ltype); \
|
#endif
|
||||||
memcpy($1,t,sizeof(Char)*n); \
|
Char* t = 0; size_t n = 0;
|
||||||
$1[n] = 0; \
|
SWIG_AsCharPtrAndSize($input, &t, &n);
|
||||||
} \
|
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||||
\
|
$1 = SWIG_new_array(n+expansion, $*1_ltype);
|
||||||
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) TYPEMAP { \
|
memcpy($1,t,sizeof(Char)*n);
|
||||||
$result = t_output_helper($result,SWIG_FromCharPtr($1));\
|
$1[n] = 0;
|
||||||
SWIG_delete_array($1); \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) TYPEMAP {
|
||||||
|
$result = t_output_helper($result,SWIG_FromCharPtr($1));
|
||||||
|
SWIG_delete_array($1);
|
||||||
|
}
|
||||||
|
%enddef
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* %cstring_output_maxsize(TYPEMAP, SIZE)
|
* %cstring_output_maxsize(TYPEMAP, SIZE)
|
||||||
|
|
@ -158,16 +164,17 @@
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define Name ## _output_maxsize(TYPEMAP, SIZE) \
|
%define Name ## _output_maxsize(TYPEMAP, SIZE)
|
||||||
%typemap(in,fragment=SWIG_As_frag(unsigned long)) (TYPEMAP, SIZE) { \
|
%typemap(in,fragment=SWIG_As_frag(unsigned long)) (TYPEMAP, SIZE) {
|
||||||
$2 = ($2_ltype) SWIG_As(unsigned long)($input); \
|
$2 = ($2_ltype) SWIG_As(unsigned long)($input);
|
||||||
if (SWIG_arg_fail($argnum)) SWIG_fail; \
|
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||||
$1 = SWIG_new_array($2+1, $*1_ltype); \
|
$1 = SWIG_new_array($2+1, $*1_ltype);
|
||||||
} \
|
|
||||||
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) (TYPEMAP,SIZE) { \
|
|
||||||
$result = t_output_helper($result,SWIG_FromCharPtr($1)); \
|
|
||||||
SWIG_delete_array($1); \
|
|
||||||
}
|
}
|
||||||
|
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) (TYPEMAP,SIZE) {
|
||||||
|
$result = t_output_helper($result,SWIG_FromCharPtr($1));
|
||||||
|
SWIG_delete_array($1);
|
||||||
|
}
|
||||||
|
%enddef
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -184,19 +191,20 @@
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define Name ## _output_withsize(TYPEMAP, SIZE) \
|
%define Name ## _output_withsize(TYPEMAP, SIZE)
|
||||||
%typemap(in,fragment=SWIG_As_frag(unsigned long)) (TYPEMAP, SIZE) { \
|
%typemap(in,fragment=SWIG_As_frag(unsigned long)) (TYPEMAP, SIZE) {
|
||||||
size_t n = SWIG_As(unsigned long)($input); \
|
size_t n = SWIG_As(unsigned long)($input);
|
||||||
if (SWIG_arg_fail($argnum)) SWIG_fail; \
|
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||||
$1 = SWIG_new_array(n+1, $*1_ltype); \
|
$1 = SWIG_new_array(n+1, $*1_ltype);
|
||||||
$2 = SWIG_new($*2_ltype); \
|
$2 = SWIG_new($*2_ltype);
|
||||||
*$2 = n; \
|
*$2 = n;
|
||||||
} \
|
|
||||||
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharArray) (TYPEMAP,SIZE) { \
|
|
||||||
$result = t_output_helper($result, SWIG_FromCharArray($1,*$2)); \
|
|
||||||
SWIG_delete_array($1); \
|
|
||||||
SWIG_delete($2); \
|
|
||||||
}
|
}
|
||||||
|
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharArray) (TYPEMAP,SIZE) {
|
||||||
|
$result = t_output_helper($result, SWIG_FromCharArray($1,*$2));
|
||||||
|
SWIG_delete_array($1);
|
||||||
|
SWIG_delete($2);
|
||||||
|
}
|
||||||
|
%enddef
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -212,16 +220,17 @@
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define Name ## _output_allocate(TYPEMAP, RELEASE) \
|
%define Name ## _output_allocate(TYPEMAP, RELEASE)
|
||||||
%typemap(in,numinputs=0) TYPEMAP($*1_ltype temp = 0) \
|
%typemap(in,numinputs=0) TYPEMAP($*1_ltype temp = 0)
|
||||||
"$1 = &temp;"; \
|
"$1 = &temp;";
|
||||||
\
|
|
||||||
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) TYPEMAP { \
|
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) TYPEMAP {
|
||||||
if (*$1) { \
|
if (*$1) {
|
||||||
$result = t_output_helper($result,SWIG_FromCharPtr(*$1));\
|
$result = t_output_helper($result,SWIG_FromCharPtr(*$1));
|
||||||
RELEASE; \
|
RELEASE;
|
||||||
} \
|
}
|
||||||
} \
|
}
|
||||||
|
%enddef
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -238,17 +247,17 @@
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define Name ## _output_allocate_size(TYPEMAP, SIZE, RELEASE) \
|
%define Name ## _output_allocate_size(TYPEMAP, SIZE, RELEASE)
|
||||||
%typemap(in,numinputs=0) (TYPEMAP, SIZE) ($*1_ltype temp = 0, $*2_ltype tempn) \
|
%typemap(in,numinputs=0) (TYPEMAP, SIZE) ($*1_ltype temp = 0, $*2_ltype tempn)
|
||||||
"$1 = &temp; $2 = &tempn;"; \
|
"$1 = &temp; $2 = &tempn;";
|
||||||
\
|
|
||||||
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharArray)(TYPEMAP,SIZE) { \
|
|
||||||
if (*$1) { \
|
|
||||||
$result = t_output_helper($result,SWIG_FromCharArray(*$1,*$2)); \
|
|
||||||
RELEASE; \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
|
|
||||||
|
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharArray)(TYPEMAP,SIZE) {
|
||||||
|
if (*$1) {
|
||||||
|
$result = t_output_helper($result,SWIG_FromCharArray(*$1,*$2));
|
||||||
|
RELEASE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%enddef
|
||||||
|
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1072,6 +1072,7 @@ Preprocessor_parse(String *s)
|
||||||
int start_line = 0;
|
int start_line = 0;
|
||||||
int allow = 1;
|
int allow = 1;
|
||||||
int level = 0;
|
int level = 0;
|
||||||
|
int dlevel = 0;
|
||||||
int mask = 0;
|
int mask = 0;
|
||||||
int start_level = 0;
|
int start_level = 0;
|
||||||
int cpp_lines = 0;
|
int cpp_lines = 0;
|
||||||
|
|
@ -1556,6 +1557,7 @@ Preprocessor_parse(String *s)
|
||||||
state = 1;
|
state = 1;
|
||||||
} else if (Cmp(decl,"%define") == 0) {
|
} else if (Cmp(decl,"%define") == 0) {
|
||||||
/* Got a define directive */
|
/* Got a define directive */
|
||||||
|
dlevel++;
|
||||||
add_chunk(ns,chunk,allow);
|
add_chunk(ns,chunk,allow);
|
||||||
copy_location(s,chunk);
|
copy_location(s,chunk);
|
||||||
Clear(value);
|
Clear(value);
|
||||||
|
|
@ -1574,27 +1576,39 @@ Preprocessor_parse(String *s)
|
||||||
case 150:
|
case 150:
|
||||||
Putc(c,value);
|
Putc(c,value);
|
||||||
if (c == '%') {
|
if (c == '%') {
|
||||||
|
const char *ed = "enddef";
|
||||||
|
const char *df = "define";
|
||||||
|
char statement[7];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char *d = "enddef";
|
for (i = 0; i < 6; ) {
|
||||||
for (i = 0; i < 6; i++) {
|
|
||||||
c = Getc(s);
|
c = Getc(s);
|
||||||
Putc(c,value);
|
Putc(c,value);
|
||||||
if (c != d[i]) break;
|
statement[i++] = c;
|
||||||
|
if (strncmp(statement, ed, i) && strncmp(statement, df, i)) break;
|
||||||
}
|
}
|
||||||
c = Getc(s);
|
c = Getc(s);
|
||||||
Ungetc(c,s);
|
Ungetc(c,s);
|
||||||
if ((i == 6) && (isspace(c))) {
|
if ((i == 6) && (isspace(c))) {
|
||||||
/* Got the macro */
|
if (strncmp(statement, df, i) == 0) {
|
||||||
for (i = 0; i < 7; i++) {
|
++dlevel;
|
||||||
Delitem(value,DOH_END);
|
} else {
|
||||||
}
|
if (strncmp(statement, ed, i) == 0) {
|
||||||
if (allow) {
|
--dlevel;
|
||||||
Seek(value,0,SEEK_SET);
|
if (!dlevel) {
|
||||||
Preprocessor_define(value,1);
|
/* Got the macro */
|
||||||
}
|
for (i = 0; i < 7; i++) {
|
||||||
Putc('\n',ns);
|
Delitem(value,DOH_END);
|
||||||
addline(ns,value,0);
|
}
|
||||||
state = 0;
|
if (allow) {
|
||||||
|
Seek(value,0,SEEK_SET);
|
||||||
|
Preprocessor_define(value,1);
|
||||||
|
}
|
||||||
|
Putc('\n',ns);
|
||||||
|
addline(ns,value,0);
|
||||||
|
state = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue