valaccodecomment.vala \
valaccodeconditionalexpression.vala \
valaccodeconstant.vala \
+ valaccodeconstantidentifier.vala \
valaccodecontinuestatement.vala \
valaccodedeclaration.vala \
valaccodedeclarator.vala \
--- /dev/null
+/* valaccodeconstantidentifier.vala
+ *
+ * Copyright (C) 2021 Rico Tzschichholz
+ *
+ * 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:
+ * Rico Tzschichholz <ricotz@ubuntu.com>
+ */
+
+using GLib;
+
+/**
+ * Represents a constant identifier in the C code.
+ */
+public class Vala.CCodeConstantIdentifier : CCodeIdentifier {
+ /**
+ * The name of this constant identifier.
+ */
+ public CCodeConstantIdentifier (string name) {
+ base (name);
+ }
+}
}
public static bool is_constant_ccode_expression (CCodeExpression cexpr) {
- if (cexpr is CCodeConstant) {
+ if (cexpr is CCodeConstant || cexpr is CCodeConstantIdentifier) {
return true;
} else if (cexpr is CCodeCastExpression) {
var ccast = (CCodeCastExpression) cexpr;
result.value_type.nullable = false;
if (!result.lvalue || !result.value_type.equals (value.value_type)) {
result.cvalue = get_implicit_cast_expression (result.cvalue, value.value_type, result.value_type, node);
- result = (GLibValue) store_temp_value (result, node);
+ if (!(result.cvalue is CCodeConstantIdentifier)) {
+ result = (GLibValue) store_temp_value (result, node);
+ }
}
result.cvalue = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, result.cvalue);
result.lvalue = false;
s = current_method.get_full_name ();
}
set_cvalue (expr, new CCodeConstant ("\"%s\"".printf (s)));
- } else {
+ } else if (c.type_reference.is_non_null_simple_type ()) {
set_cvalue (expr, new CCodeConstant (get_ccode_name (c)));
+ } else {
+ set_cvalue (expr, new CCodeConstantIdentifier (get_ccode_name (c)));
}
if (array_type != null) {
basic-types/bug788775.vala \
constants/array-type-invalid.test \
constants/glog.vala \
+ constants/member-access.vala \
constants/strings.vala \
namespace/unique.vala \
arrays/cast-silent-invalid.test \
--- /dev/null
+struct Foo {
+ public int i;
+}
+
+const Foo FOO = { 23 };
+const Foo FAZ = { 42 };
+
+class Bar {
+ public unowned Foo? foo;
+
+ public Bar (Foo _foo) {
+ foo = _foo;
+ }
+}
+
+void main () {
+ Bar bar;
+ {
+ bar = new Bar (FOO);
+ }
+ assert (bar.foo.i == 23);
+ {
+ bar.foo = FAZ;
+ }
+ assert (bar.foo.i == 42);
+}