[vala/wip/issue/327] Cleaning



commit 8fc04f0b7b311116c915b2fab18bb0cf59a1df3c
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun Apr 12 22:30:00 2020 +0200

    Cleaning

 vala/valawithstatement.vala | 76 +++++++++++++++++++++++----------------------
 1 file changed, 39 insertions(+), 37 deletions(-)
---
diff --git a/vala/valawithstatement.vala b/vala/valawithstatement.vala
index a1506902e..ecc79b1b5 100644
--- a/vala/valawithstatement.vala
+++ b/vala/valawithstatement.vala
@@ -20,8 +20,6 @@
  *     Nick Schrader <nick schrader mailbox org>
  */
 
-using GLib;
-
 public class Vala.WithStatement : Block {
        private static int next_with_id = 0;
 
@@ -72,9 +70,9 @@ public class Vala.WithStatement : Block {
                }
        }
 
-       private Expression _expression;
-       private Block _body;
-       private DataType? _data_type;
+       Expression _expression;
+       Block _body;
+       DataType? _data_type;
 
        public WithStatement (DataType? type_reference, string? variable_name, Expression expression,
                        Block body, SourceReference? source_reference = null) {
@@ -126,46 +124,50 @@ public class Vala.WithStatement : Block {
                }
        }
 
-       bool is_type_reference_compatible () {
-               if (type_reference == null) {
-                       type_reference = expression.value_type.copy ();
-               }
-
-               return expression.value_type.compatible (type_reference);
-       }
-
        public override bool check (CodeContext context) {
                if (checked) {
                        return !error;
                }
 
                checked = true;
-               if (expression.check (context)) {
-                       if (!is_object_or_value_type (expression.value_type)) {
-                               error = true;
-                               Report.error (expression.source_reference, "With: Expression must be of an 
object or basic type");
-                       } else if (!is_type_reference_compatible ()) {
-                               error = true;
-                               Report.error (type_reference.source_reference, "With: Cannot convert from %s 
to %s".printf(expression.value_type.to_string(), type_reference.to_string()));
-                       } else {
-                               var local_var = expression.symbol_reference as LocalVariable;
-                               if (with_variable_name != null || local_var == null) {
-                                       var n = with_variable_name ?? "_with_local%d_".printf 
(next_with_id++);
-                                       local_var = new LocalVariable (type_reference, n, expression, 
source_reference);
-                                       body.insert_statement (0, new DeclarationStatement (local_var, 
source_reference));
-                               }
-                               with_variable = local_var;
-
-                               var old_symbol = context.analyzer.current_symbol;
-                               owner = context.analyzer.current_symbol.scope;
-                               context.analyzer.current_symbol = this;
-                               error |= !body.check (context);
-                               context.analyzer.current_symbol = old_symbol;
-                       }
-               } else {
-                       error |= true;
+
+               if (!expression.check (context)) {
+                       error = true;
+                       return false;
                }
 
+               if (!is_object_or_value_type (expression.value_type)) {
+                       error = true;
+                       Report.error (expression.source_reference, "with statement expects an object or basic 
type");
+                       return false;
+               } else if (type_reference != null && !expression.value_type.compatible (type_reference)) {
+                       error = true;
+                       Report.error (expression.source_reference, "Cannot convert from `%s' to `%s'".printf 
(expression.value_type.to_string (), type_reference.to_string ()));
+                       return false;
+               }
+
+               if (type_reference == null) {
+                       type_reference = expression.value_type.copy ();
+               }
+
+               var local_var = expression.symbol_reference as LocalVariable;
+               if (with_variable_name != null || local_var == null) {
+                       var n = with_variable_name ?? "_with_local%d_".printf (next_with_id++);
+                       local_var = new LocalVariable (type_reference, n, expression, source_reference);
+                       body.insert_statement (0, new DeclarationStatement (local_var, source_reference));
+               }
+               with_variable = local_var;
+
+               var old_symbol = context.analyzer.current_symbol;
+               owner = context.analyzer.current_symbol.scope;
+               context.analyzer.current_symbol = this;
+
+               if (!body.check (context)) {
+                       error = true;
+               }
+
+               context.analyzer.current_symbol = old_symbol;
+
                return !error;
        }
 


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