]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Check parameters when checking arguments
authorJürg Billeter <j@bitron.ch>
Fri, 31 Oct 2008 09:37:07 +0000 (09:37 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Fri, 31 Oct 2008 09:37:07 +0000 (09:37 +0000)
2008-10-31  Jürg Billeter  <j@bitron.ch>

* vala/valacodenode.vala:
* vala/valaformalparameter.vala:
* vala/valasemanticanalyzer.vala:
* vala/valasourcefile.vala:

Check parameters when checking arguments

svn path=/trunk/; revision=1944

ChangeLog
vala/valacodenode.vala
vala/valaformalparameter.vala
vala/valasemanticanalyzer.vala
vala/valasourcefile.vala

index 722c03cee71c4bd1f8c9e07077d70602b9ee9315..8efc14f904a226bf4a2778e4da12f3495d9a3228 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-10-31  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valacodenode.vala:
+       * vala/valaformalparameter.vala:
+       * vala/valasemanticanalyzer.vala:
+       * vala/valasourcefile.vala:
+
+       Check parameters when checking arguments
+
 2008-10-31  Jürg Billeter  <j@bitron.ch>
 
        * vala/valaformalparameter.vala:
index 145e425c8d512e130495b090cdfed8c0f67d2bc1..920eecfe3d843a4f765a33a6025b5da11cfd607a 100644 (file)
@@ -64,6 +64,8 @@ public abstract class Vala.CodeNode {
                }
        }
 
+       public bool checked { get; set; }
+
        /**
         * Specifies whether a fatal error has been detected in this code node.
         */
@@ -76,7 +78,6 @@ public abstract class Vala.CodeNode {
                get { return _error_types != null && _error_types.size > 0; }
        }
 
-       bool checked;
        private Gee.List<DataType> _error_types;
        private static Gee.List<DataType> _empty_type_list;
 
index b24f42b2b4af029d3b3925931d220ba23bafd5be..a4e3adecb9f2f5631224906e0c2566a3d6323629 100644 (file)
@@ -168,6 +168,20 @@ public class Vala.FormalParameter : Symbol {
        }
 
        public override bool check (SemanticAnalyzer analyzer) {
+               if (checked) {
+                       return !error;
+               }
+
+               checked = true;
+
+               var old_source_file = analyzer.current_source_file;
+               var old_symbol = analyzer.current_symbol;
+
+               if (source_reference != null) {
+                       analyzer.current_source_file = source_reference.file;
+               }
+               analyzer.current_symbol = parent_symbol;
+
                accept_children (analyzer);
 
                if (analyzer.context.non_null && default_expression != null) {
@@ -192,7 +206,6 @@ public class Vala.FormalParameter : Symbol {
                        if (!analyzer.is_type_accessible (this, parameter_type)) {
                                error = true;
                                Report.error (source_reference, "parameter type `%s` is less accessible than method `%s`".printf (parameter_type.to_string (), parent_symbol.get_full_name ()));
-                               return false;
                        }
                }
 
@@ -201,7 +214,6 @@ public class Vala.FormalParameter : Symbol {
                        if (!(parent_symbol is CreationMethod)) {
                                error = true;
                                Report.error (source_reference, "construct parameters are only allowed in type creation methods");
-                               return false;
                        }
 
                        var method_body = ((CreationMethod) parent_symbol).body;
@@ -211,7 +223,10 @@ public class Vala.FormalParameter : Symbol {
                        method_body.add_statement (new ExpressionStatement (new Assignment (left, right), source_reference));
                }
 
-               return true;
+               analyzer.current_source_file = old_source_file;
+               analyzer.current_symbol = old_symbol;
+
+               return !error;
        }
 }
 
index bb89fe2944c41f80f0b85d3a91eeda6900ae258f..b4c35c087034c2b971b477dc1d8186113f6f6b35 100644 (file)
@@ -31,7 +31,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        public CodeContext context { get; set; }
 
        Symbol root_symbol;
-       Symbol current_symbol;
+       public Symbol current_symbol { get; set; }
        public SourceFile current_source_file { get; set; }
        DataType current_return_type;
        Class current_class;
@@ -2186,6 +2186,10 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                bool ellipsis = false;
                int i = 0;
                foreach (FormalParameter param in params) {
+                       if (!param.check (this)) {
+                               return false;
+                       }
+
                        if (param.ellipsis) {
                                ellipsis = true;
                                break;
index b38a717f655ccc7e12783e696048e0870aeb0cbe..89a08e1980a42d0d8288a8a459456ed1bb25c667 100644 (file)
@@ -265,6 +265,9 @@ public class Vala.SourceFile {
         * Adds the specified symbol to the list of symbols code in this source
         * file depends on.
         *
+        * TODO Move source and header file dependency analysis to
+        * code generator.
+        *
         * @param sym      a symbol
         * @param dep_type type of dependency
         */
@@ -328,6 +331,9 @@ public class Vala.SourceFile {
         * Adds the symbols that define the specified type to the list of
         * symbols code in this source file depends on.
         *
+        * TODO Move source and header file dependency analysis to
+        * code generator.
+        *
         * @param type     a data type
         * @param dep_type type of dependency
         */