Current section
Files
Jump to
Current section
Files
src/internal@ast_type.erl
-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 => 13})
end,
{module, _, Types, _, _, _} = 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 => 14})
end,
gleam@list:flat_map(
Types,
fun(Pub_type) ->
{definition, _, {custom_type, _, 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 => 16})
end,
case Is_public of
public ->
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 => 20})
end,
{public_type, Type_name}
end
);
_ ->
[]
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 => 46})
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 => 47})
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 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) ->
{another_files_ast, Files_ast@1} = case Files_ast of
{another_files_ast, _} -> Files_ast;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"internal/ast_type"/utf8>>,
function => <<"is_pub_type_used"/utf8>>,
line => 28})
end,
gleam@list:find_map(
Files_ast@1,
fun(File_ast) ->
{file_ast, Ast} = case File_ast of
{file_ast, _} -> File_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 => <<"is_pub_type_used"/utf8>>,
line => 30})
end,
{module, Imports, _, _, _, Fns} = case Ast of
{module, _, _, _, _, _} -> Ast;
_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 => <<"is_pub_type_used"/utf8>>,
line => 31})
end,
Imported_info_list = internal@ast:imported_info(
Imports,
Module_full_name,
Pub_type_name
),
gleam@list:find_map(
Imported_info_list,
fun(Imported_info) -> case Imported_info of
imported_as_alias ->
{ok, nil};
{module_imported, Module_name} ->
gleam@list:find_map(
Fns,
fun(Fun_def) ->
{definition,
_,
{function, _, _, _, _, Statements, _}} = case Fun_def of
{definition,
_,
{function, _, _, _, _, _, _}} -> Fun_def;
_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 => <<"is_pub_type_used"/utf8>>,
line => 39}
)
end,
check_type_usage(
Statements,
Pub_type_name,
Module_name
)
end
)
end end
)
end
).