Output declarations of all types before the functions declarations
This fixes compilation of the generated code when a function uses a forward declared type as was the case in e.g. std_vector example.
This commit is contained in:
parent
795e3adb0d
commit
62230758e4
1 changed files with 23 additions and 12 deletions
|
|
@ -101,6 +101,7 @@ class C:public Language {
|
||||||
File *f_runtime;
|
File *f_runtime;
|
||||||
File *f_header;
|
File *f_header;
|
||||||
File *f_wrappers;
|
File *f_wrappers;
|
||||||
|
File *f_wrappers_types;
|
||||||
File *f_wrappers_decl;
|
File *f_wrappers_decl;
|
||||||
File *f_init;
|
File *f_init;
|
||||||
|
|
||||||
|
|
@ -409,9 +410,6 @@ public:
|
||||||
Swig_register_filebyname("proxy_header", f_wrappers_h);
|
Swig_register_filebyname("proxy_header", f_wrappers_h);
|
||||||
|
|
||||||
{
|
{
|
||||||
// Create a string to which the wrapper declarations will be appended one by one.
|
|
||||||
f_wrappers_decl = NewString("");
|
|
||||||
|
|
||||||
String* const include_guard_name = NewStringf("SWIG_%s_WRAP_H_", Char(module));
|
String* const include_guard_name = NewStringf("SWIG_%s_WRAP_H_", Char(module));
|
||||||
String* const include_guard_begin = NewStringf(
|
String* const include_guard_begin = NewStringf(
|
||||||
"#ifndef %s\n"
|
"#ifndef %s\n"
|
||||||
|
|
@ -428,10 +426,17 @@ public:
|
||||||
begin_end_output_guard
|
begin_end_output_guard
|
||||||
include_guard_wrappers_h(f_wrappers_h, include_guard_begin, include_guard_end);
|
include_guard_wrappers_h(f_wrappers_h, include_guard_begin, include_guard_end);
|
||||||
|
|
||||||
|
// All the struct types used by the functions go to f_wrappers_types so that they're certain to be defined before they're used by any functions. All the
|
||||||
|
// functions declarations go directly to f_wrappers_decl and f_wrappers_h_body combines both of them.
|
||||||
|
String* const f_wrappers_h_body = NewString("");
|
||||||
|
f_wrappers_types = NewString("");
|
||||||
|
f_wrappers_decl = NewString("");
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
cplusplus_output_guard
|
cplusplus_output_guard
|
||||||
cplusplus_guard_wrappers(f_wrappers),
|
cplusplus_guard_wrappers(f_wrappers),
|
||||||
cplusplus_guard_wrappers_h(f_wrappers_decl);
|
cplusplus_guard_wrappers_h(f_wrappers_h_body);
|
||||||
|
|
||||||
if (except_flag) {
|
if (except_flag) {
|
||||||
start_create_object();
|
start_create_object();
|
||||||
|
|
@ -445,10 +450,16 @@ public:
|
||||||
Append(f_header, finish_create_object());
|
Append(f_header, finish_create_object());
|
||||||
Append(f_header, finish_destroy_object());
|
Append(f_header, finish_destroy_object());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dump(f_wrappers_types, f_wrappers_h_body);
|
||||||
|
Delete(f_wrappers_types);
|
||||||
|
|
||||||
|
Dump(f_wrappers_decl, f_wrappers_h_body);
|
||||||
|
Delete(f_wrappers_decl);
|
||||||
} // close extern "C" guards
|
} // close extern "C" guards
|
||||||
|
|
||||||
Dump(f_wrappers_decl, f_wrappers_h);
|
Dump(f_wrappers_h_body, f_wrappers_h);
|
||||||
Delete(f_wrappers_decl);
|
Delete(f_wrappers_h_body);
|
||||||
} // close wrapper header guard
|
} // close wrapper header guard
|
||||||
|
|
||||||
// write all to the file
|
// write all to the file
|
||||||
|
|
@ -1312,7 +1323,7 @@ ready:
|
||||||
if ((Cmp(kind, "variable") == 0) || (Cmp(kind, "function") == 0)) {
|
if ((Cmp(kind, "variable") == 0) || (Cmp(kind, "function") == 0)) {
|
||||||
String* type = NewString("");
|
String* type = NewString("");
|
||||||
Printv(type, Getattr(node, "decl"), Getattr(node, "type"), NIL);
|
Printv(type, Getattr(node, "decl"), Getattr(node, "type"), NIL);
|
||||||
Printv(f_wrappers_decl, " ", SwigType_str(type, 0), " ", Getattr(node, "name"), ";\n", NIL);
|
Printv(f_wrappers_types, " ", SwigType_str(type, 0), " ", Getattr(node, "name"), ";\n", NIL);
|
||||||
Delete(type);
|
Delete(type);
|
||||||
}
|
}
|
||||||
// WARNING: proxy delaration can be different than original code
|
// WARNING: proxy delaration can be different than original code
|
||||||
|
|
@ -1376,7 +1387,7 @@ ready:
|
||||||
}
|
}
|
||||||
|
|
||||||
// declare type for specific class in the proxy header
|
// declare type for specific class in the proxy header
|
||||||
Printv(f_wrappers_decl, "\ntypedef struct SwigObj_", name, " ", name, ";\n\n", NIL);
|
Printv(f_wrappers_types, "typedef struct SwigObj_", name, " ", name, ";\n\n", NIL);
|
||||||
|
|
||||||
Delete(sobj);
|
Delete(sobj);
|
||||||
Delete(name);
|
Delete(name);
|
||||||
|
|
@ -1387,15 +1398,15 @@ ready:
|
||||||
String *storage = Getattr(n, "storage");
|
String *storage = Getattr(n, "storage");
|
||||||
int usetd = storage && Cmp(storage, "typedef") == 0;
|
int usetd = storage && Cmp(storage, "typedef") == 0;
|
||||||
if (usetd)
|
if (usetd)
|
||||||
Append(f_wrappers_decl, "typedef struct {\n");
|
Append(f_wrappers_types, "typedef struct {\n");
|
||||||
else
|
else
|
||||||
Printv(f_wrappers_decl, "struct ", name, " {\n", NIL);
|
Printv(f_wrappers_types, "struct ", name, " {\n", NIL);
|
||||||
Node *node = firstChild(n);
|
Node *node = firstChild(n);
|
||||||
emit_c_struct_def(node);
|
emit_c_struct_def(node);
|
||||||
if (usetd)
|
if (usetd)
|
||||||
Printv(f_wrappers_decl, "} ", name, ";\n\n", NIL);
|
Printv(f_wrappers_types, "} ", name, ";\n\n", NIL);
|
||||||
else
|
else
|
||||||
Append(f_wrappers_decl, "};\n\n");
|
Append(f_wrappers_types, "};\n\n");
|
||||||
|
|
||||||
Delete(sobj);
|
Delete(sobj);
|
||||||
Delete(name);
|
Delete(name);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue