[vala/wip/transform: 224/237] Parse statements from a string
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/transform: 224/237] Parse statements from a string
- Date: Wed, 13 Dec 2017 13:59:32 +0000 (UTC)
commit 26132eafb519b76a3bb1453a45e3f26161f885d1
Author: Luca Bruno <lucabru src gnome org>
Date: Sun Feb 2 23:32:35 2014 +0100
Parse statements from a string
codegen/valaccodetransformer.vala | 3 ++-
vala/valacodebuilder.vala | 4 ++++
vala/valacodetransformer.vala | 4 ++++
vala/valaparser.vala | 25 +++++++++++++++++++++++++
4 files changed, 35 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valaccodetransformer.vala b/codegen/valaccodetransformer.vala
index d13de54..77e06c7 100644
--- a/codegen/valaccodetransformer.vala
+++ b/codegen/valaccodetransformer.vala
@@ -223,7 +223,8 @@ public class Vala.CCodeTransformer : CodeTransformer {
b.add_expression (it_expr);
}
b.add_else ();
- b.add_assignment (expression (notfirst), expression ("true"));
+ statements (@"$notfirst = true;");
+ /* b.add_assignment (expression (notfirst), expression ("true")); */
b.close ();
if (stmt.condition != null && !always_true (stmt.condition)) {
diff --git a/vala/valacodebuilder.vala b/vala/valacodebuilder.vala
index 1e041ef..d7c63b8 100644
--- a/vala/valacodebuilder.vala
+++ b/vala/valacodebuilder.vala
@@ -272,6 +272,10 @@ public class Vala.CodeBuilder {
return new Parser().parse_expression_string (str, source_reference);
}
+ public void statements (string str) {
+ new Parser().parse_statements_string (str, current_block, source_reference);
+ }
+
// only qualified types, will slightly simplify the work of SymbolResolver
public static Symbol? symbol_from_string (string symbol_string, Symbol? parent_symbol = null) {
Symbol sym = parent_symbol != null ? parent_symbol : CodeContext.get().root;
diff --git a/vala/valacodetransformer.vala b/vala/valacodetransformer.vala
index ab70e85..14bf331 100644
--- a/vala/valacodetransformer.vala
+++ b/vala/valacodetransformer.vala
@@ -184,6 +184,10 @@ public class Vala.CodeTransformer : CodeVisitor {
return b.expression (str);
}
+ public void statements (string str) {
+ b.statements (str);
+ }
+
public void check (CodeNode node) {
var sym = context.analyzer.get_current_symbol (node);
if (sym != null) {
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 732e2d1..b4ea1e8 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -344,12 +344,33 @@ public class Vala.Parser : CodeVisitor {
try {
return parse_expression ();
} catch (Error e) {
+ Report.error (source_reference, "Internal compiler error: %s".printf (e.message));
}
scanner = null;
return null;
}
+ public void parse_statements_string (string str, Block block, SourceReference source_reference) {
+ compiler_code = true;
+ context = source_reference.file.context;
+ from_string_reference = source_reference;
+
+ scanner = new Scanner.from_string (str, source_reference.file);
+ index = -1;
+ size = 0;
+
+ next ();
+
+ try {
+ parse_statements (block);
+ } catch (Error e) {
+ Report.error (source_reference, "Internal compiler error: %s".printf (e.message));
+ }
+
+ scanner = null;
+ }
+
public void parse_file (SourceFile source_file) {
scanner = new Scanner (source_file);
parse_file_comments ();
@@ -1631,6 +1652,10 @@ public class Vala.Parser : CodeVisitor {
break;
default:
bool is_expr = is_expression ();
+ if (!is_expr && compiler_code && current () == TokenType.DOT) {
+ // compiler variable assignment
+ is_expr = true;
+ }
if (is_expr) {
stmt = parse_expression_statement ();
} else {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]