Line data Source code
1 : /* valabaseaccess.vala
2 : *
3 : * Copyright (C) 2006-2010 Jürg Billeter
4 : *
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.
9 :
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.
14 :
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
18 : *
19 : * Author:
20 : * Jürg Billeter <j@bitron.ch>
21 : */
22 :
23 :
24 : /**
25 : * Represents an access to base type member in the source code.
26 : */
27 302 : public class Vala.BaseAccess : Expression {
28 : /**
29 : * Creates a new base access expression.
30 : *
31 : * @param source reference to source code
32 : * @return newly created base access expression
33 : */
34 1534 : public BaseAccess (SourceReference? source = null) {
35 767 : source_reference = source;
36 : }
37 :
38 1425 : public override void accept (CodeVisitor visitor) {
39 1425 : visitor.visit_base_access (this);
40 :
41 1425 : visitor.visit_expression (this);
42 : }
43 :
44 0 : public override string to_string () {
45 0 : return "base";
46 : }
47 :
48 0 : public override bool is_pure () {
49 0 : return true;
50 : }
51 :
52 768 : public override bool check (CodeContext context) {
53 768 : if (checked) {
54 1 : return !error;
55 : }
56 :
57 767 : checked = true;
58 :
59 767 : if (!context.analyzer.is_in_instance_method ()) {
60 1 : error = true;
61 1 : Report.error (source_reference, "Base access invalid outside of instance methods");
62 1 : return false;
63 : }
64 :
65 766 : if (context.analyzer.current_class == null) {
66 7 : if (context.analyzer.current_struct == null) {
67 1 : error = true;
68 1 : Report.error (source_reference, "Base access invalid outside of class and struct");
69 1 : return false;
70 6 : } else if (context.analyzer.current_struct.base_type == null) {
71 1 : error = true;
72 1 : Report.error (source_reference, "Base access invalid without base type");
73 1 : return false;
74 : }
75 5 : value_type = context.analyzer.current_struct.base_type;
76 759 : } else if (context.analyzer.current_class.base_class == null) {
77 1 : error = true;
78 1 : Report.error (source_reference, "Base access invalid without base class");
79 1 : return false;
80 758 : } else if (context.analyzer.current_class.is_compact && context.analyzer.current_method != null
81 20 : && !(context.analyzer.current_method is CreationMethod)
82 3 : && (context.analyzer.current_method.overrides || context.analyzer.current_method.is_virtual)) {
83 1 : error = true;
84 1 : Report.error (source_reference, "Base access invalid in virtual overridden method of compact class");
85 1 : return false;
86 757 : } else if (context.analyzer.current_class.is_compact && context.analyzer.current_property_accessor != null
87 1 : && (context.analyzer.current_property_accessor.prop.overrides || context.analyzer.current_property_accessor.prop.is_virtual)) {
88 1 : error = true;
89 1 : Report.error (source_reference, "Base access invalid in virtual overridden property of compact class");
90 1 : return false;
91 : } else {
92 2554 : foreach (var base_type in context.analyzer.current_class.get_base_types ()) {
93 899 : if (base_type.type_symbol is Class) {
94 756 : value_type = base_type.copy ();
95 756 : value_type.value_owned = false;
96 : }
97 : }
98 : }
99 :
100 761 : symbol_reference = value_type.type_symbol;
101 :
102 761 : return !error;
103 : }
104 :
105 700 : public override void emit (CodeGenerator codegen) {
106 700 : codegen.visit_base_access (this);
107 :
108 700 : codegen.visit_expression (this);
109 : }
110 : }
|