getLookup method

Lookup getLookup(
  1. Map<int, LookupValue> definitions,
  2. Map<int, int> accessibleTypes
)

Implementation

Lookup getLookup(Map<int, LookupValue> definitions, Map<int, int> accessibleTypes) {
  final Lookup typeTree = [];

  for (final entry in accessibleTypes.entries) {
    final frameId = entry.key;
    final typeId = entry.value;
    final path = definitions[frameId]!.path;

    for (final def in constructLookupTypeDef(definitions, accessibleTypes, frameId)) {
      typeTree.add(LookupEntry(
        path: path,
        typeId: typeId,
        typeDef: def,
      ));
    }
  }

  typeTree.sort((a, b) {
    if (a.typeId != b.typeId) return a.typeId.compareTo(b.typeId);
    if (a.typeDef.tag != 'enumeration' || b.typeDef.tag != 'enumeration') {
      throw Exception('Found two types with same id');
    }

    return a.typeDef.value.index.compareTo(b.typeDef.value.index);
  });

  return typeTree;
}