vala r2016 - in trunk: . gobject vala vapigen
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r2016 - in trunk: . gobject vala vapigen
- Date: Fri, 14 Nov 2008 17:41:23 +0000 (UTC)
Author: juergbi
Date: Fri Nov 14 17:41:23 2008
New Revision: 2016
URL: http://svn.gnome.org/viewvc/vala?rev=2016&view=rev
Log:
2008-11-14 JÃrg Billeter <j bitron ch>
* vala/valacfgbuilder.vala:
* vala/valamemberaccess.vala:
* vala/valamethod.vala:
* vala/valasymbol.vala:
* gobject/valaccodemethodmodule.vala:
Report unused fields, methods, and local variables
* vala/valacodecontext.vala:
* vala/valadynamicproperty.vala:
* vala/valaenum.vala:
* vala/valagenieparser.vala:
* vala/valainterfacewriter.vala:
* vala/valaparser.vala:
* vala/valastruct.vala:
* vala/valaunresolvedtype.vala:
* gobject/valaccodearraymodule.vala:
* gobject/valaccodeassignmentmodule.vala:
* gobject/valaccodebasemodule.vala:
* gobject/valaccodeinvocationexpressionmodule.vala:
* gobject/valaccodememberaccessmodule.vala:
* gobject/valadbusservermodule.vala:
* gobject/valagobjectmodule.vala:
* vapigen/valagirparser.vala:
* vapigen/valamarkupreader.vala:
Remove unused symbols
Modified:
trunk/ChangeLog
trunk/gobject/valaccodearraymodule.vala
trunk/gobject/valaccodeassignmentmodule.vala
trunk/gobject/valaccodebasemodule.vala
trunk/gobject/valaccodeinvocationexpressionmodule.vala
trunk/gobject/valaccodememberaccessmodule.vala
trunk/gobject/valaccodemethodmodule.vala
trunk/gobject/valadbusservermodule.vala
trunk/gobject/valagobjectmodule.vala
trunk/vala/valacfgbuilder.vala
trunk/vala/valacodecontext.vala
trunk/vala/valadynamicproperty.vala
trunk/vala/valaenum.vala
trunk/vala/valagenieparser.vala
trunk/vala/valainterfacewriter.vala
trunk/vala/valamemberaccess.vala
trunk/vala/valamethod.vala
trunk/vala/valaparser.vala
trunk/vala/valastruct.vala
trunk/vala/valasymbol.vala
trunk/vala/valaunresolvedtype.vala
trunk/vapigen/valagirparser.vala
trunk/vapigen/valamarkupreader.vala
Modified: trunk/gobject/valaccodearraymodule.vala
==============================================================================
--- trunk/gobject/valaccodearraymodule.vala (original)
+++ trunk/gobject/valaccodearraymodule.vala Fri Nov 14 17:41:23 2008
@@ -178,8 +178,6 @@
}
var length_cname = get_array_length_cname (field.name, dim);
- var instance_expression_type = get_data_type_for_symbol (base_type);
- var instance_target_type = get_data_type_for_symbol ((TypeSymbol) field.parent_symbol);
CCodeExpression typed_inst = (CCodeExpression) get_ccodenode (ma.inner);
CCodeExpression inst;
Modified: trunk/gobject/valaccodeassignmentmodule.vala
==============================================================================
--- trunk/gobject/valaccodeassignmentmodule.vala (original)
+++ trunk/gobject/valaccodeassignmentmodule.vala Fri Nov 14 17:41:23 2008
@@ -167,7 +167,6 @@
ccomma.append_expression (new CCodeAssignment (lhs_array_len, rhs_array_len));
}
} else if (instance_delegate) {
- var delegate_type = (DelegateType) assignment.left.value_type;
var lhs_delegate_target = get_delegate_target_cexpression (assignment.left);
var rhs_delegate_target = get_delegate_target_cexpression (assignment.right);
ccomma.append_expression (new CCodeAssignment (lhs_delegate_target, rhs_delegate_target));
Modified: trunk/gobject/valaccodebasemodule.vala
==============================================================================
--- trunk/gobject/valaccodebasemodule.vala (original)
+++ trunk/gobject/valaccodebasemodule.vala Fri Nov 14 17:41:23 2008
@@ -1592,8 +1592,6 @@
var function = new CCodeFunction (destroy_func, "void");
function.modifiers = CCodeModifiers.STATIC;
- var cparam_map = new HashMap<int,CCodeFormalParameter> (direct_hash, direct_equal);
-
function.add_parameter (new CCodeFormalParameter ("self", list_type.get_cname ()));
// definition
Modified: trunk/gobject/valaccodeinvocationexpressionmodule.vala
==============================================================================
--- trunk/gobject/valaccodeinvocationexpressionmodule.vala (original)
+++ trunk/gobject/valaccodeinvocationexpressionmodule.vala Fri Nov 14 17:41:23 2008
@@ -169,7 +169,6 @@
Iterator<FormalParameter> params_it = params.iterator ();
foreach (Expression arg in expr.get_argument_list ()) {
CCodeExpression cexpr = (CCodeExpression) arg.ccodenode;
- Gee.List<CCodeExpression> extra_args = new ArrayList<CCodeExpression> ();
if (params_it.next ()) {
var param = params_it.get ();
ellipsis = param.ellipsis;
Modified: trunk/gobject/valaccodememberaccessmodule.vala
==============================================================================
--- trunk/gobject/valaccodememberaccessmodule.vala (original)
+++ trunk/gobject/valaccodememberaccessmodule.vala Fri Nov 14 17:41:23 2008
@@ -89,7 +89,6 @@
} else if (expr.symbol_reference is Field) {
var f = (Field) expr.symbol_reference;
if (f.binding == MemberBinding.INSTANCE) {
- var instance_expression_type = base_type;
var instance_target_type = get_data_type_for_symbol ((TypeSymbol) f.parent_symbol);
var cl = instance_target_type.data_type as Class;
Modified: trunk/gobject/valaccodemethodmodule.vala
==============================================================================
--- trunk/gobject/valaccodemethodmodule.vala (original)
+++ trunk/gobject/valaccodemethodmodule.vala Fri Nov 14 17:41:23 2008
@@ -555,8 +555,6 @@
var vfunc = new CCodeFunction (m.get_cname (), creturn_type.get_cname ());
vfunc.line = function.line;
- ReferenceType this_type = new ObjectType ((Class) m.parent_symbol);
-
cparam_map = new HashMap<int,CCodeFormalParameter> (direct_hash, direct_equal);
var carg_map = new HashMap<int,CCodeExpression> (direct_hash, direct_equal);
@@ -609,9 +607,7 @@
}
}
- bool return_value = true;
- bool args_parameter = true;
- if (is_possible_entry_point (m, ref return_value, ref args_parameter)) {
+ if (m.entry_point) {
// m is possible entry point, add appropriate startup code
var cmain = new CCodeFunction ("main", "int");
cmain.line = function.line;
@@ -631,15 +627,11 @@
main_block.add_statement (type_init_call);
var main_call = new CCodeFunctionCall (new CCodeIdentifier (function.name));
- if (args_parameter) {
+ if (m.get_parameters ().size == 1) {
main_call.add_argument (new CCodeIdentifier ("argv"));
main_call.add_argument (new CCodeIdentifier ("argc"));
}
- if (return_value) {
- var main_stmt = new CCodeReturnStatement (main_call);
- main_stmt.line = cmain.line;
- main_block.add_statement (main_stmt);
- } else {
+ if (m.return_type is VoidType) {
// method returns void, always use 0 as exit code
var main_stmt = new CCodeExpressionStatement (main_call);
main_stmt.line = cmain.line;
@@ -647,6 +639,10 @@
var ret_stmt = new CCodeReturnStatement (new CCodeConstant ("0"));
ret_stmt.line = cmain.line;
main_block.add_statement (ret_stmt);
+ } else {
+ var main_stmt = new CCodeReturnStatement (main_call);
+ main_stmt.line = cmain.line;
+ main_block.add_statement (main_stmt);
}
cmain.block = main_block;
source_type_member_definition.append (cmain);
@@ -833,62 +829,6 @@
return null;
}
- private bool is_possible_entry_point (Method m, ref bool return_value, ref bool args_parameter) {
- if (m.name == null || m.name != "main") {
- // method must be called "main"
- return false;
- }
-
- if (m.binding == MemberBinding.INSTANCE) {
- // method must be static
- return false;
- }
-
- if (m.return_type.data_type == null) {
- return_value = false;
- } else if (m.return_type.data_type == int_type.data_type) {
- return_value = true;
- } else {
- // return type must be void or int
- return false;
- }
-
- var params = m.get_parameters ();
- if (params.size == 0) {
- // method may have no parameters
- args_parameter = false;
- return true;
- }
-
- if (params.size > 1) {
- // method must not have more than one parameter
- return false;
- }
-
- Iterator<FormalParameter> params_it = params.iterator ();
- params_it.next ();
- var param = params_it.get ();
-
- if (param.direction == ParameterDirection.OUT) {
- // parameter must not be an out parameter
- return false;
- }
-
- if (!(param.parameter_type is ArrayType)) {
- // parameter must be an array
- return false;
- }
-
- var array_type = (ArrayType) param.parameter_type;
- if (array_type.element_type.data_type != string_type.data_type) {
- // parameter must be an array of strings
- return false;
- }
-
- args_parameter = true;
- return true;
- }
-
private void add_object_creation (CCodeBlock b, bool has_params) {
var cl = (Class) current_type_symbol;
Modified: trunk/gobject/valadbusservermodule.vala
==============================================================================
--- trunk/gobject/valadbusservermodule.vala (original)
+++ trunk/gobject/valadbusservermodule.vala Fri Nov 14 17:41:23 2008
@@ -365,7 +365,6 @@
} else if (param.parameter_type.get_type_signature ().has_prefix ("a{")) {
// hash table output parameter
var type_args = param.parameter_type.get_type_arguments ();
- var key_type = type_args.get (0);
var value_type = type_args.get (1);
if (value_type.get_type_signature ().has_prefix ("(")) {
// values are structs
@@ -393,7 +392,6 @@
} else if (m.return_type.get_type_signature ().has_prefix ("a{")) {
// hash table output parameter
var type_args = m.return_type.get_type_arguments ();
- var key_type = type_args.get (0);
var value_type = type_args.get (1);
if (value_type.get_type_signature ().has_prefix ("(")) {
// values are structs
@@ -436,7 +434,6 @@
} else if (param.parameter_type.get_type_signature ().has_prefix ("a{")) {
// hash table output parameter
var type_args = param.parameter_type.get_type_arguments ();
- var key_type = type_args.get (0);
var value_type = type_args.get (1);
if (value_type.get_type_signature ().has_prefix ("(")) {
// values are structs
@@ -462,7 +459,6 @@
} else if (m.return_type.get_type_signature ().has_prefix ("a{")) {
// hash table return value
var type_args = m.return_type.get_type_arguments ();
- var key_type = type_args.get (0);
var value_type = type_args.get (1);
if (value_type.get_type_signature ().has_prefix ("(")) {
// values are structs
@@ -524,7 +520,6 @@
} else if (param.parameter_type.get_type_signature ().has_prefix ("a{")) {
// hash table output parameter
var type_args = param.parameter_type.get_type_arguments ();
- var key_type = type_args.get (0);
var value_type = type_args.get (1);
if (value_type.get_type_signature ().has_prefix ("(")) {
// values are structs
@@ -552,7 +547,6 @@
} else if (m.return_type.get_type_signature ().has_prefix ("a{")) {
// hash table output parameter
var type_args = m.return_type.get_type_arguments ();
- var key_type = type_args.get (0);
var value_type = type_args.get (1);
if (value_type.get_type_signature ().has_prefix ("(")) {
// values are structs
@@ -583,7 +577,6 @@
} else if (param.parameter_type.get_type_signature ().has_prefix ("a{")) {
// hash table output parameter
var type_args = param.parameter_type.get_type_arguments ();
- var key_type = type_args.get (0);
var value_type = type_args.get (1);
if (value_type.get_type_signature ().has_prefix ("(")) {
// values are structs
@@ -635,7 +628,6 @@
} else if (m.return_type.get_type_signature ().has_prefix ("a{")) {
// hash table output parameter
var type_args = m.return_type.get_type_arguments ();
- var key_type = type_args.get (0);
var value_type = type_args.get (1);
if (value_type.get_type_signature ().has_prefix ("(")) {
// values are structs
Modified: trunk/gobject/valagobjectmodule.vala
==============================================================================
--- trunk/gobject/valagobjectmodule.vala (original)
+++ trunk/gobject/valagobjectmodule.vala Fri Nov 14 17:41:23 2008
@@ -306,9 +306,11 @@
source_type_member_definition.append (function);
}
+ current_symbol = old_symbol;
current_type_symbol = old_type_symbol;
current_class = old_class;
instance_struct = old_instance_struct;
+ param_spec_struct = old_param_spec_struct;
type_struct = old_type_struct;
instance_priv_struct = old_instance_priv_struct;
prop_enum = old_prop_enum;
Modified: trunk/vala/valacfgbuilder.vala
==============================================================================
--- trunk/vala/valacfgbuilder.vala (original)
+++ trunk/vala/valacfgbuilder.vala Fri Nov 14 17:41:23 2008
@@ -118,7 +118,21 @@
ed.accept_children (this);
}
+ public override void visit_field (Field f) {
+ if (f.access != SymbolAccessibility.PUBLIC
+ && f.access != SymbolAccessibility.PROTECTED
+ && !f.used) {
+ Report.warning (f.source_reference, "field `%s' never used".printf (f.get_full_name ()));
+ }
+ }
+
public override void visit_method (Method m) {
+ if (m.access != SymbolAccessibility.PUBLIC
+ && m.access != SymbolAccessibility.PROTECTED
+ && !m.used && !m.entry_point) {
+ Report.warning (m.source_reference, "method `%s' never used".printf (m.get_full_name ()));
+ }
+
if (m.body == null) {
return;
}
@@ -189,6 +203,10 @@
return;
}
+ if (!stmt.declaration.used) {
+ Report.warning (stmt.declaration.source_reference, "local variable `%s' declared but never used".printf (stmt.declaration.name));
+ }
+
current_block.add_node (stmt);
var local = stmt.declaration as LocalVariable;
Modified: trunk/vala/valacodecontext.vala
==============================================================================
--- trunk/vala/valacodecontext.vala (original)
+++ trunk/vala/valacodecontext.vala Fri Nov 14 17:41:23 2008
@@ -345,7 +345,7 @@
continue;
}
- if (cycle_file.cycle != null) {
+ if (ref_cycle_file_cycle != null) {
/* file already in a cycle */
if (cycle_file.cycle == cycle) {
Modified: trunk/vala/valadynamicproperty.vala
==============================================================================
--- trunk/vala/valadynamicproperty.vala (original)
+++ trunk/vala/valadynamicproperty.vala Fri Nov 14 17:41:23 2008
@@ -29,8 +29,6 @@
public class Vala.DynamicProperty : Property {
public DataType dynamic_type { get; set; }
- private string cname;
-
public DynamicProperty (DataType dynamic_type, string name, SourceReference? source_reference = null) {
base (name, null, null, null, source_reference);
this.dynamic_type = dynamic_type;
Modified: trunk/vala/valaenum.vala
==============================================================================
--- trunk/vala/valaenum.vala (original)
+++ trunk/vala/valaenum.vala Fri Nov 14 17:41:23 2008
@@ -160,11 +160,7 @@
public override bool is_reference_type () {
return false;
}
-
- private void set_cname (string cname) {
- this.cname = cname;
- }
-
+
/**
* Returns the string to be prepended to the name of members of this
* enum when used in C code.
Modified: trunk/vala/valagenieparser.vala
==============================================================================
--- trunk/vala/valagenieparser.vala (original)
+++ trunk/vala/valagenieparser.vala Fri Nov 14 17:41:23 2008
@@ -201,12 +201,6 @@
return new SourceReference (scanner.source_file, tokens[index].begin.line, tokens[index].begin.column, tokens[index].end.line, tokens[index].end.column);
}
- SourceReference get_last_src () {
- int last_index = (index + BUFFER_SIZE - 1) % BUFFER_SIZE;
-
- return new SourceReference (scanner.source_file, tokens[last_index].begin.line, tokens[last_index].begin.column, tokens[last_index].end.line, tokens[last_index].end.column);
- }
-
void rollback (SourceLocation location) {
while (tokens[index].begin.pos != location.pos) {
prev ();
@@ -1684,7 +1678,6 @@
Block parse_block () throws ParseError {
var begin = get_location ();
- Gee.List<Statement> list = new ArrayList<Statement> ();
expect (TokenType.INDENT);
var block = new Block (get_src_com (begin));
parse_statements (block);
@@ -1715,8 +1708,6 @@
}
void parse_local_variable_declarations (Block block) throws ParseError {
- var begin = get_location ();
-
if (accept (TokenType.VAR)) {
/* support block vars */
if (accept (TokenType.EOL) && accept (TokenType.INDENT)) {
@@ -2342,10 +2333,7 @@
}
void parse_using_directives () throws ParseError {
- var begin = get_location ();
while (accept (TokenType.USES)) {
- var begin = get_location ();
-
if (accept_block ()) {
expect (TokenType.INDENT);
@@ -2793,7 +2781,6 @@
while (current () != TokenType.DEDENT) {
var accessor_begin = get_location ();
parse_attributes ();
- var accessor_access = SymbolAccessibility.PUBLIC;
if (accept (TokenType.GET)) {
if (prop.get_accessor != null) {
throw new ParseError.SYNTAX (get_error ("property get accessor already defined"));
@@ -3296,7 +3283,7 @@
expect (TokenType.CONSTRUCT);
- var flags = parse_member_declaration_modifiers ();
+ parse_member_declaration_modifiers ();
if (accept (TokenType.OPEN_PARENS)) {
@@ -3480,27 +3467,5 @@
} while (accept (TokenType.DOT));
return expr;
}
-
- bool is_declaration_keyword (TokenType type) {
- switch (type) {
- case TokenType.CLASS:
- case TokenType.CONST:
- case TokenType.DEF:
- case TokenType.DELEGATE:
- case TokenType.ENUM:
- case TokenType.ERRORDOMAIN:
- case TokenType.EVENT:
- case TokenType.FINAL:
- case TokenType.INIT:
- case TokenType.INTERFACE:
- case TokenType.NAMESPACE:
- case TokenType.OVERRIDE:
- case TokenType.PROP:
- case TokenType.STRUCT:
- return true;
- default:
- return false;
- }
- }
}
Modified: trunk/vala/valainterfacewriter.vala
==============================================================================
--- trunk/vala/valainterfacewriter.vala (original)
+++ trunk/vala/valainterfacewriter.vala Fri Nov 14 17:41:23 2008
@@ -36,8 +36,6 @@
/* at begin of line */
bool bol = true;
- string current_cheader_filename;
-
Scope current_scope;
/**
Modified: trunk/vala/valamemberaccess.vala
==============================================================================
--- trunk/vala/valamemberaccess.vala (original)
+++ trunk/vala/valamemberaccess.vala Fri Nov 14 17:41:23 2008
@@ -444,6 +444,8 @@
instance = true;
}
+ member.used = true;
+
if (access == SymbolAccessibility.PRIVATE) {
var target_type = member.parent_symbol;
Modified: trunk/vala/valamethod.vala
==============================================================================
--- trunk/vala/valamethod.vala (original)
+++ trunk/vala/valamethod.vala Fri Nov 14 17:41:23 2008
@@ -145,7 +145,9 @@
return _base_interface_method;
}
}
-
+
+ public bool entry_point { get; private set; }
+
/**
* Specifies the generated `this' parameter for instance methods.
*/
@@ -768,6 +770,62 @@
}
}
+ if (is_possible_entry_point (analyzer)) {
+ entry_point = true;
+ }
+
return !error;
}
+
+ bool is_possible_entry_point (SemanticAnalyzer analyzer) {
+ if (name == null || name != "main") {
+ // method must be called "main"
+ return false;
+ }
+
+ if (binding == MemberBinding.INSTANCE) {
+ // method must be static
+ return false;
+ }
+
+ if (return_type is VoidType) {
+ } else if (return_type.data_type == analyzer.int_type.data_type) {
+ } else {
+ // return type must be void or int
+ return false;
+ }
+
+ var params = get_parameters ();
+ if (params.size == 0) {
+ // method may have no parameters
+ return true;
+ }
+
+ if (params.size > 1) {
+ // method must not have more than one parameter
+ return false;
+ }
+
+ Iterator<FormalParameter> params_it = params.iterator ();
+ params_it.next ();
+ var param = params_it.get ();
+
+ if (param.direction == ParameterDirection.OUT) {
+ // parameter must not be an out parameter
+ return false;
+ }
+
+ if (!(param.parameter_type is ArrayType)) {
+ // parameter must be an array
+ return false;
+ }
+
+ var array_type = (ArrayType) param.parameter_type;
+ if (array_type.element_type.data_type != analyzer.string_type.data_type) {
+ // parameter must be an array of strings
+ return false;
+ }
+
+ return true;
+ }
}
Modified: trunk/vala/valaparser.vala
==============================================================================
--- trunk/vala/valaparser.vala (original)
+++ trunk/vala/valaparser.vala Fri Nov 14 17:41:23 2008
@@ -1341,7 +1341,6 @@
Block parse_block () throws ParseError {
var begin = get_location ();
- Gee.List<Statement> list = new ArrayList<Statement> ();
expect (TokenType.OPEN_BRACE);
var block = new Block (get_src_com (begin));
parse_statements (block);
@@ -1365,7 +1364,6 @@
}
void parse_local_variable_declarations (Block block) throws ParseError {
- var begin = get_location ();
DataType variable_type;
if (accept (TokenType.VAR)) {
variable_type = null;
@@ -1929,8 +1927,6 @@
void parse_using_directives () throws ParseError {
while (accept (TokenType.USING)) {
- var begin = get_location ();
-
do {
var begin = get_location ();
var sym = parse_symbol_name ();
Modified: trunk/vala/valastruct.vala
==============================================================================
--- trunk/vala/valastruct.vala (original)
+++ trunk/vala/valastruct.vala Fri Nov 14 17:41:23 2008
@@ -36,8 +36,6 @@
private string cname;
private string const_cname;
- private string dup_function;
- private string free_function;
private string type_id;
private string lower_case_cprefix;
private string lower_case_csuffix;
@@ -222,10 +220,6 @@
return "%s%s".printf (parent_symbol.get_cprefix (), name);
}
- private void set_cname (string cname) {
- this.cname = cname;
- }
-
private void set_const_cname (string cname) {
this.const_cname = cname;
}
Modified: trunk/vala/valasymbol.vala
==============================================================================
--- trunk/vala/valasymbol.vala (original)
+++ trunk/vala/valasymbol.vala Fri Nov 14 17:41:23 2008
@@ -69,6 +69,11 @@
public bool active { get; set; default = true; }
/**
+ * Specifies whether this symbol has been accessed.
+ */
+ public bool used { get; set; }
+
+ /**
* Specifies the accessibility of this symbol. Public accessibility
* doesn't limit access. Default accessibility limits access to this
* program or library. Private accessibility limits access to instances
Modified: trunk/vala/valaunresolvedtype.vala
==============================================================================
--- trunk/vala/valaunresolvedtype.vala (original)
+++ trunk/vala/valaunresolvedtype.vala Fri Nov 14 17:41:23 2008
@@ -56,8 +56,6 @@
* @return newly created type reference
*/
public static UnresolvedType? new_from_expression (Expression expr) {
- string ns = null;
- string type_name = null;
if (expr is MemberAccess) {
UnresolvedType type_ref = null;
Modified: trunk/vapigen/valagirparser.vala
==============================================================================
--- trunk/vapigen/valagirparser.vala (original)
+++ trunk/vapigen/valagirparser.vala Fri Nov 14 17:41:23 2008
@@ -670,7 +670,7 @@
string name = reader.get_attribute ("name");
next ();
- var return_type = parse_return_value ();
+ parse_return_value ();
var m = new CreationMethod (null, name, get_current_src ());
m.access = SymbolAccessibility.PUBLIC;
Modified: trunk/vapigen/valamarkupreader.vala
==============================================================================
--- trunk/vapigen/valamarkupreader.vala (original)
+++ trunk/vapigen/valamarkupreader.vala Fri Nov 14 17:41:23 2008
@@ -189,7 +189,7 @@
return read_token (out token_begin, out token_end);
}
type = MarkupTokenType.TEXT;
- string text = ((string) text_begin).ndup (current - text_begin);
+ // string text = ((string) text_begin).ndup (current - text_begin);
}
column += (int) (current - begin);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]