[vala/wip/issue/327: 25/27] Cleaning
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/issue/327: 25/27] Cleaning
- Date: Mon, 27 Apr 2020 12:16:07 +0000 (UTC)
commit 3fd2fcee9306a3c064f37d479fa6faa1a2d24a9b
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]