[vala] Fix usage of possibly unassigned out parameters



commit 7d1332dd66d7b12da503f2aa9239753aaa5a1719
Author: Luca Bruno <lucabru src gnome org>
Date:   Wed Jul 13 11:19:56 2011 +0200

    Fix usage of possibly unassigned out parameters

 codegen/valaccodebasemodule.vala |    4 +-
 codegen/valagdbusmodule.vala     |    1 +
 codegen/valagvariantmodule.vala  |    3 ++
 vala/valageniescanner.vala       |   65 +++++++++-----------------------------
 vala/valagirparser.vala          |    1 +
 vala/valamarkupreader.vala       |   10 ++---
 vala/valamethod.vala             |    1 +
 vala/valascanner.vala            |   33 +++++--------------
 vapigen/valagidlparser.vala      |   11 ++----
 9 files changed, 39 insertions(+), 90 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 5460b5e..d9b3800 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4501,11 +4501,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 	}
 
 	public virtual CCodeExpression? deserialize_expression (DataType type, CCodeExpression variant_expr, CCodeExpression? expr, CCodeExpression? error_expr = null, out bool may_fail = null) {
-		return null;
+		assert_not_reached ();
 	}
 
 	public virtual CCodeExpression? serialize_expression (DataType type, CCodeExpression expr) {
-		return null;
+		assert_not_reached ();
 	}
 
 	public override void visit_cast_expression (CastExpression expr) {
diff --git a/codegen/valagdbusmodule.vala b/codegen/valagdbusmodule.vala
index 1708d03..d82b573 100644
--- a/codegen/valagdbusmodule.vala
+++ b/codegen/valagdbusmodule.vala
@@ -215,6 +215,7 @@ public class Vala.GDBusModule : GVariantModule {
 			ccode.add_expression (get_fd);
 
 			ccode.add_assignment (target_expr, stream);
+			may_fail = false;
 		} else {
 			read_expression (type, iter_expr, target_expr, sym, error_expr, out may_fail);
 		}
diff --git a/codegen/valagvariantmodule.vala b/codegen/valagvariantmodule.vala
index 91b614a..f7d4d0c 100644
--- a/codegen/valagvariantmodule.vala
+++ b/codegen/valagvariantmodule.vala
@@ -79,6 +79,7 @@ public class Vala.GVariantModule : GAsyncModule {
 				return true;
 			}
 		}
+		basic_type = BasicTypeInfo ();
 		return false;
 	}
 
@@ -458,6 +459,7 @@ public class Vala.GVariantModule : GAsyncModule {
 	public override CCodeExpression? deserialize_expression (DataType type, CCodeExpression variant_expr, CCodeExpression? expr, CCodeExpression? error_expr = null, out bool may_fail = null) {
 		BasicTypeInfo basic_type;
 		CCodeExpression result = null;
+		may_fail = false;
 		if (is_string_marshalled_enum (type.data_type)) {
 			get_basic_type_info ("s", out basic_type);
 			result = deserialize_basic (basic_type, variant_expr, true);
@@ -502,6 +504,7 @@ public class Vala.GVariantModule : GAsyncModule {
 		if (sym != null && get_dbus_signature (sym) != null) {
 			// raw GVariant
 			ccode.add_assignment (target_expr, iter_call);
+			may_fail = false;
 			return;
 		}
 
diff --git a/vala/valageniescanner.vala b/vala/valageniescanner.vala
index c853827..54a557a 100644
--- a/vala/valageniescanner.vala
+++ b/vala/valageniescanner.vala
@@ -113,9 +113,7 @@ public class Vala.Genie.Scanner {
 	public TokenType read_regex_token (out SourceLocation token_begin, out SourceLocation token_end) {
 		TokenType type;
 		char* begin = current;
-		token_begin.pos = begin;
-		token_begin.line = line;
-		token_begin.column = column;
+		token_begin = SourceLocation (begin, line, column);
 
 		int token_length_in_chars = -1;
 
@@ -267,9 +265,7 @@ public class Vala.Genie.Scanner {
 			column += token_length_in_chars;
 		}
 
-		token_end.pos = current;
-		token_end.line = line;
-		token_end.column = column - 1;
+		token_end = SourceLocation (current, line, column - 1);
 
 		return type;
 	}
@@ -661,9 +657,7 @@ public class Vala.Genie.Scanner {
 	public TokenType read_template_token (out SourceLocation token_begin, out SourceLocation token_end) {
 		TokenType type;
 		char* begin = current;
-		token_begin.pos = begin;
-		token_begin.line = line;
-		token_begin.column = column;
+		token_begin = SourceLocation (begin, line, column);
 
 		int token_length_in_chars = -1;
 
@@ -767,9 +761,7 @@ public class Vala.Genie.Scanner {
 			column += token_length_in_chars;
 		}
 
-		token_end.pos = current;
-		token_end.line = line;
-		token_end.column = column - 1;
+		token_end = SourceLocation (current, line, column - 1);
 
 		return type;
 	}
@@ -783,13 +775,8 @@ public class Vala.Genie.Scanner {
 		} else if (in_template_part ()) {
 			state_stack.length--;
 
-			token_begin.pos = current;
-			token_begin.line = line;
-			token_begin.column = column;
-
-			token_end.pos = current;
-			token_end.line = line;
-			token_end.column = column - 1;
+			token_begin = SourceLocation (current, line, column);
+			token_end = SourceLocation (current, line, column - 1);
 
 			return TokenType.COMMA;
 		} else if (in_regex_literal ()) {
@@ -804,14 +791,8 @@ public class Vala.Genie.Scanner {
 			pending_dedents--;
 			indent_level--;
 
-
-			token_begin.pos = current;
-			token_begin.line = line;
-			token_begin.column = column;
-
-			token_end.pos = current;
-			token_end.line = line;
-			token_end.column = column;
+			token_begin = SourceLocation (current, line, column);
+			token_end = SourceLocation (current, line, column);
 
 			last_token = TokenType.DEDENT;
 
@@ -841,13 +822,8 @@ public class Vala.Genie.Scanner {
 
 		/* handle non-consecutive new line once parsing is underway - EOL */
 		if (newline () && parse_started && last_token != TokenType.EOL && last_token != TokenType.SEMICOLON) {
-			token_begin.pos = current;
-			token_begin.line = line;
-			token_begin.column = column;
-
-			token_end.pos = current;
-			token_end.line = line;
-			token_end.column = column;
+			token_begin = SourceLocation (current, line, column);
+			token_end = SourceLocation (current, line, column);
 
 			last_token = TokenType.EOL;
 
@@ -856,9 +832,7 @@ public class Vala.Genie.Scanner {
 
 
 		while (skip_newlines ()) {
-			token_begin.pos = current;
-			token_begin.line = line;
-			token_begin.column = column;
+			token_begin = SourceLocation (current, line, column);
 
 			current_indent_level = count_tabs ();
 
@@ -870,9 +844,7 @@ public class Vala.Genie.Scanner {
 			if (current_indent_level > indent_level) {
 				indent_level = current_indent_level;
 
-				token_end.pos = current;
-				token_end.line = line;
-				token_end.column = column;
+				token_end = SourceLocation (current, line, column);
 
 				last_token = TokenType.INDENT;
 
@@ -881,10 +853,7 @@ public class Vala.Genie.Scanner {
 				indent_level--;
 
 				pending_dedents = (indent_level - current_indent_level);
-
-				token_end.pos = current;
-				token_end.line = line;
-				token_end.column = column;
+				token_end = SourceLocation (current, line, column);
 
 				last_token = TokenType.DEDENT;
 
@@ -894,9 +863,7 @@ public class Vala.Genie.Scanner {
 
 		TokenType type;
 		char* begin = current;
-		token_begin.pos = begin;
-		token_begin.line = line;
-		token_begin.column = column;
+		token_begin = SourceLocation (begin, line, column);
 
 		int token_length_in_chars = -1;
 
@@ -1354,9 +1321,7 @@ public class Vala.Genie.Scanner {
 			column += token_length_in_chars;
 		}
 
-		token_end.pos = current;
-		token_end.line = line;
-		token_end.column = column - 1;
+		token_end = SourceLocation (current, line, column - 1);
 		last_token = type;
 
 		return type;
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 4980be8..5276c8f 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -1984,6 +1984,7 @@ public class Vala.GirParser : CodeVisitor {
 	DataType parse_type (out string? ctype = null, out int array_length_idx = null, bool transfer_elements = true, out bool no_array_length = null, out bool array_null_terminated = null) {
 		bool is_array = false;
 		string type_name = reader.get_attribute ("name");
+		ctype = null;
 
 		array_length_idx = -1;
 		no_array_length = true;
diff --git a/vala/valamarkupreader.vala b/vala/valamarkupreader.vala
index 69170e5..7f50c2d 100644
--- a/vala/valamarkupreader.vala
+++ b/vala/valamarkupreader.vala
@@ -103,6 +103,8 @@ public class Vala.MarkupReader : Object {
 
 		if (empty_element) {
 			empty_element = false;
+			token_begin = SourceLocation (begin, line, column);
+			token_end = SourceLocation (begin, line, column);
 			return MarkupTokenType.END_ELEMENT;
 		}
 
@@ -110,9 +112,7 @@ public class Vala.MarkupReader : Object {
 
 		MarkupTokenType type = MarkupTokenType.NONE;
 		char* begin = current;
-		token_begin.pos = begin;
-		token_begin.line = line;
-		token_begin.column = column;
+		token_begin = SourceLocation (begin, line, column);
 
 		if (current >= end) {
 			type = MarkupTokenType.EOF;
@@ -202,9 +202,7 @@ public class Vala.MarkupReader : Object {
 			type = MarkupTokenType.TEXT;
 		}
 
-		token_end.pos = current;
-		token_end.line = line;
-		token_end.column = column - 1;
+		token_end = SourceLocation (current, line, column - 1);
 
 		return type;
 	}
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 9664072..39b2223 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -591,6 +591,7 @@ public class Vala.Method : Subroutine {
 			return false;
 		}
 
+		invalid_match = null;
 		return true;
 	}
 
diff --git a/vala/valascanner.vala b/vala/valascanner.vala
index 352ab68..624c77d 100644
--- a/vala/valascanner.vala
+++ b/vala/valascanner.vala
@@ -97,9 +97,7 @@ public class Vala.Scanner {
 	public TokenType read_regex_token (out SourceLocation token_begin, out SourceLocation token_end) {
 		TokenType type;
 		char* begin = current;
-		token_begin.pos = begin;
-		token_begin.line = line;
-		token_begin.column = column;
+		token_begin = SourceLocation (begin, line, column);
 
 		int token_length_in_chars = -1;
 
@@ -251,9 +249,7 @@ public class Vala.Scanner {
 			column += token_length_in_chars;
 		}
 
-		token_end.pos = current;
-		token_end.line = line;
-		token_end.column = column - 1;
+		token_end = SourceLocation (current, line, column - 1);
 
 		return type;
 	}
@@ -631,9 +627,7 @@ public class Vala.Scanner {
 	public TokenType read_template_token (out SourceLocation token_begin, out SourceLocation token_end) {
 		TokenType type;
 		char* begin = current;
-		token_begin.pos = begin;
-		token_begin.line = line;
-		token_begin.column = column;
+		token_begin = SourceLocation (begin, line, column);
 
 		int token_length_in_chars = -1;
 
@@ -740,9 +734,7 @@ public class Vala.Scanner {
 			column += token_length_in_chars;
 		}
 
-		token_end.pos = current;
-		token_end.line = line;
-		token_end.column = column - 1;
+		token_end = SourceLocation (current, line, column - 1);
 
 		return type;
 	}
@@ -753,13 +745,8 @@ public class Vala.Scanner {
 		} else if (in_template_part ()) {
 			state_stack.length--;
 
-			token_begin.pos = current;
-			token_begin.line = line;
-			token_begin.column = column;
-
-			token_end.pos = current;
-			token_end.line = line;
-			token_end.column = column - 1;
+			token_begin = SourceLocation (current, line, column);
+			token_end = SourceLocation (current, line, column - 1);
 
 			return TokenType.COMMA;
 		} else if (in_regex_literal ()) {
@@ -770,9 +757,7 @@ public class Vala.Scanner {
 
 		TokenType type;
 		char* begin = current;
-		token_begin.pos = begin;
-		token_begin.line = line;
-		token_begin.column = column;
+		token_begin = SourceLocation (begin, line, column);
 
 		int token_length_in_chars = -1;
 
@@ -1187,9 +1172,7 @@ public class Vala.Scanner {
 			column += token_length_in_chars;
 		}
 
-		token_end.pos = current;
-		token_end.line = line;
-		token_end.column = column - 1;
+		token_end = SourceLocation (current, line, column - 1);
 		previous = type;
 
 		return type;
diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala
index f89441f..92fdb04 100644
--- a/vapigen/valagidlparser.vala
+++ b/vapigen/valagidlparser.vala
@@ -1645,7 +1645,7 @@ public class Vala.GIdlParser : CodeVisitor {
 	}
 	
 	private DataType? parse_type (IdlNodeType type_node, out ParameterDirection direction = null) {
-		ParameterDirection dir = ParameterDirection.IN;
+		direction = ParameterDirection.IN;
 
 		var type = new UnresolvedType ();
 		if (type_node.tag == TypeTag.VOID) {
@@ -1722,7 +1722,7 @@ public class Vala.GIdlParser : CodeVisitor {
 			    (n == "gchar" || n == "char")) {
 				type.unresolved_symbol = new UnresolvedSymbol (null, "string");
 				if (type_node.unparsed.has_suffix ("**")) {
-					dir = ParameterDirection.OUT;
+					direction = ParameterDirection.OUT;
 				}
 			} else if (n == "gunichar") {
 				type.unresolved_symbol = new UnresolvedSymbol (null, "unichar");
@@ -1775,18 +1775,15 @@ public class Vala.GIdlParser : CodeVisitor {
 				}
 				if (is_simple_type (n)) {
 					if (type_node.is_pointer) {
-						dir = ParameterDirection.OUT;
+						direction = ParameterDirection.OUT;
 					}
 				} else if (type_node.unparsed.has_suffix ("**")) {
-					dir = ParameterDirection.OUT;
+					direction = ParameterDirection.OUT;
 				}
 			}
 		} else {
 			stdout.printf ("%d\n", type_node.tag);
 		}
-		if (&direction != null) {
-			direction = dir;
-		}
 		return type;
 	}
 	



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