]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
move iteration of symbol nodes from accept to accept_children method
authorJürg Billeter <j@bitron.ch>
Fri, 15 Jun 2007 16:27:12 +0000 (16:27 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Fri, 15 Jun 2007 16:27:12 +0000 (16:27 +0000)
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

21 files changed:
ChangeLog
gobject/valacodegenerator.vala
gobject/valacodegeneratormethod.vala
gobject/valacodegeneratorsignal.vala
vala/valaattributeprocessor.vala
vala/valacodevisitor.vala
vala/valaconstant.vala
vala/valaconstructor.vala
vala/valacreationmethod.vala
vala/valadestructor.vala
vala/valafield.vala
vala/valaformalparameter.vala
vala/valainterfacewriter.vala
vala/valamemorymanager.vala
vala/valamethod.vala
vala/valaproperty.vala
vala/valapropertyaccessor.vala
vala/valasemanticanalyzer.vala
vala/valasignal.vala
vala/valasymbolbuilder.vala
vala/valasymbolresolver.vala

index bef993df7a9c255b96002dfc53fe1ec3445d2c66..5821fa0488c3ed22ad29777a50648e6d34aa4071 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+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,
index 729e0dd8ea6d52b4fd76eb11710390a093230c45..a7af9f56bb70fda945714fa916aa950a9e84ce53 100644 (file)
@@ -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;
        }
index f3660686b4297a2fd47294bbfe9874b2c94f0581..aa068b56c90b5e4956296bcca7b3e900b0c376fe 100644 (file)
 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) {
index bada079e0849940fe3bf8dbac040deb7ea06f462..e7d512ee56039ab8f93704fab29d7e032ece8505 100644 (file)
@@ -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;
index d70dcccf0c9e68bf989abdb0f629ad254f48818d..b67d53fd631d34b8553c4671db1e4166541d41c6 100644 (file)
@@ -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 ();
        }
 }
index 3c669e5ec4403632e0bd34e23b1fc61c2522572c..f7589e7dd9003da27f30120072b693ba5fdd5c7e 100644 (file)
@@ -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) {
        }
 
        /**
index 8f78535209226ec7b616a31a082aad896d635c7e..13ebe0fffb50655954ac5d57a590612ab2410598 100644 (file)
@@ -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.
         *
index 21c164a73a87bc8db8be9ec5da6cf05f7938ac68..28b72e96f9ba5b0539e4742aa3dc490e40ef8519 100644 (file)
@@ -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);
        }
 }
index 2113ab1ee9c474119525b6e1e5d0390fbe6a2902..8c43a1b99fc5ba20268ddaf4102ecb05ef1df8cf 100644 (file)
@@ -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 () {
index 726639f1e27192261139f8216aeeb7987b40251a..a169e1b79d26c07a06da6c6c31b7eb056ebc805c 100644 (file)
@@ -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);
        }
 }
index 884de754552005379815bacdefef1ab1e3a75dfb..cee3de89c81a535c69dde7cee8d9e5a84f524f2d 100644 (file)
@@ -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);
        }
 
        /**
index 4b4d3cf712f9cf7c9a222a035d6887f33708abad..042c622a533f737ebc42862db3d473982700f4f7 100644 (file)
@@ -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 () {
index 2decde1eb023f72a3c3b61b5debfb62c56a9c07d..80a6ce1af48c57bffdaf75754b1d39b5673c9b96 100644 (file)
@@ -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;
                }
index 175fef0a243b6f53fd9898a2162d0923b5953716..b65bc4df5cdb5676da19607cc7955aa85acad1dc 100644 (file)
@@ -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) {
index 0e9dd4e2ec4880e8fcdd236290e04819592030f8..c2b340bdf508ea8f9c6d0d48ad25734c0f1056bf 100644 (file)
@@ -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);
        }
 
        /**
index 16b5b29bb71ba259389f8e4ae4f3104c25c8d60c..04765aa2b8e30943b8d1353dd59e25281083e20c 100644 (file)
@@ -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
index 3177aa5d76a13ae60516c5c1b1702160e9c69f60..1dd0ab8c985d062467ea376af74c3c7c79c59442 100644 (file)
@@ -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);
        }
 }
index bdb685273849dd4102218a0e8a59c1faacfc1b8c..7d8bdadbd44c4bb030818c3a4679d3782ed715d5 100644 (file)
@@ -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;
        }
 
index 5e10a2c97efff7e44d023ad043ad86882fc28bb9..636e6a82006e7af18dbcdb5cd1c3c73ee569560d 100644 (file)
@@ -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.
         */
index a3843a3988f4bb29728e812b20a75abba5908481..e46b2f64cace2efe5c2cc2717f4ac853128603d4 100644 (file)
@@ -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;
        }
 
index ec1566e76cd700edc8c7acf4ba7d34bce7b027a0..42d449c5fe02d4168957d100fede19fcd8c2efc0 100644 (file)
@@ -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) {