codegen: Fix floating reference regression with Variants
[vala-gnome.git] / vala / valabaseaccess.vala
blob955233bdc4fae5a0c0c84665b388e2c2f57e44ca
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 if (context.analyzer.current_class.is_compact && context.analyzer.current_method != null
81 && !(context.analyzer.current_method is CreationMethod)) {
82 error = true;
83 Report.error (source_reference, "Base access invalid in virtual overridden method of compact class");
84 return false;
85 } else if (context.analyzer.current_class.is_compact && context.analyzer.current_property_accessor != null) {
86 error = true;
87 Report.error (source_reference, "Base access invalid in virtual overridden property of compact class");
88 return false;
89 } else {
90 foreach (var base_type in context.analyzer.current_class.get_base_types ()) {
91 if (base_type.data_type is Class) {
92 value_type = base_type.copy ();
93 value_type.value_owned = false;
98 symbol_reference = value_type.data_type;
100 return !error;
103 public override void emit (CodeGenerator codegen) {
104 codegen.visit_base_access (this);
106 codegen.visit_expression (this);