libwnck-3.0: Update to 3.24.1
[vala-gnome.git] / vala / valabaseaccess.vala
blob8058540689289087e6a47c65e70692c0b788a3ae
1 /* valabaseaccess.vala
3 * Copyright (C) 2006-2010 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>
24 /**
25 * Represents an access to base class members in the source code.
27 public class Vala.BaseAccess : Expression {
28 /**
29 * Creates a new base access expression.
31 * @param source reference to source code
32 * @return newly created base access expression
34 public BaseAccess (SourceReference? source = null) {
35 source_reference = source;
38 public override void accept (CodeVisitor visitor) {
39 visitor.visit_base_access (this);
41 visitor.visit_expression (this);
44 public override string to_string () {
45 return "base";
48 public override bool is_pure () {
49 return true;
52 public override bool check (CodeContext context) {
53 if (checked) {
54 return !error;
57 checked = true;
59 if (!context.analyzer.is_in_instance_method ()) {
60 error = true;
61 Report.error (source_reference, "Base access invalid outside of instance methods");
62 return false;
65 if (context.analyzer.current_class == null) {
66 if (context.analyzer.current_struct == null) {
67 error = true;
68 Report.error (source_reference, "Base access invalid outside of class and struct");
69 return false;
70 } else if (context.analyzer.current_struct.base_type == null) {
71 error = true;
72 Report.error (source_reference, "Base access invalid without base type");
73 return false;
75 value_type = context.analyzer.current_struct.base_type;
76 } else if (context.analyzer.current_class.base_class == null) {
77 error = true;
78 Report.error (source_reference, "Base access invalid without base class");
79 return false;
80 } else {
81 foreach (var base_type in context.analyzer.current_class.get_base_types ()) {
82 if (base_type.data_type is Class) {
83 value_type = base_type.copy ();
84 value_type.value_owned = false;
89 symbol_reference = value_type.data_type;
91 return !error;
94 public override void emit (CodeGenerator codegen) {
95 codegen.visit_base_access (this);
97 codegen.visit_expression (this);