%% %CopyrightBegin% %% %% 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. %% %% %CopyrightEnd% -module(gradualizer_type). -export_type([abstract_expr/0, abstract_clause/0, abstract_type/0]). %% Export the additional types that gradualizer uses -export_type([abstract_pattern/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 abstract_clause() :: af_clause(). -type abstract_pattern() :: af_pattern(). -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_atom(), af_integer()}}. -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 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(abstract_expr()) | af_map_update(abstract_expr()) | 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(), function_name(), [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(abstract_expr())]}. -type abstract_type() :: af_annotated_type() | af_atom() | af_bitstring_type() | af_empty_list_type() | af_fun_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_range_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()]}. -type af_type_variable() :: {'var', anno(), atom()}. % except '_' -type af_user_defined_type() :: {'user_type', anno(), type_name(), [abstract_type()]}. -type af_function_type() :: {'type', anno(), 'fun', [{'type', anno(), 'product', [abstract_type()]} | abstract_type()]}. -type af_range_integer_type() :: 'pos_inf' | 'neg_inf' | af_singleton_integer_type(). -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(). %% End of Abstract Format