source: trunk/essentials/sys-devel/automake-1.10/lib/Automake/Item.pm

Last change on this file was 3147, checked in by bird, 18 years ago

automake 1.10

File size: 4.6 KB
Line 
1# Copyright (C) 2003, 2004 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2, or (at your option)
6# any later version.
7
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16# 02110-1301, USA.
17
18package Automake::Item;
19use strict;
20use Carp;
21
22use Automake::ChannelDefs;
23use Automake::DisjConditions;
24
25=head1 NAME
26
27Automake::Item - base class for Automake::Variable and Automake::Rule
28
29=head1 DESCRIPTION
30
31=head2 Methods
32
33=over 4
34
35=item C<new Automake::Item $name>
36
37Create and return an empty Item called C<$name>.
38
39=cut
40
41sub new ($$)
42{
43 my ($class, $name) = @_;
44 my $self = {
45 name => $name,
46 defs => {},
47 conds => {},
48 };
49 bless $self, $class;
50 return $self;
51}
52
53=item C<$item-E<gt>name>
54
55Return the name of C<$item>.
56
57=cut
58
59sub name ($)
60{
61 my ($self) = @_;
62 return $self->{'name'};
63}
64
65=item C<$item-E<gt>def ($cond)>
66
67Return the definition for this item in condition C<$cond>, if it
68exists. Return 0 otherwise.
69
70=cut
71
72sub def ($$)
73{
74 # This method is called very often, so keep it small and fast. We
75 # don't mind the extra undefined items introduced by lookup failure;
76 # avoiding this with `exists' means doing two hash lookup on
77 # success, and proved worse on benchmark.
78 my $def = $_[0]->{'defs'}{$_[1]};
79 return defined $def && $def;
80}
81
82=item C<$item-E<gt>rdef ($cond)>
83
84Return the definition for this item in condition C<$cond>. Abort with
85an internal error if the item was not defined under this condition.
86
87The I<r> in front of C<def> stands for I<required>. One
88should call C<rdef> to assert the conditional definition's existence.
89
90=cut
91
92sub rdef ($$)
93{
94 my ($self, $cond) = @_;
95 my $d = $self->def ($cond);
96 prog_error ("undefined condition `" . $cond->human . "' for `"
97 . $self->name . "'\n" . $self->dump)
98 unless $d;
99 return $d;
100}
101
102=item C<$item-E<gt>set ($cond, $def)>
103
104Add a new definition to an existing item.
105
106=cut
107
108sub set ($$$)
109{
110 my ($self, $cond, $def) = @_;
111 $self->{'defs'}{$cond} = $def;
112 $self->{'conds'}{$cond} = $cond;
113}
114
115=item C<$var-E<gt>conditions>
116
117Return an L<Automake::DisjConditions> describing the conditions that
118that an item is defined in.
119
120These are all the conditions for which is would be safe to call
121C<rdef>.
122
123=cut
124
125sub conditions ($)
126{
127 my ($self) = @_;
128 prog_error ("self is not a reference")
129 unless ref $self;
130 return new Automake::DisjConditions (values %{$self->{'conds'}});
131}
132
133=item C<@missing_conds = $var-E<gt>not_always_defined_in_cond ($cond)>
134
135Check whether C<$var> is always defined for condition C<$cond>.
136Return a list of conditions where the definition is missing.
137
138For instance, given
139
140 if COND1
141 if COND2
142 A = foo
143 D = d1
144 else
145 A = bar
146 D = d2
147 endif
148 else
149 D = d3
150 endif
151 if COND3
152 A = baz
153 B = mumble
154 endif
155 C = mumble
156
157we should have (we display result as conditional strings in this
158illustration, but we really return DisjConditions objects):
159
160 var ('A')->not_always_defined_in_cond ('COND1_TRUE COND2_TRUE')
161 => ()
162 var ('A')->not_always_defined_in_cond ('COND1_TRUE')
163 => ()
164 var ('A')->not_always_defined_in_cond ('TRUE')
165 => ("COND1_FALSE COND3_FALSE")
166 var ('B')->not_always_defined_in_cond ('COND1_TRUE')
167 => ("COND1_TRUE COND3_FALSE")
168 var ('C')->not_always_defined_in_cond ('COND1_TRUE')
169 => ()
170 var ('D')->not_always_defined_in_cond ('TRUE')
171 => ()
172 var ('Z')->not_always_defined_in_cond ('TRUE')
173 => ("TRUE")
174
175=cut
176
177sub not_always_defined_in_cond ($$)
178{
179 my ($self, $cond) = @_;
180
181 # Compute the subconditions where $var isn't defined.
182 return
183 $self->conditions
184 ->sub_conditions ($cond)
185 ->invert
186 ->multiply ($cond);
187}
188
189
1901;
191
192### Setup "GNU" style for perl-mode and cperl-mode.
193## Local Variables:
194## perl-indent-level: 2
195## perl-continued-statement-offset: 2
196## perl-continued-brace-offset: 0
197## perl-brace-offset: 0
198## perl-brace-imaginary-offset: 0
199## perl-label-offset: -2
200## cperl-indent-level: 2
201## cperl-brace-offset: 0
202## cperl-continued-brace-offset: 0
203## cperl-label-offset: -2
204## cperl-extra-newline-before-brace: t
205## cperl-merge-trailing-else: nil
206## cperl-continued-statement-offset: 2
207## End:
Note: See TracBrowser for help on using the repository browser.