mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
General reorganization, set any empty expression statement to nop. Version bump.
This commit is contained in:
@@ -2088,6 +2088,9 @@ INLINE bool exprid_is_constant_eval(ExprId expr, ConstantEvalKind eval_kind);
|
||||
INLINE bool expr_is_init_list(Expr *expr);
|
||||
INLINE bool expr_is_deref(Expr *expr);
|
||||
INLINE bool expr_is_const(Expr *expr);
|
||||
INLINE bool expr_is_const_string(Expr *expr);
|
||||
INLINE bool expr_is_const_initializer(Expr *expr);
|
||||
INLINE bool expr_is_const_untyped_list(Expr *expr);
|
||||
|
||||
INLINE void expr_rewrite_const_null(Expr *expr, Type *type);
|
||||
INLINE void expr_rewrite_const_bool(Expr *expr, Type *type, bool b);
|
||||
@@ -2096,6 +2099,7 @@ INLINE void expr_rewrite_const_int(Expr *expr, Type *type, uint64_t v, bool narr
|
||||
INLINE void expr_rewrite_const_initializer(Expr *expr, Type *type, ConstInitializer *initializer);
|
||||
|
||||
void expr_rewrite_to_builtin_access(Expr *expr, Expr *parent, BuiltinAccessKind kind, Type *type);
|
||||
void expr_rewrite_to_string(Expr *expr_to_rewrite, const char *string);
|
||||
void expr_rewrite_to_const_zero(Expr *expr, Type *type);
|
||||
bool expr_rewrite_to_const_initializer_index(Type *list_type, ConstInitializer *list, Expr *result, unsigned index);
|
||||
|
||||
@@ -3020,3 +3024,18 @@ static inline bool decl_is_local(Decl *decl)
|
||||
|| kind == VARDECL_BITMEMBER
|
||||
|| kind == VARDECL_MEMBER;
|
||||
}
|
||||
|
||||
INLINE bool expr_is_const_string(Expr *expr)
|
||||
{
|
||||
return expr->expr_kind == EXPR_CONST && expr->const_expr.const_kind == CONST_STRING;
|
||||
}
|
||||
|
||||
INLINE bool expr_is_const_initializer(Expr *expr)
|
||||
{
|
||||
return expr->expr_kind == EXPR_CONST && expr->const_expr.const_kind == CONST_INITIALIZER;
|
||||
}
|
||||
|
||||
INLINE bool expr_is_const_untyped_list(Expr *expr)
|
||||
{
|
||||
return expr->expr_kind == EXPR_CONST && expr->const_expr.const_kind == CONST_UNTYPED_LIST;
|
||||
}
|
||||
|
||||
@@ -887,3 +887,14 @@ void expr_rewrite_insert_deref(Expr *original)
|
||||
original->type = type_add_optional(pointee, IS_OPTIONAL(inner));
|
||||
}
|
||||
}
|
||||
|
||||
void expr_rewrite_to_string(Expr *expr_to_rewrite, const char *string)
|
||||
{
|
||||
expr_to_rewrite->expr_kind = EXPR_CONST;
|
||||
expr_to_rewrite->const_expr.const_kind = CONST_STRING;
|
||||
expr_to_rewrite->const_expr.string.chars = (char *)string;
|
||||
ArraySize len = (ArraySize)strlen(string);
|
||||
expr_to_rewrite->const_expr.string.len = len;
|
||||
expr_to_rewrite->resolve_status = RESOLVE_DONE;
|
||||
expr_to_rewrite->type = type_get_ptr(type_get_array(type_char, len));
|
||||
}
|
||||
|
||||
@@ -3977,9 +3977,10 @@ static void llvm_emit_const_expr(GenContext *c, BEValue *be_value, Expr *expr)
|
||||
case CONST_ENUM:
|
||||
llvm_value_set(be_value, llvm_const_int(c, type, expr->const_expr.enum_val->enum_constant.ordinal), type);
|
||||
return;
|
||||
default:
|
||||
case CONST_UNTYPED_LIST:
|
||||
UNREACHABLE
|
||||
}
|
||||
UNREACHABLE
|
||||
}
|
||||
|
||||
static void llvm_expand_type_to_args(GenContext *context, Type *param_type, LLVMValueRef expand_ptr, LLVMValueRef **values, AlignSize alignment);
|
||||
|
||||
@@ -481,7 +481,7 @@ static inline bool sema_check_asm_arg(SemaContext *context, AsmInlineBlock *bloc
|
||||
}
|
||||
UNREACHABLE
|
||||
}
|
||||
bool sema_check_asm(SemaContext *context, AsmInlineBlock *block, Ast *asm_stmt)
|
||||
bool sema_analyse_asm(SemaContext *context, AsmInlineBlock *block, Ast *asm_stmt)
|
||||
{
|
||||
if (platform_target.arch != ARCH_TYPE_X86_64 && platform_target.arch != ARCH_TYPE_AARCH64)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
static bool bitstruct_cast(Expr *expr, Type *from_type, Type *to, Type *to_type);
|
||||
static void sema_error_const_int_out_of_range(Expr *expr, Expr *problem, Type *to_type);
|
||||
static Expr *recursive_may_narrow_float(Expr *expr, Type *type);
|
||||
Expr *recursive_may_narrow_int(Expr *expr, Type *type);
|
||||
static Expr *recursive_may_narrow_int(Expr *expr, Type *type);
|
||||
static void recursively_rewrite_untyped_list(Expr *expr, Expr **list);
|
||||
|
||||
static inline bool insert_cast(Expr *expr, CastKind kind, Type *type)
|
||||
|
||||
@@ -2600,7 +2600,7 @@ bool sema_analyse_decl(SemaContext *context, Decl *decl)
|
||||
if (decl->resolve_status == RESOLVE_DONE) return decl_ok(decl);
|
||||
|
||||
SemaContext temp_context;
|
||||
context = transform_context_for_eval(context, &temp_context, decl->unit);
|
||||
context = context_transform_for_eval(context, &temp_context, decl->unit);
|
||||
DEBUG_LOG(">>> Analysing %s.", decl->name ? decl->name : ".anon");
|
||||
if (decl->resolve_status == RESOLVE_RUNNING)
|
||||
{
|
||||
|
||||
@@ -133,7 +133,6 @@ static bool sema_call_analyse_body_expansion(SemaContext *macro_context, Expr *c
|
||||
static bool sema_slice_len_is_in_range(SemaContext *context, Type *type, Expr *len_expr, bool from_end, bool *remove_from_end);
|
||||
static bool sema_slice_index_is_in_range(SemaContext *context, Type *type, Expr *index_expr, bool end_index, bool from_end, bool *remove_from_end);
|
||||
|
||||
|
||||
static Expr **sema_vasplat_append(SemaContext *c, Expr **init_expressions, Expr *expr);
|
||||
INLINE Expr **sema_expand_vasplat(SemaContext *c, Expr **list, unsigned index);
|
||||
static inline IndexDiff range_const_len(Range *range);
|
||||
@@ -144,6 +143,7 @@ static bool sema_expr_analyse_type_var_path(SemaContext *context, Expr *expr, Ex
|
||||
Decl **decl_ref);
|
||||
static inline bool sema_expr_analyse_flat_element(SemaContext *context, ExprFlatElement *element, Type *type, Decl **member_ref, ArraySize *index_ref, Type **return_type, unsigned i, SourceSpan loc,
|
||||
bool *is_missing);
|
||||
static Expr *sema_expr_resolve_access_child(SemaContext *context, Expr *child, bool *missing);
|
||||
|
||||
static Type *sema_expr_check_type_exists(SemaContext *context, TypeInfo *type_info);
|
||||
static inline Expr *sema_ct_checks_exprlist_compiles(SemaContext *context, Expr *exprlist);
|
||||
@@ -151,6 +151,16 @@ static inline BuiltinFunction builtin_by_name(const char *name);
|
||||
static inline bool sema_cast_ct_ident_rvalue(SemaContext *context, Expr *expr);
|
||||
static bool sema_expr_rewrite_to_typeid_property(SemaContext *context, Expr *expr, Expr *typeid, const char *kw);
|
||||
static bool sema_expr_rewrite_to_type_property(SemaContext *context, Expr *expr, Type *type, const char *kw);
|
||||
static bool sema_expr_rewrite_typeid_call(Expr *expr, Expr *typeid, TypeIdInfoKind kind, Type *result_type);
|
||||
static inline void sema_expr_rewrite_typeid_kind(Expr *expr, Expr *parent);
|
||||
static inline void sema_expr_replace_with_enum_array(Expr *enum_array_expr, Decl *enum_decl);
|
||||
static inline void sema_expr_replace_with_enum_name_array(Expr *enum_array_expr, Decl *enum_decl);
|
||||
|
||||
static inline bool sema_create_const_kind(Expr *expr, Type *type);
|
||||
static inline bool sema_create_const_len(SemaContext *context, Expr *expr, Type *type);
|
||||
static inline bool sema_create_const_inner(SemaContext *context, Expr *expr, Type *type);
|
||||
static inline bool sema_create_const_min(SemaContext *context, Expr *expr, Type *type, Type *flat);
|
||||
static inline bool sema_create_const_max(SemaContext *context, Expr *expr, Type *type, Type *flat);
|
||||
|
||||
void expr_insert_widening_type(Expr *expr, Type *infer_type);
|
||||
static Expr *expr_access_inline_member(Expr *parent, Decl *parent_decl);
|
||||
@@ -162,6 +172,8 @@ static inline bool sema_expr_analyse_enum_constant(Expr *expr, const char *name,
|
||||
static inline bool sema_cast_ident_rvalue(SemaContext *context, Expr *expr);
|
||||
static inline bool sema_cast_rvalue(SemaContext *context, Expr *expr);
|
||||
|
||||
static inline bool sema_expr_analyse_type_access(SemaContext *context, Expr *expr, TypeInfo *parent, bool was_group, Expr *identifier);
|
||||
static inline bool sema_expr_fold_to_member(Expr *expr, Expr *parent, Decl *member);
|
||||
|
||||
// -- implementations
|
||||
|
||||
@@ -1052,7 +1064,7 @@ INLINE bool sema_call_expand_arguments(SemaContext *context, CalledDecl *callee,
|
||||
|
||||
SemaContext default_context;
|
||||
Type *rtype = NULL;
|
||||
SemaContext *new_context = transform_context_for_eval(context, &default_context, param->unit);
|
||||
SemaContext *new_context = context_transform_for_eval(context, &default_context, param->unit);
|
||||
bool success;
|
||||
SCOPE_START
|
||||
new_context->original_inline_line = context->original_inline_line ? context->original_inline_line : init_expr->span.row;
|
||||
@@ -2464,21 +2476,6 @@ static inline bool sema_expr_analyse_group(SemaContext *context, Expr *expr)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void expr_rewrite_to_string(Expr *expr_to_rewrite, const char *string)
|
||||
{
|
||||
expr_to_rewrite->expr_kind = EXPR_CONST;
|
||||
expr_to_rewrite->const_expr.const_kind = CONST_STRING;
|
||||
expr_to_rewrite->const_expr.string.chars = (char *)string;
|
||||
ArraySize len = (ArraySize)strlen(string);
|
||||
expr_to_rewrite->const_expr.string.len = len;
|
||||
expr_to_rewrite->resolve_status = RESOLVE_DONE;
|
||||
expr_to_rewrite->type = type_get_ptr(type_get_array(type_char, len));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 1. .A -> It is an enum constant.
|
||||
* 2. .foo -> It is a function.
|
||||
@@ -2538,7 +2535,7 @@ RETRY:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline void expr_replace_with_enum_array(Expr *enum_array_expr, Decl *enum_decl)
|
||||
static inline void sema_expr_replace_with_enum_array(Expr *enum_array_expr, Decl *enum_decl)
|
||||
{
|
||||
Decl **values = enum_decl->enums.values;
|
||||
SourceSpan span = enum_array_expr->span;
|
||||
@@ -2564,7 +2561,7 @@ static inline void expr_replace_with_enum_array(Expr *enum_array_expr, Decl *enu
|
||||
enum_array_expr->resolve_status = RESOLVE_NOT_DONE;
|
||||
}
|
||||
|
||||
static inline void expr_replace_with_enum_name_array(Expr *enum_array_expr, Decl *enum_decl)
|
||||
static inline void sema_expr_replace_with_enum_name_array(Expr *enum_array_expr, Decl *enum_decl)
|
||||
{
|
||||
Decl **values = enum_decl->enums.values;
|
||||
SourceSpan span = enum_array_expr->span;
|
||||
@@ -2631,12 +2628,12 @@ static inline bool sema_expr_analyse_type_access(SemaContext *context, Expr *exp
|
||||
}
|
||||
if (name == kw_names)
|
||||
{
|
||||
expr_replace_with_enum_name_array(expr, decl);
|
||||
sema_expr_replace_with_enum_name_array(expr, decl);
|
||||
return sema_analyse_expr(context, expr);
|
||||
}
|
||||
if (name == kw_values)
|
||||
{
|
||||
expr_replace_with_enum_array(expr, decl);
|
||||
sema_expr_replace_with_enum_array(expr, decl);
|
||||
return sema_analyse_expr(context, expr);
|
||||
}
|
||||
break;
|
||||
@@ -2699,7 +2696,7 @@ static inline bool sema_expr_analyse_type_access(SemaContext *context, Expr *exp
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void sema_rewrite_typeid_kind(Expr *expr, Expr *parent)
|
||||
static inline void sema_expr_rewrite_typeid_kind(Expr *expr, Expr *parent)
|
||||
{
|
||||
Module *module = global_context_find_module(kw_std__core__types);
|
||||
Decl *type_kind = module ? module_find_symbol(module, kw_typekind) : NULL;
|
||||
@@ -2941,7 +2938,7 @@ static bool sema_expr_rewrite_to_typeid_property(SemaContext *context, Expr *exp
|
||||
}
|
||||
if (kw == kw_kind)
|
||||
{
|
||||
sema_rewrite_typeid_kind(expr, typeid);
|
||||
sema_expr_rewrite_typeid_kind(expr, typeid);
|
||||
return true;
|
||||
}
|
||||
if (kw == kw_inner) return sema_expr_rewrite_typeid_call(expr, typeid, TYPEID_INFO_INNER, type_typeid);
|
||||
|
||||
@@ -7,41 +7,14 @@
|
||||
|
||||
#include "compiler_internal.h"
|
||||
|
||||
int sema_check_comp_time_bool(SemaContext *context, Expr *expr);
|
||||
bool sema_analyse_function_body(SemaContext *context, Decl *func);
|
||||
#define SCOPE_OUTER_START \
|
||||
do { \
|
||||
DynamicScope stored_scope = context->active_scope; \
|
||||
context_change_scope_with_flags(context, SCOPE_NONE);
|
||||
#define SCOPE_OUTER_END \
|
||||
assert(context->active_scope.defer_last == context->active_scope.defer_start); \
|
||||
context->active_scope = stored_scope; \
|
||||
} while(0)
|
||||
#define SCOPE_OUTER_START do { DynamicScope stored_scope = context->active_scope; context_change_scope_with_flags(context, SCOPE_NONE);
|
||||
#define SCOPE_OUTER_END assert(context->active_scope.defer_last == context->active_scope.defer_start); context->active_scope = stored_scope; } while(0)
|
||||
#define SCOPE_START SCOPE_START_WITH_FLAGS(SCOPE_NONE)
|
||||
#define SCOPE_START_WITH_FLAGS(flags) \
|
||||
do { \
|
||||
DynamicScope old_scope = context->active_scope; \
|
||||
context_change_scope_with_flags(context, flags);
|
||||
#define SCOPE_START_WITH_LABEL(label) \
|
||||
do { \
|
||||
DynamicScope old_scope = context->active_scope; \
|
||||
context_change_scope_for_label(context, label);
|
||||
#define SCOPE_END \
|
||||
assert(context->active_scope.defer_last == context->active_scope.defer_start); \
|
||||
context->active_scope = old_scope; \
|
||||
} while(0)
|
||||
#define SCOPE_START_WITH_FLAGS(flags) do { DynamicScope old_scope = context->active_scope; context_change_scope_with_flags(context, flags);
|
||||
#define SCOPE_START_WITH_LABEL(label) do { DynamicScope old_scope = context->active_scope; context_change_scope_for_label(context, label);
|
||||
#define SCOPE_END assert(context->active_scope.defer_last == context->active_scope.defer_start); context->active_scope = old_scope; } while(0)
|
||||
#define SCOPE_POP_ERROR() ((bool)(context->active_scope = old_scope, false))
|
||||
#define SCOPE_ERROR_END_OUTER() \
|
||||
do { context->active_scope = stored_scope; } while(0)
|
||||
|
||||
AstId context_get_defers(SemaContext *context, AstId defer_top, AstId defer_bottom);
|
||||
void context_pop_defers(SemaContext *context, AstId *next);
|
||||
|
||||
void context_pop_defers_and_replace_ast(SemaContext *context, Ast *ast);
|
||||
void context_change_scope_for_label(SemaContext *context, Decl *label);
|
||||
void context_change_scope_with_flags(SemaContext *context, ScopeFlags flags);
|
||||
bool splitpathref(const char *string, ArraySize len, Path **path_ref, const char **ident_ref, TokenType *type_ref);
|
||||
|
||||
#define SCOPE_ERROR_END_OUTER() do { context->active_scope = stored_scope; } while(0)
|
||||
#define PUSH_X(ast, X) AstId _old_##X##_defer = context->X##_defer; Ast *_old_##X = context->X##_target; context->X##_target = ast; context->X##_defer = context->active_scope.defer_last
|
||||
#define POP_X(X) context->X##_target = _old_##X; context->X##_defer = _old_##X##_defer
|
||||
#define PUSH_CONTINUE(ast) PUSH_X(ast, continue)
|
||||
@@ -52,16 +25,28 @@ bool splitpathref(const char *string, ArraySize len, Path **path_ref, const char
|
||||
#define POP_NEXT() POP_X(next); context->next_switch = _old_next_switch
|
||||
#define PUSH_BREAKCONT(ast) PUSH_CONTINUE(ast); PUSH_BREAK(ast)
|
||||
#define POP_BREAKCONT() POP_CONTINUE(); POP_BREAK()
|
||||
|
||||
#define IS_CONST(_x) ((_x)->expr_kind == EXPR_CONST)
|
||||
|
||||
bool sema_expr_check_assign(SemaContext *c, Expr *expr);
|
||||
bool sema_analyse_contracts(SemaContext *context, AstId doc, AstId **asserts);
|
||||
void sema_append_contract_asserts(AstId assert_first, Ast* compound_stmt);
|
||||
void sema_context_init(SemaContext *context, CompilationUnit *unit);
|
||||
void sema_context_destroy(SemaContext *context);
|
||||
extern const char *ct_eval_error;
|
||||
|
||||
Decl **global_context_acquire_locals_list(void);
|
||||
void generic_context_release_locals_list(Decl **);
|
||||
|
||||
AstId context_get_defers(SemaContext *context, AstId defer_top, AstId defer_bottom);
|
||||
void context_pop_defers(SemaContext *context, AstId *next);
|
||||
void context_pop_defers_and_replace_ast(SemaContext *context, Ast *ast);
|
||||
void context_change_scope_for_label(SemaContext *context, Decl *label);
|
||||
void context_change_scope_with_flags(SemaContext *context, ScopeFlags flags);
|
||||
SemaContext *context_transform_for_eval(SemaContext *context, SemaContext *temp_context, CompilationUnit *eval_unit);
|
||||
bool splitpathref(const char *string, ArraySize len, Path **path_ref, const char **ident_ref, TokenType *type_ref);
|
||||
|
||||
void sema_context_init(SemaContext *context, CompilationUnit *unit);
|
||||
void sema_context_destroy(SemaContext *context);
|
||||
|
||||
bool sema_analyse_function_body(SemaContext *context, Decl *func);
|
||||
bool sema_analyse_contracts(SemaContext *context, AstId doc, AstId **asserts);
|
||||
void sema_append_contract_asserts(AstId assert_first, Ast* compound_stmt);
|
||||
|
||||
void sema_analyse_pass_top(Module *module);
|
||||
void sema_analyse_pass_module_hierarchy(Module *module);
|
||||
void sema_analysis_pass_process_imports(Module *module);
|
||||
@@ -71,51 +56,23 @@ void sema_analysis_pass_decls(Module *module);
|
||||
void sema_analysis_pass_ct_assert(Module *module);
|
||||
void sema_analysis_pass_functions(Module *module);
|
||||
void sema_analyze_stage(Module *module, AnalysisStage stage);
|
||||
Decl *sema_find_operator(SemaContext *context, Expr *expr, OperatorOverload operator_overload);
|
||||
bool sema_insert_method_call(SemaContext *context, Expr *method_call, Decl *method_decl, Expr *parent, Expr **arguments);
|
||||
|
||||
bool sema_analyse_expr_lvalue(SemaContext *context, Expr *expr);
|
||||
bool sema_analyse_expr_lvalue_fold_const(SemaContext *context, Expr *expr);
|
||||
bool sema_analyse_ct_expr(SemaContext *context, Expr *expr);
|
||||
Decl *sema_find_operator(SemaContext *context, Expr *expr, OperatorOverload operator_overload);
|
||||
bool sema_insert_method_call(SemaContext *context, Expr *method_call, Decl *method_decl, Expr *parent, Expr **arguments);
|
||||
bool sema_expr_analyse_builtin_call(SemaContext *context, Expr *expr);
|
||||
bool sema_expr_analyse_macro_call(SemaContext *context, Expr *call_expr, Expr *struct_var, Decl *decl, bool failable);
|
||||
Expr *sema_expr_analyse_ct_arg_index(SemaContext *context, Expr *index_expr);
|
||||
void expr_rewrite_to_string(Expr *expr_to_rewrite, const char *string);
|
||||
const char *sema_ct_eval_expr(SemaContext *c, const char *expr_type, Expr *inner, TokenType *type, Path **path_ref, bool report_missing);
|
||||
extern const char *ct_eval_error;
|
||||
SemaContext *transform_context_for_eval(SemaContext *context, SemaContext *temp_context, CompilationUnit *eval_unit);
|
||||
bool sema_check_asm(SemaContext *context, AsmInlineBlock *block, Ast *asm_stmt);
|
||||
bool sema_analyse_asm(SemaContext *context, AsmInlineBlock *block, Ast *asm_stmt);
|
||||
bool sema_bit_assignment_check(Expr *right, Decl *member);
|
||||
static Expr *sema_expr_resolve_access_child(SemaContext *context, Expr *child, bool *missing);
|
||||
static inline void expr_replace_with_enum_array(Expr *enum_array_expr, Decl *enum_decl);
|
||||
static inline void expr_replace_with_enum_name_array(Expr *enum_array_expr, Decl *enum_decl);
|
||||
static inline bool sema_expr_analyse_type_access(SemaContext *context, Expr *expr, TypeInfo *parent, bool was_group, Expr *identifier);
|
||||
static inline void sema_rewrite_typeid_kind(Expr *expr, Expr *parent);
|
||||
static inline bool sema_create_const_kind(Expr *expr, Type *type);
|
||||
static inline bool sema_create_const_len(SemaContext *context, Expr *expr, Type *type);
|
||||
static inline bool sema_create_const_inner(SemaContext *context, Expr *expr, Type *type);
|
||||
static inline bool sema_create_const_min(SemaContext *context, Expr *expr, Type *type, Type *flat);
|
||||
static inline bool sema_create_const_max(SemaContext *context, Expr *expr, Type *type, Type *flat);
|
||||
static bool sema_expr_rewrite_typeid_call(Expr *expr, Expr *typeid, TypeIdInfoKind kind, Type *result_type);
|
||||
static inline bool sema_expr_fold_to_member(Expr *expr, Expr *parent, Decl *member);
|
||||
int sema_check_comp_time_bool(SemaContext *context, Expr *expr);
|
||||
bool sema_expr_check_assign(SemaContext *c, Expr *expr);
|
||||
|
||||
bool cast_widen_top_down(SemaContext *context, Expr *expr, Type *type);
|
||||
bool cast_promote_vararg(Expr *arg);
|
||||
Type *cast_numeric_arithmetic_promotion(Type *type);
|
||||
void cast_to_max_bit_size(SemaContext *context, Expr *left, Expr *right, Type *left_type, Type *right_type);
|
||||
|
||||
bool cast_decay_array_pointers(SemaContext *context, Expr *expr);
|
||||
|
||||
static inline bool expr_is_const_string(Expr *expr)
|
||||
{
|
||||
return expr->expr_kind == EXPR_CONST && expr->const_expr.const_kind == CONST_STRING;
|
||||
}
|
||||
|
||||
INLINE bool expr_is_const_initializer(Expr *expr)
|
||||
{
|
||||
return expr->expr_kind == EXPR_CONST && expr->const_expr.const_kind == CONST_INITIALIZER;
|
||||
}
|
||||
|
||||
INLINE bool expr_is_const_untyped_list(Expr *expr)
|
||||
{
|
||||
return expr->expr_kind == EXPR_CONST && expr->const_expr.const_kind == CONST_UNTYPED_LIST;
|
||||
}
|
||||
bool cast_decay_array_pointers(SemaContext *context, Expr *expr);
|
||||
@@ -61,7 +61,7 @@ static inline bool sema_analyse_asm_stmt(SemaContext *context, Ast *stmt)
|
||||
{
|
||||
Ast *ast = astptr(ast_id);
|
||||
ast_id = ast->next;
|
||||
if (!sema_check_asm(context, block, ast)) return false;
|
||||
if (!sema_analyse_asm(context, block, ast)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -938,7 +938,13 @@ static inline bool sema_analyse_expr_stmt(SemaContext *context, Ast *statement)
|
||||
{
|
||||
expr->call_expr.result_unused = true;
|
||||
}
|
||||
return sema_analyse_expr(context, expr);
|
||||
if (!sema_analyse_expr(context, expr)) return false;
|
||||
// Remove all const statements.
|
||||
if (expr_is_const(expr))
|
||||
{
|
||||
statement->ast_kind = AST_NOP_STMT;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sema_analyse_defer_stmt_body(SemaContext *context, Ast *statement, Ast *body)
|
||||
|
||||
@@ -352,7 +352,7 @@ void generic_context_release_locals_list(Decl **list)
|
||||
vec_add(global_context.locals_list, list);
|
||||
}
|
||||
|
||||
SemaContext *transform_context_for_eval(SemaContext *context, SemaContext *temp_context, CompilationUnit *eval_unit)
|
||||
SemaContext *context_transform_for_eval(SemaContext *context, SemaContext *temp_context, CompilationUnit *eval_unit)
|
||||
{
|
||||
if (eval_unit == context->unit)
|
||||
{
|
||||
|
||||
@@ -169,7 +169,6 @@ void symtab_init(uint32_t capacity)
|
||||
kw_type = KW_DEF("type");
|
||||
kw_values = KW_DEF("values");
|
||||
|
||||
|
||||
builtin_list[BUILTIN_ABS] = KW_DEF("abs");
|
||||
builtin_list[BUILTIN_BITREVERSE] = KW_DEF("bitreverse");
|
||||
builtin_list[BUILTIN_BSWAP] = KW_DEF("bswap");
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define COMPILER_VERSION "0.3.57"
|
||||
#define COMPILER_VERSION "0.3.58"
|
||||
15
test/test_suite/statements/const_statements.c3t
Normal file
15
test/test_suite/statements/const_statements.c3t
Normal file
@@ -0,0 +1,15 @@
|
||||
// #target: macos-x64
|
||||
|
||||
module test;
|
||||
fn void main()
|
||||
{
|
||||
var $x = { { 1, 2 } };
|
||||
$x;
|
||||
}
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
define void @test_main() #0 {
|
||||
entry:
|
||||
ret void
|
||||
}
|
||||
15
test/test_suite2/statements/const_statements.c3t
Normal file
15
test/test_suite2/statements/const_statements.c3t
Normal file
@@ -0,0 +1,15 @@
|
||||
// #target: macos-x64
|
||||
|
||||
module test;
|
||||
fn void main()
|
||||
{
|
||||
var $x = { { 1, 2 } };
|
||||
$x;
|
||||
}
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
define void @test_main() #0 {
|
||||
entry:
|
||||
ret void
|
||||
}
|
||||
Reference in New Issue
Block a user