Insert "%s" argument in printf calls with non-literal format string
[vala-lang.git] / vala / valapostfixexpression.vala
blobb9d6af13f1680050d524274c2eee51846aa47c42
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
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 using GLib;
25 /**
26 * Represents a postfix increment or decrement expression.
28 public class Vala.PostfixExpression : Expression {
29 /**
30 * The operand, must be a variable or a property.
32 public Expression inner { get; set; }
34 /**
35 * Specifies whether value should be incremented or decremented.
37 public bool increment { get; set; }
39 /**
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) {
48 inner = _inner;
49 increment = inc;
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 () {
62 return false;
65 public override bool check (SemanticAnalyzer analyzer) {
66 if (checked) {
67 return !error;
70 checked = true;
72 if (!inner.check (analyzer)) {
73 error = true;
74 return false;
77 if (!(inner.value_type is IntegerType) && !(inner.value_type is FloatingType) && !(inner.value_type is PointerType)) {
78 error = true;
79 Report.error (source_reference, "unsupported lvalue in postfix expression");
80 return false;
83 if (inner is MemberAccess) {
84 var ma = (MemberAccess) inner;
86 if (ma.prototype_access) {
87 error = true;
88 Report.error (source_reference, "Access to instance member `%s' denied".printf (ma.symbol_reference.get_full_name ()));
89 return false;
92 if (ma.error || ma.symbol_reference == null) {
93 error = true;
94 /* if no symbol found, skip this check */
95 return false;
97 } else if (inner is ElementAccess) {
98 var ea = (ElementAccess) inner;
99 if (!(ea.container.value_type is ArrayType)) {
100 error = true;
101 Report.error (source_reference, "unsupported lvalue in postfix expression");
102 return false;
104 } else {
105 error = true;
106 Report.error (source_reference, "unsupported lvalue in postfix expression");
107 return false;
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) {
117 ma.error = true;
118 Report.error (ma.source_reference, "Property `%s' is read-only".printf (prop.get_full_name ()));
119 return false;
124 value_type = inner.value_type;
126 return !error;