-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 pub_type_if_not_returned_in_pub_fun( binary(), list(glance:definition(glance:function_())) ) -> {ok, internal@ast:public_member()} | {error, nil}. pub_type_if_not_returned_in_pub_fun(Type_name, Fns) -> Pub_fun_usage = (gleam@list:find_map(Fns, fun(Fun) -> case Fun of {definition, _, {function, _, Public, _, {some, {named_type, T_name, _, _}}, _, _}} when (Public =:= public) andalso (T_name =:= Type_name) -> {ok, nil}; _ -> {error, nil} end end)), case Pub_fun_usage of {ok, nil} -> {error, nil}; {error, nil} -> {ok, {public_type, Type_name}} end. -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 => 11}) end, {module, _, Types, Type_aliases, _, Fns} = 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 => 12}) 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 => 15}) end, case Is_public of public -> gleam@list:filter_map(case erlang:length(Sub_types) > 0 of true -> Sub_types; false -> [{variant, Pub_type@1, []}] end, 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 => 23}) end, pub_type_if_not_returned_in_pub_fun(Type_name, Fns) end); _ -> [] end end )), lists:append( _pipe, (gleam@list:filter_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 => 31}) end, case Is_public@1 of public -> {ok, {public_type, Pub_type@3}}; _ -> {error, nil} 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 => 65}) 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 => 66}) 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 ).