2015-12-01 00:14:58 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Andrew Kelley
|
|
|
|
*
|
|
|
|
* This file is part of zig, which is MIT licensed.
|
|
|
|
* See http://opensource.org/licenses/MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ZIG_ANALYZE_HPP
|
|
|
|
#define ZIG_ANALYZE_HPP
|
|
|
|
|
2016-01-11 06:13:39 +08:00
|
|
|
#include "all_types.hpp"
|
2018-08-25 15:07:37 +08:00
|
|
|
#include "result.hpp"
|
2015-12-09 05:15:34 +08:00
|
|
|
|
2015-12-01 13:53:37 +08:00
|
|
|
void semantic_analyze(CodeGen *g);
|
2016-01-27 15:01:49 +08:00
|
|
|
ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg);
|
2016-02-28 13:06:46 +08:00
|
|
|
ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *msg);
|
2018-09-06 06:33:07 +08:00
|
|
|
ZigType *new_type_table_entry(ZigTypeId id);
|
|
|
|
ZigType *get_pointer_to_type(CodeGen *g, ZigType *child_type, bool is_const);
|
|
|
|
ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_const,
|
2018-06-04 13:09:15 +08:00
|
|
|
bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count);
|
2018-09-06 06:33:07 +08:00
|
|
|
uint64_t type_size(CodeGen *g, ZigType *type_entry);
|
|
|
|
uint64_t type_size_bits(CodeGen *g, ZigType *type_entry);
|
|
|
|
ZigType *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
|
|
|
|
ZigType **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);
|
|
|
|
ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type);
|
|
|
|
ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id);
|
|
|
|
ZigType *get_optional_type(CodeGen *g, ZigType *child_type);
|
|
|
|
ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size);
|
|
|
|
ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type);
|
|
|
|
ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,
|
2017-02-04 00:39:24 +08:00
|
|
|
AstNode *decl_node, const char *name, ContainerLayout layout);
|
2018-09-06 06:33:07 +08:00
|
|
|
ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x);
|
|
|
|
ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payload_type);
|
2018-09-06 06:34:33 +08:00
|
|
|
ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry);
|
2018-09-06 06:33:07 +08:00
|
|
|
ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name);
|
|
|
|
ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],
|
|
|
|
ZigType *field_types[], size_t field_count);
|
|
|
|
ZigType *get_promise_type(CodeGen *g, ZigType *result_type);
|
|
|
|
ZigType *get_promise_frame_type(CodeGen *g, ZigType *return_type);
|
|
|
|
ZigType *get_test_fn_type(CodeGen *g);
|
|
|
|
bool handle_is_ptr(ZigType *type_entry);
|
2016-02-16 07:52:37 +08:00
|
|
|
void find_libc_include_path(CodeGen *g);
|
|
|
|
void find_libc_lib_path(CodeGen *g);
|
2016-01-27 15:01:49 +08:00
|
|
|
|
2018-09-06 06:33:07 +08:00
|
|
|
bool type_has_bits(ZigType *type_entry);
|
2016-01-31 16:20:47 +08:00
|
|
|
|
2016-02-28 13:06:46 +08:00
|
|
|
|
2017-04-27 07:17:05 +08:00
|
|
|
ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code);
|
2016-02-28 13:06:46 +08:00
|
|
|
|
2016-10-09 14:20:01 +08:00
|
|
|
|
2018-09-06 08:32:06 +08:00
|
|
|
ZigVar *find_variable(CodeGen *g, Scope *orig_context, Buf *name, ScopeFnDef **crossed_fndef_scope);
|
2017-02-24 05:52:13 +08:00
|
|
|
Tld *find_decl(CodeGen *g, Scope *scope, Buf *name);
|
2017-06-04 03:09:40 +08:00
|
|
|
void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *source_node);
|
2018-09-06 06:33:07 +08:00
|
|
|
bool type_is_codegen_pointer(ZigType *type);
|
|
|
|
|
|
|
|
ZigType *get_codegen_ptr_type(ZigType *type);
|
|
|
|
uint32_t get_ptr_align(ZigType *type);
|
|
|
|
bool get_ptr_const(ZigType *type);
|
|
|
|
ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry);
|
|
|
|
ZigType *container_ref_type(ZigType *type_entry);
|
|
|
|
bool type_is_complete(ZigType *type_entry);
|
|
|
|
bool type_is_invalid(ZigType *type_entry);
|
|
|
|
bool type_is_global_error_set(ZigType *err_set_type);
|
|
|
|
bool type_has_zero_bits_known(ZigType *type_entry);
|
|
|
|
void resolve_container_type(CodeGen *g, ZigType *type_entry);
|
|
|
|
ScopeDecls *get_container_scope(ZigType *type_entry);
|
|
|
|
TypeStructField *find_struct_type_field(ZigType *type_entry, Buf *name);
|
|
|
|
TypeEnumField *find_enum_type_field(ZigType *enum_type, Buf *name);
|
|
|
|
TypeUnionField *find_union_type_field(ZigType *type_entry, Buf *name);
|
|
|
|
TypeEnumField *find_enum_field_by_tag(ZigType *enum_type, const BigInt *tag);
|
|
|
|
TypeUnionField *find_union_field_by_tag(ZigType *type_entry, const BigInt *tag);
|
|
|
|
|
|
|
|
bool is_ref(ZigType *type_entry);
|
|
|
|
bool is_array_ref(ZigType *type_entry);
|
|
|
|
bool is_container_ref(ZigType *type_entry);
|
2016-12-19 05:56:50 +08:00
|
|
|
void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node);
|
2017-04-28 04:15:41 +08:00
|
|
|
void scan_import(CodeGen *g, ImportTableEntry *import);
|
2016-11-27 09:52:22 +08:00
|
|
|
void preview_use_decl(CodeGen *g, AstNode *node);
|
|
|
|
void resolve_use_decl(CodeGen *g, AstNode *node);
|
2018-09-06 06:34:33 +08:00
|
|
|
ZigFn *scope_fn_entry(Scope *scope);
|
2016-12-02 12:25:09 +08:00
|
|
|
ImportTableEntry *get_scope_import(Scope *scope);
|
2016-12-19 05:56:50 +08:00
|
|
|
void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope);
|
2018-09-06 06:35:57 +08:00
|
|
|
ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
|
2017-03-21 03:32:13 +08:00
|
|
|
bool is_const, ConstExprValue *init_value, Tld *src_tld);
|
2018-09-06 06:33:07 +08:00
|
|
|
ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node);
|
2018-09-06 06:34:33 +08:00
|
|
|
ZigFn *create_fn(AstNode *proto_node);
|
|
|
|
ZigFn *create_fn_raw(FnInline inline_value, GlobalLinkageId linkage);
|
2017-02-01 05:04:26 +08:00
|
|
|
void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_count_alloc);
|
2018-09-06 06:34:33 +08:00
|
|
|
AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index);
|
|
|
|
ZigFn *scope_get_fn_if_root(Scope *scope);
|
2018-09-06 06:33:07 +08:00
|
|
|
bool type_requires_comptime(ZigType *type_entry);
|
|
|
|
Error ATTRIBUTE_MUST_USE ensure_complete_type(CodeGen *g, ZigType *type_entry);
|
|
|
|
Error ATTRIBUTE_MUST_USE type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry);
|
|
|
|
void complete_enum(CodeGen *g, ZigType *enum_type);
|
2018-09-06 06:35:57 +08:00
|
|
|
bool ir_get_var_is_comptime(ZigVar *var);
|
2016-12-25 17:15:23 +08:00
|
|
|
bool const_values_equal(ConstExprValue *a, ConstExprValue *b);
|
2018-09-06 06:33:07 +08:00
|
|
|
void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max);
|
|
|
|
void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max);
|
2016-10-03 11:48:48 +08:00
|
|
|
|
2017-04-24 01:22:36 +08:00
|
|
|
void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val);
|
2018-09-06 06:34:33 +08:00
|
|
|
void analyze_fn_ir(CodeGen *g, ZigFn *fn_table_entry, AstNode *return_type_node);
|
2017-01-05 16:22:00 +08:00
|
|
|
|
2016-12-18 09:47:35 +08:00
|
|
|
ScopeBlock *create_block_scope(AstNode *node, Scope *parent);
|
2016-12-07 10:26:17 +08:00
|
|
|
ScopeDefer *create_defer_scope(AstNode *node, Scope *parent);
|
2016-12-28 16:47:02 +08:00
|
|
|
ScopeDeferExpr *create_defer_expr_scope(AstNode *node, Scope *parent);
|
2018-09-06 06:35:57 +08:00
|
|
|
Scope *create_var_scope(AstNode *node, Scope *parent, ZigVar *var);
|
2016-12-11 13:13:43 +08:00
|
|
|
ScopeCImport *create_cimport_scope(AstNode *node, Scope *parent);
|
2017-05-21 22:41:57 +08:00
|
|
|
ScopeLoop *create_loop_scope(AstNode *node, Scope *parent);
|
2018-04-19 10:21:54 +08:00
|
|
|
ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent);
|
2018-09-06 06:34:33 +08:00
|
|
|
ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, ZigFn *fn_entry);
|
2018-09-06 06:33:07 +08:00
|
|
|
ScopeDecls *create_decls_scope(AstNode *node, Scope *parent, ZigType *container_type, ImportTableEntry *import);
|
2017-01-23 11:59:52 +08:00
|
|
|
Scope *create_comptime_scope(AstNode *node, Scope *parent);
|
2018-03-25 10:05:29 +08:00
|
|
|
Scope *create_coro_prelude_scope(AstNode *node, Scope *parent);
|
2018-09-05 03:28:13 +08:00
|
|
|
Scope *create_runtime_scope(AstNode *node, Scope *parent, IrInstruction *is_comptime);
|
2016-12-11 13:13:43 +08:00
|
|
|
|
2016-12-25 17:15:23 +08:00
|
|
|
void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str);
|
|
|
|
ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str);
|
2016-12-11 13:13:43 +08:00
|
|
|
|
2016-12-25 17:15:23 +08:00
|
|
|
void init_const_c_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *c_str);
|
|
|
|
ConstExprValue *create_const_c_str_lit(CodeGen *g, Buf *c_str);
|
2016-12-11 13:13:43 +08:00
|
|
|
|
2018-09-06 06:33:07 +08:00
|
|
|
void init_const_bigint(ConstExprValue *const_val, ZigType *type, const BigInt *bigint);
|
|
|
|
ConstExprValue *create_const_bigint(ZigType *type, const BigInt *bigint);
|
2017-12-03 11:31:42 +08:00
|
|
|
|
2018-09-06 06:33:07 +08:00
|
|
|
void init_const_unsigned_negative(ConstExprValue *const_val, ZigType *type, uint64_t x, bool negative);
|
|
|
|
ConstExprValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative);
|
2016-12-11 13:13:43 +08:00
|
|
|
|
2018-09-06 06:33:07 +08:00
|
|
|
void init_const_signed(ConstExprValue *const_val, ZigType *type, int64_t x);
|
|
|
|
ConstExprValue *create_const_signed(ZigType *type, int64_t x);
|
2016-12-02 10:08:12 +08:00
|
|
|
|
2016-12-25 17:15:23 +08:00
|
|
|
void init_const_usize(CodeGen *g, ConstExprValue *const_val, uint64_t x);
|
|
|
|
ConstExprValue *create_const_usize(CodeGen *g, uint64_t x);
|
2016-12-11 17:06:07 +08:00
|
|
|
|
2018-09-06 06:33:07 +08:00
|
|
|
void init_const_float(ConstExprValue *const_val, ZigType *type, double value);
|
|
|
|
ConstExprValue *create_const_float(ZigType *type, double value);
|
2016-12-25 17:15:23 +08:00
|
|
|
|
2018-09-06 06:33:07 +08:00
|
|
|
void init_const_enum(ConstExprValue *const_val, ZigType *type, const BigInt *tag);
|
|
|
|
ConstExprValue *create_const_enum(ZigType *type, const BigInt *tag);
|
2016-12-25 17:15:23 +08:00
|
|
|
|
|
|
|
void init_const_bool(CodeGen *g, ConstExprValue *const_val, bool value);
|
|
|
|
ConstExprValue *create_const_bool(CodeGen *g, bool value);
|
|
|
|
|
2018-09-06 06:33:07 +08:00
|
|
|
void init_const_type(CodeGen *g, ConstExprValue *const_val, ZigType *type_value);
|
|
|
|
ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value);
|
2016-12-25 17:15:23 +08:00
|
|
|
|
2018-09-06 06:33:07 +08:00
|
|
|
void init_const_runtime(ConstExprValue *const_val, ZigType *type);
|
|
|
|
ConstExprValue *create_const_runtime(ZigType *type);
|
2016-12-25 17:15:23 +08:00
|
|
|
|
2017-02-12 02:13:45 +08:00
|
|
|
void init_const_ptr_ref(CodeGen *g, ConstExprValue *const_val, ConstExprValue *pointee_val, bool is_const);
|
|
|
|
ConstExprValue *create_const_ptr_ref(CodeGen *g, ConstExprValue *pointee_val, bool is_const);
|
|
|
|
|
2018-09-06 06:33:07 +08:00
|
|
|
void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, ZigType *pointee_type,
|
2017-05-10 10:23:38 +08:00
|
|
|
size_t addr, bool is_const);
|
2018-09-06 06:33:07 +08:00
|
|
|
ConstExprValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type,
|
2017-05-10 10:23:38 +08:00
|
|
|
size_t addr, bool is_const);
|
|
|
|
|
2017-02-12 02:13:45 +08:00
|
|
|
void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,
|
2018-06-05 10:11:14 +08:00
|
|
|
size_t elem_index, bool is_const, PtrLen ptr_len);
|
|
|
|
ConstExprValue *create_const_ptr_array(CodeGen *g, ConstExprValue *array_val, size_t elem_index,
|
|
|
|
bool is_const, PtrLen ptr_len);
|
2016-12-25 17:15:23 +08:00
|
|
|
|
|
|
|
void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,
|
|
|
|
size_t start, size_t len, bool is_const);
|
|
|
|
ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t start, size_t len, bool is_const);
|
2016-12-12 05:30:01 +08:00
|
|
|
|
2017-01-24 05:40:17 +08:00
|
|
|
void init_const_arg_tuple(CodeGen *g, ConstExprValue *const_val, size_t arg_index_start, size_t arg_index_end);
|
|
|
|
ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end);
|
|
|
|
|
2017-02-03 03:55:01 +08:00
|
|
|
void init_const_undefined(CodeGen *g, ConstExprValue *const_val);
|
2017-01-30 12:35:34 +08:00
|
|
|
|
2017-05-27 11:31:38 +08:00
|
|
|
ConstExprValue *create_const_vals(size_t count);
|
|
|
|
|
2018-09-06 06:33:07 +08:00
|
|
|
ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
|
2017-04-24 01:22:36 +08:00
|
|
|
ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value);
|
|
|
|
void expand_undef_array(CodeGen *g, ConstExprValue *const_val);
|
2017-05-02 01:12:38 +08:00
|
|
|
void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value);
|
2017-02-16 07:55:29 +08:00
|
|
|
|
2018-09-06 06:33:07 +08:00
|
|
|
const char *type_id_name(ZigTypeId id);
|
|
|
|
ZigTypeId type_id_at_index(size_t index);
|
2017-05-18 00:26:35 +08:00
|
|
|
size_t type_id_len();
|
2018-09-06 06:33:07 +08:00
|
|
|
size_t type_id_index(ZigType *entry);
|
|
|
|
ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id);
|
|
|
|
Result<bool> type_is_copyable(CodeGen *g, ZigType *type_entry);
|
2017-06-14 12:04:34 +08:00
|
|
|
LinkLib *create_link_lib(Buf *name);
|
|
|
|
bool calling_convention_does_first_arg_return(CallingConvention cc);
|
|
|
|
LinkLib *add_link_lib(CodeGen *codegen, Buf *lib);
|
2017-05-18 00:26:35 +08:00
|
|
|
|
2018-09-06 06:33:07 +08:00
|
|
|
uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry);
|
|
|
|
ZigType *get_align_amt_type(CodeGen *g);
|
2017-12-09 01:28:21 +08:00
|
|
|
PackageTableEntry *new_anonymous_package(void);
|
2017-08-29 19:30:22 +08:00
|
|
|
|
2017-12-18 22:59:57 +08:00
|
|
|
Buf *const_value_to_buffer(ConstExprValue *const_val);
|
2018-09-06 06:34:33 +08:00
|
|
|
void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc);
|
2017-12-18 22:59:57 +08:00
|
|
|
|
2018-01-12 12:04:08 +08:00
|
|
|
|
|
|
|
ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name);
|
2018-09-06 06:33:07 +08:00
|
|
|
ZigType *get_ptr_to_stack_trace_type(CodeGen *g);
|
|
|
|
bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node);
|
2018-01-12 12:04:08 +08:00
|
|
|
|
2018-09-06 06:34:33 +08:00
|
|
|
ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry);
|
2018-01-12 12:04:08 +08:00
|
|
|
|
2018-02-26 04:10:29 +08:00
|
|
|
uint32_t get_coro_frame_align_bytes(CodeGen *g);
|
2018-02-28 17:01:22 +08:00
|
|
|
bool fn_type_can_fail(FnTypeId *fn_type_id);
|
2018-09-06 06:33:07 +08:00
|
|
|
bool type_can_fail(ZigType *type_entry);
|
|
|
|
bool fn_eval_cacheable(Scope *scope, ZigType *return_type);
|
|
|
|
AstNode *type_decl_node(ZigType *type_entry);
|
2018-02-26 04:10:29 +08:00
|
|
|
|
2018-09-06 06:33:07 +08:00
|
|
|
ZigType *get_primitive_type(CodeGen *g, Buf *name);
|
2018-07-16 22:53:15 +08:00
|
|
|
|
2018-09-06 09:21:59 +08:00
|
|
|
bool calling_convention_allows_zig_types(CallingConvention cc);
|
|
|
|
const char *calling_convention_name(CallingConvention cc);
|
|
|
|
|
2015-12-01 00:14:58 +08:00
|
|
|
#endif
|