Initial import
[jpf-core.git] / src / main / gov / nasa / jpf / search / PathSearch.java
1 /*
2  * Copyright (C) 2014, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The Java Pathfinder core (jpf-core) platform is licensed under the
7  * Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  * 
10  *        http://www.apache.org/licenses/LICENSE-2.0. 
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and 
16  * limitations under the License.
17  */
18 package gov.nasa.jpf.search;
19
20 import gov.nasa.jpf.Config;
21 import gov.nasa.jpf.vm.VM;
22
23
24 /**
25  * PathSearch is not really a Search object, just a simple 'forward'
26  * driver for the VM that loops until there is no next instruction or
27  * a property doesn't hold
28  * 
29  */
30 public class PathSearch extends Search {
31         
32   public PathSearch (Config config, VM vm) {
33     super(config,vm);    
34   }
35   
36   @Override
37   public boolean requestBacktrack () {
38     doBacktrack = true;
39
40     return true;
41   }
42
43   @Override
44   public void search () {
45     depth++;
46
47     if (hasPropertyTermination()) {
48       return;
49     }
50
51     notifySearchStarted();
52
53     while (true) {
54       while (doBacktrack) { // might be set by StateListeners
55
56         if (depth > 0) {
57           vm.backtrack();
58           depth--;
59
60           notifyStateBacktracked();
61         }
62
63         doBacktrack = false;
64       }
65
66       forward();
67       // isVisitedState is never true, because we don't really search, just replay
68       notifyStateAdvanced();
69
70       if (currentError != null){
71         notifyPropertyViolated();
72
73         if (hasPropertyTermination()) {
74           break;
75         }
76       }
77
78       if (isEndState()) {
79         break;
80       }
81
82       depth++;
83     }
84
85     notifySearchFinished();
86   }
87
88   @Override
89   public boolean supportsBacktrack () {
90     return true;
91   }
92 }