This repository has been archived by the owner on Dec 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
test_shallow.py
727 lines (557 loc) · 22.1 KB
/
test_shallow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
import shallow_indexer
import multiprocessing
import os
import sourcetraildb as srctrl
import sys
import unittest
class TestPythonIndexer(unittest.TestCase):
# Test Recording Symbols
def test_indexer_records_module_for_source_file(self):
client = self.indexSourceCode(
'\n'
)
self.assertTrue('MODULE: virtual_file' in client.symbols)
def test_indexer_records_module_scope_variable_as_global_variable(self):
client = self.indexSourceCode(
'foo = 9:\n'
)
self.assertTrue('GLOBAL_VARIABLE: virtual_file.foo at [1:1|1:3]' in client.symbols)
def test_indexer_records_function_definition(self):
client = self.indexSourceCode(
'def foo():\n'
' pass\n'
)
self.assertTrue('FUNCTION: virtual_file.foo at [1:5|1:7] with scope [1:1|3:0]' in client.symbols)
def test_indexer_records_class_definition(self):
client = self.indexSourceCode(
'class Foo:\n'
' pass\n'
)
self.assertTrue('CLASS: virtual_file.Foo at [1:7|1:9] with scope [1:1|3:0]' in client.symbols)
def test_indexer_records_member_function_definition(self):
client = self.indexSourceCode(
'class Foo:\n'
' def bar(self):\n'
' pass\n'
)
self.assertTrue('METHOD: virtual_file.Foo.bar at [2:6|2:8] with scope [2:2|4:0]' in client.symbols)
def test_indexer_records_static_field_definition(self):
client = self.indexSourceCode(
'class Foo:\n'
' bar = None\n'
)
self.assertTrue('FIELD: virtual_file.Foo.bar at [2:2|2:4]' in client.symbols)
def test_indexer_records_non_static_field_definition(self):
client = self.indexSourceCode(
'class Foo:\n'
' def bar(self):\n'
' self.x = None\n'
)
self.assertTrue('FIELD: virtual_file.Foo.x at [3:8|3:8]' in client.symbols)
# Test Recording Local Symbols
def test_indexer_records_usage_of_variable_with_multiple_definitions_as_single_local_symbols(self):
client = self.indexSourceCode(
'def foo(bar):\n'
' if bar:\n'
' baz = 9\n'
' else:\n'
' baz = 3\n'
' return baz\n'
'foo(True)\n'
'foo(False)\n'
)
self.assertTrue('virtual_file.foo<baz> at [6:9|6:11]' in client.localSymbols)
self.assertTrue('virtual_file.foo<baz> at [6:9|6:11]' in client.localSymbols)
def test_indexer_records_function_parameter_as_local_symbol(self):
client = self.indexSourceCode(
'def foo(bar):\n'
' pass\n'
)
self.assertTrue('virtual_file.foo<bar> at [1:9|1:11]' in client.localSymbols)
def test_indexer_records_usage_of_function_parameter_as_local_symbol(self):
client = self.indexSourceCode(
'def foo(bar):\n'
' x = bar\n'
)
self.assertTrue('virtual_file.foo<bar> at [2:6|2:8]' in client.localSymbols)
def test_indexer_records_usage_of_function_parameter_following_an_open_brace_as_local_symbol(self):
client = self.indexSourceCode(
'def foo(first):\n'
' foo(first)\n'
)
self.assertTrue('virtual_file.foo<first> at [2:6|2:10]' in client.localSymbols)
def test_indexer_records_function_scope_variable_as_local_symbol(self):
client = self.indexSourceCode(
'def foo():\n'
' x = 5\n'
)
self.assertTrue('virtual_file.foo<x> at [2:2|2:2]' in client.localSymbols)
def test_indexer_records_usage_of_function_scope_variable_as_local_symbol(self):
client = self.indexSourceCode(
'def foo():\n'
' x = 5\n'
' y = x\n'
)
self.assertTrue('virtual_file.foo<x> at [3:6|3:6]' in client.localSymbols)
def test_indexer_records_method_scope_variable_as_local_symbol(self):
client = self.indexSourceCode(
'class Foo:\n'
' def bar(self):\n'
' baz = 6\n'
)
self.assertTrue('virtual_file.Foo.bar<baz> at [3:3|3:5]' in client.localSymbols)
# Test Recording References
def test_indexer_records_import_of_builtin_module(self):
client = self.indexSourceCode(
'import itertools\n',
)
self.assertTrue('IMPORT: virtual_file -> unsolved symbol at [1:8|1:16]' in client.references)
def test_indexer_records_import_of_multiple_modules_with_single_import_statement(self):
client = self.indexSourceCode(
'import itertools, re\n'
)
self.assertTrue('IMPORT: virtual_file -> unsolved symbol at [1:8|1:16]' in client.references)
self.assertTrue('IMPORT: virtual_file -> unsolved symbol at [1:19|1:20]' in client.references)
def test_indexer_records_import_of_aliased_module_as_global_symbol(self):
# this is required to find matching name if "it" is used throughout the file
client = self.indexSourceCode(
'import itertools as it\n'
)
self.assertTrue('IMPORT: virtual_file -> unsolved symbol at [1:8|1:16]' in client.references)
self.assertTrue('GLOBAL_VARIABLE: virtual_file.it at [1:21|1:22]' in client.symbols)
def test_indexer_records_import_of_multiple_alised_modules_with_single_import_statement_as_global_symbols(self):
client = self.indexSourceCode(
'import itertools as it, re as regex\n'
)
self.assertTrue('IMPORT: virtual_file -> unsolved symbol at [1:8|1:16]' in client.references)
self.assertTrue('GLOBAL_VARIABLE: virtual_file.it at [1:21|1:22]' in client.symbols)
self.assertTrue('IMPORT: virtual_file -> unsolved symbol at [1:25|1:26]' in client.references)
self.assertTrue('GLOBAL_VARIABLE: virtual_file.regex at [1:31|1:35]' in client.symbols)
def test_indexer_records_import_of_function(self):
client = self.indexSourceCode(
'from re import match\n'
)
self.assertTrue('USAGE: virtual_file -> unsolved symbol at [1:6|1:7]' in client.references)
self.assertTrue('IMPORT: virtual_file -> unsolved symbol at [1:16|1:20]' in client.references)
def test_indexer_records_import_of_aliased_function(self):
client = self.indexSourceCode(
'from re import match as m\n'
)
self.assertTrue('USAGE: virtual_file -> unsolved symbol at [1:6|1:7]' in client.references)
self.assertTrue('IMPORT: virtual_file -> unsolved symbol at [1:16|1:20]' in client.references)
self.assertTrue('GLOBAL_VARIABLE: virtual_file.m at [1:25|1:25]' in client.symbols)
def test_indexer_records_import_of_multiple_aliased_functions_with_single_import_statement(self):
client = self.indexSourceCode(
'from re import match as m, escape as e\n'
)
self.assertTrue('USAGE: virtual_file -> unsolved symbol at [1:6|1:7]' in client.references)
self.assertTrue('IMPORT: virtual_file -> unsolved symbol at [1:16|1:20]' in client.references)
self.assertTrue('GLOBAL_VARIABLE: virtual_file.m at [1:25|1:25]' in client.symbols)
self.assertTrue('IMPORT: virtual_file -> unsolved symbol at [1:28|1:33]' in client.references)
self.assertTrue('GLOBAL_VARIABLE: virtual_file.e at [1:38|1:38]' in client.symbols)
def test_indexer_records_usage_of_imported_module(self):
client = self.indexSourceCode(
'import sys\n'
'dir(sys)\n'
)
self.assertTrue('USAGE: virtual_file -> unsolved symbol at [2:5|2:7]' in client.references)
def test_indexer_records_usage_for_access_of_other_class_field(self):
client = self.indexSourceCode(
'class Foo:\n'
' value = 0\n'
'\n'
'class Bar:\n'
' def baz(self):\n'
' foo = Foo()\n'
' foo.value = -10000\n'
)
self.assertTrue('USAGE: virtual_file.Bar.baz -> unsolved symbol at [7:7|7:11]' in client.references)
def test_indexer_records_single_class_inheritence(self):
client = self.indexSourceCode(
'class Foo:\n'
' pass\n'
'class Bar(Foo):\n'
' pass\n'
)
self.assertTrue('INHERITANCE: virtual_file.Bar -> unsolved symbol at [3:11|3:13]' in client.references)
def test_indexer_records_multiple_class_inheritence(self):
client = self.indexSourceCode(
'class Foo:\n'
' pass\n'
'class Bar():\n'
' pass\n'
'class Baz(Foo, Bar):\n'
' pass\n'
)
self.assertTrue('INHERITANCE: virtual_file.Baz -> unsolved symbol at [5:11|5:13]' in client.references)
self.assertTrue('INHERITANCE: virtual_file.Baz -> unsolved symbol at [5:16|5:18]' in client.references)
def test_indexer_records_instantiation_of_custom_class(self):
client = self.indexSourceCode(
'class Bar:\n'
' pass\n'
'\n'
'bar = Bar()\n'
)
self.assertTrue('CALL: virtual_file -> unsolved symbol at [4:7|4:9]' in client.references)
def test_indexer_records_instantiation_of_environment_class(self):
client = self.indexSourceCode(
'import itertools\n'
'itertools.cycle(None)\n'
)
self.assertTrue('CALL: virtual_file -> unsolved symbol at [2:11|2:15]' in client.references)
def test_indexer_records_usage_of_super_keyword(self):
client = self.indexSourceCode(
'class Foo(object):\n'
' def foo():\n'
' pass\n'
'\n'
'class Bar(Foo):\n'
' def bar(self):\n'
' super().foo()\n'
)
self.assertTrue('CALL: virtual_file.Bar.bar -> unsolved symbol at [7:3|7:7]' in client.references)
def test_indexer_records_usage_of_builtin_class(self):
client = self.indexSourceCode(
'foo = str(b"bar")\n'
)
self.assertTrue('CALL: virtual_file -> unsolved symbol at [1:7|1:9]' in client.references)
def test_indexer_records_call_to_builtin_function(self):
client = self.indexSourceCode(
'foo = "test string".islower()\n'
)
self.assertTrue('CALL: virtual_file -> unsolved symbol at [1:21|1:27]' in client.references)
def test_indexer_records_function_call(self):
client = self.indexSourceCode(
'def main():\n'
' pass\n'
'\n'
'main()\n'
)
self.assertTrue('CALL: virtual_file -> unsolved symbol at [4:1|4:4]' in client.references)
def test_indexer_does_not_record_static_field_initialization_as_usage(self):
client = self.indexSourceCode(
'class Foo:\n'
' x = 0\n'
)
for reference in client.references:
self.assertFalse(reference.startswith('USAGE: virtual_file.Foo -> unsolved symbol'))
def test_indexer_records_usage_of_static_field_via_self(self):
client = self.indexSourceCode(
'class Foo:\n'
' x = 0\n'
' def bar(self):\n'
' y = self.x\n'
)
self.assertTrue('USAGE: virtual_file.Foo.bar -> unsolved symbol at [4:12|4:12]' in client.references)
def test_indexer_records_initialization_of_non_static_field_via_self_as_usage(self):
client = self.indexSourceCode(
'class Foo:\n'
' def bar(self):\n'
' self.x = None\n',
)
self.assertTrue('USAGE: virtual_file.Foo.bar -> virtual_file.Foo.x at [3:8|3:8]' in client.references)
# Test Qualifiers
def test_indexer_records_module_as_qualifier_in_import_statement(self):
client = self.indexSourceCode(
'import pkg.mod\n',
[os.path.join(os.getcwd(), 'data', 'test')]
)
self.assertTrue('unsolved symbol at [1:8|1:10]' in client.qualifiers)
def test_indexer_records_module_as_qualifier_in_expression_statement(self):
client = self.indexSourceCode(
'import sys\n'
'print(sys.executable)\n'
)
self.assertTrue('unsolved symbol at [2:7|2:9]' in client.qualifiers)
def test_indexer_records_class_as_qualifier_in_expression_statement(self):
client = self.indexSourceCode(
'class Foo:\n'
' bar = 0\n'
'baz = Foo.bar\n'
)
self.assertTrue('unsolved symbol at [3:7|3:9]' in client.qualifiers)
# Test Atomic Ranges
def test_indexer_records_atomic_range_for_multi_line_string(self):
client = self.indexSourceCode(
'foo = """\n'
'\n'
'"""\n'
)
self.assertTrue('ATOMIC SOURCE RANGE: [1:7|3:3]' in client.atomicSourceRanges)
# Test Recording Errors
def test_indexer_records_syntax_error(self):
client = self.indexSourceCode(
'def foo()\n' # missing ':' character
' pass\n'
)
self.assertTrue('ERROR: "Unexpected token of type "INDENT" encountered." at [2:2|2:1]' in client.errors)
# Utility Functions
def indexSourceCode(self, sourceCode, sysPath = None, verbose = False):
workingDirectory = os.getcwd()
astVisitorClient = TestAstVisitorClient()
shallow_indexer.indexSourceCode(
sourceCode,
workingDirectory,
astVisitorClient,
verbose,
sysPath
)
astVisitorClient.updateReadableOutput()
return astVisitorClient
class TestAstVisitorClient():
def __init__(self):
self.symbols = []
self.localSymbols = []
self.references = []
self.qualifiers = []
self.atomicSourceRanges = []
self.errors = []
self.serializedSymbolsToIds = {}
self.symbolIdsToData = {}
self.serializedLocalSymbolsToIds = {}
self.localSymbolIdsToData = {}
self.serializedReferencesToIds = {}
self.referenceIdsToData = {}
self.qualifierIdsToData = {}
self.nextSymbolId = 1
def updateReadableOutput(self):
self.symbols = []
for key in self.symbolIdsToData:
symbolString = ''
if 'definition_kind' in self.symbolIdsToData[key]:
symbolString += self.symbolIdsToData[key]['definition_kind'] + ' '
else:
symbolString += 'NON-INDEXED '
if 'symbol_kind' in self.symbolIdsToData[key]:
symbolString += self.symbolIdsToData[key]['symbol_kind'] + ': '
else:
symbolString += 'SYMBOL: '
if 'name' in self.symbolIdsToData[key]:
symbolString += self.symbolIdsToData[key]['name']
if 'symbol_location' in self.symbolIdsToData[key]:
symbolString += ' at ' + self.symbolIdsToData[key]['symbol_location']
if 'scope_location' in self.symbolIdsToData[key]:
symbolString += ' with scope ' + self.symbolIdsToData[key]['scope_location']
if 'signature_location' in self.symbolIdsToData[key]:
symbolString += ' with signature ' + self.symbolIdsToData[key]['signature_location']
symbolString = symbolString.strip()
if symbolString:
self.symbols.append(symbolString)
self.localSymbols = []
for key in self.localSymbolIdsToData:
localSymbolString = ''
if 'name' in self.localSymbolIdsToData[key]:
localSymbolString += self.localSymbolIdsToData[key]['name']
if localSymbolString and 'local_symbol_locations' in self.localSymbolIdsToData[key]:
for location in self.localSymbolIdsToData[key]['local_symbol_locations']:
self.localSymbols.append(localSymbolString + ' at ' + location)
self.references = []
for key in self.referenceIdsToData:
if 'reference_location' not in self.referenceIdsToData[key] or len(self.referenceIdsToData[key]['reference_location']) == 0:
self.referenceIdsToData[key]['reference_location'].append('')
for referenceLocation in self.referenceIdsToData[key]['reference_location']:
referenceString = ''
if 'reference_kind' in self.referenceIdsToData[key]:
referenceString += self.referenceIdsToData[key]['reference_kind'] + ': '
else:
referenceString += 'UNKNOWN REFERENCE: '
if 'context_symbol_id' in self.referenceIdsToData[key] and self.referenceIdsToData[key]['context_symbol_id'] in self.symbolIdsToData:
referenceString += self.symbolIdsToData[self.referenceIdsToData[key]['context_symbol_id']]['name']
else:
referenceString += 'UNKNOWN SYMBOL'
referenceString += ' -> '
if 'referenced_symbol_id' in self.referenceIdsToData[key] and self.referenceIdsToData[key]['referenced_symbol_id'] in self.symbolIdsToData:
referenceString += self.symbolIdsToData[self.referenceIdsToData[key]['referenced_symbol_id']]['name']
else:
referenceString += 'UNKNOWN SYMBOL'
if referenceLocation:
referenceString += ' at ' + referenceLocation
referenceString = referenceString.strip()
if referenceString:
self.references.append(referenceString)
self.qualifiers = []
for key in self.qualifierIdsToData:
symbolName = 'UNKNOWN SYMBOL'
if 'id' in self.qualifierIdsToData[key] and self.qualifierIdsToData[key]['id'] in self.symbolIdsToData:
symbolName = self.symbolIdsToData[self.qualifierIdsToData[key]['id']]['name']
for qualifierLocation in self.qualifierIdsToData[key]['qualifier_locations']:
qualifierString = symbolName
if qualifierLocation:
qualifierString += ' at ' + qualifierLocation
if qualifierString:
self.qualifiers.append(qualifierString)
def getNextElementId(self):
id = self.nextSymbolId
self.nextSymbolId += 1
return id
def recordSymbol(self, nameHierarchy):
serialized = nameHierarchy.serialize()
if serialized in self.serializedSymbolsToIds:
return self.serializedSymbolsToIds[serialized]
symbolId = self.getNextElementId()
self.serializedSymbolsToIds[serialized] = symbolId
self.symbolIdsToData[symbolId] = {
'id': symbolId,
'name': nameHierarchy.getDisplayString()
}
return symbolId
def recordSymbolDefinitionKind(self, symbolId, symbolDefinitionKind):
if symbolId in self.symbolIdsToData:
self.symbolIdsToData[symbolId]['definition_kind'] = symbolDefinitionKindToString(symbolDefinitionKind)
def recordSymbolKind(self, symbolId, symbolKind):
if symbolId in self.symbolIdsToData:
self.symbolIdsToData[symbolId]['symbol_kind'] = symbolKindToString(symbolKind)
def recordSymbolLocation(self, symbolId, sourceRange):
if symbolId in self.symbolIdsToData:
self.symbolIdsToData[symbolId]['symbol_location'] = sourceRange.toString()
def recordSymbolScopeLocation(self, symbolId, sourceRange):
if symbolId in self.symbolIdsToData:
self.symbolIdsToData[symbolId]['scope_location'] = sourceRange.toString()
def recordSymbolSignatureLocation(self, symbolId, sourceRange):
if symbolId in self.symbolIdsToData:
self.symbolIdsToData[symbolId]['signature_location'] = sourceRange.toString()
def recordReference(self, contextSymbolId, referencedSymbolId, referenceKind):
serialized = str(contextSymbolId) + ' -> ' + str(referencedSymbolId) + '[' + str(referenceKind) + ']'
if serialized in self.serializedReferencesToIds:
return self.serializedReferencesToIds[serialized]
referenceId = self.getNextElementId()
self.serializedReferencesToIds[serialized] = referenceId
self.referenceIdsToData[referenceId] = {
'id': referenceId,
'context_symbol_id': contextSymbolId,
'referenced_symbol_id': referencedSymbolId,
'reference_kind': referenceKindToString(referenceKind),
'reference_location': []
}
return referenceId
def recordReferenceLocation(self, referenceId, sourceRange):
if referenceId in self.referenceIdsToData:
self.referenceIdsToData[referenceId]['reference_location'].append(sourceRange.toString())
def recordReferenceIsAmbiguous(self, referenceId):
raise NotImplementedError
def recordReferenceToUnsolvedSymhol(self, contextSymbolId, referenceKind, sourceRange):
referencedSymbolId = self.recordSymbol(shallow_indexer.getNameHierarchyForUnsolvedSymbol())
referenceId = self.recordReference(contextSymbolId, referencedSymbolId, referenceKind)
self.recordReferenceLocation(referenceId, sourceRange)
return referenceId
def recordQualifierLocation(self, referencedSymbolId, sourceRange):
if referencedSymbolId not in self.qualifierIdsToData:
self.qualifierIdsToData[referencedSymbolId] = {
'id': referencedSymbolId,
'qualifier_locations': []
}
self.qualifierIdsToData[referencedSymbolId]['qualifier_locations'].append(sourceRange.toString())
def recordFile(self, filePath):
serialized = filePath
if serialized in self.serializedSymbolsToIds:
return self.serializedSymbolsToIds[serialized]
fileId = self.getNextElementId()
self.serializedSymbolsToIds[serialized] = fileId
self.symbolIdsToData[fileId] = {
'id': fileId,
'name': filePath,
'symbol_kind': 'FILE',
'definition_kind': 'INDEXED'
}
return fileId
def recordFileLanguage(self, fileId, languageIdentifier):
# FIXME: implement this one!
return
def recordLocalSymbol(self, name):
if name in self.serializedLocalSymbolsToIds:
return self.serializedLocalSymbolsToIds[name]
localSymbolId = self.getNextElementId()
self.serializedLocalSymbolsToIds[name] = localSymbolId
self.localSymbolIdsToData[localSymbolId] = {
'id': localSymbolId,
'name': name,
'local_symbol_locations': []
}
return localSymbolId
def recordLocalSymbolLocation(self, localSymbolId, sourceRange):
if localSymbolId in self.localSymbolIdsToData:
self.localSymbolIdsToData[localSymbolId]['local_symbol_locations'].append(sourceRange.toString())
def recordAtomicSourceRange(self, sourceRange):
self.atomicSourceRanges.append('ATOMIC SOURCE RANGE: ' + sourceRange.toString())
return
def recordError(self, message, fatal, sourceRange):
errorString = ''
if fatal:
errorString += 'FATAL '
errorString += 'ERROR: "' + message + '" at ' + sourceRange.toString()
self.errors.append(errorString)
return
def symbolDefinitionKindToString(symbolDefinitionKind):
if symbolDefinitionKind == srctrl.SYMBOL_ANNOTATION:
return 'EXPLICIT'
if symbolDefinitionKind == srctrl.DEFINITION_IMPLICIT:
return 'IMPLICIT'
return ''
def symbolKindToString(symbolKind):
if symbolKind == srctrl.SYMBOL_TYPE:
return 'TYPE'
if symbolKind == srctrl.SYMBOL_BUILTIN_TYPE:
return 'BUILTIN_TYPE'
if symbolKind == srctrl.SYMBOL_MODULE:
return 'MODULE'
if symbolKind == srctrl.SYMBOL_NAMESPACE:
return 'NAMESPACE'
if symbolKind == srctrl.SYMBOL_PACKAGE:
return 'PACKAGE'
if symbolKind == srctrl.SYMBOL_STRUCT:
return 'STRUCT'
if symbolKind == srctrl.SYMBOL_CLASS:
return 'CLASS'
if symbolKind == srctrl.SYMBOL_INTERFACE:
return 'INTERFACE'
if symbolKind == srctrl.SYMBOL_ANNOTATION:
return 'ANNOTATION'
if symbolKind == srctrl.SYMBOL_GLOBAL_VARIABLE:
return 'GLOBAL_VARIABLE'
if symbolKind == srctrl.SYMBOL_FIELD:
return 'FIELD'
if symbolKind == srctrl.SYMBOL_FUNCTION:
return 'FUNCTION'
if symbolKind == srctrl.SYMBOL_METHOD:
return 'METHOD'
if symbolKind == srctrl.SYMBOL_ENUM:
return 'ENUM'
if symbolKind == srctrl.SYMBOL_ENUM_CONSTANT:
return 'ENUM_CONSTANT'
if symbolKind == srctrl.SYMBOL_TYPEDEF:
return 'TYPEDEF'
if symbolKind == srctrl.SYMBOL_TYPE_PARAMETER:
return 'TYPE_PARAMETER'
if symbolKind == srctrl.SYMBOL_FILE:
return 'FILE'
if symbolKind == srctrl.SYMBOL_MACRO:
return 'MACRO'
if symbolKind == srctrl.SYMBOL_UNION:
return 'UNION'
return ''
def referenceKindToString(referenceKind):
if referenceKind == srctrl.REFERENCE_TYPE_USAGE:
return 'TYPE_USAGE'
if referenceKind == srctrl.REFERENCE_USAGE:
return 'USAGE'
if referenceKind == srctrl.REFERENCE_CALL:
return 'CALL'
if referenceKind == srctrl.REFERENCE_INHERITANCE:
return 'INHERITANCE'
if referenceKind == srctrl.REFERENCE_OVERRIDE:
return 'OVERRIDE'
if referenceKind == srctrl.REFERENCE_TYPE_ARGUMENT:
return 'TYPE_ARGUMENT'
if referenceKind == srctrl.REFERENCE_TEMPLATE_SPECIALIZATION:
return 'TEMPLATE_SPECIALIZATION'
if referenceKind == srctrl.REFERENCE_INCLUDE:
return 'INCLUDE'
if referenceKind == srctrl.REFERENCE_IMPORT:
return 'IMPORT'
if referenceKind == srctrl.REFERENCE_MACRO_USAGE:
return 'MACRO_USAGE'
if referenceKind == srctrl.REFERENCE_ANNOTATION_USAGE:
return 'ANNOTATION_USAGE'
return ''
if __name__ == '__main__':
unittest.main(exit=True)