Merge pull request #22 from c3lang/develop

Missing commits
This commit is contained in:
Christoffer Lerno
2020-04-09 13:50:47 +02:00
committed by GitHub
4 changed files with 27 additions and 29 deletions

View File

@@ -110,6 +110,10 @@ Decl *decl_new_var(Token name, TypeInfo *type, VarDeclKind kind, Visibility visi
return decl;
}
/**
* Recursively find a node in a declaration.
* @return NULL if it wasn't found, otherwise the member.
*/
Decl *struct_find_name(Decl *decl, const char* name)
{
Decl** compare_members = decl->strukt.members;

View File

@@ -521,17 +521,6 @@ typedef struct
Expr** initializer_expr;
} ExprInitializer;
typedef struct _DesignatedInitPath
{
Decl *decl;
struct _DesignatedInitPath *sub_path;
} DesignatedInitPath;
typedef struct
{
DesignatedInitPath path;
Expr *value;
} ExprDesignatedInit;
struct _Expr
{
@@ -540,7 +529,7 @@ struct _Expr
SourceRange span;
Type *type;
union {
ExprDesignatedInit designated_init_expr;
Expr *group_expr;
ExprCast cast_expr;
ExprConst const_expr;
ExprStructValue struct_value_expr;

View File

@@ -180,7 +180,6 @@ LLVMValueRef gencontext_emit_address(GenContext *context, Expr *expr)
case EXPR_EXPRESSION_LIST:
case EXPR_CAST:
case EXPR_MACRO_EXPR:
case EXPR_DESIGNATED_INIT:
UNREACHABLE
}
UNREACHABLE
@@ -968,9 +967,6 @@ LLVMValueRef gencontext_emit_expr(GenContext *context, Expr *expr)
{
case EXPR_POISONED:
UNREACHABLE
case EXPR_DESIGNATED_INIT:
// This is handled inside of initializer setup
UNREACHABLE
case EXPR_EXPR_BLOCK:
return gencontext_emit_expr_block(context, expr);
case EXPR_SCOPED_EXPR:

View File

@@ -281,11 +281,10 @@ static inline bool sema_expr_analyse_call(Context *context, Type *to, Expr *expr
}
}
static inline bool sema_expr_analyse_subscript(Context *context, Type *to, Expr *expr)
static inline bool sema_expr_analyse_subscript_after_parent_resolution(Context *context, Expr *expr)
{
if (!sema_analyse_expr(context, NULL, expr->subscript_expr.expr)) return false;
assert(expr->expr_kind == EXPR_SUBSCRIPT);
assert(expr->subscript_expr.expr->resolve_status == RESOLVE_DONE);
Type *type = expr->subscript_expr.expr->type->canonical;
Type *inner_type;
switch (type->type_kind)
@@ -307,7 +306,6 @@ static inline bool sema_expr_analyse_subscript(Context *context, Type *to, Expr
return false;
}
if (!sema_analyse_expr(context, type_isize, expr->subscript_expr.index)) return false;
// Unless we already have type_usize, cast to type_isize;
@@ -319,6 +317,13 @@ static inline bool sema_expr_analyse_subscript(Context *context, Type *to, Expr
return true;
}
static inline bool sema_expr_analyse_subscript(Context *context, Type *to, Expr *expr)
{
if (!sema_analyse_expr(context, NULL, expr->subscript_expr.expr)) return false;
return sema_expr_analyse_subscript_after_parent_resolution(context, expr);
}
static inline bool sema_expr_analyse_method_function(Context *context, Expr *expr, Decl *decl, bool is_pointer)
{
const char *name = expr->access_expr.sub_element.string;
@@ -362,11 +367,12 @@ static inline bool sema_expr_analyse_group(Context *context, Type *to, Expr *exp
}
static inline bool sema_expr_analyse_access(Context *context, Type *to, Expr *expr)
static inline bool sema_expr_analyse_access_after_parent_resolution(Context *context, Expr *expr)
{
if (!sema_analyse_expr(context, NULL, expr->access_expr.parent)) return false;
Type *parent_type = expr->access_expr.parent->type;
assert(expr->expr_kind == EXPR_ACCESS);
assert(expr->access_expr.parent->resolve_status == RESOLVE_DONE);
Type *parent_type = expr->access_expr.parent->type;
Type *type = parent_type->canonical;
bool is_pointer = type->type_kind == TYPE_POINTER;
if (is_pointer)
@@ -410,6 +416,13 @@ static inline bool sema_expr_analyse_access(Context *context, Type *to, Expr *ex
return true;
}
static inline bool sema_expr_analyse_access(Context *context, Expr *expr)
{
if (!sema_analyse_expr(context, NULL, expr->access_expr.parent)) return false;
return sema_expr_analyse_access_after_parent_resolution(context, expr);
}
static inline bool sema_expr_analyse_type_access(Context *context, Type *to, Expr *expr)
{
TypeInfo *type_info = expr->type_access.type;
@@ -1992,9 +2005,6 @@ static Expr *expr_copy_from_macro(Context *context, Expr *macro, Expr *source_ex
Expr *expr = expr_shallow_copy(source_expr);
switch (source_expr->expr_kind)
{
case EXPR_DESIGNATED_INIT:
// This type of expression is only created after analysis.
UNREACHABLE
case EXPR_EXPR_BLOCK:
ast_copy_list_from_macro(context, macro, &expr->expr_block.stmts);
return expr;
@@ -2449,7 +2459,6 @@ static inline bool sema_analyse_expr_dispatch(Context *context, Type *to, Expr *
case EXPR_POISONED:
return false;
case EXPR_SCOPED_EXPR:
case EXPR_DESIGNATED_INIT:
UNREACHABLE
case EXPR_EXPR_BLOCK:
return sema_expr_analyse_expr_block(context, to, expr);
@@ -2482,7 +2491,7 @@ static inline bool sema_analyse_expr_dispatch(Context *context, Type *to, Expr *
case EXPR_GROUP:
return sema_expr_analyse_group(context, to, expr);
case EXPR_ACCESS:
return sema_expr_analyse_access(context, to, expr);
return sema_expr_analyse_access(context, expr);
case EXPR_INITIALIZER_LIST:
return sema_expr_analyse_initializer_list(context, to, expr);
case EXPR_CAST: