7
7
// Dart debug symbol information stored by DDC.
8
8
//
9
9
// The data format below stores descriptions of dart code objects and their
10
- // mapping to JS that is generated by DDC. Every field, except ids, descrbes
10
+ // mapping to JS that is generated by DDC. Every field, except ids, describes
11
11
// dart.
12
12
13
13
// Note that 'localId' and 'scopeId' combine into a unique id that is used for
14
14
// object lookup and mapping between JS and dart concepts. As a result, it
15
- // needs to be either stored or easly computed for each corresponding JS object
15
+ // needs to be either stored or easily computed for each corresponding JS object
16
16
// created by DDC, so the debugger is able to look up dart symbol from JS ones.
17
17
//
18
- // For example, to detect all dart variables in current scope and display
18
+ // For example, to detect all dart variables in the current scope and display
19
19
// their values, the debugger can do the following:
20
20
//
21
21
// - map current JS location to dart location using source maps
@@ -83,6 +83,10 @@ class SemanticVersion {
83
83
}
84
84
}
85
85
86
+ /// Base class for a symbol table element.
87
+ ///
88
+ /// Symbol tables and its elements are stored by the compiler using
89
+ /// [toJson] method, and are read from json using `fromJson` constructors.
86
90
abstract class SymbolTableElement {
87
91
Map <String , dynamic > toJson ();
88
92
}
@@ -168,7 +172,6 @@ class ModuleSymbols implements SymbolTableElement {
168
172
169
173
_setValueIfNotNull (json, 'version' , version);
170
174
_setValueIfNotNull (json, 'moduleName' , moduleName);
171
-
172
175
_setObjectListIfNotNull (json, 'libraries' , libraries);
173
176
_setObjectListIfNotNull (json, 'scripts' , scripts);
174
177
_setObjectListIfNotNull (json, 'classes' , classes);
@@ -195,7 +198,7 @@ class Symbol implements SymbolTableElement {
195
198
/// '<scope id>|<js name>'
196
199
///
197
200
/// Where scope refers to a Library, Class, Function, or Scope.
198
- String get id => '$scopeId |$localId ' ;
201
+ String get id => scopeId == null ? localId : '$scopeId |$localId ' ;
199
202
200
203
/// Source location of the symbol.
201
204
SourceLocation location;
@@ -316,8 +319,8 @@ class ClassSymbol extends ScopeSymbol implements TypeSymbol {
316
319
/// A list of interface types for this class.
317
320
List <String > interfaceIds;
318
321
319
- /// Type parameters for this class .
320
- List < String > typeParameters;
322
+ /// Mapping of type parameter dart names to JS names .
323
+ Map < String , String > typeParameters;
321
324
322
325
/// Library that contains this class.
323
326
String get libraryId => scopeId;
@@ -359,9 +362,8 @@ class ClassSymbol extends ScopeSymbol implements TypeSymbol {
359
362
isAbstract = _createValue (json['isAbstract' ]);
360
363
isConst = _createValue (json['isConst' ]);
361
364
superClassId = _createValue (json['superClassId' ]);
362
-
363
365
interfaceIds = _createValueList (json['interfaceIds' ]);
364
- typeParameters = _createValueList (json['typeParameters' ]);
366
+ typeParameters = _createValueMap (json['typeParameters' ]);
365
367
}
366
368
367
369
@override
@@ -372,7 +374,6 @@ class ClassSymbol extends ScopeSymbol implements TypeSymbol {
372
374
_setValueIfNotNull (json, 'isAbstract' , isAbstract);
373
375
_setValueIfNotNull (json, 'isConst' , isConst);
374
376
_setValueIfNotNull (json, 'superClassId' , superClassId);
375
-
376
377
_setValueIfNotNull (json, 'interfaceIds' , interfaceIds);
377
378
_setValueIfNotNull (json, 'typeParameters' , typeParameters);
378
379
@@ -381,8 +382,8 @@ class ClassSymbol extends ScopeSymbol implements TypeSymbol {
381
382
}
382
383
383
384
class FunctionTypeSymbol extends Symbol implements TypeSymbol {
384
- /// Type parameters for this function .
385
- List < String > typeParameters;
385
+ /// Mapping of dart type parameter names to JS names .
386
+ Map < String , String > typeParameters;
386
387
387
388
/// Types for positional parameters for this function.
388
389
List <String > parameterTypeIds;
@@ -409,26 +410,23 @@ class FunctionTypeSymbol extends Symbol implements TypeSymbol {
409
410
410
411
FunctionTypeSymbol .fromJson (Map <String , dynamic > json)
411
412
: super .fromJson (json) {
412
- typeParameters = _createValueList (json['typeParameters' ]);
413
413
parameterTypeIds = _createValueList (json['parameterTypeIds' ]);
414
414
optionalParameterTypeIds =
415
415
_createValueList (json['optionalParameterTypeIds' ]);
416
-
417
- namedParameterTypeIds = _createObject (json['namedParameterTypeIds' ],
418
- (json) => Map <String , String >.from (json));
416
+ namedParameterTypeIds = _createValueMap (json['namedParameterTypeIds' ]);
417
+ typeParameters = _createValueMap (json['typeParameters' ]);
419
418
returnTypeId = _createValue (json['returnTypeId' ]);
420
419
}
421
420
422
421
@override
423
422
Map <String , dynamic > toJson () {
424
423
final json = super .toJson ();
425
424
426
- _setValueIfNotNull (json, 'typeParameters' , typeParameters);
427
425
_setValueIfNotNull (json, 'parameterTypeIds' , parameterTypeIds);
428
426
_setValueIfNotNull (
429
427
json, 'optionalParameterTypeIds' , optionalParameterTypeIds);
430
-
431
428
_setValueIfNotNull (json, 'namedParameterTypeIds' , namedParameterTypeIds);
429
+ _setValueIfNotNull (json, 'typeParameters' , typeParameters);
432
430
_setValueIfNotNull (json, 'returnTypeId' , returnTypeId);
433
431
434
432
return json;
@@ -524,17 +522,14 @@ class LibrarySymbol extends ScopeSymbol {
524
522
List <String > scopeIds,
525
523
}) : super (
526
524
localId: uri,
527
- scopeId: null ,
528
525
variableIds: variableIds,
529
526
scopeIds: scopeIds,
530
- location: null ,
531
527
);
532
528
533
529
LibrarySymbol .fromJson (Map <String , dynamic > json) : super .fromJson (json) {
534
- name = _createValue (json['name' ], ifNull : '' );
530
+ name = _createValue (json['name' ]);
535
531
uri = _createValue (json['uri' ]);
536
532
scriptIds = _createValueList (json['scriptIds' ]);
537
-
538
533
dependencies = _createObjectList (
539
534
json['dependencies' ], (json) => LibraryDependency .fromJson (json));
540
535
}
@@ -544,10 +539,8 @@ class LibrarySymbol extends ScopeSymbol {
544
539
final json = super .toJson ();
545
540
546
541
_setValueIfNotNull (json, 'name' , name);
547
- _setValueIfNotNull (json, 'id' , id);
548
542
_setValueIfNotNull (json, 'uri' , uri);
549
543
_setValueIfNotNull (json, 'scriptIds' , scriptIds);
550
-
551
544
_setObjectListIfNotNull (json, 'dependencies' , dependencies);
552
545
553
546
return json;
@@ -603,24 +596,31 @@ class Script implements SymbolTableElement {
603
596
/// This can be just an integer. The mapping from JS to dart script
604
597
/// happens using the source map. The id is only used for references
605
598
/// in other elements.
606
- String id;
599
+ String localId;
600
+
601
+ String libraryId;
602
+
603
+ String get id => '$libraryId |$localId ' ;
607
604
608
605
Script ({
609
606
this .uri,
610
- this .id,
607
+ this .localId,
608
+ this .libraryId,
611
609
});
612
610
613
611
Script .fromJson (Map <String , dynamic > json) {
614
612
uri = _createValue (json['uri' ]);
615
- id = _createValue (json['id' ]);
613
+ localId = _createValue (json['localId' ]);
614
+ libraryId = _createValue (json['libraryId' ]);
616
615
}
617
616
618
617
@override
619
618
Map <String , dynamic > toJson () {
620
619
final json = < String , dynamic > {};
621
620
622
621
_setValueIfNotNull (json, 'uri' , uri);
623
- _setValueIfNotNull (json, 'id' , id);
622
+ _setValueIfNotNull (json, 'localId' , localId);
623
+ _setValueIfNotNull (json, 'libraryId' , libraryId);
624
624
625
625
return json;
626
626
}
@@ -697,10 +697,9 @@ class SourceLocation implements SymbolTableElement {
697
697
}
698
698
}
699
699
700
- List <T > _createObjectList <T >(
700
+ List <T > _createObjectList <T extends SymbolTableElement >(
701
701
dynamic json, T Function (Map <String , dynamic >) creator) {
702
- if (json == null ) return null ;
703
-
702
+ if (json == null ) return [];
704
703
if (json is List ) {
705
704
return json.map ((e) => _createObject (e, creator)).toList ();
706
705
}
@@ -709,7 +708,6 @@ List<T> _createObjectList<T>(
709
708
710
709
T _createObject <T >(dynamic json, T Function (Map <String , dynamic >) creator) {
711
710
if (json == null ) return null ;
712
-
713
711
if (json is Map <String , dynamic >) {
714
712
return creator (json);
715
713
}
@@ -718,8 +716,7 @@ T _createObject<T>(dynamic json, T Function(Map<String, dynamic>) creator) {
718
716
719
717
List <T > _createValueList <T >(dynamic json,
720
718
{T ifNull, T Function (String ) parse}) {
721
- if (json == null ) return null ;
722
-
719
+ if (json == null ) return [];
723
720
if (json is List ) {
724
721
return json
725
722
.map ((e) => _createValue <T >(e, ifNull: ifNull, parse: parse))
@@ -728,12 +725,14 @@ List<T> _createValueList<T>(dynamic json,
728
725
throw ArgumentError ('Not a list: $json ' );
729
726
}
730
727
728
+ Map <String , T > _createValueMap <T >(dynamic json) {
729
+ if (json == null ) return {};
730
+ return Map <String , T >.from (json as Map <String , dynamic >);
731
+ }
732
+
731
733
T _createValue <T >(dynamic json, {T ifNull, T Function (String ) parse}) {
732
734
if (json == null ) return ifNull;
733
-
734
- if (json is T ) {
735
- return json;
736
- }
735
+ if (json is T ) return json;
737
736
if (json is String && parse != null ) {
738
737
return parse (json);
739
738
}
0 commit comments