aboutsummaryrefslogtreecommitdiffstats
path: root/lib/percept/src
diff options
context:
space:
mode:
authorKostis Sagonas <[email protected]>2010-02-13 10:13:46 +0100
committerBjörn Gustavsson <[email protected]>2010-02-16 13:24:55 +0100
commitf2592e6ef6bd6179d45884794d722e8cb551d1aa (patch)
treed945c9bb65badffa4c32074ee2ec124bd8960234 /lib/percept/src
parentc12397f937d450d885ca6ec44d53ef34ff8788f4 (diff)
downloadotp-f2592e6ef6bd6179d45884794d722e8cb551d1aa.tar.gz
otp-f2592e6ef6bd6179d45884794d722e8cb551d1aa.tar.bz2
otp-f2592e6ef6bd6179d45884794d722e8cb551d1aa.zip
percept: Modernize types and specs
Diffstat (limited to 'lib/percept/src')
-rw-r--r--lib/percept/src/egd.erl28
-rw-r--r--lib/percept/src/egd.hrl6
-rw-r--r--lib/percept/src/percept.erl38
-rw-r--r--lib/percept/src/percept.hrl8
-rw-r--r--lib/percept/src/percept_db.erl4
-rw-r--r--lib/percept/src/percept_html.erl42
6 files changed, 56 insertions, 70 deletions
diff --git a/lib/percept/src/egd.erl b/lib/percept/src/egd.erl
index 7972fde597..8e17707224 100644
--- a/lib/percept/src/egd.erl
+++ b/lib/percept/src/egd.erl
@@ -46,10 +46,10 @@
%% @type color()
%% @type render_option() = {render_engine, opaque} | {render_engine, alpha}
--type(egd_image() :: pid()).
--type(point() :: {non_neg_integer(), non_neg_integer()}).
--type(render_option() :: {'render_engine', 'opaque'} | {'render_engine', 'alpha'}).
--type(color() :: {float(), float(), float(), float()}).
+-type egd_image() :: pid().
+-type point() :: {non_neg_integer(), non_neg_integer()}.
+-type render_option() :: {'render_engine', 'opaque'} | {'render_engine', 'alpha'}.
+-type color() :: {float(), float(), float(), float()}.
%%==========================================================================
%%
@@ -60,7 +60,7 @@
%% @spec create(integer(), integer()) -> egd_image()
%% @doc Creates an image area and returns its reference.
--spec(create/2 :: (Width :: integer(), Height :: integer()) -> egd_image()).
+-spec create(Width :: integer(), Height :: integer()) -> egd_image().
create(Width,Height) ->
spawn_link(fun() -> init(trunc(Width),trunc(Height)) end).
@@ -69,16 +69,17 @@ create(Width,Height) ->
%% @spec destroy(egd_image()) -> ok
%% @doc Destroys the image.
--spec(destroy/1 :: (Image :: egd_image()) -> ok).
+-spec destroy(Image :: egd_image()) -> ok.
destroy(Image) ->
cast(Image, destroy),
ok.
-%% @spec render(egd_image()) -> binary()
+%% @spec render(egd_image()) -> binary()
%% @equiv render(Image, png, [{render_engine, opaque}])
+-spec render(Image :: egd_image()) -> binary().
render(Image) ->
render(Image, png, [{render_engine, opaque}]).
@@ -94,10 +95,10 @@ render(Image, Type) ->
%% binary can either be a raw bitmap with rgb tripplets or a binary in png
%% format.
--spec(render/3 :: (
+-spec render(
Image :: egd_image(),
Type :: 'png' | 'raw_bitmap' | 'eps',
- Options :: [render_option()]) -> binary()).
+ Options :: [render_option()]) -> binary().
render(Image, Type, Options) ->
{render_engine, RenderType} = proplists:lookup(render_engine, Options),
@@ -116,11 +117,11 @@ information(Pid) ->
%% @spec line(egd_image(), point(), point(), color()) -> ok
%% @doc Creates a line object from P1 to P2 in the image.
--spec(line/4 :: (
+-spec line(
Image :: egd_image(),
P1 :: point(),
P2 :: point(),
- Color :: color()) -> 'ok').
+ Color :: color()) -> 'ok'.
line(Image, P1, P2, Color) ->
cast(Image, {line, P1, P2, Color}),
@@ -132,9 +133,8 @@ line(Image, P1, P2, Color) ->
%% Name = black | silver | gray | white | maroon | red | purple | fuchia | green | lime | olive | yellow | navy | blue | teal | aqua
%% @doc Creates a color reference.
--spec(color/1 :: (
- Value :: {byte(), byte(), byte()} | {byte(), byte(), byte(), byte()} | atom()) ->
- color()).
+-spec color(Value :: {byte(), byte(), byte()} | {byte(), byte(), byte(), byte()} | atom()) ->
+ color().
color(Color) ->
egd_primitives:color(Color).
diff --git a/lib/percept/src/egd.hrl b/lib/percept/src/egd.hrl
index 450c6620cf..2e8f5ebc50 100644
--- a/lib/percept/src/egd.hrl
+++ b/lib/percept/src/egd.hrl
@@ -16,9 +16,9 @@
%%
%% %CopyrightEnd%
--type(rgba_float() :: {float(), float(), float(), float()}).
--type(rgba_byte() :: {byte(), byte(), byte(), byte()}).
--type(rgb() :: {byte(), byte(), byte()}).
+-type rgba_float() :: {float(), float(), float(), float()}.
+-type rgba_byte() :: {byte(), byte(), byte(), byte()}.
+-type rgb() :: {byte(), byte(), byte()}.
-record(image_object, {
type,
diff --git a/lib/percept/src/percept.erl b/lib/percept/src/percept.erl
index af1a920efd..b0d6739478 100644
--- a/lib/percept/src/percept.erl
+++ b/lib/percept/src/percept.erl
@@ -50,7 +50,7 @@
%% @type percept_option() = procs | ports | exclusive
--type(percept_option() :: 'procs' | 'ports' | 'exclusive' | 'scheduler').
+-type percept_option() :: 'procs' | 'ports' | 'exclusive' | 'scheduler'.
%%==========================================================================
%%
@@ -85,8 +85,8 @@ stop(_State) ->
%% profiling
--spec(profile/1 :: (Filename :: string()) ->
- {'ok', port()} | {'already_started', port()}).
+-spec profile(Filename :: file:filename()) ->
+ {'ok', port()} | {'already_started', port()}.
profile(Filename) ->
percept_profile:start(Filename, [procs]).
@@ -94,10 +94,9 @@ profile(Filename) ->
%% @spec profile(Filename::string(), [percept_option()]) -> {ok, Port} | {already_started, Port}
%% @see percept_profile
--spec(profile/2 :: (
- Filename :: string(),
- Options :: [percept_option()]) ->
- {'ok', port()} | {'already_started', port()}).
+-spec profile(Filename :: file:filename(),
+ Options :: [percept_option()]) ->
+ {'ok', port()} | {'already_started', port()}.
profile(Filename, Options) ->
percept_profile:start(Filename, Options).
@@ -105,16 +104,15 @@ profile(Filename, Options) ->
%% @spec profile(Filename::string(), MFA::mfa(), [percept_option()]) -> ok | {already_started, Port} | {error, not_started}
%% @see percept_profile
--spec(profile/3 :: (
- Filename :: string(),
- Entry :: {atom(), atom(), list()},
- Options :: [percept_option()]) ->
- 'ok' | {'already_started', port()} | {'error', 'not_started'}).
+-spec profile(Filename :: file:filename(),
+ Entry :: {atom(), atom(), list()},
+ Options :: [percept_option()]) ->
+ 'ok' | {'already_started', port()} | {'error', 'not_started'}.
profile(Filename, MFA, Options) ->
percept_profile:start(Filename, MFA, Options).
--spec(stop_profile/0 :: () -> 'ok' | {'error', 'not_started'}).
+-spec stop_profile() -> 'ok' | {'error', 'not_started'}.
%% @spec stop_profile() -> ok | {'error', 'not_started'}
%% @see percept_profile
@@ -125,8 +123,8 @@ stop_profile() ->
%% @spec analyze(string()) -> ok | {error, Reason}
%% @doc Analyze file.
--spec(analyze/1 :: (Filename :: string()) ->
- 'ok' | {'error', any()}).
+-spec analyze(Filename :: file:filename()) ->
+ 'ok' | {'error', any()}.
analyze(Filename) ->
case percept_db:start() of
@@ -142,9 +140,8 @@ analyze(Filename) ->
%% Reason = term()
%% @doc Starts webserver.
--spec(start_webserver/0 :: () ->
- {'started', string(), pos_integer()} |
- {'error', any()}).
+-spec start_webserver() ->
+ {'started', string(), pos_integer()} | {'error', any()}.
start_webserver() ->
start_webserver(0).
@@ -156,9 +153,8 @@ start_webserver() ->
%% @doc Starts webserver. If port number is 0, an available port number will
%% be assigned by inets.
--spec(start_webserver/1 :: (Port :: non_neg_integer()) ->
- {'started', string(), pos_integer()} |
- {'error', any()}).
+-spec start_webserver(Port :: non_neg_integer()) ->
+ {'started', string(), pos_integer()} | {'error', any()}.
start_webserver(Port) when is_integer(Port) ->
application:load(percept),
diff --git a/lib/percept/src/percept.hrl b/lib/percept/src/percept.hrl
index a9afceb6d1..3772a0164b 100644
--- a/lib/percept/src/percept.hrl
+++ b/lib/percept/src/percept.hrl
@@ -23,10 +23,10 @@
%%% Type definitions %%%
%%% ------------------- %%%
--type(timestamp() :: {non_neg_integer(), non_neg_integer(), non_neg_integer()}).
--type(true_mfa() :: {atom(), atom(), byte() | list()}).
--type(state() :: 'active' | 'inactive').
--type(scheduler_id() :: {'scheduler_id', non_neg_integer()}).
+-type timestamp() :: {non_neg_integer(), non_neg_integer(), non_neg_integer()}.
+-type true_mfa() :: {atom(), atom(), byte() | list()}.
+-type state() :: 'active' | 'inactive'.
+-type scheduler_id() :: {'scheduler_id', non_neg_integer()}.
%%% ------------------- %%%
%%% Records %%%
diff --git a/lib/percept/src/percept_db.erl b/lib/percept/src/percept_db.erl
index dc85fa3510..df29381c57 100644
--- a/lib/percept/src/percept_db.erl
+++ b/lib/percept/src/percept_db.erl
@@ -72,7 +72,7 @@
%% Pid = pid()
%% @doc Starts or restarts the percept database.
--spec(start/0 :: () -> {'started', pid()} | {'restarted', pid()}).
+-spec start() -> {'started', pid()} | {'restarted', pid()}.
start() ->
case erlang:whereis(percept_db) of
@@ -92,7 +92,7 @@ start() ->
%% Pid = pid()
%% @doc Stops the percept database.
--spec(stop/0 :: () -> 'not_started' | {'stopped', pid()}).
+-spec stop() -> 'not_started' | {'stopped', pid()}.
stop() ->
case erlang:whereis(percept_db) of
diff --git a/lib/percept/src/percept_html.erl b/lib/percept/src/percept_html.erl
index ffce7a98fa..3039ab0227 100644
--- a/lib/percept/src/percept_html.erl
+++ b/lib/percept/src/percept_html.erl
@@ -172,12 +172,12 @@ div_tag_graph() ->
width:40px;
height:40px;\"></div></div>".
--spec(url_graph/5 :: (
+-spec url_graph(
Widht :: non_neg_integer(),
Height :: non_neg_integer(),
Min :: float(),
Max :: float(),
- Pids :: [pid()]) -> string()).
+ Pids :: [pid()]) -> string().
url_graph(W, H, Min, Max, []) ->
"/cgi-bin/percept_graph/graph?range_min=" ++ term2html(float(Min))
@@ -508,10 +508,7 @@ cl_deltas([A,B|Ls], Out) -> cl_deltas([B|Ls], [B - A | Out]).
join_strings(Strings) ->
lists:flatten(Strings).
--spec(join_strings_with/2 :: (
- Strings :: [string()],
- Separator :: string()) ->
- string()).
+-spec join_strings_with(Strings :: [string()], Separator :: string()) -> string().
join_strings_with([S1, S2 | R], S) ->
join_strings_with([join_strings_with(S1,S2,S) | R], S);
@@ -522,7 +519,7 @@ join_strings_with(S1, S2, S) ->
%%% Generic erlang2html
--spec(html_table/1 :: (Rows :: [[string() | {'td' | 'th', string()}]]) -> string()).
+-spec html_table(Rows :: [[string() | {'td' | 'th', string()}]]) -> string().
html_table(Rows) -> "<table>" ++ html_table_row(Rows) ++ "</table>".
@@ -539,7 +536,7 @@ html_table_data([Data|Row]) -> "<td>" ++ Data ++ "</td>" ++ html_table_dat
--spec(table_line/1 :: (Table :: [any()]) -> string()).
+-spec table_line(Table :: [any()]) -> string().
table_line(List) -> table_line(List, ["<tr>"]).
table_line([], Out) -> lists:flatten(lists:reverse(["</tr>\n"|Out]));
@@ -548,16 +545,12 @@ table_line([Element | Elements], Out) when is_list(Element) ->
table_line([Element | Elements], Out) ->
table_line(Elements, ["<td>" ++ term2html(Element) ++ "</td>"|Out]).
--spec(term2html/1 :: (any()) -> string()).
+-spec term2html(any()) -> string().
term2html(Term) when is_float(Term) -> lists:flatten(io_lib:format("~.4f", [Term]));
term2html(Term) -> lists:flatten(io_lib:format("~p", [Term])).
--spec(mfa2html/1 :: (MFA :: {
- atom(),
- atom(),
- list() | integer()}) ->
- string()).
+-spec mfa2html(MFA :: {atom(), atom(), list() | integer()}) -> string().
mfa2html({Module, Function, Arguments}) when is_list(Arguments) ->
lists:flatten(io_lib:format("~p:~p/~p", [Module, Function, length(Arguments)]));
@@ -566,7 +559,7 @@ mfa2html({Module, Function, Arity}) when is_integer(Arity) ->
mfa2html(_) ->
"undefined".
--spec(pid2html/1 :: (Pid :: pid() | port()) -> string()).
+-spec pid2html(Pid :: pid() | port()) -> string().
pid2html(Pid) when is_pid(Pid) ->
PidString = term2html(Pid),
@@ -577,14 +570,14 @@ pid2html(Pid) when is_port(Pid) ->
pid2html(_) ->
"undefined".
--spec(image_string/1 :: (Request :: string()) -> string()).
+-spec image_string(Request :: string()) -> string().
image_string(Request) ->
"<img border=0 src=\"/cgi-bin/percept_graph/" ++
Request ++
" \">".
--spec(image_string/2 :: (atom() | string(), list()) -> string()).
+-spec image_string(atom() | string(), list()) -> string().
image_string(Request, Options) when is_atom(Request), is_list(Options) ->
image_string(image_string_head(erlang:atom_to_list(Request), Options, []));
@@ -610,13 +603,13 @@ image_string_tail(Request, [{Type, Value} | Opts], Out) ->
%%% percept conversions
--spec(pid2value/1 :: (Pid :: pid()) -> string()).
+-spec pid2value(Pid :: pid()) -> string().
pid2value(Pid) ->
String = lists:flatten(io_lib:format("~p", [Pid])),
lists:sublist(String, 2, erlang:length(String)-2).
--spec(value2pid/1 :: (Value :: string()) -> pid()).
+-spec value2pid(Value :: string()) -> pid().
value2pid(Value) ->
String = lists:flatten("<" ++ Value ++ ">"),
@@ -625,10 +618,8 @@ value2pid(Value) ->
%%% get value
--spec(get_option_value/2 :: (
- Option :: string(),
- Options :: [{string(),any()}]) ->
- {'error', any()} | bool() | pid() | [pid()] | number()).
+-spec get_option_value(Option :: string(), Options :: [{string(),any()}]) ->
+ {'error', any()} | boolean() | pid() | [pid()] | number().
get_option_value(Option, Options) ->
case catch get_option_value0(Option, Options) of
@@ -662,8 +653,7 @@ get_default_option_value(Option) ->
_ -> {error, {undefined_default_option, Option}}
end.
--spec(get_number_value/1 :: (Value :: string()) ->
- number() | {'error', 'illegal_number'}).
+-spec get_number_value(string()) -> number() | {'error', 'illegal_number'}.
get_number_value(Value) ->
% Try float
@@ -710,7 +700,7 @@ menu() ->
<li><a href=/cgi-bin/percept_html/page>overview</a></li>
</ul></div>\n".
--spec(error_msg/1 :: (Error :: string()) -> string()).
+-spec error_msg(Error :: string()) -> string().
error_msg(Error) ->
"<table width=300>