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"
|
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);
|
2015-12-09 05:15:34 +08:00
|
|
|
TypeTableEntry *new_type_table_entry(TypeTableEntryId id);
|
2016-01-14 09:15:51 +08:00
|
|
|
TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const);
|
2017-02-17 02:58:42 +08:00
|
|
|
TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type, bool is_const,
|
|
|
|
uint8_t bit_offset, bool is_volatile);
|
2016-01-14 09:15:51 +08:00
|
|
|
bool is_node_void_expr(AstNode *node);
|
2016-05-08 09:45:28 +08:00
|
|
|
uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry);
|
2017-02-16 07:55:29 +08:00
|
|
|
TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, uint8_t size_in_bits);
|
|
|
|
TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint8_t size_in_bits);
|
2016-01-31 16:20:47 +08:00
|
|
|
TypeTableEntry **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);
|
|
|
|
TypeTableEntry *get_c_int_type(CodeGen *g, CIntType c_int_type);
|
|
|
|
TypeTableEntry *get_typedecl_type(CodeGen *g, const char *name, TypeTableEntry *child_type);
|
2016-12-02 12:25:09 +08:00
|
|
|
TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id);
|
2016-01-31 16:20:47 +08:00
|
|
|
TypeTableEntry *get_maybe_type(CodeGen *g, TypeTableEntry *child_type);
|
|
|
|
TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t array_size);
|
2016-04-09 23:55:53 +08:00
|
|
|
TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_const);
|
2017-02-04 00:39:24 +08:00
|
|
|
TypeTableEntry *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,
|
|
|
|
AstNode *decl_node, const char *name, ContainerLayout layout);
|
2016-01-31 16:20:47 +08:00
|
|
|
TypeTableEntry *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x);
|
2016-11-08 07:58:01 +08:00
|
|
|
TypeTableEntry *get_error_type(CodeGen *g, TypeTableEntry *child_type);
|
2016-11-28 15:40:01 +08:00
|
|
|
TypeTableEntry *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry);
|
2016-01-18 23:50:10 +08:00
|
|
|
bool handle_is_ptr(TypeTableEntry *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
|
|
|
|
2016-01-31 16:20:47 +08:00
|
|
|
TypeTableEntry *get_underlying_type(TypeTableEntry *type_entry);
|
2016-02-03 15:42:24 +08:00
|
|
|
bool type_has_bits(TypeTableEntry *type_entry);
|
2016-01-31 16:20:47 +08:00
|
|
|
|
2016-02-28 13:06:46 +08:00
|
|
|
|
|
|
|
ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package,
|
|
|
|
Buf *abs_full_path, Buf *src_dirname, Buf *src_basename, Buf *source_code);
|
|
|
|
|
2016-10-09 14:20:01 +08:00
|
|
|
|
2016-10-30 14:46:16 +08:00
|
|
|
// TODO move these over, these used to be static
|
2016-10-03 11:48:48 +08:00
|
|
|
bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *actual_type);
|
2016-12-02 02:55:56 +08:00
|
|
|
VariableTableEntry *find_variable(CodeGen *g, Scope *orig_context, Buf *name);
|
2016-12-02 12:25:09 +08:00
|
|
|
Tld *find_decl(Scope *scope, Buf *name);
|
|
|
|
void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only);
|
2016-10-09 14:20:01 +08:00
|
|
|
bool type_is_codegen_pointer(TypeTableEntry *type);
|
2016-10-30 07:14:48 +08:00
|
|
|
TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEntry *type_entry);
|
2016-10-30 14:46:16 +08:00
|
|
|
TypeTableEntry *container_ref_type(TypeTableEntry *type_entry);
|
|
|
|
bool type_is_complete(TypeTableEntry *type_entry);
|
2017-01-14 06:33:19 +08:00
|
|
|
bool type_is_invalid(TypeTableEntry *type_entry);
|
2016-12-28 14:15:09 +08:00
|
|
|
bool type_has_zero_bits_known(TypeTableEntry *type_entry);
|
2016-10-30 14:46:16 +08:00
|
|
|
void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry);
|
|
|
|
TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name);
|
2016-12-02 10:08:12 +08:00
|
|
|
ScopeDecls *get_container_scope(TypeTableEntry *type_entry);
|
2016-10-30 14:46:16 +08:00
|
|
|
TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name);
|
|
|
|
bool is_container_ref(TypeTableEntry *type_entry);
|
2016-12-19 05:56:50 +08:00
|
|
|
void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node);
|
2016-11-27 09:52:22 +08:00
|
|
|
void preview_use_decl(CodeGen *g, AstNode *node);
|
|
|
|
void resolve_use_decl(CodeGen *g, AstNode *node);
|
2016-12-02 12:25:09 +08:00
|
|
|
FnTableEntry *scope_fn_entry(Scope *scope);
|
|
|
|
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);
|
2016-12-02 12:25:09 +08:00
|
|
|
VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
|
2016-12-25 17:15:23 +08:00
|
|
|
bool is_const, ConstExprValue *init_value);
|
2016-12-05 14:08:17 +08:00
|
|
|
TypeTableEntry *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node);
|
2016-12-11 13:13:43 +08:00
|
|
|
FnTableEntry *create_fn(AstNode *proto_node);
|
|
|
|
FnTableEntry *create_fn_raw(FnInline inline_value, bool internal_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);
|
2016-12-05 18:12:05 +08:00
|
|
|
AstNode *get_param_decl_node(FnTableEntry *fn_entry, size_t index);
|
2016-12-18 09:47:35 +08:00
|
|
|
FnTableEntry *scope_get_fn_if_root(Scope *scope);
|
2016-12-18 13:09:43 +08:00
|
|
|
bool type_requires_comptime(TypeTableEntry *type_entry);
|
2016-12-19 09:09:34 +08:00
|
|
|
void ensure_complete_type(CodeGen *g, TypeTableEntry *type_entry);
|
2016-12-28 14:15:09 +08:00
|
|
|
void type_ensure_zero_bits_known(CodeGen *g, TypeTableEntry *type_entry);
|
2016-12-19 09:09:34 +08:00
|
|
|
void complete_enum(CodeGen *g, TypeTableEntry *enum_type);
|
2016-12-19 13:04:51 +08:00
|
|
|
bool ir_get_var_is_comptime(VariableTableEntry *var);
|
2016-12-25 17:15:23 +08:00
|
|
|
bool const_values_equal(ConstExprValue *a, ConstExprValue *b);
|
2016-12-20 14:50:32 +08:00
|
|
|
void eval_min_max_value(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val, bool is_max);
|
2017-02-14 14:08:30 +08:00
|
|
|
int64_t min_signed_val(TypeTableEntry *type_entry);
|
2016-10-03 11:48:48 +08:00
|
|
|
|
2017-01-05 16:22:00 +08:00
|
|
|
void render_const_value(Buf *buf, ConstExprValue *const_val);
|
2017-01-12 16:15:06 +08:00
|
|
|
void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entry, VariableTableEntry **arg_vars);
|
|
|
|
void analyze_fn_ir(CodeGen *g, FnTableEntry *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);
|
2016-12-02 10:08:12 +08:00
|
|
|
Scope *create_var_scope(AstNode *node, Scope *parent, VariableTableEntry *var);
|
2016-12-11 13:13:43 +08:00
|
|
|
ScopeCImport *create_cimport_scope(AstNode *node, Scope *parent);
|
2016-12-02 10:08:12 +08:00
|
|
|
Scope *create_loop_scope(AstNode *node, Scope *parent);
|
2016-12-02 12:25:09 +08:00
|
|
|
ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, FnTableEntry *fn_entry);
|
2016-12-11 13:13:43 +08:00
|
|
|
ScopeDecls *create_decls_scope(AstNode *node, Scope *parent, TypeTableEntry *container_type, ImportTableEntry *import);
|
2017-01-23 11:59:52 +08:00
|
|
|
Scope *create_comptime_scope(AstNode *node, Scope *parent);
|
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
|
|
|
|
2016-12-25 17:15:23 +08:00
|
|
|
void init_const_unsigned_negative(ConstExprValue *const_val, TypeTableEntry *type, uint64_t x, bool negative);
|
|
|
|
ConstExprValue *create_const_unsigned_negative(TypeTableEntry *type, uint64_t x, bool negative);
|
2016-12-11 13:13:43 +08:00
|
|
|
|
2016-12-25 17:15:23 +08:00
|
|
|
void init_const_signed(ConstExprValue *const_val, TypeTableEntry *type, int64_t x);
|
|
|
|
ConstExprValue *create_const_signed(TypeTableEntry *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
|
|
|
|
2016-12-25 17:15:23 +08:00
|
|
|
void init_const_float(ConstExprValue *const_val, TypeTableEntry *type, double value);
|
|
|
|
ConstExprValue *create_const_float(TypeTableEntry *type, double value);
|
|
|
|
|
|
|
|
void init_const_enum_tag(ConstExprValue *const_val, TypeTableEntry *type, uint64_t tag);
|
|
|
|
ConstExprValue *create_const_enum_tag(TypeTableEntry *type, uint64_t tag);
|
|
|
|
|
|
|
|
void init_const_bool(CodeGen *g, ConstExprValue *const_val, bool value);
|
|
|
|
ConstExprValue *create_const_bool(CodeGen *g, bool value);
|
|
|
|
|
|
|
|
void init_const_type(CodeGen *g, ConstExprValue *const_val, TypeTableEntry *type_value);
|
|
|
|
ConstExprValue *create_const_type(CodeGen *g, TypeTableEntry *type_value);
|
|
|
|
|
|
|
|
void init_const_runtime(ConstExprValue *const_val, TypeTableEntry *type);
|
|
|
|
ConstExprValue *create_const_runtime(TypeTableEntry *type);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,
|
|
|
|
size_t elem_index, bool is_const);
|
|
|
|
ConstExprValue *create_const_ptr_array(CodeGen *g, ConstExprValue *array_val, size_t elem_index, bool is_const);
|
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-02-16 07:55:29 +08:00
|
|
|
TypeTableEntry *make_int_type(CodeGen *g, bool is_signed, size_t size_in_bits);
|
|
|
|
|
2015-12-01 00:14:58 +08:00
|
|
|
#endif
|