Improved converting return values (avoiding using assignment and default constructors).
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10746 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
948c474a0d
commit
83d60a1d36
2 changed files with 40 additions and 19 deletions
|
|
@ -34,7 +34,6 @@ class C:public Language {
|
||||||
|
|
||||||
bool proxy_flag;
|
bool proxy_flag;
|
||||||
bool runtime_flag;
|
bool runtime_flag;
|
||||||
bool typecheck_flag;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -49,8 +48,7 @@ public:
|
||||||
create_object(0),
|
create_object(0),
|
||||||
destroy_object(0),
|
destroy_object(0),
|
||||||
proxy_flag(true),
|
proxy_flag(true),
|
||||||
runtime_flag(true),
|
runtime_flag(true) {
|
||||||
typecheck_flag(false) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------
|
/* ------------------------------------------------------------
|
||||||
|
|
@ -325,8 +323,6 @@ public:
|
||||||
Delete(result);
|
Delete(result);
|
||||||
result = NewString("");
|
result = NewString("");
|
||||||
|
|
||||||
/*Printf(stderr, "MANGLING TYPE: %s\n", type_arg);*/
|
|
||||||
|
|
||||||
SwigType *type = Copy(type_arg);
|
SwigType *type = Copy(type_arg);
|
||||||
|
|
||||||
if (SwigType_ismemberpointer(type)) {
|
if (SwigType_ismemberpointer(type)) {
|
||||||
|
|
@ -364,8 +360,6 @@ public:
|
||||||
Printf(result, "%s", Char(SwigType_base(type)));
|
Printf(result, "%s", Char(SwigType_base(type)));
|
||||||
|
|
||||||
ready:
|
ready:
|
||||||
/*Printf(stderr, " RESULT: %s\n", result);*/
|
|
||||||
|
|
||||||
if (prefix)
|
if (prefix)
|
||||||
Delete(prefix);
|
Delete(prefix);
|
||||||
if (type)
|
if (type)
|
||||||
|
|
@ -459,6 +453,7 @@ ready:
|
||||||
else {
|
else {
|
||||||
// C++ function wrapper
|
// C++ function wrapper
|
||||||
|
|
||||||
|
// mark the first parameter as object-struct
|
||||||
if ((Cmp(Getattr(n, "storage"), "static") != 0) &&
|
if ((Cmp(Getattr(n, "storage"), "static") != 0) &&
|
||||||
(Cmp(Getattr(n, "ismember"), "1") == 0) &&
|
(Cmp(Getattr(n, "ismember"), "1") == 0) &&
|
||||||
(Cmp(nodeType(n), "constructor") != 0)) {
|
(Cmp(nodeType(n), "constructor") != 0)) {
|
||||||
|
|
@ -506,23 +501,40 @@ ready:
|
||||||
}
|
}
|
||||||
|
|
||||||
// add variable for holding result of original function
|
// add variable for holding result of original function
|
||||||
|
bool return_object = false;
|
||||||
if (!is_void_return && (Cmp(Getattr(n, "c:objstruct"), "1") != 0)) {
|
if (!is_void_return && (Cmp(Getattr(n, "c:objstruct"), "1") != 0)) {
|
||||||
if (SwigType_isconst(type))
|
if (SwigType_isconst(type))
|
||||||
SwigType_del_qualifier(type);
|
SwigType_del_qualifier(type);
|
||||||
SwigType *return_var_type;
|
SwigType *return_var_type;
|
||||||
|
|
||||||
if (SwigType_isenum(type))
|
SwigType *tdtype = SwigType_typedef_resolve(type);
|
||||||
|
if (tdtype)
|
||||||
|
type = tdtype;
|
||||||
|
|
||||||
|
if (SwigType_isenum(type)) {
|
||||||
Wrapper_add_localv(wrapper, "cppresult", "int", "cppresult", NIL);
|
Wrapper_add_localv(wrapper, "cppresult", "int", "cppresult", NIL);
|
||||||
else {
|
}
|
||||||
if (SwigType_isreference(type))
|
else if (SwigType_isbuiltin(SwigType_base(type))) {
|
||||||
return_var_type = SwigType_base(type);
|
// type is built-in (int, char, double, etc.)
|
||||||
else if (SwigType_isarray(type))
|
if (SwigType_isreference(type) || SwigType_isarray(type))
|
||||||
return_var_type = SwigType_add_pointer(SwigType_base(type));
|
return_var_type = SwigType_add_pointer(SwigType_base(type));
|
||||||
else
|
else
|
||||||
return_var_type = type;
|
return_var_type = type;
|
||||||
|
|
||||||
Wrapper_add_localv(wrapper, "cppresult", SwigType_str(return_var_type, 0), "cppresult", NIL);
|
Wrapper_add_localv(wrapper, "cppresult", SwigType_str(return_var_type, 0), "cppresult", NIL);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// type is class
|
||||||
|
if (SwigType_ispointer(type))
|
||||||
|
return_var_type = type;
|
||||||
|
else if (SwigType_isreference(type) || SwigType_isarray(type))
|
||||||
|
return_var_type = SwigType_add_pointer(SwigType_base(type));
|
||||||
|
else
|
||||||
|
return_var_type = SwigType_add_pointer(type);
|
||||||
|
|
||||||
|
Wrapper_add_localv(wrapper, "cppresult", SwigType_str(return_var_type, 0), "cppresult", NIL);
|
||||||
|
return_object = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure lnames are set
|
// make sure lnames are set
|
||||||
|
|
@ -624,7 +636,9 @@ ready:
|
||||||
|
|
||||||
// emit action code
|
// emit action code
|
||||||
String *action = emit_action(n);
|
String *action = emit_action(n);
|
||||||
if (Getattr(n, "throws") || (Cmp(Getattr(n, "feature:except"), "0") != 0)) {
|
String *except = Getattr(n, "feature:except");
|
||||||
|
if (Getattr(n, "throws") || except) {
|
||||||
|
if (!except || (Cmp(except, "0") != 0))
|
||||||
Printf(action, "if (SWIG_exc.handled) {\nSWIG_rt_stack_pop();\nlongjmp(SWIG_rt_env, 1);\n}\n");
|
Printf(action, "if (SWIG_exc.handled) {\nSWIG_rt_stack_pop();\nlongjmp(SWIG_rt_env, 1);\n}\n");
|
||||||
}
|
}
|
||||||
if (Cmp(nodeType(n), "constructor") != 0)
|
if (Cmp(nodeType(n), "constructor") != 0)
|
||||||
|
|
@ -637,13 +651,14 @@ ready:
|
||||||
//Printf(ref_cast, "(%s*)", SwigType_str(SwigType_base(type), 0));
|
//Printf(ref_cast, "(%s*)", SwigType_str(SwigType_base(type), 0));
|
||||||
Printf(ref_cast, "*");
|
Printf(ref_cast, "*");
|
||||||
}
|
}
|
||||||
else
|
|
||||||
Printf(ref_cast, "&");
|
|
||||||
Replaceall(action, "$mod", ref_cast);
|
Replaceall(action, "$mod", ref_cast);
|
||||||
Delete(ref_cast);
|
Delete(ref_cast);
|
||||||
}
|
}
|
||||||
else if (SwigType_isenum(type))
|
else if (SwigType_isenum(type))
|
||||||
Replaceall(action, "$mod", "(int)");
|
Replaceall(action, "$mod", "(int)");
|
||||||
|
else if (return_object && Getattr(n, "c:retval")) {
|
||||||
|
Replaceall(action, "$mod", "&");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
Replaceall(action, "$mod", "");
|
Replaceall(action, "$mod", "");
|
||||||
|
|
||||||
|
|
@ -847,6 +862,9 @@ ready:
|
||||||
* --------------------------------------------------------------------- */
|
* --------------------------------------------------------------------- */
|
||||||
|
|
||||||
virtual int memberfunctionHandler(Node *n) {
|
virtual int memberfunctionHandler(Node *n) {
|
||||||
|
SwigType *type = Getattr(n, "type");
|
||||||
|
if (!SwigType_ispointer(type) && !SwigType_ispointer(SwigType_typedef_resolve(type)))
|
||||||
|
Setattr(n, "c:retval", "1");
|
||||||
return Language::memberfunctionHandler(n);
|
return Language::memberfunctionHandler(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1151,6 +1169,8 @@ ready:
|
||||||
virtual int enumDeclaration(Node *n) {
|
virtual int enumDeclaration(Node *n) {
|
||||||
if (!proxy_flag)
|
if (!proxy_flag)
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
|
if (Cmp(Getattr(n, "access"), "public") != 0)
|
||||||
|
return SWIG_OK;
|
||||||
String *newclassname = Getattr(Swig_methodclass(n), "sym:name");
|
String *newclassname = Getattr(Swig_methodclass(n), "sym:name");
|
||||||
String *name = Getattr(n, "sym:name");
|
String *name = Getattr(n, "sym:name");
|
||||||
String *code = NewString("");
|
String *code = NewString("");
|
||||||
|
|
@ -1175,7 +1195,6 @@ ready:
|
||||||
Setattr(entry, "sym:symtab", symtab);
|
Setattr(entry, "sym:symtab", symtab);
|
||||||
Swig_symbol_add(name, entry);
|
Swig_symbol_add(name, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newclassname) {
|
if (newclassname) {
|
||||||
if (symtab) {
|
if (symtab) {
|
||||||
Node *node = Swig_symbol_clookup(name, symtab);
|
Node *node = Swig_symbol_clookup(name, symtab);
|
||||||
|
|
@ -1207,6 +1226,8 @@ ready:
|
||||||
|
|
||||||
virtual int enumvalueDeclaration(Node *n) {
|
virtual int enumvalueDeclaration(Node *n) {
|
||||||
String *name = Getattr(n, "sym:name");
|
String *name = Getattr(n, "sym:name");
|
||||||
|
if (Cmp(Getattr(n, "access"), "public") != 0)
|
||||||
|
return SWIG_OK;
|
||||||
String *enumvalue = Getattr(n, "enumvalue");
|
String *enumvalue = Getattr(n, "enumvalue");
|
||||||
String *init = 0;
|
String *init = 0;
|
||||||
if (enumvalue) {
|
if (enumvalue) {
|
||||||
|
|
|
||||||
|
|
@ -271,7 +271,7 @@ int SwigType_issimple(SwigType *t) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int SwigType_isbuiltin(SwigType *t) {
|
int SwigType_isbuiltin(SwigType *t) {
|
||||||
const char* builtins[] = { "void", "short", "int", "long", "char", "float", "double", 0 };
|
const char* builtins[] = { "void", "short", "int", "long", "char", "float", "double", "bool", 0 };
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char *c = Char(t);
|
char *c = Char(t);
|
||||||
if (!t)
|
if (!t)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue