1
2 package eu.simuline.relana.parser;
3
4 import eu.simuline.relana.model.ClassLocator;
5 import eu.simuline.relana.model.SClass;
6 import eu.simuline.relana.model.Deficiency;
7 import eu.simuline.relana.model.DeficiencyNode;
8 import eu.simuline.relana.model.SClassLoader;
9 import eu.simuline.relana.model.Package;
10
11 import java.util.Map;
12 import java.util.HashMap;
13 import java.util.Set;
14 import java.util.HashSet;
15 import java.util.Iterator;
16 import java.util.Collections;
17
18 import java.io.Reader;
19 import java.io.IOException;
20 import java.io.InputStream;
21
22 import org.antlr.v4.runtime.atn.*;
23 import org.antlr.v4.runtime.dfa.DFA;
24 import org.antlr.v4.runtime.*;
25 import org.antlr.v4.runtime.misc.*;
26 import org.antlr.v4.runtime.tree.*;
27 import java.util.List;
28 import java.util.Iterator;
29 import java.util.ArrayList;
30
31 @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
32 public class SClassParser extends Parser {
33 static { RuntimeMetaData.checkVersion("4.7", RuntimeMetaData.VERSION); }
34
35 protected static final DFA[] _decisionToDFA;
36 protected static final PredictionContextCache _sharedContextCache =
37 new PredictionContextCache();
38 public static final int
39 T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, WS=6, SingleLineComment=7, MultiLineComment=8,
40 PACKAGE=9, SCLASS=10, EXTENDS=11, PROPERTIES=12, MAP=13, REPLACE=14, RELATIONS=15,
41 IMPLIES=16, END=17, SEP=18, NAME=19;
42 public static final int
43 RULE_sClass = 0, RULE_getPath = 1, RULE_addPath = 2, RULE_getSuperClass = 3,
44 RULE_getDeficiencies = 4, RULE_addDeficiency = 5, RULE_getInnerCls = 6,
45 RULE_addMap = 7, RULE_getCheckedDeficiencies = 8, RULE_addRelations = 9,
46 RULE_addRelation = 10;
47 public static final String[] ruleNames = {
48 "sClass", "getPath", "addPath", "getSuperClass", "getDeficiencies", "addDeficiency",
49 "getInnerCls", "addMap", "getCheckedDeficiencies", "addRelations", "addRelation"
50 };
51
52 private static final String[] _LITERAL_NAMES = {
53 null, "'{'", "'}'", "'['", "','", "']'", null, null, null, "'package'",
54 "'sclass'", "'extends'", "'properties'", "'map'", "'replace'", "'relations'",
55 "'==>'", "';'", "'.'"
56 };
57 private static final String[] _SYMBOLIC_NAMES = {
58 null, null, null, null, null, null, "WS", "SingleLineComment", "MultiLineComment",
59 "PACKAGE", "SCLASS", "EXTENDS", "PROPERTIES", "MAP", "REPLACE", "RELATIONS",
60 "IMPLIES", "END", "SEP", "NAME"
61 };
62 public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
63
64
65
66
67 @Deprecated
68 public static final String[] tokenNames;
69 static {
70 tokenNames = new String[_SYMBOLIC_NAMES.length];
71 for (int i = 0; i < tokenNames.length; i++) {
72 tokenNames[i] = VOCABULARY.getLiteralName(i);
73 if (tokenNames[i] == null) {
74 tokenNames[i] = VOCABULARY.getSymbolicName(i);
75 }
76
77 if (tokenNames[i] == null) {
78 tokenNames[i] = "<INVALID>";
79 }
80 }
81 }
82
83 @Override
84 @Deprecated
85 public String[] getTokenNames() {
86 return tokenNames;
87 }
88
89 @Override
90
91 public Vocabulary getVocabulary() {
92 return VOCABULARY;
93 }
94
95 @Override
96 public String getGrammarFileName() { return "SClass.g4"; }
97
98 @Override
99 public String[] getRuleNames() { return ruleNames; }
100
101 @Override
102 public String getSerializedATN() { return _serializedATN; }
103
104 @Override
105 public ATN getATN() { return _ATN; }
106
107
108
109
110
111
112
113 private SClassLoader classLoader;
114 private ClassLocator loc;
115 private Map<ClassLocator,ClassLocator> subclassDep;
116
117
118
119
120
121 private static CommonTokenStream inputStream2tokenStream(InputStream str)
122 throws IOException {
123 CharStream input = CharStreams.fromStream(str);
124 SClassLexer lexer = new SClassLexer(input);
125 return new CommonTokenStream(lexer);
126 }
127
128 public SClassParser(InputStream str) throws IOException {
129 this(inputStream2tokenStream(str));
130 }
131
132
133
134
135
136
137
138
139
140
141
142
143 void report(String msg) throws RuntimeException {
144 System.out.print("[" + loc + "] ");
145
146 RuntimeException pe = new RuntimeException(msg);
147
148 throw pe;
149 }
150
151
152
153
154
155
156
157
158
159
160 public void setClassLoader(SClassLoader classLoader) {
161 this.classLoader = classLoader;
162 }
163
164 public SClass getSClass(ClassLocator loc,
165 Map<ClassLocator,ClassLocator> subclassDep) {
166 return sClass(loc,subclassDep).res;
167 }
168
169
170
171
172
173
174
175
176
177
178
179 private void checkDependencies(ClassLocator needed)
180 throws RuntimeException {
181
182 ClassLocator needs = this.subclassDep.get(needed);
183 if (needs != null) {
184
185 List<ClassLocator> trace = new ArrayList<ClassLocator>();
186 ClassLocator stop = needed;
187 while (needs != null && !needs.equals(stop)) {
188 trace.add(needed);
189 needed = needs;
190 needs = this.subclassDep.get(needed);
191 }
192 report("Cyclic subclass-dependency: trace \"" + trace + "\". ");
193 }
194
195 this.subclassDep.put(needed, this.loc);
196 }
197
198
199 public SClassParser(TokenStream input) {
200 super(input);
201 _interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
202 }
203 public static class SClassContext extends ParserRuleContext {
204 public ClassLocator loc;
205 public Map<ClassLocator,ClassLocator> subclassDep;
206 public SClass res;
207 public GetPathContext pkgPathC;
208 public Token sClassName;
209 public GetSuperClassContext superclassC;
210 public GetDeficienciesContext deficiency2orderingC;
211 public GetInnerClsContext old2innerClsC;
212 public TerminalNode PACKAGE() { return getToken(SClassParser.PACKAGE, 0); }
213 public TerminalNode END() { return getToken(SClassParser.END, 0); }
214 public TerminalNode SCLASS() { return getToken(SClassParser.SCLASS, 0); }
215 public AddRelationsContext addRelations() {
216 return getRuleContext(AddRelationsContext.class,0);
217 }
218 public TerminalNode EOF() { return getToken(SClassParser.EOF, 0); }
219 public GetPathContext getPath() {
220 return getRuleContext(GetPathContext.class,0);
221 }
222 public TerminalNode NAME() { return getToken(SClassParser.NAME, 0); }
223 public GetSuperClassContext getSuperClass() {
224 return getRuleContext(GetSuperClassContext.class,0);
225 }
226 public GetDeficienciesContext getDeficiencies() {
227 return getRuleContext(GetDeficienciesContext.class,0);
228 }
229 public GetInnerClsContext getInnerCls() {
230 return getRuleContext(GetInnerClsContext.class,0);
231 }
232 public SClassContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); }
233 public SClassContext(ParserRuleContext parent, int invokingState, ClassLocator loc, Map<ClassLocator,ClassLocator> subclassDep) {
234 super(parent, invokingState);
235 this.loc = loc;
236 this.subclassDep = subclassDep;
237 }
238 @Override public int getRuleIndex() { return RULE_sClass; }
239 @Override
240 public void enterRule(ParseTreeListener listener) {
241 if ( listener instanceof SClassListener ) ((SClassListener)listener).enterSClass(this);
242 }
243 @Override
244 public void exitRule(ParseTreeListener listener) {
245 if ( listener instanceof SClassListener ) ((SClassListener)listener).exitSClass(this);
246 }
247 }
248
249 public final SClassContext sClass(ClassLocator loc,Map<ClassLocator,ClassLocator> subclassDep) throws RecognitionException {
250 SClassContext _localctx = new SClassContext(_ctx, getState(), loc, subclassDep);
251 enterRule(_localctx, 0, RULE_sClass);
252
253 this.loc = loc;
254 this.subclassDep = subclassDep;
255 Map<List<String>,SClass> paths2innerCls =
256 new HashMap<List<String>,SClass>();
257 List<String> pkgPath;
258 SClass superclass;
259 Map<Deficiency,DeficiencyNode> deficiency2ordering;
260 Map<Deficiency,SClass> old2innerCls;
261
262 try {
263 enterOuterAlt(_localctx, 1);
264 {
265 {
266 setState(22);
267 match(PACKAGE);
268 setState(23);
269 ((SClassContext)_localctx).pkgPathC = getPath();
270 setState(24);
271 match(END);
272
273 pkgPath = ((GetPathContext)
274 ((SClassContext)_localctx).pkgPathC).res;
275
276 setState(26);
277 match(SCLASS);
278 setState(27);
279 ((SClassContext)_localctx).sClassName = match(NAME);
280 setState(28);
281 ((SClassContext)_localctx).superclassC = getSuperClass(paths2innerCls);
282 setState(29);
283 match(T__0);
284 setState(30);
285 ((SClassContext)_localctx).deficiency2orderingC = getDeficiencies();
286
287 superclass = ((GetSuperClassContext)
288 ((SClassContext)_localctx).superclassC).res;
289 deficiency2ordering = ((GetDeficienciesContext)
290 ((SClassContext)_localctx).deficiency2orderingC)
291 .deficiency2ordering;
292
293 setState(32);
294 ((SClassContext)_localctx).old2innerClsC = getInnerCls(superclass,
295 new HashSet<Deficiency>(deficiency2ordering.keySet()));
296
297 old2innerCls = ((GetInnerClsContext)
298 ((SClassContext)_localctx).old2innerClsC)
299 .old2innerCls;
300
301 setState(34);
302 addRelations(deficiency2ordering);
303 setState(35);
304 match(T__1);
305 setState(36);
306 match(EOF);
307 }
308
309
310 if (!this.loc.getPackage().getPath().equals(pkgPath)) {
311 report("Expected Package \""
312 + this.loc.getPackage().getPathName()
313 + "\" but found: \""
314 + Package.getPackage(pkgPath).getPathName() + "\". ");
315 }
316
317 if (!this.loc.getName().equals((((SClassContext)_localctx).sClassName!=null?((SClassContext)_localctx).sClassName.getText():null))) {
318 report("Expected Class \"" + this.loc.getName() +
319 "\" but found: \"" + (((SClassContext)_localctx).sClassName!=null?((SClassContext)_localctx).sClassName.getText():null) + "\". ");
320 }
321
322
323
324
325
326
327
328 ((SClassContext)_localctx).res = SClass.getSClass(this.loc.getName(),
329 this.loc.getPackage(),
330 superclass,
331 old2innerCls,
332 deficiency2ordering);
333
334 }
335 }
336 catch (RecognitionException re) {
337 _localctx.exception = re;
338 _errHandler.reportError(this, re);
339 _errHandler.recover(this, re);
340 }
341 finally {
342 exitRule();
343 }
344 return _localctx;
345 }
346
347 public static class GetPathContext extends ParserRuleContext {
348 public List<String> res;
349 public Token first;
350 public Token next;
351 public List<TerminalNode> NAME() { return getTokens(SClassParser.NAME); }
352 public TerminalNode NAME(int i) {
353 return getToken(SClassParser.NAME, i);
354 }
355 public List<TerminalNode> SEP() { return getTokens(SClassParser.SEP); }
356 public TerminalNode SEP(int i) {
357 return getToken(SClassParser.SEP, i);
358 }
359 public GetPathContext(ParserRuleContext parent, int invokingState) {
360 super(parent, invokingState);
361 }
362 @Override public int getRuleIndex() { return RULE_getPath; }
363 @Override
364 public void enterRule(ParseTreeListener listener) {
365 if ( listener instanceof SClassListener ) ((SClassListener)listener).enterGetPath(this);
366 }
367 @Override
368 public void exitRule(ParseTreeListener listener) {
369 if ( listener instanceof SClassListener ) ((SClassListener)listener).exitGetPath(this);
370 }
371 }
372
373 public final GetPathContext getPath() throws RecognitionException {
374 GetPathContext _localctx = new GetPathContext(_ctx, getState());
375 enterRule(_localctx, 2, RULE_getPath);
376 List<String> res0 = new ArrayList<String>();
377 int _la;
378 try {
379 enterOuterAlt(_localctx, 1);
380 {
381 setState(40);
382 ((GetPathContext)_localctx).first = match(NAME);
383 res0.add((((GetPathContext)_localctx).first!=null?((GetPathContext)_localctx).first.getText():null));
384 setState(47);
385 _errHandler.sync(this);
386 _la = _input.LA(1);
387 while (_la==SEP) {
388 {
389 {
390 setState(42);
391 match(SEP);
392 setState(43);
393 ((GetPathContext)_localctx).next = match(NAME);
394 res0.add( (((GetPathContext)_localctx).next!=null?((GetPathContext)_localctx).next.getText():null));
395 }
396 }
397 setState(49);
398 _errHandler.sync(this);
399 _la = _input.LA(1);
400 }
401 }
402 _ctx.stop = _input.LT(-1);
403 ((GetPathContext)_localctx).res = Collections.unmodifiableList(res0);
404 }
405 catch (RecognitionException re) {
406 _localctx.exception = re;
407 _errHandler.reportError(this, re);
408 _errHandler.recover(this, re);
409 }
410 finally {
411 exitRule();
412 }
413 return _localctx;
414 }
415
416 public static class AddPathContext extends ParserRuleContext {
417 public Set<List<String>> innerPaths;
418 public GetPathContext pkgPathC;
419 public GetPathContext getPath() {
420 return getRuleContext(GetPathContext.class,0);
421 }
422 public AddPathContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); }
423 public AddPathContext(ParserRuleContext parent, int invokingState, Set<List<String>> innerPaths) {
424 super(parent, invokingState);
425 this.innerPaths = innerPaths;
426 }
427 @Override public int getRuleIndex() { return RULE_addPath; }
428 @Override
429 public void enterRule(ParseTreeListener listener) {
430 if ( listener instanceof SClassListener ) ((SClassListener)listener).enterAddPath(this);
431 }
432 @Override
433 public void exitRule(ParseTreeListener listener) {
434 if ( listener instanceof SClassListener ) ((SClassListener)listener).exitAddPath(this);
435 }
436 }
437
438 public final AddPathContext addPath(Set<List<String>> innerPaths) throws RecognitionException {
439 AddPathContext _localctx = new AddPathContext(_ctx, getState(), innerPaths);
440 enterRule(_localctx, 4, RULE_addPath);
441 try {
442 enterOuterAlt(_localctx, 1);
443 {
444 setState(50);
445 ((AddPathContext)_localctx).pkgPathC = getPath();
446
447 List<String> path = ((GetPathContext)
448 ((AddPathContext)_localctx).pkgPathC).res;
449 _localctx.innerPaths.add(path);
450
451 }
452 }
453 catch (RecognitionException re) {
454 _localctx.exception = re;
455 _errHandler.reportError(this, re);
456 _errHandler.recover(this, re);
457 }
458 finally {
459 exitRule();
460 }
461 return _localctx;
462 }
463
464 public static class GetSuperClassContext extends ParserRuleContext {
465 public Map<List<String>,SClass > paths2innerCls;
466 public SClass res;
467 public GetPathContext superPathC;
468 public TerminalNode EXTENDS() { return getToken(SClassParser.EXTENDS, 0); }
469 public GetPathContext getPath() {
470 return getRuleContext(GetPathContext.class,0);
471 }
472 public List<AddPathContext> addPath() {
473 return getRuleContexts(AddPathContext.class);
474 }
475 public AddPathContext addPath(int i) {
476 return getRuleContext(AddPathContext.class,i);
477 }
478 public GetSuperClassContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); }
479 public GetSuperClassContext(ParserRuleContext parent, int invokingState, Map<List<String>,SClass > paths2innerCls) {
480 super(parent, invokingState);
481 this.paths2innerCls = paths2innerCls;
482 }
483 @Override public int getRuleIndex() { return RULE_getSuperClass; }
484 @Override
485 public void enterRule(ParseTreeListener listener) {
486 if ( listener instanceof SClassListener ) ((SClassListener)listener).enterGetSuperClass(this);
487 }
488 @Override
489 public void exitRule(ParseTreeListener listener) {
490 if ( listener instanceof SClassListener ) ((SClassListener)listener).exitGetSuperClass(this);
491 }
492 }
493
494 public final GetSuperClassContext getSuperClass(Map<List<String>,SClass > paths2innerCls) throws RecognitionException {
495 GetSuperClassContext _localctx = new GetSuperClassContext(_ctx, getState(), paths2innerCls);
496 enterRule(_localctx, 6, RULE_getSuperClass);
497
498
499 ClassLocator needed;
500 Set<List<String> > innerPaths = new HashSet<List<String> >();
501 List<String> superPath = null;
502
503 int _la;
504 try {
505 enterOuterAlt(_localctx, 1);
506 {
507 setState(69);
508 _errHandler.sync(this);
509 _la = _input.LA(1);
510 if (_la==EXTENDS) {
511 {
512 setState(53);
513 match(EXTENDS);
514 setState(54);
515 ((GetSuperClassContext)_localctx).superPathC = getPath();
516
517 superPath = ((GetPathContext)
518 ((GetSuperClassContext)_localctx).superPathC).res;
519
520
521 setState(67);
522 _errHandler.sync(this);
523 _la = _input.LA(1);
524 if (_la==T__2) {
525 {
526 setState(56);
527 match(T__2);
528 setState(57);
529 addPath(innerPaths);
530 setState(62);
531 _errHandler.sync(this);
532 _la = _input.LA(1);
533 while (_la==T__3) {
534 {
535 {
536 setState(58);
537 match(T__3);
538 setState(59);
539 addPath(innerPaths);
540 }
541 }
542 setState(64);
543 _errHandler.sync(this);
544 _la = _input.LA(1);
545 }
546 setState(65);
547 match(T__4);
548 }
549 }
550
551 }
552 }
553
554
555 if (superPath == null) {
556
557 ((GetSuperClassContext)_localctx).res = SClass.BOOLEAN;
558 return _localctx;
559 }
560
561
562 if (superPath.size() == 1 &&
563 (superPath.get(0).equals(SClass.BOOLEAN.getName()))) {
564
565 ((GetSuperClassContext)_localctx).res = SClass.BOOLEAN;
566 return _localctx;
567 }
568
569
570
571
572 try {
573 for (List<String> innerPath : innerPaths) {
574 needed = ClassLocator.getLocator(superPath);
575 checkDependencies(needed);
576 paths2innerCls.put(innerPath,
577 this.classLoader
578 .loadSClass(needed,
579 this.loc.getPackage(),
580 this.subclassDep));
581
582 }
583 } catch(IOException ioe) {
584 throw new IllegalStateException
585 ("Thrown exception while loading class: \"" +
586 ioe + "\". ");
587 }
588
589 needed = ClassLocator.getLocator(superPath);
590 checkDependencies(needed);
591
592 try {
593 ((GetSuperClassContext)_localctx).res = this.classLoader.loadSClass(needed,
594 this.loc.getPackage(),
595 this.subclassDep);
596 } catch(IOException ioe) {
597 ((GetSuperClassContext)_localctx).res = null;
598 throw new IllegalStateException
599 ("Thrown exception while loading class: \"" +
600 ioe + "\". ");
601 }
602
603 }
604 }
605 catch (RecognitionException re) {
606 _localctx.exception = re;
607 _errHandler.reportError(this, re);
608 _errHandler.recover(this, re);
609 }
610 finally {
611 exitRule();
612 }
613 return _localctx;
614 }
615
616 public static class GetDeficienciesContext extends ParserRuleContext {
617 public Map<Deficiency,DeficiencyNode> deficiency2ordering;
618 public TerminalNode PROPERTIES() { return getToken(SClassParser.PROPERTIES, 0); }
619 public List<AddDeficiencyContext> addDeficiency() {
620 return getRuleContexts(AddDeficiencyContext.class);
621 }
622 public AddDeficiencyContext addDeficiency(int i) {
623 return getRuleContext(AddDeficiencyContext.class,i);
624 }
625 public GetDeficienciesContext(ParserRuleContext parent, int invokingState) {
626 super(parent, invokingState);
627 }
628 @Override public int getRuleIndex() { return RULE_getDeficiencies; }
629 @Override
630 public void enterRule(ParseTreeListener listener) {
631 if ( listener instanceof SClassListener ) ((SClassListener)listener).enterGetDeficiencies(this);
632 }
633 @Override
634 public void exitRule(ParseTreeListener listener) {
635 if ( listener instanceof SClassListener ) ((SClassListener)listener).exitGetDeficiencies(this);
636 }
637 }
638
639 public final GetDeficienciesContext getDeficiencies() throws RecognitionException {
640 GetDeficienciesContext _localctx = new GetDeficienciesContext(_ctx, getState());
641 enterRule(_localctx, 8, RULE_getDeficiencies);
642
643 Map<Deficiency,DeficiencyNode> deficiency2ordering0 = new HashMap<Deficiency,DeficiencyNode>();
644
645 int _la;
646 try {
647 enterOuterAlt(_localctx, 1);
648 {
649 setState(80);
650 _errHandler.sync(this);
651 _la = _input.LA(1);
652 if (_la==PROPERTIES) {
653 {
654 setState(73);
655 match(PROPERTIES);
656 setState(77);
657 _errHandler.sync(this);
658 _la = _input.LA(1);
659 while (_la==NAME) {
660 {
661 {
662 setState(74);
663 addDeficiency(deficiency2ordering0);
664 }
665 }
666 setState(79);
667 _errHandler.sync(this);
668 _la = _input.LA(1);
669 }
670 }
671 }
672
673 }
674 _ctx.stop = _input.LT(-1);
675
676 ((GetDeficienciesContext)_localctx).deficiency2ordering = deficiency2ordering0;
677
678 }
679 catch (RecognitionException re) {
680 _localctx.exception = re;
681 _errHandler.reportError(this, re);
682 _errHandler.recover(this, re);
683 }
684 finally {
685 exitRule();
686 }
687 return _localctx;
688 }
689
690 public static class AddDeficiencyContext extends ParserRuleContext {
691 public Map<Deficiency,DeficiencyNode> deficiency2ordering;
692 public Token defT;
693 public TerminalNode NAME() { return getToken(SClassParser.NAME, 0); }
694 public AddDeficiencyContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); }
695 public AddDeficiencyContext(ParserRuleContext parent, int invokingState, Map<Deficiency,DeficiencyNode> deficiency2ordering) {
696 super(parent, invokingState);
697 this.deficiency2ordering = deficiency2ordering;
698 }
699 @Override public int getRuleIndex() { return RULE_addDeficiency; }
700 @Override
701 public void enterRule(ParseTreeListener listener) {
702 if ( listener instanceof SClassListener ) ((SClassListener)listener).enterAddDeficiency(this);
703 }
704 @Override
705 public void exitRule(ParseTreeListener listener) {
706 if ( listener instanceof SClassListener ) ((SClassListener)listener).exitAddDeficiency(this);
707 }
708 }
709
710 public final AddDeficiencyContext addDeficiency(Map<Deficiency,DeficiencyNode> deficiency2ordering) throws RecognitionException {
711 AddDeficiencyContext _localctx = new AddDeficiencyContext(_ctx, getState(), deficiency2ordering);
712 enterRule(_localctx, 10, RULE_addDeficiency);
713 try {
714 enterOuterAlt(_localctx, 1);
715 {
716 {
717 setState(82);
718 ((AddDeficiencyContext)_localctx).defT = match(NAME);
719 }
720
721 Deficiency def = new Deficiency((((AddDeficiencyContext)_localctx).defT!=null?((AddDeficiencyContext)_localctx).defT.getText():null));
722 DeficiencyNode old = deficiency2ordering
723 .put(def, new DeficiencyNode(def));
724 if (old != null) {
725
726 report("Property \"" + (((AddDeficiencyContext)_localctx).defT!=null?((AddDeficiencyContext)_localctx).defT.getText():null) + "\" is duplicate. ");
727 }
728
729 }
730 }
731 catch (RecognitionException re) {
732 _localctx.exception = re;
733 _errHandler.reportError(this, re);
734 _errHandler.recover(this, re);
735 }
736 finally {
737 exitRule();
738 }
739 return _localctx;
740 }
741
742 public static class GetInnerClsContext extends ParserRuleContext {
743 public SClass superclass;
744 public Set<Deficiency> newDefs;
745 public Map<Deficiency,SClass> old2innerCls;
746 public TerminalNode MAP() { return getToken(SClassParser.MAP, 0); }
747 public List<AddMapContext> addMap() {
748 return getRuleContexts(AddMapContext.class);
749 }
750 public AddMapContext addMap(int i) {
751 return getRuleContext(AddMapContext.class,i);
752 }
753 public GetInnerClsContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); }
754 public GetInnerClsContext(ParserRuleContext parent, int invokingState, SClass superclass, Set<Deficiency> newDefs) {
755 super(parent, invokingState);
756 this.superclass = superclass;
757 this.newDefs = newDefs;
758 }
759 @Override public int getRuleIndex() { return RULE_getInnerCls; }
760 @Override
761 public void enterRule(ParseTreeListener listener) {
762 if ( listener instanceof SClassListener ) ((SClassListener)listener).enterGetInnerCls(this);
763 }
764 @Override
765 public void exitRule(ParseTreeListener listener) {
766 if ( listener instanceof SClassListener ) ((SClassListener)listener).exitGetInnerCls(this);
767 }
768 }
769
770 public final GetInnerClsContext getInnerCls(SClass superclass,Set<Deficiency> newDefs) throws RecognitionException {
771 GetInnerClsContext _localctx = new GetInnerClsContext(_ctx, getState(), superclass, newDefs);
772 enterRule(_localctx, 12, RULE_getInnerCls);
773
774 Map<Deficiency,SClass> old2innerCls0 = new HashMap<Deficiency,SClass>();
775 Set<Deficiency> oldDefs = superclass.getType().asSet();
776
777 int _la;
778 try {
779 enterOuterAlt(_localctx, 1);
780 {
781 setState(92);
782 _errHandler.sync(this);
783 _la = _input.LA(1);
784 if (_la==MAP) {
785 {
786 setState(85);
787 match(MAP);
788 setState(89);
789 _errHandler.sync(this);
790 _la = _input.LA(1);
791 while (_la==REPLACE) {
792 {
793 {
794 setState(86);
795 addMap(oldDefs,old2innerCls0,newDefs);
796 }
797 }
798 setState(91);
799 _errHandler.sync(this);
800 _la = _input.LA(1);
801 }
802 }
803 }
804
805
806 if (!newDefs.isEmpty()) {
807
808 report("Found properties nowhere referenced: "
809 + newDefs + ". ");
810 }
811 ((GetInnerClsContext)_localctx).old2innerCls = old2innerCls0;
812
813 }
814 }
815 catch (RecognitionException re) {
816 _localctx.exception = re;
817 _errHandler.reportError(this, re);
818 _errHandler.recover(this, re);
819 }
820 finally {
821 exitRule();
822 }
823 return _localctx;
824 }
825
826 public static class AddMapContext extends ParserRuleContext {
827 public Set<Deficiency> oldDefs;
828 public Map<Deficiency,SClass> old2innerCls;
829 public Set<Deficiency> newDefs;
830 public Map<Deficiency,SClass> res;
831 public Token oldD;
832 public GetCheckedDeficienciesContext deficiency2orderingC;
833 public GetPathContext pathC;
834 public TerminalNode REPLACE() { return getToken(SClassParser.REPLACE, 0); }
835 public TerminalNode NAME() { return getToken(SClassParser.NAME, 0); }
836 public TerminalNode RELATIONS() { return getToken(SClassParser.RELATIONS, 0); }
837 public GetCheckedDeficienciesContext getCheckedDeficiencies() {
838 return getRuleContext(GetCheckedDeficienciesContext.class,0);
839 }
840 public GetPathContext getPath() {
841 return getRuleContext(GetPathContext.class,0);
842 }
843 public List<AddRelationContext> addRelation() {
844 return getRuleContexts(AddRelationContext.class);
845 }
846 public AddRelationContext addRelation(int i) {
847 return getRuleContext(AddRelationContext.class,i);
848 }
849 public AddMapContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); }
850 public AddMapContext(ParserRuleContext parent, int invokingState, Set<Deficiency> oldDefs, Map<Deficiency,SClass> old2innerCls, Set<Deficiency> newDefs) {
851 super(parent, invokingState);
852 this.oldDefs = oldDefs;
853 this.old2innerCls = old2innerCls;
854 this.newDefs = newDefs;
855 }
856 @Override public int getRuleIndex() { return RULE_addMap; }
857 @Override
858 public void enterRule(ParseTreeListener listener) {
859 if ( listener instanceof SClassListener ) ((SClassListener)listener).enterAddMap(this);
860 }
861 @Override
862 public void exitRule(ParseTreeListener listener) {
863 if ( listener instanceof SClassListener ) ((SClassListener)listener).exitAddMap(this);
864 }
865 }
866
867 public final AddMapContext addMap(Set<Deficiency> oldDefs,Map<Deficiency,SClass> old2innerCls,Set<Deficiency> newDefs) throws RecognitionException {
868 AddMapContext _localctx = new AddMapContext(_ctx, getState(), oldDefs, old2innerCls, newDefs);
869 enterRule(_localctx, 14, RULE_addMap);
870
871 Map<Deficiency,DeficiencyNode> deficiency2ordering = null;
872 List<String> clsPath = null;
873
874 int _la;
875 try {
876 enterOuterAlt(_localctx, 1);
877 {
878 {
879 setState(96);
880 match(REPLACE);
881 setState(97);
882 ((AddMapContext)_localctx).oldD = match(NAME);
883 setState(113);
884 _errHandler.sync(this);
885 switch (_input.LA(1)) {
886 case T__0:
887 {
888 setState(98);
889 match(T__0);
890 setState(99);
891 ((AddMapContext)_localctx).deficiency2orderingC = getCheckedDeficiencies(newDefs);
892
893 deficiency2ordering = ((GetCheckedDeficienciesContext)
894 ((AddMapContext)_localctx).deficiency2orderingC)
895 .deficiency2ordering;
896
897 setState(101);
898 match(RELATIONS);
899 setState(105);
900 _errHandler.sync(this);
901 _la = _input.LA(1);
902 while (_la==NAME) {
903 {
904 {
905 setState(102);
906 addRelation(deficiency2ordering);
907 }
908 }
909 setState(107);
910 _errHandler.sync(this);
911 _la = _input.LA(1);
912 }
913 setState(108);
914 match(T__1);
915 }
916 break;
917 case NAME:
918 {
919 setState(110);
920 ((AddMapContext)_localctx).pathC = getPath();
921
922 clsPath = ((GetPathContext)
923 ((AddMapContext)_localctx).pathC).res;
924
925 }
926 break;
927 default:
928 throw new NoViableAltException(this);
929 }
930 }
931
932 Deficiency oldDef = new Deficiency((((AddMapContext)_localctx).oldD!=null?((AddMapContext)_localctx).oldD.getText():null));
933 SClass sClass = null;
934 assert deficiency2ordering == null ^ clsPath == null;
935 if (deficiency2ordering != null) {
936
937 sClass = SClass.getSClass(oldDef.getName(),
938 Package
939 .getPackage(this.loc.getPath()),
940 SClass.BOOLEAN,
941 new HashMap<Deficiency,SClass>(),
942 deficiency2ordering);
943 sClass.verifyInner();
944 } else {
945
946 try {
947 sClass = this.classLoader
948 .loadSClass(ClassLocator.getLocator(clsPath),
949 this.loc.getPackage());
950 } catch(IOException e) {
951 throw new IllegalStateException
952 ("Thrown exception "
953 +"which should have been loaded before: \"" +
954 e + "\". ");
955 }
956 }
957 SClass overWrittenDef = old2innerCls.put(oldDef,sClass);
958
959 if (overWrittenDef != null) {
960 report("Tried to overwrite " + oldDef + ". ");
961 }
962 ((AddMapContext)_localctx).res = old2innerCls;
963
964 }
965 }
966 catch (RecognitionException re) {
967 _localctx.exception = re;
968 _errHandler.reportError(this, re);
969 _errHandler.recover(this, re);
970 }
971 finally {
972 exitRule();
973 }
974 return _localctx;
975 }
976
977 public static class GetCheckedDeficienciesContext extends ParserRuleContext {
978 public Set<Deficiency> newDefs;
979 public Map<Deficiency,DeficiencyNode> deficiency2ordering;
980 public List<AddDeficiencyContext> addDeficiency() {
981 return getRuleContexts(AddDeficiencyContext.class);
982 }
983 public AddDeficiencyContext addDeficiency(int i) {
984 return getRuleContext(AddDeficiencyContext.class,i);
985 }
986 public GetCheckedDeficienciesContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); }
987 public GetCheckedDeficienciesContext(ParserRuleContext parent, int invokingState, Set<Deficiency> newDefs) {
988 super(parent, invokingState);
989 this.newDefs = newDefs;
990 }
991 @Override public int getRuleIndex() { return RULE_getCheckedDeficiencies; }
992 @Override
993 public void enterRule(ParseTreeListener listener) {
994 if ( listener instanceof SClassListener ) ((SClassListener)listener).enterGetCheckedDeficiencies(this);
995 }
996 @Override
997 public void exitRule(ParseTreeListener listener) {
998 if ( listener instanceof SClassListener ) ((SClassListener)listener).exitGetCheckedDeficiencies(this);
999 }
1000 }
1001
1002 public final GetCheckedDeficienciesContext getCheckedDeficiencies(Set<Deficiency> newDefs) throws RecognitionException {
1003 GetCheckedDeficienciesContext _localctx = new GetCheckedDeficienciesContext(_ctx, getState(), newDefs);
1004 enterRule(_localctx, 16, RULE_getCheckedDeficiencies);
1005
1006 Map<Deficiency,DeficiencyNode> deficiency2ordering0 =
1007 new HashMap<Deficiency,DeficiencyNode>();
1008
1009 int _la;
1010 try {
1011 enterOuterAlt(_localctx, 1);
1012 {
1013 {
1014 setState(118);
1015 _errHandler.sync(this);
1016 _la = _input.LA(1);
1017 do {
1018 {
1019 {
1020 setState(117);
1021 addDeficiency(deficiency2ordering0);
1022 }
1023 }
1024 setState(120);
1025 _errHandler.sync(this);
1026 _la = _input.LA(1);
1027 } while ( _la==NAME );
1028 }
1029
1030 if (!newDefs.containsAll(deficiency2ordering0.keySet())) {
1031
1032 Set<Deficiency> undeclared =
1033 new HashSet<Deficiency>(deficiency2ordering0.keySet());
1034 undeclared.removeAll(newDefs);
1035 report("Found properties: " + undeclared +
1036 " either undeclared or used above. ");
1037 }
1038
1039 newDefs.removeAll(deficiency2ordering0.keySet());
1040 ((GetCheckedDeficienciesContext)_localctx).deficiency2ordering = deficiency2ordering0;
1041
1042 }
1043 }
1044 catch (RecognitionException re) {
1045 _localctx.exception = re;
1046 _errHandler.reportError(this, re);
1047 _errHandler.recover(this, re);
1048 }
1049 finally {
1050 exitRule();
1051 }
1052 return _localctx;
1053 }
1054
1055 public static class AddRelationsContext extends ParserRuleContext {
1056 public Map<Deficiency,DeficiencyNode> deficiency2ordering;
1057 public TerminalNode RELATIONS() { return getToken(SClassParser.RELATIONS, 0); }
1058 public List<AddRelationContext> addRelation() {
1059 return getRuleContexts(AddRelationContext.class);
1060 }
1061 public AddRelationContext addRelation(int i) {
1062 return getRuleContext(AddRelationContext.class,i);
1063 }
1064 public AddRelationsContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); }
1065 public AddRelationsContext(ParserRuleContext parent, int invokingState, Map<Deficiency,DeficiencyNode> deficiency2ordering) {
1066 super(parent, invokingState);
1067 this.deficiency2ordering = deficiency2ordering;
1068 }
1069 @Override public int getRuleIndex() { return RULE_addRelations; }
1070 @Override
1071 public void enterRule(ParseTreeListener listener) {
1072 if ( listener instanceof SClassListener ) ((SClassListener)listener).enterAddRelations(this);
1073 }
1074 @Override
1075 public void exitRule(ParseTreeListener listener) {
1076 if ( listener instanceof SClassListener ) ((SClassListener)listener).exitAddRelations(this);
1077 }
1078 }
1079
1080 public final AddRelationsContext addRelations(Map<Deficiency,DeficiencyNode> deficiency2ordering) throws RecognitionException {
1081 AddRelationsContext _localctx = new AddRelationsContext(_ctx, getState(), deficiency2ordering);
1082 enterRule(_localctx, 18, RULE_addRelations);
1083 int _la;
1084 try {
1085 enterOuterAlt(_localctx, 1);
1086 {
1087 setState(131);
1088 _errHandler.sync(this);
1089 _la = _input.LA(1);
1090 if (_la==RELATIONS) {
1091 {
1092 setState(124);
1093 match(RELATIONS);
1094 setState(128);
1095 _errHandler.sync(this);
1096 _la = _input.LA(1);
1097 while (_la==NAME) {
1098 {
1099 {
1100 setState(125);
1101 addRelation(deficiency2ordering);
1102 }
1103 }
1104 setState(130);
1105 _errHandler.sync(this);
1106 _la = _input.LA(1);
1107 }
1108 }
1109 }
1110
1111
1112 Iterator<Deficiency> iter = deficiency2ordering.keySet().iterator();
1113 Deficiency def;
1114 DeficiencyNode node;
1115 while (iter.hasNext()) {
1116 def = iter.next();
1117 node = deficiency2ordering.get(def);
1118 if (node.getPredecessors().isEmpty() &&
1119 node.getSuccessors() .isEmpty()) {
1120 iter.remove();
1121 }
1122 }
1123
1124 }
1125 }
1126 catch (RecognitionException re) {
1127 _localctx.exception = re;
1128 _errHandler.reportError(this, re);
1129 _errHandler.recover(this, re);
1130 }
1131 finally {
1132 exitRule();
1133 }
1134 return _localctx;
1135 }
1136
1137 public static class AddRelationContext extends ParserRuleContext {
1138 public Map<Deficiency,DeficiencyNode> deficiency2ordering;
1139 public Token defT1;
1140 public Token defT2;
1141 public TerminalNode IMPLIES() { return getToken(SClassParser.IMPLIES, 0); }
1142 public TerminalNode END() { return getToken(SClassParser.END, 0); }
1143 public List<TerminalNode> NAME() { return getTokens(SClassParser.NAME); }
1144 public TerminalNode NAME(int i) {
1145 return getToken(SClassParser.NAME, i);
1146 }
1147 public AddRelationContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); }
1148 public AddRelationContext(ParserRuleContext parent, int invokingState, Map<Deficiency,DeficiencyNode> deficiency2ordering) {
1149 super(parent, invokingState);
1150 this.deficiency2ordering = deficiency2ordering;
1151 }
1152 @Override public int getRuleIndex() { return RULE_addRelation; }
1153 @Override
1154 public void enterRule(ParseTreeListener listener) {
1155 if ( listener instanceof SClassListener ) ((SClassListener)listener).enterAddRelation(this);
1156 }
1157 @Override
1158 public void exitRule(ParseTreeListener listener) {
1159 if ( listener instanceof SClassListener ) ((SClassListener)listener).exitAddRelation(this);
1160 }
1161 }
1162
1163 public final AddRelationContext addRelation(Map<Deficiency,DeficiencyNode> deficiency2ordering) throws RecognitionException {
1164 AddRelationContext _localctx = new AddRelationContext(_ctx, getState(), deficiency2ordering);
1165 enterRule(_localctx, 20, RULE_addRelation);
1166 try {
1167 enterOuterAlt(_localctx, 1);
1168 {
1169 {
1170 setState(135);
1171 ((AddRelationContext)_localctx).defT1 = match(NAME);
1172 setState(136);
1173 match(IMPLIES);
1174 setState(137);
1175 ((AddRelationContext)_localctx).defT2 = match(NAME);
1176 setState(138);
1177 match(END);
1178 }
1179
1180 DeficiencyNode defN1 = deficiency2ordering
1181 .get(new Deficiency((((AddRelationContext)_localctx).defT1!=null?((AddRelationContext)_localctx).defT1.getText():null)));
1182 if (defN1 == null) {
1183 report("Deficiency \"" + (((AddRelationContext)_localctx).defT1!=null?((AddRelationContext)_localctx).defT1.getText():null) + "\" is unknown. ");
1184 }
1185 DeficiencyNode defN2 = deficiency2ordering
1186 .get(new Deficiency((((AddRelationContext)_localctx).defT2!=null?((AddRelationContext)_localctx).defT2.getText():null)));
1187 if (defN2 == null) {
1188 report("Deficiency \"" + (((AddRelationContext)_localctx).defT2!=null?((AddRelationContext)_localctx).defT2.getText():null) + "\" is unknown. ");
1189 }
1190
1191 defN1.addSuccessor (defN2);
1192 defN2.addPredecessor(defN1);
1193
1194 }
1195 }
1196 catch (RecognitionException re) {
1197 _localctx.exception = re;
1198 _errHandler.reportError(this, re);
1199 _errHandler.recover(this, re);
1200 }
1201 finally {
1202 exitRule();
1203 }
1204 return _localctx;
1205 }
1206
1207 public static final String _serializedATN =
1208 "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3\25\u0091\4\2\t\2"+
1209 "\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13"+
1210 "\t\13\4\f\t\f\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\2"+
1211 "\3\2\3\2\3\2\3\2\3\3\3\3\3\3\3\3\3\3\7\3\60\n\3\f\3\16\3\63\13\3\3\4\3"+
1212 "\4\3\4\3\5\3\5\3\5\3\5\3\5\3\5\3\5\7\5?\n\5\f\5\16\5B\13\5\3\5\3\5\5\5"+
1213 "F\n\5\5\5H\n\5\3\5\3\5\3\6\3\6\7\6N\n\6\f\6\16\6Q\13\6\5\6S\n\6\3\7\3"+
1214 "\7\3\7\3\b\3\b\7\bZ\n\b\f\b\16\b]\13\b\5\b_\n\b\3\b\3\b\3\t\3\t\3\t\3"+
1215 "\t\3\t\3\t\3\t\7\tj\n\t\f\t\16\tm\13\t\3\t\3\t\3\t\3\t\3\t\5\tt\n\t\3"+
1216 "\t\3\t\3\n\6\ny\n\n\r\n\16\nz\3\n\3\n\3\13\3\13\7\13\u0081\n\13\f\13\16"+
1217 "\13\u0084\13\13\5\13\u0086\n\13\3\13\3\13\3\f\3\f\3\f\3\f\3\f\3\f\3\f"+
1218 "\3\f\2\2\r\2\4\6\b\n\f\16\20\22\24\26\2\2\2\u0092\2\30\3\2\2\2\4*\3\2"+
1219 "\2\2\6\64\3\2\2\2\bG\3\2\2\2\nR\3\2\2\2\fT\3\2\2\2\16^\3\2\2\2\20b\3\2"+
1220 "\2\2\22x\3\2\2\2\24\u0085\3\2\2\2\26\u0089\3\2\2\2\30\31\7\13\2\2\31\32"+
1221 "\5\4\3\2\32\33\7\23\2\2\33\34\b\2\1\2\34\35\7\f\2\2\35\36\7\25\2\2\36"+
1222 "\37\5\b\5\2\37 \7\3\2\2 !\5\n\6\2!\"\b\2\1\2\"#\5\16\b\2#$\b\2\1\2$%\5"+
1223 "\24\13\2%&\7\4\2\2&\'\7\2\2\3\'(\3\2\2\2()\b\2\1\2)\3\3\2\2\2*+\7\25\2"+
1224 "\2+\61\b\3\1\2,-\7\24\2\2-.\7\25\2\2.\60\b\3\1\2/,\3\2\2\2\60\63\3\2\2"+
1225 "\2\61/\3\2\2\2\61\62\3\2\2\2\62\5\3\2\2\2\63\61\3\2\2\2\64\65\5\4\3\2"+
1226 "\65\66\b\4\1\2\66\7\3\2\2\2\678\7\r\2\289\5\4\3\29E\b\5\1\2:;\7\5\2\2"+
1227 ";@\5\6\4\2<=\7\6\2\2=?\5\6\4\2><\3\2\2\2?B\3\2\2\2@>\3\2\2\2@A\3\2\2\2"+
1228 "AC\3\2\2\2B@\3\2\2\2CD\7\7\2\2DF\3\2\2\2E:\3\2\2\2EF\3\2\2\2FH\3\2\2\2"+
1229 "G\67\3\2\2\2GH\3\2\2\2HI\3\2\2\2IJ\b\5\1\2J\t\3\2\2\2KO\7\16\2\2LN\5\f"+
1230 "\7\2ML\3\2\2\2NQ\3\2\2\2OM\3\2\2\2OP\3\2\2\2PS\3\2\2\2QO\3\2\2\2RK\3\2"+
1231 "\2\2RS\3\2\2\2S\13\3\2\2\2TU\7\25\2\2UV\b\7\1\2V\r\3\2\2\2W[\7\17\2\2"+
1232 "XZ\5\20\t\2YX\3\2\2\2Z]\3\2\2\2[Y\3\2\2\2[\\\3\2\2\2\\_\3\2\2\2][\3\2"+
1233 "\2\2^W\3\2\2\2^_\3\2\2\2_`\3\2\2\2`a\b\b\1\2a\17\3\2\2\2bc\7\20\2\2cs"+
1234 "\7\25\2\2de\7\3\2\2ef\5\22\n\2fg\b\t\1\2gk\7\21\2\2hj\5\26\f\2ih\3\2\2"+
1235 "\2jm\3\2\2\2ki\3\2\2\2kl\3\2\2\2ln\3\2\2\2mk\3\2\2\2no\7\4\2\2ot\3\2\2"+
1236 "\2pq\5\4\3\2qr\b\t\1\2rt\3\2\2\2sd\3\2\2\2sp\3\2\2\2tu\3\2\2\2uv\b\t\1"+
1237 "\2v\21\3\2\2\2wy\5\f\7\2xw\3\2\2\2yz\3\2\2\2zx\3\2\2\2z{\3\2\2\2{|\3\2"+
1238 "\2\2|}\b\n\1\2}\23\3\2\2\2~\u0082\7\21\2\2\177\u0081\5\26\f\2\u0080\177"+
1239 "\3\2\2\2\u0081\u0084\3\2\2\2\u0082\u0080\3\2\2\2\u0082\u0083\3\2\2\2\u0083"+
1240 "\u0086\3\2\2\2\u0084\u0082\3\2\2\2\u0085~\3\2\2\2\u0085\u0086\3\2\2\2"+
1241 "\u0086\u0087\3\2\2\2\u0087\u0088\b\13\1\2\u0088\25\3\2\2\2\u0089\u008a"+
1242 "\7\25\2\2\u008a\u008b\7\22\2\2\u008b\u008c\7\25\2\2\u008c\u008d\7\23\2"+
1243 "\2\u008d\u008e\3\2\2\2\u008e\u008f\b\f\1\2\u008f\27\3\2\2\2\17\61@EGO"+
1244 "R[^ksz\u0082\u0085";
1245 public static final ATN _ATN =
1246 new ATNDeserializer().deserialize(_serializedATN.toCharArray());
1247 static {
1248 _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
1249 for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
1250 _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
1251 }
1252 }
1253 }