diff options
author | Timm Bäder <mail@baedert.org> | 2016-11-09 09:45:49 +0100 |
---|---|---|
committer | Timm Bäder <mail@baedert.org> | 2016-11-09 09:45:49 +0100 |
commit | b29ce57cb9c4280f09761436b1618041b814b27e (patch) | |
tree | 789e6ca66ce242fc9c1afde9828fd8bf0437a8de | |
parent | 08849bb74579967db7196d276e31d671a46440c5 (diff) | |
download | vala-wip/baedert/nullable.tar.gz |
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | vala/Makefile.am | 1 | ||||
-rw-r--r-- | vala/valaassignment.vala | 14 | ||||
-rw-r--r-- | vala/valaastprinter.vala | 4 | ||||
-rw-r--r-- | vala/valablock.vala | 28 | ||||
-rw-r--r-- | vala/valadeclarationstatement.vala | 61 |
6 files changed, 99 insertions, 11 deletions
diff --git a/configure.ac b/configure.ac index 540d4a2bd..a48a1ff6b 100644 --- a/configure.ac +++ b/configure.ac @@ -49,7 +49,7 @@ AS_IF([test "$VALAC" != valac], [FOUND_VALAC_VERION=`$VALAC --version | sed 's/V AS_VERSION_COMPARE(["$VALAC_BOOTSTRAP_REQUIRED"], ["$FOUND_VALAC_VERION"], [enable_boostrap=yes], [enable_boostrap=yes], [enable_boostrap=no])]) -VALAFLAGS="$VALAFLAGS --disable-version-header" +VALAFLAGS="$VALAFLAGS --disable-version-header -g" if test x$enable_boostrap = xyes; then VALAFLAGS="$VALAFLAGS --hide-internal" fi diff --git a/vala/Makefile.am b/vala/Makefile.am index 8b13a2fe7..11399aeb7 100644 --- a/vala/Makefile.am +++ b/vala/Makefile.am @@ -8,6 +8,7 @@ AM_CPPFLAGS = \ $(GLIB_CFLAGS) \ $(GMODULE_CFLAGS) \ -DPACKAGE_DATADIR=\"$(pkgdatadir)\" \ + -g \ $(NULL) BUILT_SOURCES = vala.vala.stamp diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala index 88e45ffda..cd674f220 100644 --- a/vala/valaassignment.vala +++ b/vala/valaassignment.vala @@ -37,12 +37,12 @@ public class Vala.Assignment : Expression { _left.parent_node = this; } } - + /** * Assignment operator. */ public AssignmentOperator operator { get; set; } - + /** * Right hand side of the assignment. */ @@ -53,10 +53,10 @@ public class Vala.Assignment : Expression { _right.parent_node = this; } } - + private Expression _left; private Expression _right; - + /** * Creates a new assignment. * @@ -72,7 +72,7 @@ public class Vala.Assignment : Expression { this.source_reference = source_reference; this.left = left; } - + public override void accept (CodeVisitor visitor) { visitor.visit_assignment (this); @@ -220,6 +220,8 @@ public class Vala.Assignment : Expression { return false; } + //message ("Right: %p", right); + //message ("Checking right: %s, %s", right.type_name, right.to_string ()); if (!right.check (context)) { // skip on error in inner expression error = true; @@ -572,7 +574,7 @@ public class Vala.Assignment : Expression { right.get_used_variables (collection); } } - + public enum Vala.AssignmentOperator { NONE, SIMPLE, diff --git a/vala/valaastprinter.vala b/vala/valaastprinter.vala index a1b49567e..34ea690da 100644 --- a/vala/valaastprinter.vala +++ b/vala/valaastprinter.vala @@ -18,6 +18,10 @@ public class Vala.AstPrinter : CodeVisitor { context.accept (this); } + public void print_subtree (CodeNode node, CodeContext context) { + this.context = context; + node.accept (this); + } public override void visit_namespace (Namespace ns) { print ("Namespace %s".printf (ns.name)); diff --git a/vala/valablock.vala b/vala/valablock.vala index 4064b6e90..a096307d6 100644 --- a/vala/valablock.vala +++ b/vala/valablock.vala @@ -37,7 +37,7 @@ public class Vala.Block : Symbol, Statement { private List<Statement> statement_list = new ArrayList<Statement> (); private List<LocalVariable> local_variables = new ArrayList<LocalVariable> (); private List<Constant> local_constants = new ArrayList<Constant> (); - + /** * Creates a new block. * @@ -46,7 +46,7 @@ public class Vala.Block : Symbol, Statement { public Block (SourceReference? source_reference) { base (null, source_reference); } - + /** * Append a statement to this block. * @@ -81,7 +81,7 @@ public class Vala.Block : Symbol, Statement { } return list; } - + /** * Add a local variable to this block. * @@ -197,6 +197,28 @@ public class Vala.Block : Symbol, Statement { } } + + public void insert_after (Statement stmt, Statement new_stmt) { + for (int i = 0; i < statement_list.size; i++) { + var stmt_list = statement_list[i] as StatementList; + if (stmt_list != null) { + for (int j = 0; j < stmt_list.length; j++) { + if (stmt_list.get (j) == stmt) { + stmt_list.insert (j + 1, new_stmt); + new_stmt.parent_node = this; + break; + } + } + } else if (statement_list[i] == stmt) { + stmt_list = new StatementList (source_reference); + stmt_list.add (stmt); + stmt_list.add (new_stmt); + statement_list[i] = stmt_list; + new_stmt.parent_node = this; + } + } + } + public void replace_statement (Statement old_stmt, Statement new_stmt) { for (int i = 0; i < statement_list.size; i++) { var stmt_list = statement_list[i] as StatementList; diff --git a/vala/valadeclarationstatement.vala b/vala/valadeclarationstatement.vala index f0a3d4161..a0e7bc116 100644 --- a/vala/valadeclarationstatement.vala +++ b/vala/valadeclarationstatement.vala @@ -69,10 +69,69 @@ public class Vala.DeclarationStatement : CodeNode, Statement { checked = true; - declaration.check (context); var local = declaration as LocalVariable; if (local != null && local.initializer != null) { + var block = this.parent_node as Block; + //var block = context.analyzer.current_symbol as Block; + if (block != null) { + // For var declarations, we need to resolve the type now, + // since removing the initializer will make it impossible later. + if (local.variable_type != null) { + local.variable_type.check (context); + } + local.initializer.target_type = local.variable_type; + local.initializer.check (context); + + message ("Before: %p", local.variable_type); + if (local.variable_type == null) { + // var decl + local.variable_type = local.initializer.value_type.copy (); + //local.variable_type = context.analyzer.get_value_type_for_symbol + //(local.initializer.value_type.data_type, true); + assert (local.variable_type != null); + local.variable_type.value_owned = true; + local.variable_type.floating_reference = false; + local.initializer.target_type = local.variable_type; + // TODO: This is code copied from LocalVariable's check() + // but if we *always* remove the initializer here, + // we could also remove it from there... + } + var init = local.initializer; + message ("Method: %s", context.analyzer.find_current_method ().to_string ()); + message ("Init: %s, %s", init.type_name, init.to_string ()); + message ("var type: %s", local.variable_type.type_name); + message ("var type: %s", local.variable_type.to_string ()); + + if (local.variable_type is NullType) { + var printer = new AstPrinter (); + printer.print_subtree (block, context); + + message ("Start type: %s", local.initializer.value_type.to_qualified_string ()); + + } + local.initializer = null; + var left = new MemberAccess.simple (local.name, local.source_reference); + //left.pointer_member_access = (local.variable_type is PointerType); + var assign = new Assignment (left, init, AssignmentOperator.SIMPLE, local.source_reference); + var stmt = new ExpressionStatement (assign); + //block.add_statement (stmt); + //block.insert_statement (0, stmt); + block.insert_after (this, stmt); + declaration.check (context); + if (!stmt.check (context)) { + error = true; + return false; + } + } else { + message ("Parent type: %s", this.parent_node.type_name); + } + } else { + declaration.check (context); + } + + + if (local != null && local.initializer != null) { foreach (DataType error_type in local.initializer.get_error_types ()) { // ensure we can trace back which expression may throw errors of this type var initializer_error_type = error_type.copy (); |