mirror of https://github.com/swig/swig
Improved namespace validity checks for the nspace feature
This commit is contained in:
parent
71e639bd13
commit
54916f150e
|
@ -5,18 +5,18 @@
|
|||
%feature("flatnested"); // must have in order to see nspace warnings when using Python as nested classes are otherwise simply ignored in Python
|
||||
|
||||
%nspace Space::OuterClass1;
|
||||
%nspacemove(BadSpace1) Space::OuterClass1::InnerClass1;
|
||||
%nspacemove(BadSpace1) Space::OuterClass1::InnerEnum1;
|
||||
%nspacemove(Bad::Space1) Space::OuterClass1::InnerClass1;
|
||||
%nspacemove(Bad::Space1) Space::OuterClass1::InnerEnum1;
|
||||
|
||||
%nspace Space::OuterClass2;
|
||||
%nonspace Space::OuterClass2::InnerClass2;
|
||||
%nonspace Space::OuterClass2::InnerEnum2;
|
||||
|
||||
%nspacemove(NewSpace3) Space::OuterClass3;
|
||||
%nspacemove(BadSpace3) Space::OuterClass3::InnerClass3;
|
||||
%nspacemove(BadSpace3) Space::OuterClass3::InnerEnum3;
|
||||
%nspacemove(Bad::Space3) Space::OuterClass3::InnerClass3;
|
||||
%nspacemove(Bad::Space3) Space::OuterClass3::InnerEnum3;
|
||||
|
||||
%nspacemove(NewSpace4) Space::OuterClass4;
|
||||
%nspacemove(NewSpace4::NewSubSpace4) Space::OuterClass4;
|
||||
%nonspace Space::OuterClass4::InnerClass4;
|
||||
%nonspace Space::OuterClass4::InnerEnum4;
|
||||
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
cpp_nspacemove.i:37: Warning 406: Ignoring nspace setting (BadSpace1) for 'Space::OuterClass1::InnerClass1',
|
||||
cpp_nspacemove.i:37: Warning 406: Ignoring nspace setting (Bad::Space1) for 'Space::OuterClass1::InnerClass1',
|
||||
cpp_nspacemove.i:36: Warning 406: as it conflicts with the nspace setting (Space) for outer class 'Space::OuterClass1'.
|
||||
cpp_nspacemove.i:40: Warning 406: Ignoring nspace setting (BadSpace1) for 'Space::OuterClass1::InnerEnum1',
|
||||
cpp_nspacemove.i:40: Warning 406: Ignoring nspace setting (Bad::Space1) for 'Space::OuterClass1::InnerEnum1',
|
||||
cpp_nspacemove.i:36: Warning 406: as it conflicts with the nspace setting (Space) for outer class 'Space::OuterClass1'.
|
||||
cpp_nspacemove.i:44: Warning 406: Ignoring nspace setting (0) for 'Space::OuterClass2::InnerClass2',
|
||||
cpp_nspacemove.i:43: Warning 406: as it conflicts with the nspace setting (Space) for outer class 'Space::OuterClass2'.
|
||||
cpp_nspacemove.i:47: Warning 406: Ignoring nspace setting (0) for 'Space::OuterClass2::InnerEnum2',
|
||||
cpp_nspacemove.i:43: Warning 406: as it conflicts with the nspace setting (Space) for outer class 'Space::OuterClass2'.
|
||||
cpp_nspacemove.i:51: Warning 406: Ignoring nspace setting (BadSpace3) for 'Space::OuterClass3::InnerClass3',
|
||||
cpp_nspacemove.i:51: Warning 406: Ignoring nspace setting (Bad::Space3) for 'Space::OuterClass3::InnerClass3',
|
||||
cpp_nspacemove.i:50: Warning 406: as it conflicts with the nspace setting (NewSpace3) for outer class 'Space::OuterClass3'.
|
||||
cpp_nspacemove.i:54: Warning 406: Ignoring nspace setting (BadSpace3) for 'Space::OuterClass3::InnerEnum3',
|
||||
cpp_nspacemove.i:54: Warning 406: Ignoring nspace setting (Bad::Space3) for 'Space::OuterClass3::InnerEnum3',
|
||||
cpp_nspacemove.i:50: Warning 406: as it conflicts with the nspace setting (NewSpace3) for outer class 'Space::OuterClass3'.
|
||||
cpp_nspacemove.i:58: Warning 406: Ignoring nspace setting (0) for 'Space::OuterClass4::InnerClass4',
|
||||
cpp_nspacemove.i:57: Warning 406: as it conflicts with the nspace setting (NewSpace4) for outer class 'Space::OuterClass4'.
|
||||
cpp_nspacemove.i:57: Warning 406: as it conflicts with the nspace setting (NewSpace4::NewSubSpace4) for outer class 'Space::OuterClass4'.
|
||||
cpp_nspacemove.i:61: Warning 406: Ignoring nspace setting (0) for 'Space::OuterClass4::InnerEnum4',
|
||||
cpp_nspacemove.i:57: Warning 406: as it conflicts with the nspace setting (NewSpace4) for outer class 'Space::OuterClass4'.
|
||||
cpp_nspacemove.i:57: Warning 406: as it conflicts with the nspace setting (NewSpace4::NewSubSpace4) for outer class 'Space::OuterClass4'.
|
||||
cpp_nspacemove.i:65: Warning 406: Ignoring nspace setting (NewSpace5) for 'Space::OuterClass5::InnerClass5',
|
||||
cpp_nspacemove.i:64: Warning 406: as it conflicts with the nspace setting () for outer class 'Space::OuterClass5'.
|
||||
cpp_nspacemove.i:68: Warning 406: Ignoring nspace setting (NewSpace5) for 'Space::OuterClass5::InnerEnum5',
|
||||
|
|
|
@ -27,3 +27,31 @@ namespace AA {
|
|||
struct Good3 {};
|
||||
}
|
||||
}
|
||||
|
||||
// Good names (containing whitespace) for %nspacemove
|
||||
%nspacemove( Good :: Spaces ) AA::BB::Good4;
|
||||
%nspacemove( Good :: Spaces ) AA::BB::Good5;
|
||||
|
||||
// Bad names (single colons) for %nspacemove
|
||||
%nspacemove(:) AA::BB::Bad7;
|
||||
%nspacemove(X: :Y) AA::BB::Bad8;
|
||||
%nspacemove(X:Y) AA::BB::Bad9;
|
||||
|
||||
// Bad names (bad double colons) for %nspacemove
|
||||
%nspacemove(X::Y::) AA::BB::Bad10;
|
||||
%nspacemove(X:::Y) AA::BB::Bad11;
|
||||
%nspacemove(X::::Y) AA::BB::Bad12;
|
||||
|
||||
namespace AA {
|
||||
namespace BB {
|
||||
struct Good4 {};
|
||||
struct Good5 {};
|
||||
|
||||
struct Bad7 {};
|
||||
struct Bad8 {};
|
||||
struct Bad9 {};
|
||||
struct Bad10 {};
|
||||
struct Bad11 {};
|
||||
struct Bad12 {};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,3 +4,9 @@ cpp_nspacemove_bad.i:20: Error: 'abc.def' is not a valid identifier for nspace.
|
|||
cpp_nspacemove_bad.i:21: Error: '0gh::ij' is not a valid identifier for nspace.
|
||||
cpp_nspacemove_bad.i:22: Error: 'kl::1mn' is not a valid identifier for nspace.
|
||||
cpp_nspacemove_bad.i:23: Error: 'kl::mn<int>' is not a valid identifier for nspace.
|
||||
cpp_nspacemove_bad.i:50: Error: ':' is not a valid identifier for nspace.
|
||||
cpp_nspacemove_bad.i:51: Error: 'X: :Y' is not a valid identifier for nspace.
|
||||
cpp_nspacemove_bad.i:52: Error: 'X:Y' is not a valid identifier for nspace.
|
||||
cpp_nspacemove_bad.i:53: Error: 'X::Y::' is not a valid identifier for nspace.
|
||||
cpp_nspacemove_bad.i:54: Error: 'X:::Y' is not a valid identifier for nspace.
|
||||
cpp_nspacemove_bad.i:55: Error: 'X::::Y' is not a valid identifier for nspace.
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
%nspacemove(Additional) ::GlobalClass;
|
||||
|
||||
// move enum
|
||||
%nspacemove(Euter::Extra::Inner1) Outer::Inner1::Channel;
|
||||
%nspacemove(Outer::Enner2) Outer::Inner2::Channel;
|
||||
%nspacemove(Euter :: Extra :: Inner1) Outer::Inner1::Channel;
|
||||
%nspacemove(Outer:: Enner2) Outer::Inner2::Channel;
|
||||
%nspacemove(More) ::GlobalEnum;
|
||||
|
||||
%include "nspace.i"
|
||||
|
|
|
@ -352,8 +352,23 @@ class TypePass:private Dispatcher {
|
|||
String *nspace_setting(Node *n, Node *outer) {
|
||||
String *nssymname_new = nssymname;
|
||||
String *feature_nspace = GetFlagAttr(n, "feature:nspace");
|
||||
int valid = feature_nspace ? Equal(feature_nspace, "1") || Swig_scopename_isvalid(feature_nspace) : 1;
|
||||
String *nspace = Copy(feature_nspace);
|
||||
|
||||
// Check validity - single colons not allowed
|
||||
const char *c = Char(feature_nspace);
|
||||
int valid = 1;
|
||||
while(c && *c) {
|
||||
if (*(c++) == ':' && *(c++) != ':') {
|
||||
valid = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove whitespace
|
||||
Replaceall(nspace, " ", "");
|
||||
Replaceall(nspace, "\t", "");
|
||||
|
||||
valid = valid && (feature_nspace ? Equal(feature_nspace, "1") || Swig_scopename_isvalid(nspace) : 1);
|
||||
Replaceall(nspace, "::", ".");
|
||||
if (valid) {
|
||||
if (outer) {
|
||||
|
@ -374,7 +389,7 @@ class TypePass:private Dispatcher {
|
|||
String *outer_nspace_feature = Copy(outer_nspace);
|
||||
Replaceall(outer_nspace_feature, ".", "::");
|
||||
Swig_warning(WARN_TYPE_NSPACE_SETTING, Getfile(n), Getline(n), "Ignoring nspace setting (%s) for '%s',\n", nspace_attribute, Swig_name_decl(n));
|
||||
Swig_warning(WARN_TYPE_NSPACE_SETTING, Getfile(outer), Getline(outer), "as it conflicts with the nspace setting (%s) for outer class '%s'.\n", outer_nspace, Swig_name_decl(outer));
|
||||
Swig_warning(WARN_TYPE_NSPACE_SETTING, Getfile(outer), Getline(outer), "as it conflicts with the nspace setting (%s) for outer class '%s'.\n", outer_nspace_feature, Swig_name_decl(outer));
|
||||
}
|
||||
Setattr(n, "sym:nspace", outer_nspace);
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue