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]).
-file("/Users/darky/Projects/cleam/src/internal/ast_type.gleam", 39).
-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.
-file("/Users/darky/Projects/cleam/src/internal/ast_type.gleam", 10).
-spec public_type(internal@ast:file_ast()) -> list(internal@ast:public_member()).
public_type(File_ast) ->
{file_ast, Ast} = File_ast,
{module, _, Types, Type_aliases, _, Fns} = Ast,
_pipe = (gleam@list:flat_map(
Types,
fun(Pub_type) ->
{definition,
_,
{custom_type, Pub_type@1, Is_public, _, _, Sub_types}} = Pub_type,
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, _} = Sub_type,
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, _, _}} = Pub_type@2,
case Is_public@1 of
public ->
{ok, {public_type, Pub_type@3}};
_ ->
{error, nil}
end
end
))
).
-file("/Users/darky/Projects/cleam/src/internal/ast_type.gleam", 64).
-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 => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"internal/ast_type"/utf8>>,
function => <<"check_type_usage"/utf8>>,
line => 65})
end,
{module_name, Module_name@1} = Module_name,
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
).
-file("/Users/darky/Projects/cleam/src/internal/ast_type.gleam", 55).
-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
).