[vala] Report error on unsupported type check expressions
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vala] Report error on unsupported type check expressions
- Date: Sun, 16 Aug 2009 14:57:37 +0000 (UTC)
commit 380b0786f633baa40b877f079317ab070b6402fb
Author: Jürg Billeter <j bitron ch>
Date: Sun Aug 16 16:56:39 2009 +0200
Report error on unsupported type check expressions
Fixes bug 585344.
ccode/Makefile.am | 1 +
ccode/valaccodeinvalidexpression.vala | 33 +++++++++++++++++++++++++++++++++
codegen/valaccodebasemodule.vala | 15 ++++++++++++---
3 files changed, 46 insertions(+), 3 deletions(-)
---
diff --git a/ccode/Makefile.am b/ccode/Makefile.am
index d70c568..af79c1f 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 0000000..cf01e31
--- /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 <j bitron ch>
+ */
+
+/**
+ * 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 0cfdb30..a970c3a 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) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]