[vala/wip/transform: 338/373] Fix get_current_* methods in the semantic analyzer
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 338/373] Fix get_current_* methods in the semantic analyzer
- Date: Mon, 22 Oct 2018 15:00:30 +0000 (UTC)
commit 4a325a51065af3b777d5b8b6a306474eda9482d4
Author: Luca Bruno <lucabru src gnome org>
Date: Thu May 2 20:32:51 2013 +0200
Fix get_current_* methods in the semantic analyzer
codegen/valaccodetransformer.vala | 6 +++---
vala/valablock.vala | 2 +-
vala/valaconditionalexpression.vala | 2 +-
vala/valacreationmethod.vala | 2 +-
vala/valalambdaexpression.vala | 2 +-
vala/valalocalvariable.vala | 17 ++++++++++-------
vala/valamemberaccess.vala | 6 +++---
vala/valaobjectcreationexpression.vala | 2 +-
vala/valasemanticanalyzer.vala | 27 +++++++++++++++++----------
9 files changed, 38 insertions(+), 28 deletions(-)
---
diff --git a/codegen/valaccodetransformer.vala b/codegen/valaccodetransformer.vala
index 8941b7778..bd64fb030 100644
--- a/codegen/valaccodetransformer.vala
+++ b/codegen/valaccodetransformer.vala
@@ -363,7 +363,7 @@ public class Vala.CCodeTransformer : CodeTransformer {
if (expr.tree_can_fail) {
if (expr.parent_node is LocalVariable || expr.parent_node is ExpressionStatement) {
// simple statements, no side effects after method call
- } else if (!(context.analyzer.get_current_symbol (expr) is Block)) {
+ } else if (!(context.analyzer.get_current_non_local_symbol (expr) is Block)) {
// can't handle errors in field initializers
Report.error (expr.source_reference, "Field initializers must not throw
errors");
} else {
@@ -424,7 +424,7 @@ public class Vala.CCodeTransformer : CodeTransformer {
var target_type = expr.target_type != null ? expr.target_type.copy () : null;
push_builder (new CodeBuilder (context, parent_statement, expr.source_reference));
- if (context.analyzer.get_current_symbol (expr) is Block
+ if (context.analyzer.get_current_non_local_symbol (expr) is Block
&& (expr.operator == BinaryOperator.AND || expr.operator == BinaryOperator.OR)) {
var is_and = expr.operator == BinaryOperator.AND;
var result = b.add_temp_declaration (data_type ("bool"));
@@ -499,7 +499,7 @@ public class Vala.CCodeTransformer : CodeTransformer {
if (expr.tree_can_fail) {
if (expr.parent_node is LocalVariable || expr.parent_node is ExpressionStatement) {
// simple statements, no side effects after method call
- } else if (!(context.analyzer.get_current_symbol (expr) is Block)) {
+ } else if (!(context.analyzer.get_current_non_local_symbol (expr) is Block)) {
// can't handle errors in field initializers
Report.error (expr.source_reference, "Field initializers must not throw
errors");
} else {
diff --git a/vala/valablock.vala b/vala/valablock.vala
index 79c1c630b..3e82d8014 100644
--- a/vala/valablock.vala
+++ b/vala/valablock.vala
@@ -154,7 +154,7 @@ public class Vala.Block : Symbol, Statement {
checked = true;
- owner = context.analyzer.get_current_symbol (parent_node).scope;
+ owner = context.analyzer.get_current_non_local_symbol (parent_node).scope;
foreach (var stmt in this) {
stmt.check (context);
diff --git a/vala/valaconditionalexpression.vala b/vala/valaconditionalexpression.vala
index 7d80edda3..f70c8c004 100644
--- a/vala/valaconditionalexpression.vala
+++ b/vala/valaconditionalexpression.vala
@@ -133,7 +133,7 @@ public class Vala.ConditionalExpression : Expression {
checked = true;
- if (!(context.analyzer.get_current_symbol (this) is Block)) {
+ if (!(context.analyzer.get_current_non_local_symbol (this) is Block)) {
Report.error (source_reference, "Conditional expressions may only be used in blocks");
error = true;
return false;
diff --git a/vala/valacreationmethod.vala b/vala/valacreationmethod.vala
index b1b4fc862..e201624a9 100644
--- a/vala/valacreationmethod.vala
+++ b/vala/valacreationmethod.vala
@@ -88,7 +88,7 @@ public class Vala.CreationMethod : Method {
if (class_name != null && class_name != parent_symbol.name) {
// class_name is null for constructors generated by GIdlParser
- Report.error (source_reference, "missing return type in method `%s.%s´".printf
(context.analyzer.get_current_symbol (this).get_full_name (), class_name));
+ Report.error (source_reference, "missing return type in method `%s.%s´".printf
(context.analyzer.get_current_symbol (parent_node).get_full_name (), class_name));
error = true;
return false;
}
diff --git a/vala/valalambdaexpression.vala b/vala/valalambdaexpression.vala
index 705974b38..45eb6c330 100644
--- a/vala/valalambdaexpression.vala
+++ b/vala/valalambdaexpression.vala
@@ -159,7 +159,7 @@ public class Vala.LambdaExpression : Expression {
sym = sym.parent_symbol;
}
}
- method.owner = context.analyzer.get_current_symbol (this).scope;
+ method.owner = context.analyzer.get_current_non_local_symbol (this).scope;
var lambda_params = get_parameters ();
Iterator<Parameter> lambda_param_it = lambda_params.iterator ();
diff --git a/vala/valalocalvariable.vala b/vala/valalocalvariable.vala
index 76787449e..aa0fbbde2 100644
--- a/vala/valalocalvariable.vala
+++ b/vala/valalocalvariable.vala
@@ -92,6 +92,16 @@ public class Vala.LocalVariable : Variable {
}
}
+ // current_symbol is a Method if this is the `result'
+ // variable used for postconditions
+ var block = context.analyzer.get_current_block (this);
+ if (block != null) {
+ /* so that we can use parent_symbol */
+ block.add_local_variable (this);
+ }
+
+ active = false;
+
if (variable_type != null) {
if (variable_type is VoidType) {
error = true;
@@ -205,13 +215,6 @@ public class Vala.LocalVariable : Variable {
}
}
- // current_symbol is a Method if this is the `result'
- // variable used for postconditions
- var block = context.analyzer.get_current_block (this);
- if (block != null) {
- block.add_local_variable (this);
- }
-
active = true;
return !error;
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index b65d5e6a1..258e7e06f 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -233,7 +233,7 @@ public class Vala.MemberAccess : Expression {
}
}
- base_symbol = context.analyzer.get_current_symbol (this);
+ base_symbol = context.analyzer.get_current_non_local_symbol (this);
// track whether method has been found to make sure that access
// to instance member is denied from within static lambda expressions
@@ -720,7 +720,7 @@ public class Vala.MemberAccess : Expression {
var target_type = (TypeSymbol) member.parent_symbol;
bool in_subtype = false;
- for (Symbol this_symbol = context.analyzer.get_current_symbol (this); this_symbol !=
null; this_symbol = this_symbol.parent_symbol) {
+ for (Symbol this_symbol = context.analyzer.get_current_non_local_symbol (this);
this_symbol != null; this_symbol = this_symbol.parent_symbol) {
if (this_symbol == target_type) {
// required for interfaces with non-abstract methods
// accessing protected interface members
@@ -744,7 +744,7 @@ public class Vala.MemberAccess : Expression {
var target_type = member.parent_symbol;
bool in_target_type = false;
- for (Symbol this_symbol = context.analyzer.get_current_symbol (this); this_symbol !=
null; this_symbol = this_symbol.parent_symbol) {
+ for (Symbol this_symbol = context.analyzer.get_current_non_local_symbol (this);
this_symbol != null; this_symbol = this_symbol.parent_symbol) {
if (target_type == this_symbol) {
in_target_type = true;
break;
diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala
index 66e1a12d7..9aa18a813 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -293,7 +293,7 @@ public class Vala.ObjectCreationExpression : Expression {
if (symbol_reference != null
&& (symbol_reference.access == SymbolAccessibility.PRIVATE ||
symbol_reference.access == SymbolAccessibility.PROTECTED)) {
bool in_target_type = false;
- for (Symbol this_symbol = context.analyzer.get_current_symbol (this);
this_symbol != null; this_symbol = this_symbol.parent_symbol) {
+ for (Symbol this_symbol = context.analyzer.get_current_non_local_symbol
(this); this_symbol != null; this_symbol = this_symbol.parent_symbol) {
if (this_symbol == cl) {
in_target_type = true;
break;
diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala
index fcddc89d0..40b6d7aab 100644
--- a/vala/valasemanticanalyzer.vala
+++ b/vala/valasemanticanalyzer.vala
@@ -127,18 +127,22 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
file.check (context);
}
- public unowned Symbol get_current_symbol (CodeNode node) {
- while (!(node is Symbol) || is_local_symbol ((Symbol) node)) {
+ public unowned Symbol? get_current_symbol (CodeNode node) {
+ while (node != null && !(node is Symbol)) {
node = node.parent_node;
}
return (Symbol) node;
}
- public bool is_local_symbol (Symbol sym) {
- if (sym is LocalVariable) {
- return true;
+ public unowned Symbol? get_current_non_local_symbol (CodeNode node) {
+ while (node != null && (!(node is Symbol) || is_local_symbol ((Symbol) node))) {
+ node = node.parent_node;
+ }
+ return (Symbol) node;
}
- if (sym is Constant && sym.parent_symbol is Block) {
+
+ public bool is_local_symbol (Symbol sym) {
+ if ((sym is LocalVariable || sym is Constant) && sym.parent_symbol is Block) {
return true;
}
return false;
@@ -163,7 +167,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
public unowned Method? get_current_method (CodeNode node) {
unowned Symbol sym = get_current_symbol (node);
- while (sym is Block) {
+ while (sym != null && !(sym is Method)) {
sym = sym.parent_symbol;
}
return sym as Method;
@@ -179,7 +183,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
public unowned PropertyAccessor? get_current_property_accessor (CodeNode node) {
unowned Symbol sym = get_current_symbol (node);
- while (sym is Block) {
+ while (sym != null && !(sym is PropertyAccessor)) {
sym = sym.parent_symbol;
}
return sym as PropertyAccessor;
@@ -187,7 +191,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
public unowned Symbol? get_current_method_or_property_accessor (CodeNode node) {
unowned Symbol sym = get_current_symbol (node);
- while (sym is Block) {
+ while (sym != null && !(sym is Method) && !(sym is PropertyAccessor)) {
sym = sym.parent_symbol;
}
if (sym is Method) {
@@ -222,7 +226,10 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
}
public unowned Block? get_current_block (CodeNode node) {
- return get_current_symbol (node) as Block;
+ while (node != null && !(node is Block)) {
+ node = node.parent_node;
+ }
+ return (Block) node;
}
// check whether type is at least as accessible as the specified symbol
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]