Improve string tests
[vala-lang.git] / vala / valalockstatement.vala
blob8f9b5a592d2c61f89a321c6969de4b5faf01213c
1 /* valalockstatement.vala
3 * Copyright (C) 2006-2007 Raffaele Sandrini, 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 * Raffaele Sandrini <raffaele@sandrini.ch>
23 using GLib;
25 /**
26 * Represents a lock statement e.g. "lock (a) { f(a) }".
28 public class Vala.LockStatement : CodeNode, Statement {
29 /**
30 * Expression representing the resource to be locked.
32 public Expression resource { get; set; }
34 /**
35 * The statement during its execution the resource is locked.
37 public Block body { get; set; }
39 public LockStatement (Expression resource, Block body, SourceReference? source_reference = null) {
40 this.body = body;
41 this.source_reference = source_reference;
42 this.resource = resource;
45 public override void accept (CodeVisitor visitor) {
46 resource.accept (visitor);
47 body.accept (visitor);
48 visitor.visit_lock_statement (this);
51 public override bool check (SemanticAnalyzer analyzer) {
52 if (checked) {
53 return !error;
56 checked = true;
58 resource.check (analyzer);
59 body.check (analyzer);
61 /* resource must be a member access and denote a Lockable */
62 if (!(resource is MemberAccess && resource.symbol_reference is Lockable)) {
63 error = true;
64 resource.error = true;
65 Report.error (resource.source_reference, "Expression is either not a member access or does not denote a lockable member");
66 return false;
69 /* parent symbol must be the current class */
70 if (resource.symbol_reference.parent_symbol != analyzer.current_class) {
71 error = true;
72 resource.error = true;
73 Report.error (resource.source_reference, "Only members of the current class are lockable");
76 ((Lockable) resource.symbol_reference).set_lock_used (true);
78 return !error;