vala r1985 - in trunk: . vala
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r1985 - in trunk: . vala
- Date: Wed, 5 Nov 2008 21:48:45 +0000 (UTC)
Author: juergbi
Date: Wed Nov 5 21:48:44 2008
New Revision: 1985
URL: http://svn.gnome.org/viewvc/vala?rev=1985&view=rev
Log:
2008-11-05 JÃrg Billeter <j bitron ch>
* vala/valabinaryexpression.vala:
* vala/valaobjectcreationexpression.vala:
* vala/valasemanticanalyzer.vala:
Move object creation expression checking to
ObjectCreationExpression.check
Modified:
trunk/ChangeLog
trunk/vala/valabinaryexpression.vala
trunk/vala/valaobjectcreationexpression.vala
trunk/vala/valasemanticanalyzer.vala
Modified: trunk/vala/valabinaryexpression.vala
==============================================================================
--- trunk/vala/valabinaryexpression.vala (original)
+++ trunk/vala/valabinaryexpression.vala Wed Nov 5 21:48:44 2008
@@ -139,6 +139,12 @@
}
public override bool check (SemanticAnalyzer analyzer) {
+ if (checked) {
+ return !error;
+ }
+
+ checked = true;
+
if (left.error || right.error) {
/* if there were any errors in inner expressions, skip type check */
error = true;
Modified: trunk/vala/valaobjectcreationexpression.vala
==============================================================================
--- trunk/vala/valaobjectcreationexpression.vala (original)
+++ trunk/vala/valaobjectcreationexpression.vala Wed Nov 5 21:48:44 2008
@@ -149,4 +149,201 @@
type_reference = new_type;
}
}
+
+ public override bool check (SemanticAnalyzer analyzer) {
+ if (checked) {
+ return !error;
+ }
+
+ checked = true;
+
+ if (member_name != null) {
+ member_name.accept (analyzer);
+ }
+
+ TypeSymbol type = null;
+
+ if (type_reference == null) {
+ if (member_name == null) {
+ error = true;
+ Report.error (source_reference, "Incomplete object creation expression");
+ return false;
+ }
+
+ if (member_name.symbol_reference == null) {
+ error = true;
+ return false;
+ }
+
+ var constructor_sym = member_name.symbol_reference;
+ var type_sym = member_name.symbol_reference;
+
+ var type_args = member_name.get_type_arguments ();
+
+ if (constructor_sym is Method) {
+ type_sym = constructor_sym.parent_symbol;
+
+ var constructor = (Method) constructor_sym;
+ if (!(constructor_sym is CreationMethod)) {
+ error = true;
+ Report.error (source_reference, "`%s' is not a creation method".printf (constructor.get_full_name ()));
+ return false;
+ }
+
+ symbol_reference = constructor;
+
+ // inner expression can also be base access when chaining constructors
+ var ma = member_name.inner as MemberAccess;
+ if (ma != null) {
+ type_args = ma.get_type_arguments ();
+ }
+ }
+
+ if (type_sym is Class) {
+ type = (TypeSymbol) type_sym;
+ type_reference = new ObjectType ((Class) type);
+ } else if (type_sym is Struct) {
+ type = (TypeSymbol) type_sym;
+ type_reference = new ValueType (type);
+ } else if (type_sym is ErrorCode) {
+ type_reference = new ErrorType ((ErrorDomain) type_sym.parent_symbol, (ErrorCode) type_sym, source_reference);
+ symbol_reference = type_sym;
+ } else {
+ error = true;
+ Report.error (source_reference, "`%s' is not a class, struct, or error code".printf (type_sym.get_full_name ()));
+ return false;
+ }
+
+ foreach (DataType type_arg in type_args) {
+ type_reference.add_type_argument (type_arg);
+
+ analyzer.current_source_file.add_type_dependency (type_arg, SourceFileDependencyType.SOURCE);
+ }
+ } else {
+ type = type_reference.data_type;
+ }
+
+ analyzer.current_source_file.add_symbol_dependency (type, SourceFileDependencyType.SOURCE);
+
+ value_type = type_reference.copy ();
+ value_type.value_owned = true;
+
+ int given_num_type_args = type_reference.get_type_arguments ().size;
+ int expected_num_type_args = 0;
+
+ if (type is Class) {
+ var cl = (Class) type;
+
+ expected_num_type_args = cl.get_type_parameters ().size;
+
+ if (struct_creation) {
+ error = true;
+ Report.error (source_reference, "syntax error, use `new' to create new objects");
+ return false;
+ }
+
+ if (cl.is_abstract) {
+ value_type = null;
+ error = true;
+ Report.error (source_reference, "Can't create instance of abstract class `%s'".printf (cl.get_full_name ()));
+ return false;
+ }
+
+ if (symbol_reference == null) {
+ symbol_reference = cl.default_construction_method;
+ }
+
+ while (cl != null) {
+ if (cl == analyzer.initially_unowned_type) {
+ value_type.floating_reference = true;
+ break;
+ }
+
+ cl = cl.base_class;
+ }
+ } else if (type is Struct) {
+ var st = (Struct) type;
+
+ expected_num_type_args = st.get_type_parameters ().size;
+
+ if (!struct_creation) {
+ Report.warning (source_reference, "deprecated syntax, don't use `new' to initialize structs");
+ }
+
+ if (symbol_reference == null) {
+ symbol_reference = st.default_construction_method;
+ }
+ }
+
+ if (expected_num_type_args > given_num_type_args) {
+ error = true;
+ Report.error (source_reference, "too few type arguments");
+ return false;
+ } else if (expected_num_type_args < given_num_type_args) {
+ error = true;
+ Report.error (source_reference, "too many type arguments");
+ return false;
+ }
+
+ if (symbol_reference == null && get_argument_list ().size != 0) {
+ value_type = null;
+ error = true;
+ Report.error (source_reference, "No arguments allowed when constructing type `%s'".printf (type.get_full_name ()));
+ return false;
+ }
+
+ if (symbol_reference is Method) {
+ var m = (Method) symbol_reference;
+
+ var args = get_argument_list ();
+ Iterator<Expression> arg_it = args.iterator ();
+ foreach (FormalParameter param in m.get_parameters ()) {
+ if (param.ellipsis) {
+ break;
+ }
+
+ if (arg_it.next ()) {
+ Expression arg = arg_it.get ();
+
+ /* store expected type for callback parameters */
+ arg.target_type = param.parameter_type;
+ }
+ }
+
+ foreach (Expression arg in args) {
+ arg.accept (analyzer);
+ }
+
+ analyzer.check_arguments (this, new MethodType (m), m.get_parameters (), args);
+
+ foreach (DataType error_type in m.get_error_types ()) {
+ // ensure we can trace back which expression may throw errors of this type
+ var call_error_type = error_type.copy ();
+ call_error_type.source_reference = source_reference;
+
+ add_error_type (call_error_type);
+ }
+ } else if (type_reference is ErrorType) {
+ accept_children (analyzer);
+
+ if (get_argument_list ().size == 0) {
+ error = true;
+ Report.error (source_reference, "Too few arguments, errors need at least 1 argument");
+ } else {
+ Iterator<Expression> arg_it = get_argument_list ().iterator ();
+ arg_it.next ();
+ var ex = arg_it.get ();
+ if (ex.value_type == null || !ex.value_type.compatible (analyzer.string_type)) {
+ error = true;
+ Report.error (source_reference, "Invalid type for argument 1");
+ }
+ }
+ }
+
+ foreach (MemberInitializer init in get_object_initializer ()) {
+ analyzer.visit_member_initializer (init, type_reference);
+ }
+
+ return !error;
+ }
}
Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala (original)
+++ trunk/vala/valasemanticanalyzer.vala Wed Nov 5 21:48:44 2008
@@ -55,7 +55,7 @@
DataType double_type;
DataType type_type;
Class object_type;
- TypeSymbol initially_unowned_type;
+ public TypeSymbol initially_unowned_type;
DataType glist_type;
DataType gslist_type;
Class gerror_type;
@@ -2182,7 +2182,7 @@
check_arguments (expr, mtype, params, expr.get_argument_list ());
}
- private bool check_arguments (Expression expr, DataType mtype, Gee.List<FormalParameter> params, Gee.List<Expression> args) {
+ public bool check_arguments (Expression expr, DataType mtype, Gee.List<FormalParameter> params, Gee.List<Expression> args) {
Expression prev_arg = null;
Iterator<Expression> arg_it = args.iterator ();
@@ -2652,195 +2652,10 @@
}
public override void visit_object_creation_expression (ObjectCreationExpression expr) {
- if (expr.member_name != null) {
- expr.member_name.accept (this);
- }
-
- TypeSymbol type = null;
-
- if (expr.type_reference == null) {
- if (expr.member_name == null) {
- expr.error = true;
- Report.error (expr.source_reference, "Incomplete object creation expression");
- return;
- }
-
- if (expr.member_name.symbol_reference == null) {
- expr.error = true;
- return;
- }
-
- var constructor_sym = expr.member_name.symbol_reference;
- var type_sym = expr.member_name.symbol_reference;
-
- var type_args = expr.member_name.get_type_arguments ();
-
- if (constructor_sym is Method) {
- type_sym = constructor_sym.parent_symbol;
-
- var constructor = (Method) constructor_sym;
- if (!(constructor_sym is CreationMethod)) {
- expr.error = true;
- Report.error (expr.source_reference, "`%s' is not a creation method".printf (constructor.get_full_name ()));
- return;
- }
-
- expr.symbol_reference = constructor;
-
- // inner expression can also be base access when chaining constructors
- var ma = expr.member_name.inner as MemberAccess;
- if (ma != null) {
- type_args = ma.get_type_arguments ();
- }
- }
-
- if (type_sym is Class) {
- type = (TypeSymbol) type_sym;
- expr.type_reference = new ObjectType ((Class) type);
- } else if (type_sym is Struct) {
- type = (TypeSymbol) type_sym;
- expr.type_reference = new ValueType (type);
- } else if (type_sym is ErrorCode) {
- expr.type_reference = new ErrorType ((ErrorDomain) type_sym.parent_symbol, (ErrorCode) type_sym, expr.source_reference);
- expr.symbol_reference = type_sym;
- } else {
- expr.error = true;
- Report.error (expr.source_reference, "`%s' is not a class, struct, or error code".printf (type_sym.get_full_name ()));
- return;
- }
-
- foreach (DataType type_arg in type_args) {
- expr.type_reference.add_type_argument (type_arg);
-
- current_source_file.add_type_dependency (type_arg, SourceFileDependencyType.SOURCE);
- }
- } else {
- type = expr.type_reference.data_type;
- }
-
- current_source_file.add_symbol_dependency (type, SourceFileDependencyType.SOURCE);
-
- expr.value_type = expr.type_reference.copy ();
- expr.value_type.value_owned = true;
-
- int given_num_type_args = expr.type_reference.get_type_arguments ().size;
- int expected_num_type_args = 0;
-
- if (type is Class) {
- var cl = (Class) type;
-
- expected_num_type_args = cl.get_type_parameters ().size;
-
- if (expr.struct_creation) {
- expr.error = true;
- Report.error (expr.source_reference, "syntax error, use `new' to create new objects");
- return;
- }
-
- if (cl.is_abstract) {
- expr.value_type = null;
- expr.error = true;
- Report.error (expr.source_reference, "Can't create instance of abstract class `%s'".printf (cl.get_full_name ()));
- return;
- }
-
- if (expr.symbol_reference == null) {
- expr.symbol_reference = cl.default_construction_method;
- }
-
- while (cl != null) {
- if (cl == initially_unowned_type) {
- expr.value_type.floating_reference = true;
- break;
- }
-
- cl = cl.base_class;
- }
- } else if (type is Struct) {
- var st = (Struct) type;
-
- expected_num_type_args = st.get_type_parameters ().size;
-
- if (!expr.struct_creation) {
- Report.warning (expr.source_reference, "deprecated syntax, don't use `new' to initialize structs");
- }
-
- if (expr.symbol_reference == null) {
- expr.symbol_reference = st.default_construction_method;
- }
- }
-
- if (expected_num_type_args > given_num_type_args) {
- expr.error = true;
- Report.error (expr.source_reference, "too few type arguments");
- return;
- } else if (expected_num_type_args < given_num_type_args) {
- expr.error = true;
- Report.error (expr.source_reference, "too many type arguments");
- return;
- }
-
- if (expr.symbol_reference == null && expr.get_argument_list ().size != 0) {
- expr.value_type = null;
- expr.error = true;
- Report.error (expr.source_reference, "No arguments allowed when constructing type `%s'".printf (type.get_full_name ()));
- return;
- }
-
- if (expr.symbol_reference is Method) {
- var m = (Method) expr.symbol_reference;
-
- var args = expr.get_argument_list ();
- Iterator<Expression> arg_it = args.iterator ();
- foreach (FormalParameter param in m.get_parameters ()) {
- if (param.ellipsis) {
- break;
- }
-
- if (arg_it.next ()) {
- Expression arg = arg_it.get ();
-
- /* store expected type for callback parameters */
- arg.target_type = param.parameter_type;
- }
- }
-
- foreach (Expression arg in args) {
- arg.accept (this);
- }
-
- check_arguments (expr, new MethodType (m), m.get_parameters (), args);
-
- foreach (DataType error_type in m.get_error_types ()) {
- // ensure we can trace back which expression may throw errors of this type
- var call_error_type = error_type.copy ();
- call_error_type.source_reference = expr.source_reference;
-
- expr.add_error_type (call_error_type);
- }
- } else if (expr.type_reference is ErrorType) {
- expr.accept_children (this);
-
- if (expr.get_argument_list ().size == 0) {
- expr.error = true;
- Report.error (expr.source_reference, "Too few arguments, errors need at least 1 argument");
- } else {
- Iterator<Expression> arg_it = expr.get_argument_list ().iterator ();
- arg_it.next ();
- var ex = arg_it.get ();
- if (ex.value_type == null || !ex.value_type.compatible (string_type)) {
- expr.error = true;
- Report.error (expr.source_reference, "Invalid type for argument 1");
- }
- }
- }
-
- foreach (MemberInitializer init in expr.get_object_initializer ()) {
- visit_member_initializer (init, expr.type_reference);
- }
+ expr.check (this);
}
- void visit_member_initializer (MemberInitializer init, DataType type) {
+ public void visit_member_initializer (MemberInitializer init, DataType type) {
init.accept (this);
init.symbol_reference = symbol_lookup_inherited (type.data_type, init.name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]