[vala/wip/issue/327: 18/26] First version, seems to work
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/issue/327: 18/26] First version, seems to work
- Date: Sat, 28 Mar 2020 11:54:52 +0000 (UTC)
commit 628ab2944fba72ab05beafb3b1c36cf5d58bbe26
Author: Nick Schrader <nick schrader mailbox org>
Date: Fri Mar 27 20:53:59 2020 -0300
First version, seems to work
codegen/valaccodememberaccessmodule.vala | 3 +++
tmp/with.vala | 2 +-
vala/valamemberaccess.vala | 22 +++++++++++++++++++---
vala/valasemanticanalyzer.vala | 14 ++++++++++----
with | Bin 23160 -> 23160 bytes
5 files changed, 33 insertions(+), 8 deletions(-)
---
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index ed838cb20..1393008b9 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -587,6 +587,9 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
/* Returns lvalue access to the given field */
public override TargetValue get_field_cvalue (Field field, TargetValue? instance) {
+ if (field.name == "field")
+ stdout.printf("Field name: %s\n", field.name);
+
var value_type = field.variable_type.copy ();
var result = new GLibValue (value_type);
diff --git a/tmp/with.vala b/tmp/with.vala
index 5b35015d9..319381ede 100644
--- a/tmp/with.vala
+++ b/tmp/with.vala
@@ -13,7 +13,7 @@ class Foo {
void main() {
var foo = new Foo();
// foo.print();
- //foo.field = 0;
+ foo.field = 0;
with(foo) {
field = 42;
prop = "foo";
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 3cef59c9c..45ee4b83c 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -225,6 +225,7 @@ public class Vala.MemberAccess : Expression {
bool may_access_klass_members = false;
symbol_reference = null;
+ var is_with = false;
if (qualified) {
base_symbol = context.root;
@@ -284,6 +285,7 @@ public class Vala.MemberAccess : Expression {
}
symbol_reference = SemanticAnalyzer.symbol_lookup_inherited (sym,
member_name);
+ stdout.printf("symbol_reference: %s\n", symbol_reference != null ?
symbol_reference.name : "(null)");
if (symbol_reference == null && sym is TypeSymbol &&
may_access_instance_members) {
// used for generated to_string methods in enums
@@ -309,6 +311,17 @@ public class Vala.MemberAccess : Expression {
}
}
+ if (symbol_reference == null && sym is WithStatement) {
+ unowned WithStatement w = (WithStatement) sym;
+ var e = w.expression;
+ base_symbol = e.value_type.type_symbol;
+ symbol_reference = e.value_type.get_member (member_name);
+ may_access_instance_members = true;
+ may_access_klass_members = true;
+ is_with = true;
+ inner = e;
+ }
+
var x = "null";
if (sym != null)
x = Type.from_instance(sym).name();
@@ -373,6 +386,7 @@ public class Vala.MemberAccess : Expression {
if (symbol_reference == null && (base_symbol is Namespace || base_symbol is
TypeSymbol)) {
symbol_reference = base_symbol.scope.lookup (member_name);
+ stdout.printf("Inner symbol_reference %s, synmol_reference_name
%s\n", Type.from_instance(symbol_reference).name(), symbol_reference.name);
if (inner is BaseAccess) {
// inner expression is base access
// access to instance members of the base type possible
@@ -865,7 +879,7 @@ public class Vala.MemberAccess : Expression {
}
} else {
// implicit this access
- if (instance && inner == null) {
+ if (instance && inner == null && !is_with) {
inner = new MemberAccess (null, "this", source_reference);
inner.value_type = this_parameter.variable_type.copy ();
inner.value_type.value_owned = false;
@@ -918,11 +932,13 @@ public class Vala.MemberAccess : Expression {
}
} else if (symbol_reference is Property
&& instance && symbol_reference.parent_symbol != null) {
- inner.target_type = SemanticAnalyzer.get_data_type_for_symbol
(symbol_reference.parent_symbol);
+ if (inner != null)
+ inner.target_type = SemanticAnalyzer.get_data_type_for_symbol
(symbol_reference.parent_symbol);
} else if ((symbol_reference is Field || symbol_reference is Signal)
&& instance && symbol_reference.parent_symbol != null) {
var parent_type = SemanticAnalyzer.get_data_type_for_symbol
(symbol_reference.parent_symbol);
- inner.target_type = parent_type.get_actual_type (inner.value_type, null,
this);
+ if (inner != null)
+ inner.target_type = parent_type.get_actual_type (inner.value_type,
null, this);
}
}
diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala
index 5bef6f277..1ffc09585 100644
--- a/vala/valasemanticanalyzer.vala
+++ b/vala/valasemanticanalyzer.vala
@@ -318,11 +318,17 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
return result;
}
- if (sym is WithStatement) {
+ /*if (sym is WithStatement) {
unowned WithStatement w = (WithStatement) sym;
- stdout.printf("Resolved with statement\n");
- return w.expression.symbol_reference;
- } else if (sym is Class) {
+ var lv = w.expression;
+ var base_symbol = lv.value_type.type_symbol;
+ var symbol_reference = lv.value_type.get_member (name);
+ // var vt = get_value_type_for_symbol(real_sym);
+ // var vt_sym = x.symbol;
+ // stdout.printf("Resolved with statement: %s, value type: %s, value type symbol:
%s\n", Type.from_instance(real_sym).name(), Type.from_instance(vt).name(), Type.from_instance(vt_sym).name());
+ // return symbol_lookup_inherited(vt_sym, name);
+ return symbol_reference;
+ } else */ if (sym is Class) {
unowned Class cl = (Class) sym;
// first check interfaces without prerequisites
// (prerequisites can be assumed to be met already)
diff --git a/with b/with
index a4a4cf460..8b32f74ca 100755
Binary files a/with and b/with differ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]