1 /*
2
3 This file is part of the Maude 2 interpreter.
4
5 Copyright 1997-2006 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 abstract class Strategy.
25 //
26
27 // utility stuff
28 #include "macros.hh"
29 #include "vector.hh"
30
31 // forward declarations
32 #include "interface.hh"
33 #include "core.hh"
34 #include "strategyLanguage.hh"
35
36 // interface class definitions
37 #include "term.hh"
38
39 // strategy language class definitions
40 #include "strategicSearch.hh"
41 #include "applicationStrategy.hh"
42 #include "applicationProcess.hh"
43 #include "decompositionProcess.hh"
44
ApplicationStrategy(int label,const Vector<Term * > & variables,const Vector<Term * > & values,const Vector<StrategyExpression * > & strategies)45 ApplicationStrategy::ApplicationStrategy(int label,
46 const Vector<Term*>& variables,
47 const Vector<Term*>& values,
48 const Vector<StrategyExpression*>& strategies)
49 : label(label),
50 variables(variables),
51 valueDags(values.size()),
52 strategies(strategies)
53 {
54 Assert(label != NONE || (variables.empty() && strategies.empty()),
55 "substitutions and condition strategies aren't allowed without a label");
56 top = false;
57 int nrValues = values.size();
58 Assert(variables.size() == nrValues, "bad substitution");
59 for (int i = 0; i < nrValues; ++i)
60 {
61 valueDags[i].setTerm(values[i]);
62 valueDags[i].normalize();
63 valueDags[i].prepare();
64 }
65 }
66
~ApplicationStrategy()67 ApplicationStrategy::~ApplicationStrategy()
68 {
69 int nrVariables = variables.size();
70 for (int i = 0; i < nrVariables; ++i)
71 variables[i]->deepSelfDestruct();
72 int nrStrategies = strategies.size();
73 for (int i = 0; i < nrStrategies; ++i)
74 delete strategies[i];
75 }
76
77 StrategicExecution::Survival
decompose(StrategicSearch & searchObject,DecompositionProcess * remainder)78 ApplicationStrategy::decompose(StrategicSearch& searchObject, DecompositionProcess* remainder)
79 {
80 (void) new ApplicationProcess(searchObject,
81 remainder->getDagIndex(),
82 this,
83 remainder->getPending(),
84 remainder, // working for same task
85 remainder); // place in process queue ahead of old process
86 return StrategicExecution::DIE; // request deletion of DecompositionProcess
87 }
88