Update automake to version 1.10
[msysgit.git] / share / automake-1.10 / Automake / Item.pm
blob60d6bf4155f75ac99a6b064033552af9380f2b07
1 # Copyright (C) 2003, 2004 Free Software Foundation, Inc.
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.
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.
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.
18 package Automake::Item;
19 use strict;
20 use Carp;
22 use Automake::ChannelDefs;
23 use Automake::DisjConditions;
25 =head1 NAME
27 Automake::Item - base class for Automake::Variable and Automake::Rule
29 =head1 DESCRIPTION
31 =head2 Methods
33 =over 4
35 =item C<new Automake::Item $name>
37 Create and return an empty Item called C<$name>.
39 =cut
41 sub new ($$)
43 my ($class, $name) = @_;
44 my $self = {
45 name => $name,
46 defs => {},
47 conds => {},
49 bless $self, $class;
50 return $self;
53 =item C<$item-E<gt>name>
55 Return the name of C<$item>.
57 =cut
59 sub name ($)
61 my ($self) = @_;
62 return $self->{'name'};
65 =item C<$item-E<gt>def ($cond)>
67 Return the definition for this item in condition C<$cond>, if it
68 exists. Return 0 otherwise.
70 =cut
72 sub def ($$)
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;
82 =item C<$item-E<gt>rdef ($cond)>
84 Return the definition for this item in condition C<$cond>. Abort with
85 an internal error if the item was not defined under this condition.
87 The I<r> in front of C<def> stands for I<required>. One
88 should call C<rdef> to assert the conditional definition's existence.
90 =cut
92 sub rdef ($$)
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;
102 =item C<$item-E<gt>set ($cond, $def)>
104 Add a new definition to an existing item.
106 =cut
108 sub set ($$$)
110 my ($self, $cond, $def) = @_;
111 $self->{'defs'}{$cond} = $def;
112 $self->{'conds'}{$cond} = $cond;
115 =item C<$var-E<gt>conditions>
117 Return an L<Automake::DisjConditions> describing the conditions that
118 that an item is defined in.
120 These are all the conditions for which is would be safe to call
121 C<rdef>.
123 =cut
125 sub conditions ($)
127 my ($self) = @_;
128 prog_error ("self is not a reference")
129 unless ref $self;
130 return new Automake::DisjConditions (values %{$self->{'conds'}});
133 =item C<@missing_conds = $var-E<gt>not_always_defined_in_cond ($cond)>
135 Check whether C<$var> is always defined for condition C<$cond>.
136 Return a list of conditions where the definition is missing.
138 For instance, given
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
157 we should have (we display result as conditional strings in this
158 illustration, but we really return DisjConditions objects):
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")
175 =cut
177 sub not_always_defined_in_cond ($$)
179 my ($self, $cond) = @_;
181 # Compute the subconditions where $var isn't defined.
182 return
183 $self->conditions
184 ->sub_conditions ($cond)
185 ->invert
186 ->multiply ($cond);
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: