Add %proxycode directive for adding code into proxy classes for C#, D and Java

This commit is contained in:
William S Fulton 2017-01-13 20:42:12 +00:00
commit 3d2e57b0f2
18 changed files with 478 additions and 5 deletions

View file

@ -1584,11 +1584,23 @@ public:
* ----------------------------------------------------------------------------- */
virtual int insertDirective(Node *n) {
int ret = SWIG_OK;
String *code = Getattr(n, "code");
String *section = Getattr(n, "section");
Replaceall(code, "$module", module_class_name);
Replaceall(code, "$imclassname", imclass_name);
Replaceall(code, "$dllimport", dllimport);
return Language::insertDirective(n);
if (!ImportMode && (Cmp(section, "proxycode") == 0)) {
if (proxy_class_code) {
Swig_typemap_replace_embedded_typemap(code, n);
int offset = Len(code) > 0 && *Char(code) == '\n' ? 1 : 0;
Printv(proxy_class_code, Char(code) + offset, "\n", NIL);
}
} else {
ret = Language::insertDirective(n);
}
return ret;
}
/* -----------------------------------------------------------------------------

View file

@ -717,9 +717,20 @@ public:
* D::insertDirective()
* --------------------------------------------------------------------------- */
virtual int insertDirective(Node *n) {
int ret = SWIG_OK;
String *code = Getattr(n, "code");
String *section = Getattr(n, "section");
replaceModuleVariables(code);
return Language::insertDirective(n);
if (!ImportMode && (Cmp(section, "proxycode") == 0)) {
if (proxy_class_body_code) {
Swig_typemap_replace_embedded_typemap(code, n);
Printv(proxy_class_body_code, code, NIL);
}
} else {
ret = Language::insertDirective(n);
}
return ret;
}
/* ---------------------------------------------------------------------------

View file

@ -1612,10 +1612,22 @@ public:
* ----------------------------------------------------------------------------- */
virtual int insertDirective(Node *n) {
int ret = SWIG_OK;
String *code = Getattr(n, "code");
String *section = Getattr(n, "section");
Replaceall(code, "$module", module_class_name);
Replaceall(code, "$imclassname", imclass_name);
return Language::insertDirective(n);
if (!ImportMode && (Cmp(section, "proxycode") == 0)) {
if (proxy_class_code) {
Swig_typemap_replace_embedded_typemap(code, n);
int offset = Len(code) > 0 && *Char(code) == '\n' ? 1 : 0;
Printv(proxy_class_code, Char(code) + offset, "\n", NIL);
}
} else {
ret = Language::insertDirective(n);
}
return ret;
}
/* -----------------------------------------------------------------------------

View file

@ -400,6 +400,7 @@ extern int ParmList_is_compactdefargs(ParmList *p);
extern void Swig_typemap_clear(const_String_or_char_ptr tmap_method, ParmList *pattern);
extern int Swig_typemap_apply(ParmList *srcpat, ParmList *destpat);
extern void Swig_typemap_clear_apply(ParmList *pattern);
extern void Swig_typemap_replace_embedded_typemap(String *s, Node *file_line_node);
extern void Swig_typemap_debug(void);
extern void Swig_typemap_search_debug_set(void);
extern void Swig_typemap_used_debug_set(void);

View file

@ -1876,6 +1876,21 @@ static List *split_embedded_typemap(String *s) {
return args;
}
/* -----------------------------------------------------------------------------
* Swig_typemap_replace_embedded_typemap()
*
* For special variable macro $typemap(...) expansion outside of typemaps.
* Only limited usage works as most typemap special variables ($1, $input etc)
* are not expanded correctly outside of typemaps.
* ----------------------------------------------------------------------------- */
void Swig_typemap_replace_embedded_typemap(String *s, Node *file_line_node) {
Setfile(s, Getfile(file_line_node));
Setline(s, Getline(file_line_node));
Replaceall(s, "$typemap", "$TYPEMAP");
replace_embedded_typemap(s, 0, 0, file_line_node);
}
/* -----------------------------------------------------------------------------
* replace_embedded_typemap()
*