Commit 5cfdd606 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

move iteration of symbol nodes from accept to accept_children method

2007-06-15  Jürg Billeter  <j@bitron.ch>

	* vala/valaattributeprocessor.vala, vala/valacodevisitor.vala,
	  vala/valainterfacewriter.vala, vala/valamemorymanager.vala,
	  vala/valasemanticanalyzer.vala, vala/valasymbolbuilder.vala,
	  vala/valasymbolresolver.vala, vala/valaconstant.vala,
	  vala/valaconstructor.vala, vala/valacreationmethod.vala,
	  vala/valadestructor.vala, vala/valafield.vala,
	  vala/valaformalparameter.vala, vala/valamethod.vala,
	  vala/valaproperty.vala, vala/valapropertyaccessor.vala,
	  vala/valasignal.vala, gobject/valacodegenerator.vala,
	  gobject/valacodegeneratormethod.vala,
	  gobject/valacodegeneratorsignal.vala: move iteration of symbol nodes
	  from accept to accept_children method

svn path=/trunk/; revision=324
parent 6cbc5a68
2007-06-15 Jürg Billeter <j@bitron.ch>
* vala/valaattributeprocessor.vala, vala/valacodevisitor.vala,
vala/valainterfacewriter.vala, vala/valamemorymanager.vala,
vala/valasemanticanalyzer.vala, vala/valasymbolbuilder.vala,
vala/valasymbolresolver.vala, vala/valaconstant.vala,
vala/valaconstructor.vala, vala/valacreationmethod.vala,
vala/valadestructor.vala, vala/valafield.vala,
vala/valaformalparameter.vala, vala/valamethod.vala,
vala/valaproperty.vala, vala/valapropertyaccessor.vala,
vala/valasignal.vala, gobject/valacodegenerator.vala,
gobject/valacodegeneratormethod.vala,
gobject/valacodegeneratorsignal.vala: move iteration of symbol nodes
from accept to accept_children method
2007-06-15 Jürg Billeter <j@bitron.ch>
* vala/valaattributeprocessor.vala, vala/valacodevisitor.vala,
......
......@@ -345,6 +345,8 @@ public class Vala.CodeGenerator : CodeVisitor {
}
public override void visit_constant (Constant! c) {
c.accept_children (this);
if (c.symbol.parent_symbol.node is DataType) {
var t = (DataType) c.symbol.parent_symbol.node;
var cdecl = new CCodeDeclaration (c.type_reference.get_const_cname ());
......@@ -364,6 +366,8 @@ public class Vala.CodeGenerator : CodeVisitor {
}
public override void visit_field (Field! f) {
f.accept_children (this);
CCodeExpression lhs = null;
CCodeStruct st = null;
......@@ -427,16 +431,20 @@ public class Vala.CodeGenerator : CodeVisitor {
}
public override void visit_formal_parameter (FormalParameter! p) {
p.accept_children (this);
if (!p.ellipsis) {
p.ccodenode = new CCodeFormalParameter (p.name, p.type_reference.get_cname (false, !p.type_reference.takes_ownership));
}
}
public override void visit_end_property (Property! prop) {
public override void visit_property (Property! prop) {
prop.accept_children (this);
prop_enum.add_value (prop.get_upper_case_cname (), null);
}
public override void visit_begin_property_accessor (PropertyAccessor! acc) {
public override void visit_property_accessor (PropertyAccessor! acc) {
var prop = (Property) acc.symbol.parent_symbol.node;
if (acc.readable) {
......@@ -445,10 +453,8 @@ public class Vala.CodeGenerator : CodeVisitor {
// void
current_return_type = new TypeReference ();
}
}
public override void visit_end_property_accessor (PropertyAccessor! acc) {
var prop = (Property) acc.symbol.parent_symbol.node;
acc.accept_children (this);
current_return_type = null;
......@@ -550,7 +556,9 @@ public class Vala.CodeGenerator : CodeVisitor {
}
}
public override void visit_end_constructor (Constructor! c) {
public override void visit_constructor (Constructor! c) {
c.accept_children (this);
var cl = (Class) c.symbol.parent_symbol.node;
function = new CCodeFunction ("%s_constructor".printf (cl.get_lower_case_cname (null)), "GObject *");
......@@ -618,6 +626,10 @@ public class Vala.CodeGenerator : CodeVisitor {
source_type_member_definition.append (function);
}
public override void visit_destructor (Destructor! d) {
d.accept_children (this);
}
public override void visit_begin_block (Block! b) {
current_symbol = b.symbol;
}
......
......@@ -24,79 +24,24 @@
using GLib;
public class Vala.CodeGenerator {
public override void visit_begin_method (Method! m) {
public override void visit_method (Method! m) {
current_symbol = m.symbol;
current_return_type = m.return_type;
}
private ref CCodeStatement create_method_type_check_statement (Method! m, DataType! t, bool non_null, string! var_name) {
return create_type_check_statement (m, m.return_type.data_type, t, non_null, var_name);
}
private ref CCodeStatement create_property_type_check_statement (Property! prop, bool getter, DataType! t, bool non_null, string! var_name) {
if (getter) {
return create_type_check_statement (prop, prop.type_reference.data_type, t, non_null, var_name);
} else {
return create_type_check_statement (prop, null, t, non_null, var_name);
}
}
private ref CCodeStatement create_type_check_statement (CodeNode! method_node, DataType ret_type, DataType! t, bool non_null, string! var_name) {
var ccheck = new CCodeFunctionCall ();
if (t is Class || t is Interface) {
var ctype_check = new CCodeFunctionCall (new CCodeIdentifier (t.get_upper_case_cname ("IS_")));
ctype_check.add_argument (new CCodeIdentifier (var_name));
ref CCodeExpression cexpr = ctype_check;
if (!non_null) {
var cnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeIdentifier (var_name), new CCodeConstant ("NULL"));
cexpr = new CCodeBinaryExpression (CCodeBinaryOperator.OR, cnull, ctype_check);
}
ccheck.add_argument (cexpr);
} else if (!non_null) {
return null;
} else {
var cnonnull = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, new CCodeIdentifier (var_name), new CCodeConstant ("NULL"));
ccheck.add_argument (cnonnull);
}
if (ret_type == null) {
/* void function */
ccheck.call = new CCodeIdentifier ("g_return_if_fail");
} else {
ccheck.call = new CCodeIdentifier ("g_return_val_if_fail");
if (ret_type.is_reference_type () || ret_type is Pointer) {
ccheck.add_argument (new CCodeConstant ("NULL"));
} else if (ret_type.get_default_value () != null) {
ccheck.add_argument (new CCodeConstant (ret_type.get_default_value ()));
} else {
Report.warning (method_node.source_reference, "not supported return type for runtime type checks");
return new CCodeExpressionStatement (new CCodeConstant ("0"));
}
if (m is CreationMethod) {
in_creation_method = true;
}
return new CCodeExpressionStatement (ccheck);
}
private DataType find_parent_type (CodeNode node) {
var sym = node.symbol;
while (sym != null) {
if (sym.node is DataType) {
return (DataType) sym.node;
m.accept_children (this);
if (m is CreationMethod) {
if (current_class != null && m.body != null) {
add_object_creation ((CCodeBlock) m.body.ccodenode);
}
sym = sym.parent_symbol;
in_creation_method = false;
}
return null;
}
private ref string! get_array_length_cname (string! array_cname, int dim) {
return "%s_length%d".printf (array_cname, dim);
}
public override void visit_end_method (Method! m) {
current_symbol = current_symbol.parent_symbol;
current_return_type = null;
......@@ -384,20 +329,75 @@ public class Vala.CodeGenerator {
}
}
public override void visit_begin_creation_method (CreationMethod! m) {
current_symbol = m.symbol;
current_return_type = m.return_type;
in_creation_method = true;
private ref CCodeStatement create_method_type_check_statement (Method! m, DataType! t, bool non_null, string! var_name) {
return create_type_check_statement (m, m.return_type.data_type, t, non_null, var_name);
}
public override void visit_end_creation_method (CreationMethod! m) {
if (current_class != null && m.body != null) {
add_object_creation ((CCodeBlock) m.body.ccodenode);
private ref CCodeStatement create_property_type_check_statement (Property! prop, bool getter, DataType! t, bool non_null, string! var_name) {
if (getter) {
return create_type_check_statement (prop, prop.type_reference.data_type, t, non_null, var_name);
} else {
return create_type_check_statement (prop, null, t, non_null, var_name);
}
}
private ref CCodeStatement create_type_check_statement (CodeNode! method_node, DataType ret_type, DataType! t, bool non_null, string! var_name) {
var ccheck = new CCodeFunctionCall ();
if (t is Class || t is Interface) {
var ctype_check = new CCodeFunctionCall (new CCodeIdentifier (t.get_upper_case_cname ("IS_")));
ctype_check.add_argument (new CCodeIdentifier (var_name));
ref CCodeExpression cexpr = ctype_check;
if (!non_null) {
var cnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeIdentifier (var_name), new CCodeConstant ("NULL"));
cexpr = new CCodeBinaryExpression (CCodeBinaryOperator.OR, cnull, ctype_check);
}
ccheck.add_argument (cexpr);
} else if (!non_null) {
return null;
} else {
var cnonnull = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, new CCodeIdentifier (var_name), new CCodeConstant ("NULL"));
ccheck.add_argument (cnonnull);
}
if (ret_type == null) {
/* void function */
ccheck.call = new CCodeIdentifier ("g_return_if_fail");
} else {
ccheck.call = new CCodeIdentifier ("g_return_val_if_fail");
if (ret_type.is_reference_type () || ret_type is Pointer) {
ccheck.add_argument (new CCodeConstant ("NULL"));
} else if (ret_type.get_default_value () != null) {
ccheck.add_argument (new CCodeConstant (ret_type.get_default_value ()));
} else {
Report.warning (method_node.source_reference, "not supported return type for runtime type checks");
return new CCodeExpressionStatement (new CCodeConstant ("0"));
}
}
return new CCodeExpressionStatement (ccheck);
}
in_creation_method = false;
private DataType find_parent_type (CodeNode node) {
var sym = node.symbol;
while (sym != null) {
if (sym.node is DataType) {
return (DataType) sym.node;
}
sym = sym.parent_symbol;
}
return null;
}
private ref string! get_array_length_cname (string! array_cname, int dim) {
return "%s_length%d".printf (array_cname, dim);
}
visit_end_method (m);
public override void visit_creation_method (CreationMethod! m) {
visit_method (m);
}
private bool is_possible_entry_point (Method! m, ref bool return_value, ref bool args_parameter) {
......
......@@ -107,7 +107,9 @@ public class Vala.CodeGenerator {
return signature;
}
public override void visit_end_signal (Signal! sig) {
public override void visit_signal (Signal! sig) {
sig.accept_children (this);
string signature;
var params = sig.get_parameters ();
int n_params, i;
......
......@@ -72,15 +72,15 @@ public class Vala.AttributeProcessor : CodeVisitor {
fl.process_attributes ();
}
public override void visit_begin_method (Method! m) {
public override void visit_method (Method! m) {
m.process_attributes ();
}
public override void visit_begin_creation_method (CreationMethod! m) {
public override void visit_creation_method (CreationMethod! m) {
m.process_attributes ();
}
public override void visit_begin_property (Property! prop) {
public override void visit_property (Property! prop) {
prop.process_attributes ();
}
......@@ -92,7 +92,7 @@ public class Vala.AttributeProcessor : CodeVisitor {
f.process_attributes ();
}
public override void visit_begin_signal (Signal! sig) {
public override void visit_signal (Signal! sig) {
sig.process_attributes ();
}
}
......@@ -108,7 +108,7 @@ public abstract class Vala.CodeVisitor {
}
/**
* Visit operation called for Members.
* Visit operation called for members.
*
* @param m a member
*/
......@@ -132,35 +132,19 @@ public abstract class Vala.CodeVisitor {
}
/**
* Visit operation called at beginning of methods.
* Visit operation called for methods.
*
* @param m a method
*/
public virtual void visit_begin_method (Method! m) {
public virtual void visit_method (Method! m) {
}
/**
* Visit operation called at end of methods.
* Visit operation called for creation methods.
*
* @param m a method
*/
public virtual void visit_end_method (Method! m) {
}
/**
* Visit operation called at beginning of creation methods.
*
* @param m a method
*/
public virtual void visit_begin_creation_method (CreationMethod! m) {
}
/**
* Visit operation called at end of creation methods.
*
* @param m a method
*/
public virtual void visit_end_creation_method (CreationMethod! m) {
public virtual void visit_creation_method (CreationMethod! m) {
}
/**
......@@ -172,83 +156,43 @@ public abstract class Vala.CodeVisitor {
}
/**
* Visit operation called at beginning of properties.
*
* @param prop a property
*/
public virtual void visit_begin_property (Property! prop) {
}
/**
* Visit operation called at end of properties.
* Visit operation called for properties.
*
* @param prop a property
*/
public virtual void visit_end_property (Property! prop) {
}
/**
* Visit operation called at beginning of property accessors.
*
* @param acc a property accessor
*/
public virtual void visit_begin_property_accessor (PropertyAccessor! acc) {
public virtual void visit_property (Property! prop) {
}
/**
* Visit operation called at end of property accessors.
* Visit operation called for property accessors.
*
* @param acc a property accessor
*/
public virtual void visit_end_property_accessor (PropertyAccessor! acc) {
public virtual void visit_property_accessor (PropertyAccessor! acc) {
}
/**
* Visit operation called at beginning of signals.
* Visit operation called for signals.
*
* @param sig a signal
*/
public virtual void visit_begin_signal (Signal! sig) {
public virtual void visit_signal (Signal! sig) {
}
/**
* Visit operation called at end of signals.
*
* @param sig a signal
*/
public virtual void visit_end_signal (Signal! sig) {
}
/**
* Visit operation called at beginning of constructors.
* Visit operation called for constructors.
*
* @param c a constructor
*/
public virtual void visit_begin_constructor (Constructor! c) {
}
/**
* Visit operation called at end of constructors.
*
* @param c a constructor
*/
public virtual void visit_end_constructor (Constructor! c) {
}
/**
* Visit operation called at beginning of destructors.
*
* @param d a destructor
*/
public virtual void visit_begin_destructor (Destructor! d) {
public virtual void visit_constructor (Constructor! c) {
}
/**
* Visit operation called at end of destructors.
* Visit operation called for destructors.
*
* @param d a destructor
*/
public virtual void visit_end_destructor (Destructor! d) {
public virtual void visit_destructor (Destructor! d) {
}
/**
......
/* valaconstant.vala
*
* Copyright (C) 2006 Jürg Billeter
* 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
......@@ -68,19 +68,21 @@ public class Vala.Constant : Member, Lockable {
initializer = init;
source_reference = source;
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_member (this);
visitor.visit_constant (this);
}
public override void accept_children (CodeVisitor! visitor) {
type_reference.accept (visitor);
if (initializer != null) {
initializer.accept (visitor);
}
visitor.visit_constant (this);
}
/**
* Returns the name of this constant as it is used in C code.
*
......
/* valaconstructor.vala
*
* Copyright (C) 2006 Jürg Billeter
* 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
......@@ -54,14 +54,14 @@ public class Vala.Constructor : CodeNode {
public Constructor (SourceReference source) {
source_reference = source;
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_begin_constructor (this);
visitor.visit_constructor (this);
}
public override void accept_children (CodeVisitor! visitor) {
if (body != null) {
body.accept (visitor);
}
visitor.visit_end_constructor (this);
}
}
......@@ -42,8 +42,10 @@ public class Vala.CreationMethod : Method {
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_begin_creation_method (this);
visitor.visit_creation_method (this);
}
public override void accept_children (CodeVisitor! visitor) {
foreach (FormalParameter param in get_parameters()) {
param.accept (visitor);
}
......@@ -51,8 +53,6 @@ public class Vala.CreationMethod : Method {
if (body != null) {
body.accept (visitor);
}
visitor.visit_end_creation_method (this);
}
public override ref string! get_default_cname () {
......
/* valadestructor.vala
*
* Copyright (C) 2006 Jürg Billeter
* 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
......@@ -54,14 +54,14 @@ public class Vala.Destructor : CodeNode {
public Destructor (SourceReference source) {
source_reference = source;
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_begin_destructor (this);
visitor.visit_destructor (this);
}
public override void accept_children (CodeVisitor! visitor) {
if (body != null) {
body.accept (visitor);
}
visitor.visit_end_destructor (this);
}
}
/* valafield.vala
*
* Copyright (C) 2006 Jürg Billeter
* 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
......@@ -88,17 +88,19 @@ public class Vala.Field : Member, Invokable, Lockable {
initializer = init;
source_reference = source;
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_member (this);
visitor.visit_field (this);
}
public override void accept_children (CodeVisitor! visitor) {
type_reference.accept (visitor);
if (initializer != null) {
initializer.accept (visitor);
}
visitor.visit_field (this);
}
/**
......
......@@ -83,8 +83,12 @@ public class Vala.FormalParameter : CodeNode, Invokable {
ellipsis = true;
source_reference = source;
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_formal_parameter (this);
}
public override void accept_children (CodeVisitor! visitor) {
if (!ellipsis) {
type_reference.accept (visitor);
......@@ -92,8 +96,6 @@ public class Vala.FormalParameter : CodeNode, Invokable {
default_expression.accept (visitor);
}
}
visitor.visit_formal_parameter (this);
}
public ref List<weak FormalParameter> get_parameters () {
......
......@@ -352,7 +352,7 @@ public class Vala.InterfaceWriter : CodeVisitor {
write_newline ();
}
public override void visit_begin_method (Method! m) {
public override void visit_method (Method! m) {
if (m.access == MemberAccessibility.PRIVATE || m.overrides) {
return;
}
......@@ -433,11 +433,11 @@ public class Vala.InterfaceWriter : CodeVisitor {
write_newline ();
}
public override void visit_begin_creation_method (CreationMethod! m) {
visit_begin_method (m);
public override void visit_creation_method (CreationMethod! m) {
visit_method (m);
}
public override void visit_begin_property (Property! prop) {
public override void visit_property (Property! prop) {
if (prop.no_accessor_method) {
write_indent ();
write_string ("[NoAccessorMethod]");
......@@ -481,7 +481,7 @@ public class Vala.InterfaceWriter : CodeVisitor {
write_newline ();
}
public override void visit_begin_signal (Signal! sig) {
public override void visit_signal (Signal! sig) {
if (sig.access == MemberAccessibility.PRIVATE) {
return;
}
......
......@@ -91,16 +91,32 @@ public class Vala.MemoryManager : CodeVisitor {
}
}
public override void visit_begin_method (Method! m) {
public override void visit_method (Method! m) {
current_symbol = m.symbol;
m.accept_children (this);
}
public override void visit_begin_creation_method (CreationMethod! m) {
current_symbol = m.symbol;
public override void visit_creation_method (CreationMethod! m) {
visit_method (m);
}
public override void visit_begin_property (Property! prop) {
public override void visit_property (Property! prop) {
current_symbol = prop.symbol;
prop.accept_children (this);
}
public override void visit_property_accessor (PropertyAccessor! acc) {
acc.accept_children (this);
}
public override void visit_constructor (Constructor! c) {
c.accept_children (this);
}
public override void visit_destructor (Destructor! d) {
d.accept_children (this);
}
public override void visit_named_argument (NamedArgument! n) {
......
......@@ -179,10 +179,12 @@ public class Vala.Method : Member, Invokable {
public bool is_invokable () {
return true;
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_begin_method (this);
visitor.visit_method (this);
}
public override void accept_children (CodeVisitor! visitor) {
if (return_type != null) {
return_type.accept (visitor);
}
......@@ -194,8 +196,6 @@ public class Vala.Method : Member, Invokable {
if (body != null) {
body.accept (visitor);
}
visitor.visit_end_method (this);
}
/**
......
......@@ -121,11 +121,14 @@ public class Vala.Property : Member, Lockable {
set_accessor = _set_accessor;
source_reference = source;
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_member (this);
visitor.visit_begin_property (this);
visitor.visit_property (this);
}
public override void accept_children (CodeVisitor! visitor) {
type_reference.accept (visitor);
if (get_accessor != null) {
......@@ -134,10 +137,8 @@ public class Vala.Property : Member, Lockable {