@cparra/apex-reflection 0.1.0-alpha.0 → 0.1.1-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/end-to-end.test.ts +256 -0
- package/coverage/clover.xml +12857 -0
- package/coverage/coverage-final.json +3 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +79 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +126 -0
- package/coverage/lcov-report/index.js.html +104 -0
- package/coverage/lcov-report/out.js.html +41126 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +170 -0
- package/coverage/lcov.info +24801 -0
- package/index.d.ts +118 -0
- package/index.js +8 -0
- package/index.ts +141 -0
- package/jest.config.js +11 -0
- package/out.js +13708 -0
- package/package.json +22 -17
- package/tsconfig.json +5 -3
- package/.idea/apexdocs-dart.iml +0 -18
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/libraries/Dart_Packages.xml +0 -556
- package/.idea/libraries/Dart_SDK.xml +0 -28
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/runConfigurations/_template__of_Dart_Test.xml +0 -6
- package/.idea/vcs.xml +0 -6
- package/CHANGELOG.md +0 -3
- package/README.md +0 -26
- package/TODO.md +0 -5
- package/analysis_options.yaml +0 -30
- package/antlr4-4.9.2/CHANGELOG.md +0 -4
- package/antlr4-4.9.2/LICENSE +0 -52
- package/antlr4-4.9.2/README.md +0 -11
- package/antlr4-4.9.2/analysis_options.yaml +0 -1
- package/antlr4-4.9.2/lib/antlr4.dart +0 -21
- package/antlr4-4.9.2/lib/src/atn/atn.dart +0 -18
- package/antlr4-4.9.2/lib/src/atn/src/atn.dart +0 -170
- package/antlr4-4.9.2/lib/src/atn/src/atn_config.dart +0 -242
- package/antlr4-4.9.2/lib/src/atn/src/atn_config_set.dart +0 -283
- package/antlr4-4.9.2/lib/src/atn/src/atn_deserializer.dart +0 -809
- package/antlr4-4.9.2/lib/src/atn/src/atn_simulator.dart +0 -95
- package/antlr4-4.9.2/lib/src/atn/src/atn_state.dart +0 -296
- package/antlr4-4.9.2/lib/src/atn/src/atn_type.dart +0 -14
- package/antlr4-4.9.2/lib/src/atn/src/info.dart +0 -553
- package/antlr4-4.9.2/lib/src/atn/src/lexer_action.dart +0 -601
- package/antlr4-4.9.2/lib/src/atn/src/lexer_action_executor.dart +0 -167
- package/antlr4-4.9.2/lib/src/atn/src/lexer_atn_simulator.dart +0 -731
- package/antlr4-4.9.2/lib/src/atn/src/parser_atn_simulator.dart +0 -2630
- package/antlr4-4.9.2/lib/src/atn/src/profiling_atn_simulator.dart +0 -229
- package/antlr4-4.9.2/lib/src/atn/src/semantic_context.dart +0 -404
- package/antlr4-4.9.2/lib/src/atn/src/transition.dart +0 -305
- package/antlr4-4.9.2/lib/src/dfa/dfa.dart +0 -8
- package/antlr4-4.9.2/lib/src/dfa/src/dfa.dart +0 -138
- package/antlr4-4.9.2/lib/src/dfa/src/dfa_serializer.dart +0 -76
- package/antlr4-4.9.2/lib/src/dfa/src/dfa_state.dart +0 -151
- package/antlr4-4.9.2/lib/src/error/error.dart +0 -10
- package/antlr4-4.9.2/lib/src/error/src/diagnostic_error_listener.dart +0 -116
- package/antlr4-4.9.2/lib/src/error/src/error_listener.dart +0 -241
- package/antlr4-4.9.2/lib/src/error/src/error_strategy.dart +0 -902
- package/antlr4-4.9.2/lib/src/error/src/errors.dart +0 -204
- package/antlr4-4.9.2/lib/src/input_stream.dart +0 -335
- package/antlr4-4.9.2/lib/src/interval_set.dart +0 -735
- package/antlr4-4.9.2/lib/src/lexer.dart +0 -343
- package/antlr4-4.9.2/lib/src/ll1_analyzer.dart +0 -204
- package/antlr4-4.9.2/lib/src/misc/multi_map.dart +0 -32
- package/antlr4-4.9.2/lib/src/misc/pair.dart +0 -34
- package/antlr4-4.9.2/lib/src/parser.dart +0 -777
- package/antlr4-4.9.2/lib/src/parser_interpreter.dart +0 -393
- package/antlr4-4.9.2/lib/src/parser_rule_context.dart +0 -275
- package/antlr4-4.9.2/lib/src/prediction_context.dart +0 -877
- package/antlr4-4.9.2/lib/src/recognizer.dart +0 -182
- package/antlr4-4.9.2/lib/src/rule_context.dart +0 -192
- package/antlr4-4.9.2/lib/src/runtime_meta_data.dart +0 -188
- package/antlr4-4.9.2/lib/src/token.dart +0 -431
- package/antlr4-4.9.2/lib/src/token_factory.dart +0 -88
- package/antlr4-4.9.2/lib/src/token_source.dart +0 -241
- package/antlr4-4.9.2/lib/src/token_stream.dart +0 -627
- package/antlr4-4.9.2/lib/src/tree/src/pattern/chunk.dart +0 -90
- package/antlr4-4.9.2/lib/src/tree/src/pattern/parse_tree_match.dart +0 -635
- package/antlr4-4.9.2/lib/src/tree/src/tree.dart +0 -370
- package/antlr4-4.9.2/lib/src/tree/src/trees.dart +0 -226
- package/antlr4-4.9.2/lib/src/tree/tree.dart +0 -10
- package/antlr4-4.9.2/lib/src/util/bit_set.dart +0 -308
- package/antlr4-4.9.2/lib/src/util/murmur_hash.dart +0 -77
- package/antlr4-4.9.2/lib/src/util/utils.dart +0 -31
- package/antlr4-4.9.2/lib/src/vocabulary.dart +0 -254
- package/antlr4-4.9.2/pubspec.yaml +0 -13
- package/example/node_example/index.js +0 -8
- package/example/node_example/package.json +0 -12
- package/example/node_example_ts/package-lock.json +0 -70
- package/example/node_example_ts/package.json +0 -19
- package/example/node_example_ts/src/index.js +0 -5
- package/example/node_example_ts/src/index.ts +0 -9
- package/example/node_example_ts/tsconfig.json +0 -79
- package/js/dart2jsout.js +0 -25898
- package/js/dart2jsout.js.map +0 -16
- package/js/index.d.ts +0 -1
- package/js/index.js +0 -4
- package/js/out.js +0 -26023
- package/js/out.js.map +0 -16
- package/js/package-lock.json +0 -57
- package/js/preamble.js +0 -125
- package/lib/apexdocs_dart.dart +0 -28
- package/lib/src/antlr/grammars/Apexdoc/ApexdocLexer.g4 +0 -120
- package/lib/src/antlr/grammars/Apexdoc/ApexdocParser.g4 +0 -158
- package/lib/src/antlr/grammars/Apexdoc/gen/ApexdocLexer.interp +0 -95
- package/lib/src/antlr/grammars/Apexdoc/gen/ApexdocLexer.java +0 -238
- package/lib/src/antlr/grammars/Apexdoc/gen/ApexdocLexer.tokens +0 -23
- package/lib/src/antlr/grammars/apex/ApexLexer.g4 +0 -255
- package/lib/src/antlr/grammars/apex/ApexParser.g4 +0 -567
- package/lib/src/antlr/grammars/apex/examples/ApexClass.cls +0 -6
- package/lib/src/antlr/lib/apex/ApexLexer.dart +0 -1223
- package/lib/src/antlr/lib/apex/ApexLexer.interp +0 -393
- package/lib/src/antlr/lib/apex/ApexLexer.tokens +0 -212
- package/lib/src/antlr/lib/apex/ApexParser.dart +0 -9349
- package/lib/src/antlr/lib/apex/ApexParser.interp +0 -326
- package/lib/src/antlr/lib/apex/ApexParser.tokens +0 -212
- package/lib/src/antlr/lib/apex/ApexParserBaseListener.dart +0 -1036
- package/lib/src/antlr/lib/apex/ApexParserListener.dart +0 -975
- package/lib/src/antlr/lib/apexdoc/ApexdocLexer.dart +0 -373
- package/lib/src/antlr/lib/apexdoc/ApexdocLexer.interp +0 -95
- package/lib/src/antlr/lib/apexdoc/ApexdocLexer.tokens +0 -23
- package/lib/src/antlr/lib/apexdoc/ApexdocParser.dart +0 -2471
- package/lib/src/antlr/lib/apexdoc/ApexdocParser.interp +0 -69
- package/lib/src/antlr/lib/apexdoc/ApexdocParser.tokens +0 -23
- package/lib/src/antlr/lib/apexdoc/ApexdocParserBaseListener.dart +0 -252
- package/lib/src/antlr/lib/apexdoc/ApexdocParserListener.dart +0 -215
- package/lib/src/builders/builders.dart +0 -32
- package/lib/src/model/apex_file_manifest.dart +0 -37
- package/lib/src/model/apex_file_manifest.g.dart +0 -18
- package/lib/src/model/declaration.dart +0 -50
- package/lib/src/model/doc_comment.dart +0 -117
- package/lib/src/model/doc_comment.g.dart +0 -118
- package/lib/src/model/members.dart +0 -143
- package/lib/src/model/members.g.dart +0 -105
- package/lib/src/model/types.dart +0 -159
- package/lib/src/model/types.g.dart +0 -111
- package/lib/src/service/apex_listener.dart +0 -226
- package/lib/src/service/apexdoc_listener.dart +0 -82
- package/lib/src/service/parsers.dart +0 -33
- package/lib/src/service/utils/parsing/access_modifiers_parser.dart +0 -33
- package/lib/src/service/utils/parsing/parameters_parser.dart +0 -18
- package/lib/src/service/utils/parsing/parsing_utils.dart +0 -2
- package/lib/src/service/walker.dart +0 -82
- package/pubspec.yaml +0 -19
- package/test/apex_file_manifest_test.dart +0 -16
- package/test/apex_listener_test.dart +0 -703
- package/test/apexdoc_parser_test.dart +0 -179
- package/test/doc_comment_test.dart +0 -89
- package/test/members_serialization_test.dart +0 -158
- package/test/members_test.dart +0 -178
- package/test/types_serialization_test.dart +0 -191
- package/test/types_test.dart +0 -311
- package/test/walker_test.dart +0 -58
- package/tool/grind.dart +0 -20
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
|
|
3
|
-
* Use of this file is governed by the BSD 3-clause license that
|
|
4
|
-
* can be found in the LICENSE.txt file in the project root.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import 'dart:math';
|
|
8
|
-
|
|
9
|
-
import '../../dfa/dfa.dart';
|
|
10
|
-
import '../../parser.dart';
|
|
11
|
-
import '../../parser_rule_context.dart';
|
|
12
|
-
import '../../token_stream.dart';
|
|
13
|
-
import '../../util/bit_set.dart';
|
|
14
|
-
import 'atn_config_set.dart';
|
|
15
|
-
import 'atn_simulator.dart';
|
|
16
|
-
import 'info.dart';
|
|
17
|
-
import 'parser_atn_simulator.dart';
|
|
18
|
-
import 'semantic_context.dart';
|
|
19
|
-
|
|
20
|
-
class ProfilingATNSimulator extends ParserATNSimulator {
|
|
21
|
-
List<DecisionInfo> decisions;
|
|
22
|
-
int numDecisions;
|
|
23
|
-
|
|
24
|
-
int _sllStopIndex;
|
|
25
|
-
int _llStopIndex;
|
|
26
|
-
|
|
27
|
-
int currentDecision;
|
|
28
|
-
DFAState currentState;
|
|
29
|
-
|
|
30
|
-
/// At the point of LL failover, we record how SLL would resolve the conflict so that
|
|
31
|
-
/// we can determine whether or not a decision / input pair is context-sensitive.
|
|
32
|
-
/// If LL gives a different result than SLL's predicted alternative, we have a
|
|
33
|
-
/// context sensitivity for sure. The converse is not necessarily true, however.
|
|
34
|
-
/// It's possible that after conflict resolution chooses minimum alternatives,
|
|
35
|
-
/// SLL could get the same answer as LL. Regardless of whether or not the result indicates
|
|
36
|
-
/// an ambiguity, it is not treated as a context sensitivity because LL prediction
|
|
37
|
-
/// was not required in order to produce a correct prediction for this decision and input sequence.
|
|
38
|
-
/// It may in fact still be a context sensitivity but we don't know by looking at the
|
|
39
|
-
/// minimum alternatives for the current input.
|
|
40
|
-
int conflictingAltResolvedBySLL;
|
|
41
|
-
|
|
42
|
-
ProfilingATNSimulator(Parser parser)
|
|
43
|
-
: super(parser, parser.interpreter.atn, parser.interpreter.decisionToDFA,
|
|
44
|
-
parser.interpreter.sharedContextCache) {
|
|
45
|
-
numDecisions = atn.decisionToState.length;
|
|
46
|
-
decisions = List<DecisionInfo>(numDecisions);
|
|
47
|
-
for (var i = 0; i < numDecisions; i++) {
|
|
48
|
-
decisions[i] = DecisionInfo(i);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@override
|
|
53
|
-
int adaptivePredict(
|
|
54
|
-
TokenStream input, int decision, ParserRuleContext outerContext) {
|
|
55
|
-
try {
|
|
56
|
-
_sllStopIndex = -1;
|
|
57
|
-
_llStopIndex = -1;
|
|
58
|
-
currentDecision = decision;
|
|
59
|
-
|
|
60
|
-
final start =
|
|
61
|
-
DateTime.now(); // TODO get nano seconds expensive but useful info
|
|
62
|
-
final alt = super.adaptivePredict(input, decision, outerContext);
|
|
63
|
-
final stop = DateTime.now();
|
|
64
|
-
decisions[decision].timeInPrediction +=
|
|
65
|
-
(stop.difference(start)).inMicroseconds;
|
|
66
|
-
decisions[decision].invocations++;
|
|
67
|
-
|
|
68
|
-
final SLL_k = _sllStopIndex - startIndex + 1;
|
|
69
|
-
decisions[decision].SLL_TotalLook += SLL_k;
|
|
70
|
-
decisions[decision].SLL_MinLook = decisions[decision].SLL_MinLook == 0
|
|
71
|
-
? SLL_k
|
|
72
|
-
: min(decisions[decision].SLL_MinLook, SLL_k);
|
|
73
|
-
if (SLL_k > decisions[decision].SLL_MaxLook) {
|
|
74
|
-
decisions[decision].SLL_MaxLook = SLL_k;
|
|
75
|
-
decisions[decision].SLL_MaxLookEvent = LookaheadEventInfo(
|
|
76
|
-
decision, null, alt, input, startIndex, _sllStopIndex, false);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (_llStopIndex >= 0) {
|
|
80
|
-
final LL_k = _llStopIndex - startIndex + 1;
|
|
81
|
-
decisions[decision].LL_TotalLook += LL_k;
|
|
82
|
-
decisions[decision].LL_MinLook = decisions[decision].LL_MinLook == 0
|
|
83
|
-
? LL_k
|
|
84
|
-
: min(decisions[decision].LL_MinLook, LL_k);
|
|
85
|
-
if (LL_k > decisions[decision].LL_MaxLook) {
|
|
86
|
-
decisions[decision].LL_MaxLook = LL_k;
|
|
87
|
-
decisions[decision].LL_MaxLookEvent = LookaheadEventInfo(
|
|
88
|
-
decision, null, alt, input, startIndex, _llStopIndex, true);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return alt;
|
|
93
|
-
} finally {
|
|
94
|
-
currentDecision = -1;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
@override
|
|
99
|
-
DFAState getExistingTargetState(DFAState previousD, int t) {
|
|
100
|
-
// this method is called after each time the input position advances
|
|
101
|
-
// during SLL prediction
|
|
102
|
-
_sllStopIndex = input.index;
|
|
103
|
-
|
|
104
|
-
final existingTargetState = super.getExistingTargetState(previousD, t);
|
|
105
|
-
if (existingTargetState != null) {
|
|
106
|
-
decisions[currentDecision]
|
|
107
|
-
.SLL_DFATransitions++; // count only if we transition over a DFA state
|
|
108
|
-
if (existingTargetState == ATNSimulator.ERROR) {
|
|
109
|
-
decisions[currentDecision].errors.add(ErrorInfo(currentDecision,
|
|
110
|
-
previousD.configs, input, startIndex, _sllStopIndex, false));
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
currentState = existingTargetState;
|
|
115
|
-
return existingTargetState;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
@override
|
|
119
|
-
DFAState computeTargetState(DFA dfa, DFAState previousD, int t) {
|
|
120
|
-
final state = super.computeTargetState(dfa, previousD, t);
|
|
121
|
-
currentState = state;
|
|
122
|
-
return state;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
@override
|
|
126
|
-
ATNConfigSet computeReachSet(ATNConfigSet closure, int t, bool fullCtx) {
|
|
127
|
-
if (fullCtx) {
|
|
128
|
-
// this method is called after each time the input position advances
|
|
129
|
-
// during full context prediction
|
|
130
|
-
_llStopIndex = input.index;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
final reachConfigs = super.computeReachSet(closure, t, fullCtx);
|
|
134
|
-
if (fullCtx) {
|
|
135
|
-
decisions[currentDecision]
|
|
136
|
-
.LL_ATNTransitions++; // count computation even if error
|
|
137
|
-
if (reachConfigs != null) {
|
|
138
|
-
} else {
|
|
139
|
-
// no reach on current lookahead symbol. ERROR.
|
|
140
|
-
// TODO: does not handle delayed errors per getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule()
|
|
141
|
-
decisions[currentDecision].errors.add(ErrorInfo(
|
|
142
|
-
currentDecision, closure, input, startIndex, _llStopIndex, true));
|
|
143
|
-
}
|
|
144
|
-
} else {
|
|
145
|
-
decisions[currentDecision].SLL_ATNTransitions++;
|
|
146
|
-
if (reachConfigs != null) {
|
|
147
|
-
} else {
|
|
148
|
-
// no reach on current lookahead symbol. ERROR.
|
|
149
|
-
decisions[currentDecision].errors.add(ErrorInfo(
|
|
150
|
-
currentDecision, closure, input, startIndex, _sllStopIndex, false));
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return reachConfigs;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
@override
|
|
157
|
-
bool evalSemanticContextOne(SemanticContext pred,
|
|
158
|
-
ParserRuleContext parserCallStack, int alt, bool fullCtx) {
|
|
159
|
-
final result =
|
|
160
|
-
super.evalSemanticContextOne(pred, parserCallStack, alt, fullCtx);
|
|
161
|
-
if (!(pred is PrecedencePredicate)) {
|
|
162
|
-
final fullContext = _llStopIndex >= 0;
|
|
163
|
-
final stopIndex = fullContext ? _llStopIndex : _sllStopIndex;
|
|
164
|
-
decisions[currentDecision].predicateEvals.add(PredicateEvalInfo(
|
|
165
|
-
currentDecision,
|
|
166
|
-
input,
|
|
167
|
-
startIndex,
|
|
168
|
-
stopIndex,
|
|
169
|
-
pred,
|
|
170
|
-
result,
|
|
171
|
-
alt,
|
|
172
|
-
fullCtx));
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return result;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
@override
|
|
179
|
-
void reportAttemptingFullContext(DFA dfa, BitSet conflictingAlts,
|
|
180
|
-
ATNConfigSet configs, int startIndex, int stopIndex) {
|
|
181
|
-
if (conflictingAlts != null) {
|
|
182
|
-
conflictingAltResolvedBySLL = conflictingAlts.nextset(0);
|
|
183
|
-
} else {
|
|
184
|
-
conflictingAltResolvedBySLL = configs.alts.nextset(0);
|
|
185
|
-
}
|
|
186
|
-
decisions[currentDecision].LL_Fallback++;
|
|
187
|
-
super.reportAttemptingFullContext(
|
|
188
|
-
dfa, conflictingAlts, configs, startIndex, stopIndex);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
@override
|
|
192
|
-
void reportContextSensitivity(DFA dfa, int prediction, ATNConfigSet configs,
|
|
193
|
-
int startIndex, int stopIndex) {
|
|
194
|
-
if (prediction != conflictingAltResolvedBySLL) {
|
|
195
|
-
decisions[currentDecision].contextSensitivities.add(
|
|
196
|
-
ContextSensitivityInfo(
|
|
197
|
-
currentDecision, configs, input, startIndex, stopIndex));
|
|
198
|
-
}
|
|
199
|
-
super.reportContextSensitivity(
|
|
200
|
-
dfa, prediction, configs, startIndex, stopIndex);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
@override
|
|
204
|
-
void reportAmbiguity(DFA dfa, DFAState D, int startIndex, int stopIndex,
|
|
205
|
-
bool exact, BitSet ambigAlts, ATNConfigSet configs) {
|
|
206
|
-
final prediction =
|
|
207
|
-
ambigAlts != null ? ambigAlts.nextset(0) : configs.alts.nextset(0);
|
|
208
|
-
if (configs.fullCtx && prediction != conflictingAltResolvedBySLL) {
|
|
209
|
-
// Even though this is an ambiguity we are reporting, we can
|
|
210
|
-
// still detect some context sensitivities. Both SLL and LL
|
|
211
|
-
// are showing a conflict, hence an ambiguity, but if they resolve
|
|
212
|
-
// to different minimum alternatives we have also identified a
|
|
213
|
-
// context sensitivity.
|
|
214
|
-
decisions[currentDecision].contextSensitivities.add(
|
|
215
|
-
ContextSensitivityInfo(
|
|
216
|
-
currentDecision, configs, input, startIndex, stopIndex));
|
|
217
|
-
}
|
|
218
|
-
decisions[currentDecision].ambiguities.add(AmbiguityInfo(currentDecision,
|
|
219
|
-
configs, ambigAlts, input, startIndex, stopIndex, configs.fullCtx));
|
|
220
|
-
super.reportAmbiguity(
|
|
221
|
-
dfa, D, startIndex, stopIndex, exact, ambigAlts, configs);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// ---------------------------------------------------------------------
|
|
225
|
-
|
|
226
|
-
List<DecisionInfo> get decisionInfo {
|
|
227
|
-
return decisions;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
|
|
3
|
-
* Use of this file is governed by the BSD 3-clause license that
|
|
4
|
-
* can be found in the LICENSE.txt file in the project root.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import 'package:collection/collection.dart';
|
|
8
|
-
|
|
9
|
-
import '../../recognizer.dart';
|
|
10
|
-
import '../../rule_context.dart';
|
|
11
|
-
import '../../util/murmur_hash.dart';
|
|
12
|
-
|
|
13
|
-
/// A tree structure used to record the semantic context in which
|
|
14
|
-
/// an ATN configuration is valid. It's either a single predicate,
|
|
15
|
-
/// a conjunction {@code p1&&p2}, or a sum of products {@code p1||p2}.
|
|
16
|
-
///
|
|
17
|
-
/// <p>I have scoped the [AND], [OR], and [Predicate] subclasses of
|
|
18
|
-
/// [SemanticContext] within the scope of this outer class.</p>
|
|
19
|
-
abstract class SemanticContext {
|
|
20
|
-
/// The default [SemanticContext], which is semantically equivalent to
|
|
21
|
-
/// a predicate of the form {@code {true}?}.
|
|
22
|
-
static const SemanticContext NONE = Predicate();
|
|
23
|
-
|
|
24
|
-
const SemanticContext();
|
|
25
|
-
|
|
26
|
-
/// For context independent predicates, we evaluate them without a local
|
|
27
|
-
/// context (i.e., null context). That way, we can evaluate them without
|
|
28
|
-
/// having to create proper rule-specific context during prediction (as
|
|
29
|
-
/// opposed to the parser, which creates them naturally). In a practical
|
|
30
|
-
/// sense, this avoids a cast exception from RuleContext to myruleContext.
|
|
31
|
-
///
|
|
32
|
-
/// <p>For context dependent predicates, we must pass in a local context so that
|
|
33
|
-
/// references such as $arg evaluate properly as _localctx.arg. We only
|
|
34
|
-
/// capture context dependent predicates in the context in which we begin
|
|
35
|
-
/// prediction, so we passed in the outer context here in case of context
|
|
36
|
-
/// dependent predicate evaluation.</p>
|
|
37
|
-
bool eval(Recognizer parser, RuleContext parserCallStack);
|
|
38
|
-
|
|
39
|
-
/// Evaluate the precedence predicates for the context and reduce the result.
|
|
40
|
-
///
|
|
41
|
-
/// @param parser The parser instance.
|
|
42
|
-
/// @param parserCallStack
|
|
43
|
-
/// @return The simplified semantic context after precedence predicates are
|
|
44
|
-
/// evaluated, which will be one of the following values.
|
|
45
|
-
/// <ul>
|
|
46
|
-
/// <li>{@link #NONE}in if the predicate simplifies to [true] after
|
|
47
|
-
/// precedence predicates are evaluated.</li>
|
|
48
|
-
/// <li>nullin if the predicate simplifies to [false] after
|
|
49
|
-
/// precedence predicates are evaluated.</li>
|
|
50
|
-
/// <li>[this]in if the semantic context is not changed as a result of
|
|
51
|
-
/// precedence predicate evaluation.</li>
|
|
52
|
-
/// <li>A non-null [SemanticContext]in the new simplified
|
|
53
|
-
/// semantic context after precedence predicates are evaluated.</li>
|
|
54
|
-
/// </ul>
|
|
55
|
-
SemanticContext evalPrecedence(Recognizer parser,
|
|
56
|
-
RuleContext parserCallStack) {
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
static SemanticContext and(SemanticContext a, SemanticContext b) {
|
|
61
|
-
if (a == null || a == NONE) return b;
|
|
62
|
-
if (b == null || b == NONE) return a;
|
|
63
|
-
final result = AND(a, b);
|
|
64
|
-
if (result.opnds.length == 1) {
|
|
65
|
-
return result.opnds[0];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return result;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
///
|
|
72
|
-
/// @see ParserATNSimulator#getPredsForAmbigAlts
|
|
73
|
-
static SemanticContext or(SemanticContext a, SemanticContext b) {
|
|
74
|
-
if (a == null) return b;
|
|
75
|
-
if (b == null) return a;
|
|
76
|
-
if (a == NONE || b == NONE) return NONE;
|
|
77
|
-
final result = OR(a, b);
|
|
78
|
-
if (result.opnds.length == 1) {
|
|
79
|
-
return result.opnds[0];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return result;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
static Iterable<PrecedencePredicate> filterPrecedencePredicates(
|
|
86
|
-
Iterable<SemanticContext> collection) {
|
|
87
|
-
return collection.whereType<PrecedencePredicate>();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
static Iterable<SemanticContext> filterNonPrecedencePredicates(
|
|
91
|
-
Iterable<SemanticContext> collection) {
|
|
92
|
-
return collection.where((e) => !(e is PrecedencePredicate));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
class Predicate extends SemanticContext {
|
|
97
|
-
final int ruleIndex;
|
|
98
|
-
final int predIndex;
|
|
99
|
-
final bool isCtxDependent; // e.g., $i ref in pred
|
|
100
|
-
|
|
101
|
-
const Predicate(
|
|
102
|
-
[this.ruleIndex = -1, this.predIndex = -1, this.isCtxDependent = false]);
|
|
103
|
-
|
|
104
|
-
@override
|
|
105
|
-
bool eval(Recognizer parser, RuleContext parserCallStack) {
|
|
106
|
-
final localctx = isCtxDependent ? parserCallStack : null;
|
|
107
|
-
return parser.sempred(localctx, ruleIndex, predIndex);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
@override
|
|
111
|
-
int get hashCode {
|
|
112
|
-
var hashCode = MurmurHash.initialize();
|
|
113
|
-
hashCode = MurmurHash.update(hashCode, ruleIndex);
|
|
114
|
-
hashCode = MurmurHash.update(hashCode, predIndex);
|
|
115
|
-
hashCode = MurmurHash.update(hashCode, isCtxDependent ? 1 : 0);
|
|
116
|
-
hashCode = MurmurHash.finish(hashCode, 3);
|
|
117
|
-
return hashCode;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
@override
|
|
121
|
-
bool operator ==(Object obj) {
|
|
122
|
-
return obj is Predicate &&
|
|
123
|
-
ruleIndex == obj.ruleIndex &&
|
|
124
|
-
predIndex == obj.predIndex &&
|
|
125
|
-
isCtxDependent == obj.isCtxDependent;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
@override
|
|
129
|
-
String toString() {
|
|
130
|
-
return '{$ruleIndex:$predIndex}?';
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
class PrecedencePredicate extends SemanticContext
|
|
135
|
-
implements Comparable<PrecedencePredicate> {
|
|
136
|
-
final int precedence;
|
|
137
|
-
|
|
138
|
-
PrecedencePredicate([this.precedence = 0]);
|
|
139
|
-
|
|
140
|
-
@override
|
|
141
|
-
bool eval(Recognizer parser, RuleContext parserCallStack) {
|
|
142
|
-
return parser.precpred(parserCallStack, precedence);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
@override
|
|
146
|
-
SemanticContext evalPrecedence(Recognizer parser,
|
|
147
|
-
RuleContext parserCallStack) {
|
|
148
|
-
if (parser.precpred(parserCallStack, precedence)) {
|
|
149
|
-
return SemanticContext.NONE;
|
|
150
|
-
} else {
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
@override
|
|
156
|
-
int compareTo(PrecedencePredicate o) {
|
|
157
|
-
return precedence - o.precedence;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
@override
|
|
161
|
-
int get hashCode {
|
|
162
|
-
var hashCode = 1;
|
|
163
|
-
hashCode = 31 * hashCode + precedence;
|
|
164
|
-
return hashCode;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
@override
|
|
168
|
-
bool operator ==(Object obj) {
|
|
169
|
-
if (!(obj is PrecedencePredicate)) {
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
PrecedencePredicate other = obj;
|
|
173
|
-
return precedence == other.precedence;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// precedence >= _precedenceStack.peek()
|
|
177
|
-
@override
|
|
178
|
-
String toString() {
|
|
179
|
-
return '{$precedence>=prec}?';
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/// This is the base class for semantic context "operators", which operate on
|
|
184
|
-
/// a collection of semantic context "operands".
|
|
185
|
-
///
|
|
186
|
-
/// @since 4.3
|
|
187
|
-
abstract class Operator extends SemanticContext {
|
|
188
|
-
/// Gets the operands for the semantic context operator.
|
|
189
|
-
///
|
|
190
|
-
/// @return a collection of [SemanticContext] operands for the
|
|
191
|
-
/// operator.
|
|
192
|
-
///
|
|
193
|
-
/// @since 4.3
|
|
194
|
-
List<SemanticContext> get operands;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/// A semantic context which is true whenever none of the contained contexts
|
|
198
|
-
/// is false.
|
|
199
|
-
|
|
200
|
-
class AND extends Operator {
|
|
201
|
-
List<SemanticContext> opnds;
|
|
202
|
-
|
|
203
|
-
AND(SemanticContext a, SemanticContext b) {
|
|
204
|
-
var operands = <SemanticContext>{};
|
|
205
|
-
if (a is AND) {
|
|
206
|
-
operands.addAll(a.opnds);
|
|
207
|
-
} else {
|
|
208
|
-
operands.add(a);
|
|
209
|
-
}
|
|
210
|
-
if (b is AND) {
|
|
211
|
-
operands.addAll(b.opnds);
|
|
212
|
-
} else {
|
|
213
|
-
operands.add(b);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
final precedencePredicates =
|
|
217
|
-
SemanticContext.filterPrecedencePredicates(operands);
|
|
218
|
-
|
|
219
|
-
operands = SemanticContext.filterNonPrecedencePredicates(operands).toSet();
|
|
220
|
-
if (precedencePredicates.isNotEmpty) {
|
|
221
|
-
// interested in the transition with the lowest precedence
|
|
222
|
-
final reduced =
|
|
223
|
-
precedencePredicates.reduce((a, b) => a.compareTo(b) <= 0 ? a : b);
|
|
224
|
-
operands.add(reduced);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
opnds = operands.toList();
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
@override
|
|
231
|
-
List<SemanticContext> get operands {
|
|
232
|
-
return opnds;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
@override
|
|
236
|
-
bool operator ==(Object obj) {
|
|
237
|
-
if (!(obj is AND)) return false;
|
|
238
|
-
AND other = obj;
|
|
239
|
-
return ListEquality().equals(opnds, other.opnds);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
@override
|
|
243
|
-
int get hashCode {
|
|
244
|
-
return MurmurHash.getHashCode(opnds, runtimeType.hashCode);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/// {@inheritDoc}
|
|
248
|
-
///
|
|
249
|
-
/// <p>
|
|
250
|
-
/// The evaluation of predicates by this context is short-circuiting, but
|
|
251
|
-
/// unordered.</p>
|
|
252
|
-
|
|
253
|
-
@override
|
|
254
|
-
bool eval(Recognizer parser, RuleContext parserCallStack) {
|
|
255
|
-
for (var opnd in opnds) {
|
|
256
|
-
if (!opnd.eval(parser, parserCallStack)) return false;
|
|
257
|
-
}
|
|
258
|
-
return true;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
@override
|
|
262
|
-
SemanticContext evalPrecedence(Recognizer parser,
|
|
263
|
-
RuleContext parserCallStack) {
|
|
264
|
-
var differs = false;
|
|
265
|
-
final operands = <SemanticContext>[];
|
|
266
|
-
for (var context in opnds) {
|
|
267
|
-
final evaluated =
|
|
268
|
-
context.evalPrecedence(parser, parserCallStack);
|
|
269
|
-
differs |= (evaluated != context);
|
|
270
|
-
if (evaluated == null) {
|
|
271
|
-
// The AND context is false if any element is false
|
|
272
|
-
return null;
|
|
273
|
-
} else if (evaluated != SemanticContext.NONE) {
|
|
274
|
-
// Reduce the result by skipping true elements
|
|
275
|
-
operands.add(evaluated);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
if (!differs) {
|
|
280
|
-
return this;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
if (operands.isEmpty) {
|
|
284
|
-
// all elements were true, so the AND context is true
|
|
285
|
-
return SemanticContext.NONE;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
var result = operands[0];
|
|
289
|
-
for (var i = 1; i < operands.length; i++) {
|
|
290
|
-
result = SemanticContext.and(result, operands[i]);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
return result;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
@override
|
|
297
|
-
String toString() {
|
|
298
|
-
return opnds.join('&&');
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/// A semantic context which is true whenever at least one of the contained
|
|
303
|
-
/// contexts is true.
|
|
304
|
-
class OR extends Operator {
|
|
305
|
-
List<SemanticContext> opnds;
|
|
306
|
-
|
|
307
|
-
OR(SemanticContext a, SemanticContext b) {
|
|
308
|
-
var operands = <SemanticContext>{};
|
|
309
|
-
if (a is OR) {
|
|
310
|
-
operands.addAll(a.opnds);
|
|
311
|
-
} else {
|
|
312
|
-
operands.add(a);
|
|
313
|
-
}
|
|
314
|
-
if (b is OR) {
|
|
315
|
-
operands.addAll(b.opnds);
|
|
316
|
-
} else {
|
|
317
|
-
operands.add(b);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
final precedencePredicates =
|
|
321
|
-
SemanticContext.filterPrecedencePredicates(operands);
|
|
322
|
-
|
|
323
|
-
operands = SemanticContext.filterNonPrecedencePredicates(operands).toSet();
|
|
324
|
-
if (precedencePredicates.isNotEmpty) {
|
|
325
|
-
// interested in the transition with the highest precedence
|
|
326
|
-
final reduced =
|
|
327
|
-
precedencePredicates.reduce((a, b) => a.compareTo(b) >= 0 ? a : b);
|
|
328
|
-
operands.add(reduced);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
opnds = operands.toList();
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
@override
|
|
335
|
-
List<SemanticContext> get operands {
|
|
336
|
-
return opnds;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
@override
|
|
340
|
-
bool operator ==(Object obj) {
|
|
341
|
-
if (!(obj is OR)) return false;
|
|
342
|
-
OR other = obj;
|
|
343
|
-
return ListEquality().equals(opnds, other.opnds);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
@override
|
|
347
|
-
int get hashCode {
|
|
348
|
-
return MurmurHash.getHashCode(opnds, runtimeType.hashCode);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/// {@inheritDoc}
|
|
352
|
-
///
|
|
353
|
-
/// <p>
|
|
354
|
-
/// The evaluation of predicates by this context is short-circuiting, but
|
|
355
|
-
/// unordered.</p>
|
|
356
|
-
|
|
357
|
-
@override
|
|
358
|
-
bool eval(Recognizer parser, RuleContext parserCallStack) {
|
|
359
|
-
for (var opnd in opnds) {
|
|
360
|
-
if (opnd.eval(parser, parserCallStack)) return true;
|
|
361
|
-
}
|
|
362
|
-
return false;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
@override
|
|
366
|
-
SemanticContext evalPrecedence(Recognizer parser,
|
|
367
|
-
RuleContext parserCallStack) {
|
|
368
|
-
var differs = false;
|
|
369
|
-
final operands = <SemanticContext>[];
|
|
370
|
-
for (var context in opnds) {
|
|
371
|
-
final evaluated =
|
|
372
|
-
context.evalPrecedence(parser, parserCallStack);
|
|
373
|
-
differs |= (evaluated != context);
|
|
374
|
-
if (evaluated == SemanticContext.NONE) {
|
|
375
|
-
// The OR context is true if any element is true
|
|
376
|
-
return SemanticContext.NONE;
|
|
377
|
-
} else if (evaluated != null) {
|
|
378
|
-
// Reduce the result by skipping false elements
|
|
379
|
-
operands.add(evaluated);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
if (!differs) {
|
|
384
|
-
return this;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
if (operands.isEmpty) {
|
|
388
|
-
// all elements were false, so the OR context is false
|
|
389
|
-
return null;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
var result = operands[0];
|
|
393
|
-
for (var i = 1; i < operands.length; i++) {
|
|
394
|
-
result = SemanticContext.or(result, operands[i]);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
return result;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
@override
|
|
401
|
-
String toString() {
|
|
402
|
-
return opnds.join('||');
|
|
403
|
-
}
|
|
404
|
-
}
|