vala r1243 - in trunk: . gobject vala
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r1243 - in trunk: . gobject vala
- Date: Wed, 16 Apr 2008 16:45:34 +0100 (BST)
Author: juergbi
Date: Wed Apr 16 16:45:33 2008
New Revision: 1243
URL: http://svn.gnome.org/viewvc/vala?rev=1243&view=rev
Log:
2008-04-16 Juerg Billeter <j bitron ch>
* vala/Makefile.am, vala/vala.h, vala/valablock.vala,
vala/valacatchclause.vala, vala/valacfgbuilder.vala,
vala/valaclass.vala, vala/valacodecontext.vala,
vala/valacodegenerator.vala, vala/valacodevisitor.vala,
vala/valadeclarationstatement.vala, vala/valaexpression.vala,
vala/valaforeachstatement.vala, vala/valainterface.vala,
vala/valalocalvariable.vala, vala/valamemorymanager.vala,
vala/valamethod.vala, vala/valanullchecker.vala,
vala/valaparser.vala, vala/valasemanticanalyzer.vala,
vala/valastruct.vala, vala/valaswitchsection.vala,
vala/valasymbolresolver.vala,
gobject/valaccodearraycreationexpressionbinding.vala,
gobject/valaccodeassignmentbinding.vala,
gobject/valaccodegenerator.vala,
gobject/valaccodegeneratorinvocationexpression.vala,
gobject/valaccodegeneratormemberaccess.vala:
Rename VariableDeclarator to LocalVariable,
remove LocalVariableDeclaration class
Added:
trunk/vala/valalocalvariable.vala
- copied, changed from r1234, /trunk/vala/valavariabledeclarator.vala
Removed:
trunk/vala/valalocalvariabledeclaration.vala
trunk/vala/valavariabledeclarator.vala
Modified:
trunk/ChangeLog
trunk/gobject/valaccodearraycreationexpressionbinding.vala
trunk/gobject/valaccodeassignmentbinding.vala
trunk/gobject/valaccodegenerator.vala
trunk/gobject/valaccodegeneratorinvocationexpression.vala
trunk/gobject/valaccodegeneratormemberaccess.vala
trunk/vala/Makefile.am
trunk/vala/vala.h
trunk/vala/valablock.vala
trunk/vala/valacatchclause.vala
trunk/vala/valacfgbuilder.vala
trunk/vala/valaclass.vala
trunk/vala/valacodecontext.vala
trunk/vala/valacodegenerator.vala
trunk/vala/valacodevisitor.vala
trunk/vala/valadeclarationstatement.vala
trunk/vala/valaexpression.vala
trunk/vala/valaforeachstatement.vala
trunk/vala/valainterface.vala
trunk/vala/valamemorymanager.vala
trunk/vala/valamethod.vala
trunk/vala/valanullchecker.vala
trunk/vala/valaparser.vala
trunk/vala/valasemanticanalyzer.vala
trunk/vala/valastruct.vala
trunk/vala/valaswitchsection.vala
trunk/vala/valasymbolresolver.vala
Modified: trunk/gobject/valaccodearraycreationexpressionbinding.vala
==============================================================================
--- trunk/gobject/valaccodearraycreationexpressionbinding.vala (original)
+++ trunk/gobject/valaccodearraycreationexpressionbinding.vala Wed Apr 16 16:45:33 2008
@@ -48,7 +48,7 @@
CCodeExpression csize = (CCodeExpression) size.ccodenode;
if (!codegen.is_pure_ccode_expression (csize)) {
- var temp_var = codegen.get_temp_variable_declarator (codegen.int_type, false, expr);
+ var temp_var = codegen.get_temp_variable (codegen.int_type, false, expr);
var name_cnode = new CCodeIdentifier (temp_var.name);
size.ccodenode = name_cnode;
@@ -79,7 +79,7 @@
}
var ce = new CCodeCommaExpression ();
- var temp_var = codegen.get_temp_variable_declarator (expr.static_type, true, expr);
+ var temp_var = codegen.get_temp_variable (expr.static_type, true, expr);
var name_cnode = new CCodeIdentifier (temp_var.name);
int i = 0;
Modified: trunk/gobject/valaccodeassignmentbinding.vala
==============================================================================
--- trunk/gobject/valaccodeassignmentbinding.vala (original)
+++ trunk/gobject/valaccodeassignmentbinding.vala Wed Apr 16 16:45:33 2008
@@ -176,7 +176,7 @@
// get signal id
var ccomma = new CCodeCommaExpression ();
- var temp_decl = codegen.get_temp_variable_declarator (codegen.uint_type);
+ var temp_decl = codegen.get_temp_variable (codegen.uint_type);
codegen.temp_vars.insert (0, temp_decl);
var parse_call = new CCodeFunctionCall (new CCodeIdentifier ("g_signal_parse_name"));
parse_call.add_argument (sig.get_canonical_cconstant ());
@@ -475,7 +475,7 @@
if (unref_old || array || instance_delegate) {
var ccomma = new CCodeCommaExpression ();
- var temp_decl = codegen.get_temp_variable_declarator (assignment.left.static_type);
+ var temp_decl = codegen.get_temp_variable (assignment.left.static_type);
codegen.temp_vars.insert (0, temp_decl);
ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (temp_decl.name), rhs));
if (unref_old) {
@@ -532,7 +532,7 @@
// except when it's a simple expression
var cea = (CCodeElementAccess) assignment.left.ccodenode;
if (!(cea.index is CCodeConstant || cea.index is CCodeIdentifier)) {
- var index_temp_decl = codegen.get_temp_variable_declarator (codegen.int_type);
+ var index_temp_decl = codegen.get_temp_variable (codegen.int_type);
codegen.temp_vars.insert (0, index_temp_decl);
var ccomma = new CCodeCommaExpression ();
Modified: trunk/gobject/valaccodegenerator.vala
==============================================================================
--- trunk/gobject/valaccodegenerator.vala (original)
+++ trunk/gobject/valaccodegenerator.vala Wed Apr 16 16:45:33 2008
@@ -67,9 +67,9 @@
CCodeBlock block;
/* all temporary variables */
- public ArrayList<VariableDeclarator> temp_vars = new ArrayList<VariableDeclarator> ();
+ public ArrayList<LocalVariable> temp_vars = new ArrayList<LocalVariable> ();
/* temporary variables that own their content */
- ArrayList<VariableDeclarator> temp_ref_vars = new ArrayList<VariableDeclarator> ();
+ ArrayList<LocalVariable> temp_ref_vars = new ArrayList<LocalVariable> ();
/* cache to check whether a certain marshaller has been created yet */
Gee.Set<string> user_marshal_set;
/* (constant) hash table with all predefined marshallers */
@@ -997,8 +997,8 @@
b.accept_children (this);
var local_vars = b.get_local_variables ();
- foreach (VariableDeclarator decl in local_vars) {
- decl.active = false;
+ foreach (LocalVariable local in local_vars) {
+ local.active = false;
}
var cblock = new CCodeBlock ();
@@ -1018,11 +1018,11 @@
}
}
- foreach (VariableDeclarator decl in local_vars) {
- if (decl.type_reference.takes_ownership) {
- var ma = new MemberAccess.simple (decl.name);
- ma.symbol_reference = decl;
- cblock.add_statement (new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (get_variable_cname (decl.name)), decl.type_reference, ma)));
+ foreach (LocalVariable local in local_vars) {
+ if (local.variable_type.takes_ownership) {
+ var ma = new MemberAccess.simple (local.name);
+ ma.symbol_reference = local;
+ cblock.add_statement (new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (get_variable_cname (local.name)), local.variable_type, ma)));
}
}
@@ -1047,34 +1047,11 @@
}
public override void visit_declaration_statement (DeclarationStatement stmt) {
- /* split declaration statement as var declarators
- * might have different types */
-
- var cfrag = new CCodeFragment ();
-
- foreach (VariableDeclarator decl in stmt.declaration.get_variable_declarators ()) {
- var cdecl = new CCodeDeclaration (decl.type_reference.get_cname (false, !decl.type_reference.takes_ownership));
-
- cdecl.add_declarator ((CCodeVariableDeclarator) decl.ccodenode);
-
- cfrag.append (cdecl);
-
- if (decl.initializer != null && decl.initializer.can_fail) {
- add_simple_check (decl.initializer, cfrag);
- }
+ stmt.ccodenode = stmt.declaration.ccodenode;
- /* try to initialize uninitialized variables */
- if (decl.initializer == null) {
- ((CCodeVariableDeclarator) decl.ccodenode).initializer = default_value_for_type (decl.type_reference, true);
- }
- }
-
- stmt.ccodenode = cfrag;
-
- foreach (VariableDeclarator decl in stmt.declaration.get_variable_declarators ()) {
- if (decl.initializer != null) {
- create_temp_decl (stmt, decl.initializer.temp_vars);
- }
+ var local = stmt.declaration as LocalVariable;
+ if (local != null && local.initializer != null) {
+ create_temp_decl (stmt, local.initializer.temp_vars);
}
create_temp_decl (stmt, temp_vars);
@@ -1089,80 +1066,92 @@
}
}
- public override void visit_variable_declarator (VariableDeclarator decl) {
- decl.accept_children (this);
+ public override void visit_local_variable (LocalVariable local) {
+ local.accept_children (this);
- if (decl.type_reference is ArrayType) {
+ if (local.variable_type is ArrayType) {
// create variables to store array dimensions
- var array_type = (ArrayType) decl.type_reference;
+ var array_type = (ArrayType) local.variable_type;
for (int dim = 1; dim <= array_type.rank; dim++) {
- var len_decl = new VariableDeclarator (get_array_length_cname (decl.name, dim));
- len_decl.type_reference = int_type.copy ();
-
- temp_vars.insert (0, len_decl);
+ var len_var = new LocalVariable (int_type.copy (), get_array_length_cname (local.name, dim));
+ temp_vars.insert (0, len_var);
}
- } else if (decl.type_reference is DelegateType) {
- var deleg_type = (DelegateType) decl.type_reference;
+ } else if (local.variable_type is DelegateType) {
+ var deleg_type = (DelegateType) local.variable_type;
var d = deleg_type.delegate_symbol;
if (d.instance) {
// create variable to store delegate target
- var target_decl = new VariableDeclarator (get_delegate_target_cname (decl.name));
- target_decl.type_reference = new PointerType (new VoidType ());
-
- temp_vars.insert (0, target_decl);
+ var target_var = new LocalVariable (new PointerType (new VoidType ()), get_delegate_target_cname (local.name));
+ temp_vars.insert (0, target_var);
}
}
CCodeExpression rhs = null;
- if (decl.initializer != null) {
- rhs = (CCodeExpression) decl.initializer.ccodenode;
- rhs = get_implicit_cast_expression (rhs, decl.initializer.static_type, decl.type_reference);
+ if (local.initializer != null) {
+ rhs = (CCodeExpression) local.initializer.ccodenode;
+ rhs = get_implicit_cast_expression (rhs, local.initializer.static_type, local.variable_type);
- if (decl.type_reference is ArrayType) {
- var array_type = (ArrayType) decl.type_reference;
+ if (local.variable_type is ArrayType) {
+ var array_type = (ArrayType) local.variable_type;
var ccomma = new CCodeCommaExpression ();
- var temp_decl = get_temp_variable_declarator (decl.type_reference, true, decl);
- temp_vars.insert (0, temp_decl);
- ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (temp_decl.name), rhs));
+ var temp_var = get_temp_variable (local.variable_type, true, local);
+ temp_vars.insert (0, temp_var);
+ ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (temp_var.name), rhs));
for (int dim = 1; dim <= array_type.rank; dim++) {
- var lhs_array_len = new CCodeIdentifier (get_array_length_cname (decl.name, dim));
- var rhs_array_len = get_array_length_cexpression (decl.initializer, dim);
+ var lhs_array_len = new CCodeIdentifier (get_array_length_cname (local.name, dim));
+ var rhs_array_len = get_array_length_cexpression (local.initializer, dim);
ccomma.append_expression (new CCodeAssignment (lhs_array_len, rhs_array_len));
}
- ccomma.append_expression (new CCodeIdentifier (temp_decl.name));
+ ccomma.append_expression (new CCodeIdentifier (temp_var.name));
rhs = ccomma;
- } else if (decl.type_reference is DelegateType) {
- var deleg_type = (DelegateType) decl.type_reference;
+ } else if (local.variable_type is DelegateType) {
+ var deleg_type = (DelegateType) local.variable_type;
var d = deleg_type.delegate_symbol;
if (d.instance) {
var ccomma = new CCodeCommaExpression ();
- var temp_decl = get_temp_variable_declarator (decl.type_reference, true, decl);
- temp_vars.insert (0, temp_decl);
- ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (temp_decl.name), rhs));
+ var temp_var = get_temp_variable (local.variable_type, true, local);
+ temp_vars.insert (0, temp_var);
+ ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (temp_var.name), rhs));
- var lhs_delegate_target = new CCodeIdentifier (get_delegate_target_cname (decl.name));
- var rhs_delegate_target = get_delegate_target_cexpression (decl.initializer);
+ var lhs_delegate_target = new CCodeIdentifier (get_delegate_target_cname (local.name));
+ var rhs_delegate_target = get_delegate_target_cexpression (local.initializer);
ccomma.append_expression (new CCodeAssignment (lhs_delegate_target, rhs_delegate_target));
- ccomma.append_expression (new CCodeIdentifier (temp_decl.name));
+ ccomma.append_expression (new CCodeIdentifier (temp_var.name));
rhs = ccomma;
}
}
- } else if (decl.type_reference.data_type != null && decl.type_reference.data_type.is_reference_type ()) {
+ } else if (local.variable_type.data_type != null && local.variable_type.data_type.is_reference_type ()) {
rhs = new CCodeConstant ("NULL");
}
- decl.ccodenode = new CCodeVariableDeclarator.with_initializer (get_variable_cname (decl.name), rhs);
+ var cvar = new CCodeVariableDeclarator.with_initializer (get_variable_cname (local.name), rhs);
+
+ var cfrag = new CCodeFragment ();
+ var cdecl = new CCodeDeclaration (local.variable_type.get_cname (false, !local.variable_type.takes_ownership));
+ cdecl.add_declarator (cvar);
+ cfrag.append (cdecl);
- decl.active = true;
+ if (local.initializer != null && local.initializer.can_fail) {
+ add_simple_check (local.initializer, cfrag);
+ }
+
+ /* try to initialize uninitialized variables */
+ if (local.initializer == null) {
+ cvar.initializer = default_value_for_type (local.variable_type, true);
+ }
+
+ local.ccodenode = cfrag;
+
+ local.active = true;
}
public override void visit_initializer_list (InitializerList list) {
@@ -1175,18 +1164,18 @@
list.ccodenode = clist;
}
- public VariableDeclarator get_temp_variable_declarator (DataType type, bool takes_ownership = true, CodeNode? node_reference = null) {
- var decl = new VariableDeclarator ("_tmp%d".printf (next_temp_var_id));
- decl.type_reference = type.copy ();
- decl.type_reference.takes_ownership = takes_ownership;
+ public LocalVariable get_temp_variable (DataType type, bool takes_ownership = true, CodeNode? node_reference = null) {
+ var var_type = type.copy ();
+ var_type.takes_ownership = takes_ownership;
+ var local = new LocalVariable (var_type, "_tmp%d".printf (next_temp_var_id));
if (node_reference != null) {
- decl.source_reference = node_reference.source_reference;
+ local.source_reference = node_reference.source_reference;
}
next_temp_var_id++;
- return decl;
+ return local;
}
private CCodeExpression get_type_id_expression (DataType type) {
@@ -1356,47 +1345,47 @@
* when deep list copying works
*/
expr.temp_vars.clear ();
- foreach (VariableDeclarator decl1 in temp_vars) {
- expr.temp_vars.add (decl1);
+ foreach (LocalVariable local in temp_vars) {
+ expr.temp_vars.add (local);
}
temp_vars.clear ();
- if (((Gee.List<VariableDeclarator>) temp_ref_vars).size == 0) {
+ if (((Gee.List<LocalVariable>) temp_ref_vars).size == 0) {
/* nothing to do without temporary variables */
return;
}
- var full_expr_decl = get_temp_variable_declarator (expr.static_type, true, expr);
- expr.temp_vars.add (full_expr_decl);
+ var full_expr_var = get_temp_variable (expr.static_type, true, expr);
+ expr.temp_vars.add (full_expr_var);
var expr_list = new CCodeCommaExpression ();
- expr_list.append_expression (new CCodeAssignment (new CCodeIdentifier (full_expr_decl.name), (CCodeExpression) expr.ccodenode));
+ expr_list.append_expression (new CCodeAssignment (new CCodeIdentifier (full_expr_var.name), (CCodeExpression) expr.ccodenode));
- foreach (VariableDeclarator decl in temp_ref_vars) {
- var ma = new MemberAccess.simple (decl.name);
- ma.symbol_reference = decl;
- expr_list.append_expression (get_unref_expression (new CCodeIdentifier (decl.name), decl.type_reference, ma));
+ foreach (LocalVariable local in temp_ref_vars) {
+ var ma = new MemberAccess.simple (local.name);
+ ma.symbol_reference = local;
+ expr_list.append_expression (get_unref_expression (new CCodeIdentifier (local.name), local.variable_type, ma));
}
- expr_list.append_expression (new CCodeIdentifier (full_expr_decl.name));
+ expr_list.append_expression (new CCodeIdentifier (full_expr_var.name));
expr.ccodenode = expr_list;
temp_ref_vars.clear ();
}
- private void append_temp_decl (CCodeFragment cfrag, Collection<VariableDeclarator> temp_vars) {
- foreach (VariableDeclarator decl in temp_vars) {
- var cdecl = new CCodeDeclaration (decl.type_reference.get_cname (true, !decl.type_reference.takes_ownership));
+ private void append_temp_decl (CCodeFragment cfrag, Collection<LocalVariable> temp_vars) {
+ foreach (LocalVariable local in temp_vars) {
+ var cdecl = new CCodeDeclaration (local.variable_type.get_cname (true, !local.variable_type.takes_ownership));
- var vardecl = new CCodeVariableDeclarator (decl.name);
+ var vardecl = new CCodeVariableDeclarator (local.name);
// sets #line
- decl.ccodenode = vardecl;
+ local.ccodenode = vardecl;
cdecl.add_declarator (vardecl);
- var st = decl.type_reference.data_type as Struct;
+ var st = local.variable_type.data_type as Struct;
- if (decl.type_reference.is_reference_type_or_type_parameter ()) {
+ if (local.variable_type.is_reference_type_or_type_parameter ()) {
vardecl.initializer = new CCodeConstant ("NULL");
} else if (st != null && !st.is_simple_type ()) {
// 0-initialize struct with struct initializer { 0 }
@@ -1432,13 +1421,13 @@
var cerror_block = new CCodeBlock ();
foreach (CatchClause clause in current_try.get_catch_clauses ()) {
// go to catch clause if error domain matches
- var cgoto_stmt = new CCodeGotoStatement ("__catch%d_%s".printf (current_try_id, clause.type_reference.get_lower_case_cname ()));
+ var cgoto_stmt = new CCodeGotoStatement ("__catch%d_%s".printf (current_try_id, clause.error_type.get_lower_case_cname ()));
- if (clause.type_reference.equals (gerror_type)) {
+ if (clause.error_type.equals (gerror_type)) {
// general catch clause
cerror_block.add_statement (cgoto_stmt);
} else {
- var ccond = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeMemberAccess.pointer (new CCodeIdentifier ("inner_error"), "domain"), new CCodeIdentifier (clause.type_reference.data_type.get_upper_case_cname ()));
+ var ccond = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeMemberAccess.pointer (new CCodeIdentifier ("inner_error"), "domain"), new CCodeIdentifier (clause.error_type.data_type.get_upper_case_cname ()));
var cgoto_block = new CCodeBlock ();
cgoto_block.add_statement (cgoto_stmt);
@@ -1505,7 +1494,7 @@
/* free temporary objects */
- if (((Gee.List<VariableDeclarator>) temp_vars).size == 0) {
+ if (((Gee.List<LocalVariable>) temp_vars).size == 0) {
/* nothing to do without temporary variables */
return;
}
@@ -1515,10 +1504,10 @@
cfrag.append (stmt.ccodenode);
- foreach (VariableDeclarator decl in temp_ref_vars) {
- var ma = new MemberAccess.simple (decl.name);
- ma.symbol_reference = decl;
- cfrag.append (new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (decl.name), decl.type_reference, ma)));
+ foreach (LocalVariable local in temp_ref_vars) {
+ var ma = new MemberAccess.simple (local.name);
+ ma.symbol_reference = local;
+ cfrag.append (new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (local.name), local.variable_type, ma)));
}
stmt.ccodenode = cfrag;
@@ -1527,7 +1516,7 @@
temp_ref_vars.clear ();
}
- private void create_temp_decl (Statement stmt, Collection<VariableDeclarator> temp_vars) {
+ private void create_temp_decl (Statement stmt, Collection<LocalVariable> temp_vars) {
/* declare temporary variables */
if (temp_vars.size == 0) {
@@ -1558,17 +1547,17 @@
public override void visit_switch_statement (SwitchStatement stmt) {
// we need a temporary variable to save the property value
- var temp_decl = get_temp_variable_declarator (stmt.expression.static_type, true, stmt);
- stmt.expression.temp_vars.insert (0, temp_decl);
+ var temp_var = get_temp_variable (stmt.expression.static_type, true, stmt);
+ stmt.expression.temp_vars.insert (0, temp_var);
- var ctemp = new CCodeIdentifier (temp_decl.name);
+ var ctemp = new CCodeIdentifier (temp_var.name);
var cinit = new CCodeAssignment (ctemp, (CCodeExpression) stmt.expression.ccodenode);
var czero = new CCodeConstant ("0");
var cswitchblock = new CCodeFragment ();
stmt.ccodenode = cswitchblock;
- var is_string_cmp = temp_decl.type_reference.data_type.is_subtype_of (string_type.data_type);
+ var is_string_cmp = temp_var.variable_type.data_type.is_subtype_of (string_type.data_type);
if (is_string_cmp) {
var cisnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeConstant ("NULL"), ctemp);
@@ -1577,8 +1566,8 @@
var ccond = new CCodeConditionalExpression (cisnull, new CCodeConstant ("0"), cquark);
- temp_decl = get_temp_variable_declarator (gquark_type);
- stmt.expression.temp_vars.insert (0, temp_decl);
+ temp_var = get_temp_variable (gquark_type);
+ stmt.expression.temp_vars.insert (0, temp_var);
var label_count = 0;
@@ -1591,7 +1580,7 @@
var cexpr = (CCodeExpression) label.expression.ccodenode;
if (is_constant_ccode_expression (cexpr)) {
- var cname = "%s_label%d".printf (temp_decl.name, label_count++);
+ var cname = "%s_label%d".printf (temp_var.name, label_count++);
var cdecl = new CCodeDeclaration (gquark_type.get_cname ());
cdecl.modifiers = CCodeModifiers.STATIC;
@@ -1604,7 +1593,7 @@
cswitchblock.append (new CCodeExpressionStatement (cinit));
- ctemp = new CCodeIdentifier (temp_decl.name);
+ ctemp = new CCodeIdentifier (temp_var.name);
cinit = new CCodeAssignment (ctemp, ccond);
}
@@ -1630,7 +1619,7 @@
if (is_string_cmp) {
if (is_constant_ccode_expression (cexpr)) {
- var cname = new CCodeIdentifier ("%s_label%d".printf (temp_decl.name, label_count++));
+ var cname = new CCodeIdentifier ("%s_label%d".printf (temp_var.name, label_count++));
var ccond = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, czero, cname);
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_quark_from_static_string"));
var cinit = new CCodeParenthesizedExpression (new CCodeAssignment (cname, ccall));
@@ -1744,10 +1733,10 @@
}
public override void visit_foreach_statement (ForeachStatement stmt) {
- stmt.variable_declarator.active = true;
- stmt.collection_variable_declarator.active = true;
- if (stmt.iterator_variable_declarator != null) {
- stmt.iterator_variable_declarator.active = true;
+ stmt.element_variable.active = true;
+ stmt.collection_variable.active = true;
+ if (stmt.iterator_variable != null) {
+ stmt.iterator_variable.active = true;
}
visit_block (stmt);
@@ -1760,8 +1749,8 @@
append_temp_decl (cfrag, stmt.collection.temp_vars);
cblock.add_statement (cfrag);
- var collection_backup = stmt.collection_variable_declarator;
- var collection_type = collection_backup.type_reference.copy ();
+ var collection_backup = stmt.collection_variable;
+ var collection_type = collection_backup.variable_type.copy ();
var ccoldecl = new CCodeDeclaration (collection_type.get_cname ());
var ccolvardecl = new CCodeVariableDeclarator.with_initializer (collection_backup.name, (CCodeExpression) stmt.collection.ccodenode);
ccolvardecl.line = cblock.line;
@@ -1991,11 +1980,11 @@
cblock.add_statement (cwhile);
}
- foreach (VariableDeclarator decl in stmt.get_local_variables ()) {
- if (decl.type_reference.takes_ownership) {
- var ma = new MemberAccess.simple (decl.name);
- ma.symbol_reference = decl;
- var cunref = new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (get_variable_cname (decl.name)), decl.type_reference, ma));
+ foreach (LocalVariable local in stmt.get_local_variables ()) {
+ if (local.variable_type.takes_ownership) {
+ var ma = new MemberAccess.simple (local.name);
+ ma.symbol_reference = local;
+ var cunref = new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (get_variable_cname (local.name)), local.variable_type, ma));
cunref.line = cblock.line;
cblock.add_statement (cunref);
}
@@ -2018,11 +2007,11 @@
var b = (Block) sym;
var local_vars = b.get_local_variables ();
- foreach (VariableDeclarator decl in local_vars) {
- if (decl.active && decl.type_reference.is_reference_type_or_type_parameter () && decl.type_reference.takes_ownership) {
- var ma = new MemberAccess.simple (decl.name);
- ma.symbol_reference = decl;
- cfrag.append (new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (get_variable_cname (decl.name)), decl.type_reference, ma)));
+ foreach (LocalVariable local in local_vars) {
+ if (local.active && local.variable_type.is_reference_type_or_type_parameter () && local.variable_type.takes_ownership) {
+ var ma = new MemberAccess.simple (local.name);
+ ma.symbol_reference = local;
+ cfrag.append (new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (get_variable_cname (local.name)), local.variable_type, ma)));
}
}
@@ -2066,12 +2055,12 @@
var b = (Block) sym;
var local_vars = b.get_local_variables ();
- foreach (VariableDeclarator decl in local_vars) {
- if (decl.active && decl.type_reference.is_reference_type_or_type_parameter () && decl.type_reference.takes_ownership) {
+ foreach (LocalVariable local in local_vars) {
+ if (local.active && local.variable_type.is_reference_type_or_type_parameter () && local.variable_type.takes_ownership) {
found = true;
- var ma = new MemberAccess.simple (decl.name);
- ma.symbol_reference = decl;
- ccomma.append_expression (get_unref_expression (new CCodeIdentifier (get_variable_cname (decl.name)), decl.type_reference, ma));
+ var ma = new MemberAccess.simple (local.name);
+ ma.symbol_reference = local;
+ ccomma.append_expression (get_unref_expression (new CCodeIdentifier (get_variable_cname (local.name)), local.variable_type, ma));
}
}
@@ -2100,7 +2089,7 @@
}
private void create_local_free_expr (Expression expr) {
- var return_expr_decl = get_temp_variable_declarator (expr.static_type, true, expr);
+ var return_expr_decl = get_temp_variable (expr.static_type, true, expr);
var ccomma = new CCodeCommaExpression ();
ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (return_expr_decl.name), (CCodeExpression) expr.ccodenode));
@@ -2120,9 +2109,9 @@
if (stmt.return_expression != null) {
// avoid unnecessary ref/unref pair
if (stmt.return_expression.ref_missing &&
- stmt.return_expression.symbol_reference is VariableDeclarator) {
- var decl = (VariableDeclarator) stmt.return_expression.symbol_reference;
- if (decl.type_reference.takes_ownership) {
+ stmt.return_expression.symbol_reference is LocalVariable) {
+ var local = (LocalVariable) stmt.return_expression.symbol_reference;
+ if (local.variable_type.takes_ownership) {
/* return expression is local variable taking ownership and
* current method is transferring ownership */
@@ -2145,21 +2134,21 @@
// avoid unnecessary ref/unref pair
if (stmt.return_expression.ref_sink &&
- stmt.return_expression.symbol_reference is VariableDeclarator) {
- var decl = (VariableDeclarator) stmt.return_expression.symbol_reference;
- if (decl.type_reference.takes_ownership) {
+ stmt.return_expression.symbol_reference is LocalVariable) {
+ var local = (LocalVariable) stmt.return_expression.symbol_reference;
+ if (local.variable_type.takes_ownership) {
/* return expression is local variable taking ownership and
* current method is transferring ownership */
// don't unref expression
- return_expression_symbol = decl;
+ return_expression_symbol = local;
return_expression_symbol.active = false;
}
}
// return array length if appropriate
if (current_method != null && !current_method.no_array_length && current_return_type is ArrayType) {
- var return_expr_decl = get_temp_variable_declarator (stmt.return_expression.static_type, true, stmt);
+ var return_expr_decl = get_temp_variable (stmt.return_expression.static_type, true, stmt);
var ccomma = new CCodeCommaExpression ();
ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (return_expr_decl.name), (CCodeExpression) stmt.return_expression.ccodenode));
@@ -2259,7 +2248,7 @@
clause.accept_children (this);
var cfrag = new CCodeFragment ();
- cfrag.append (new CCodeLabel ("__catch%d_%s".printf (current_try_id, clause.type_reference.get_lower_case_cname ())));
+ cfrag.append (new CCodeLabel ("__catch%d_%s".printf (current_try_id, clause.error_type.get_lower_case_cname ())));
var cblock = new CCodeBlock ();
@@ -2429,9 +2418,9 @@
return length_expr;
}
}
- } else if (array_expr.symbol_reference is VariableDeclarator) {
- var decl = (VariableDeclarator) array_expr.symbol_reference;
- var length_expr = new CCodeIdentifier (get_array_length_cname (decl.name, dim));
+ } else if (array_expr.symbol_reference is LocalVariable) {
+ var local = (LocalVariable) array_expr.symbol_reference;
+ var length_expr = new CCodeIdentifier (get_array_length_cname (local.name, dim));
if (is_out) {
return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, length_expr);
} else {
@@ -2549,9 +2538,9 @@
} else {
return target_expr;
}
- } else if (delegate_expr.symbol_reference is VariableDeclarator) {
- var decl = (VariableDeclarator) delegate_expr.symbol_reference;
- var target_expr = new CCodeIdentifier (get_delegate_target_cname (decl.name));
+ } else if (delegate_expr.symbol_reference is LocalVariable) {
+ var local = (LocalVariable) delegate_expr.symbol_reference;
+ var target_expr = new CCodeIdentifier (get_delegate_target_cname (local.name));
if (is_out) {
return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, target_expr);
} else {
@@ -2641,7 +2630,7 @@
var ccomma = new CCodeCommaExpression ();
// assign current value to temp variable
- var temp_decl = get_temp_variable_declarator (prop.type_reference, true, expr);
+ var temp_decl = get_temp_variable (prop.type_reference, true, expr);
temp_vars.insert (0, temp_decl);
ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (temp_decl.name), (CCodeExpression) expr.inner.ccodenode));
@@ -2706,7 +2695,7 @@
return ccall;
} else {
- var decl = get_temp_variable_declarator (expr.static_type, false, expr);
+ var decl = get_temp_variable (expr.static_type, false, expr);
temp_vars.insert (0, decl);
var ctemp = new CCodeIdentifier (decl.name);
@@ -2785,7 +2774,7 @@
}
if (expr.ref_leaked) {
- var decl = get_temp_variable_declarator (expr.static_type, true, expr);
+ var decl = get_temp_variable (expr.static_type, true, expr);
temp_vars.insert (0, decl);
temp_ref_vars.insert (0, decl);
expr.ccodenode = new CCodeParenthesizedExpression (new CCodeAssignment (new CCodeIdentifier (get_variable_cname (decl.name)), (CCodeExpression) expr.ccodenode));
@@ -2802,7 +2791,7 @@
if (expr.type_reference.data_type is Struct || expr.get_object_initializer ().size > 0) {
// value-type initialization or object creation expression with object initializer
- var temp_decl = get_temp_variable_declarator (expr.type_reference, false, expr);
+ var temp_decl = get_temp_variable (expr.type_reference, false, expr);
temp_vars.add (temp_decl);
instance = new CCodeIdentifier (get_variable_cname (temp_decl.name));
@@ -3026,7 +3015,7 @@
// GObject cast
if (expr.is_silent_cast) {
var ccomma = new CCodeCommaExpression ();
- var temp_decl = get_temp_variable_declarator (expr.inner.static_type, true, expr);
+ var temp_decl = get_temp_variable (expr.inner.static_type, true, expr);
temp_vars.add (temp_decl);
@@ -3066,7 +3055,7 @@
public override void visit_reference_transfer_expression (ReferenceTransferExpression expr) {
/* (tmp = var, var = null, tmp) */
var ccomma = new CCodeCommaExpression ();
- var temp_decl = get_temp_variable_declarator (expr.static_type, true, expr);
+ var temp_decl = get_temp_variable (expr.static_type, true, expr);
temp_vars.insert (0, temp_decl);
var cvar = new CCodeIdentifier (temp_decl.name);
@@ -3192,8 +3181,8 @@
public override void visit_lambda_expression (LambdaExpression l) {
var old_temp_vars = temp_vars;
var old_temp_ref_vars = temp_ref_vars;
- temp_vars = new ArrayList<VariableDeclarator> ();
- temp_ref_vars = new ArrayList<VariableDeclarator> ();
+ temp_vars = new ArrayList<LocalVariable> ();
+ temp_ref_vars = new ArrayList<LocalVariable> ();
l.accept_children (this);
@@ -3499,7 +3488,7 @@
if (ma.symbol_reference is FormalParameter) {
return true;
}
- if (ma.symbol_reference is VariableDeclarator) {
+ if (ma.symbol_reference is LocalVariable) {
return true;
}
if (ma.symbol_reference is Field) {
@@ -3517,7 +3506,7 @@
}
var ccomma = new CCodeCommaExpression ();
- var temp_decl = get_temp_variable_declarator (e.static_type);
+ var temp_decl = get_temp_variable (e.static_type);
var ctemp = new CCodeIdentifier (temp_decl.name);
temp_vars.add (temp_decl);
ccomma.append_expression (new CCodeAssignment (ctemp, ce));
@@ -3640,11 +3629,7 @@
return null;
}
- public override CodeBinding? create_local_variable_declaration_binding (LocalVariableDeclaration node) {
- return null;
- }
-
- public override CodeBinding? create_variable_declarator_binding (VariableDeclarator node) {
+ public override CodeBinding? create_local_variable_binding (LocalVariable node) {
return null;
}
Modified: trunk/gobject/valaccodegeneratorinvocationexpression.vala
==============================================================================
--- trunk/gobject/valaccodegeneratorinvocationexpression.vala (original)
+++ trunk/gobject/valaccodegeneratorinvocationexpression.vala Wed Apr 16 16:45:33 2008
@@ -267,7 +267,7 @@
var ccomma = new CCodeCommaExpression ();
- var temp_decl = get_temp_variable_declarator (arg.static_type);
+ var temp_decl = get_temp_variable (arg.static_type);
temp_vars.insert (0, temp_decl);
ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (temp_decl.name), cexpr));
@@ -285,29 +285,29 @@
// (ret_tmp = call (&tmp), free (var1), var1 = tmp, ret_tmp)
var ccomma = new CCodeCommaExpression ();
- var temp_decl = get_temp_variable_declarator (unary.inner.static_type);
- temp_vars.insert (0, temp_decl);
- cexpr = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (temp_decl.name));
+ var temp_var = get_temp_variable (unary.inner.static_type);
+ temp_vars.insert (0, temp_var);
+ cexpr = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (temp_var.name));
// call function
- VariableDeclarator ret_temp_decl;
+ LocalVariable ret_temp_var;
if (m.return_type is VoidType) {
ccomma.append_expression (ccall_expr);
} else {
- ret_temp_decl = get_temp_variable_declarator (m.return_type);
- temp_vars.insert (0, ret_temp_decl);
- ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (ret_temp_decl.name), ccall_expr));
+ ret_temp_var = get_temp_variable (m.return_type);
+ temp_vars.insert (0, ret_temp_var);
+ ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (ret_temp_var.name), ccall_expr));
}
// unref old value
ccomma.append_expression (get_unref_expression ((CCodeExpression) unary.inner.ccodenode, arg.static_type, arg));
// assign new value
- ccomma.append_expression (new CCodeAssignment ((CCodeExpression) unary.inner.ccodenode, new CCodeIdentifier (temp_decl.name)));
+ ccomma.append_expression (new CCodeAssignment ((CCodeExpression) unary.inner.ccodenode, new CCodeIdentifier (temp_var.name)));
// return value
if (!(m.return_type is VoidType)) {
- ccomma.append_expression (new CCodeIdentifier (ret_temp_decl.name));
+ ccomma.append_expression (new CCodeIdentifier (ret_temp_var.name));
}
ccall_expr = ccomma;
@@ -358,10 +358,10 @@
var array_type = (ArrayType) m.return_type;
for (int dim = 1; dim <= array_type.rank; dim++) {
if (!m.no_array_length) {
- var temp_decl = get_temp_variable_declarator (int_type);
- var temp_ref = new CCodeIdentifier (temp_decl.name);
+ var temp_var = get_temp_variable (int_type);
+ var temp_ref = new CCodeIdentifier (temp_var.name);
- temp_vars.insert (0, temp_decl);
+ temp_vars.insert (0, temp_var);
carg_map.set (get_param_pos (m.carray_length_parameter_position + 0.01 * dim), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
@@ -374,10 +374,10 @@
var deleg_type = (DelegateType) m.return_type;
var d = deleg_type.delegate_symbol;
if (d.instance) {
- var temp_decl = get_temp_variable_declarator (new PointerType (new VoidType ()));
- var temp_ref = new CCodeIdentifier (temp_decl.name);
+ var temp_var = get_temp_variable (new PointerType (new VoidType ()));
+ var temp_ref = new CCodeIdentifier (temp_var.name);
- temp_vars.insert (0, temp_decl);
+ temp_vars.insert (0, temp_var);
carg_map.set (get_param_pos (m.cdelegate_target_parameter_position), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
@@ -450,7 +450,7 @@
arg_it.next ();
var new_size = (CCodeExpression) arg_it.get ().ccodenode;
- var temp_decl = get_temp_variable_declarator (int_type);
+ var temp_decl = get_temp_variable (int_type);
var temp_ref = new CCodeIdentifier (temp_decl.name);
temp_vars.insert (0, temp_decl);
@@ -478,7 +478,7 @@
expr.ccodenode = ccomma;
} else if (m == substring_method) {
- var temp_decl = get_temp_variable_declarator (string_type);
+ var temp_decl = get_temp_variable (string_type);
var temp_ref = new CCodeIdentifier (temp_decl.name);
temp_vars.insert (0, temp_decl);
@@ -514,7 +514,7 @@
ccall.add_argument (get_dbus_array_type (array_type));
var garray_type_reference = get_data_type_for_symbol (garray_type);
- var temp_decl = get_temp_variable_declarator (garray_type_reference);
+ var temp_decl = get_temp_variable (garray_type_reference);
temp_vars.insert (0, temp_decl);
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (temp_decl.name)));
@@ -541,7 +541,7 @@
ccall.add_argument (new CCodeIdentifier (m.return_type.data_type.get_type_id ()));
}
- var temp_decl = get_temp_variable_declarator (m.return_type);
+ var temp_decl = get_temp_variable (m.return_type);
temp_vars.insert (0, temp_decl);
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (temp_decl.name)));
Modified: trunk/gobject/valaccodegeneratormemberaccess.vala
==============================================================================
--- trunk/gobject/valaccodegeneratormemberaccess.vala (original)
+++ trunk/gobject/valaccodegeneratormemberaccess.vala Wed Apr 16 16:45:33 2008
@@ -54,9 +54,9 @@
if (expr.inner != null && !expr.inner.is_pure ()) {
// instance expression has side-effects
// store in temp. variable
- var temp_decl = get_temp_variable_declarator (expr.inner.static_type);
- temp_vars.insert (0, temp_decl);
- var ctemp = new CCodeIdentifier (temp_decl.name);
+ var temp_var = get_temp_variable (expr.inner.static_type);
+ temp_vars.insert (0, temp_var);
+ var ctemp = new CCodeIdentifier (temp_var.name);
inst = new CCodeAssignment (ctemp, pub_inst);
expr.inner.ccodenode = ctemp;
}
@@ -131,9 +131,9 @@
// They are returned as out parameter.
if (base_property.type_reference.is_real_struct_type ()) {
var ccomma = new CCodeCommaExpression ();
- var temp_decl = get_temp_variable_declarator (base_property.type_reference);
- var ctemp = new CCodeIdentifier (temp_decl.name);
- temp_vars.add (temp_decl);
+ var temp_var = get_temp_variable (base_property.type_reference);
+ var ctemp = new CCodeIdentifier (temp_var.name);
+ temp_vars.add (temp_var);
ccall.add_argument (new CCodeUnaryExpression(CCodeUnaryOperator.ADDRESS_OF, ctemp));
ccomma.append_expression (ccall);
ccomma.append_expression (ctemp);
@@ -153,10 +153,10 @@
// we need a temporary variable to save the property value
- var temp_decl = get_temp_variable_declarator (expr.static_type);
- temp_vars.insert (0, temp_decl);
+ var temp_var = get_temp_variable (expr.static_type);
+ temp_vars.insert (0, temp_var);
- var ctemp = new CCodeIdentifier (temp_decl.name);
+ var ctemp = new CCodeIdentifier (temp_var.name);
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, ctemp));
@@ -170,9 +170,9 @@
} else if (expr.symbol_reference is EnumValue) {
var ev = (EnumValue) expr.symbol_reference;
expr.ccodenode = new CCodeConstant (ev.get_cname ());
- } else if (expr.symbol_reference is VariableDeclarator) {
- var decl = (VariableDeclarator) expr.symbol_reference;
- expr.ccodenode = new CCodeIdentifier (get_variable_cname (decl.name));
+ } else if (expr.symbol_reference is LocalVariable) {
+ var local = (LocalVariable) expr.symbol_reference;
+ expr.ccodenode = new CCodeIdentifier (get_variable_cname (local.name));
} else if (expr.symbol_reference is FormalParameter) {
var p = (FormalParameter) expr.symbol_reference;
if (p.name == "this") {
Modified: trunk/vala/Makefile.am
==============================================================================
--- trunk/vala/Makefile.am (original)
+++ trunk/vala/Makefile.am Wed Apr 16 16:45:33 2008
@@ -78,7 +78,7 @@
valainvocationexpression.vala \
valalambdaexpression.vala \
valaliteral.vala \
- valalocalvariabledeclaration.vala \
+ valalocalvariable.vala \
valalockable.vala \
valalockstatement.vala \
valamember.vala \
@@ -137,7 +137,6 @@
valaunresolvedsymbol.vala \
valaunresolvedtype.vala \
valavaluetype.vala \
- valavariabledeclarator.vala \
valavoidtype.vala \
valawhilestatement.vala \
$(NULL)
Modified: trunk/vala/vala.h
==============================================================================
--- trunk/vala/vala.h (original)
+++ trunk/vala/vala.h Wed Apr 16 16:45:33 2008
@@ -41,7 +41,7 @@
#include <vala/valainvocationexpression.h>
#include <vala/valalambdaexpression.h>
#include <vala/valaliteral.h>
-#include <vala/valalocalvariabledeclaration.h>
+#include <vala/valalocalvariable.h>
#include <vala/valalockstatement.h>
#include <vala/valamemberaccess.h>
#include <vala/valamemberinitializer.h>
@@ -81,6 +81,5 @@
#include <vala/valaunaryexpression.h>
#include <vala/valaunresolvedsymbol.h>
#include <vala/valaunresolvedtype.h>
-#include <vala/valavariabledeclarator.h>
#include <vala/valavoidtype.h>
#include <vala/valawhilestatement.h>
Modified: trunk/vala/valablock.vala
==============================================================================
--- trunk/vala/valablock.vala (original)
+++ trunk/vala/valablock.vala Wed Apr 16 16:45:33 2008
@@ -1,6 +1,6 @@
/* valablock.vala
*
- * Copyright (C) 2006-2007 JÃrg Billeter
+ * Copyright (C) 2006-2008 JÃrg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -34,7 +34,7 @@
public bool contains_jump_statement { get; set; }
private Gee.List<Statement> statement_list = new ArrayList<Statement> ();
- private Gee.List<VariableDeclarator> local_variables = new ArrayList<VariableDeclarator> ();
+ private Gee.List<LocalVariable> local_variables = new ArrayList<LocalVariable> ();
/**
* Creates a new block.
@@ -68,8 +68,8 @@
*
* @param decl a variable declarator
*/
- public void add_local_variable (VariableDeclarator decl) {
- local_variables.add (decl);
+ public void add_local_variable (LocalVariable local) {
+ local_variables.add (local);
}
/**
@@ -77,8 +77,8 @@
*
* @return variable declarator list
*/
- public Collection<VariableDeclarator> get_local_variables () {
- return new ReadOnlyCollection<VariableDeclarator> (local_variables);
+ public Collection<LocalVariable> get_local_variables () {
+ return new ReadOnlyCollection<LocalVariable> (local_variables);
}
public override void accept (CodeVisitor visitor) {
Modified: trunk/vala/valacatchclause.vala
==============================================================================
--- trunk/vala/valacatchclause.vala (original)
+++ trunk/vala/valacatchclause.vala Wed Apr 16 16:45:33 2008
@@ -29,7 +29,7 @@
/**
* Specifies the error type.
*/
- public DataType? type_reference {
+ public DataType? error_type {
get { return _data_type; }
set {
_data_type = value;
@@ -52,7 +52,7 @@
/**
* Specifies the declarator for the generated error variable.
*/
- public VariableDeclarator variable_declarator { get; set; }
+ public LocalVariable error_variable { get; set; }
private DataType _data_type;
@@ -65,8 +65,8 @@
* @param source_reference reference to source code
* @return newly created catch clause
*/
- public CatchClause (DataType? type_reference, string variable_name, Block body, SourceReference? source_reference = null) {
- this.type_reference = type_reference;
+ public CatchClause (DataType? error_type, string variable_name, Block body, SourceReference? source_reference = null) {
+ this.error_type = error_type;
this.variable_name = variable_name;
this.body = body;
this.source_reference = source_reference;
@@ -77,16 +77,16 @@
}
public override void accept_children (CodeVisitor visitor) {
- if (type_reference != null) {
- type_reference.accept (visitor);
+ if (error_type != null) {
+ error_type.accept (visitor);
}
body.accept (visitor);
}
public override void replace_type (DataType old_type, DataType new_type) {
- if (type_reference == old_type) {
- type_reference = new_type;
+ if (error_type == old_type) {
+ error_type = new_type;
}
}
}
Modified: trunk/vala/valacfgbuilder.vala
==============================================================================
--- trunk/vala/valacfgbuilder.vala (original)
+++ trunk/vala/valacfgbuilder.vala Wed Apr 16 16:45:33 2008
@@ -32,8 +32,8 @@
public bool continue_target { get; set; }
public bool return_target { get; set; }
public bool error_target { get; set; }
- public Enum? error_domain { get; set; }
- public EnumValue? error_code { get; set; }
+ public ErrorDomain? error_domain { get; set; }
+ public ErrorCode? error_code { get; set; }
public bool finally_clause { get; set; }
public BasicBlock basic_block { get; set; }
public BasicBlock? last_block { get; set; }
@@ -54,7 +54,7 @@
return_target = true;
}
- public JumpTarget.error_target (BasicBlock basic_block, CatchClause catch_clause, Enum? error_domain, EnumValue? error_code) {
+ public JumpTarget.error_target (BasicBlock basic_block, CatchClause catch_clause, ErrorDomain? error_domain, ErrorCode? error_code) {
this.basic_block = basic_block;
this.catch_clause = catch_clause;
this.error_domain = error_domain;
@@ -187,10 +187,9 @@
current_block.add_node (stmt);
- foreach (VariableDeclarator decl in stmt.declaration.get_variable_declarators ()) {
- if (decl.initializer != null) {
- handle_errors (decl.initializer);
- }
+ var local = stmt.declaration as LocalVariable;
+ if (local != null && local.initializer != null) {
+ handle_errors (local.initializer);
}
}
@@ -635,8 +634,8 @@
var catch_clauses = stmt.get_catch_clauses ();
for (int i = catch_clauses.size - 1; i >= 0; i--) {
var catch_clause = catch_clauses[i];
- if (catch_clause.type_reference != null) {
- jump_stack.add (new JumpTarget.error_target (new BasicBlock (), catch_clause, catch_clause.type_reference.data_type as Enum, null));
+ if (catch_clause.error_type != null) {
+ jump_stack.add (new JumpTarget.error_target (new BasicBlock (), catch_clause, catch_clause.error_type.data_type as ErrorDomain, null));
} else {
jump_stack.add (new JumpTarget.error_target (new BasicBlock (), catch_clause, null, null));
}
Modified: trunk/vala/valaclass.vala
==============================================================================
--- trunk/vala/valaclass.vala (original)
+++ trunk/vala/valaclass.vala Wed Apr 16 16:45:33 2008
@@ -205,8 +205,7 @@
if (m.result_var != null) {
m.scope.remove (m.result_var.name);
}
- m.result_var = new VariableDeclarator ("result");
- m.result_var.type_reference = m.return_type.copy ();
+ m.result_var = new LocalVariable (m.return_type.copy (), "result");
m.scope.add (m.result_var.name, m.result_var);
}
if (m is CreationMethod) {
Modified: trunk/vala/valacodecontext.vala
==============================================================================
--- trunk/vala/valacodecontext.vala (original)
+++ trunk/vala/valacodecontext.vala Wed Apr 16 16:45:33 2008
@@ -559,27 +559,15 @@
return node;
}
- public DeclarationStatement create_declaration_statement (LocalVariableDeclaration declaration, SourceReference? source_reference) {
+ public DeclarationStatement create_declaration_statement (Symbol declaration, SourceReference? source_reference) {
var node = new DeclarationStatement (declaration, source_reference);
node.code_binding = codegen.create_declaration_statement_binding (node);
return node;
}
- public LocalVariableDeclaration create_local_variable_declaration (DataType type_reference, SourceReference? source_reference) {
- var node = new LocalVariableDeclaration (type_reference, source_reference);
- node.code_binding = codegen.create_local_variable_declaration_binding (node);
- return node;
- }
-
- public LocalVariableDeclaration create_local_variable_declaration_var_type (SourceReference? source_reference) {
- var node = new LocalVariableDeclaration.var_type (source_reference);
- node.code_binding = codegen.create_local_variable_declaration_binding (node);
- return node;
- }
-
- public VariableDeclarator create_variable_declarator (string name, Expression? initializer = null, SourceReference? source_reference = null) {
- var node = new VariableDeclarator (name, initializer, source_reference);
- node.code_binding = codegen.create_variable_declarator_binding (node);
+ public LocalVariable create_local_variable (DataType? variable_type, string name, Expression? initializer = null, SourceReference? source_reference = null) {
+ var node = new LocalVariable (variable_type, name, initializer, source_reference);
+ node.code_binding = codegen.create_local_variable_binding (node);
return node;
}
Modified: trunk/vala/valacodegenerator.vala
==============================================================================
--- trunk/vala/valacodegenerator.vala (original)
+++ trunk/vala/valacodegenerator.vala Wed Apr 16 16:45:33 2008
@@ -126,11 +126,7 @@
return null;
}
- public virtual CodeBinding? create_local_variable_declaration_binding (LocalVariableDeclaration node) {
- return null;
- }
-
- public virtual CodeBinding? create_variable_declarator_binding (VariableDeclarator node) {
+ public virtual CodeBinding? create_local_variable_binding (LocalVariable node) {
return null;
}
Modified: trunk/vala/valacodevisitor.vala
==============================================================================
--- trunk/vala/valacodevisitor.vala (original)
+++ trunk/vala/valacodevisitor.vala Wed Apr 16 16:45:33 2008
@@ -252,19 +252,11 @@
}
/**
- * Visit operation called for local variable declarations.
+ * Visit operation called for local variables.
*
- * @param decl a local variable declaration
+ * @param local a local variable
*/
- public virtual void visit_local_variable_declaration (LocalVariableDeclaration decl) {
- }
-
- /**
- * Visit operation called for variable declarators.
- *
- * @param decl a variable declarator
- */
- public virtual void visit_variable_declarator (VariableDeclarator decl) {
+ public virtual void visit_local_variable (LocalVariable local) {
}
/**
Modified: trunk/vala/valadeclarationstatement.vala
==============================================================================
--- trunk/vala/valadeclarationstatement.vala (original)
+++ trunk/vala/valadeclarationstatement.vala Wed Apr 16 16:45:33 2008
@@ -1,6 +1,6 @@
/* valadeclarationstatement.vala
*
- * Copyright (C) 2006-2007 JÃrg Billeter
+ * Copyright (C) 2006-2008 JÃrg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -23,13 +23,13 @@
using GLib;
/**
- * Represents a local variable declaration statement in the source code.
+ * Represents a local variable or constant declaration statement in the source code.
*/
public class Vala.DeclarationStatement : CodeNode, Statement {
/**
- * The local variable declaration.
+ * The local variable or constant declaration.
*/
- public LocalVariableDeclaration declaration { get; set construct; }
+ public Symbol declaration { get; set construct; }
/**
* Creates a new declaration statement.
@@ -38,9 +38,9 @@
* @param source reference to source code
* @return newly created declaration statement
*/
- public DeclarationStatement (LocalVariableDeclaration decl, SourceReference source) {
- declaration = decl;
- source_reference = source;
+ public DeclarationStatement (Symbol declaration, SourceReference? source_reference) {
+ this.declaration = declaration;
+ this.source_reference = source_reference;
}
public override void accept (CodeVisitor visitor) {
Modified: trunk/vala/valaexpression.vala
==============================================================================
--- trunk/vala/valaexpression.vala (original)
+++ trunk/vala/valaexpression.vala Wed Apr 16 16:45:33 2008
@@ -84,7 +84,7 @@
*
* The code generator sets and uses them for memory management.
*/
- public ArrayList<VariableDeclarator> temp_vars = new ArrayList<VariableDeclarator> ();
+ public ArrayList<LocalVariable> temp_vars = new ArrayList<LocalVariable> ();
/**
* Returns whether this expression is pure, i.e. whether this expression
Modified: trunk/vala/valaforeachstatement.vala
==============================================================================
--- trunk/vala/valaforeachstatement.vala (original)
+++ trunk/vala/valaforeachstatement.vala Wed Apr 16 16:45:33 2008
@@ -72,17 +72,17 @@
/**
* Specifies the declarator for the generated element variable.
*/
- public VariableDeclarator variable_declarator { get; set; }
+ public LocalVariable element_variable { get; set; }
/**
* Specifies the declarator for the generated collection variable.
*/
- public VariableDeclarator collection_variable_declarator { get; set; }
+ public LocalVariable collection_variable { get; set; }
/**
* Specifies the declarator for the generated iterator variable.
*/
- public VariableDeclarator iterator_variable_declarator { get; set; }
+ public LocalVariable iterator_variable { get; set; }
private Expression _collection;
private Block _body;
Modified: trunk/vala/valainterface.vala
==============================================================================
--- trunk/vala/valainterface.vala (original)
+++ trunk/vala/valainterface.vala Wed Apr 16 16:45:33 2008
@@ -134,8 +134,7 @@
m.scope.add (m.this_parameter.name, m.this_parameter);
}
if (!(m.return_type is VoidType) && m.get_postconditions ().size > 0) {
- m.result_var = new VariableDeclarator ("result");
- m.result_var.type_reference = m.return_type.copy ();
+ m.result_var = new LocalVariable (m.return_type.copy (), "result");
m.scope.add (m.result_var.name, m.result_var);
}
Copied: trunk/vala/valalocalvariable.vala (from r1234, /trunk/vala/valavariabledeclarator.vala)
==============================================================================
--- /trunk/vala/valavariabledeclarator.vala (original)
+++ trunk/vala/valalocalvariable.vala Wed Apr 16 16:45:33 2008
@@ -1,4 +1,4 @@
-/* valavariabledeclarator.vala
+/* valalocalvariable.vala
*
* Copyright (C) 2006-2008 JÃrg Billeter
*
@@ -21,16 +21,15 @@
*/
using GLib;
-using Gee;
/**
- * Represents a variable declarator in the source code.
+ * Represents a local variable declaration in the source code.
*/
-public class Vala.VariableDeclarator : Symbol {
+public class Vala.LocalVariable : Symbol {
/**
* The optional initializer expression.
*/
- public Expression initializer {
+ public Expression? initializer {
get {
return _initializer;
}
@@ -45,33 +44,36 @@
/**
* The variable type.
*/
- public DataType type_reference {
- get { return _data_type; }
+ public DataType? variable_type {
+ get { return _variable_type; }
set {
- _data_type = value;
- _data_type.parent_node = this;
+ _variable_type = value;
+ if (_variable_type != null) {
+ _variable_type.parent_node = this;
+ }
}
}
- private Expression _initializer;
- private DataType _data_type;
+ private Expression? _initializer;
+ private DataType? _variable_type;
/**
- * Creates a new variable declarator.
+ * Creates a new local variable.
*
* @param name name of the variable
* @param init optional initializer expression
* @param source reference to source code
* @return newly created variable declarator
*/
- public VariableDeclarator (string name, Expression? initializer = null, SourceReference? source_reference = null) {
+ public LocalVariable (DataType? variable_type, string name, Expression? initializer = null, SourceReference? source_reference = null) {
+ this.variable_type = variable_type;
this.name = name;
this.initializer = initializer;
this.source_reference = source_reference;
}
public override void accept (CodeVisitor visitor) {
- visitor.visit_variable_declarator (this);
+ visitor.visit_local_variable (this);
}
public override void accept_children (CodeVisitor visitor) {
@@ -81,8 +83,8 @@
visitor.visit_end_full_expression (initializer);
}
- if (type_reference != null) {
- type_reference.accept (visitor);
+ if (variable_type != null) {
+ variable_type.accept (visitor);
}
}
@@ -93,8 +95,8 @@
}
public override void replace_type (DataType old_type, DataType new_type) {
- if (type_reference == old_type) {
- type_reference = new_type;
+ if (variable_type == old_type) {
+ variable_type = new_type;
}
}
}
Modified: trunk/vala/valamemorymanager.vala
==============================================================================
--- trunk/vala/valamemorymanager.vala (original)
+++ trunk/vala/valamemorymanager.vala Wed Apr 16 16:45:33 2008
@@ -126,15 +126,15 @@
b.accept_children (this);
}
- public override void visit_variable_declarator (VariableDeclarator decl) {
- decl.accept_children (this);
+ public override void visit_local_variable (LocalVariable local) {
+ local.accept_children (this);
- if (decl.initializer != null) {
- if (!(decl.type_reference is PointerType)) {
- if (decl.type_reference.takes_ownership) {
- visit_possibly_missing_copy_expression (decl.initializer);
+ if (local.initializer != null) {
+ if (!(local.variable_type is PointerType)) {
+ if (local.variable_type.takes_ownership) {
+ visit_possibly_missing_copy_expression (local.initializer);
} else {
- visit_possibly_leaked_expression (decl.initializer);
+ visit_possibly_leaked_expression (local.initializer);
}
}
}
Modified: trunk/vala/valamethod.vala
==============================================================================
--- trunk/vala/valamethod.vala (original)
+++ trunk/vala/valamethod.vala Wed Apr 16 16:45:33 2008
@@ -151,7 +151,7 @@
/**
* Specifies the generated `result' variable for postconditions.
*/
- public VariableDeclarator result_var { get; set; }
+ public LocalVariable result_var { get; set; }
/**
* Specifies the position of the instance parameter in the C function.
@@ -264,7 +264,7 @@
}
if (result_var != null) {
- result_var.type_reference.accept (visitor);
+ result_var.variable_type.accept (visitor);
}
foreach (Expression precondition in preconditions) {
Modified: trunk/vala/valanullchecker.vala
==============================================================================
--- trunk/vala/valanullchecker.vala (original)
+++ trunk/vala/valanullchecker.vala Wed Apr 16 16:45:33 2008
@@ -122,11 +122,11 @@
b.accept_children (this);
}
- public override void visit_variable_declarator (VariableDeclarator decl) {
- decl.accept_children (this);
+ public override void visit_local_variable (LocalVariable local) {
+ local.accept_children (this);
- if (decl.initializer != null) {
- check_compatible (decl.initializer, decl.type_reference);
+ if (local.initializer != null) {
+ check_compatible (local.initializer, local.variable_type);
}
}
Modified: trunk/vala/valaparser.vala
==============================================================================
--- trunk/vala/valaparser.vala (original)
+++ trunk/vala/valaparser.vala Wed Apr 16 16:45:33 2008
@@ -1094,55 +1094,97 @@
return expr;
}
- Statement parse_statement () throws ParseError {
- comment = scanner.pop_comment ();
- switch (current ()) {
- case TokenType.OPEN_BRACE:
- return parse_block ();
- case TokenType.SEMICOLON:
- return parse_empty_statement ();
- case TokenType.IF:
- return parse_if_statement ();
- case TokenType.SWITCH:
- return parse_switch_statement ();
- case TokenType.WHILE:
- return parse_while_statement ();
- case TokenType.DO:
- return parse_do_statement ();
- case TokenType.FOR:
- return parse_for_statement ();
- case TokenType.FOREACH:
- return parse_foreach_statement ();
- case TokenType.BREAK:
- return parse_break_statement ();
- case TokenType.CONTINUE:
- return parse_continue_statement ();
- case TokenType.RETURN:
- return parse_return_statement ();
- case TokenType.THROW:
- return parse_throw_statement ();
- case TokenType.TRY:
- return parse_try_statement ();
- case TokenType.LOCK:
- return parse_lock_statement ();
- case TokenType.DELETE:
- return parse_delete_statement ();
- case TokenType.VAR:
- return parse_declaration_statement ();
- case TokenType.OP_INC:
- case TokenType.OP_DEC:
- case TokenType.BASE:
- case TokenType.THIS:
- case TokenType.OPEN_PARENS:
- case TokenType.STAR:
- case TokenType.NEW:
- return parse_expression_statement ();
- }
+ void parse_statements (Block block) throws ParseError {
+ while (current () != TokenType.CLOSE_BRACE
+ && current () != TokenType.CASE
+ && current () != TokenType.DEFAULT) {
+ try {
+ Statement stmt;
+ bool is_decl = false;
+ comment = scanner.pop_comment ();
+ switch (current ()) {
+ case TokenType.OPEN_BRACE:
+ stmt = parse_block ();
+ break;
+ case TokenType.SEMICOLON:
+ stmt = parse_empty_statement ();
+ break;
+ case TokenType.IF:
+ stmt = parse_if_statement ();
+ break;
+ case TokenType.SWITCH:
+ stmt = parse_switch_statement ();
+ break;
+ case TokenType.WHILE:
+ stmt = parse_while_statement ();
+ break;
+ case TokenType.DO:
+ stmt = parse_do_statement ();
+ break;
+ case TokenType.FOR:
+ stmt = parse_for_statement ();
+ break;
+ case TokenType.FOREACH:
+ stmt = parse_foreach_statement ();
+ break;
+ case TokenType.BREAK:
+ stmt = parse_break_statement ();
+ break;
+ case TokenType.CONTINUE:
+ stmt = parse_continue_statement ();
+ break;
+ case TokenType.RETURN:
+ stmt = parse_return_statement ();
+ break;
+ case TokenType.THROW:
+ stmt = parse_throw_statement ();
+ break;
+ case TokenType.TRY:
+ stmt = parse_try_statement ();
+ break;
+ case TokenType.LOCK:
+ stmt = parse_lock_statement ();
+ break;
+ case TokenType.DELETE:
+ stmt = parse_delete_statement ();
+ break;
+ case TokenType.VAR:
+ is_decl = true;
+ parse_local_variable_declarations (block);
+ break;
+ case TokenType.OP_INC:
+ case TokenType.OP_DEC:
+ case TokenType.BASE:
+ case TokenType.THIS:
+ case TokenType.OPEN_PARENS:
+ case TokenType.STAR:
+ case TokenType.NEW:
+ stmt = parse_expression_statement ();
+ break;
+ default:
+ if (is_expression ()) {
+ stmt = parse_expression_statement ();
+ } else {
+ is_decl = true;
+ parse_local_variable_declarations (block);
+ }
+ break;
+ }
- if (is_expression ()) {
- return parse_expression_statement ();
- } else {
- return parse_declaration_statement ();
+ if (!is_decl) {
+ if (stmt == null) {
+ // workaround for current limitation of exception handling
+ throw new ParseError.SYNTAX ("syntax error in statement");
+ }
+ block.add_statement (stmt);
+ }
+ } catch (ParseError e) {
+ if (recover () != RecoveryState.STATEMENT_BEGIN) {
+ // beginning of next declaration or end of file reached
+ // return what we have so far
+ break;
+ }
+ }
}
}
@@ -1226,22 +1268,7 @@
Gee.List<Statement> list = new ArrayList<Statement> ();
expect (TokenType.OPEN_BRACE);
var block = context.create_block (get_src_com (begin));
- while (current () != TokenType.CLOSE_BRACE) {
- try {
- var stmt = parse_statement ();
- if (stmt == null) {
- // workaround for current limitation of exception handling
- throw new ParseError.SYNTAX ("syntax error in statement");
- }
- block.add_statement (stmt);
- } catch (ParseError e) {
- if (recover () != RecoveryState.STATEMENT_BEGIN) {
- // beginning of next declaration or end of file reached
- // return what we have so far
- return block;
- }
- }
- }
+ parse_statements (block);
if (!accept (TokenType.CLOSE_BRACE)) {
Report.error (get_current_src (), "expected `}'");
}
@@ -1255,35 +1282,37 @@
return context.create_empty_statement (get_src_com (begin));
}
- Statement parse_declaration_statement () throws ParseError {
+ void parse_local_variable_declarations (Block block) throws ParseError {
var begin = get_location ();
- var decl = parse_local_variable_declaration ();
+ DataType variable_type;
+ if (accept (TokenType.VAR)) {
+ variable_type = null;
+ } else {
+ variable_type = parse_type ();
+ var ut = variable_type as UnresolvedType;
+ if (ut != null && !ut.is_weak) {
+ variable_type.takes_ownership = true;
+ }
+ }
+ do {
+ DataType type_copy = null;
+ if (variable_type != null) {
+ type_copy = variable_type.copy ();
+ }
+ var local = parse_local_variable (type_copy);
+ block.add_statement (context.create_declaration_statement (local, local.source_reference));
+ } while (accept (TokenType.COMMA));
expect (TokenType.SEMICOLON);
- return context.create_declaration_statement (decl, get_src_com (begin));
}
- LocalVariableDeclaration parse_local_variable_declaration () throws ParseError {
+ LocalVariable parse_local_variable (DataType? variable_type) throws ParseError {
var begin = get_location ();
- LocalVariableDeclaration decl;
- if (accept (TokenType.VAR)) {
- var declarators = parse_variable_declarators ();
- decl = context.create_local_variable_declaration_var_type (get_src (begin));
- foreach (VariableDeclarator var_decl in declarators) {
- decl.add_declarator (var_decl);
- }
- } else {
- var type = parse_type ();
- var declarators = parse_variable_declarators ();
- if (!((UnresolvedType) type).is_weak) {
- type.takes_ownership = true;
- }
- decl = context.create_local_variable_declaration (type, get_src (begin));
- foreach (VariableDeclarator var_decl in declarators) {
- var_decl.type_reference = type.copy ();
- decl.add_declarator (var_decl);
- }
+ string id = parse_identifier ();
+ Expression initializer = null;
+ if (accept (TokenType.ASSIGN)) {
+ initializer = parse_variable_initializer ();
}
- return decl;
+ return context.create_local_variable (variable_type, id, initializer, get_src_com (begin));
}
Statement parse_expression_statement () throws ParseError {
@@ -1334,11 +1363,7 @@
}
expect (TokenType.COLON);
} while (current () == TokenType.CASE || current () == TokenType.DEFAULT);
- while (current () != TokenType.CLOSE_BRACE
- && current () != TokenType.CASE
- && current () != TokenType.DEFAULT) {
- section.add_statement (parse_statement ());
- }
+ parse_statements (section);
stmt.add_section (section);
}
expect (TokenType.CLOSE_BRACE);
@@ -1392,11 +1417,22 @@
do {
initializer_list.add (parse_statement_expression ());
} while (accept (TokenType.COMMA));
- expect (TokenType.SEMICOLON);
} else {
block = context.create_block (get_src (begin));
- block.add_statement (parse_declaration_statement ());
+ DataType variable_type;
+ if (accept (TokenType.VAR)) {
+ variable_type = null;
+ } else {
+ variable_type = parse_type ();
+ var ut = variable_type as UnresolvedType;
+ if (ut != null && !ut.is_weak) {
+ variable_type.takes_ownership = true;
+ }
+ }
+ var local = parse_local_variable (variable_type);
+ block.add_statement (context.create_declaration_statement (local, local.source_reference));
}
+ expect (TokenType.SEMICOLON);
}
Expression condition = null;
if (current () != TokenType.SEMICOLON) {
@@ -1988,25 +2024,6 @@
return f;
}
- Gee.List<VariableDeclarator> parse_variable_declarators () throws ParseError {
- var list = new ArrayList<VariableDeclarator> ();
- do {
- var var_decl = parse_variable_declarator ();
- list.add (var_decl);
- } while (accept (TokenType.COMMA));
- return list;
- }
-
- VariableDeclarator parse_variable_declarator () throws ParseError {
- var begin = get_location ();
- string id = parse_identifier ();
- Expression initializer = null;
- if (accept (TokenType.ASSIGN)) {
- initializer = parse_variable_initializer ();
- }
- return context.create_variable_declarator (id, initializer, get_src (begin));
- }
-
InitializerList parse_initializer () throws ParseError {
var begin = get_location ();
expect (TokenType.OPEN_BRACE);
Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala (original)
+++ trunk/vala/valasemanticanalyzer.vala Wed Apr 16 16:45:33 2008
@@ -771,93 +771,93 @@
b.accept_children (this);
- foreach (VariableDeclarator decl in b.get_local_variables ()) {
- decl.active = false;
+ foreach (LocalVariable local in b.get_local_variables ()) {
+ local.active = false;
}
current_symbol = current_symbol.parent_symbol;
}
- public override void visit_variable_declarator (VariableDeclarator decl) {
- if (decl.initializer != null) {
- decl.initializer.expected_type = decl.type_reference;
+ public override void visit_local_variable (LocalVariable local) {
+ if (local.initializer != null) {
+ local.initializer.expected_type = local.variable_type;
}
- decl.accept_children (this);
+ local.accept_children (this);
- if (decl.type_reference == null) {
+ if (local.variable_type == null) {
/* var type */
- if (decl.initializer == null) {
- decl.error = true;
- Report.error (decl.source_reference, "var declaration not allowed without initializer");
+ if (local.initializer == null) {
+ local.error = true;
+ Report.error (local.source_reference, "var declaration not allowed without initializer");
return;
}
- if (decl.initializer.static_type == null) {
- decl.error = true;
- Report.error (decl.source_reference, "var declaration not allowed with non-typed initializer");
+ if (local.initializer.static_type == null) {
+ local.error = true;
+ Report.error (local.source_reference, "var declaration not allowed with non-typed initializer");
return;
}
- decl.type_reference = decl.initializer.static_type.copy ();
- decl.type_reference.takes_ownership = (decl.type_reference.data_type == null || decl.type_reference.data_type.is_reference_type ());
- decl.type_reference.transfers_ownership = false;
+ local.variable_type = local.initializer.static_type.copy ();
+ local.variable_type.takes_ownership = (local.variable_type.data_type == null || local.variable_type.data_type.is_reference_type ());
+ local.variable_type.transfers_ownership = false;
}
- if (decl.initializer != null) {
- if (decl.initializer.static_type == null) {
- if (!(decl.initializer is MemberAccess) && !(decl.initializer is LambdaExpression)) {
- decl.error = true;
- Report.error (decl.source_reference, "expression type not allowed as initializer");
+ if (local.initializer != null) {
+ if (local.initializer.static_type == null) {
+ if (!(local.initializer is MemberAccess) && !(local.initializer is LambdaExpression)) {
+ local.error = true;
+ Report.error (local.source_reference, "expression type not allowed as initializer");
return;
}
- if (decl.initializer.symbol_reference is Method &&
- decl.type_reference is DelegateType) {
- var m = (Method) decl.initializer.symbol_reference;
- var dt = (DelegateType) decl.type_reference;
+ if (local.initializer.symbol_reference is Method &&
+ local.variable_type is DelegateType) {
+ var m = (Method) local.initializer.symbol_reference;
+ var dt = (DelegateType) local.variable_type;
var cb = dt.delegate_symbol;
/* check whether method matches callback type */
if (!cb.matches_method (m)) {
- decl.error = true;
- Report.error (decl.source_reference, "declaration of method `%s' doesn't match declaration of callback `%s'".printf (m.get_full_name (), cb.get_full_name ()));
+ local.error = true;
+ Report.error (local.source_reference, "declaration of method `%s' doesn't match declaration of callback `%s'".printf (m.get_full_name (), cb.get_full_name ()));
return;
}
- decl.initializer.static_type = decl.type_reference;
+ local.initializer.static_type = local.variable_type;
} else {
- decl.error = true;
- Report.error (decl.source_reference, "expression type not allowed as initializer");
+ local.error = true;
+ Report.error (local.source_reference, "expression type not allowed as initializer");
return;
}
}
- if (!decl.initializer.static_type.compatible (decl.type_reference)) {
- decl.error = true;
- Report.error (decl.source_reference, "Assignment: Cannot convert from `%s' to `%s'".printf (decl.initializer.static_type.to_string (), decl.type_reference.to_string ()));
+ if (!local.initializer.static_type.compatible (local.variable_type)) {
+ local.error = true;
+ Report.error (local.source_reference, "Assignment: Cannot convert from `%s' to `%s'".printf (local.initializer.static_type.to_string (), local.variable_type.to_string ()));
return;
}
- if (decl.initializer.static_type.transfers_ownership) {
+ if (local.initializer.static_type.transfers_ownership) {
/* rhs transfers ownership of the expression */
- if (!(decl.type_reference is PointerType) && !decl.type_reference.takes_ownership) {
+ if (!(local.variable_type is PointerType) && !local.variable_type.takes_ownership) {
/* lhs doesn't own the value */
- decl.error = true;
- Report.error (decl.source_reference, "Invalid assignment from owned expression to unowned variable");
+ local.error = true;
+ Report.error (local.source_reference, "Invalid assignment from owned expression to unowned variable");
return;
}
}
}
- current_source_file.add_type_dependency (decl.type_reference, SourceFileDependencyType.SOURCE);
+ current_source_file.add_type_dependency (local.variable_type, SourceFileDependencyType.SOURCE);
- current_symbol.scope.add (decl.name, decl);
+ current_symbol.scope.add (local.name, local);
var block = (Block) current_symbol;
- block.add_local_variable (decl);
+ block.add_local_variable (local);
- decl.active = true;
+ local.active = true;
}
/**
@@ -968,8 +968,8 @@
st.accept (this);
}
- foreach (VariableDeclarator decl in section.get_local_variables ()) {
- decl.active = false;
+ foreach (LocalVariable local in section.get_local_variables ()) {
+ local.active = false;
}
current_symbol = current_symbol.parent_symbol;
@@ -1026,21 +1026,20 @@
public override void visit_foreach_statement (ForeachStatement stmt) {
current_source_file.add_type_dependency (stmt.type_reference, SourceFileDependencyType.SOURCE);
- stmt.variable_declarator = new VariableDeclarator (stmt.variable_name);
- stmt.variable_declarator.type_reference = stmt.type_reference;
+ stmt.element_variable = new LocalVariable (stmt.type_reference, stmt.variable_name);
- stmt.body.scope.add (stmt.variable_name, stmt.variable_declarator);
+ stmt.body.scope.add (stmt.variable_name, stmt.element_variable);
- stmt.body.add_local_variable (stmt.variable_declarator);
- stmt.variable_declarator.active = true;
+ stmt.body.add_local_variable (stmt.element_variable);
+ stmt.element_variable.active = true;
stmt.owner = current_symbol.scope;
current_symbol = stmt;
stmt.accept_children (this);
- foreach (VariableDeclarator decl in stmt.get_local_variables ()) {
- decl.active = false;
+ foreach (LocalVariable local in stmt.get_local_variables ()) {
+ local.active = false;
}
current_symbol = current_symbol.parent_symbol;
@@ -1055,15 +1054,14 @@
return;
}
- stmt.collection_variable_declarator = new VariableDeclarator ("%s_collection".printf (stmt.variable_name));
- stmt.collection_variable_declarator.type_reference = stmt.collection.static_type.copy ();
- stmt.collection_variable_declarator.type_reference.transfers_ownership = false;
- stmt.collection_variable_declarator.type_reference.takes_ownership = stmt.collection.static_type.transfers_ownership;
+ var collection_type = stmt.collection.static_type.copy ();
+ collection_type.transfers_ownership = false;
+ collection_type.takes_ownership = stmt.collection.static_type.transfers_ownership;
+ stmt.collection_variable = new LocalVariable (collection_type, "%s_collection".printf (stmt.variable_name));
- stmt.add_local_variable (stmt.collection_variable_declarator);
- stmt.collection_variable_declarator.active = true;
+ stmt.add_local_variable (stmt.collection_variable);
+ stmt.collection_variable.active = true;
- var collection_type = stmt.collection.static_type;
DataType element_data_type = null;
bool need_type_check = false;
@@ -1077,13 +1075,13 @@
need_type_check = true;
}
} else if (iterable_type != null && collection_type.compatible (iterable_type)) {
- stmt.iterator_variable_declarator = new VariableDeclarator ("%s_it".printf (stmt.variable_name));
- stmt.iterator_variable_declarator.type_reference = new InterfaceType (iterator_type);
- stmt.iterator_variable_declarator.type_reference.takes_ownership = true;
- stmt.iterator_variable_declarator.type_reference.add_type_argument (stmt.type_reference);
+ var foreach_iterator_type = new InterfaceType (iterator_type);
+ foreach_iterator_type.takes_ownership = true;
+ foreach_iterator_type.add_type_argument (stmt.type_reference);
+ stmt.iterator_variable = new LocalVariable (foreach_iterator_type, "%s_it".printf (stmt.variable_name));
- stmt.add_local_variable (stmt.iterator_variable_declarator);
- stmt.iterator_variable_declarator.active = true;
+ stmt.add_local_variable (stmt.iterator_variable);
+ stmt.iterator_variable.active = true;
var it_method = (Method) iterable_type.data_type.scope.lookup ("iterator");
if (it_method.return_type.get_type_arguments ().size > 0) {
@@ -1154,7 +1152,7 @@
}
if (stmt.return_expression != null &&
- stmt.return_expression.symbol_reference is VariableDeclarator &&
+ stmt.return_expression.symbol_reference is LocalVariable &&
stmt.return_expression.static_type.takes_ownership &&
!current_return_type.transfers_ownership) {
Report.warning (stmt.source_reference, "Local variable with strong reference used as return value and method return type hasn't been declared to transfer ownership");
@@ -1175,15 +1173,14 @@
}
public override void visit_catch_clause (CatchClause clause) {
- if (clause.type_reference != null) {
- current_source_file.add_type_dependency (clause.type_reference, SourceFileDependencyType.SOURCE);
+ if (clause.error_type != null) {
+ current_source_file.add_type_dependency (clause.error_type, SourceFileDependencyType.SOURCE);
- clause.variable_declarator = new VariableDeclarator (clause.variable_name);
- clause.variable_declarator.type_reference = clause.type_reference.copy ();
+ clause.error_variable = new LocalVariable (clause.error_type.copy (), clause.variable_name);
- clause.body.scope.add (clause.variable_name, clause.variable_declarator);
+ clause.body.scope.add (clause.variable_name, clause.error_variable);
} else {
- clause.type_reference = new ErrorType (null, clause.source_reference);
+ clause.error_type = new ErrorType (null, clause.source_reference);
}
clause.accept_children (this);
@@ -1387,9 +1384,9 @@
return type;
} else if (sym is DataType) {
return (DataType) sym;
- } else if (sym is VariableDeclarator) {
- var decl = (VariableDeclarator) sym;
- return decl.type_reference;
+ } else if (sym is LocalVariable) {
+ var local = (LocalVariable) sym;
+ return local.variable_type;
} else if (sym is EnumValue) {
return new ValueType ((Typesymbol) sym.parent_symbol);
} else if (sym is Method) {
@@ -2453,7 +2450,7 @@
parenthexp.accept (this);
return;
} else if (expr.operator == UnaryOperator.REF || expr.operator == UnaryOperator.OUT) {
- if (expr.inner.symbol_reference is Field || expr.inner.symbol_reference is FormalParameter || expr.inner.symbol_reference is VariableDeclarator) {
+ if (expr.inner.symbol_reference is Field || expr.inner.symbol_reference is FormalParameter || expr.inner.symbol_reference is LocalVariable) {
// ref and out can only be used with fields, parameters, and local variables
expr.static_type = expr.inner.static_type;
} else {
@@ -2965,23 +2962,23 @@
Report.error (ma.source_reference, "Property `%s' is read-only".printf (prop.get_full_name ()));
return;
}
- } else if (ma.symbol_reference is VariableDeclarator && a.right.static_type == null) {
- var decl = (VariableDeclarator) ma.symbol_reference;
+ } else if (ma.symbol_reference is LocalVariable && a.right.static_type == null) {
+ var local = (LocalVariable) ma.symbol_reference;
if (a.right.symbol_reference is Method &&
- decl.type_reference is DelegateType) {
+ local.variable_type is DelegateType) {
var m = (Method) a.right.symbol_reference;
- var dt = (DelegateType) decl.type_reference;
+ var dt = (DelegateType) local.variable_type;
var cb = dt.delegate_symbol;
/* check whether method matches callback type */
if (!cb.matches_method (m)) {
- decl.error = true;
+ a.error = true;
Report.error (a.source_reference, "declaration of method `%s' doesn't match declaration of callback `%s'".printf (m.get_full_name (), cb.get_full_name ()));
return;
}
- a.right.static_type = decl.type_reference;
+ a.right.static_type = local.variable_type;
} else {
a.error = true;
Report.error (a.source_reference, "Assignment: Invalid callback assignment attempt");
Modified: trunk/vala/valastruct.vala
==============================================================================
--- trunk/vala/valastruct.vala (original)
+++ trunk/vala/valastruct.vala Wed Apr 16 16:45:33 2008
@@ -120,8 +120,7 @@
m.scope.add (m.this_parameter.name, m.this_parameter);
}
if (!(m.return_type is VoidType) && m.get_postconditions ().size > 0) {
- m.result_var = new VariableDeclarator ("result");
- m.result_var.type_reference = m.return_type.copy ();
+ m.result_var = new LocalVariable (m.return_type.copy (), "result");
m.scope.add (m.result_var.name, m.result_var);
}
if (m is CreationMethod) {
Modified: trunk/vala/valaswitchsection.vala
==============================================================================
--- trunk/vala/valaswitchsection.vala (original)
+++ trunk/vala/valaswitchsection.vala Wed Apr 16 16:45:33 2008
@@ -1,6 +1,6 @@
/* valaswitchsection.vala
*
- * Copyright (C) 2006-2007 JÃrg Billeter
+ * Copyright (C) 2006-2008 JÃrg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -28,7 +28,6 @@
*/
public class Vala.SwitchSection : Block {
private Gee.List<SwitchLabel> labels = new ArrayList<SwitchLabel> ();
- private Gee.List<Statement> statement_list = new ArrayList<Statement> ();
/**
* Creates a new switch section.
@@ -68,24 +67,6 @@
return false;
}
- /**
- * Appends the specified statement to this switch section.
- *
- * @param stmt a statement
- */
- public void add_statement (Statement stmt) {
- statement_list.add (stmt);
- }
-
- /**
- * Returns a copy of the list of statements.
- *
- * @return statement list
- */
- public Collection<Statement> get_statements () {
- return new ReadOnlyCollection<Statement> (statement_list);
- }
-
public override void accept (CodeVisitor visitor) {
visitor.visit_switch_section (this);
}
@@ -95,7 +76,7 @@
label.accept (visitor);
}
- foreach (Statement st in statement_list) {
+ foreach (Statement st in get_statements ()) {
st.accept (visitor);
}
}
Modified: trunk/vala/valasymbolresolver.vala
==============================================================================
--- trunk/vala/valasymbolresolver.vala (original)
+++ trunk/vala/valasymbolresolver.vala Wed Apr 16 16:45:33 2008
@@ -317,10 +317,10 @@
unresolved_type.parent_node.replace_type (unresolved_type, resolve_type (unresolved_type));
}
- public override void visit_variable_declarator (VariableDeclarator decl) {
- decl.accept_children (this);
- if (decl.type_reference is ReferenceType) {
- decl.type_reference.nullable = true;
+ public override void visit_local_variable (LocalVariable local) {
+ local.accept_children (this);
+ if (local.variable_type is ReferenceType) {
+ local.variable_type.nullable = true;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]