vala r1992 - in trunk: . vala



Author: juergbi
Date: Thu Nov  6 20:19:50 2008
New Revision: 1992
URL: http://svn.gnome.org/viewvc/vala?rev=1992&view=rev

Log:
2008-11-06  JÃrg Billeter  <j bitron ch>

	* vala/valamethod.vala:
	* vala/valasemanticanalyzer.vala:

	Move method checking to Method.check


Modified:
   trunk/ChangeLog
   trunk/vala/valamethod.vala
   trunk/vala/valasemanticanalyzer.vala

Modified: trunk/vala/valamethod.vala
==============================================================================
--- trunk/vala/valamethod.vala	(original)
+++ trunk/vala/valamethod.vala	Thu Nov  6 20:19:50 2008
@@ -594,4 +594,152 @@
 			}
 		}
 	}
+
+	public override bool check (SemanticAnalyzer analyzer) {
+		if (checked) {
+			return !error;
+		}
+
+		checked = true;
+
+		process_attributes ();
+
+		if (is_abstract) {
+			if (parent_symbol is Class) {
+				var cl = (Class) parent_symbol;
+				if (!cl.is_abstract) {
+					error = true;
+					Report.error (source_reference, "Abstract methods may not be declared in non-abstract classes");
+					return false;
+				}
+			} else if (!(parent_symbol is Interface)) {
+				error = true;
+				Report.error (source_reference, "Abstract methods may not be declared outside of classes and interfaces");
+				return false;
+			}
+		} else if (is_virtual) {
+			if (!(parent_symbol is Class) && !(parent_symbol is Interface)) {
+				error = true;
+				Report.error (source_reference, "Virtual methods may not be declared outside of classes and interfaces");
+				return false;
+			}
+
+			if (parent_symbol is Class) {
+				var cl = (Class) parent_symbol;
+				if (cl.is_compact) {
+					Report.error (source_reference, "Virtual methods may not be declared in compact classes");
+					return false;
+				}
+			}
+		} else if (overrides) {
+			if (!(parent_symbol is Class)) {
+				error = true;
+				Report.error (source_reference, "Methods may not be overridden outside of classes");
+				return false;
+			}
+		}
+
+		if (is_abstract && body != null) {
+			Report.error (source_reference, "Abstract methods cannot have bodies");
+		} else if (external && body != null) {
+			Report.error (source_reference, "Extern methods cannot have bodies");
+		} else if (!is_abstract && !external && !external_package && body == null) {
+			Report.error (source_reference, "Non-abstract, non-extern methods must have bodies");
+		}
+
+		var old_symbol = analyzer.current_symbol;
+		var old_return_type = analyzer.current_return_type;
+		analyzer.current_symbol = this;
+		analyzer.current_return_type = return_type;
+
+		var init_attr = get_attribute ("ModuleInit");
+		if (init_attr != null) {
+			source_reference.file.context.module_init_method = this;
+		}
+
+		if (!is_internal_symbol ()) {
+			if (return_type is ValueType) {
+				analyzer.current_source_file.add_type_dependency (return_type, SourceFileDependencyType.HEADER_FULL);
+			} else {
+				analyzer.current_source_file.add_type_dependency (return_type, SourceFileDependencyType.HEADER_SHALLOW);
+			}
+		}
+		analyzer.current_source_file.add_type_dependency (return_type, SourceFileDependencyType.SOURCE);
+
+		accept_children (analyzer);
+
+		analyzer.current_symbol = old_symbol;
+		analyzer.current_return_type = old_return_type;
+
+		if (analyzer.current_symbol.parent_symbol is Method) {
+			/* lambda expressions produce nested methods */
+			var up_method = (Method) analyzer.current_symbol.parent_symbol;
+			analyzer.current_return_type = up_method.return_type;
+		}
+
+		if (analyzer.current_symbol is Struct) {
+			if (is_abstract || is_virtual || overrides) {
+				Report.error (source_reference, "A struct member `%s' cannot be marked as override, virtual, or abstract".printf (get_full_name ()));
+				return false;
+			}
+		} else if (overrides && base_method == null) {
+			Report.error (source_reference, "%s: no suitable method found to override".printf (get_full_name ()));
+		}
+
+		// check whether return type is at least as accessible as the method
+		if (!analyzer.is_type_accessible (this, return_type)) {
+			error = true;
+			Report.error (source_reference, "return type `%s` is less accessible than method `%s`".printf (return_type.to_string (), get_full_name ()));
+			return false;
+		}
+
+		foreach (Expression precondition in get_preconditions ()) {
+			if (precondition.error) {
+				// if there was an error in the precondition, skip this check
+				error = true;
+				return false;
+			}
+
+			if (!precondition.value_type.compatible (analyzer.bool_type)) {
+				error = true;
+				Report.error (precondition.source_reference, "Precondition must be boolean");
+				return false;
+			}
+		}
+
+		foreach (Expression postcondition in get_postconditions ()) {
+			if (postcondition.error) {
+				// if there was an error in the postcondition, skip this check
+				error = true;
+				return false;
+			}
+
+			if (!postcondition.value_type.compatible (analyzer.bool_type)) {
+				error = true;
+				Report.error (postcondition.source_reference, "Postcondition must be boolean");
+				return false;
+			}
+		}
+
+		if (tree_can_fail && name == "main") {
+			Report.error (source_reference, "\"main\" method cannot throw errors");
+		}
+
+		// check that all errors that can be thrown in the method body are declared
+		if (body != null) { 
+			foreach (DataType body_error_type in body.get_error_types ()) {
+				bool can_propagate_error = false;
+				foreach (DataType method_error_type in get_error_types ()) {
+					if (body_error_type.compatible (method_error_type)) {
+						can_propagate_error = true;
+					}
+				}
+				if (!can_propagate_error) {
+					Report.warning (body_error_type.source_reference, "unhandled error `%s'".printf (body_error_type.to_string()));
+				}
+			}
+		}
+
+		return !error;
+	}
 }

Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala	(original)
+++ trunk/vala/valasemanticanalyzer.vala	Thu Nov  6 20:19:50 2008
@@ -278,143 +278,7 @@
 	}
 
 	public override void visit_method (Method m) {
-		m.process_attributes ();
-
-		if (m.is_abstract) {
-			if (m.parent_symbol is Class) {
-				var cl = (Class) m.parent_symbol;
-				if (!cl.is_abstract) {
-					m.error = true;
-					Report.error (m.source_reference, "Abstract methods may not be declared in non-abstract classes");
-					return;
-				}
-			} else if (!(m.parent_symbol is Interface)) {
-				m.error = true;
-				Report.error (m.source_reference, "Abstract methods may not be declared outside of classes and interfaces");
-				return;
-			}
-		} else if (m.is_virtual) {
-			if (!(m.parent_symbol is Class) && !(m.parent_symbol is Interface)) {
-				m.error = true;
-				Report.error (m.source_reference, "Virtual methods may not be declared outside of classes and interfaces");
-				return;
-			}
-
-			if (m.parent_symbol is Class) {
-				var cl = (Class) m.parent_symbol;
-				if (cl.is_compact) {
-					Report.error (m.source_reference, "Virtual methods may not be declared in compact classes");
-					return;
-				}
-			}
-		} else if (m.overrides) {
-			if (!(m.parent_symbol is Class)) {
-				m.error = true;
-				Report.error (m.source_reference, "Methods may not be overridden outside of classes");
-				return;
-			}
-		}
-
-		if (m.is_abstract && m.body != null) {
-			Report.error (m.source_reference, "Abstract methods cannot have bodies");
-		} else if (m.external && m.body != null) {
-			Report.error (m.source_reference, "Extern methods cannot have bodies");
-		} else if (!m.is_abstract && !m.external && !m.external_package && m.body == null) {
-			Report.error (m.source_reference, "Non-abstract, non-extern methods must have bodies");
-		}
-
-		var old_symbol = current_symbol;
-		var old_return_type = current_return_type;
-		current_symbol = m;
-		current_return_type = m.return_type;
-
-		var init_attr = m.get_attribute ("ModuleInit");
-		if (init_attr != null) {
-			m.source_reference.file.context.module_init_method = m;
-		}
-
-		if (!m.is_internal_symbol ()) {
-			if (m.return_type is ValueType) {
-				current_source_file.add_type_dependency (m.return_type, SourceFileDependencyType.HEADER_FULL);
-			} else {
-				current_source_file.add_type_dependency (m.return_type, SourceFileDependencyType.HEADER_SHALLOW);
-			}
-		}
-		current_source_file.add_type_dependency (m.return_type, SourceFileDependencyType.SOURCE);
-
-		m.accept_children (this);
-
-		current_symbol = old_symbol;
-		current_return_type = old_return_type;
-
-		if (current_symbol.parent_symbol is Method) {
-			/* lambda expressions produce nested methods */
-			var up_method = (Method) current_symbol.parent_symbol;
-			current_return_type = up_method.return_type;
-		}
-
-		if (current_symbol 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.get_full_name ()));
-				return;
-			}
-		} else if (m.overrides && m.base_method == null) {
-			Report.error (m.source_reference, "%s: no suitable method found to override".printf (m.get_full_name ()));
-		}
-
-		// check whether return type is at least as accessible as the method
-		if (!is_type_accessible (m, m.return_type)) {
-			m.error = true;
-			Report.error (m.source_reference, "return type `%s` is less accessible than method `%s`".printf (m.return_type.to_string (), m.get_full_name ()));
-			return;
-		}
-
-		foreach (Expression precondition in m.get_preconditions ()) {
-			if (precondition.error) {
-				// if there was an error in the precondition, skip this check
-				m.error = true;
-				return;
-			}
-
-			if (!precondition.value_type.compatible (bool_type)) {
-				m.error = true;
-				Report.error (precondition.source_reference, "Precondition must be boolean");
-				return;
-			}
-		}
-
-		foreach (Expression postcondition in m.get_postconditions ()) {
-			if (postcondition.error) {
-				// if there was an error in the postcondition, skip this check
-				m.error = true;
-				return;
-			}
-
-			if (!postcondition.value_type.compatible (bool_type)) {
-				m.error = true;
-				Report.error (postcondition.source_reference, "Postcondition must be boolean");
-				return;
-			}
-		}
-
-		if (m.tree_can_fail && m.name == "main") {
-			Report.error (m.source_reference, "\"main\" method cannot throw errors");
-		}
-
-		// check that all errors that can be thrown in the method body are declared
-		if (m.body != null) { 
-			foreach (DataType body_error_type in m.body.get_error_types ()) {
-				bool can_propagate_error = false;
-				foreach (DataType method_error_type in m.get_error_types ()) {
-					if (body_error_type.compatible (method_error_type)) {
-						can_propagate_error = true;
-					}
-				}
-				if (!can_propagate_error) {
-					Report.warning (body_error_type.source_reference, "unhandled error `%s'".printf (body_error_type.to_string()));
-				}
-			}
-		}
+		m.check (this);
 	}
 
 	public override void visit_creation_method (CreationMethod m) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]