Typemap API changes to facilitate more uniform typemap handling across language modules - in particular some typemaps usage did not respect the warning attribute and other warning handling and $typemap special variable (which will be refined in future commit) as well as local typemap variable handling:
- remove Swig_typemap_search, Swig_typemap_search_multi and Swig_typemap_attach_kwargs from access outside of typemaps.c (made static) - all static methods in typemap.c renamed dropping Swig_ prefix git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11380 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
531e341309
commit
224c83ef09
9 changed files with 304 additions and 280 deletions
|
|
@ -1115,16 +1115,16 @@ public:
|
|||
// Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper C# enum
|
||||
|
||||
// Pure C# baseclass and interfaces
|
||||
const String *pure_baseclass = typemapLookup("csbase", typemap_lookup_type, WARN_NONE);
|
||||
const String *pure_interfaces = typemapLookup("csinterfaces", typemap_lookup_type, WARN_NONE);
|
||||
const String *pure_baseclass = typemapLookup(n, "csbase", typemap_lookup_type, WARN_NONE);
|
||||
const String *pure_interfaces = typemapLookup(n, "csinterfaces", typemap_lookup_type, WARN_NONE);
|
||||
|
||||
// Class attributes
|
||||
const String *csattributes = typemapLookup("csattributes", typemap_lookup_type, WARN_NONE);
|
||||
const String *csattributes = typemapLookup(n, "csattributes", typemap_lookup_type, WARN_NONE);
|
||||
if (csattributes && *Char(csattributes))
|
||||
Printf(enum_code, "%s\n", csattributes);
|
||||
|
||||
// Emit the enum
|
||||
Printv(enum_code, typemapLookup("csclassmodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers (enum modifiers really)
|
||||
Printv(enum_code, typemapLookup(n, "csclassmodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers (enum modifiers really)
|
||||
" ", symname, (*Char(pure_baseclass) || *Char(pure_interfaces)) ? " : " : "", pure_baseclass, ((*Char(pure_baseclass)) && *Char(pure_interfaces)) ? // Interfaces
|
||||
", " : "", pure_interfaces, " {\n", NIL);
|
||||
} else {
|
||||
|
|
@ -1140,8 +1140,8 @@ public:
|
|||
// Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper C# enum
|
||||
// Finish the enum declaration
|
||||
// Typemaps are used to generate the enum definition in a similar manner to proxy classes.
|
||||
Printv(enum_code, (enum_feature == ProperEnum) ? "\n" : typemapLookup("csbody", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class
|
||||
typemapLookup("cscode", typemap_lookup_type, WARN_NONE), // extra C# code
|
||||
Printv(enum_code, (enum_feature == ProperEnum) ? "\n" : typemapLookup(n, "csbody", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class
|
||||
typemapLookup(n, "cscode", typemap_lookup_type, WARN_NONE), // extra C# code
|
||||
"}", NIL);
|
||||
|
||||
Replaceall(enum_code, "$csclassname", symname);
|
||||
|
|
@ -1177,7 +1177,7 @@ public:
|
|||
|
||||
addOpenNamespace(namespce, f_enum);
|
||||
|
||||
Printv(f_enum, typemapLookup("csimports", typemap_lookup_type, WARN_NONE), // Import statements
|
||||
Printv(f_enum, typemapLookup(n, "csimports", typemap_lookup_type, WARN_NONE), // Import statements
|
||||
"\n", enum_code, "\n", NIL);
|
||||
|
||||
addCloseNamespace(namespce, f_enum);
|
||||
|
|
@ -1243,7 +1243,7 @@ public:
|
|||
// Wrap C/C++ enums with constant integers or use the typesafe enum pattern
|
||||
const String *parent_name = Getattr(parentNode(n), "name");
|
||||
String *typemap_lookup_type = parent_name ? Copy(parent_name) : NewString("int");
|
||||
const String *tm = typemapLookup("cstype", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF);
|
||||
const String *tm = typemapLookup(n, "cstype", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF);
|
||||
String *return_type = Copy(tm);
|
||||
Delete(typemap_lookup_type);
|
||||
typemap_lookup_type = NULL;
|
||||
|
|
@ -1490,12 +1490,12 @@ public:
|
|||
String *c_baseclass = NULL;
|
||||
String *baseclass = NULL;
|
||||
String *c_baseclassname = NULL;
|
||||
String *typemap_lookup_type = Getattr(n, "classtypeobj");
|
||||
SwigType *typemap_lookup_type = Getattr(n, "classtypeobj");
|
||||
bool feature_director = Swig_directorclass(n) ? true : false;
|
||||
|
||||
// Inheritance from pure C# classes
|
||||
Node *attributes = NewHash();
|
||||
const String *pure_baseclass = typemapLookup("csbase", typemap_lookup_type, WARN_NONE, attributes);
|
||||
const String *pure_baseclass = typemapLookup(n, "csbase", typemap_lookup_type, WARN_NONE, attributes);
|
||||
bool purebase_replace = GetFlag(attributes, "tmap:csbase:replace") ? true : false;
|
||||
bool purebase_notderived = GetFlag(attributes, "tmap:csbase:notderived") ? true : false;
|
||||
Delete(attributes);
|
||||
|
|
@ -1549,21 +1549,21 @@ public:
|
|||
}
|
||||
|
||||
// Pure C# interfaces
|
||||
const String *pure_interfaces = typemapLookup(derived ? "csinterfaces_derived" : "csinterfaces", typemap_lookup_type, WARN_NONE);
|
||||
const String *pure_interfaces = typemapLookup(n, derived ? "csinterfaces_derived" : "csinterfaces", typemap_lookup_type, WARN_NONE);
|
||||
// Start writing the proxy class
|
||||
Printv(proxy_class_def, typemapLookup("csimports", typemap_lookup_type, WARN_NONE), // Import statements
|
||||
Printv(proxy_class_def, typemapLookup(n, "csimports", typemap_lookup_type, WARN_NONE), // Import statements
|
||||
"\n", NIL);
|
||||
|
||||
// Class attributes
|
||||
const String *csattributes = typemapLookup("csattributes", typemap_lookup_type, WARN_NONE);
|
||||
const String *csattributes = typemapLookup(n, "csattributes", typemap_lookup_type, WARN_NONE);
|
||||
if (csattributes && *Char(csattributes))
|
||||
Printf(proxy_class_def, "%s\n", csattributes);
|
||||
|
||||
Printv(proxy_class_def, typemapLookup("csclassmodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
|
||||
Printv(proxy_class_def, typemapLookup(n, "csclassmodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
|
||||
" $csclassname", // Class name and base class
|
||||
(*Char(wanted_base) || *Char(pure_interfaces)) ? " : " : "", wanted_base, (*Char(wanted_base) && *Char(pure_interfaces)) ? // Interfaces
|
||||
", " : "", pure_interfaces, " {", derived ? typemapLookup("csbody_derived", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF) : // main body of class
|
||||
typemapLookup("csbody", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class
|
||||
", " : "", pure_interfaces, " {", derived ? typemapLookup(n, "csbody_derived", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF) : // main body of class
|
||||
typemapLookup(n, "csbody", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class
|
||||
NIL);
|
||||
|
||||
// C++ destructor is wrapped by the Dispose method
|
||||
|
|
@ -1574,11 +1574,11 @@ public:
|
|||
String *destruct_methodname = NULL;
|
||||
String *destruct_methodmodifiers = NULL;
|
||||
if (derived) {
|
||||
tm = typemapLookup("csdestruct_derived", typemap_lookup_type, WARN_NONE, attributes);
|
||||
tm = typemapLookup(n, "csdestruct_derived", typemap_lookup_type, WARN_NONE, attributes);
|
||||
destruct_methodname = Getattr(attributes, "tmap:csdestruct_derived:methodname");
|
||||
destruct_methodmodifiers = Getattr(attributes, "tmap:csdestruct_derived:methodmodifiers");
|
||||
} else {
|
||||
tm = typemapLookup("csdestruct", typemap_lookup_type, WARN_NONE, attributes);
|
||||
tm = typemapLookup(n, "csdestruct", typemap_lookup_type, WARN_NONE, attributes);
|
||||
destruct_methodname = Getattr(attributes, "tmap:csdestruct:methodname");
|
||||
destruct_methodmodifiers = Getattr(attributes, "tmap:csdestruct:methodmodifiers");
|
||||
}
|
||||
|
|
@ -1595,7 +1595,7 @@ public:
|
|||
if (tm) {
|
||||
// Finalize method
|
||||
if (*Char(destructor_call)) {
|
||||
Printv(proxy_class_def, typemapLookup("csfinalize", typemap_lookup_type, WARN_NONE), NIL);
|
||||
Printv(proxy_class_def, typemapLookup(n, "csfinalize", typemap_lookup_type, WARN_NONE), NIL);
|
||||
}
|
||||
// Dispose method
|
||||
Printv(destruct, tm, NIL);
|
||||
|
|
@ -1690,7 +1690,7 @@ public:
|
|||
Delete(destruct);
|
||||
|
||||
// Emit extra user code
|
||||
Printv(proxy_class_def, typemapLookup("cscode", typemap_lookup_type, WARN_NONE), // extra C# code
|
||||
Printv(proxy_class_def, typemapLookup(n, "cscode", typemap_lookup_type, WARN_NONE), // extra C# code
|
||||
"\n", NIL);
|
||||
|
||||
// Substitute various strings into the above template
|
||||
|
|
@ -2355,7 +2355,7 @@ public:
|
|||
|
||||
/* Insert the csconstruct typemap, doing the replacement for $directorconnect, as needed */
|
||||
Hash *attributes = NewHash();
|
||||
String *construct_tm = Copy(typemapLookup("csconstruct", Getattr(n, "name"),
|
||||
String *construct_tm = Copy(typemapLookup(n, "csconstruct", Getattr(n, "name"),
|
||||
WARN_CSHARP_TYPEMAP_CSCONSTRUCT_UNDEF, attributes));
|
||||
if (construct_tm) {
|
||||
if (!feature_director) {
|
||||
|
|
@ -2972,6 +2972,10 @@ public:
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void emitTypeWrapperClass(String *classname, SwigType *type) {
|
||||
Node *n = NewHash();
|
||||
Setfile(n, input_file);
|
||||
Setline(n, line_number);
|
||||
|
||||
String *swigtype = NewString("");
|
||||
String *filen = NewStringf("%s%s.cs", SWIG_output_directory(), classname);
|
||||
File *f_swigtype = NewFile(filen, "w", SWIG_output_files());
|
||||
|
|
@ -2989,23 +2993,23 @@ public:
|
|||
addOpenNamespace(namespce, f_swigtype);
|
||||
|
||||
// Pure C# baseclass and interfaces
|
||||
const String *pure_baseclass = typemapLookup("csbase", type, WARN_NONE);
|
||||
const String *pure_interfaces = typemapLookup("csinterfaces", type, WARN_NONE);
|
||||
const String *pure_baseclass = typemapLookup(n, "csbase", type, WARN_NONE);
|
||||
const String *pure_interfaces = typemapLookup(n, "csinterfaces", type, WARN_NONE);
|
||||
|
||||
// Emit the class
|
||||
Printv(swigtype, typemapLookup("csimports", type, WARN_NONE), // Import statements
|
||||
Printv(swigtype, typemapLookup(n, "csimports", type, WARN_NONE), // Import statements
|
||||
"\n", NIL);
|
||||
|
||||
// Class attributes
|
||||
const String *csattributes = typemapLookup("csattributes", type, WARN_NONE);
|
||||
const String *csattributes = typemapLookup(n, "csattributes", type, WARN_NONE);
|
||||
if (csattributes && *Char(csattributes))
|
||||
Printf(swigtype, "%s\n", csattributes);
|
||||
|
||||
Printv(swigtype, typemapLookup("csclassmodifiers", type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
|
||||
Printv(swigtype, typemapLookup(n, "csclassmodifiers", type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers
|
||||
" $csclassname", // Class name and base class
|
||||
(*Char(pure_baseclass) || *Char(pure_interfaces)) ? " : " : "", pure_baseclass, ((*Char(pure_baseclass)) && *Char(pure_interfaces)) ? // Interfaces
|
||||
", " : "", pure_interfaces, " {", typemapLookup("csbody", type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class
|
||||
typemapLookup("cscode", type, WARN_NONE), // extra C# code
|
||||
", " : "", pure_interfaces, " {", typemapLookup(n, "csbody", type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class
|
||||
typemapLookup(n, "cscode", type, WARN_NONE), // extra C# code
|
||||
"}\n", NIL);
|
||||
|
||||
Replaceall(swigtype, "$csclassname", classname);
|
||||
|
|
@ -3019,29 +3023,34 @@ public:
|
|||
|
||||
Close(f_swigtype);
|
||||
Delete(swigtype);
|
||||
Delete(n);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* typemapLookup()
|
||||
* n - for input only and must contain info for Getfile(n) and Getline(n) to work
|
||||
* op - typemap method name
|
||||
* type - typemap type to lookup
|
||||
* warning - warning number to issue if no typemaps found
|
||||
* typemap_attributes - the typemap attributes are attached to this node and will
|
||||
* also be used for temporary storage if non null
|
||||
* return is never NULL, unlike Swig_typemap_lookup()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
const String *typemapLookup(const String *op, String *type, int warning, Node *typemap_attributes = NULL) {
|
||||
String *tm = NULL;
|
||||
const String *code = NULL;
|
||||
|
||||
if ((tm = Swig_typemap_search(op, type, NULL, NULL))) {
|
||||
code = Getattr(tm, "code");
|
||||
if (typemap_attributes)
|
||||
Swig_typemap_attach_kwargs(tm, op, typemap_attributes);
|
||||
}
|
||||
|
||||
if (!code) {
|
||||
code = empty_string;
|
||||
const String *typemapLookup(Node *n, const_String_or_char_ptr op, SwigType *type, int warning, Node *typemap_attributes = 0) {
|
||||
Node *node = !typemap_attributes ? NewHash() : typemap_attributes;
|
||||
Setattr(node, "type", type);
|
||||
Setfile(node, Getfile(n));
|
||||
Setline(node, Getline(n));
|
||||
const String *tm = Swig_typemap_lookup(op, node, "", 0);
|
||||
if (!tm) {
|
||||
tm = empty_string;
|
||||
if (warning != WARN_NONE)
|
||||
Swig_warning(warning, input_file, line_number, "No %s typemap defined for %s\n", op, type);
|
||||
Swig_warning(warning, Getfile(n), Getline(n), "No %s typemap defined for %s\n", op, SwigType_str(type, 0));
|
||||
}
|
||||
|
||||
return code ? code : empty_string;
|
||||
if (!typemap_attributes)
|
||||
Delete(node);
|
||||
return tm;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
@ -3820,7 +3829,7 @@ public:
|
|||
Node *disconn_attr = NewHash();
|
||||
String *disconn_methodname = NULL;
|
||||
|
||||
disconn_tm = typemapLookup("directordisconnect", full_classname, WARN_NONE, disconn_attr);
|
||||
disconn_tm = typemapLookup(n, "directordisconnect", full_classname, WARN_NONE, disconn_attr);
|
||||
disconn_methodname = Getattr(disconn_attr, "tmap:directordisconnect:methodname");
|
||||
|
||||
Printv(w->code, "}\n", NIL);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue