Type _extractfromRecord()

in lib/src/header_parser/type_extractor/extractor.dart [144:210]


Type _extractfromRecord(clang_types.CXType cxtype, bool pointerReference) {
  Type type;

  final cursor = clang.clang_getTypeDeclaration(cxtype);
  _logger.fine('${_padding}_extractfromRecord: ${cursor.completeStringRepr()}');

  final cursorKind = clang.clang_getCursorKind(cursor);
  if (cursorKind == clang_types.CXCursorKind.CXCursor_StructDecl ||
      cursorKind == clang_types.CXCursorKind.CXCursor_UnionDecl) {
    final declUsr = cursor.usr();
    final declSpelling = cursor.spelling();

    // Set includer functions according to compoundType.
    final bool Function(String) isSeenDecl;
    final Compound? Function(String) getSeenDecl;
    final CompoundType compoundType;
    final Map<String, ImportedType> compoundTypeMappings;

    switch (cursorKind) {
      case clang_types.CXCursorKind.CXCursor_StructDecl:
        isSeenDecl = bindingsIndex.isSeenStruct;
        getSeenDecl = bindingsIndex.getSeenStruct;
        compoundType = CompoundType.struct;
        compoundTypeMappings = config.structTypeMappings;
        break;
      case clang_types.CXCursorKind.CXCursor_UnionDecl:
        isSeenDecl = bindingsIndex.isSeenUnion;
        getSeenDecl = bindingsIndex.getSeenUnion;
        compoundType = CompoundType.union;
        compoundTypeMappings = config.unionTypeMappings;
        break;
      default:
        throw Exception('Unhandled compound type cursorkind.');
    }

    // Also add a struct binding, if its unseen.
    // TODO(23): Check if we should auto add compound declarations.
    if (compoundTypeMappings.containsKey(declSpelling)) {
      _logger.fine('  Type Mapped from type-map');
      return Type.importedType(compoundTypeMappings[declSpelling]!);
    } else if (isSeenDecl(declUsr)) {
      type = Type.compound(getSeenDecl(declUsr)!);

      // This will parse the dependencies if needed.
      parseCompoundDeclaration(
        cursor,
        compoundType,
        ignoreFilter: true,
        pointerReference: pointerReference,
      );
    } else {
      final struc = parseCompoundDeclaration(
        cursor,
        compoundType,
        ignoreFilter: true,
        pointerReference: pointerReference,
      );
      type = Type.compound(struc!);
    }
  } else {
    _logger.fine(
        'typedeclarationCursorVisitor: _extractfromRecord: Not Implemented, ${cursor.completeStringRepr()}');
    return Type.unimplemented('Type: ${cxtype.kindSpelling()} not implemented');
  }

  return type;
}