diff options
author | Björn Gustavsson <[email protected]> | 2010-10-06 14:31:42 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2010-10-06 14:31:42 +0200 |
commit | b7c6b7d8082f4df2d0888292e2a2180cc60ebab2 (patch) | |
tree | 4aa994eaa97d300945fc2d299b1d72688de8106a | |
parent | 90b514aa9f2aa35b93136ea9776543d8e4461f41 (diff) | |
parent | 44d6f54d6782d63a25d80f6d920d67adb33bda52 (diff) | |
download | otp-b7c6b7d8082f4df2d0888292e2a2180cc60ebab2.tar.gz otp-b7c6b7d8082f4df2d0888292e2a2180cc60ebab2.tar.bz2 otp-b7c6b7d8082f4df2d0888292e2a2180cc60ebab2.zip |
Merge branch 'ks/syntax_tools-types' into dev
* ks/syntax_tools-types:
syntax_tools: Add types to record definitions
-rw-r--r-- | lib/syntax_tools/src/erl_prettypr.erl | 16 | ||||
-rw-r--r-- | lib/syntax_tools/src/erl_recomment.erl | 5 | ||||
-rw-r--r-- | lib/syntax_tools/src/erl_syntax_lib.erl | 26 | ||||
-rw-r--r-- | lib/syntax_tools/src/erl_tidy.erl | 15 | ||||
-rw-r--r-- | lib/syntax_tools/src/igor.erl | 18 |
5 files changed, 47 insertions, 33 deletions
diff --git a/lib/syntax_tools/src/erl_prettypr.erl b/lib/syntax_tools/src/erl_prettypr.erl index c2c72d1ed2..7caf0b3db6 100644 --- a/lib/syntax_tools/src/erl_prettypr.erl +++ b/lib/syntax_tools/src/erl_prettypr.erl @@ -50,11 +50,15 @@ -type hook() :: 'none' | fun((erl_syntax:syntaxTree(), _, _) -> prettypr:document()). +-type clause_t() :: 'case_expr' | 'cond_expr' | 'fun_expr' + | 'if_expr' | 'receive_expr' | 'try_expr' + | {'function', prettypr:document()} + | {'rule', prettypr:document()}. -record(ctxt, {prec = 0 :: integer(), sub_indent = 2 :: non_neg_integer(), break_indent = 4 :: non_neg_integer(), - clause = undefined, + clause = undefined :: clause_t() | 'undefined', hook = ?NOHOOK :: hook(), paper = ?PAPER :: integer(), ribbon = ?RIBBON :: integer(), @@ -599,9 +603,8 @@ lay_2(Node, Ctxt) -> case_expr -> Ctxt1 = reset_prec(Ctxt), D1 = lay(erl_syntax:case_expr_argument(Node), Ctxt1), - D2 = lay_clauses( - erl_syntax:case_expr_clauses(Node), - case_expr, Ctxt1), + D2 = lay_clauses(erl_syntax:case_expr_clauses(Node), + case_expr, Ctxt1), sep([par([follow(text("case"), D1, Ctxt1#ctxt.sub_indent), text("of")], Ctxt1#ctxt.break_indent), @@ -819,9 +822,8 @@ lay_2(Node, Ctxt) -> receive_expr -> Ctxt1 = reset_prec(Ctxt), - D1 = lay_clauses( - erl_syntax:receive_expr_clauses(Node), - receive_expr, Ctxt1), + D1 = lay_clauses(erl_syntax:receive_expr_clauses(Node), + receive_expr, Ctxt1), D2 = case erl_syntax:receive_expr_timeout(Node) of none -> D1; diff --git a/lib/syntax_tools/src/erl_recomment.erl b/lib/syntax_tools/src/erl_recomment.erl index 94e760dad7..919e9cfc5d 100644 --- a/lib/syntax_tools/src/erl_recomment.erl +++ b/lib/syntax_tools/src/erl_recomment.erl @@ -215,7 +215,8 @@ comment_delta(Text) -> %% the source file itself, but have been included by preprocessing. This %% way, comments will not be inserted into such parts by mistake. --record(filter, {file = undefined, line = 0 :: integer()}). +-record(filter, {file = undefined :: file:filename() | 'undefined', + line = 0 :: integer()}). filter_forms(Fs) -> filter_forms(Fs, false, #filter{}). @@ -721,8 +722,6 @@ tree_node_attrs(#tree{attrs = Attrs}) -> %% ===================================================================== %% General utility functions -%% Just the generic "maximum" function - %% Return the least positive integer of X and Y, or zero if none of them %% are positive. (This is necessary for computing minimum source line %% numbers, since zero (or negative) numbers may occur, but they diff --git a/lib/syntax_tools/src/erl_syntax_lib.erl b/lib/syntax_tools/src/erl_syntax_lib.erl index 4808971a59..daef74e874 100644 --- a/lib/syntax_tools/src/erl_syntax_lib.erl +++ b/lib/syntax_tools/src/erl_syntax_lib.erl @@ -1134,21 +1134,21 @@ collect_attribute(_, {N, V}, Info) -> %% Abstract datatype for collecting module information. --record(forms, {module, exports, module_imports, imports, attributes, - records, errors, warnings, functions, rules}). +-record(forms, {module = none :: 'none' | {'value', atom()}, + exports = [] :: [{atom(), arity()}], + module_imports = [] :: [atom()], + imports = [] :: [{atom(), [{atom(), arity()}]}], + attributes = [] :: [{atom(), term()}], + records = [] :: [{atom(), [{atom(), field_default()}]}], + errors = [] :: [term()], + warnings = [] :: [term()], + functions = [] :: [{atom(), arity()}], + rules = [] :: [{atom(), arity()}]}). + +-type field_default() :: 'none' | erl_syntax:syntaxTree(). new_finfo() -> - #forms{module = none, - exports = [], - module_imports = [], - imports = [], - attributes = [], - records = [], - errors = [], - warnings = [], - functions = [], - rules = [] - }. + #forms{}. finfo_set_module(Name, Info) -> case Info#forms.module of diff --git a/lib/syntax_tools/src/erl_tidy.erl b/lib/syntax_tools/src/erl_tidy.erl index 021ab18736..1cfdc7234a 100644 --- a/lib/syntax_tools/src/erl_tidy.erl +++ b/lib/syntax_tools/src/erl_tidy.erl @@ -935,12 +935,13 @@ hidden_uses_2(Tree, Used) -> Used end. +-type fa() :: {atom(), arity()}. -type context() :: 'guard_expr' | 'guard_test' | 'normal'. -record(env, {file :: file:filename(), - module, - current, - imports, + module :: atom(), + current :: fa(), + imports = dict:new() :: dict(), context = normal :: context(), verbosity = 1 :: 0 | 1 | 2, quiet = false :: boolean(), @@ -951,7 +952,13 @@ hidden_uses_2(Tree, Used) -> new_guard_tests = true :: boolean(), old_guard_tests = false :: boolean()}). --record(st, {varc, used, imported, vars, functions, new_forms, rename}). +-record(st, {varc :: non_neg_integer(), + used = sets:new() :: set(), + imported :: set(), + vars :: set(), + functions :: set(), + new_forms = [] :: [erl_syntax:syntaxTree()], + rename :: dict()}). visit_used(Names, Defs, Roots, Imports, Module, Opts) -> File = proplists:get_value(file, Opts, ""), diff --git a/lib/syntax_tools/src/igor.erl b/lib/syntax_tools/src/igor.erl index 702b399615..7ec62f1dba 100644 --- a/lib/syntax_tools/src/igor.erl +++ b/lib/syntax_tools/src/igor.erl @@ -1035,7 +1035,12 @@ make_stub(M, Map, Env) -> %% Removing and/or out-commenting program forms. The returned form %% sequence tree is not necessarily flat. --record(filter, {records :: set(), file_attributes, attributes}). +-type atts() :: 'delete' | 'kill'. +-type file_atts() :: 'delete' | 'keep' | 'kill'. + +-record(filter, {records :: set(), + file_attributes :: file_atts(), + attributes :: atts()}). filter_forms(Tree, Env) -> Forms = erl_syntax:form_list_elements( @@ -1576,6 +1581,8 @@ alias_expansions_2(Modules, Table) -> %% --------------------------------------------------------------------- %% Merging the source code. +-type map_fun() :: fun(({atom(), integer()}) -> {atom(), integer()}). + %% Data structure for code transformation environment. -record(code, {module :: atom(), @@ -1586,11 +1593,10 @@ alias_expansions_2(Modules, Table) -> preserved :: boolean(), no_headers :: boolean(), notes :: notes(), - map, % = ({atom(), int()}) -> {atom(), int()} - renaming, % = (atom()) -> ({atom(), int()}) -> - % {atom(), int()} - expand :: dict(), % = dict({atom(), int()}, - % {atom(), {atom(), int()}}) + map :: map_fun(), + renaming :: fun((atom()) -> map_fun()), + expand :: dict(), % = dict({atom(), integer()}, + % {atom(), {atom(), integer()}}) redirect :: dict() % = dict(atom(), atom()) }). |