Current section
Files
Jump to
Current section
Files
src/internal@ast_const.erl
-module(internal@ast_const).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([public_const/1, is_pub_const_used/3]).
-spec public_const(internal@ast:file_ast()) -> list(internal@ast:public_member()).
public_const(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_const"/utf8>>,
function => <<"public_const"/utf8>>,
line => 12})
end,
{module, _, _, _, Constants, _, _, _} = 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_const"/utf8>>,
function => <<"public_const"/utf8>>,
line => 13})
end,
gleam@list:flat_map(
Constants,
fun(Constant) ->
{definition, _, {constant, Const_name, Is_public, _, _}} = case Constant of
{definition, _, {constant, _, _, _, _}} -> Constant;
_assert_fail@2 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@2,
module => <<"internal/ast_const"/utf8>>,
function => <<"public_const"/utf8>>,
line => 15})
end,
case Is_public of
public ->
[{public_const, Const_name}];
_ ->
[]
end
end
).
-spec check_const_usage(
list(any()),
internal@ast:public_member(),
internal@ast:module_name()
) -> {ok, nil} | {error, nil}.
check_const_usage(Statements, Pub_const_name, Module_name) ->
{public_const, Pub_const_name@1} = case Pub_const_name of
{public_const, _} -> Pub_const_name;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"internal/ast_const"/utf8>>,
function => <<"check_const_usage"/utf8>>,
line => 41})
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_const"/utf8>>,
function => <<"check_const_usage"/utf8>>,
line => 42})
end,
gleam@list:find_map(
Statements,
fun(Statement) ->
case begin
_pipe = Statement,
_pipe@1 = gleam@string:inspect(_pipe),
gleam_stdlib:contains_string(
_pipe@1,
<<<<<<<<"FieldAccess(Variable(\""/utf8,
Module_name@1/binary>>/binary,
"\"), \""/utf8>>/binary,
Pub_const_name@1/binary>>/binary,
"\")"/utf8>>
)
end of
true ->
{ok, nil};
false ->
{error, nil}
end
end
).
-spec is_pub_const_used(
internal@ast:another_files_ast(),
internal@ast:public_member(),
internal@fs:module_full_name()
) -> {ok, nil} | {error, nil}.
is_pub_const_used(Files_ast, Pub_const_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_const"/utf8>>,
function => <<"is_pub_const_used"/utf8>>,
line => 23})
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_const"/utf8>>,
function => <<"is_pub_const_used"/utf8>>,
line => 25})
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_const"/utf8>>,
function => <<"is_pub_const_used"/utf8>>,
line => 26})
end,
Imported_info_list = internal@ast:imported_info(
Imports,
Module_full_name,
Pub_const_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_const"/utf8>>,
function => <<"is_pub_const_used"/utf8>>,
line => 34}
)
end,
check_const_usage(
Statements,
Pub_const_name,
Module_name
)
end
)
end end
)
end
).