-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stdlib: make it possible to list local functions and types #7844
stdlib: make it possible to list local functions and types #7844
Conversation
I'll do a review of the code later, but maybe there should be tests that the function do what they are supposed to? |
424f893
to
488ac94
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shell_default:help()
needs to be updated, but otherwise this looks good to me.
488ac94
to
6a334e5
Compare
introducing lf(), lt(), lr() to list local functions, types and records respectively. introducing fl(), ff(), tf() to remove locally defined types and functions. introducing save_module(FilePath) that saves local defined functions and types to given filename. updating fd to store the original function definition. updating rd, rf to accurately add and remove locally defined records to local table.
6a334e5
to
d6ceeb9
Compare
lib/stdlib/test/shell_SUITE.erl
Outdated
"ok.\nok.\nok.\nok.\n{ok,my_module}.\n" = t( | ||
<<"-type hej() :: integer().\n" | ||
"-record(svej, {a :: hej()}).\n" | ||
"-spec my_func(X) -> X.\n my_func(#svej{a=A}) -> A.\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"-spec my_func(X) -> X.\n my_func(#svej{a=A}) -> A.\n" | |
"-spec my_func(X) -> X.\n" | |
"my_func(#svej{a=A}) -> A.\n" |
for consistency
lib/stdlib/test/shell_SUITE.erl
Outdated
"ok.\n-record(svej,{a}).\n.\nok.\n" = t( | ||
<<"-record(svej, {a}).\n" | ||
"lr().">>), | ||
"ok.\nok.\n-spec my_func(X) -> X.\nmy_func(X) ->\n X.\n\n.\nok.\n" = t( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"ok.\nok.\n-spec my_func(X) -> X.\nmy_func(X) ->\n X.\n\n.\nok.\n" = t( | |
"ok.\nok.\n-spec my_func(X) -> X.\nmy_func(X) ->\n X.\n\n.\nok.\n" = t( | |
^^^^^^^ |
Why are there three newlines here? Seems a bit excessive.
lib/stdlib/src/shell.erl
Outdated
[Module, _] = string:split(FileName, ".", leading), | ||
Output = ( | ||
"-module("++Module++").\n\n" ++ | ||
"-export(["++[atom_to_list(F)++"/"++integer_to_list(A)||{F,A}<-local_defined_functions(FT)]++"]).\n\n"++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"-export(["++[atom_to_list(F)++"/"++integer_to_list(A)||{F,A}<-local_defined_functions(FT)]++"]).\n\n"++ | |
Exports = [atom_to_list(F)++"/"++integer_to_list(A)||{F,A}<-local_defined_functions(FT)], | |
"-export(["++lists:join(",",Exports)++"]).\n\n"++ |
Need to add ,
inbetween exports. Also should probably be a test for multiple functions when saving module to make sure it works.
<p>Forget locally defined functions (including function specs if they exist). | ||
</p> | ||
</item> | ||
<tag><c>ff({FunName,Arity})</c></tag> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have expected this to take two arguments, FuncName and Arity, not a two tuple.
lib/stdlib/src/shell.erl
Outdated
lists:join($\n,lists:map(fun(Key) -> | ||
Spec = maps:get(Key, Output_function_specs, nospec), | ||
Def = maps:get(Key, Output_functions, nodef), | ||
case {Spec, Def} of | ||
{nospec, _} -> Def; | ||
{_, nodef} -> | ||
{FunName, Arity} = Key, | ||
Spec ++ "%% " ++ atom_to_list(FunName) ++ "/" ++ integer_to_list(Arity) ++ " not implemented"; | ||
{_, _} -> Spec ++ Def | ||
end | ||
end, | ||
Keys)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lists:join($\n,lists:map(fun(Key) -> | |
Spec = maps:get(Key, Output_function_specs, nospec), | |
Def = maps:get(Key, Output_functions, nodef), | |
case {Spec, Def} of | |
{nospec, _} -> Def; | |
{_, nodef} -> | |
{FunName, Arity} = Key, | |
Spec ++ "%% " ++ atom_to_list(FunName) ++ "/" ++ integer_to_list(Arity) ++ " not implemented"; | |
{_, _} -> Spec ++ Def | |
end | |
end, | |
Keys)). | |
string:trim(lists:join($\n,lists:map(fun(Key) -> | |
Spec = maps:get(Key, Output_function_specs, nospec), | |
Def = maps:get(Key, Output_functions, nodef), | |
case {Spec, Def} of | |
{nospec, _} -> Def; | |
{_, nodef} -> | |
{FunName, Arity} = Key, | |
Spec ++ "%% " ++ atom_to_list(FunName) ++ "/" ++ integer_to_list(Arity) ++ " not implemented"; | |
{_, _} -> Spec ++ Def | |
end | |
end, | |
Keys))). |
strip som trailing newlines
lib/stdlib/src/shell.erl
Outdated
lists:join($\n, | ||
[RecDef||{{record_def, _},RecDef} <- ets:tab2list(FT)]). | ||
write_and_compile_module(PathToFile, Output) -> | ||
case file:write_file(PathToFile, Output) of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
case file:write_file(PathToFile, Output) of | |
case file:write_file(PathToFile, unicode:characters_to_binary(Output)) of |
To handle unicode function names... and maybe a test?
CT Test Results 2 files 92 suites 35m 40s ⏱️ For more details on these failures, see this check. Results for commit a1c802f. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts// Erlang/OTP Github Action Bot |
dee0a86
to
a1c802f
Compare
introducing lf(), lt(), lr() to list local functions, types and
records respectively.
introducing fl(), ff(), tf() to remove locally defined types
and functions.
introducing save_module(FilePath) that saves local defined
functions and types to given filename.
updating fd to store the original function definition. updating rd, rf to accurately add and remove locally defined records
to local table.