1 /*
2 
3     This file is part of the Maude 2 interpreter.
4 
5     Copyright 1997-2003 SRI International, Menlo Park, CA 94025, USA.
6 
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11 
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20 
21 */
22 
23 //
24 //      Base class for ACU stripper-collector left hand side automata.
25 //
26 #ifndef _ACU_CollectorLhsAutomaton_hh_
27 #define _ACU_CollectorLhsAutomaton_hh_
28 #include "ACU_LhsAutomaton.hh"
29 
30 class ACU_CollectorLhsAutomaton : public ACU_LhsAutomaton
31 {
32   NO_COPYING(ACU_CollectorLhsAutomaton);
33 
34 public:
35   ACU_CollectorLhsAutomaton(ACU_Symbol* symbol,
36 			    bool matchAtTop,
37 			    bool collapsePossible,
38 			    int nrVariables,
39 			    VariableTerm* collector);
40 
41 #ifdef DUMP
42   void dump(ostream& s, const VariableInfo& variableInfo, int indentLevel);
43 #endif
44 
45 protected:
46   bool collectorFree(Substitution& solution) const;
47   bool collect(int stripped, ACU_DagNode* subject, Substitution& solution) const;
48   bool collect(ACU_Stack& stripped,  // destroyed
49 	       ACU_TreeDagNode* subject,
50 	       Substitution& solution) const;
51   void collapse(Substitution& solution) const;
52 
53 private:
54   //
55   //	The stripper variable/automaton/term in the derived class
56   //	strips off one argument.
57   //	The collector variable collects all the other arguments.
58   //
59   const int collectorVarIndex;
60   //
61   //	The collector sort must be unbounded. If it is the error sort
62   //	or the unique maximal sort of an error free component we set
63   //	it to 0 to switch off sort checks since they should always succeed.
64   //
65   const Sort* collectorSort;
66 };
67 
68 inline bool
collectorFree(Substitution & solution) const69 ACU_CollectorLhsAutomaton::collectorFree(Substitution& solution) const
70 {
71   return solution.value(collectorVarIndex) == 0;
72 }
73 
74 inline void
collapse(Substitution & solution) const75 ACU_CollectorLhsAutomaton::collapse(Substitution& solution) const
76 {
77   solution.bind(collectorVarIndex, getSymbol()->getIdentityDag());
78 }
79 
80 #endif
81