girparser: Fix parameter index calculation
[vala-lang.git] / vala / valaunlockstatement.vala
blobe0ae1a034e6e85822dd96e8468989b139158fa5d
1 /* valaunlockstatement.vala
3 * Copyright (C) 2009 Jiří Zárevúcky, 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 * Jiří Zárevúcky <zarevucky.jiri@gmail.com>
23 /**
24 * Represents an unlock statement e.g. {{{ unlock (a); }}}.
26 public class Vala.UnlockStatement : CodeNode, Statement {
27 /**
28 * Expression representing the resource to be unlocked.
30 public Expression resource { get; set; }
32 public UnlockStatement (Expression resource, SourceReference? source_reference = null) {
33 this.source_reference = source_reference;
34 this.resource = resource;
37 public override void accept (CodeVisitor visitor) {
38 resource.accept (visitor);
39 visitor.visit_unlock_statement (this);
42 public override bool check (SemanticAnalyzer analyzer) {
43 if (checked) {
44 return !error;
47 checked = true;
49 resource.check (analyzer);
51 /* resource must be a member access and denote a Lockable */
52 if (!(resource is MemberAccess && resource.symbol_reference is Lockable)) {
53 error = true;
54 resource.error = true;
55 Report.error (resource.source_reference, "Expression is either not a member access or does not denote a lockable member");
56 return false;
59 /* parent symbol must be the current class */
60 if (resource.symbol_reference.parent_symbol != analyzer.current_class) {
61 error = true;
62 resource.error = true;
63 Report.error (resource.source_reference, "Only members of the current class are lockable");
66 ((Lockable) resource.symbol_reference).set_lock_used (true);
68 return !error;