1 /* valapostfixexpression.vala
3 * Copyright (C) 2006-2009 Jürg Billeter
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Jürg Billeter <j@bitron.ch>
26 * Represents a postfix increment or decrement expression.
28 public class Vala
.PostfixExpression
: Expression
{
30 * The operand, must be a variable or a property.
32 public Expression inner
{ get; set; }
35 * Specifies whether value should be incremented or decremented.
37 public bool increment
{ get; set; }
40 * Creates a new postfix expression.
42 * @param inner operand expression
43 * @param inc true for increment, false for decrement
44 * @param source reference to source code
45 * @return newly created postfix expression
47 public PostfixExpression (Expression _inner
, bool inc
, SourceReference source
) {
50 source_reference
= source
;
53 public override void accept (CodeVisitor visitor
) {
54 inner
.accept (visitor
);
56 visitor
.visit_postfix_expression (this
);
58 visitor
.visit_expression (this
);
61 public override bool is_pure () {
65 public override bool check (SemanticAnalyzer analyzer
) {
72 if (!inner
.check (analyzer
)) {
77 if (!(inner
.value_type is IntegerType
) && !(inner
.value_type is FloatingType
) && !(inner
.value_type is PointerType
)) {
79 Report
.error (source_reference
, "unsupported lvalue in postfix expression");
83 if (inner is MemberAccess
) {
84 var ma
= (MemberAccess
) inner
;
86 if (ma
.prototype_access
) {
88 Report
.error (source_reference
, "Access to instance member `%s' denied".printf (ma
.symbol_reference
.get_full_name ()));
92 if (ma
.error
|| ma
.symbol_reference
== null) {
94 /* if no symbol found, skip this check */
97 } else if (inner is ElementAccess
) {
98 var ea
= (ElementAccess
) inner
;
99 if (!(ea
.container
.value_type is ArrayType
)) {
101 Report
.error (source_reference
, "unsupported lvalue in postfix expression");
106 Report
.error (source_reference
, "unsupported lvalue in postfix expression");
110 if (inner is MemberAccess
) {
111 var ma
= (MemberAccess
) inner
;
113 if (ma
.symbol_reference is Property
) {
114 var prop
= (Property
) ma
.symbol_reference
;
116 if (prop
.set_accessor
== null || !prop
.set_accessor
.writable
) {
118 Report
.error (ma
.source_reference
, "Property `%s' is read-only".printf (prop
.get_full_name ()));
124 value_type
= inner
.value_type
;