girparser: Provide default constructor for classes.
[vala-lang.git] / vala / valaunlockstatement.vala
blobff2f401850f9e31ef6540bf83451241b2c317f6a
1 /* valaunlockstatement.vala
3 * Copyright (C) 2009-2010 Jürg Billeter
4 * Copyright (C) 2009 Jiří Zárevúcky
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Author:
21 * Jiří Zárevúcky <zarevucky.jiri@gmail.com>
24 /**
25 * Represents an unlock statement e.g. {{{ unlock (a); }}}.
27 public class Vala.UnlockStatement : CodeNode, Statement {
28 /**
29 * Expression representing the resource to be unlocked.
31 public Expression resource { get; set; }
33 public UnlockStatement (Expression resource, SourceReference? source_reference = null) {
34 this.source_reference = source_reference;
35 this.resource = resource;
38 public override void accept (CodeVisitor visitor) {
39 resource.accept (visitor);
40 visitor.visit_unlock_statement (this);
43 public override bool check (CodeContext context) {
44 if (checked) {
45 return !error;
48 checked = true;
50 resource.check (context);
52 /* resource must be a member access and denote a Lockable */
53 if (!(resource is MemberAccess && resource.symbol_reference is Lockable)) {
54 error = true;
55 resource.error = true;
56 Report.error (resource.source_reference, "Expression is either not a member access or does not denote a lockable member");
57 return false;
60 /* parent symbol must be the current class */
61 if (resource.symbol_reference.parent_symbol != context.analyzer.current_class) {
62 error = true;
63 resource.error = true;
64 Report.error (resource.source_reference, "Only members of the current class are lockable");
67 ((Lockable) resource.symbol_reference).set_lock_used (true);
69 return !error;
72 public override void emit (CodeGenerator codegen) {
73 resource.emit (codegen);
74 codegen.visit_unlock_statement (this);