The default is now to not generate an additional method declaration when a method is declared with an extern. Use -addextern option to recreate original behaviour (new commandline option), with -noextern now redundant.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7318 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2005-06-27 20:39:20 +00:00
commit 11dc59b22e
3 changed files with 41 additions and 33 deletions

View file

@ -62,7 +62,7 @@ int SmartPointer = 0;
extern int GenerateDefault;
extern int ForceExtern;
extern int NoExtern;
extern int AddExtern;
/* import modes */
@ -799,40 +799,43 @@ int Language::cDeclaration(Node *n) {
/* Transform the node into a 'function' node and emit */
if (!CurrentClass) {
f_header = Swig_filebyname("header");
/*
in C++ mode we can't emit a extern declaration derived from
the definition, for example, if we have
--- foo.c ---
int foo(int bar) {
}
--- foo.c ---
if (AddExtern) {
if (f_header) {
if ((Cmp(storage,"extern") == 0) || (ForceExtern && !storage)) {
/* we don't need the 'extern' part in the C/C++ declaration,
and it produces some problems when namespace and SUN
Studio is used.
we could be tempted to declare
extern int foo(int bar);
but the real declaration could be:
extern int foo(int bar = 1);
hence, the user MUST provide the declaration, and swig
shouldn't attempt to deduce it.
*/
if (f_header) {
int extern_c = Cmp(storage,"externc") == 0;
int need_extern = CPlusPlus ? extern_c : 1;
if (!NoExtern && need_extern) {
if ((storage && Strstr(storage,"extern")) || (ForceExtern && !storage)) {
Printf(f_header,"extern %s", SwigType_str(ty,name));
In fact generating extern declarations is quite error prone and is
no longer the default. Getting it right seems impossible with namespaces
and default arguments and when a method is declared with the various Windows
calling conventions - SWIG doesn't understand Windows (non standard) calling
conventions in the first place, so can't regenerate them.
*/
String *str = SwigType_str(ty,name);
Printf(f_header,"extern ", str);
if (extern_c) {
/* here 'extern "C"' is needed */
Printf(f_header, "\"C\" ");
}
Printf(f_header,"%s", str);
Delete(str);
{
DOH *t = Getattr(n,"throws");
if (t) {
Printf(f_header," throw(");
while (t) {
Printf(f_header,"%s", Getattr(t,"type"));
t = nextSibling(t);
if (t) Printf(f_header,",");
}
Printf(f_header,")");
}
}
Printf(f_header,";\n");
} else if (Cmp(storage,"externc") == 0) {
/* here 'extern "C"' is needed */
String *str = SwigType_str(ty,name);
Printf(f_header, "extern \"C\" %s;\n", str);
Delete(str);
}
}
}
@ -858,7 +861,7 @@ int Language::cDeclaration(Node *n) {
if (!CurrentClass) {
if ((Cmp(storage,"extern") == 0) || ForceExtern) {
f_header = Swig_filebyname("header");
if (!NoExtern) {
if (AddExtern) {
if (f_header) {
String *str = SwigType_str(ty,name);
Printf(f_header,"extern %s;\n", str);