valaccodeifstatement.vala \
valaccodeincludedirective.vala \
valaccodeinitializerlist.vala \
+ valaccodeinvalidexpression.vala \
valaccodelabel.vala \
valaccodelinedirective.vala \
valaccodemacroreplacement.vala \
--- /dev/null
+/* 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 ();
+ }
+}
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"));
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;
}
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) {