Commit 882c3bcc authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

Rename VariableDeclarator to LocalVariable, remove

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

svn path=/trunk/; revision=1243
parent 51bc9af7
2008-04-16 Jürg 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
2008-04-16 Marc-Andre Lureau <marcandre.lureau@gmail.com>
* vapi/glib-2.0.vapi: Make DestroyNotify delegate argument
......
......@@ -48,7 +48,7 @@ public class Vala.CCodeArrayCreationExpressionBinding : CCodeExpressionBinding {
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 @@ public class Vala.CCodeArrayCreationExpressionBinding : CCodeExpressionBinding {
}
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;
......
......@@ -176,7 +176,7 @@ public class Vala.CCodeAssignmentBinding : CCodeExpressionBinding {
// 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 @@ public class Vala.CCodeAssignmentBinding : CCodeExpressionBinding {
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 @@ public class Vala.CCodeAssignmentBinding : CCodeExpressionBinding {
// 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 ();
......
This diff is collapsed.
......@@ -267,7 +267,7 @@ public class Vala.CCodeGenerator {
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 @@ public class Vala.CCodeGenerator {
// (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 @@ public class Vala.CCodeGenerator {
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 @@ public class Vala.CCodeGenerator {
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 @@ public class Vala.CCodeGenerator {
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 @@ public class Vala.CCodeGenerator {
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 @@ public class Vala.CCodeGenerator {
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 @@ public class Vala.CCodeGenerator {
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)));
......
......@@ -54,9 +54,9 @@ public class Vala.CCodeGenerator {
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 @@ public class Vala.CCodeGenerator {
// 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 @@ public class Vala.CCodeGenerator {
// 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 @@ public class Vala.CCodeGenerator {
} 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") {
......
......@@ -78,7 +78,7 @@ libvalacore_la_VALASOURCES = \
valainvocationexpression.vala \
valalambdaexpression.vala \
valaliteral.vala \
valalocalvariabledeclaration.vala \
valalocalvariable.vala \
valalockable.vala \
valalockstatement.vala \
valamember.vala \
......@@ -137,7 +137,6 @@ libvalacore_la_VALASOURCES = \
valaunresolvedsymbol.vala \
valaunresolvedtype.vala \
valavaluetype.vala \
valavariabledeclarator.vala \
valavoidtype.vala \
valawhilestatement.vala \
$(NULL)
......
......@@ -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>
/* 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 class Vala.Block : Symbol, Statement {
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 @@ public class Vala.Block : Symbol, Statement {
*
* @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 @@ public class Vala.Block : Symbol, Statement {
*
* @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) {
......
......@@ -29,7 +29,7 @@ public class Vala.CatchClause : CodeNode {
/**
* Specifies the error type.
*/
public DataType? type_reference {
public DataType? error_type {
get { return _data_type; }
set {
_data_type = value;
......@@ -52,7 +52,7 @@ public class Vala.CatchClause : CodeNode {
/**
* 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 @@ public class Vala.CatchClause : CodeNode {
* @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 class Vala.CatchClause : CodeNode {
}
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;
}
}
}
......@@ -32,8 +32,8 @@ public class Vala.CFGBuilder : CodeVisitor {
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 @@ public class Vala.CFGBuilder : CodeVisitor {
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 @@ public class Vala.CFGBuilder : CodeVisitor {
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 @@ public class Vala.CFGBuilder : CodeVisitor {
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));
}
......
......@@ -205,8 +205,7 @@ public class Vala.Class : Typesymbol {
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) {
......
......@@ -559,27 +559,15 @@ public class Vala.CodeContext : Object {
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;
}
......
......@@ -126,11 +126,7 @@ public class Vala.CodeGenerator : CodeVisitor {
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;
}
......
......@@ -252,19 +252,11 @@ public abstract class Vala.CodeVisitor : Object {
}
/**
* 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) {
}
/**
......
/* 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 @@ public class Vala.DeclarationStatement : CodeNode, Statement {
* @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) {
......
......@@ -84,7 +84,7 @@ public abstract class Vala.Expression : CodeNode {
*
* 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
......
......@@ -72,17 +72,17 @@ public class Vala.ForeachStatement : Block {
/**
* 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;
......
......@@ -134,8 +134,7 @@ public class Vala.Interface : Typesymbol {
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);
}
......
/* 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 @@ public class Vala.VariableDeclarator : Symbol {
/**
* 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 @@ public class Vala.VariableDeclarator : Symbol {
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 class Vala.VariableDeclarator : Symbol {
}
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;
}
}
}
/* valalocalvariabledeclaration.vala
*
* Copyright (C) 2006-2007 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
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author:
* Jürg Billeter <j@bitron.ch>
*/
using GLib;
using Gee;
/**
* Represents a local variable declaration in the source code.
*/
public class Vala.LocalVariableDeclaration : CodeNode {
/**
* The type of the local variable.
*/
public DataType type_reference {
get { return _data_type; }
set {
_data_type = value;
_data_type.parent_node = this;
}
}
private DataType _data_type;
private Gee.List<VariableDeclarator> variable_declarators = new ArrayList<VariableDeclarator> ();
/**
* Creates a new local variable declaration.
*
* @param type_reference type of the variable
* @param source_reference reference to source code
* @return newly created local variable declaration
*/
public LocalVariableDeclaration (DataType type_reference, SourceReference source_reference) {
this.type_reference = type_reference;
this.source_reference = source_reference;
}
/**