|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.qedeq.kernel.bo.control; |
|
19 |
| |
|
20 |
| import org.qedeq.kernel.base.module.Axiom; |
|
21 |
| import org.qedeq.kernel.base.module.Formula; |
|
22 |
| import org.qedeq.kernel.base.module.FunctionDefinition; |
|
23 |
| import org.qedeq.kernel.base.module.PredicateDefinition; |
|
24 |
| import org.qedeq.kernel.base.module.Proposition; |
|
25 |
| import org.qedeq.kernel.base.module.Qedeq; |
|
26 |
| import org.qedeq.kernel.base.module.Rule; |
|
27 |
| import org.qedeq.kernel.base.module.Term; |
|
28 |
| import org.qedeq.kernel.bo.logic.ExistenceChecker; |
|
29 |
| import org.qedeq.kernel.bo.logic.FormulaChecker; |
|
30 |
| import org.qedeq.kernel.bo.logic.Function; |
|
31 |
| import org.qedeq.kernel.bo.logic.Predicate; |
|
32 |
| import org.qedeq.kernel.bo.module.IllegalModuleDataException; |
|
33 |
| import org.qedeq.kernel.bo.module.LogicalState; |
|
34 |
| import org.qedeq.kernel.bo.module.ModuleContext; |
|
35 |
| import org.qedeq.kernel.bo.module.ModuleDataException; |
|
36 |
| import org.qedeq.kernel.bo.module.ModuleProperties; |
|
37 |
| import org.qedeq.kernel.bo.module.ModuleReferenceList; |
|
38 |
| import org.qedeq.kernel.bo.visitor.AbstractModuleVisitor; |
|
39 |
| import org.qedeq.kernel.bo.visitor.QedeqNotNullTraverser; |
|
40 |
| import org.qedeq.kernel.common.SourceFileExceptionList; |
|
41 |
| import org.qedeq.kernel.log.ModuleEventLog; |
|
42 |
| import org.qedeq.kernel.trace.Trace; |
|
43 |
| import org.qedeq.kernel.xml.mapper.ModuleDataException2XmlFileException; |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| public final class QedeqBoFormalLogicChecker extends AbstractModuleVisitor { |
|
53 |
| |
|
54 |
| |
|
55 |
| private static final Class CLASS = QedeqBoFormalLogicChecker.class; |
|
56 |
| |
|
57 |
| |
|
58 |
| private final ModuleProperties prop; |
|
59 |
| |
|
60 |
| |
|
61 |
| private final QedeqNotNullTraverser traverser; |
|
62 |
| |
|
63 |
| |
|
64 |
| private ModuleConstantsExistenceChecker existence; |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
59
| private QedeqBoFormalLogicChecker(final ModuleProperties prop) {
|
|
72 |
59
| this.traverser = new QedeqNotNullTraverser(prop.getModuleAddress(), this);
|
|
73 |
59
| this.prop = prop;
|
|
74 |
| } |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
99
| public static void check(final ModuleProperties prop)
|
|
83 |
| throws SourceFileExceptionList { |
|
84 |
99
| if (prop.isChecked()) {
|
|
85 |
40
| return;
|
|
86 |
| } |
|
87 |
59
| if (!prop.hasLoadedRequiredModules()) {
|
|
88 |
0
| throw new IllegalStateException("QEDEQ module has not loaded with required files: "
|
|
89 |
| + prop); |
|
90 |
| } |
|
91 |
59
| prop.setLogicalProgressState(LogicalState.STATE_EXTERNAL_CHECKING);
|
|
92 |
59
| ModuleEventLog.getInstance().stateChanged(prop);
|
|
93 |
59
| ModuleReferenceList list = prop.getRequiredModules();
|
|
94 |
59
| for (int i = 0; i < list.size(); i++) {
|
|
95 |
38
| try {
|
|
96 |
38
| Trace.trace(CLASS, "check(ModuleProperties)", "checking label",
|
|
97 |
| list.getLabel(i)); |
|
98 |
38
| check(list.getModuleProperties(i));
|
|
99 |
| } catch (SourceFileExceptionList e) { |
|
100 |
0
| ModuleDataException md = new CheckRequiredModuleException(11231,
|
|
101 |
| "import check failed: " + list.getModuleProperties(i).getModuleAddress(), |
|
102 |
| list.getModuleContext(i)); |
|
103 |
0
| final SourceFileExceptionList sfl =
|
|
104 |
| ModuleDataException2XmlFileException.createXmlFileExceptionList(md, |
|
105 |
| prop.getModule().getQedeq()); |
|
106 |
0
| prop.setLogicalFailureState(LogicalState.STATE_EXTERNAL_CHECKING_FAILED, sfl);
|
|
107 |
0
| ModuleEventLog.getInstance().stateChanged(prop);
|
|
108 |
0
| throw e;
|
|
109 |
| } |
|
110 |
| } |
|
111 |
59
| prop.setLogicalProgressState(LogicalState.STATE_INTERNAL_CHECKING);
|
|
112 |
59
| ModuleEventLog.getInstance().stateChanged(prop);
|
|
113 |
59
| final QedeqBoFormalLogicChecker checker = new QedeqBoFormalLogicChecker(prop);
|
|
114 |
59
| try {
|
|
115 |
59
| checker.check();
|
|
116 |
| } catch (ModuleDataException e) { |
|
117 |
21
| final SourceFileExceptionList sfl =
|
|
118 |
| ModuleDataException2XmlFileException.createXmlFileExceptionList(e, |
|
119 |
| prop.getModule().getQedeq()); |
|
120 |
21
| prop.setLogicalFailureState(LogicalState.STATE_INTERNAL_CHECKING_FAILED, sfl);
|
|
121 |
21
| ModuleEventLog.getInstance().stateChanged(prop);
|
|
122 |
21
| throw sfl;
|
|
123 |
| } |
|
124 |
38
| prop.setChecked(checker.existence);
|
|
125 |
38
| ModuleEventLog.getInstance().stateChanged(prop);
|
|
126 |
| } |
|
127 |
| |
|
128 |
59
| private void check() throws ModuleDataException {
|
|
129 |
59
| this.existence = new ModuleConstantsExistenceChecker(prop);
|
|
130 |
59
| traverser.accept(prop.getModule().getQedeq());
|
|
131 |
| } |
|
132 |
| |
|
133 |
181
| public void visitEnter(final Axiom axiom) throws ModuleDataException {
|
|
134 |
181
| if (axiom == null) {
|
|
135 |
0
| return;
|
|
136 |
| } |
|
137 |
181
| final String context = getCurrentContext().getLocationWithinModule();
|
|
138 |
181
| if (axiom.getFormula() != null) {
|
|
139 |
181
| setLocationWithinModule(context + ".getFormula().getElement()");
|
|
140 |
181
| final Formula formula = axiom.getFormula();
|
|
141 |
181
| FormulaChecker.checkFormula(formula.getElement(), getCurrentContext(), existence);
|
|
142 |
| } |
|
143 |
168
| setLocationWithinModule(context);
|
|
144 |
168
| traverser.setBlocked(true);
|
|
145 |
| } |
|
146 |
| |
|
147 |
168
| public void visitLeave(final Axiom axiom) {
|
|
148 |
168
| traverser.setBlocked(false);
|
|
149 |
| } |
|
150 |
| |
|
151 |
164
| public void visitEnter(final PredicateDefinition definition)
|
|
152 |
| throws ModuleDataException { |
|
153 |
164
| if (definition == null) {
|
|
154 |
0
| return;
|
|
155 |
| } |
|
156 |
164
| final String context = getCurrentContext().getLocationWithinModule();
|
|
157 |
164
| final Predicate predicate = new Predicate(definition.getName(),
|
|
158 |
| definition.getArgumentNumber()); |
|
159 |
164
| if (existence.predicateExists(predicate)) {
|
|
160 |
0
| throw new IllegalModuleDataException(HigherLogicalErrors.PREDICATE_ALREADY_DEFINED,
|
|
161 |
| HigherLogicalErrors.PREDICATE_ALREADY_DEFINED_TEXT + predicate, |
|
162 |
| getCurrentContext()); |
|
163 |
| } |
|
164 |
164
| if ("2".equals(predicate.getArguments())
|
|
165 |
| && ExistenceChecker.NAME_EQUAL.equals(predicate.getName())) { |
|
166 |
13
| existence.setIdentityOperatorDefined(true, predicate.getName());
|
|
167 |
| } |
|
168 |
164
| if (definition.getFormula() != null) {
|
|
169 |
129
| setLocationWithinModule(context + ".getFormula().getElement()");
|
|
170 |
129
| final Formula formula = definition.getFormula();
|
|
171 |
129
| FormulaChecker.checkFormula(formula.getElement(), getCurrentContext(), existence);
|
|
172 |
| } |
|
173 |
164
| existence.add(definition);
|
|
174 |
164
| setLocationWithinModule(context);
|
|
175 |
164
| traverser.setBlocked(true);
|
|
176 |
| } |
|
177 |
| |
|
178 |
164
| public void visitLeave(final PredicateDefinition definition) {
|
|
179 |
164
| traverser.setBlocked(false);
|
|
180 |
| } |
|
181 |
| |
|
182 |
96
| public void visitEnter(final FunctionDefinition definition)
|
|
183 |
| throws ModuleDataException { |
|
184 |
96
| if (definition == null) {
|
|
185 |
0
| return;
|
|
186 |
| } |
|
187 |
96
| final String context = getCurrentContext().getLocationWithinModule();
|
|
188 |
96
| final Function function = new Function(definition.getName(),
|
|
189 |
| definition.getArgumentNumber()); |
|
190 |
96
| if (existence.functionExists(function)) {
|
|
191 |
0
| throw new IllegalModuleDataException(HigherLogicalErrors.FUNCTION_ALREADY_DEFINED,
|
|
192 |
| HigherLogicalErrors.FUNCTION_ALREADY_DEFINED_TEXT + function, |
|
193 |
| getCurrentContext()); |
|
194 |
| } |
|
195 |
96
| if (definition.getTerm() != null) {
|
|
196 |
96
| setLocationWithinModule(context + ".getTerm().getElement()");
|
|
197 |
96
| final Term term = definition.getTerm();
|
|
198 |
96
| FormulaChecker.checkTerm(term.getElement(), getCurrentContext(), existence);
|
|
199 |
| } |
|
200 |
96
| existence.add(definition);
|
|
201 |
96
| setLocationWithinModule(context);
|
|
202 |
96
| traverser.setBlocked(true);
|
|
203 |
| } |
|
204 |
| |
|
205 |
96
| public void visitLeave(final FunctionDefinition definition) {
|
|
206 |
96
| traverser.setBlocked(false);
|
|
207 |
| } |
|
208 |
| |
|
209 |
374
| public void visitEnter(final Proposition proposition)
|
|
210 |
| throws ModuleDataException { |
|
211 |
374
| if (proposition == null) {
|
|
212 |
0
| return;
|
|
213 |
| } |
|
214 |
374
| final String context = getCurrentContext().getLocationWithinModule();
|
|
215 |
374
| if (proposition.getFormula() != null) {
|
|
216 |
374
| setLocationWithinModule(context + ".getFormula().getElement()");
|
|
217 |
374
| final Formula formula = proposition.getFormula();
|
|
218 |
374
| FormulaChecker.checkFormula(formula.getElement(), getCurrentContext(), existence);
|
|
219 |
| } |
|
220 |
366
| setLocationWithinModule(context);
|
|
221 |
366
| traverser.setBlocked(true);
|
|
222 |
| } |
|
223 |
| |
|
224 |
366
| public void visitLeave(final Proposition definition) {
|
|
225 |
366
| traverser.setBlocked(false);
|
|
226 |
| } |
|
227 |
| |
|
228 |
114
| public void visitEnter(final Rule rule) throws ModuleDataException {
|
|
229 |
114
| if (rule == null) {
|
|
230 |
0
| return;
|
|
231 |
| } |
|
232 |
114
| if (rule.getName() != null) {
|
|
233 |
114
| if ("SET_DEFINION_BY_FORMULA".equals(rule.getName())) {
|
|
234 |
| |
|
235 |
6
| existence.setClassOperatorExists(true);
|
|
236 |
| } |
|
237 |
| } |
|
238 |
114
| traverser.setBlocked(true);
|
|
239 |
| } |
|
240 |
| |
|
241 |
114
| public void visitLeave(final Rule rule) {
|
|
242 |
114
| traverser.setBlocked(false);
|
|
243 |
| } |
|
244 |
| |
|
245 |
| |
|
246 |
| |
|
247 |
| |
|
248 |
| |
|
249 |
| |
|
250 |
1574
| public void setLocationWithinModule(final String locationWithinModule) {
|
|
251 |
1574
| getCurrentContext().setLocationWithinModule(locationWithinModule);
|
|
252 |
| } |
|
253 |
| |
|
254 |
| |
|
255 |
| |
|
256 |
| |
|
257 |
| |
|
258 |
| |
|
259 |
3169
| public final ModuleContext getCurrentContext() {
|
|
260 |
3169
| return traverser.getCurrentContext();
|
|
261 |
| } |
|
262 |
| |
|
263 |
| |
|
264 |
| |
|
265 |
| |
|
266 |
| |
|
267 |
| |
|
268 |
0
| protected final Qedeq getQedeqOriginal() {
|
|
269 |
0
| return prop.getModule().getQedeq();
|
|
270 |
| } |
|
271 |
| |
|
272 |
| } |