From: Rico Tzschichholz Date: Sun, 29 Sep 2019 16:15:54 +0000 (+0200) Subject: vala: Micro optimizations X-Git-Tag: 0.47.1~129 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9811ebe2f9b984bca96248183fc412fa8d049c60;p=thirdparty%2Fvala.git vala: Micro optimizations --- diff --git a/vala/valaaddressofexpression.vala b/vala/valaaddressofexpression.vala index 4948a46c2..991596b22 100644 --- a/vala/valaaddressofexpression.vala +++ b/vala/valaaddressofexpression.vala @@ -93,7 +93,8 @@ public class Vala.AddressofExpression : Expression { error = true; return false; } - var ea = inner as ElementAccess; + + unowned ElementAccess? ea = inner as ElementAccess; if (inner is MemberAccess && inner.symbol_reference is Variable) { // address of variable is always possible } else if (ea != null && diff --git a/vala/valaarraytype.vala b/vala/valaarraytype.vala index 762168933..e9b7192d7 100644 --- a/vala/valaarraytype.vala +++ b/vala/valaarraytype.vala @@ -223,7 +223,7 @@ public class Vala.ArrayType : ReferenceType { return true; } - var target_array_type = target_type as ArrayType; + unowned ArrayType? target_array_type = target_type as ArrayType; if (target_array_type == null) { return false; } @@ -332,7 +332,7 @@ public class Vala.ArrayType : ReferenceType { } public override DataType? infer_type_argument (TypeParameter type_param, DataType value_type) { - var array_type = value_type as ArrayType; + unowned ArrayType? array_type = value_type as ArrayType; if (array_type != null) { return element_type.infer_type_argument (type_param, array_type.element_type); } diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala index 893670232..f3127dcc0 100644 --- a/vala/valabinaryexpression.vala +++ b/vala/valabinaryexpression.vala @@ -341,7 +341,7 @@ public class Vala.BinaryExpression : Expression { } else if (left.value_type is ArrayType && operator == BinaryOperator.PLUS) { // array concatenation - var array_type = (ArrayType) left.value_type; + unowned ArrayType array_type = (ArrayType) left.value_type; if (right.value_type == null || !right.value_type.compatible (array_type.element_type)) { error = true; @@ -359,14 +359,14 @@ public class Vala.BinaryExpression : Expression { || operator == BinaryOperator.DIV) { // check for pointer arithmetic if (left.value_type is PointerType) { - var pointer_type = (PointerType) left.value_type; + unowned PointerType pointer_type = (PointerType) left.value_type; if (pointer_type.base_type is VoidType) { error = true; Report.error (source_reference, "Pointer arithmetic not supported for `void*'"); return false; } - var offset_type = right.value_type.type_symbol as Struct; + unowned Struct? offset_type = right.value_type.type_symbol as Struct; if (offset_type != null && offset_type.is_integer_type ()) { if (operator == BinaryOperator.PLUS || operator == BinaryOperator.MINUS) { diff --git a/vala/valablock.vala b/vala/valablock.vala index ae30c8b15..c4e8ab74e 100644 --- a/vala/valablock.vala +++ b/vala/valablock.vala @@ -70,7 +70,7 @@ public class Vala.Block : Symbol, Statement { public List get_statements () { var list = new ArrayList (); foreach (Statement stmt in statement_list) { - var stmt_list = stmt as StatementList; + unowned StatementList? stmt_list = stmt as StatementList; if (stmt_list != null) { for (int i = 0; i < stmt_list.length; i++) { list.add (stmt_list.get (i)); @@ -88,7 +88,7 @@ public class Vala.Block : Symbol, Statement { * @param local a variable declarator */ public void add_local_variable (LocalVariable local) { - var parent_block = parent_symbol; + unowned Symbol? parent_block = parent_symbol; while (parent_block is Block || parent_block is Method || parent_block is PropertyAccessor) { if (parent_block.scope.lookup (local.name) != null) { Report.error (local.source_reference, "Local variable `%s' conflicts with a local variable or constant declared in a parent scope".printf (local.name)); @@ -113,7 +113,7 @@ public class Vala.Block : Symbol, Statement { } public void add_local_constant (Constant constant) { - var parent_block = parent_symbol; + unowned Symbol? parent_block = parent_symbol; while (parent_block is Block || parent_block is Method || parent_block is PropertyAccessor) { if (parent_block.scope.lookup (constant.name) != null) { Report.error (constant.source_reference, "Local constant `%s' conflicts with a local variable or constant declared in a parent scope".printf (constant.name)); diff --git a/vala/valacallabletype.vala b/vala/valacallabletype.vala index d0db023bd..14813ec5b 100644 --- a/vala/valacallabletype.vala +++ b/vala/valacallabletype.vala @@ -52,7 +52,7 @@ public abstract class Vala.CallableType : DataType { StringBuilder builder = new StringBuilder (); // Append return-type - var return_type = get_return_type (); + unowned DataType return_type = get_return_type (); if (return_type.is_weak ()) { builder.append ("unowned "); } @@ -67,9 +67,9 @@ public abstract class Vala.CallableType : DataType { builder.append_c ('('); int i = 1; // add sender parameter for internal signal-delegates - var delegate_type = this as DelegateType; + unowned DelegateType? delegate_type = this as DelegateType; if (delegate_type != null) { - var delegate_symbol = delegate_type.delegate_symbol; + unowned Delegate delegate_symbol = delegate_type.delegate_symbol; if (delegate_symbol.parent_symbol is Signal && delegate_symbol.sender_type != null) { builder.append (delegate_symbol.sender_type.to_qualified_string ()); i++; diff --git a/vala/valaclass.vala b/vala/valaclass.vala index 6fb3ff660..fcf239b33 100644 --- a/vala/valaclass.vala +++ b/vala/valaclass.vala @@ -289,7 +289,7 @@ public class Vala.Class : ObjectTypeSymbol { m.name = ".new"; } - var cm = (CreationMethod) m; + unowned CreationMethod cm = (CreationMethod) m; if (cm.class_name != null && cm.class_name != name) { // class_name is null for constructors generated by GIdlParser Report.error (m.source_reference, "missing return type in method `%s.%s´".printf (get_full_name (), cm.class_name)); @@ -732,7 +732,7 @@ public class Vala.Class : ObjectTypeSymbol { /* all abstract symbols defined in base types have to be at least defined (or implemented) also in this type */ foreach (DataType base_type in get_base_types ()) { if (base_type.type_symbol is Interface) { - Interface iface = (Interface) base_type.type_symbol; + unowned Interface iface = (Interface) base_type.type_symbol; if (base_class != null && base_class.is_subtype_of (iface)) { // reimplementation of interface, class is not required to reimplement all methods @@ -747,7 +747,7 @@ public class Vala.Class : ObjectTypeSymbol { foreach (Method m in iface.get_methods ()) { if (m.is_abstract) { var implemented = false; - var base_class = this; + unowned Class? base_class = this; while (base_class != null && !implemented) { foreach (var impl in base_class.get_methods ()) { if (impl.base_interface_method == m || (base_class != this @@ -777,7 +777,7 @@ public class Vala.Class : ObjectTypeSymbol { foreach (Property prop in iface.get_properties ()) { if (prop.is_abstract) { Symbol sym = null; - var base_class = this; + unowned Class? base_class = this; while (base_class != null && !(sym is Property)) { sym = base_class.scope.lookup (prop.name); base_class = base_class.base_class; @@ -804,7 +804,7 @@ public class Vala.Class : ObjectTypeSymbol { /* all abstract symbols defined in base classes have to be implemented in non-abstract classes */ if (!is_abstract) { - var base_class = base_class; + unowned Class? base_class = base_class; while (base_class != null && base_class.is_abstract) { foreach (Method base_method in base_class.get_methods ()) { if (base_method.is_abstract) { diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala index 97aa48136..930fbdf2e 100644 --- a/vala/valacodewriter.vala +++ b/vala/valacodewriter.vala @@ -1476,7 +1476,7 @@ public class Vala.CodeWriter : CodeVisitor { } private void write_type_suffix (DataType type) { - var array_type = type as ArrayType; + unowned ArrayType? array_type = type as ArrayType; if (array_type != null && array_type.fixed_length) { write_string ("["); array_type.length.accept (this); @@ -1555,7 +1555,7 @@ public class Vala.CodeWriter : CodeVisitor { } private void write_attributes (CodeNode node) { - var sym = node as Symbol; + unowned Symbol? sym = node as Symbol; var need_cheaders = type != CodeWriterType.FAST && sym != null && !(sym is Namespace) && sym.parent_symbol is Namespace; diff --git a/vala/valaconstant.vala b/vala/valaconstant.vala index 2fc75afab..519d43b1b 100644 --- a/vala/valaconstant.vala +++ b/vala/valaconstant.vala @@ -141,9 +141,9 @@ public class Vala.Constant : Symbol { // support translated string constants for efficiency / convenience // even though the expression is not a compile-time constant - var call = value as MethodCall; + unowned MethodCall? call = value as MethodCall; if (call != null) { - var method_type = call.call.value_type as MethodType; + unowned MethodType? method_type = call.call.value_type as MethodType; if (method_type != null && method_type.method_symbol.get_full_name () == "GLib._") { // first argument is string var literal = call.get_argument_list ().get (0) as StringLiteral; @@ -183,7 +183,7 @@ public class Vala.Constant : Symbol { if (type is ValueType) { return true; } else if (type is ArrayType) { - var array_type = type as ArrayType; + unowned ArrayType array_type = (ArrayType) type; return check_const_type (array_type.element_type, context); } else if (type.type_symbol.is_subtype_of (context.analyzer.string_type.type_symbol)) { return true; diff --git a/vala/valacreationmethod.vala b/vala/valacreationmethod.vala index ae8daab38..48f301ddf 100644 --- a/vala/valacreationmethod.vala +++ b/vala/valacreationmethod.vala @@ -128,7 +128,7 @@ public class Vala.CreationMethod : Method { if (body != null) { body.check (context); - var cl = parent_symbol as Class; + unowned Class? cl = parent_symbol as Class; // ensure we chain up to base constructor if (!chain_up && cl != null && cl.base_class != null) { diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala index 2a9b33b1f..6dc7cd07f 100644 --- a/vala/valadatatype.vala +++ b/vala/valadatatype.vala @@ -351,8 +351,8 @@ public abstract class Vala.DataType : CodeNode { } if (type_symbol is Struct && target_type.type_symbol is Struct) { - var expr_struct = (Struct) type_symbol; - var expect_struct = (Struct) target_type.type_symbol; + unowned Struct expr_struct = (Struct) type_symbol; + unowned Struct expect_struct = (Struct) target_type.type_symbol; /* integer types may be implicitly cast to floating point types */ if (expr_struct.is_integer_type () && expect_struct.is_floating_type ()) { @@ -549,7 +549,7 @@ public abstract class Vala.DataType : CodeNode { } return string.nfill (array_type.rank, 'a') + element_type_signature; - } else if (type_symbol != null && type_symbol is Enum && type_symbol.get_attribute_bool ("DBus", "use_string_marshalling")) { + } else if (type_symbol is Enum && type_symbol.get_attribute_bool ("DBus", "use_string_marshalling")) { return "s"; } else if (type_symbol != null) { string sig = type_symbol.get_attribute_string ("CCode", "type_signature"); diff --git a/vala/valadeclarationstatement.vala b/vala/valadeclarationstatement.vala index ab652e906..e10302413 100644 --- a/vala/valadeclarationstatement.vala +++ b/vala/valadeclarationstatement.vala @@ -66,7 +66,7 @@ public class Vala.DeclarationStatement : CodeNode, Statement { if (source_reference == null) { source_reference = this.source_reference; } - var local = declaration as LocalVariable; + unowned LocalVariable? local = declaration as LocalVariable; if (local != null && local.initializer != null) { local.initializer.get_error_types (collection, source_reference); } @@ -89,9 +89,9 @@ public class Vala.DeclarationStatement : CodeNode, Statement { } public override void get_defined_variables (Collection collection) { - var local = declaration as LocalVariable; + unowned LocalVariable? local = declaration as LocalVariable; if (local != null) { - var array_type = local.variable_type as ArrayType; + unowned ArrayType? array_type = local.variable_type as ArrayType; if (local.initializer != null) { local.initializer.get_defined_variables (collection); collection.add (local); @@ -102,7 +102,7 @@ public class Vala.DeclarationStatement : CodeNode, Statement { } public override void get_used_variables (Collection collection) { - var local = declaration as LocalVariable; + unowned LocalVariable? local = declaration as LocalVariable; if (local != null && local.initializer != null) { local.initializer.get_used_variables (collection); } diff --git a/vala/valadelegatetype.vala b/vala/valadelegatetype.vala index 91b349081..539b53050 100644 --- a/vala/valadelegatetype.vala +++ b/vala/valadelegatetype.vala @@ -91,7 +91,7 @@ public class Vala.DelegateType : CallableType { } public override bool compatible (DataType target_type) { - var dt_target = target_type as DelegateType; + unowned DelegateType? dt_target = target_type as DelegateType; if (dt_target == null) { return false; } diff --git a/vala/valadostatement.vala b/vala/valadostatement.vala index f34e22358..fb9095858 100644 --- a/vala/valadostatement.vala +++ b/vala/valadostatement.vala @@ -82,7 +82,7 @@ public class Vala.DoStatement : CodeNode, Statement { } bool always_true (Expression condition) { - var literal = condition as BooleanLiteral; + unowned BooleanLiteral? literal = condition as BooleanLiteral; return (literal != null && literal.value); } @@ -105,7 +105,7 @@ public class Vala.DoStatement : CodeNode, Statement { if (always_true (condition)) { var loop = new Loop (body, source_reference); - var parent_block = (Block) parent_node; + unowned Block parent_block = (Block) parent_node; parent_block.replace_statement (this, loop); if (!loop.check (context)) { @@ -134,7 +134,7 @@ public class Vala.DoStatement : CodeNode, Statement { block.add_statement (new Loop (body, source_reference)); - var parent_block = (Block) parent_node; + unowned Block parent_block = (Block) parent_node; parent_block.replace_statement (this, block); if (!block.check (context)) { diff --git a/vala/valaelementaccess.vala b/vala/valaelementaccess.vala index 90c718ff8..9ecc6c67e 100644 --- a/vala/valaelementaccess.vala +++ b/vala/valaelementaccess.vala @@ -171,16 +171,16 @@ public class Vala.ElementAccess : Expression { bool index_int_type_check = true; - var pointer_type = container.value_type as PointerType; + unowned PointerType? pointer_type = container.value_type as PointerType; /* assign a value_type when possible */ if (container.value_type is ArrayType) { - var array_type = (ArrayType) container.value_type; + unowned ArrayType array_type = (ArrayType) container.value_type; value_type = array_type.element_type.copy (); if (!lvalue) { value_type.value_owned = false; } else { - var ma = container as MemberAccess; + unowned MemberAccess? ma = container as MemberAccess; if (context.profile == Profile.GOBJECT && ma != null && ma.symbol_reference is ArrayLengthField) { // propagate lvalue for gobject length access ma.inner.lvalue = true; @@ -209,7 +209,7 @@ public class Vala.ElementAccess : Expression { } else { if (lvalue) { var set_method = container.value_type.get_member ("set") as Method; - var assignment = parent_node as Assignment; + unowned Assignment? assignment = parent_node as Assignment; if (set_method != null && set_method.return_type is VoidType && assignment != null) { return !error; } diff --git a/vala/valaerrortype.vala b/vala/valaerrortype.vala index 868a41b28..26edcaddd 100644 --- a/vala/valaerrortype.vala +++ b/vala/valaerrortype.vala @@ -55,7 +55,7 @@ public class Vala.ErrorType : ReferenceType { return true; } - var et = target_type as ErrorType; + unowned ErrorType? et = target_type as ErrorType; /* error types are only compatible to error types */ if (et == null) { @@ -105,7 +105,7 @@ public class Vala.ErrorType : ReferenceType { } public override bool equals (DataType type2) { - var et = type2 as ErrorType; + unowned ErrorType? et = type2 as ErrorType; if (et == null) { return false; diff --git a/vala/valaexpression.vala b/vala/valaexpression.vala index 885d82b9d..2b9170e42 100644 --- a/vala/valaexpression.vala +++ b/vala/valaexpression.vala @@ -88,10 +88,10 @@ public abstract class Vala.Expression : CodeNode { public Statement? parent_statement { get { - var expr = parent_node as Expression; - var stmt = parent_node as Statement; - var local = parent_node as LocalVariable; - var initializer = parent_node as MemberInitializer; + unowned Expression? expr = parent_node as Expression; + unowned Statement? stmt = parent_node as Statement; + unowned LocalVariable? local = parent_node as LocalVariable; + unowned MemberInitializer? initializer = parent_node as MemberInitializer; if (stmt != null) { return (Statement) parent_node; } else if (expr != null) { diff --git a/vala/valaflowanalyzer.vala b/vala/valaflowanalyzer.vala index 4e81db9e2..978ab94f8 100644 --- a/vala/valaflowanalyzer.vala +++ b/vala/valaflowanalyzer.vala @@ -566,7 +566,7 @@ public class Vala.FlowAnalyzer : CodeVisitor { current_block.add_node (stmt); - var local = stmt.declaration as LocalVariable; + unowned LocalVariable? local = stmt.declaration as LocalVariable; if (local != null && local.initializer != null) { handle_errors (local.initializer); } @@ -590,8 +590,8 @@ public class Vala.FlowAnalyzer : CodeVisitor { handle_errors (stmt); if (stmt.expression is MethodCall) { - var expr = (MethodCall) stmt.expression; - var ma = expr.call as MemberAccess; + unowned MethodCall expr = (MethodCall) stmt.expression; + unowned MemberAccess? ma = expr.call as MemberAccess; if (ma != null && ma.symbol_reference != null && ma.symbol_reference.get_attribute ("NoReturn") != null) { mark_unreachable (); return; @@ -600,12 +600,12 @@ public class Vala.FlowAnalyzer : CodeVisitor { } bool always_true (Expression condition) { - var literal = condition as BooleanLiteral; + unowned BooleanLiteral? literal = condition as BooleanLiteral; return (literal != null && literal.value); } bool always_false (Expression condition) { - var literal = condition as BooleanLiteral; + unowned BooleanLiteral? literal = condition as BooleanLiteral; return (literal != null && !literal.value); } @@ -870,8 +870,8 @@ public class Vala.FlowAnalyzer : CodeVisitor { var error_types = new ArrayList (); node.get_error_types (error_types); foreach (DataType error_data_type in error_types) { - var error_type = error_data_type as ErrorType; - var error_class = error_data_type.type_symbol as Class; + unowned ErrorType? error_type = error_data_type as ErrorType; + unowned Class? error_class = error_data_type.type_symbol as Class; current_block = last_block; unreachable_reported = true; @@ -989,10 +989,10 @@ public class Vala.FlowAnalyzer : CodeVisitor { if (catch_clause.error_type != null) { if (context.profile == Profile.GOBJECT) { - var error_type = (ErrorType) catch_clause.error_type; + unowned ErrorType error_type = (ErrorType) catch_clause.error_type; jump_stack.add (new JumpTarget.error_target (error_block, catch_clause, catch_clause.error_type.type_symbol as ErrorDomain, error_type.error_code, null)); } else { - var error_class = catch_clause.error_type.type_symbol as Class; + unowned Class? error_class = catch_clause.error_type.type_symbol as Class; jump_stack.add (new JumpTarget.error_target (error_block, catch_clause, null, null, error_class)); } } else { diff --git a/vala/valaforstatement.vala b/vala/valaforstatement.vala index 19501c614..0bef2cc3e 100644 --- a/vala/valaforstatement.vala +++ b/vala/valaforstatement.vala @@ -155,12 +155,12 @@ public class Vala.ForStatement : CodeNode, Statement { } bool always_true (Expression condition) { - var literal = condition as BooleanLiteral; + unowned BooleanLiteral? literal = condition as BooleanLiteral; return (literal != null && literal.value); } bool always_false (Expression condition) { - var literal = condition as BooleanLiteral; + unowned BooleanLiteral? literal = condition as BooleanLiteral; return (literal != null && !literal.value); } @@ -209,7 +209,7 @@ public class Vala.ForStatement : CodeNode, Statement { block.add_statement (new Loop (body, source_reference)); - var parent_block = (Block) parent_node; + unowned Block parent_block = (Block) parent_node; parent_block.replace_statement (this, block); if (!block.check (context)) { diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala index 9c7d72dd6..05c300723 100644 --- a/vala/valagenieparser.vala +++ b/vala/valagenieparser.vala @@ -1176,8 +1176,8 @@ public class Vala.Genie.Parser : CodeVisitor { var expr = parse_expression (); - var call = expr as MethodCall; - var object_creation = expr as ObjectCreationExpression; + unowned MethodCall? call = expr as MethodCall; + unowned ObjectCreationExpression? object_creation = expr as ObjectCreationExpression; if (call == null && object_creation == null) { Report.error (expr.source_reference, "syntax error, expected method call"); throw new ParseError.SYNTAX ("expected method call"); @@ -2757,7 +2757,7 @@ public class Vala.Genie.Parser : CodeVisitor { expect_terminator (); // constant arrays don't own their element - var array_type = type as ArrayType; + unowned ArrayType? array_type = type as ArrayType; if (array_type != null) { array_type.element_type.value_owned = false; } diff --git a/vala/valainitializerlist.vala b/vala/valainitializerlist.vala index 5183640f8..50d1ed487 100644 --- a/vala/valainitializerlist.vala +++ b/vala/valainitializerlist.vala @@ -143,7 +143,7 @@ public class Vala.InitializerList : Expression { return false; } else if (target_type is ArrayType) { /* initializer is used as array initializer */ - var array_type = (ArrayType) target_type; + unowned ArrayType array_type = (ArrayType) target_type; bool requires_constants_only = false; unowned CodeNode? node = parent_node; @@ -189,7 +189,7 @@ public class Vala.InitializerList : Expression { } } else if (target_type.type_symbol is Struct) { /* initializer is used as struct initializer */ - var st = (Struct) target_type.type_symbol; + unowned Struct st = (Struct) target_type.type_symbol; while (st.base_struct != null) { st = st.base_struct; } @@ -233,7 +233,7 @@ public class Vala.InitializerList : Expression { continue; } - var unary = e as UnaryExpression; + unowned UnaryExpression? unary = e as UnaryExpression; if (unary != null && (unary.operator == UnaryOperator.REF || unary.operator == UnaryOperator.OUT)) { // TODO check type for ref and out expressions } else if (!e.value_type.compatible (e.target_type)) { diff --git a/vala/valalocalvariable.vala b/vala/valalocalvariable.vala index 24c2f2b19..f6a39ba8e 100644 --- a/vala/valalocalvariable.vala +++ b/vala/valalocalvariable.vala @@ -83,7 +83,7 @@ public class Vala.LocalVariable : Variable { // local reference variables are considered nullable // except when using experimental non-null enhancements if (variable_type is ReferenceType) { - var array_type = variable_type as ArrayType; + unowned ArrayType? array_type = variable_type as ArrayType; if (array_type != null && array_type.fixed_length) { // local fixed length arrays are not nullable } else { @@ -218,7 +218,7 @@ public class Vala.LocalVariable : Variable { // current_symbol is a Method if this is the `result' // variable used for postconditions - var block = context.analyzer.current_symbol as Block; + unowned Block? block = context.analyzer.current_symbol as Block; if (block != null) { block.add_local_variable (this); } diff --git a/vala/valamethod.vala b/vala/valamethod.vala index d118fb50e..4e288a210 100644 --- a/vala/valamethod.vala +++ b/vala/valamethod.vala @@ -609,11 +609,11 @@ public class Vala.Method : Subroutine, Callable { private void find_base_class_method (Class cl) { var sym = cl.scope.lookup (name); if (sym is Signal) { - var sig = (Signal) sym; + unowned Signal sig = (Signal) sym; sym = sig.default_handler; } if (sym is Method) { - var base_method = (Method) sym; + unowned Method base_method = (Method) sym; if (base_method.is_abstract || base_method.is_virtual) { string invalid_match; if (!compatible (base_method, out invalid_match)) { @@ -648,11 +648,11 @@ public class Vala.Method : Subroutine, Callable { var sym = type.type_symbol.scope.lookup (name); if (sym is Signal) { - var sig = (Signal) sym; + unowned Signal sig = (Signal) sym; sym = sig.default_handler; } if (sym is Method) { - var base_method = (Method) sym; + unowned Method base_method = (Method) sym; if (base_method.is_abstract || base_method.is_virtual) { if (base_interface_type == null) { // check for existing explicit implementation @@ -712,7 +712,7 @@ public class Vala.Method : Subroutine, Callable { } if (parent_symbol is Class && (is_abstract || is_virtual)) { - var cl = (Class) parent_symbol; + unowned Class cl = (Class) parent_symbol; if (cl.is_compact && cl.base_class != null) { error = true; Report.error (source_reference, "Abstract and virtual methods may not be declared in derived compact classes"); @@ -728,7 +728,7 @@ public class Vala.Method : Subroutine, Callable { if (is_abstract) { if (parent_symbol is Class) { - var cl = (Class) parent_symbol; + unowned Class cl = (Class) parent_symbol; if (!cl.is_abstract) { error = true; Report.error (source_reference, "Abstract methods may not be declared in non-abstract classes"); @@ -843,16 +843,16 @@ public class Vala.Method : Subroutine, Callable { if (error_types != null) { foreach (DataType error_type in error_types) { - error_type.check (context); + error_type.check (context); - // check whether error type is at least as accessible as the method - if (!context.analyzer.is_type_accessible (this, error_type)) { - error = true; - Report.error (source_reference, "error type `%s' is less accessible than method `%s'".printf (error_type.to_string (), get_full_name ())); - return false; + // check whether error type is at least as accessible as the method + if (!context.analyzer.is_type_accessible (this, error_type)) { + error = true; + Report.error (source_reference, "error type `%s' is less accessible than method `%s'".printf (error_type.to_string (), get_full_name ())); + return false; + } } } - } if (result_var != null) { result_var.check (context); @@ -889,7 +889,7 @@ public class Vala.Method : Subroutine, Callable { } if (base_interface_type != null && base_interface_method != null && parent_symbol is Class) { - var cl = (Class) parent_symbol; + unowned Class cl = (Class) parent_symbol; foreach (var m in cl.get_methods ()) { if (m != this && m.base_interface_method == base_interface_method) { m.checked = true; @@ -1080,7 +1080,7 @@ public class Vala.Method : Subroutine, Callable { return false; } - var array_type = (ArrayType) param.variable_type; + unowned ArrayType array_type = (ArrayType) param.variable_type; if (array_type.element_type.type_symbol != context.analyzer.string_type.type_symbol) { // parameter must be an array of strings return false; diff --git a/vala/valamethodtype.vala b/vala/valamethodtype.vala index 2ebef7451..2fc531870 100644 --- a/vala/valamethodtype.vala +++ b/vala/valamethodtype.vala @@ -41,7 +41,7 @@ public class Vala.MethodType : CallableType { } public override bool compatible (DataType target_type) { - var dt = target_type as DelegateType; + unowned DelegateType? dt = target_type as DelegateType; if (dt == null) { // method types incompatible to anything but delegates return false; diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala index 9e688cf70..410f43afd 100644 --- a/vala/valaobjectcreationexpression.vala +++ b/vala/valaobjectcreationexpression.vala @@ -220,7 +220,7 @@ public class Vala.ObjectCreationExpression : Expression { symbol_reference = constructor; // inner expression can also be base access when chaining constructors - var ma = member_name.inner as MemberAccess; + unowned MemberAccess? ma = member_name.inner as MemberAccess; if (ma != null) { type_args = ma.get_type_arguments (); } diff --git a/vala/valaobjecttype.vala b/vala/valaobjecttype.vala index 97b56e169..154fa3872 100644 --- a/vala/valaobjecttype.vala +++ b/vala/valaobjecttype.vala @@ -55,7 +55,7 @@ public class Vala.ObjectType : ReferenceType { } public override bool stricter (DataType target_type) { - var obj_target_type = target_type as ObjectType; + unowned ObjectType? obj_target_type = target_type as ObjectType; if (obj_target_type == null) { return false; } @@ -72,7 +72,7 @@ public class Vala.ObjectType : ReferenceType { } public override bool is_invokable () { - var cl = type_symbol as Class; + unowned Class? cl = type_symbol as Class; if (cl != null && cl.default_construction_method != null) { return true; } else { @@ -81,7 +81,7 @@ public class Vala.ObjectType : ReferenceType { } public override unowned DataType? get_return_type () { - var cl = type_symbol as Class; + unowned Class? cl = type_symbol as Class; if (cl != null && cl.default_construction_method != null) { return cl.default_construction_method.return_type; } else { @@ -90,7 +90,7 @@ public class Vala.ObjectType : ReferenceType { } public override unowned List? get_parameters () { - var cl = type_symbol as Class; + unowned Class? cl = type_symbol as Class; if (cl != null && cl.default_construction_method != null) { return cl.default_construction_method.get_parameters (); } else { diff --git a/vala/valaparameter.vala b/vala/valaparameter.vala index 19e78a994..978fec737 100644 --- a/vala/valaparameter.vala +++ b/vala/valaparameter.vala @@ -197,9 +197,9 @@ public class Vala.Parameter : Variable { } } - var m = parent_symbol as Method; + unowned Method? m = parent_symbol as Method; if (m != null) { - Method base_method = m.base_method != null ? m.base_method : m.base_interface_method; + unowned Method? base_method = m.base_method != null ? m.base_method : m.base_interface_method; if (base_method != null && base_method != m) { int index = m.get_parameters ().index_of (this); if (index >= 0) { diff --git a/vala/valaparser.vala b/vala/valaparser.vala index 754d50cb5..37d34ec81 100644 --- a/vala/valaparser.vala +++ b/vala/valaparser.vala @@ -779,7 +779,7 @@ public class Vala.Parser : CodeVisitor { if (init_list.size > 0 && inner is MemberAccess) { // struct creation expression - var member = (MemberAccess) inner; + unowned MemberAccess member = (MemberAccess) inner; member.creation_member = true; var expr = new ObjectCreationExpression (member, src); @@ -1000,8 +1000,8 @@ public class Vala.Parser : CodeVisitor { var expr = parse_expression (); - var call = expr as MethodCall; - var object_creation = expr as ObjectCreationExpression; + unowned MethodCall? call = expr as MethodCall; + unowned ObjectCreationExpression? object_creation = expr as ObjectCreationExpression; if (call == null && object_creation == null) { Report.error (expr.source_reference, "syntax error, expected method call"); throw new ParseError.SYNTAX ("expected method call"); @@ -1054,7 +1054,7 @@ public class Vala.Parser : CodeVisitor { if (operator != UnaryOperator.NONE) { next (); var op = parse_unary_expression (); - var lit = op as IntegerLiteral; + unowned IntegerLiteral? lit = op as IntegerLiteral; if (lit != null) { if (operator == UnaryOperator.PLUS) { return lit; @@ -1852,7 +1852,7 @@ public class Vala.Parser : CodeVisitor { var constant_type = parse_type (false, false); // constant arrays don't own their element - var array_type = constant_type as ArrayType; + unowned ArrayType? array_type = constant_type as ArrayType; if (array_type != null) { array_type.element_type.value_owned = false; } @@ -2623,7 +2623,7 @@ public class Vala.Parser : CodeVisitor { type = parse_inline_array_type (type); // constant arrays don't own their element - var array_type = type as ArrayType; + unowned ArrayType? array_type = type as ArrayType; if (array_type != null) { array_type.element_type.value_owned = false; } diff --git a/vala/valapointertype.vala b/vala/valapointertype.vala index ee2864fbd..2a26f92cb 100644 --- a/vala/valapointertype.vala +++ b/vala/valapointertype.vala @@ -55,7 +55,7 @@ public class Vala.PointerType : DataType { public override bool compatible (DataType target_type) { if (target_type is PointerType) { - var tt = target_type as PointerType; + unowned PointerType? tt = target_type as PointerType; if (tt.base_type is VoidType || base_type is VoidType) { return true; @@ -96,7 +96,7 @@ public class Vala.PointerType : DataType { } public override Symbol? get_pointer_member (string member_name) { - Symbol base_symbol = base_type.type_symbol; + unowned Symbol? base_symbol = base_type.type_symbol; if (base_symbol == null) { return null; @@ -138,7 +138,7 @@ public class Vala.PointerType : DataType { } public override DataType? infer_type_argument (TypeParameter type_param, DataType value_type) { - var pointer_type = value_type as PointerType; + unowned PointerType? pointer_type = value_type as PointerType; if (pointer_type != null) { return base_type.infer_type_argument (type_param, pointer_type.base_type); } diff --git a/vala/valapostfixexpression.vala b/vala/valapostfixexpression.vala index 1dd646625..a7849235e 100644 --- a/vala/valapostfixexpression.vala +++ b/vala/valapostfixexpression.vala @@ -78,8 +78,8 @@ public class Vala.PostfixExpression : Expression { public override void get_defined_variables (Collection collection) { inner.get_defined_variables (collection); - var local = inner.symbol_reference as LocalVariable; - var param = inner.symbol_reference as Parameter; + unowned LocalVariable? local = inner.symbol_reference as LocalVariable; + unowned Parameter? param = inner.symbol_reference as Parameter; if (local != null) { collection.add (local); } else if (param != null && param.direction == ParameterDirection.OUT) { @@ -117,7 +117,7 @@ public class Vala.PostfixExpression : Expression { } if (inner is MemberAccess) { - var ma = (MemberAccess) inner; + unowned MemberAccess ma = (MemberAccess) inner; if (ma.prototype_access) { error = true; @@ -131,7 +131,7 @@ public class Vala.PostfixExpression : Expression { return false; } } else if (inner is ElementAccess) { - var ea = (ElementAccess) inner; + unowned ElementAccess ea = (ElementAccess) inner; if (!(ea.container.value_type is ArrayType)) { error = true; Report.error (source_reference, "unsupported lvalue in postfix expression"); @@ -144,10 +144,10 @@ public class Vala.PostfixExpression : Expression { } if (inner is MemberAccess) { - var ma = (MemberAccess) inner; + unowned MemberAccess ma = (MemberAccess) inner; if (ma.symbol_reference is Property) { - var prop = (Property) ma.symbol_reference; + unowned Property prop = (Property) ma.symbol_reference; if (prop.set_accessor == null || !prop.set_accessor.writable) { ma.error = true; diff --git a/vala/valareferencetransferexpression.vala b/vala/valareferencetransferexpression.vala index f9b428997..3363c30f5 100644 --- a/vala/valareferencetransferexpression.vala +++ b/vala/valareferencetransferexpression.vala @@ -124,8 +124,8 @@ public class Vala.ReferenceTransferExpression : Expression { public override void get_defined_variables (Collection collection) { inner.get_defined_variables (collection); - var local = inner.symbol_reference as LocalVariable; - var param = inner.symbol_reference as Parameter; + unowned LocalVariable? local = inner.symbol_reference as LocalVariable; + unowned Parameter? param = inner.symbol_reference as Parameter; if (local != null) { collection.add (local); } else if (param != null && param.direction == ParameterDirection.OUT) { @@ -135,8 +135,8 @@ public class Vala.ReferenceTransferExpression : Expression { public override void get_used_variables (Collection collection) { inner.get_used_variables (collection); - var local = inner.symbol_reference as LocalVariable; - var param = inner.symbol_reference as Parameter; + unowned LocalVariable? local = inner.symbol_reference as LocalVariable; + unowned Parameter? param = inner.symbol_reference as Parameter; if (local != null) { collection.add (local); } else if (param != null && param.direction == ParameterDirection.OUT) { diff --git a/vala/valareturnstatement.vala b/vala/valareturnstatement.vala index f51164968..026dd1f28 100644 --- a/vala/valareturnstatement.vala +++ b/vala/valareturnstatement.vala @@ -131,7 +131,7 @@ public class Vala.ReturnStatement : CodeNode, Statement { return false; } - var local = return_expression.symbol_reference as LocalVariable; + unowned LocalVariable? local = return_expression.symbol_reference as LocalVariable; if (local != null && local.variable_type.is_disposable () && !context.analyzer.current_return_type.value_owned) { error = true; diff --git a/vala/valasignal.vala b/vala/valasignal.vala index 607b75ba7..66c7a89c2 100644 --- a/vala/valasignal.vala +++ b/vala/valasignal.vala @@ -128,7 +128,7 @@ public class Vala.Signal : Symbol, Callable { } if (is_generic) { - var cl = (ObjectTypeSymbol) parent_symbol; + unowned ObjectTypeSymbol cl = (ObjectTypeSymbol) parent_symbol; foreach (var type_param in cl.get_type_parameters ()) { generated_delegate.add_type_parameter (new TypeParameter (type_param.name, type_param.source_reference)); } @@ -136,7 +136,7 @@ public class Vala.Signal : Symbol, Callable { // parameter types must refer to the delegate type parameters // instead of to the class type parameters foreach (var param in generated_delegate.get_parameters ()) { - var generic_type = param.variable_type as GenericType; + unowned GenericType? generic_type = param.variable_type as GenericType; if (generic_type != null) { generic_type.type_parameter = generated_delegate.get_type_parameters ().get (generated_delegate.get_type_parameter_index (generic_type.type_parameter.name)); } @@ -182,7 +182,7 @@ public class Vala.Signal : Symbol, Callable { checked = true; // parent_symbol may be null for dynamic signals - var parent_cl = parent_symbol as Class; + unowned Class? parent_cl = parent_symbol as Class; if (parent_cl != null && parent_cl.is_compact) { error = true; Report.error (source_reference, "Signals are not supported in compact classes"); @@ -235,7 +235,7 @@ public class Vala.Signal : Symbol, Callable { default_handler.add_parameter (param); } - var cl = parent_symbol as ObjectTypeSymbol; + unowned ObjectTypeSymbol? cl = parent_symbol as ObjectTypeSymbol; cl.add_hidden_method (default_handler); default_handler.check (context); @@ -262,7 +262,7 @@ public class Vala.Signal : Symbol, Callable { } emitter.body = body; - var cl = parent_symbol as ObjectTypeSymbol; + unowned ObjectTypeSymbol? cl = parent_symbol as ObjectTypeSymbol; cl.add_hidden_method (emitter); emitter.check (context); diff --git a/vala/valasliceexpression.vala b/vala/valasliceexpression.vala index 563733031..bb280c339 100644 --- a/vala/valasliceexpression.vala +++ b/vala/valasliceexpression.vala @@ -115,7 +115,7 @@ public class Vala.SliceExpression : Expression { } if (container.value_type is ArrayType) { - var array_type = (ArrayType) container.value_type; + unowned ArrayType array_type = (ArrayType) container.value_type; start.target_type = array_type.length_type.copy (); stop.target_type = array_type.length_type.copy (); } diff --git a/vala/valastringliteral.vala b/vala/valastringliteral.vala index d1995576c..4aa931aeb 100644 --- a/vala/valastringliteral.vala +++ b/vala/valastringliteral.vala @@ -98,12 +98,12 @@ public class Vala.StringLiteral : Literal { } public static StringLiteral? get_format_literal (Expression expr) { - var format_literal = expr as StringLiteral; + unowned StringLiteral? format_literal = expr as StringLiteral; if (format_literal != null) { return format_literal; } - var call = expr as MethodCall; + unowned MethodCall? call = expr as MethodCall; if (call != null) { return call.get_format_literal (); } diff --git a/vala/valastruct.vala b/vala/valastruct.vala index b777c4c12..f8b725fd8 100644 --- a/vala/valastruct.vala +++ b/vala/valastruct.vala @@ -332,7 +332,7 @@ public class Vala.Struct : TypeSymbol { * @return true if this is a boolean type, false otherwise */ public bool is_boolean_type () { - var st = base_struct; + unowned Struct? st = base_struct; if (st != null && st.is_boolean_type ()) { return true; } @@ -348,7 +348,7 @@ public class Vala.Struct : TypeSymbol { * @return true if this is an integer type, false otherwise */ public bool is_integer_type () { - var st = base_struct; + unowned Struct? st = base_struct; if (st != null && st.is_integer_type ()) { return true; } @@ -364,7 +364,7 @@ public class Vala.Struct : TypeSymbol { * @return true if this is a floating point type, false otherwise */ public bool is_floating_type () { - var st = base_struct; + unowned Struct? st = base_struct; if (st != null && st.is_floating_type ()) { return true; } @@ -375,7 +375,7 @@ public class Vala.Struct : TypeSymbol { } public bool is_decimal_floating_type () { - var st = base_struct; + unowned Struct? st = base_struct; if (st != null && st.is_decimal_floating_type ()) { return true; } @@ -403,7 +403,7 @@ public class Vala.Struct : TypeSymbol { * instances are passed by value. */ public bool is_simple_type () { - var st = base_struct; + unowned Struct? st = base_struct; if (st != null && st.is_simple_type ()) { return true; } @@ -459,9 +459,9 @@ public class Vala.Struct : TypeSymbol { } bool is_recursive_value_type (DataType type) { - var struct_type = type as StructValueType; + unowned StructValueType? struct_type = type as StructValueType; if (struct_type != null && !struct_type.nullable) { - var st = (Struct) struct_type.type_symbol; + unowned Struct st = (Struct) struct_type.type_symbol; if (st == this) { return true; } diff --git a/vala/valastructvaluetype.vala b/vala/valastructvaluetype.vala index 1413b5d32..bdd20f3cd 100644 --- a/vala/valastructvaluetype.vala +++ b/vala/valastructvaluetype.vala @@ -31,7 +31,7 @@ public class Vala.StructValueType : ValueType { } public override bool is_invokable () { - var st = type_symbol as Struct; + unowned Struct? st = type_symbol as Struct; if (st != null && st.default_construction_method != null) { return true; } else { @@ -40,7 +40,7 @@ public class Vala.StructValueType : ValueType { } public override unowned DataType? get_return_type () { - var st = type_symbol as Struct; + unowned Struct? st = type_symbol as Struct; if (st != null && st.default_construction_method != null) { return st.default_construction_method.return_type; } else { @@ -49,7 +49,7 @@ public class Vala.StructValueType : ValueType { } public override unowned List? get_parameters () { - var st = type_symbol as Struct; + unowned Struct? st = type_symbol as Struct; if (st != null && st.default_construction_method != null) { return st.default_construction_method.get_parameters (); } else { diff --git a/vala/valasymbolresolver.vala b/vala/valasymbolresolver.vala index bb36b54be..dbe9b1f21 100644 --- a/vala/valasymbolresolver.vala +++ b/vala/valasymbolresolver.vala @@ -402,7 +402,7 @@ public class Vala.SymbolResolver : CodeVisitor { if (sym is Delegate) { type = new DelegateType ((Delegate) sym); } else if (sym is Class) { - var cl = (Class) sym; + unowned Class cl = (Class) sym; if (cl.is_error_base) { type = new ErrorType (null, null, unresolved_type.source_reference); } else { diff --git a/vala/valaunaryexpression.vala b/vala/valaunaryexpression.vala index af4ede95d..4e2b50b90 100644 --- a/vala/valaunaryexpression.vala +++ b/vala/valaunaryexpression.vala @@ -87,7 +87,7 @@ public class Vala.UnaryExpression : Expression { } if (operator == UnaryOperator.REF || operator == UnaryOperator.OUT) { - var field = inner.symbol_reference as Field; + unowned Field? field = inner.symbol_reference as Field; if (field != null && field.binding == MemberBinding.STATIC) { return true; } else { @@ -111,20 +111,20 @@ public class Vala.UnaryExpression : Expression { } bool is_numeric_type (DataType type) { - if (type.nullable || !(type.type_symbol is Struct)) { + unowned Struct? st = type.type_symbol as Struct; + if (type.nullable || st == null) { return false; } - var st = (Struct) type.type_symbol; return st.is_integer_type () || st.is_floating_type (); } bool is_integer_type (DataType type) { - if (type.nullable || !(type.type_symbol is Struct)) { + unowned Struct? st = type.type_symbol as Struct; + if (type.nullable || st == null) { return false; } - var st = (Struct) type.type_symbol; return st.is_integer_type (); } @@ -219,7 +219,7 @@ public class Vala.UnaryExpression : Expression { assignment.check (context); return true; } else if (operator == UnaryOperator.REF || operator == UnaryOperator.OUT) { - var ea = inner as ElementAccess; + unowned ElementAccess? ea = inner as ElementAccess; if (inner.symbol_reference is Field || inner.symbol_reference is Parameter || inner.symbol_reference is LocalVariable || (ea != null && ea.container.value_type is ArrayType)) { // ref and out can only be used with fields, parameters, local variables, and array element access @@ -252,8 +252,8 @@ public class Vala.UnaryExpression : Expression { public override void get_defined_variables (Collection collection) { inner.get_defined_variables (collection); if (operator == UnaryOperator.OUT || operator == UnaryOperator.REF) { - var local = inner.symbol_reference as LocalVariable; - var param = inner.symbol_reference as Parameter; + unowned LocalVariable? local = inner.symbol_reference as LocalVariable; + unowned Parameter? param = inner.symbol_reference as Parameter; if (local != null) { collection.add (local); } diff --git a/vala/valaunresolvedsymbol.vala b/vala/valaunresolvedsymbol.vala index 40b437159..5e4791d44 100644 --- a/vala/valaunresolvedsymbol.vala +++ b/vala/valaunresolvedsymbol.vala @@ -40,7 +40,7 @@ public class Vala.UnresolvedSymbol : Symbol { } public static UnresolvedSymbol? new_from_expression (Expression expr) { - var ma = expr as MemberAccess; + unowned MemberAccess? ma = expr as MemberAccess; if (ma != null) { if (ma.inner != null) { return new UnresolvedSymbol (new_from_expression (ma.inner), ma.member_name, ma.source_reference); diff --git a/vala/valawhilestatement.vala b/vala/valawhilestatement.vala index a15b1abe8..b91867817 100644 --- a/vala/valawhilestatement.vala +++ b/vala/valawhilestatement.vala @@ -82,12 +82,12 @@ public class Vala.WhileStatement : CodeNode, Statement { } bool always_true (Expression condition) { - var literal = condition as BooleanLiteral; + unowned BooleanLiteral? literal = condition as BooleanLiteral; return (literal != null && literal.value); } bool always_false (Expression condition) { - var literal = condition as BooleanLiteral; + unowned BooleanLiteral? literal = condition as BooleanLiteral; return (literal != null && !literal.value); } @@ -121,7 +121,7 @@ public class Vala.WhileStatement : CodeNode, Statement { var loop = new Loop (body, source_reference); - var parent_block = (Block) parent_node; + unowned Block parent_block = (Block) parent_node; parent_block.replace_statement (this, loop); if (!loop.check (context)) {