[vala] Replace current_return_type field by property
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vala] Replace current_return_type field by property
- Date: Sun, 16 Aug 2009 10:21:16 +0000 (UTC)
commit 886feff1492d82d6fdac1022012e9d31f7482146
Author: Jürg Billeter <j bitron ch>
Date: Sun Aug 16 12:19:04 2009 +0200
Replace current_return_type field by property
codegen/valaccodebasemodule.vala | 50 ++++++++++++++++++++++-------------
codegen/valaccodemethodmodule.vala | 3 --
vala/valacreationmethod.vala | 9 ------
vala/valamethod.vala | 11 +-------
vala/valapropertyaccessor.vala | 8 ------
vala/valasemanticanalyzer.vala | 42 +++++++++++++++++++++++++++++-
6 files changed, 73 insertions(+), 50 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 1939e42..aceec9a 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -32,9 +32,25 @@ internal class Vala.CCodeBaseModule : CCodeModule {
public Symbol root_symbol;
public Symbol current_symbol;
- public DataType current_return_type;
public TryStatement current_try;
+ public TypeSymbol? current_type_symbol {
+ get {
+ var sym = current_symbol;
+ while (sym != null) {
+ if (sym is TypeSymbol) {
+ return (TypeSymbol) sym;
+ }
+ sym = sym.parent_symbol;
+ }
+ return null;
+ }
+ }
+
+ public Class? current_class {
+ get { return current_type_symbol as Class; }
+ }
+
public Method? current_method {
get {
var sym = current_symbol;
@@ -55,23 +71,26 @@ internal class Vala.CCodeBaseModule : CCodeModule {
}
}
- public TypeSymbol? current_type_symbol {
+ public DataType? current_return_type {
get {
- var sym = current_symbol;
- while (sym != null) {
- if (sym is TypeSymbol) {
- return (TypeSymbol) sym;
+ var m = current_method;
+ if (m != null) {
+ return m.return_type;
+ }
+
+ var acc = current_property_accessor;
+ if (acc != null) {
+ if (acc.readable) {
+ return acc.value_type;
+ } else {
+ return void_type;
}
- sym = sym.parent_symbol;
}
+
return null;
}
}
- public Class? current_class {
- get { return current_type_symbol as Class; }
- }
-
public CCodeDeclarationSpace header_declarations;
public CCodeDeclarationSpace internal_header_declarations;
public CCodeDeclarationSpace source_declarations;
@@ -114,6 +133,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
public bool current_method_inner_error = false;
public int next_coroutine_state = 1;
+ public DataType void_type = new VoidType ();
public DataType bool_type;
public DataType char_type;
public DataType uchar_type;
@@ -1276,13 +1296,6 @@ internal class Vala.CCodeBaseModule : CCodeModule {
bool returns_real_struct = prop.property_type.is_real_struct_type ();
- var old_return_type = current_return_type;
- if (acc.readable && !returns_real_struct) {
- current_return_type = acc.value_type;
- } else {
- current_return_type = new VoidType ();
- }
-
acc.accept_children (codegen);
var t = (ObjectTypeSymbol) prop.parent_symbol;
@@ -1508,7 +1521,6 @@ internal class Vala.CCodeBaseModule : CCodeModule {
}
current_symbol = old_symbol;
- current_return_type = old_return_type;
current_method_inner_error = old_method_inner_error;
}
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index d1ada7e..93150df 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -184,7 +184,6 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
public override void visit_method (Method m) {
var old_symbol = current_symbol;
- DataType old_return_type = current_return_type;
bool old_method_inner_error = current_method_inner_error;
bool old_in_creation_method = in_creation_method;
int old_next_temp_var_id = next_temp_var_id;
@@ -193,7 +192,6 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
var old_variable_name_map = variable_name_map;
var old_try = current_try;
current_symbol = m;
- current_return_type = m.return_type;
current_method_inner_error = false;
next_temp_var_id = 0;
temp_vars = new ArrayList<LocalVariable> ();
@@ -299,7 +297,6 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
bool inner_error = current_method_inner_error;
current_symbol = old_symbol;
- current_return_type = old_return_type;
current_method_inner_error = old_method_inner_error;
next_temp_var_id = old_next_temp_var_id;
temp_vars = old_temp_vars;
diff --git a/vala/valacreationmethod.vala b/vala/valacreationmethod.vala
index e73a195..7f78ae4 100644
--- a/vala/valacreationmethod.vala
+++ b/vala/valacreationmethod.vala
@@ -134,13 +134,11 @@ public class Vala.CreationMethod : Method {
var old_source_file = analyzer.current_source_file;
var old_symbol = analyzer.current_symbol;
- var old_return_type = analyzer.current_return_type;
if (source_reference != null) {
analyzer.current_source_file = source_reference.file;
}
analyzer.current_symbol = this;
- analyzer.current_return_type = return_type;
foreach (FormalParameter param in get_parameters()) {
param.check (analyzer);
@@ -156,13 +154,6 @@ public class Vala.CreationMethod : Method {
analyzer.current_source_file = old_source_file;
analyzer.current_symbol = old_symbol;
- analyzer.current_return_type = old_return_type;
-
- if (analyzer.current_symbol.parent_symbol is Method) {
- /* lambda expressions produce nested methods */
- var up_method = (Method) analyzer.current_symbol.parent_symbol;
- analyzer.current_return_type = up_method.return_type;
- }
if (is_abstract || is_virtual || overrides) {
Report.error (source_reference, "The creation method `%s' cannot be marked as override, virtual, or abstract".printf (get_full_name ()));
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index e26c56f..51ea569 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -720,13 +720,11 @@ public class Vala.Method : Member {
var old_source_file = analyzer.current_source_file;
var old_symbol = analyzer.current_symbol;
- var old_return_type = analyzer.current_return_type;
if (source_reference != null) {
analyzer.current_source_file = source_reference.file;
}
analyzer.current_symbol = this;
- analyzer.current_return_type = return_type;
return_type.check (analyzer);
@@ -765,15 +763,8 @@ public class Vala.Method : Member {
analyzer.current_source_file = old_source_file;
analyzer.current_symbol = old_symbol;
- analyzer.current_return_type = old_return_type;
- if (analyzer.current_symbol.parent_symbol is Method) {
- /* lambda expressions produce nested methods */
- var up_method = (Method) analyzer.current_symbol.parent_symbol;
- analyzer.current_return_type = up_method.return_type;
- }
-
- if (analyzer.current_symbol is Struct) {
+ if (analyzer.current_struct != null) {
if (is_abstract || is_virtual || overrides) {
Report.error (source_reference, "A struct member `%s' cannot be marked as override, virtual, or abstract".printf (get_full_name ()));
return false;
diff --git a/vala/valapropertyaccessor.vala b/vala/valapropertyaccessor.vala
index 63cbfe0..b37f08e 100644
--- a/vala/valapropertyaccessor.vala
+++ b/vala/valapropertyaccessor.vala
@@ -170,15 +170,8 @@ public class Vala.PropertyAccessor : Symbol {
}
var old_symbol = analyzer.current_symbol;
- var old_return_type = analyzer.current_return_type;
analyzer.current_symbol = this;
- if (readable) {
- analyzer.current_return_type = value_type;
- } else {
- // void
- analyzer.current_return_type = new VoidType ();
- }
if (!prop.external_package) {
if (body == null && !prop.interface_only && !prop.is_abstract) {
@@ -211,7 +204,6 @@ public class Vala.PropertyAccessor : Symbol {
}
analyzer.current_symbol = old_symbol;
- analyzer.current_return_type = old_return_type;
return !error;
}
diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala
index c62fe5e..147e602 100644
--- a/vala/valasemanticanalyzer.vala
+++ b/vala/valasemanticanalyzer.vala
@@ -34,7 +34,6 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
public Symbol root_symbol;
public Symbol current_symbol { get; set; }
public SourceFile current_source_file { get; set; }
- public DataType current_return_type;
public TypeSymbol? current_type_symbol {
get {
@@ -58,8 +57,49 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
get { return current_type_symbol as Struct; }
}
+ public Method? current_method {
+ get {
+ var sym = current_symbol;
+ while (sym is Block) {
+ sym = sym.parent_symbol;
+ }
+ return sym as Method;
+ }
+ }
+
+ public PropertyAccessor? current_property_accessor {
+ get {
+ var sym = current_symbol;
+ while (sym is Block) {
+ sym = sym.parent_symbol;
+ }
+ return sym as PropertyAccessor;
+ }
+ }
+
+ public DataType? current_return_type {
+ get {
+ var m = current_method;
+ if (m != null) {
+ return m.return_type;
+ }
+
+ var acc = current_property_accessor;
+ if (acc != null) {
+ if (acc.readable) {
+ return acc.value_type;
+ } else {
+ return void_type;
+ }
+ }
+
+ return null;
+ }
+ }
+
public Block insert_block;
+ public DataType void_type = new VoidType ();
public DataType bool_type;
public DataType string_type;
public DataType uchar_type;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]