From ca1b6706239197ce37da5107a49f45c72de0b7f1 Mon Sep 17 00:00:00 2001 From: Ulf Wiger Date: Thu, 13 Jan 2011 18:07:27 +0100 Subject: [PATCH] dialyzer warnings reported by Kostis --- doc/ct_expand.md | 4 +++- doc/exprecs.md | 4 +++- doc/parse_trans.md | 4 +++- doc/parse_trans_codegen.md | 4 +++- doc/parse_trans_pp.md | 4 +++- ebin/.gitignore | 0 src/parse_trans.erl | 35 +++++++++++++++++++---------------- 7 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 ebin/.gitignore diff --git a/doc/ct_expand.md b/doc/ct_expand.md index 5ab0e13..34fcff8 100644 --- a/doc/ct_expand.md +++ b/doc/ct_expand.md @@ -7,6 +7,8 @@ Module ct_expand * [Description](#description) * [Function Index](#index) * [Function Details](#functions) + + Compile-time expansion utility. @@ -62,4 +64,4 @@ would be expanded at compile-time to `[1,2,3,4,5]`. -_Generated by EDoc, Oct 31 2010, 18:33:42._ \ No newline at end of file +_Generated by EDoc, Nov 11 2010, 22:26:54._ \ No newline at end of file diff --git a/doc/exprecs.md b/doc/exprecs.md index 62bc668..3d6c04d 100644 --- a/doc/exprecs.md +++ b/doc/exprecs.md @@ -7,6 +7,8 @@ Module exprecs * [Description](#description) * [Function Index](#index) * [Function Details](#functions) + + Parse transform for generating record access functions. @@ -142,4 +144,4 @@ F(AttrNames, Rec, F). -_Generated by EDoc, Oct 31 2010, 18:33:42._ \ No newline at end of file +_Generated by EDoc, Nov 11 2010, 22:26:54._ \ No newline at end of file diff --git a/doc/parse_trans.md b/doc/parse_trans.md index e67b96e..7259972 100644 --- a/doc/parse_trans.md +++ b/doc/parse_trans.md @@ -7,6 +7,8 @@ Module parse_trans * [Description](#description) * [Function Index](#index) * [Function Details](#functions) + + Generic parse transform library for Erlang. @@ -393,4 +395,4 @@ regular Erlang forms. Makes one pass -_Generated by EDoc, Oct 31 2010, 18:33:42._ \ No newline at end of file +_Generated by EDoc, Nov 11 2010, 22:26:54._ \ No newline at end of file diff --git a/doc/parse_trans_codegen.md b/doc/parse_trans_codegen.md index c3b0c44..29eef55 100644 --- a/doc/parse_trans_codegen.md +++ b/doc/parse_trans_codegen.md @@ -7,6 +7,8 @@ Module parse_trans_codegen * [Description](#description) * [Function Index](#index) * [Function Details](#functions) + + Parse transform for code generation pseduo functions. @@ -180,4 +182,4 @@ X =:= foo. -_Generated by EDoc, Oct 31 2010, 18:33:42._ \ No newline at end of file +_Generated by EDoc, Nov 11 2010, 22:26:54._ \ No newline at end of file diff --git a/doc/parse_trans_pp.md b/doc/parse_trans_pp.md index 2c523b4..d273f95 100644 --- a/doc/parse_trans_pp.md +++ b/doc/parse_trans_pp.md @@ -7,6 +7,8 @@ Module parse_trans_pp * [Description](#description) * [Function Index](#index) * [Function Details](#functions) + + Generic parse transform library for Erlang. @@ -113,4 +115,4 @@ Erlang source code, storing it in the file Out. Pretty-prints the erlang source code corresponding to Forms into Out -_Generated by EDoc, Oct 31 2010, 18:33:42._ \ No newline at end of file +_Generated by EDoc, Nov 11 2010, 22:26:54._ \ No newline at end of file diff --git a/ebin/.gitignore b/ebin/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/src/parse_trans.erl b/src/parse_trans.erl index 4d075d0..28c390c 100644 --- a/src/parse_trans.erl +++ b/src/parse_trans.erl @@ -89,18 +89,22 @@ -define(ERROR(R, F, I), begin rpt_error(R, F, I), - throw({error,get_pos(I),{unknown,R}}) end). -%% Typer typedefs +-export_type([forms/0]). + +%% Typedefs -type form() :: any(). -type forms() :: [form()]. -type options() :: [{atom(), any()}]. -type type() :: atom(). --type xform_f() :: fun((type(), form(), #context{}, Acc) -> - {form(), boolean(), Acc} - | {forms(), form(), forms(), boolean(), Acc}). +-type xform_f_rec() :: fun((type(), form(), #context{}, Acc) -> + {form(), boolean(), Acc} + | {forms(), form(), forms(), boolean(), Acc}). +-type xform_f_df() :: fun((type(), form(), #context{}, Acc) -> + {form(), Acc} + | {forms(), form(), forms(), Acc}). -type insp_f() :: fun((type(), form(), #context{}, A) -> {boolean(), A}). @@ -168,7 +172,8 @@ get_module(Forms) -> %%% @end %%% -spec get_attribute(atom(), [any()]) -> - false | list(). + 'none' | [erl_syntax:syntaxTree()]. +%% get_attribute(A, Forms) -> case find_attribute(A, Forms) of false -> @@ -229,12 +234,12 @@ initial_context(Forms, Options) -> %%% @doc %%% Makes one pass %%% @end --spec transform(xform_f(), Acc, forms(), options()) -> +-spec transform(xform_f_rec(), Acc, forms(), options()) -> {forms(), Acc} | {error, list()}. transform(Fun, Acc, Forms, Options) when is_function(Fun, 4) -> do(fun do_transform/4, Fun, Acc, Forms, Options). --spec depth_first(xform_f(), Acc, forms(), options()) -> +-spec depth_first(xform_f_df(), Acc, forms(), options()) -> {forms(), Acc} | {error, list()}. depth_first(Fun, Acc, Forms, Options) when is_function(Fun, 4) -> do(fun do_depth_first/4, Fun, Acc, Forms, Options). @@ -306,9 +311,9 @@ optionally_pretty_print(Result, Options, Context) -> if DoLFs -> Out1 = outfile(File, forms), {ok,Fd} = file:open(Out1, [write]), - try [io:fwrite(Fd, "~p.~n", [F]) || F <- Result] + try lists:foreach(fun(F) -> io:fwrite(Fd, "~p.~n", [F]) end, Result) after - file:close(Fd) + ok = file:close(Fd) end; true -> ok end, @@ -369,13 +374,13 @@ pp_src(Res, F) -> %% Fm <- revert(Res)])])], %% file:write_file(F, list_to_binary(Str)). -%% @spec (Beam::filename()) -> string() | {error, Reason} +%% @spec (Beam::file:filename()) -> string() | {error, Reason} %% %% @doc %% Reads debug_info from the beam file Beam and returns a string containing %% the pretty-printed corresponding erlang source code. %% @end --spec pp_beam(filename:filename()) -> ok. +-spec pp_beam(file:filename()) -> ok. pp_beam(Beam) -> parse_trans_pp:pp_beam(Beam). @@ -402,8 +407,6 @@ pp_beam(F, Out) -> %%% -spec get_orig_syntax_tree(string()) -> forms(). -get_orig_syntax_tree(undefined) -> - ?ERROR(unknown_source_file, ?HERE, []); get_orig_syntax_tree(File) -> case epp_dodger:parse_file(File) of {ok, Forms} -> @@ -473,7 +476,7 @@ recurse(Form, Else, F) -> F(ListOfLists) end. --spec do_transform(xform_f(), term(), forms(), #context{}) -> +-spec do_transform(xform_f_rec(), term(), forms(), #context{}) -> {forms(), term()}. do_transform(F, Acc, Forms, Context) -> Rec = fun do_transform/4, % this function @@ -491,7 +494,7 @@ do_transform(F, Acc, Forms, Context) -> end, mapfoldl(F1, Acc, Forms). --spec do_depth_first(xform_f(), term(), forms(), #context{}) -> +-spec do_depth_first(xform_f_df(), term(), forms(), #context{}) -> {forms(), term()}. do_depth_first(F, Acc, Forms, Context) -> Rec = fun do_depth_first/4, % this function