From: Jürg Billeter Date: Fri, 15 Jun 2007 16:27:12 +0000 (+0000) Subject: move iteration of symbol nodes from accept to accept_children method X-Git-Tag: VALA_0_1_0~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5cfdd606dfd40e14ce8acc6afc8e63e024816bcf;p=thirdparty%2Fvala.git move iteration of symbol nodes from accept to accept_children method 2007-06-15 Jürg Billeter * 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 --- diff --git a/ChangeLog b/ChangeLog index bef993df7..5821fa048 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2007-06-15 Jürg Billeter + + * 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 * vala/valaattributeprocessor.vala, vala/valacodevisitor.vala, diff --git a/gobject/valacodegenerator.vala b/gobject/valacodegenerator.vala index 729e0dd8e..a7af9f56b 100644 --- a/gobject/valacodegenerator.vala +++ b/gobject/valacodegenerator.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; } diff --git a/gobject/valacodegeneratormethod.vala b/gobject/valacodegeneratormethod.vala index f3660686b..aa068b56c 100644 --- a/gobject/valacodegeneratormethod.vala +++ b/gobject/valacodegeneratormethod.vala @@ -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) { diff --git a/gobject/valacodegeneratorsignal.vala b/gobject/valacodegeneratorsignal.vala index bada079e0..e7d512ee5 100644 --- a/gobject/valacodegeneratorsignal.vala +++ b/gobject/valacodegeneratorsignal.vala @@ -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; diff --git a/vala/valaattributeprocessor.vala b/vala/valaattributeprocessor.vala index d70dcccf0..b67d53fd6 100644 --- a/vala/valaattributeprocessor.vala +++ b/vala/valaattributeprocessor.vala @@ -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 (); } } diff --git a/vala/valacodevisitor.vala b/vala/valacodevisitor.vala index 3c669e5ec..f7589e7dd 100644 --- a/vala/valacodevisitor.vala +++ b/vala/valacodevisitor.vala @@ -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) { } /** diff --git a/vala/valaconstant.vala b/vala/valaconstant.vala index 8f7853520..13ebe0fff 100644 --- a/vala/valaconstant.vala +++ b/vala/valaconstant.vala @@ -1,6 +1,6 @@ /* 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. * diff --git a/vala/valaconstructor.vala b/vala/valaconstructor.vala index 21c164a73..28b72e96f 100644 --- a/vala/valaconstructor.vala +++ b/vala/valaconstructor.vala @@ -1,6 +1,6 @@ /* 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); } } diff --git a/vala/valacreationmethod.vala b/vala/valacreationmethod.vala index 2113ab1ee..8c43a1b99 100644 --- a/vala/valacreationmethod.vala +++ b/vala/valacreationmethod.vala @@ -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 () { diff --git a/vala/valadestructor.vala b/vala/valadestructor.vala index 726639f1e..a169e1b79 100644 --- a/vala/valadestructor.vala +++ b/vala/valadestructor.vala @@ -1,6 +1,6 @@ /* 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); } } diff --git a/vala/valafield.vala b/vala/valafield.vala index 884de7545..cee3de89c 100644 --- a/vala/valafield.vala +++ b/vala/valafield.vala @@ -1,6 +1,6 @@ /* 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); } /** diff --git a/vala/valaformalparameter.vala b/vala/valaformalparameter.vala index 4b4d3cf71..042c622a5 100644 --- a/vala/valaformalparameter.vala +++ b/vala/valaformalparameter.vala @@ -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 get_parameters () { diff --git a/vala/valainterfacewriter.vala b/vala/valainterfacewriter.vala index 2decde1eb..80a6ce1af 100644 --- a/vala/valainterfacewriter.vala +++ b/vala/valainterfacewriter.vala @@ -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; } diff --git a/vala/valamemorymanager.vala b/vala/valamemorymanager.vala index 175fef0a2..b65bc4df5 100644 --- a/vala/valamemorymanager.vala +++ b/vala/valamemorymanager.vala @@ -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) { diff --git a/vala/valamethod.vala b/vala/valamethod.vala index 0e9dd4e2e..c2b340bdf 100644 --- a/vala/valamethod.vala +++ b/vala/valamethod.vala @@ -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); } /** diff --git a/vala/valaproperty.vala b/vala/valaproperty.vala index 16b5b29bb..04765aa2b 100644 --- a/vala/valaproperty.vala +++ b/vala/valaproperty.vala @@ -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 { if (set_accessor != null) { set_accessor.accept (visitor); } - - visitor.visit_end_property (this); } - + /** * Returns the C name of this property in upper case. Words are * separated by underscores. The upper case C name of the class is diff --git a/vala/valapropertyaccessor.vala b/vala/valapropertyaccessor.vala index 3177aa5d7..1dd0ab8c9 100644 --- a/vala/valapropertyaccessor.vala +++ b/vala/valapropertyaccessor.vala @@ -1,6 +1,6 @@ /* valapropertyaccessor.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 @@ -69,14 +69,14 @@ public class Vala.PropertyAccessor : CodeNode { body = _body; source_reference = source; } - + public override void accept (CodeVisitor! visitor) { - visitor.visit_begin_property_accessor (this); + visitor.visit_property_accessor (this); + } + public override void accept_children (CodeVisitor! visitor) { if (body != null) { body.accept (visitor); } - - visitor.visit_end_property_accessor (this); } } diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index bdb685273..7d8bdadbd 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -296,6 +296,8 @@ public class Vala.SemanticAnalyzer : CodeVisitor { } public override void visit_constant (Constant! c) { + c.accept_children (this); + if (!current_source_file.pkg) { if (c.initializer == null) { c.error = true; @@ -305,6 +307,8 @@ public class Vala.SemanticAnalyzer : CodeVisitor { } public override void visit_field (Field! f) { + f.accept_children (this); + if (f.access != MemberAccessibility.PRIVATE) { if (f.type_reference.data_type != null) { /* is null if it references a type parameter */ @@ -318,7 +322,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor { } } - 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; @@ -331,6 +335,35 @@ public class Vala.SemanticAnalyzer : CodeVisitor { /* is null if it is void or a reference to a type parameter */ current_source_file.add_symbol_dependency (m.return_type.data_type.symbol, SourceFileDependencyType.HEADER_SHALLOW); } + + m.accept_children (this); + + current_symbol = current_symbol.parent_symbol; + current_return_type = null; + + if (current_symbol.parent_symbol != null && + current_symbol.parent_symbol.node is Method) { + /* lambda expressions produce nested methods */ + var up_method = (Method) current_symbol.parent_symbol.node; + current_return_type = up_method.return_type; + } + + if (current_symbol.node is Class) { + if (!(m is CreationMethod)) { + find_base_interface_method (m, (Class) current_symbol.node); + if (m.is_virtual || m.overrides) { + find_base_class_method (m, (Class) current_symbol.node); + if (m.base_method == null) { + Report.error (m.source_reference, "%s: no suitable method found to override".printf (m.symbol.get_full_name ())); + } + } + } + } else if (current_symbol.node is Struct) { + if (m.is_abstract || m.is_virtual || m.overrides) { + Report.error (m.source_reference, "A struct member `%s' cannot be marked as override, virtual, or abstract".printf (m.symbol.get_full_name ())); + return; + } + } } private void find_base_class_method (Method! m, Class! cl) { @@ -376,7 +409,29 @@ public class Vala.SemanticAnalyzer : CodeVisitor { } } - public override void visit_end_method (Method! m) { + public override void visit_creation_method (CreationMethod! m) { + m.return_type = new TypeReference (); + m.return_type.data_type = (DataType) current_symbol.node; + m.return_type.transfers_ownership = true; + + if (current_symbol.node is Class) { + // check for floating reference + var cl = (Class) current_symbol.node; + while (cl != null) { + if (cl == initially_unowned_type) { + m.return_type.floating_reference = true; + break; + } + + cl = cl.base_class; + } + } + + current_symbol = m.symbol; + current_return_type = m.return_type; + + m.accept_children (this); + current_symbol = current_symbol.parent_symbol; current_return_type = null; @@ -403,32 +458,6 @@ public class Vala.SemanticAnalyzer : CodeVisitor { return; } } - } - - public override void visit_begin_creation_method (CreationMethod! m) { - m.return_type = new TypeReference (); - m.return_type.data_type = (DataType) current_symbol.node; - m.return_type.transfers_ownership = true; - - if (current_symbol.node is Class) { - // check for floating reference - var cl = (Class) current_symbol.node; - while (cl != null) { - if (cl == initially_unowned_type) { - m.return_type.floating_reference = true; - break; - } - - cl = cl.base_class; - } - } - - current_symbol = m.symbol; - current_return_type = m.return_type; - } - - public override void visit_end_creation_method (CreationMethod! m) { - visit_end_method (m); if (m.body != null && current_class != null) { int n_params = 0; @@ -446,6 +475,8 @@ public class Vala.SemanticAnalyzer : CodeVisitor { } public override void visit_formal_parameter (FormalParameter! p) { + p.accept_children (this); + if (!p.ellipsis) { if (p.type_reference.data_type != null) { /* is null if it references a type parameter */ @@ -524,7 +555,9 @@ public class Vala.SemanticAnalyzer : CodeVisitor { } } - public override void visit_end_property (Property! prop) { + public override void visit_property (Property! prop) { + prop.accept_children (this); + if (prop.type_reference.data_type != null) { /* is null if it references a type parameter */ current_source_file.add_symbol_dependency (prop.type_reference.data_type.symbol, SourceFileDependencyType.HEADER_SHALLOW); @@ -544,7 +577,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor { } } - 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) { @@ -553,25 +586,29 @@ public class Vala.SemanticAnalyzer : CodeVisitor { // void current_return_type = new TypeReference (); } - } - public override void visit_end_property_accessor (PropertyAccessor! acc) { + acc.accept_children (this); + current_return_type = null; } - public override void visit_begin_constructor (Constructor! c) { - current_symbol = c.symbol; + public override void visit_signal (Signal! sig) { + sig.accept_children (this); } - public override void visit_end_constructor (Constructor! c) { + public override void visit_constructor (Constructor! c) { + current_symbol = c.symbol; + + c.accept_children (this); + current_symbol = current_symbol.parent_symbol; } - public override void visit_begin_destructor (Destructor! d) { + public override void visit_destructor (Destructor! d) { current_symbol = d.symbol; - } - public override void visit_end_destructor (Destructor! d) { + d.accept_children (this); + current_symbol = current_symbol.parent_symbol; } diff --git a/vala/valasignal.vala b/vala/valasignal.vala index 5e10a2c97..636e6a820 100644 --- a/vala/valasignal.vala +++ b/vala/valasignal.vala @@ -1,6 +1,6 @@ /* valasignal.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 @@ -153,21 +153,21 @@ public class Vala.Signal : Member, Invokable, Lockable { return new CCodeConstant (str.str); } - + public override void accept (CodeVisitor! visitor) { visitor.visit_member (this); - visitor.visit_begin_signal (this); - + visitor.visit_signal (this); + } + + public override void accept_children (CodeVisitor! visitor) { return_type.accept (visitor); foreach (FormalParameter param in parameters) { param.accept (visitor); } - - visitor.visit_end_signal (this); } - + /** * Process all associated attributes. */ diff --git a/vala/valasymbolbuilder.vala b/vala/valasymbolbuilder.vala index a3843a398..e46b2f64c 100644 --- a/vala/valasymbolbuilder.vala +++ b/vala/valasymbolbuilder.vala @@ -222,6 +222,11 @@ public class Vala.SymbolBuilder : CodeVisitor { } public override void visit_callback (Callback! cb) { + if (cb.error) { + /* skip enums with errors */ + return; + } + if (add_symbol (cb.name, cb) == null) { return; } @@ -230,11 +235,6 @@ public class Vala.SymbolBuilder : CodeVisitor { cb.accept_children (this); - if (cb.error) { - /* skip enums with errors */ - return; - } - current_symbol = current_symbol.parent_symbol; } @@ -246,7 +246,7 @@ public class Vala.SymbolBuilder : CodeVisitor { add_symbol (f.name, f); } - public override void visit_begin_method (Method! m) { + public override void visit_method (Method! m) { if (add_symbol (m.name, m) == null) { return; } @@ -266,18 +266,13 @@ public class Vala.SymbolBuilder : CodeVisitor { } current_symbol = m.symbol; - } - - public override void visit_end_method (Method! m) { - if (m.error) { - /* skip methods with errors */ - return; - } - + + m.accept_children (this); + current_symbol = current_symbol.parent_symbol; } - public override void visit_begin_creation_method (CreationMethod! m) { + public override void visit_creation_method (CreationMethod! m) { if (add_symbol (m.name, m) == null) { return; } @@ -299,14 +294,9 @@ public class Vala.SymbolBuilder : CodeVisitor { } current_symbol = m.symbol; - } - - public override void visit_end_creation_method (CreationMethod! m) { - if (m.error) { - /* skip methods with errors */ - return; - } - + + m.accept_children (this); + current_symbol = current_symbol.parent_symbol; } @@ -316,7 +306,12 @@ public class Vala.SymbolBuilder : CodeVisitor { } } - public override void visit_begin_property (Property! prop) { + public override void visit_property (Property! prop) { + if (prop.error) { + /* skip properties with errors */ + return; + } + if (add_symbol (prop.name, prop) == null) { return; } @@ -327,26 +322,22 @@ public class Vala.SymbolBuilder : CodeVisitor { prop.this_parameter.type_reference.data_type = (DataType) prop.symbol.parent_symbol.node; prop.this_parameter.symbol = new Symbol (prop.this_parameter); current_symbol.add (prop.this_parameter.name, prop.this_parameter.symbol); - } - - public override void visit_end_property (Property! prop) { - if (prop.error) { - /* skip properties with errors */ - return; - } - + + prop.accept_children (this); + current_symbol = current_symbol.parent_symbol; } - public override void visit_begin_property_accessor (PropertyAccessor! acc) { + public override void visit_property_accessor (PropertyAccessor! acc) { acc.symbol = new Symbol (acc); acc.symbol.parent_symbol = current_symbol; - current_symbol = acc.symbol; - + if (current_source_file.pkg) { return; } + current_symbol = acc.symbol; + if (acc.writable || acc.construction) { acc.value_parameter = new FormalParameter ("value", ((Property) current_symbol.parent_symbol.node).type_reference); acc.value_parameter.symbol = new Symbol (acc.value_parameter); @@ -371,46 +362,46 @@ public class Vala.SymbolBuilder : CodeVisitor { } acc.body = block; } - } - - public override void visit_end_property_accessor (PropertyAccessor! acc) { + + acc.accept_children (this); + current_symbol = current_symbol.parent_symbol; } - public override void visit_begin_signal (Signal! sig) { - if (add_symbol (sig.name, sig) == null) { + public override void visit_signal (Signal! sig) { + if (sig.error) { + /* skip signals with errors */ return; } - - current_symbol = sig.symbol; - } - public override void visit_end_signal (Signal! sig) { - if (sig.error) { - /* skip signals with errors */ + if (add_symbol (sig.name, sig) == null) { return; } + current_symbol = sig.symbol; + + sig.accept_children (this); + current_symbol = current_symbol.parent_symbol; } - public override void visit_begin_constructor (Constructor! c) { + public override void visit_constructor (Constructor! c) { c.symbol = new Symbol (c); c.symbol.parent_symbol = current_symbol; current_symbol = c.symbol; - } - public override void visit_end_constructor (Constructor! c) { + c.accept_children (this); + current_symbol = current_symbol.parent_symbol; } - public override void visit_begin_destructor (Destructor! d) { + public override void visit_destructor (Destructor! d) { d.symbol = new Symbol (d); d.symbol.parent_symbol = current_symbol; current_symbol = d.symbol; - } - public override void visit_end_destructor (Destructor! d) { + d.accept_children (this); + current_symbol = current_symbol.parent_symbol; } diff --git a/vala/valasymbolresolver.vala b/vala/valasymbolresolver.vala index ec1566e76..42d449c5f 100644 --- a/vala/valasymbolresolver.vala +++ b/vala/valasymbolresolver.vala @@ -116,7 +116,25 @@ public class Vala.SymbolResolver : CodeVisitor { current_scope = current_scope.parent_symbol; } + public override void visit_constant (Constant! c) { + c.accept_children (this); + } + + public override void visit_field (Field! f) { + f.accept_children (this); + } + + public override void visit_method (Method! m) { + m.accept_children (this); + } + + public override void visit_creation_method (CreationMethod! m) { + m.accept_children (this); + } + public override void visit_formal_parameter (FormalParameter! p) { + p.accept_children (this); + if (!p.ellipsis && p.type_reference.is_ref) { if ((p.type_reference.data_type != null && p.type_reference.data_type.is_reference_type ()) || @@ -128,6 +146,26 @@ public class Vala.SymbolResolver : CodeVisitor { } } + public override void visit_property (Property! prop) { + prop.accept_children (this); + } + + public override void visit_property_accessor (PropertyAccessor! acc) { + acc.accept_children (this); + } + + public override void visit_signal (Signal! sig) { + sig.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_namespace_reference (NamespaceReference! ns) { ns.namespace_symbol = current_scope.lookup (ns.name); if (ns.namespace_symbol == null) {