Current section

Files

Jump to
gradualizer src gradualizer_type.erl
Raw

src/gradualizer_type.erl

%% @private
%% This file was automatically generated from the file "erl_parse.yrl".
%%
%% Copyright Ericsson AB 1996-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
-module(gradualizer_type).
-export_type([abstract_clause/0, abstract_expr/0,
abstract_type/0, form_info/0, error_info/0]).
%% Export the additional types that gradualizer uses
-export_type([abstract_pattern/0,
af_assoc_type/0,
af_binary_op/1,
af_constrained_function_type/0,
af_constraint/0,
af_fun_type/0,
af_function_type_list/0,
af_record_field/1,
af_string/0,
af_unary_op/1,
binary_op/0,
gr_type_var/0,
unary_op/0]).
%% Start of Abstract Format
-type anno() :: erl_anno:anno().
-type abstract_expr() :: af_literal()
| af_match(abstract_expr())
| af_variable()
| af_tuple(abstract_expr())
| af_nil()
| af_cons(abstract_expr())
| af_bin(abstract_expr())
| af_binary_op(abstract_expr())
| af_unary_op(abstract_expr())
| af_record_creation(abstract_expr())
| af_record_update(abstract_expr())
| af_record_index()
| af_record_field_access(abstract_expr())
| af_map_creation(abstract_expr())
| af_map_update(abstract_expr())
| af_catch()
| af_local_call()
| af_remote_call()
| af_list_comprehension()
| af_binary_comprehension()
| af_block()
| af_if()
| af_case()
| af_try()
| af_receive()
| af_local_fun()
| af_remote_fun()
| af_fun()
| af_named_fun().
-type af_record_update(T) :: {'record',
anno(),
abstract_expr(),
record_name(),
[af_record_field(T)]}.
-type af_catch() :: {'catch', anno(), abstract_expr()}.
-type af_local_call() :: {'call', anno(), af_local_function(), af_args()}.
-type af_remote_call() :: {'call', anno(), af_remote_function(), af_args()}.
-type af_args() :: [abstract_expr()].
-type af_local_function() :: abstract_expr().
-type af_remote_function() ::
{'remote', anno(), abstract_expr(), abstract_expr()}.
-type af_list_comprehension() ::
{'lc', anno(), af_template(), af_qualifier_seq()}.
-type af_binary_comprehension() ::
{'bc', anno(), af_template(), af_qualifier_seq()}.
-type af_template() :: abstract_expr().
-type af_qualifier_seq() :: [af_qualifier(), ...].
-type af_qualifier() :: af_generator() | af_filter().
-type af_generator() :: {'generate', anno(), af_pattern(), abstract_expr()}
| {'b_generate', anno(), af_pattern(), abstract_expr()}.
-type af_filter() :: abstract_expr().
-type af_block() :: {'block', anno(), af_body()}.
-type af_if() :: {'if', anno(), af_clause_seq()}.
-type af_case() :: {'case', anno(), abstract_expr(), af_clause_seq()}.
-type af_try() :: {'try',
anno(),
af_body(),
af_clause_seq() | [],
af_clause_seq() | [],
af_body() | []}.
-type af_clause_seq() :: [af_clause(), ...].
-type af_receive() ::
{'receive', anno(), af_clause_seq()}
| {'receive', anno(), af_clause_seq(), abstract_expr(), af_body()}.
-type af_local_fun() ::
{'fun', anno(), {'function', function_name(), arity()}}.
-type af_remote_fun() ::
{'fun', anno(), {'function', module(), function_name(), arity()}}
| {'fun', anno(), {'function',
af_atom() | af_variable(),
af_atom() | af_variable(),
af_integer() | af_variable()}}.
-type af_fun() :: {'fun', anno(), {'clauses', af_clause_seq()}}.
-type af_named_fun() :: {'named_fun', anno(), fun_name(), af_clause_seq()}.
-type fun_name() :: atom().
-type abstract_clause() :: af_clause().
-type abstract_pattern() :: af_pattern().
-type af_clause() ::
{'clause', anno(), [af_pattern()], af_guard_seq(), af_body()}.
-type af_body() :: [abstract_expr(), ...].
-type af_guard_seq() :: [af_guard()].
-type af_guard() :: [af_guard_test(), ...].
-type af_guard_test() :: af_literal()
| af_variable()
| af_tuple(af_guard_test())
| af_nil()
| af_cons(af_guard_test())
| af_bin(af_guard_test())
| af_binary_op(af_guard_test())
| af_unary_op(af_guard_test())
| af_record_creation(af_guard_test())
| af_record_index()
| af_record_field_access(af_guard_test())
| af_map_creation(af_guard_test())
| af_map_update(af_guard_test())
| af_guard_call()
| af_remote_guard_call().
-type af_record_field_access(T) ::
{'record_field', anno(), T, record_name(), af_field_name()}.
-type af_map_creation(T) :: {'map', anno(), [af_assoc(T)]}.
-type af_map_update(T) :: {'map', anno(), T, [af_assoc(T)]}.
-type af_assoc(T) :: {'map_field_assoc', anno(), T, T}
| af_assoc_exact(T).
-type af_assoc_exact(T) :: {'map_field_exact', anno(), T, T}.
-type af_guard_call() :: {'call', anno(), af_atom(), [af_guard_test()]}.
-type af_remote_guard_call() ::
{'call', anno(),
{'remote', anno(), af_lit_atom('erlang'), af_atom()},
[af_guard_test()]}.
-type af_pattern() :: af_literal()
| af_match(af_pattern())
| af_variable()
| af_tuple(af_pattern())
| af_nil()
| af_cons(af_pattern())
| af_bin(af_pattern())
| af_binary_op(af_pattern())
| af_unary_op(af_pattern())
| af_record_creation(af_pattern())
| af_record_index()
| af_map_pattern().
-type af_record_index() ::
{'record_index', anno(), record_name(), af_field_name()}.
-type af_record_creation(T) ::
{'record', anno(), record_name(), [af_record_field(T)]}.
-type af_record_field(T) :: {'record_field', anno(), af_field_name(), T}.
-type af_map_pattern() ::
{'map', anno(), [af_assoc_exact(af_pattern())]}.
-type abstract_type() :: af_annotated_type()
| af_atom()
| af_bitstring_type()
| af_empty_list_type()
| af_fun_type()
| af_constrained_function_type()
| af_integer_range_type()
| af_map_type()
| af_predefined_type()
| af_record_type()
| af_remote_type()
| af_singleton_integer_type()
| af_tuple_type()
| af_type_union()
| af_type_variable()
| af_user_defined_type().
-type af_annotated_type() ::
{'ann_type', anno(), [af_anno() | abstract_type()]}. % [Var, Type]
-type af_anno() :: af_variable().
-type af_bitstring_type() ::
{'type', anno(), 'binary', [af_singleton_integer_type()]}.
-type af_empty_list_type() :: {'type', anno(), 'nil', []}.
-type af_fun_type() :: {'type', anno(), 'fun', []}
| {'type', anno(), 'fun', [{'type', anno(), 'any'} |
abstract_type()]}
| af_function_type().
-type af_integer_range_type() ::
{'type', anno(), 'range', [af_singleton_integer_type()]}.
-type af_map_type() :: {'type', anno(), 'map', 'any'}
| {'type', anno(), 'map', [af_assoc_type()]}.
-type af_assoc_type() ::
{'type', anno(), 'map_field_assoc', [abstract_type()]}
| {'type', anno(), 'map_field_exact', [abstract_type()]}.
-type af_predefined_type() ::
{'type', anno(), type_name(), [abstract_type()]}.
-type af_record_type() ::
{'type', anno(), 'record', [(Name :: af_atom()) % [Name, T1, ... Tk]
| af_record_field_type()]}.
-type af_record_field_type() ::
{'type', anno(), 'field_type', [(Name :: af_atom()) |
abstract_type()]}. % [Name, Type]
-type af_remote_type() ::
{'remote_type', anno(), [(Module :: af_atom()) |
(TypeName :: af_atom()) |
[abstract_type()]]}. % [Module, Name, [T]]
-type af_tuple_type() :: {'type', anno(), 'tuple', 'any'}
| {'type', anno(), 'tuple', [abstract_type()]}.
-type af_type_union() ::
{'type', anno(), 'union', [abstract_type(), ...]}. % at least two
%% Gradualizer-specific:
%% - for explicit type variables, `var' is any atom except `_'
%% - for implicit ones (autogenerated for fun parameters), `var' is a string
-type gr_type_var() :: atom() | string().
-type af_type_variable() :: {'var', anno(), gr_type_var()}.
-type af_user_defined_type() ::
{'user_type', anno(), type_name(), [abstract_type()]}.
%% Gradualizer: this is a part of `abstract_form()'.
%% We do not copy the entire `abstract_form()' from `erl_parse.erl',
%% but we want to have `af_function_type_list()' defined here as it's the only type
%% that defines the `bounded_fun' form which we use.
-type af_function_type_list() :: [af_constrained_function_type() |
af_function_type(), ...].
%% Gradualizer: we make `af_constrained_function_type()' part of `af_fun_type()',
%% and therefore a part of `abstract_type()'.
-type af_constrained_function_type() ::
{'type', anno(), 'bounded_fun', [af_function_type() | % [Ft, Fc]
af_function_constraint()]}.
-type af_function_type() ::
{'type', anno(), 'fun',
[{'type', anno(), 'product', [abstract_type()]} | abstract_type()]}.
%% Originally, `af_function_constraint()' is defined as a non-empty list.
%% In Gradualizer, however, all functions are normalized to the `bounded_fun' form,
%% so the constraints might be empty.
%-type af_function_constraint() :: [af_constraint(), ...].
-type af_function_constraint() :: [af_constraint()].
-type af_constraint() :: {'type', anno(), 'constraint',
[af_lit_atom('is_subtype') |
[af_type_variable() | abstract_type()]]}. % [IsSubtype, [V, T]]
-type af_singleton_integer_type() :: af_integer()
| af_character()
| af_unary_op(af_singleton_integer_type())
| af_binary_op(af_singleton_integer_type()).
-type af_literal() :: af_atom()
| af_character()
| af_float()
| af_integer()
| af_string().
-type af_atom() :: af_lit_atom(atom()).
-type af_lit_atom(A) :: {'atom', anno(), A}.
-type af_character() :: {'char', anno(), char()}.
-type af_float() :: {'float', anno(), float()}.
-type af_integer() :: {'integer', anno(), non_neg_integer()}.
-type af_string() :: {'string', anno(), string()}.
-type af_match(T) :: {'match', anno(), af_pattern(), T}.
-type af_variable() :: {'var', anno(), atom()}. % | af_anon_variable()
%-type af_anon_variable() :: {'var', anno(), '_'}.
-type af_tuple(T) :: {'tuple', anno(), [T]}.
-type af_nil() :: {'nil', anno()}.
-type af_cons(T) :: {'cons', anno(), T, T}.
-type af_bin(T) :: {'bin', anno(), [af_binelement(T)]}.
-type af_binelement(T) :: {'bin_element',
anno(),
T,
af_binelement_size(),
type_specifier_list()}.
-type af_binelement_size() :: 'default' | abstract_expr().
-type af_binary_op(T) :: {'op', anno(), binary_op(), T, T}.
-type binary_op() :: '/' | '*' | 'div' | 'rem' | 'band' | 'and' | '+' | '-'
| 'bor' | 'bxor' | 'bsl' | 'bsr' | 'or' | 'xor' | '++'
| '--' | '==' | '/=' | '=<' | '<' | '>=' | '>' | '=:='
| '=/='.
-type af_unary_op(T) :: {'op', anno(), unary_op(), T}.
-type unary_op() :: '+' | '-' | 'bnot' | 'not'.
%% See also lib/stdlib/{src/erl_bits.erl,include/erl_bits.hrl}.
-type type_specifier_list() :: 'default' | [type_specifier(), ...].
-type type_specifier() :: type()
| signedness()
| endianness()
| unit().
-type type() :: 'integer'
| 'float'
| 'binary'
| 'bytes'
| 'bitstring'
| 'bits'
| 'utf8'
| 'utf16'
| 'utf32'.
-type signedness() :: 'signed' | 'unsigned'.
-type endianness() :: 'big' | 'little' | 'native'.
-type unit() :: {'unit', 1..256}.
-type record_name() :: atom().
-type af_field_name() :: af_atom().
-type function_name() :: atom().
-type type_name() :: atom().
-type form_info() :: {'eof', erl_anno:location()}
| {'error', erl_scan:error_info() | error_info()}
| {'warning', erl_scan:error_info() | error_info()}.
%% End of Abstract Format
%% XXX. To be refined.
-type error_description() :: term().
-type error_info() :: {erl_anno:location(), module(), error_description()}.