vala r2000 - in trunk: . vala



Author: juergbi
Date: Fri Nov  7 10:31:16 2008
New Revision: 2000
URL: http://svn.gnome.org/viewvc/vala?rev=2000&view=rev

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

	* vala/valaconstant.vala:
	* vala/valaconstructor.vala:
	* vala/valacreationmethod.vala:
	* vala/valadestructor.vala:
	* vala/valafield.vala:
	* vala/valaformalparameter.vala:
	* vala/valaproperty.vala:
	* vala/valapropertyaccessor.vala:
	* vala/valasemanticanalyzer.vala:
	* vala/valasignal.vala:

	Move member checking to code nodes


Modified:
   trunk/ChangeLog
   trunk/vala/valaconstant.vala
   trunk/vala/valaconstructor.vala
   trunk/vala/valacreationmethod.vala
   trunk/vala/valadestructor.vala
   trunk/vala/valafield.vala
   trunk/vala/valaformalparameter.vala
   trunk/vala/valaproperty.vala
   trunk/vala/valapropertyaccessor.vala
   trunk/vala/valasemanticanalyzer.vala
   trunk/vala/valasignal.vala

Modified: trunk/vala/valaconstant.vala
==============================================================================
--- trunk/vala/valaconstant.vala	(original)
+++ trunk/vala/valaconstant.vala	Fri Nov  7 10:31:16 2008
@@ -150,4 +150,29 @@
 			}
 		}
 	}
+
+	public override bool check (SemanticAnalyzer analyzer) {
+		if (checked) {
+			return !error;
+		}
+
+		checked = true;
+
+		process_attributes ();
+
+		type_reference.accept (analyzer);
+
+		if (!external_package) {
+			if (initializer == null) {
+				error = true;
+				Report.error (source_reference, "A const field requires a initializer to be provided");
+			} else {
+				initializer.target_type = type_reference;
+
+				initializer.accept (analyzer);
+			}
+		}
+
+		return !error;
+	}
 }

Modified: trunk/vala/valaconstructor.vala
==============================================================================
--- trunk/vala/valaconstructor.vala	(original)
+++ trunk/vala/valaconstructor.vala	Fri Nov  7 10:31:16 2008
@@ -60,4 +60,28 @@
 			body.accept (visitor);
 		}
 	}
+
+	public override bool check (SemanticAnalyzer analyzer) {
+		if (checked) {
+			return !error;
+		}
+
+		checked = true;
+
+		this_parameter = new FormalParameter ("this", new ObjectType (analyzer.current_class));
+		scope.add (this_parameter.name, this_parameter);
+
+		owner = analyzer.current_symbol.scope;
+		analyzer.current_symbol = this;
+
+		accept_children (analyzer);
+
+		foreach (DataType body_error_type in body.get_error_types ()) {
+			Report.warning (body_error_type.source_reference, "unhandled error `%s'".printf (body_error_type.to_string()));
+		}
+
+		analyzer.current_symbol = analyzer.current_symbol.parent_symbol;
+
+		return !error;
+	}
 }

Modified: trunk/vala/valacreationmethod.vala
==============================================================================
--- trunk/vala/valacreationmethod.vala	(original)
+++ trunk/vala/valacreationmethod.vala	Fri Nov  7 10:31:16 2008
@@ -114,4 +114,42 @@
 			return "%s%s_%s".printf (parent.get_lower_case_cprefix (), infix, name);
 		}
 	}
+
+	public override bool check (SemanticAnalyzer analyzer) {
+		if (checked) {
+			return !error;
+		}
+
+		checked = true;
+
+		process_attributes ();
+
+		if (type_name != null && type_name != analyzer.current_symbol.name) {
+			// type_name is null for constructors generated by GIdlParser
+			Report.error (source_reference, "missing return type in method `%s.%sÂ".printf (analyzer.current_symbol.get_full_name (), type_name));
+			error = true;
+			return false;
+		}
+
+		analyzer.current_symbol = this;
+		analyzer.current_return_type = return_type;
+
+		accept_children (analyzer);
+
+		analyzer.current_symbol = analyzer.current_symbol.parent_symbol;
+		analyzer.current_return_type = null;
+
+		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 (is_abstract || is_virtual || overrides) {
+			Report.error (source_reference, "The creation method `%s' cannot be marked as override, virtual, or abstract".printf (get_full_name ()));
+			return false;
+		}
+
+		return !error;
+	}
 }

Modified: trunk/vala/valadestructor.vala
==============================================================================
--- trunk/vala/valadestructor.vala	(original)
+++ trunk/vala/valadestructor.vala	Fri Nov  7 10:31:16 2008
@@ -60,4 +60,21 @@
 			body.accept (visitor);
 		}
 	}
+
+	public override bool check (SemanticAnalyzer analyzer) {
+		if (checked) {
+			return !error;
+		}
+
+		checked = true;
+
+		owner = analyzer.current_symbol.scope;
+		analyzer.current_symbol = this;
+
+		accept_children (analyzer);
+
+		analyzer.current_symbol = analyzer.current_symbol.parent_symbol;
+
+		return !error;
+	}
 }

Modified: trunk/vala/valafield.vala
==============================================================================
--- trunk/vala/valafield.vala	(original)
+++ trunk/vala/valafield.vala	Fri Nov  7 10:31:16 2008
@@ -195,4 +195,44 @@
 		}
 		attr.add_argument ("type", new StringLiteral ("\"%s\"".printf (ctype)));
 	}
+
+	public override bool check (SemanticAnalyzer analyzer) {
+		if (checked) {
+			return !error;
+		}
+
+		checked = true;
+
+		process_attributes ();
+
+		if (initializer != null) {
+			initializer.target_type = field_type;
+		}
+
+		accept_children (analyzer);
+
+		if (binding == MemberBinding.INSTANCE && parent_symbol is Interface) {
+			error = true;
+			Report.error (source_reference, "Interfaces may not have instance fields");
+			return false;
+		}
+
+		if (!is_internal_symbol ()) {
+			if (field_type is ValueType) {
+				analyzer.current_source_file.add_type_dependency (field_type, SourceFileDependencyType.HEADER_FULL);
+			} else {
+				analyzer.current_source_file.add_type_dependency (field_type, SourceFileDependencyType.HEADER_SHALLOW);
+			}
+		} else {
+			if (parent_symbol is Namespace) {
+				error = true;
+				Report.error (source_reference, "Namespaces may not have private members");
+				return false;
+			}
+
+			analyzer.current_source_file.add_type_dependency (field_type, SourceFileDependencyType.SOURCE);
+		}
+
+		return !error;
+	}
 }

Modified: trunk/vala/valaformalparameter.vala
==============================================================================
--- trunk/vala/valaformalparameter.vala	(original)
+++ trunk/vala/valaformalparameter.vala	Fri Nov  7 10:31:16 2008
@@ -174,6 +174,8 @@
 
 		checked = true;
 
+		process_attributes ();
+
 		var old_source_file = analyzer.current_source_file;
 		var old_symbol = analyzer.current_symbol;
 

Modified: trunk/vala/valaproperty.vala
==============================================================================
--- trunk/vala/valaproperty.vala	(original)
+++ trunk/vala/valaproperty.vala	Fri Nov  7 10:31:16 2008
@@ -411,6 +411,8 @@
 
 		checked = true;
 
+		process_attributes ();
+
 		var old_source_file = analyzer.current_source_file;
 		var old_symbol = analyzer.current_symbol;
 

Modified: trunk/vala/valapropertyaccessor.vala
==============================================================================
--- trunk/vala/valapropertyaccessor.vala	(original)
+++ trunk/vala/valapropertyaccessor.vala	Fri Nov  7 10:31:16 2008
@@ -131,4 +131,55 @@
 			}
 		}
 	}
+
+	public override bool check (SemanticAnalyzer analyzer) {
+		if (checked) {
+			return !error;
+		}
+
+		checked = true;
+
+		process_attributes ();
+
+		var old_return_type = analyzer.current_return_type;
+		if (readable) {
+			analyzer.current_return_type = prop.property_type;
+		} else {
+			// void
+			analyzer.current_return_type = new VoidType ();
+		}
+
+		if (!prop.external_package) {
+			if (body == null && !prop.interface_only && !prop.is_abstract) {
+				/* no accessor body specified, insert default body */
+
+				if (prop.parent_symbol is Interface) {
+					error = true;
+					Report.error (source_reference, "Automatic properties can't be used in interfaces");
+					return false;
+				}
+				automatic_body = true;
+				body = new Block (source_reference);
+				var ma = new MemberAccess.simple ("_%s".printf (prop.name), source_reference);
+				if (readable) {
+					body.add_statement (new ReturnStatement (ma, source_reference));
+				} else {
+					var assignment = new Assignment (ma, new MemberAccess.simple ("value", source_reference), AssignmentOperator.SIMPLE, source_reference);
+					body.add_statement (new ExpressionStatement (assignment));
+				}
+			}
+
+			if (body != null && (writable || construction)) {
+				var value_type = prop.property_type.copy ();
+				value_parameter = new FormalParameter ("value", value_type, source_reference);
+				body.scope.add (value_parameter.name, value_parameter);
+			}
+		}
+
+		accept_children (analyzer);
+
+		analyzer.current_return_type = old_return_type;
+
+		return !error;
+	}
 }

Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala	(original)
+++ trunk/vala/valasemanticanalyzer.vala	Fri Nov  7 10:31:16 2008
@@ -175,52 +175,11 @@
 	}
 
 	public override void visit_constant (Constant c) {
-		c.process_attributes ();
-
-		c.type_reference.accept (this);
-
-		if (!c.external_package) {
-			if (c.initializer == null) {
-				c.error = true;
-				Report.error (c.source_reference, "A const field requires a initializer to be provided");
-			} else {
-				c.initializer.target_type = c.type_reference;
-
-				c.initializer.accept (this);
-			}
-		}
+		c.check (this);
 	}
 
 	public override void visit_field (Field f) {
-		f.process_attributes ();
-
-		if (f.initializer != null) {
-			f.initializer.target_type = f.field_type;
-		}
-
-		f.accept_children (this);
-
-		if (f.binding == MemberBinding.INSTANCE && f.parent_symbol is Interface) {
-			f.error = true;
-			Report.error (f.source_reference, "Interfaces may not have instance fields");
-			return;
-		}
-
-		if (!f.is_internal_symbol ()) {
-			if (f.field_type is ValueType) {
-				current_source_file.add_type_dependency (f.field_type, SourceFileDependencyType.HEADER_FULL);
-			} else {
-				current_source_file.add_type_dependency (f.field_type, SourceFileDependencyType.HEADER_SHALLOW);
-			}
-		} else {
-			if (f.parent_symbol is Namespace) {
-				f.error = true;
-				Report.error (f.source_reference, "Namespaces may not have private members");
-				return;
-			}
-
-			current_source_file.add_type_dependency (f.field_type, SourceFileDependencyType.SOURCE);
-		}
+		f.check (this);
 	}
 
 	public override void visit_method (Method m) {
@@ -228,38 +187,10 @@
 	}
 
 	public override void visit_creation_method (CreationMethod m) {
-		m.process_attributes ();
-
-		if (m.type_name != null && m.type_name != current_symbol.name) {
-			// type_name is null for constructors generated by GIdlParser
-			Report.error (m.source_reference, "missing return type in method `%s.%sÂ".printf (current_symbol.get_full_name (), m.type_name));
-			m.error = true;
-			return;
-		}
-
-		current_symbol = m;
-		current_return_type = m.return_type;
-
-		m.accept_children (this);
-
-		current_symbol = current_symbol.parent_symbol;
-		current_return_type = null;
-
-		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 (m.is_abstract || m.is_virtual || m.overrides) {
-			Report.error (m.source_reference, "The creation method `%s' cannot be marked as override, virtual, or abstract".printf (m.get_full_name ()));
-			return;
-		}
+		m.check (this);
 	}
 
 	public override void visit_formal_parameter (FormalParameter p) {
-		p.process_attributes ();
-
 		p.check (this);
 	}
 
@@ -278,83 +209,23 @@
 	}
 
 	public override void visit_property (Property prop) {
-		prop.process_attributes ();
-
 		prop.check (this);
 	}
 
 	public override void visit_property_accessor (PropertyAccessor acc) {
-		acc.process_attributes ();
-
-		var old_return_type = current_return_type;
-		if (acc.readable) {
-			current_return_type = acc.prop.property_type;
-		} else {
-			// void
-			current_return_type = new VoidType ();
-		}
-
-		if (!acc.prop.external_package) {
-			if (acc.body == null && !acc.prop.interface_only && !acc.prop.is_abstract) {
-				/* no accessor body specified, insert default body */
-
-				if (acc.prop.parent_symbol is Interface) {
-					acc.error = true;
-					Report.error (acc.source_reference, "Automatic properties can't be used in interfaces");
-					return;
-				}
-				acc.automatic_body = true;
-				acc.body = new Block (acc.source_reference);
-				var ma = new MemberAccess.simple ("_%s".printf (acc.prop.name), acc.source_reference);
-				if (acc.readable) {
-					acc.body.add_statement (new ReturnStatement (ma, acc.source_reference));
-				} else {
-					var assignment = new Assignment (ma, new MemberAccess.simple ("value", acc.source_reference), AssignmentOperator.SIMPLE, acc.source_reference);
-					acc.body.add_statement (new ExpressionStatement (assignment));
-				}
-			}
-
-			if (acc.body != null && (acc.writable || acc.construction)) {
-				var value_type = acc.prop.property_type.copy ();
-				acc.value_parameter = new FormalParameter ("value", value_type, acc.source_reference);
-				acc.body.scope.add (acc.value_parameter.name, acc.value_parameter);
-			}
-		}
-
-		acc.accept_children (this);
-
-		current_return_type = old_return_type;
+		acc.check (this);
 	}
 
 	public override void visit_signal (Signal sig) {
-		sig.process_attributes ();
-
-		sig.accept_children (this);
+		sig.check (this);
 	}
 
 	public override void visit_constructor (Constructor c) {
-		c.this_parameter = new FormalParameter ("this", new ObjectType (current_class));
-		c.scope.add (c.this_parameter.name, c.this_parameter);
-
-		c.owner = current_symbol.scope;
-		current_symbol = c;
-
-		c.accept_children (this);
-
-		foreach (DataType body_error_type in c.body.get_error_types ()) {
-			Report.warning (body_error_type.source_reference, "unhandled error `%s'".printf (body_error_type.to_string()));
-		}
-
-		current_symbol = current_symbol.parent_symbol;
+		c.check (this);
 	}
 
 	public override void visit_destructor (Destructor d) {
-		d.owner = current_symbol.scope;
-		current_symbol = d;
-
-		d.accept_children (this);
-
-		current_symbol = current_symbol.parent_symbol;
+		d.check (this);
 	}
 
 	public override void visit_block (Block b) {

Modified: trunk/vala/valasignal.vala
==============================================================================
--- trunk/vala/valasignal.vala	(original)
+++ trunk/vala/valasignal.vala	Fri Nov  7 10:31:16 2008
@@ -218,5 +218,19 @@
 		
 		return generated_method;
 	}
+
+	public override bool check (SemanticAnalyzer analyzer) {
+		if (checked) {
+			return !error;
+		}
+
+		checked = true;
+
+		process_attributes ();
+
+		accept_children (analyzer);
+
+		return !error;
+	}
 }
 



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