mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
lvalue refactoring.
This commit is contained in:
committed by
Christoffer Lerno
parent
5e4d790fc3
commit
e795745e43
@@ -1016,13 +1016,6 @@ typedef enum
|
||||
STORAGE_UNKNOWN
|
||||
} StorageType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SUBSCRIPT_EVAL_VALUE,
|
||||
SUBSCRIPT_EVAL_REF,
|
||||
SUBSCRIPT_EVAL_ASSIGN,
|
||||
SUBSCRIPT_EVAL_VALID,
|
||||
} SubscriptEval;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
||||
@@ -3646,7 +3646,7 @@ bool sema_analyse_var_decl_ct(SemaContext *context, Decl *decl)
|
||||
if ((init = decl->var.init_expr))
|
||||
{
|
||||
// Try to fold any constant into an lvalue.
|
||||
if (!sema_analyse_expr_lvalue_fold_const(context, init)) goto FAIL;
|
||||
if (!sema_analyse_expr_value(context, init)) goto FAIL;
|
||||
|
||||
// If this isn't a type, it's an error.
|
||||
if (init->expr_kind != EXPR_TYPEINFO)
|
||||
@@ -4266,7 +4266,7 @@ static inline bool sema_analyse_define(SemaContext *context, Decl *decl, bool *e
|
||||
if (*erase_decl) return true;
|
||||
|
||||
Expr *expr = decl->define_decl.alias_expr;
|
||||
if (!sema_analyse_expr_lvalue_fold_const(context, expr)) return false;
|
||||
if (!sema_analyse_expr_value(context, expr)) return false;
|
||||
if (expr->expr_kind == EXPR_TYPEINFO)
|
||||
{
|
||||
RETURN_SEMA_ERROR(decl, "To alias a type, the alias name must start with uppercase and contain at least one lowercase letter.");
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,7 +19,13 @@
|
||||
|
||||
#define SEMA_ERROR(_node, ...) sema_error_at(context, (_node)->span, __VA_ARGS__)
|
||||
#define RETURN_SEMA_ERROR(_node, ...) do { sema_error_at(context, (_node)->span, __VA_ARGS__); return false; } while (0)
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define ASSERT_SPANF(node__, check__, format__, ...) do { } while(0)
|
||||
#define ASSERT_SPAN(node__, check__) do { } while(0)
|
||||
#else
|
||||
#define ASSERT_SPANF(node__, check__, format__, ...) do { if (!(check__)) { assert_print_line((node__)->span); eprintf(format__, __VA_ARGS__); assert(check__); } } while(0)
|
||||
#define ASSERT_SPAN(node__, check__) do { if (!(check__)) { assert_print_line((node__)->span); assert(check__); } } while(0)
|
||||
#endif
|
||||
#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)
|
||||
@@ -81,8 +87,10 @@ void sema_analyze_stage(Module *module, AnalysisStage stage);
|
||||
void sema_trace_liveness(void);
|
||||
|
||||
Expr *sema_expr_resolve_access_child(SemaContext *context, Expr *child, bool *missing);
|
||||
bool sema_analyse_expr_address(SemaContext *context, Expr *expr);
|
||||
bool sema_analyse_expr_lvalue(SemaContext *context, Expr *expr);
|
||||
bool sema_analyse_expr_lvalue_fold_const(SemaContext *context, Expr *expr);
|
||||
|
||||
bool sema_analyse_expr_value(SemaContext *context, Expr *expr);
|
||||
Expr *expr_access_inline_member(Expr *parent, Decl *parent_decl);
|
||||
bool sema_analyse_ct_expr(SemaContext *context, Expr *expr);
|
||||
Decl *sema_find_operator(SemaContext *context, Type *type, OperatorOverload operator_overload);
|
||||
@@ -113,6 +121,18 @@ INLINE bool sema_set_alloca_alignment(SemaContext *context, Type *type, AlignSiz
|
||||
INLINE void sema_display_deprecated_warning_on_use(SemaContext *context, Decl *decl, SourceSpan use);
|
||||
bool sema_expr_analyse_ct_concat(SemaContext *context, Expr *concat_expr, Expr *left, Expr *right);
|
||||
|
||||
INLINE void assert_print_line(SourceSpan span)
|
||||
{
|
||||
if (span.row == 0)
|
||||
{
|
||||
eprintf("Assert analysing code at unknown location:\n");
|
||||
return;
|
||||
}
|
||||
File *file = source_file_by_id(span.file_id);
|
||||
eprintf("Assert analysing '%s' at row %d, col %d.\n", file->name, span.row, span.col);
|
||||
}
|
||||
|
||||
|
||||
INLINE bool sema_set_abi_alignment(SemaContext *context, Type *type, AlignSize *result)
|
||||
{
|
||||
if (type_is_func_ptr(type))
|
||||
|
||||
@@ -303,7 +303,7 @@ INLINE bool sema_resolve_evaltype(SemaContext *context, TypeInfo *type_info, Res
|
||||
INLINE bool sema_resolve_typeof(SemaContext *context, TypeInfo *type_info)
|
||||
{
|
||||
Expr *expr = type_info->unresolved_type_expr;
|
||||
if (!sema_analyse_expr_lvalue_fold_const(context, expr)) return false;
|
||||
if (!sema_analyse_expr_value(context, expr)) return false;
|
||||
Type *expr_type = expr->type;
|
||||
if (expr_type->type_kind == TYPE_FUNC_RAW) expr_type = type_get_func_ptr(expr_type);
|
||||
switch (type_storage_type(expr_type))
|
||||
@@ -342,7 +342,7 @@ INLINE bool sema_resolve_vatype(SemaContext *context, TypeInfo *type_info)
|
||||
}
|
||||
ASSIGN_EXPR_OR_RET(Expr *arg_expr, sema_expr_analyse_ct_arg_index(context, type_info->unresolved_type_expr, NULL,
|
||||
true), false);
|
||||
if (!sema_analyse_expr_lvalue(context, arg_expr)) return false;
|
||||
if (!sema_analyse_expr_value(context, arg_expr)) return false;
|
||||
if (arg_expr->expr_kind != EXPR_TYPEINFO) RETURN_SEMA_ERROR(arg_expr, "The argument was not a type.");
|
||||
type_info->type = arg_expr->type_expr->type;
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user