cariboujs 2.0.3 → 2.0.5
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/README.md +330 -324
- package/ada/ada2012/AdaLexer.js +486 -316
- package/ada/ada2012/AdaLexerBase.js +25 -0
- package/ada/ada2012/AdaParser.js +4547 -3823
- package/ada/ada2012/AdaParserBase.js +682 -0
- package/ada/ada2012/AdaParserListener.js +36 -0
- package/ada/ada2012/AdaParserVisitor.js +24 -0
- package/ada/ada2012/Symbol.js +20 -0
- package/ada/ada2012/SymbolTable.js +144 -0
- package/ada/ada2012/TypeClassification.js +15 -0
- package/ada/ada2022/AdaLexer.js +699 -0
- package/ada/ada2022/AdaLexerBase.js +25 -0
- package/ada/ada2022/AdaParser.js +37818 -0
- package/ada/ada2022/AdaParserBase.js +686 -0
- package/ada/ada2022/AdaParserListener.js +3024 -0
- package/ada/ada2022/AdaParserVisitor.js +2020 -0
- package/ada/ada2022/Symbol.js +20 -0
- package/ada/ada2022/SymbolTable.js +144 -0
- package/ada/ada2022/TypeClassification.js +15 -0
- package/c/CLexer.js +846 -603
- package/c/CLexerBase.js +96 -0
- package/c/CParser.js +8798 -4776
- package/c/CParserBase.js +591 -0
- package/c/{CListener.js → CParserListener.js} +382 -112
- package/c/{CVisitor.js → CParserVisitor.js} +252 -72
- package/c/ErrorListener.js +50 -0
- package/c/Symbol.js +28 -0
- package/c/SymbolTable.js +215 -0
- package/c/TypeClassification.js +21 -0
- package/cpp/CPP14Parser.js +215 -215
- package/cpp/CPP14ParserListener.js +56 -56
- package/cpp/CPP14ParserVisitor.js +28 -28
- package/cql3/CqlLexer.js +708 -692
- package/cql3/CqlParser.js +3356 -2802
- package/cql3/CqlParserListener.js +36 -0
- package/cql3/CqlParserVisitor.js +24 -0
- package/csharp/v7/CSharpLexer.js +1339 -0
- package/csharp/v7/CSharpLexerBase.js +332 -0
- package/csharp/v7/CSharpParser.js +29239 -0
- package/csharp/v7/CSharpParserBase.js +48 -0
- package/csharp/v7/CSharpParserListener.js +2304 -0
- package/csharp/v7/CSharpParserVisitor.js +1540 -0
- package/csharp/v8-spec/CSharpLexer.js +1549 -0
- package/csharp/v8-spec/CSharpLexerBase.js +296 -0
- package/csharp/v8-spec/CSharpParser.js +45044 -0
- package/csharp/v8-spec/CSharpParserBase.js +569 -0
- package/csharp/v8-spec/CSharpParserListener.js +3582 -0
- package/csharp/v8-spec/CSharpParserVisitor.js +2392 -0
- package/geekcode/geekcodeLexer.js +232 -0
- package/geekcode/geekcodeListener.js +81 -0
- package/geekcode/geekcodeParser.js +1516 -0
- package/geekcode/geekcodeVisitor.js +58 -0
- package/kotlin/kotlin/KotlinLexer.js +1257 -1247
- package/kotlin/kotlin/KotlinParser.js +3991 -3425
- package/kotlin/kotlin/KotlinParserListener.js +36 -0
- package/kotlin/kotlin/KotlinParserVisitor.js +24 -0
- package/package.json +1 -1
- package/plantUML/PlantUMLLexer.js +215 -316
- package/plantUML/PlantUMLParser.js +1045 -2393
- package/plantUML/PlantUMLParserListener.js +171 -0
- package/plantUML/PlantUMLParserVisitor.js +118 -0
- package/sql/cockroachdb/CockroachDBLexer.js +3865 -0
- package/sql/cockroachdb/CockroachDBParser.js +123259 -0
- package/sql/cockroachdb/CockroachDBParserListener.js +7281 -0
- package/sql/cockroachdb/CockroachDBParserVisitor.js +4858 -0
- package/sql/plsql/PlSqlParser.js +27187 -42911
- package/sql/plsql/PlSqlParserBase.js +30 -0
- package/sql/plsql/PlSqlParserListener.js +0 -9
- package/sql/plsql/PlSqlParserVisitor.js +0 -6
- package/sql/snowflake/SnowflakeLexer.js +5675 -5497
- package/sql/snowflake/SnowflakeParser.js +27230 -22653
- package/sql/snowflake/SnowflakeParserListener.js +278 -8
- package/sql/snowflake/SnowflakeParserVisitor.js +184 -4
- package/sql/sqlite/SQLiteParser.js +1115 -1115
- package/sql/sqlite/SQLiteParserListener.js +9 -9
- package/sql/sqlite/SQLiteParserVisitor.js +6 -6
- package/sysml-v2/SysMLv2Lexer.js +1047 -0
- package/sysml-v2/SysMLv2Parser.js +51339 -0
- package/sysml-v2/SysMLv2ParserListener.js +4464 -0
- package/sysml-v2/SysMLv2ParserVisitor.js +2980 -0
- package/plantUML/PlantUMLListener.js +0 -279
- package/plantUML/PlantUMLVisitor.js +0 -190
|
@@ -0,0 +1,682 @@
|
|
|
1
|
+
import antlr4 from 'antlr4';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import pathModule from 'path';
|
|
4
|
+
import AdaLexer from './AdaLexer.js';
|
|
5
|
+
import AdaParser from './AdaParser.js';
|
|
6
|
+
import Symbol from './Symbol.js';
|
|
7
|
+
import SymbolTable from './SymbolTable.js';
|
|
8
|
+
import TypeClassification from './TypeClassification.js';
|
|
9
|
+
|
|
10
|
+
const ALL_SEMANTIC_FUNCTIONS = ["IsAggregate", "IsTypeName"];
|
|
11
|
+
|
|
12
|
+
function parseNoSemantics(args) {
|
|
13
|
+
var result = new Set();
|
|
14
|
+
if (!args) return result;
|
|
15
|
+
for (var a of args) {
|
|
16
|
+
if (a.toLowerCase().startsWith("--no-semantics")) {
|
|
17
|
+
var eqIndex = a.indexOf('=');
|
|
18
|
+
if (eqIndex === -1) {
|
|
19
|
+
for (var func of ALL_SEMANTIC_FUNCTIONS) {
|
|
20
|
+
result.add(func);
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
var value = a.substring(eqIndex + 1);
|
|
24
|
+
var funcs = value.split(',');
|
|
25
|
+
for (var f of funcs) {
|
|
26
|
+
result.add(f.trim());
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
class SimpleTokenSource {
|
|
35
|
+
constructor(tokens) {
|
|
36
|
+
this.tokens = tokens;
|
|
37
|
+
this.pos = 0;
|
|
38
|
+
}
|
|
39
|
+
nextToken() {
|
|
40
|
+
if (this.pos >= this.tokens.length) {
|
|
41
|
+
return this.tokens[this.tokens.length - 1];
|
|
42
|
+
}
|
|
43
|
+
return this.tokens[this.pos++];
|
|
44
|
+
}
|
|
45
|
+
getSourceName() { return "pragma"; }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default class AdaParserBase extends antlr4.Parser {
|
|
49
|
+
constructor(input) {
|
|
50
|
+
super(input);
|
|
51
|
+
this._st = new SymbolTable();
|
|
52
|
+
this._expectedTypeStack = [];
|
|
53
|
+
this._debug = false;
|
|
54
|
+
this._outputSymbolTable = false;
|
|
55
|
+
this._outputAppliedOccurrences = false;
|
|
56
|
+
this._noSemantics = new Set();
|
|
57
|
+
this._searchPaths = [];
|
|
58
|
+
this._currentFile = "";
|
|
59
|
+
this._initOptions();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
_initOptions() {
|
|
63
|
+
var args = (typeof process !== 'undefined' && process.argv) ? process.argv : [];
|
|
64
|
+
this._noSemantics = parseNoSemantics(args);
|
|
65
|
+
this._debug = args.some(a => a.toLowerCase().indexOf("--debug") >= 0);
|
|
66
|
+
this._outputSymbolTable = args.some(a => a.toLowerCase().indexOf("--output-symbol-table") >= 0);
|
|
67
|
+
this._outputAppliedOccurrences = args.some(a => a.toLowerCase().indexOf("--output-applied-occurrences") >= 0);
|
|
68
|
+
for (var a of args) {
|
|
69
|
+
if (a.toLowerCase().startsWith("--i") && a.length > 3) {
|
|
70
|
+
this._searchPaths.push(a.substring(3));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
IsAggregate() {
|
|
76
|
+
if (this._noSemantics.has("IsAggregate")) return true;
|
|
77
|
+
var stream = this._input;
|
|
78
|
+
var lt1 = stream.LT(1);
|
|
79
|
+
if (lt1.type !== AdaLexer.LP) {
|
|
80
|
+
if (this._debug) process.stderr.write("IsAggregate: LT(1) is not LP, returning false\n");
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
// Structural scan from LT(2), tracking paren depth
|
|
84
|
+
var depth = 0;
|
|
85
|
+
for (var i = 2; ; i++) {
|
|
86
|
+
var t = stream.LT(i);
|
|
87
|
+
if (t === null || t.type === antlr4.Token.EOF) break;
|
|
88
|
+
if (t.type === AdaLexer.LP) {
|
|
89
|
+
depth++;
|
|
90
|
+
} else if (t.type === AdaLexer.RP) {
|
|
91
|
+
if (depth === 0) {
|
|
92
|
+
// Reached closing paren without indicators -- fall through to type context
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
depth--;
|
|
96
|
+
} else if (depth === 0) {
|
|
97
|
+
if (t.type === AdaLexer.COMMA) {
|
|
98
|
+
if (this._debug) process.stderr.write("IsAggregate: found COMMA at depth 0, returning true\n");
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
if (t.type === AdaLexer.ARROW) {
|
|
102
|
+
if (this._debug) process.stderr.write("IsAggregate: found ARROW at depth 0, returning true\n");
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
if (t.type === AdaLexer.WITH) {
|
|
106
|
+
if (this._debug) process.stderr.write("IsAggregate: found WITH at depth 0, returning true\n");
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
if (t.type === AdaLexer.NULL_) {
|
|
110
|
+
var next = stream.LT(i + 1);
|
|
111
|
+
if (next !== null && next.type === AdaLexer.RECORD) {
|
|
112
|
+
if (this._debug) process.stderr.write("IsAggregate: found NULL RECORD at depth 0, returning true\n");
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// Type-context check
|
|
119
|
+
if (this._expectedTypeStack.length > 0) {
|
|
120
|
+
var expected = this._expectedTypeStack[this._expectedTypeStack.length - 1];
|
|
121
|
+
if (expected !== null && expected.isComposite) {
|
|
122
|
+
if (this._debug) process.stderr.write("IsAggregate: expected type is composite, returning true\n");
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (this._debug) process.stderr.write("IsAggregate: no aggregate indicators, returning false\n");
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
IsTypeName() {
|
|
131
|
+
if (this._noSemantics.has("IsTypeName")) return true;
|
|
132
|
+
var stream = this._input;
|
|
133
|
+
var lt1 = stream.LT(1);
|
|
134
|
+
if (lt1.type !== AdaLexer.IDENTIFIER_) {
|
|
135
|
+
if (this._debug) process.stderr.write("IsTypeName: LT(1) is not IDENTIFIER_, returning false\n");
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
// Collect dotted name — but for lookup use just first component
|
|
139
|
+
var firstName = lt1.text;
|
|
140
|
+
var resolved = this._st.resolve(firstName);
|
|
141
|
+
if (resolved !== null && resolved.classification.has(TypeClassification.TypeName_)) {
|
|
142
|
+
if (this._debug) process.stderr.write("IsTypeName: " + firstName + " resolved as TypeName_, returning true\n");
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
if (this._debug) process.stderr.write("IsTypeName: " + firstName + " not a type name, returning false\n");
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
EnterDeclaration() {
|
|
150
|
+
if (this._debug) process.stderr.write("EnterDeclaration\n");
|
|
151
|
+
var context = this._ctx;
|
|
152
|
+
for (; context !== null; context = context.parentCtx) {
|
|
153
|
+
if (context instanceof AdaParser.Full_type_declarationContext) {
|
|
154
|
+
var defId = context.defining_identifier();
|
|
155
|
+
if (defId !== null) {
|
|
156
|
+
var name = defId.getText();
|
|
157
|
+
var isComposite = false;
|
|
158
|
+
var typeDef = context.type_definition();
|
|
159
|
+
if (typeDef !== null) {
|
|
160
|
+
isComposite = typeDef.record_type_definition() !== null
|
|
161
|
+
|| typeDef.array_type_definition() !== null;
|
|
162
|
+
}
|
|
163
|
+
this._defineSymbol(name, TypeClassification.TypeName_, defId.start, isComposite);
|
|
164
|
+
}
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (context instanceof AdaParser.Subtype_declarationContext) {
|
|
168
|
+
var defId = context.defining_identifier();
|
|
169
|
+
if (defId !== null) {
|
|
170
|
+
var name = defId.getText();
|
|
171
|
+
var isComposite = false;
|
|
172
|
+
var si = context.subtype_indication();
|
|
173
|
+
if (si !== null) {
|
|
174
|
+
var sm = si.subtype_mark();
|
|
175
|
+
if (sm !== null) {
|
|
176
|
+
var baseSym = this._st.resolve(sm.getText());
|
|
177
|
+
if (baseSym !== null) isComposite = baseSym.isComposite;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
this._defineSymbol(name, TypeClassification.TypeName_, defId.start, isComposite);
|
|
181
|
+
}
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (context instanceof AdaParser.Object_declarationContext) {
|
|
185
|
+
var defIdList = context.defining_identifier_list();
|
|
186
|
+
if (defIdList !== null) {
|
|
187
|
+
var defIds = defIdList.defining_identifier();
|
|
188
|
+
for (var di of defIds) {
|
|
189
|
+
this._defineSymbol(di.getText(), TypeClassification.ObjectName_, di.start);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (context instanceof AdaParser.Number_declarationContext) {
|
|
195
|
+
var defIdList = context.defining_identifier_list();
|
|
196
|
+
if (defIdList !== null) {
|
|
197
|
+
var defIds = defIdList.defining_identifier();
|
|
198
|
+
for (var di of defIds) {
|
|
199
|
+
this._defineSymbol(di.getText(), TypeClassification.ObjectName_, di.start);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (context instanceof AdaParser.Subprogram_declarationContext) {
|
|
205
|
+
this._defineSubprogramFromSpec(context.subprogram_specification());
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (context instanceof AdaParser.Subprogram_bodyContext) {
|
|
209
|
+
this._defineSubprogramFromSpec(context.subprogram_specification());
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (context instanceof AdaParser.Package_declarationContext) {
|
|
213
|
+
var pkgSpec = context.package_specification();
|
|
214
|
+
if (pkgSpec !== null) {
|
|
215
|
+
var dpun = pkgSpec.defining_program_unit_name();
|
|
216
|
+
if (dpun !== null) {
|
|
217
|
+
var defId = dpun.defining_identifier();
|
|
218
|
+
if (defId !== null)
|
|
219
|
+
this._defineSymbol(defId.getText(), TypeClassification.PackageName_, defId.start);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (context instanceof AdaParser.Package_bodyContext) {
|
|
225
|
+
var dpun = context.defining_program_unit_name();
|
|
226
|
+
if (dpun !== null) {
|
|
227
|
+
var defId = dpun.defining_identifier();
|
|
228
|
+
if (defId !== null)
|
|
229
|
+
this._defineSymbol(defId.getText(), TypeClassification.PackageName_, defId.start);
|
|
230
|
+
}
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (context instanceof AdaParser.Exception_declarationContext) {
|
|
234
|
+
var defIdList = context.defining_identifier_list();
|
|
235
|
+
if (defIdList !== null) {
|
|
236
|
+
var defIds = defIdList.defining_identifier();
|
|
237
|
+
for (var di of defIds) {
|
|
238
|
+
this._defineSymbol(di.getText(), TypeClassification.ExceptionName_, di.start);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (context instanceof AdaParser.Task_type_declarationContext) {
|
|
244
|
+
var defId = context.defining_identifier();
|
|
245
|
+
if (defId !== null)
|
|
246
|
+
this._defineSymbol(defId.getText(), TypeClassification.TypeName_, defId.start);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (context instanceof AdaParser.Single_task_declarationContext) {
|
|
250
|
+
var defId = context.defining_identifier();
|
|
251
|
+
if (defId !== null)
|
|
252
|
+
this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (context instanceof AdaParser.Protected_type_declarationContext) {
|
|
256
|
+
var defId = context.defining_identifier();
|
|
257
|
+
if (defId !== null)
|
|
258
|
+
this._defineSymbol(defId.getText(), TypeClassification.TypeName_, defId.start);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (context instanceof AdaParser.Single_protected_declarationContext) {
|
|
262
|
+
var defId = context.defining_identifier();
|
|
263
|
+
if (defId !== null)
|
|
264
|
+
this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (context instanceof AdaParser.Entry_declarationContext) {
|
|
268
|
+
var defId = context.defining_identifier();
|
|
269
|
+
if (defId !== null)
|
|
270
|
+
this._defineSymbol(defId.getText(), TypeClassification.SubprogramName_, defId.start);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (context instanceof AdaParser.Component_declarationContext) {
|
|
274
|
+
var defIdList = context.defining_identifier_list();
|
|
275
|
+
if (defIdList !== null) {
|
|
276
|
+
var defIds = defIdList.defining_identifier();
|
|
277
|
+
for (var di of defIds) {
|
|
278
|
+
this._defineSymbol(di.getText(), TypeClassification.ComponentName_, di.start);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (context instanceof AdaParser.Incomplete_type_declarationContext) {
|
|
284
|
+
var defId = context.defining_identifier();
|
|
285
|
+
if (defId !== null)
|
|
286
|
+
this._defineSymbol(defId.getText(), TypeClassification.TypeName_, defId.start);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (context instanceof AdaParser.Private_type_declarationContext) {
|
|
290
|
+
var defId = context.defining_identifier();
|
|
291
|
+
if (defId !== null)
|
|
292
|
+
this._defineSymbol(defId.getText(), TypeClassification.TypeName_, defId.start);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
if (context instanceof AdaParser.Private_extension_declarationContext) {
|
|
296
|
+
var defId = context.defining_identifier();
|
|
297
|
+
if (defId !== null)
|
|
298
|
+
this._defineSymbol(defId.getText(), TypeClassification.TypeName_, defId.start, true);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (context instanceof AdaParser.Generic_instantiationContext) {
|
|
302
|
+
var dpuns = context.defining_program_unit_name();
|
|
303
|
+
if (dpuns !== null && dpuns.length > 0) {
|
|
304
|
+
var dpun = dpuns[0];
|
|
305
|
+
var defId = dpun.defining_identifier();
|
|
306
|
+
if (defId !== null) {
|
|
307
|
+
var tc = TypeClassification.PackageName_;
|
|
308
|
+
if (context.PROCEDURE() !== null) tc = TypeClassification.SubprogramName_;
|
|
309
|
+
else if (context.FUNCTION() !== null) tc = TypeClassification.SubprogramName_;
|
|
310
|
+
this._defineSymbol(defId.getText(), tc, defId.start);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
var dds = context.defining_designator();
|
|
314
|
+
if (dds !== null && dds.length > 0) {
|
|
315
|
+
var dd = dds[0];
|
|
316
|
+
var dpun = dd.defining_program_unit_name();
|
|
317
|
+
if (dpun !== null) {
|
|
318
|
+
var defId = dpun.defining_identifier();
|
|
319
|
+
if (defId !== null)
|
|
320
|
+
this._defineSymbol(defId.getText(), TypeClassification.SubprogramName_, defId.start);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (context instanceof AdaParser.Object_renaming_declarationContext) {
|
|
326
|
+
var defId = context.defining_identifier();
|
|
327
|
+
if (defId !== null)
|
|
328
|
+
this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
if (context instanceof AdaParser.Exception_renaming_declarationContext) {
|
|
332
|
+
var defId = context.defining_identifier();
|
|
333
|
+
if (defId !== null)
|
|
334
|
+
this._defineSymbol(defId.getText(), TypeClassification.ExceptionName_, defId.start);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (context instanceof AdaParser.Package_renaming_declarationContext) {
|
|
338
|
+
var dpun = context.defining_program_unit_name();
|
|
339
|
+
if (dpun !== null) {
|
|
340
|
+
var defId = dpun.defining_identifier();
|
|
341
|
+
if (defId !== null)
|
|
342
|
+
this._defineSymbol(defId.getText(), TypeClassification.PackageName_, defId.start);
|
|
343
|
+
}
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
if (context instanceof AdaParser.Formal_complete_type_declarationContext) {
|
|
347
|
+
var defId = context.defining_identifier();
|
|
348
|
+
if (defId !== null)
|
|
349
|
+
this._defineSymbol(defId.getText(), TypeClassification.TypeName_, defId.start);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (context instanceof AdaParser.Formal_incomplete_type_declarationContext) {
|
|
353
|
+
var defId = context.defining_identifier();
|
|
354
|
+
if (defId !== null)
|
|
355
|
+
this._defineSymbol(defId.getText(), TypeClassification.TypeName_, defId.start);
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
if (context instanceof AdaParser.Formal_object_declarationContext) {
|
|
359
|
+
var defIdList = context.defining_identifier_list();
|
|
360
|
+
if (defIdList !== null) {
|
|
361
|
+
var defIds = defIdList.defining_identifier();
|
|
362
|
+
for (var di of defIds) {
|
|
363
|
+
this._defineSymbol(di.getText(), TypeClassification.ObjectName_, di.start);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
if (context instanceof AdaParser.Formal_package_declarationContext) {
|
|
369
|
+
var defId = context.defining_identifier();
|
|
370
|
+
if (defId !== null)
|
|
371
|
+
this._defineSymbol(defId.getText(), TypeClassification.PackageName_, defId.start);
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
if (context instanceof AdaParser.Parameter_specificationContext) {
|
|
375
|
+
var defIdList = context.defining_identifier_list();
|
|
376
|
+
if (defIdList !== null) {
|
|
377
|
+
var defIds = defIdList.defining_identifier();
|
|
378
|
+
for (var di of defIds) {
|
|
379
|
+
this._defineSymbol(di.getText(), TypeClassification.ObjectName_, di.start);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
if (context instanceof AdaParser.Loop_parameter_specificationContext) {
|
|
385
|
+
var defId = context.defining_identifier();
|
|
386
|
+
if (defId !== null)
|
|
387
|
+
this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (context instanceof AdaParser.Iterator_specificationContext) {
|
|
391
|
+
var defId = context.defining_identifier();
|
|
392
|
+
if (defId !== null)
|
|
393
|
+
this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
if (context instanceof AdaParser.Enumeration_literal_specificationContext) {
|
|
397
|
+
var defId = context.defining_identifier();
|
|
398
|
+
if (defId !== null)
|
|
399
|
+
this._defineSymbol(defId.getText(), TypeClassification.EnumerationLiteral_, defId.start);
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
if (context instanceof AdaParser.Choice_parameter_specificationContext) {
|
|
403
|
+
var defId = context.defining_identifier();
|
|
404
|
+
if (defId !== null)
|
|
405
|
+
this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
if (context instanceof AdaParser.Entry_index_specificationContext) {
|
|
409
|
+
var defId = context.defining_identifier();
|
|
410
|
+
if (defId !== null)
|
|
411
|
+
this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
if (context instanceof AdaParser.Extended_return_object_declarationContext) {
|
|
415
|
+
var defId = context.defining_identifier();
|
|
416
|
+
if (defId !== null)
|
|
417
|
+
this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
if (context instanceof AdaParser.Entry_bodyContext) {
|
|
421
|
+
var defId = context.defining_identifier();
|
|
422
|
+
if (defId !== null)
|
|
423
|
+
this._defineSymbol(defId.getText(), TypeClassification.SubprogramName_, defId.start);
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
if (context instanceof AdaParser.Task_bodyContext) {
|
|
427
|
+
var defId = context.defining_identifier();
|
|
428
|
+
if (defId !== null)
|
|
429
|
+
this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
if (context instanceof AdaParser.Protected_bodyContext) {
|
|
433
|
+
var defId = context.defining_identifier();
|
|
434
|
+
if (defId !== null)
|
|
435
|
+
this._defineSymbol(defId.getText(), TypeClassification.ObjectName_, defId.start);
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
if (context instanceof AdaParser.Discriminant_specificationContext) {
|
|
439
|
+
var defIdList = context.defining_identifier_list();
|
|
440
|
+
if (defIdList !== null) {
|
|
441
|
+
var defIds = defIdList.defining_identifier();
|
|
442
|
+
for (var di of defIds) {
|
|
443
|
+
this._defineSymbol(di.getText(), TypeClassification.ObjectName_, di.start);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
_defineSubprogramFromSpec(spec) {
|
|
452
|
+
if (spec === null) return;
|
|
453
|
+
var procSpec = spec.procedure_specification();
|
|
454
|
+
if (procSpec !== null) {
|
|
455
|
+
var dpun = procSpec.defining_program_unit_name();
|
|
456
|
+
if (dpun !== null) {
|
|
457
|
+
var defId = dpun.defining_identifier();
|
|
458
|
+
if (defId !== null)
|
|
459
|
+
this._defineSymbol(defId.getText(), TypeClassification.SubprogramName_, defId.start);
|
|
460
|
+
}
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
var funcSpec = spec.function_specification();
|
|
464
|
+
if (funcSpec !== null) {
|
|
465
|
+
var dd = funcSpec.defining_designator();
|
|
466
|
+
if (dd !== null) {
|
|
467
|
+
var dpun = dd.defining_program_unit_name();
|
|
468
|
+
if (dpun !== null) {
|
|
469
|
+
var defId = dpun.defining_identifier();
|
|
470
|
+
if (defId !== null)
|
|
471
|
+
this._defineSymbol(defId.getText(), TypeClassification.SubprogramName_, defId.start);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
_defineSymbol(name, classification, token, isComposite) {
|
|
478
|
+
var s = new Symbol();
|
|
479
|
+
s.name = name;
|
|
480
|
+
s.classification = new Set([classification]);
|
|
481
|
+
s.isComposite = isComposite || false;
|
|
482
|
+
s.definedFile = (token && token.source && token.source[0]) ? token.source[0].sourceName || "" : "";
|
|
483
|
+
s.definedLine = token ? token.line || 0 : 0;
|
|
484
|
+
s.definedColumn = token ? token.column || 0 : 0;
|
|
485
|
+
this._st.define(s);
|
|
486
|
+
if (this._debug) process.stderr.write("Defined symbol: " + s.toString() + "\n");
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
EnterScope() {
|
|
490
|
+
if (this._debug) process.stderr.write("EnterScope\n");
|
|
491
|
+
this._st.pushBlockScope();
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
ExitScope() {
|
|
495
|
+
if (this._debug) process.stderr.write("ExitScope\n");
|
|
496
|
+
this._st.popBlockScope();
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
PushExpectedType() {
|
|
500
|
+
this._expectedTypeStack.push(null);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
PopExpectedType() {
|
|
504
|
+
if (this._expectedTypeStack.length > 0) {
|
|
505
|
+
this._expectedTypeStack.pop();
|
|
506
|
+
if (this._debug) process.stderr.write("PopExpectedType\n");
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
OutputSymbolTable() {
|
|
511
|
+
if (this._outputSymbolTable) {
|
|
512
|
+
process.stderr.write(this._st.toString());
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
ImportWithClause() {
|
|
517
|
+
if (this._noSemantics.has("IsTypeName") && this._noSemantics.has("IsAggregate")) return;
|
|
518
|
+
|
|
519
|
+
// Auto-detect current file from the token stream if not already set
|
|
520
|
+
if (!this._currentFile) {
|
|
521
|
+
var stream = this._input;
|
|
522
|
+
var sourceName = stream && stream.tokenSource && stream.tokenSource.inputStream ? stream.tokenSource.inputStream.name : null;
|
|
523
|
+
if (sourceName && sourceName !== "unknown" && fs.existsSync(sourceName)) {
|
|
524
|
+
this._currentFile = pathModule.resolve(sourceName);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
var context = this._ctx;
|
|
529
|
+
var names = null;
|
|
530
|
+
if (context instanceof AdaParser.Nonlimited_with_clauseContext) {
|
|
531
|
+
names = context.name();
|
|
532
|
+
} else if (context instanceof AdaParser.Limited_with_clauseContext) {
|
|
533
|
+
names = context.name();
|
|
534
|
+
}
|
|
535
|
+
if (!names || names.length === 0) return;
|
|
536
|
+
|
|
537
|
+
for (var ni = 0; ni < names.length; ni++) {
|
|
538
|
+
var nameCtx = names[ni];
|
|
539
|
+
var packageName = nameCtx.getText();
|
|
540
|
+
if (this._debug) process.stderr.write("ImportWithClause: processing 'with " + packageName + "'\n");
|
|
541
|
+
|
|
542
|
+
var fileName = this._packageNameToFileName(packageName);
|
|
543
|
+
var cacheKey = packageName.toLowerCase();
|
|
544
|
+
|
|
545
|
+
if (AdaParserBase._packageCache.has(cacheKey)) {
|
|
546
|
+
if (this._debug) process.stderr.write("ImportWithClause: using cached symbols for " + packageName + "\n");
|
|
547
|
+
var cachedSymbols = AdaParserBase._packageCache.get(cacheKey);
|
|
548
|
+
for (var ci = 0; ci < cachedSymbols.length; ci++) {
|
|
549
|
+
var sym = cachedSymbols[ci];
|
|
550
|
+
var copy = new Symbol();
|
|
551
|
+
copy.name = sym.name;
|
|
552
|
+
copy.classification = new Set(sym.classification);
|
|
553
|
+
copy.isComposite = sym.isComposite;
|
|
554
|
+
copy.definedFile = sym.definedFile;
|
|
555
|
+
copy.definedLine = sym.definedLine;
|
|
556
|
+
copy.definedColumn = sym.definedColumn;
|
|
557
|
+
this._st.define(copy);
|
|
558
|
+
}
|
|
559
|
+
continue;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
var adsPath = this._findAdsFile(fileName);
|
|
563
|
+
if (adsPath === null) {
|
|
564
|
+
if (this._debug) process.stderr.write("ImportWithClause: could not find " + fileName + "\n");
|
|
565
|
+
continue;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
var fullPath = pathModule.resolve(adsPath).toLowerCase();
|
|
569
|
+
if (AdaParserBase._parsingInProgress.has(fullPath)) {
|
|
570
|
+
if (this._debug) process.stderr.write("ImportWithClause: skipping " + fileName + " (cycle detected)\n");
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
var symbols = this._parseAdsFile(adsPath);
|
|
575
|
+
if (symbols !== null) {
|
|
576
|
+
AdaParserBase._packageCache.set(cacheKey, symbols);
|
|
577
|
+
for (var si = 0; si < symbols.length; si++) {
|
|
578
|
+
var sym = symbols[si];
|
|
579
|
+
var copy = new Symbol();
|
|
580
|
+
copy.name = sym.name;
|
|
581
|
+
copy.classification = new Set(sym.classification);
|
|
582
|
+
copy.isComposite = sym.isComposite;
|
|
583
|
+
copy.definedFile = sym.definedFile;
|
|
584
|
+
copy.definedLine = sym.definedLine;
|
|
585
|
+
copy.definedColumn = sym.definedColumn;
|
|
586
|
+
this._st.define(copy);
|
|
587
|
+
if (this._debug) process.stderr.write("ImportWithClause: imported symbol " + sym.name + " from " + packageName + "\n");
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
_packageNameToFileName(packageName) {
|
|
594
|
+
return packageName.toLowerCase().replace(/\./g, '-') + ".ads";
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
_findAdsFile(fileName) {
|
|
598
|
+
if (this._currentFile) {
|
|
599
|
+
var dir = pathModule.dirname(this._currentFile);
|
|
600
|
+
var candidate = pathModule.join(dir, fileName);
|
|
601
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
602
|
+
}
|
|
603
|
+
for (var i = 0; i < this._searchPaths.length; i++) {
|
|
604
|
+
var candidate = pathModule.join(this._searchPaths[i], fileName);
|
|
605
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
606
|
+
}
|
|
607
|
+
return null;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
_parseAdsFile(adsPath) {
|
|
611
|
+
var fullPath = pathModule.resolve(adsPath).toLowerCase();
|
|
612
|
+
AdaParserBase._parsingInProgress.add(fullPath);
|
|
613
|
+
try {
|
|
614
|
+
if (this._debug) process.stderr.write("ImportWithClause: parsing " + adsPath + "\n");
|
|
615
|
+
var input = new antlr4.CharStream(fs.readFileSync(adsPath, 'utf-8'));
|
|
616
|
+
var lexer = new AdaLexer(input);
|
|
617
|
+
lexer.removeErrorListeners();
|
|
618
|
+
var tokenStream = new antlr4.CommonTokenStream(lexer);
|
|
619
|
+
var parser = new AdaParser(tokenStream);
|
|
620
|
+
parser.removeErrorListeners();
|
|
621
|
+
parser._currentFile = pathModule.resolve(adsPath);
|
|
622
|
+
parser.compilation();
|
|
623
|
+
return parser._st.getExportedSymbols();
|
|
624
|
+
} catch (ex) {
|
|
625
|
+
if (this._debug) process.stderr.write("ImportWithClause: error parsing " + adsPath + ": " + ex.message + "\n");
|
|
626
|
+
return null;
|
|
627
|
+
} finally {
|
|
628
|
+
AdaParserBase._parsingInProgress.delete(fullPath);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
ParsePragmas() {
|
|
633
|
+
var stream = this._input;
|
|
634
|
+
stream.fill();
|
|
635
|
+
var allTokens = stream.tokens;
|
|
636
|
+
var PRAGMA_CHANNEL = 2;
|
|
637
|
+
var currentPragma = null;
|
|
638
|
+
var pragmas = [];
|
|
639
|
+
for (var i = 0; i < allTokens.length; i++) {
|
|
640
|
+
var token = allTokens[i];
|
|
641
|
+
if (token.channel !== PRAGMA_CHANNEL) continue;
|
|
642
|
+
if (token.type === AdaLexer.PRAGMA) {
|
|
643
|
+
currentPragma = [token];
|
|
644
|
+
} else if (currentPragma !== null) {
|
|
645
|
+
currentPragma.push(token);
|
|
646
|
+
if (token.type === AdaLexer.SEMI) {
|
|
647
|
+
pragmas.push(currentPragma);
|
|
648
|
+
currentPragma = null;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
for (var j = 0; j < pragmas.length; j++) {
|
|
653
|
+
var pragmaTokens = pragmas[j];
|
|
654
|
+
var defaultChannelTokens = [];
|
|
655
|
+
for (var k = 0; k < pragmaTokens.length; k++) {
|
|
656
|
+
var t = pragmaTokens[k];
|
|
657
|
+
var ct = new antlr4.CommonToken(t.source, t.type, antlr4.Token.DEFAULT_CHANNEL, t.start, t.stop);
|
|
658
|
+
ct.text = t.text;
|
|
659
|
+
ct.line = t.line;
|
|
660
|
+
ct.column = t.column;
|
|
661
|
+
ct.tokenIndex = t.tokenIndex;
|
|
662
|
+
defaultChannelTokens.push(ct);
|
|
663
|
+
}
|
|
664
|
+
var eof = new antlr4.CommonToken([null, null], antlr4.Token.EOF, antlr4.Token.DEFAULT_CHANNEL, -1, -1);
|
|
665
|
+
defaultChannelTokens.push(eof);
|
|
666
|
+
var tokenSource = new SimpleTokenSource(defaultChannelTokens);
|
|
667
|
+
var tokenStream = new antlr4.CommonTokenStream(tokenSource);
|
|
668
|
+
var parser = new AdaParser(tokenStream);
|
|
669
|
+
parser.removeErrorListeners();
|
|
670
|
+
var listeners = this._listeners;
|
|
671
|
+
if (listeners) {
|
|
672
|
+
for (var l = 0; l < listeners.length; l++) {
|
|
673
|
+
parser.addErrorListener(listeners[l]);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
parser.pragmaRule();
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
AdaParserBase._packageCache = new Map();
|
|
682
|
+
AdaParserBase._parsingInProgress = new Set();
|