From: Jürg Billeter Date: Sun, 16 Aug 2009 14:56:39 +0000 (+0200) Subject: Report error on unsupported type check expressions X-Git-Tag: 0.7.6~196 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=380b0786f633baa40b877f079317ab070b6402fb;p=thirdparty%2Fvala.git Report error on unsupported type check expressions Fixes bug 585344. --- diff --git a/ccode/Makefile.am b/ccode/Makefile.am index d70c56897..af79c1f96 100644 --- a/ccode/Makefile.am +++ b/ccode/Makefile.am @@ -42,6 +42,7 @@ libvalaccode_la_VALASOURCES = \ valaccodeifstatement.vala \ valaccodeincludedirective.vala \ valaccodeinitializerlist.vala \ + valaccodeinvalidexpression.vala \ valaccodelabel.vala \ valaccodelinedirective.vala \ valaccodemacroreplacement.vala \ diff --git a/ccode/valaccodeinvalidexpression.vala b/ccode/valaccodeinvalidexpression.vala new file mode 100644 index 000000000..cf01e31b3 --- /dev/null +++ b/ccode/valaccodeinvalidexpression.vala @@ -0,0 +1,33 @@ +/* valaccodeinvalidexpression.vala + * + * Copyright (C) 2009 Jürg Billeter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jürg Billeter + */ + +/** + * Represents an invalid expression. + */ +public class Vala.CCodeInvalidExpression : CCodeExpression { + public CCodeInvalidExpression () { + } + + public override void write (CCodeWriter writer) { + assert_not_reached (); + } +} diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 0cfdb307b..a970c3a5a 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -3656,16 +3656,18 @@ internal class Vala.CCodeBaseModule : CCodeModule { expr.ccodenode = new CCodeBinaryExpression (op, cleft, cright); } - public string get_type_check_function (TypeSymbol type) { + public string? get_type_check_function (TypeSymbol type) { var cl = type as Class; if (cl != null && cl.type_check_function != null) { return cl.type_check_function; + } else if ((cl != null && cl.is_compact) || type is Struct || type is Enum || type is Delegate) { + return null; } else { return type.get_upper_case_cname ("IS_"); } } - CCodeExpression create_type_check (CCodeNode ccodenode, DataType type) { + CCodeExpression? create_type_check (CCodeNode ccodenode, DataType type) { var et = type as ErrorType; if (et != null && et.error_code != null) { var matches_call = new CCodeFunctionCall (new CCodeIdentifier ("g_error_matches")); @@ -3678,7 +3680,11 @@ internal class Vala.CCodeBaseModule : CCodeModule { var type_domain = new CCodeIdentifier (et.error_domain.get_upper_case_cname ()); return new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, instance_domain, type_domain); } else { - var ccheck = new CCodeFunctionCall (new CCodeIdentifier (get_type_check_function (type.data_type))); + string type_check_func = get_type_check_function (type.data_type); + if (type_check_func == null) { + return new CCodeInvalidExpression (); + } + var ccheck = new CCodeFunctionCall (new CCodeIdentifier (type_check_func)); ccheck.add_argument ((CCodeExpression) ccodenode); return ccheck; } @@ -3688,6 +3694,9 @@ internal class Vala.CCodeBaseModule : CCodeModule { generate_type_declaration (expr.type_reference, source_declarations); expr.ccodenode = create_type_check (expr.expression.ccodenode, expr.type_reference); + if (expr.ccodenode is CCodeInvalidExpression) { + Report.error (expr.source_reference, "type check expressions not supported for compact classes, structs, and enums"); + } } public override void visit_lambda_expression (LambdaExpression l) {