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 // Implementation for class RhsBuilder.
25 //
26
27 // utility stuff
28 #include "macros.hh"
29 #include "vector.hh"
30 #include "indent.hh"
31
32 // forward declarations
33 #include "interface.hh"
34 #include "core.hh"
35
36 // core class definitions
37 #include "rhsBuilder.hh"
38
~RhsBuilder()39 RhsBuilder::~RhsBuilder()
40 {
41 int nrAutomata = automata.length();
42 for (int i = 0; i < nrAutomata; i++)
43 delete automata[i];
44 delete lastAutomaton;
45 }
46
47 void
remapIndices(VariableInfo & variableInfo)48 RhsBuilder::remapIndices(VariableInfo& variableInfo)
49 {
50 int nrAutomata = automata.length();
51 for (int i = 0; i < nrAutomata; i++)
52 automata[i]->remapIndices(variableInfo);
53 if (lastAutomaton != 0)
54 lastAutomaton->remapIndices(variableInfo);
55 }
56
57 bool
recordInfo(StackMachineRhsCompiler & compiler)58 RhsBuilder::recordInfo(StackMachineRhsCompiler& compiler)
59 {
60 FOR_EACH_CONST(i, Vector<RhsAutomaton*>, automata)
61 {
62 if (!((*i)->recordInfo(compiler)))
63 return false;
64 }
65 return (lastAutomaton == 0) ? true : lastAutomaton->recordInfo(compiler);
66 }
67
68 #ifdef DUMP
69 void
dump(ostream & s,const VariableInfo & variableInfo,int indentLevel)70 RhsBuilder::dump(ostream& s, const VariableInfo& variableInfo, int indentLevel)
71 {
72 s << Indent(indentLevel) << "Begin{FreeRhsAutomaton}\n";
73 s << Indent(indentLevel + 1) << "automata:\n";
74 int nrAutomata = automata.length();
75 for (int i = 0; i < nrAutomata; i++)
76 automata[i]->dump(s, variableInfo, indentLevel + 2);
77 s << Indent(indentLevel + 1) << "lastAutomata:\n";
78 lastAutomaton->dump(s, variableInfo, indentLevel + 2);
79 s << Indent(indentLevel) << "End{FreeRhsAutomaton}\n";
80 }
81 #endif
82