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
21 * Jiří Zárevúcky <zarevucky.jiri@gmail.com>
25 * Represents an unlock statement e.g. {{{ unlock (a); }}}.
27 public class Vala
.UnlockStatement
: CodeNode
, Statement
{
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
) {
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
)) {
55 resource
.error
= true;
56 Report
.error (resource
.source_reference
, "Expression is either not a member access or does not denote a lockable member");
60 /* parent symbol must be the current class */
61 if (resource
.symbol_reference
.parent_symbol
!= context
.analyzer
.current_class
) {
63 resource
.error
= true;
64 Report
.error (resource
.source_reference
, "Only members of the current class are lockable");
67 ((Lockable
) resource
.symbol_reference
).lock_used
= true;
72 public override void emit (CodeGenerator codegen
) {
73 resource
.emit (codegen
);
74 codegen
.visit_unlock_statement (this
);