Commit 89179ce0 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

report warning when using null literal as return expression of method

2008-04-14  Juerg Billeter  <j@bitron.ch>

	* vala/valasemanticanalyzer.vala: report warning when using null
	  literal as return expression of method returning non-null value

	* */*.vala: fix warnings

svn path=/trunk/; revision=1228
parent 94979a22
2008-04-14 Jürg Billeter <j@bitron.ch>
* vala/valasemanticanalyzer.vala: report warning when using null
literal as return expression of method returning non-null value
* */*.vala: fix warnings
2008-04-14 Marc-Andre Lureau <marcandre.lureau@gmail.com>
* vapi/dbus-glib-1.vapi, vapi/enchant.vapi, vapi/libxml-2.0.vapi,
......
......@@ -68,7 +68,7 @@ public class Gee.ArrayList<G> : Object, Iterable<G>, Collection<G>, List<G> {
return -1;
}
public G get (int index) {
public G? get (int index) {
assert (index >= 0 && index < _size);
return _items[index];
......@@ -178,7 +178,7 @@ public class Gee.ArrayList<G> : Object, Iterable<G>, Collection<G>, List<G> {
return (_index < _list._size);
}
public G get () {
public G? get () {
assert (_stamp == _list._stamp);
if (_index < 0 || _index >= _list._size) {
......
......@@ -91,7 +91,7 @@ public class Gee.HashMap<K,V> : Object, Map<K,V> {
return (*node != null);
}
public V get (K key) {
public V? get (K key) {
Node<K,V>* node = (*lookup_node (key));
if (node != null) {
return node->value;
......@@ -251,7 +251,7 @@ public class Gee.HashMap<K,V> : Object, Map<K,V> {
return (_node != null);
}
public K get () {
public K? get () {
assert (_stamp == _map._stamp);
assert (_node != null);
return _node.key;
......@@ -334,7 +334,7 @@ public class Gee.HashMap<K,V> : Object, Map<K,V> {
return (_node != null);
}
public V get () {
public V? get () {
assert (_stamp == _map._stamp);
assert (_node != null);
return _node.value;
......
......@@ -193,7 +193,7 @@ public class Gee.HashSet<G> : Object, Iterable<G>, Collection<G>, Set<G> {
return (_node != null);
}
public G get () {
public G? get () {
assert (_stamp == _set._stamp);
assert (_node != null);
return _node.key;
......
/* iterator.vala
*
* Copyright (C) 2007 Jürg Billeter
* Copyright (C) 2007-2008 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -37,6 +37,6 @@ public interface Gee.Iterator<G> : GLib.Object {
*
* @return the current element in the iteration
*/
public abstract G get ();
public abstract G? get ();
}
......@@ -31,7 +31,7 @@ public interface Gee.List<G> : Collection<G> {
*
* @return the item at the specified index in the list
*/
public abstract G get (int index);
public abstract G? get (int index);
/**
* Sets the item at the specified index in this list.
......
......@@ -60,7 +60,7 @@ public interface Gee.Map<K,V> : GLib.Object {
* @return the value associated with the key, or null if the key
* couldn't be found
*/
public abstract V get (K key);
public abstract V? get (K key);
/**
* Inserts a new key and value into this map.
......
......@@ -77,7 +77,7 @@ public class Gee.ReadOnlyCollection<G> : Object, Iterable<G>, Collection<G> {
return false;
}
public G get () {
public G? get () {
return null;
}
}
......
......@@ -84,7 +84,7 @@ public class Gee.ReadOnlyList<G> : Object, Iterable<G>, Collection<G>, List<G> {
assert_not_reached ();
}
public G get (int index) {
public G? get (int index) {
if (_list == null) {
return null;
}
......@@ -105,7 +105,7 @@ public class Gee.ReadOnlyList<G> : Object, Iterable<G>, Collection<G>, List<G> {
return false;
}
public G get () {
public G? get () {
return null;
}
}
......
......@@ -64,7 +64,7 @@ public class Gee.ReadOnlyMap<K,V> : Object, Map<K,V> {
return _map.contains (key);
}
public V get (K key) {
public V? get (K key) {
if (_map == null) {
return null;
}
......
......@@ -77,7 +77,7 @@ public class Gee.ReadOnlySet<G> : Object, Iterable<G>, Collection<G>, Set<G> {
return false;
}
public G get () {
public G? get () {
return null;
}
}
......
......@@ -594,7 +594,7 @@ class Vala.ProjectGenerator : Dialog {
FileUtils.set_contents (project_path + "/MAINTAINERS", s, -1);
}
private string get_automake_path () {
private string? get_automake_path () {
var automake_paths = new string[] { "/usr/share/automake",
"/usr/share/automake-1.10",
"/usr/share/automake-1.9" };
......
......@@ -1198,7 +1198,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
}
}
private CCodeExpression get_dup_func_expression (DataType type, SourceReference? source_reference) {
private CCodeExpression? get_dup_func_expression (DataType type, SourceReference? source_reference) {
if (type.data_type != null) {
string dup_function;
if (type.data_type.is_reference_counting ()) {
......@@ -1226,7 +1226,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
}
}
private CCodeExpression get_destroy_func_expression (DataType type) {
private CCodeExpression? get_destroy_func_expression (DataType type) {
if (type.data_type != null) {
string unref_function;
if (type.data_type.is_reference_counting ()) {
......@@ -2665,7 +2665,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
visit_expression (expr);
}
private MemberAccess find_property_access (Expression expr) {
private MemberAccess? find_property_access (Expression expr) {
if (expr is ParenthesizedExpression) {
var pe = (ParenthesizedExpression) expr;
return find_property_access (pe.inner);
......@@ -2683,7 +2683,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
return null;
}
private CCodeExpression get_ref_expression (Expression expr) {
private CCodeExpression? get_ref_expression (Expression expr) {
/* (temp = expr, temp == NULL ? NULL : ref (temp))
*
* can be simplified to
......@@ -3548,287 +3548,287 @@ public class Vala.CCodeGenerator : CodeGenerator {
return type;
}
public override CodeBinding create_namespace_binding (Namespace node) {
public override CodeBinding? create_namespace_binding (Namespace node) {
return null;
}
public override CodeBinding create_class_binding (Class node) {
public override CodeBinding? create_class_binding (Class node) {
return null;
}
public override CodeBinding create_struct_binding (Struct node) {
public override CodeBinding? create_struct_binding (Struct node) {
return null;
}
public override CodeBinding create_interface_binding (Interface node) {
public override CodeBinding? create_interface_binding (Interface node) {
return null;
}
public override CodeBinding create_enum_binding (Enum node) {
public override CodeBinding? create_enum_binding (Enum node) {
return null;
}
public override CodeBinding create_enum_value_binding (EnumValue node) {
public override CodeBinding? create_enum_value_binding (EnumValue node) {
return null;
}
public override CodeBinding create_error_domain_binding (ErrorDomain node) {
public override CodeBinding? create_error_domain_binding (ErrorDomain node) {
return null;
}
public override CodeBinding create_error_code_binding (ErrorCode node) {
public override CodeBinding? create_error_code_binding (ErrorCode node) {
return null;
}
public override CodeBinding create_delegate_binding (Delegate node) {
public override CodeBinding? create_delegate_binding (Delegate node) {
return null;
}
public override CodeBinding create_constant_binding (Constant node) {
public override CodeBinding? create_constant_binding (Constant node) {
return null;
}
public override CodeBinding create_field_binding (Field node) {
public override CodeBinding? create_field_binding (Field node) {
return null;
}
public override CodeBinding create_method_binding (Method node) {
public override CodeBinding? create_method_binding (Method node) {
return new CCodeMethodBinding (this, node);
}
public override CodeBinding create_creation_method_binding (CreationMethod node) {
public override CodeBinding? create_creation_method_binding (CreationMethod node) {
return null;
}
public override CodeBinding create_formal_parameter_binding (FormalParameter node) {
public override CodeBinding? create_formal_parameter_binding (FormalParameter node) {
return null;
}
public override CodeBinding create_property_binding (Property node) {
public override CodeBinding? create_property_binding (Property node) {
return null;
}
public override CodeBinding create_property_accessor_binding (PropertyAccessor node) {
public override CodeBinding? create_property_accessor_binding (PropertyAccessor node) {
return null;
}
public override CodeBinding create_signal_binding (Signal node) {
public override CodeBinding? create_signal_binding (Signal node) {
return null;
}
public override CodeBinding create_constructor_binding (Constructor node) {
public override CodeBinding? create_constructor_binding (Constructor node) {
return null;
}
public override CodeBinding create_destructor_binding (Destructor node) {
public override CodeBinding? create_destructor_binding (Destructor node) {
return null;
}
public override CodeBinding create_type_parameter_binding (TypeParameter node) {
public override CodeBinding? create_type_parameter_binding (TypeParameter node) {
return null;
}
public override CodeBinding create_block_binding (Block node) {
public override CodeBinding? create_block_binding (Block node) {
return null;
}
public override CodeBinding create_empty_statement_binding (EmptyStatement node) {
public override CodeBinding? create_empty_statement_binding (EmptyStatement node) {
return null;
}
public override CodeBinding create_declaration_statement_binding (DeclarationStatement node) {
public override CodeBinding? create_declaration_statement_binding (DeclarationStatement node) {
return null;
}
public override CodeBinding create_local_variable_declaration_binding (LocalVariableDeclaration node) {
public override CodeBinding? create_local_variable_declaration_binding (LocalVariableDeclaration node) {
return null;
}
public override CodeBinding create_variable_declarator_binding (VariableDeclarator node) {
public override CodeBinding? create_variable_declarator_binding (VariableDeclarator node) {
return null;
}
public override CodeBinding create_initializer_list_binding (InitializerList node) {
public override CodeBinding? create_initializer_list_binding (InitializerList node) {
return null;
}
public override CodeBinding create_expression_statement_binding (ExpressionStatement node) {
public override CodeBinding? create_expression_statement_binding (ExpressionStatement node) {
return null;
}
public override CodeBinding create_if_statement_binding (IfStatement node) {
public override CodeBinding? create_if_statement_binding (IfStatement node) {
return null;
}
public override CodeBinding create_switch_statement_binding (SwitchStatement node) {
public override CodeBinding? create_switch_statement_binding (SwitchStatement node) {
return null;
}
public override CodeBinding create_switch_section_binding (SwitchSection node) {
public override CodeBinding? create_switch_section_binding (SwitchSection node) {
return null;
}
public override CodeBinding create_switch_label_binding (SwitchLabel node) {
public override CodeBinding? create_switch_label_binding (SwitchLabel node) {
return null;
}
public override CodeBinding create_while_statement_binding (WhileStatement node) {
public override CodeBinding? create_while_statement_binding (WhileStatement node) {
return null;
}
public override CodeBinding create_do_statement_binding (DoStatement node) {
public override CodeBinding? create_do_statement_binding (DoStatement node) {
return null;
}
public override CodeBinding create_for_statement_binding (ForStatement node) {
public override CodeBinding? create_for_statement_binding (ForStatement node) {
return null;
}
public override CodeBinding create_foreach_statement_binding (ForeachStatement node) {
public override CodeBinding? create_foreach_statement_binding (ForeachStatement node) {
return null;
}
public override CodeBinding create_break_statement_binding (BreakStatement node) {
public override CodeBinding? create_break_statement_binding (BreakStatement node) {
return null;
}
public override CodeBinding create_continue_statement_binding (ContinueStatement node) {
public override CodeBinding? create_continue_statement_binding (ContinueStatement node) {
return null;
}
public override CodeBinding create_return_statement_binding (ReturnStatement node) {
public override CodeBinding? create_return_statement_binding (ReturnStatement node) {
return null;
}
public override CodeBinding create_throw_statement_binding (ThrowStatement node) {
public override CodeBinding? create_throw_statement_binding (ThrowStatement node) {
return null;
}
public override CodeBinding create_try_statement_binding (TryStatement node) {
public override CodeBinding? create_try_statement_binding (TryStatement node) {
return null;
}
public override CodeBinding create_catch_clause_binding (CatchClause node) {
public override CodeBinding? create_catch_clause_binding (CatchClause node) {
return null;
}
public override CodeBinding create_lock_statement_binding (LockStatement node) {
public override CodeBinding? create_lock_statement_binding (LockStatement node) {
return null;
}
public override CodeBinding create_delete_statement_binding (DeleteStatement node) {
public override CodeBinding? create_delete_statement_binding (DeleteStatement node) {
return null;
}
public override CodeBinding create_array_creation_expression_binding (ArrayCreationExpression node) {
public override CodeBinding? create_array_creation_expression_binding (ArrayCreationExpression node) {
return new CCodeArrayCreationExpressionBinding (this, node);
}
public override CodeBinding create_boolean_literal_binding (BooleanLiteral node) {
public override CodeBinding? create_boolean_literal_binding (BooleanLiteral node) {
return null;
}
public override CodeBinding create_character_literal_binding (CharacterLiteral node) {
public override CodeBinding? create_character_literal_binding (CharacterLiteral node) {
return null;
}
public override CodeBinding create_integer_literal_binding (IntegerLiteral node) {
public override CodeBinding? create_integer_literal_binding (IntegerLiteral node) {
return null;
}
public override CodeBinding create_real_literal_binding (RealLiteral node) {
public override CodeBinding? create_real_literal_binding (RealLiteral node) {
return null;
}
public override CodeBinding create_string_literal_binding (StringLiteral node) {
public override CodeBinding? create_string_literal_binding (StringLiteral node) {
return null;
}
public override CodeBinding create_null_literal_binding (NullLiteral node) {
public override CodeBinding? create_null_literal_binding (NullLiteral node) {
return null;
}
public override CodeBinding create_parenthesized_expression_binding (ParenthesizedExpression node) {
public override CodeBinding? create_parenthesized_expression_binding (ParenthesizedExpression node) {
return null;
}
public override CodeBinding create_member_access_binding (MemberAccess node) {
public override CodeBinding? create_member_access_binding (MemberAccess node) {
return null;
}
public override CodeBinding create_member_access_simple_binding (MemberAccess node) {
public override CodeBinding? create_member_access_simple_binding (MemberAccess node) {
return null;
}
public override CodeBinding create_invocation_expression_binding (InvocationExpression node) {
public override CodeBinding? create_invocation_expression_binding (InvocationExpression node) {
return null;
}
public override CodeBinding create_element_access_binding (ElementAccess node) {
public override CodeBinding? create_element_access_binding (ElementAccess node) {
return new CCodeElementAccessBinding (this, node);
}
public override CodeBinding create_base_access_binding (BaseAccess node) {
public override CodeBinding? create_base_access_binding (BaseAccess node) {
return null;
}
public override CodeBinding create_postfix_expression_binding (PostfixExpression node) {
public override CodeBinding? create_postfix_expression_binding (PostfixExpression node) {
return null;
}
public override CodeBinding create_object_creation_expression_binding (ObjectCreationExpression node) {
public override CodeBinding? create_object_creation_expression_binding (ObjectCreationExpression node) {
return null;
}
public override CodeBinding create_sizeof_expression_binding (SizeofExpression node) {
public override CodeBinding? create_sizeof_expression_binding (SizeofExpression node) {
return null;
}
public override CodeBinding create_typeof_expression_binding (TypeofExpression node) {
public override CodeBinding? create_typeof_expression_binding (TypeofExpression node) {
return null;
}
public override CodeBinding create_unary_expression_binding (UnaryExpression node) {
public override CodeBinding? create_unary_expression_binding (UnaryExpression node) {
return null;
}
public override CodeBinding create_cast_expression_binding (CastExpression node) {
public override CodeBinding? create_cast_expression_binding (CastExpression node) {
return null;
}
public override CodeBinding create_pointer_indirection_binding (PointerIndirection node) {
public override CodeBinding? create_pointer_indirection_binding (PointerIndirection node) {
return null;
}
public override CodeBinding create_addressof_expression_binding (AddressofExpression node) {
public override CodeBinding? create_addressof_expression_binding (AddressofExpression node) {
return null;
}
public override CodeBinding create_reference_transfer_expression_binding (ReferenceTransferExpression node) {
public override CodeBinding? create_reference_transfer_expression_binding (ReferenceTransferExpression node) {
return null;
}
public override CodeBinding create_binary_expression_binding (BinaryExpression node) {
public override CodeBinding? create_binary_expression_binding (BinaryExpression node) {
return null;
}
public override CodeBinding create_type_check_binding (TypeCheck node) {
public override CodeBinding? create_type_check_binding (TypeCheck node) {
return null;
}
public override CodeBinding create_conditional_expression_binding (ConditionalExpression node) {
public override CodeBinding? create_conditional_expression_binding (ConditionalExpression node) {
return null;
}
public override CodeBinding create_lambda_expression_binding (LambdaExpression node) {
public override CodeBinding? create_lambda_expression_binding (LambdaExpression node) {
return null;
}
public override CodeBinding create_lambda_expression_with_statement_body_binding (LambdaExpression node) {
public override CodeBinding? create_lambda_expression_with_statement_body_binding (LambdaExpression node) {
return null;
}
public override CodeBinding create_assignment_binding (Assignment node) {
public override CodeBinding? create_assignment_binding (Assignment node) {
return new CCodeAssignmentBinding (this, node);
}
}
......@@ -649,7 +649,7 @@ public class Vala.CCodeGenerator {
}
}
private CCodeStatement create_type_check_statement (CodeNode method_node, DataType ret_type, Typesymbol t, bool non_null, string var_name) {
private CCodeStatement? create_type_check_statement (CodeNode method_node, DataType ret_type, Typesymbol t, bool non_null, string var_name) {
var ccheck = new CCodeFunctionCall ();
if ((t is Class && ((Class) t).is_subtype_of (gobject_type)) || (t is Interface && !((Interface) t).declaration_only)) {
......@@ -717,7 +717,7 @@ public class Vala.CCodeGenerator {
return new CCodeExpressionStatement (cassert);
}
private CCodeExpression default_value_for_type (DataType type, bool initializer_expression) {
private CCodeExpression? default_value_for_type (DataType type, bool initializer_expression) {
if ((type.data_type != null && type.data_type.is_reference_type ()) || type is PointerType || type is ArrayType) {
return new CCodeConstant ("NULL");
} else if (type.data_type != null && type.data_type.get_default_value () != null) {
......@@ -736,7 +736,7 @@ public class Vala.CCodeGenerator {
return null;
}
private Typesymbol find_parent_type (Symbol sym) {
private Typesymbol? find_parent_type (Symbol sym) {
while (sym != null) {
if (sym is Typesymbol) {
return (Typesymbol) sym;
......
......@@ -62,7 +62,7 @@ public class Vala.CCodeGenerator {
return ret;
}
private string get_value_type_name_from_type_reference (DataType t) {
private string? get_value_type_name_from_type_reference (DataType t) {
if (t is PointerType || t.type_parameter != null || t.is_ref || t.is_out) {
return "gpointer";
} else if (t is VoidType) {
......
......@@ -51,7 +51,7 @@ public class Vala.DBusBindingProvider : Object, BindingProvider {
public DBusBindingProvider () {
}
public Symbol get_binding (MemberAccess ma) {
public Symbol? get_binding (MemberAccess ma) {
if (connection_type != null && ma.inner != null && ma.inner.static_type != null && ma.inner.static_type.data_type == connection_type) {
var type_args = ma.get_type_arguments ();
if (type_args.size != 1) {
......
......@@ -131,7 +131,7 @@ public class Vala.ArrayType : ReferenceType {
return result;
}
public override string get_cname (bool var_type, bool const_type) {
public override string? get_cname (bool var_type, bool const_type) {
return element_type.get_cname () + "*";
}
......
......@@ -81,7 +81,7 @@ public class Vala.Attribute : CodeNode {
* @param name argument name
* @return string value
*/
public string get_string (string name) {
public string? get_string (string name) {
// FIXME: use hash table
foreach (NamedArgument arg in args) {
if (arg.name == name) {
......
/* valabindingprovider.vala
*
* Copyright (C) 2007 Jürg Billeter
* Copyright (C) 2007-2008 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -32,6 +32,6 @@ public interface Vala.BindingProvider : Object {
* @param ma member access expression
* @return resolved symbol or null if no binding can be provided
*/
public abstract Symbol get_binding (MemberAccess ma);
public abstract Symbol? get_binding (MemberAccess ma);
}
......@@ -470,7 +470,7 @@ public class Vala.Class : Typesymbol {
return lower_case_cprefix;
}
public override string get_upper_case_cname (string? infix) {
public override string? get_upper_case_cname (string? infix) {
return get_lower_case_cname (infix).up ();
}
......@@ -544,7 +544,7 @@ public class Vala.Class : Typesymbol {
return has_type_id || (base_class != null && base_class.get_has_type_id ());
}
public override string get_type_id () {
public override string? get_type_id () {
if (type_id == null) {
if (get_has_type_id ()) {
type_id = get_upper_case_cname ("TYPE_");
......@@ -560,7 +560,7 @@ public class Vala.Class : Typesymbol {
this.type_id = type_id;
}
public override string get_marshaller_type_name () {
public override string? get_marshaller_type_name () {
if (marshaller_type_name == null) {
if (base_class != null) {
marshaller_type_name = base_class.get_marshaller_type_name ();
......@@ -572,7 +572,7 @@ public class Vala.Class : Typesymbol {
return marshaller_type_name;
}
public override string get_get_value_function () {
public override string? get_get_value_function () {
if (get_value_function == null) {
if (base_class != null) {
get_value_function = base_class.get_get_value_function ();
......@@ -584,7 +584,7 @@ public class Vala.Class : Typesymbol {
return get_value_function;
}
public override string get_set_value_function () {
public override string? get_set_value_function () {
if (set_value_function == null) {
if (base_class != null) {
set_value_function = base_class.get_set_value_function ();
......
......@@ -381,7 +381,7 @@ public class Vala.CodeContext : Object {
}
}
public string get_package_path (string pkg, [CCode (array_length_pos = 1.9)] string[] vapi_directories) {
public string? get_package_path (string pkg, [CCode (array_length_pos = 1.9)] string[] vapi_directories) {
string basename = "%s.vapi".printf (pkg);
string filename = null;
......
......@@ -34,287 +34,287 @@ public class Vala.CodeGenerator : CodeVisitor {
public virtual void emit (CodeContext context) {
}
public virtual CodeBinding create_namespace_binding (Namespace node) {
public virtual CodeBinding? create_namespace_binding (Namespace node) {
return null;
}
public virtual CodeBinding create_class_binding (Class node) {
public virtual CodeBinding? create_class_binding (Class node) {
return null;
}
public virtual CodeBinding create_struct_binding (Struct node) {
public virtual CodeBinding? create_struct_binding (Struct node) {
return null;
}
public virtual CodeBinding create_interface_binding (Interface node) {
public virtual CodeBinding? create_interface_binding (Interface node) {
return null;
}