-module(internal@ast_type). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([public_type/1, is_pub_type_used/3]). -spec public_type(internal@ast:file_ast()) -> list(internal@ast:public_member()). public_type(File_ast) -> {file_ast, Ast} = case File_ast of {file_ast, _} -> File_ast; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Assertion pattern match failed"/utf8>>, value => _assert_fail, module => <<"internal/ast_type"/utf8>>, function => <<"public_type"/utf8>>, line => 10}) end, {module, _, Types, Type_aliases, _, _} = case Ast of {module, _, _, _, _, _} -> Ast; _assert_fail@1 -> erlang:error(#{gleam_error => let_assert, message => <<"Assertion pattern match failed"/utf8>>, value => _assert_fail@1, module => <<"internal/ast_type"/utf8>>, function => <<"public_type"/utf8>>, line => 11}) end, _pipe = (gleam@list:flat_map( Types, fun(Pub_type) -> {definition, _, {custom_type, Pub_type@1, Is_public, _, _, Sub_types}} = case Pub_type of {definition, _, {custom_type, _, _, _, _, _}} -> Pub_type; _assert_fail@2 -> erlang:error(#{gleam_error => let_assert, message => <<"Assertion pattern match failed"/utf8>>, value => _assert_fail@2, module => <<"internal/ast_type"/utf8>>, function => <<"public_type"/utf8>>, line => 14}) end, case Is_public of public -> case erlang:length(Sub_types) > 0 of true -> gleam@list:map( Sub_types, fun(Sub_type) -> {variant, Type_name, _} = case Sub_type of {variant, _, _} -> Sub_type; _assert_fail@3 -> erlang:error( #{gleam_error => let_assert, message => <<"Assertion pattern match failed"/utf8>>, value => _assert_fail@3, module => <<"internal/ast_type"/utf8>>, function => <<"public_type"/utf8>>, line => 21} ) end, {public_type, Type_name} end ); false -> [{public_type, Pub_type@1}] end; _ -> [] end end )), lists:append( _pipe, (gleam@list:flat_map( Type_aliases, fun(Pub_type@2) -> {definition, _, {type_alias, Pub_type@3, Is_public@1, _, _}} = case Pub_type@2 of {definition, _, {type_alias, _, _, _, _}} -> Pub_type@2; _assert_fail@4 -> erlang:error(#{gleam_error => let_assert, message => <<"Assertion pattern match failed"/utf8>>, value => _assert_fail@4, module => <<"internal/ast_type"/utf8>>, function => <<"public_type"/utf8>>, line => 32}) end, case Is_public@1 of public -> [{public_type, Pub_type@3}]; _ -> [] end end )) ). -spec check_type_usage( list(any()), internal@ast:public_member(), internal@ast:module_name() ) -> {ok, nil} | {error, nil}. check_type_usage(Statements, Pub_type_name, Module_name) -> {public_type, Pub_type_name@1} = case Pub_type_name of {public_type, _} -> Pub_type_name; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Assertion pattern match failed"/utf8>>, value => _assert_fail, module => <<"internal/ast_type"/utf8>>, function => <<"check_type_usage"/utf8>>, line => 50}) end, {module_name, Module_name@1} = case Module_name of {module_name, _} -> Module_name; _assert_fail@1 -> erlang:error(#{gleam_error => let_assert, message => <<"Assertion pattern match failed"/utf8>>, value => _assert_fail@1, module => <<"internal/ast_type"/utf8>>, function => <<"check_type_usage"/utf8>>, line => 51}) end, gleam@list:find_map( Statements, fun(Statement) -> Serialized_statement = begin _pipe = Statement, gleam@string:inspect(_pipe) end, case (begin _pipe@1 = Serialized_statement, gleam_stdlib:contains_string( _pipe@1, <<<<<<<<"FieldAccess(Variable(\""/utf8, Module_name@1/binary>>/binary, "\"), \""/utf8>>/binary, Pub_type_name@1/binary>>/binary, "\")"/utf8>> ) end orelse begin _pipe@2 = Serialized_statement, gleam_stdlib:contains_string( _pipe@2, <<<<<<<<"Some(NamedType(\""/utf8, Pub_type_name@1/binary>>/binary, "\", Some(\""/utf8>>/binary, Module_name@1/binary>>/binary, "\")"/utf8>> ) end) orelse begin _pipe@3 = Serialized_statement, gleam_stdlib:contains_string( _pipe@3, <<<<<<<<"PatternConstructor(Some(\""/utf8, Module_name@1/binary>>/binary, "\"), \""/utf8>>/binary, Pub_type_name@1/binary>>/binary, "\""/utf8>> ) end of true -> {ok, nil}; false -> {error, nil} end end ). -spec is_pub_type_used( internal@ast:another_files_ast(), internal@ast:public_member(), internal@fs:module_full_name() ) -> {ok, nil} | {error, nil}. is_pub_type_used(Files_ast, Pub_type_name, Module_full_name) -> internal@ast:is_pub_member_used( Files_ast, Pub_type_name, Module_full_name, fun check_type_usage/3 ).