]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Move parameter checking to FormalParameter.check
authorJürg Billeter <j@bitron.ch>
Fri, 31 Oct 2008 08:27:51 +0000 (08:27 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Fri, 31 Oct 2008 08:27:51 +0000 (08:27 +0000)
2008-10-31  Jürg Billeter  <j@bitron.ch>

* vala/valaformalparameter.vala:
* vala/valasemanticanalyzer.vala:

Move parameter checking to FormalParameter.check

svn path=/trunk/; revision=1943

ChangeLog
vala/valaformalparameter.vala
vala/valasemanticanalyzer.vala

index 5c72f912bb4644080e4137d506758e22e5c7e465..722c03cee71c4bd1f8c9e07077d70602b9ee9315 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-10-31  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valaformalparameter.vala:
+       * vala/valasemanticanalyzer.vala:
+
+       Move parameter checking to FormalParameter.check
+
 2008-10-31  Jürg Billeter  <j@bitron.ch>
 
        * vala/valasemanticanalyzer.vala:
index d0693759a497576e22e84875cc78f4dda914af9b..b24f42b2b4af029d3b3925931d220ba23bafd5be 100644 (file)
@@ -166,6 +166,53 @@ public class Vala.FormalParameter : Symbol {
                        return new FormalParameter.with_ellipsis ();
                }
        }
+
+       public override bool check (SemanticAnalyzer analyzer) {
+               accept_children (analyzer);
+
+               if (analyzer.context.non_null && default_expression != null) {
+                       if (default_expression is NullLiteral
+                           && !parameter_type.nullable
+                           && direction != ParameterDirection.OUT) {
+                               Report.warning (source_reference, "`null' incompatible with parameter type `%s`".printf (parameter_type.to_string ()));
+                       }
+               }
+
+               if (!ellipsis) {
+                       if (!is_internal_symbol ()) {
+                               if (parameter_type is ValueType && !parameter_type.is_real_struct_type ()) {
+                                       analyzer.current_source_file.add_type_dependency (parameter_type, SourceFileDependencyType.HEADER_FULL);
+                               } else {
+                                       analyzer.current_source_file.add_type_dependency (parameter_type, SourceFileDependencyType.HEADER_SHALLOW);
+                               }
+                       }
+                       analyzer.current_source_file.add_type_dependency (parameter_type, SourceFileDependencyType.SOURCE);
+
+                       // check whether parameter type is at least as accessible as the method
+                       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;
+                       }
+               }
+
+               /* special treatment for construct formal parameters used in creation methods */
+               if (construct_parameter) {
+                       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;
+                       var left = new MemberAccess (new MemberAccess.simple ("this"), name);
+                       var right = new MemberAccess.simple (name);
+
+                       method_body.add_statement (new ExpressionStatement (new Assignment (left, right), source_reference));
+               }
+
+               return true;
+       }
 }
 
 public enum Vala.ParameterDirection {
index 7fb6cc0dfec1612eefbab97c2cff622bad47d629..bb89fe2944c41f80f0b85d3a91eeda6900ae258f 100644 (file)
@@ -28,11 +28,11 @@ using Gee;
  * Code visitor analyzing and checking code.
  */
 public class Vala.SemanticAnalyzer : CodeVisitor {
-       private CodeContext context;
+       public CodeContext context { get; set; }
 
        Symbol root_symbol;
        Symbol current_symbol;
-       SourceFile current_source_file;
+       public SourceFile current_source_file { get; set; }
        DataType current_return_type;
        Class current_class;
        Struct current_struct;
@@ -594,52 +594,11 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        }
 
        public override void visit_formal_parameter (FormalParameter p) {
-               p.accept_children (this);
-
-               if (context.non_null && p.default_expression != null) {
-                       if (p.default_expression is NullLiteral
-                           && !p.parameter_type.nullable
-                           && p.direction != ParameterDirection.OUT) {
-                               Report.warning (p.source_reference, "`null' incompatible with parameter type `%s`".printf (p.parameter_type.to_string ()));
-                       }
-               }
-
-               if (!p.ellipsis) {
-                       if (!p.is_internal_symbol ()) {
-                               if (p.parameter_type is ValueType && !p.parameter_type.is_real_struct_type ()) {
-                                       current_source_file.add_type_dependency (p.parameter_type, SourceFileDependencyType.HEADER_FULL);
-                               } else {
-                                       current_source_file.add_type_dependency (p.parameter_type, SourceFileDependencyType.HEADER_SHALLOW);
-                               }
-                       }
-                       current_source_file.add_type_dependency (p.parameter_type, SourceFileDependencyType.SOURCE);
-
-                       // check whether parameter type is at least as accessible as the method
-                       if (!is_type_accessible (p, p.parameter_type)) {
-                               p.error = true;
-                               Report.error (p.source_reference, "parameter type `%s` is less accessible than method `%s`".printf (p.parameter_type.to_string (), p.parent_symbol.get_full_name ()));
-                               return;
-                       }
-               }
-
-               /* special treatment for construct formal parameters used in creation methods */
-               if (p.construct_parameter) {
-                       if (!(p.parent_symbol is CreationMethod)) {
-                               p.error = true;
-                               Report.error (p.source_reference, "construct parameters are only allowed in type creation methods");
-                               return;
-                       }
-
-                       var method_body = ((CreationMethod) p.parent_symbol).body;
-                       var left = new MemberAccess (new MemberAccess.simple ("this"), p.name);
-                       var right = new MemberAccess.simple (p.name);
-
-                       method_body.add_statement (new ExpressionStatement (new Assignment (left, right), p.source_reference));
-               }
+               p.check (this);
        }
 
        // check whether type is at least as accessible as the specified symbol
-       private bool is_type_accessible (Symbol sym, DataType type) {
+       public bool is_type_accessible (Symbol sym, DataType type) {
                foreach (Symbol type_symbol in type.get_symbols ()) {
                        Scope method_scope = sym.get_top_accessible_scope ();
                        Scope type_scope = type_symbol.get_top_accessible_scope ();