1 | # Copyright (C) 2003 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 |
|
---|
18 | package Automake::Item;
|
---|
19 | use strict;
|
---|
20 | use Carp;
|
---|
21 |
|
---|
22 | use Automake::ChannelDefs;
|
---|
23 | use Automake::DisjConditions;
|
---|
24 |
|
---|
25 | =head1 NAME
|
---|
26 |
|
---|
27 | Automake::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 |
|
---|
37 | Create and return an empty Item called C<$name>.
|
---|
38 |
|
---|
39 | =cut
|
---|
40 |
|
---|
41 | sub 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 |
|
---|
55 | Return the name of C<$item>.
|
---|
56 |
|
---|
57 | =cut
|
---|
58 |
|
---|
59 | sub name ($)
|
---|
60 | {
|
---|
61 | my ($self) = @_;
|
---|
62 | return $self->{'name'};
|
---|
63 | }
|
---|
64 |
|
---|
65 | =item C<$item-E<gt>def ($cond)>
|
---|
66 |
|
---|
67 | Return the definition for this item in condition C<$cond>, if it
|
---|
68 | exists. Return 0 otherwise.
|
---|
69 |
|
---|
70 | =cut
|
---|
71 |
|
---|
72 | sub def ($$)
|
---|
73 | {
|
---|
74 | my ($self, $cond) = @_;
|
---|
75 | return $self->{'defs'}{$cond} if exists $self->{'defs'}{$cond};
|
---|
76 | return 0;
|
---|
77 | }
|
---|
78 |
|
---|
79 | =item C<$item-E<gt>rdef ($cond)>
|
---|
80 |
|
---|
81 | Return the definition for this item in condition C<$cond>. Abort with
|
---|
82 | an internal error if the item was not defined under this condition.
|
---|
83 |
|
---|
84 | The I<r> in front of C<def> stands for I<required>. One
|
---|
85 | should call C<rdef> to assert the conditional definition's existence.
|
---|
86 |
|
---|
87 | =cut
|
---|
88 |
|
---|
89 | sub rdef ($$)
|
---|
90 | {
|
---|
91 | my ($self, $cond) = @_;
|
---|
92 | my $d = $self->def ($cond);
|
---|
93 | prog_error ("undefined condition `" . $cond->human . "' for `"
|
---|
94 | . $self->name . "'\n" . $self->dump)
|
---|
95 | unless $d;
|
---|
96 | return $d;
|
---|
97 | }
|
---|
98 |
|
---|
99 | =item C<$item-E<gt>set ($cond, $def)>
|
---|
100 |
|
---|
101 | Add a new definition to an existing item.
|
---|
102 |
|
---|
103 | =cut
|
---|
104 |
|
---|
105 | sub set ($$$)
|
---|
106 | {
|
---|
107 | my ($self, $cond, $def) = @_;
|
---|
108 | $self->{'defs'}{$cond} = $def;
|
---|
109 | $self->{'conds'}{$cond} = $cond;
|
---|
110 | }
|
---|
111 |
|
---|
112 | =item C<$var-E<gt>conditions>
|
---|
113 |
|
---|
114 | Return an L<Automake::DisjConditions> describing the conditions that
|
---|
115 | that an item is defined in.
|
---|
116 |
|
---|
117 | These are all the conditions for which is would be safe to call
|
---|
118 | C<rdef>.
|
---|
119 |
|
---|
120 | =cut
|
---|
121 |
|
---|
122 | sub conditions ($)
|
---|
123 | {
|
---|
124 | my ($self) = @_;
|
---|
125 | prog_error ("self is not a reference")
|
---|
126 | unless ref $self;
|
---|
127 | return new Automake::DisjConditions (values %{$self->{'conds'}});
|
---|
128 | }
|
---|
129 |
|
---|
130 | =item C<@missing_conds = $var-E<gt>not_always_defined_in_cond ($cond)>
|
---|
131 |
|
---|
132 | Check whether C<$var> is always defined for condition C<$cond>.
|
---|
133 | Return a list of conditions where the definition is missing.
|
---|
134 |
|
---|
135 | For instance, given
|
---|
136 |
|
---|
137 | if COND1
|
---|
138 | if COND2
|
---|
139 | A = foo
|
---|
140 | D = d1
|
---|
141 | else
|
---|
142 | A = bar
|
---|
143 | D = d2
|
---|
144 | endif
|
---|
145 | else
|
---|
146 | D = d3
|
---|
147 | endif
|
---|
148 | if COND3
|
---|
149 | A = baz
|
---|
150 | B = mumble
|
---|
151 | endif
|
---|
152 | C = mumble
|
---|
153 |
|
---|
154 | we should have (we display result as conditional strings in this
|
---|
155 | illustration, but we really return DisjConditions objects):
|
---|
156 |
|
---|
157 | var ('A')->not_always_defined_in_cond ('COND1_TRUE COND2_TRUE')
|
---|
158 | => ()
|
---|
159 | var ('A')->not_always_defined_in_cond ('COND1_TRUE')
|
---|
160 | => ()
|
---|
161 | var ('A')->not_always_defined_in_cond ('TRUE')
|
---|
162 | => ("COND1_FALSE COND3_FALSE")
|
---|
163 | var ('B')->not_always_defined_in_cond ('COND1_TRUE')
|
---|
164 | => ("COND1_TRUE COND3_FALSE")
|
---|
165 | var ('C')->not_always_defined_in_cond ('COND1_TRUE')
|
---|
166 | => ()
|
---|
167 | var ('D')->not_always_defined_in_cond ('TRUE')
|
---|
168 | => ()
|
---|
169 | var ('Z')->not_always_defined_in_cond ('TRUE')
|
---|
170 | => ("TRUE")
|
---|
171 |
|
---|
172 | =cut
|
---|
173 |
|
---|
174 | sub not_always_defined_in_cond ($$)
|
---|
175 | {
|
---|
176 | my ($self, $cond) = @_;
|
---|
177 |
|
---|
178 | # Compute the subconditions where $var isn't defined.
|
---|
179 | return
|
---|
180 | $self->conditions
|
---|
181 | ->sub_conditions ($cond)
|
---|
182 | ->invert
|
---|
183 | ->multiply ($cond);
|
---|
184 | }
|
---|
185 |
|
---|
186 |
|
---|
187 | 1;
|
---|
188 |
|
---|
189 | ### Setup "GNU" style for perl-mode and cperl-mode.
|
---|
190 | ## Local Variables:
|
---|
191 | ## perl-indent-level: 2
|
---|
192 | ## perl-continued-statement-offset: 2
|
---|
193 | ## perl-continued-brace-offset: 0
|
---|
194 | ## perl-brace-offset: 0
|
---|
195 | ## perl-brace-imaginary-offset: 0
|
---|
196 | ## perl-label-offset: -2
|
---|
197 | ## cperl-indent-level: 2
|
---|
198 | ## cperl-brace-offset: 0
|
---|
199 | ## cperl-continued-brace-offset: 0
|
---|
200 | ## cperl-label-offset: -2
|
---|
201 | ## cperl-extra-newline-before-brace: t
|
---|
202 | ## cperl-merge-trailing-else: nil
|
---|
203 | ## cperl-continued-statement-offset: 2
|
---|
204 | ## End:
|
---|