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