[vala] girparser: mark non-simpletype struct return values as nullable



commit 5fb5a7d39385e518dfa2d395f85509e276077f25
Author: Evan Nemerson <evan coeus-group com>
Date:   Mon Feb 18 03:55:01 2013 -0800

    girparser: mark non-simpletype struct return values as nullable
    
    Functions which return structs currently generate incorrect C code
    since valac thinks the struct is actually an out argument.  This patch
    will mark the return values of functions returning structs as nullable
    in order to prevent valac from adding extra arguments.

 vala/valagirparser.vala |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 2773397..f58345c 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -3308,6 +3308,31 @@ public class Vala.GirParser : CodeVisitor {
                                        }
                                }
                        }
+               } else {
+                       if (return_type is UnresolvedType && !return_type.nullable) {
+                               var st = resolve_symbol (node.parent, ((UnresolvedType) 
return_type).unresolved_symbol) as Struct;
+                               if (st != null) {
+                                       bool is_simple_type = false;
+                                       Struct? base_st = st;
+
+                                       while (base_st != null) {
+                                               if (base_st.is_simple_type ()) {
+                                                       is_simple_type = true;
+                                                       break;
+                                               }
+
+                                               if (base_st.base_type is UnresolvedType) {
+                                                       base_st = resolve_symbol (node.parent, 
((UnresolvedType) base_st.base_type).unresolved_symbol) as Struct;
+                                               } else {
+                                                       base_st = base_st.base_struct;
+                                               }
+                                       }
+
+                                       if (!is_simple_type) {
+                                               return_type.nullable = true;
+                                       }
+                               }
+                       }
                }
                if (parameters.size > 1) {
                        ParameterInfo last_param = parameters[parameters.size-1];


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]