blob: 3b62b875a36201bcd577b653080a5b4512d882c4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/*******************************************************************************
* Copyright (c) 2009 Elliott Baron
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Elliott Baron - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.codan.extension;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.cdt.codan.extension.Minterm.Value;
import org.eclipse.cdt.core.dom.ast.IVariable;
public class ESSimplifier extends QuineMcCluskeySimplifier<IVariable> {
public ESSimplifier(ITruthTable<IVariable> tt) {
super(tt);
}
public Set<ExecutionState> getExecutionStateCover() {
Set<ExecutionState> ret = new HashSet<ExecutionState>();
List<Minterm<IVariable>> implicantCover = getImplicantCover();
for (Minterm<IVariable> term : implicantCover) {
ExecutionState es = new ExecutionState();
for (IVariable var : variables) {
Value val = term.getValue(var);
if (val == Value.TRUE) {
es.addClause(new ExecutionStateClause(var, true));
}
else if (val == Value.FALSE) {
es.addClause(new ExecutionStateClause(var, false));
}
// Don't care about Don't cares
}
ret.add(es);
}
return ret;
}
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
for (IVariable var : variables) {
buf.append(var.getName());
buf.append(" ");
}
buf.append("\n");
for (Minterm<IVariable> term : minterms) {
for (IVariable var : variables) {
switch (term.getValue(var)) {
case TRUE:
buf.append("1");
break;
case FALSE:
buf.append("0");
break;
default:
buf.append("-");
}
buf.append(" ");
}
buf.append("\n");
}
return buf.toString();
}
}
|