Skip to content

Commit

Permalink
Additional cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Jan 30, 2025
1 parent 7782602 commit b040736
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 94 deletions.
2 changes: 2 additions & 0 deletions src/build/common_build.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const char *get_cflags(BuildParseContext context, JSONObject *json, const char *
if (cflags && cflags_add)
{
// TODO remove in 0.7
static_assert(ALLOW_DEPRECATED_6, "Fix deprecation");
error_exit("In file '%s': '%s' is combining both 'cflags-add' and 'cflags-override', only one may be used.", context.file, context.target);
}

Expand Down Expand Up @@ -149,6 +150,7 @@ void get_list_append_strings(BuildParseContext context, JSONObject *json, const
if (value && add_value)
{
// TODO remove in 0.7
static_assert(ALLOW_DEPRECATED_6, "Fix deprecation");
error_exit("In file '%s': '%s' is combining both '%s' and '%s', only one may be used.", context.file, context.target, override, add);
}
if (value) *list_ptr = value;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compiler_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2321,7 +2321,7 @@ bool sema_analyse_inferred_expr(SemaContext *context, Type *to, Expr *expr);
bool sema_analyse_decl(SemaContext *context, Decl *decl);

bool sema_analyse_method_register(SemaContext *context, Decl *method);
bool sema_resolve_type_structure(SemaContext *context, Type *type, SourceSpan span);
bool sema_resolve_type_structure(SemaContext *context, Type *type);
bool sema_analyse_var_decl_ct(SemaContext *context, Decl *decl);
bool sema_analyse_var_decl(SemaContext *context, Decl *decl, bool local);
bool sema_analyse_ct_assert_stmt(SemaContext *context, Ast *statement);
Expand Down
58 changes: 36 additions & 22 deletions src/compiler/parse_expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ static Expr *parse_lambda(ParseContext *c, Expr *left)
ASSIGN_TYPE_OR_RET(return_type, parse_optional_type(c), poisoned_expr);
}
CONSUME_OR_RET(TOKEN_LPAREN, poisoned_expr);
Decl **params = NULL;
Decl **decls = NULL;
Variadic variadic = VARIADIC_NONE;
int vararg_index = -1;
Expand Down Expand Up @@ -454,6 +453,8 @@ static Expr *parse_lambda(ParseContext *c, Expr *left)
return expr;
}

static_assert(ALLOW_DEPRECATED_6, "Fix deprecation");

/**
* vasplat ::= CT_VASPLAT '(' range_expr ')'
* -> TODO, this is the only one in 0.7
Expand All @@ -471,16 +472,19 @@ Expr *parse_vasplat(ParseContext *c)
CONSUME_OR_RET(lparen ? TOKEN_RPAREN : TOKEN_RBRACKET, poisoned_expr);
}
RANGE_EXTEND_PREV(expr);
END:
END:;
// TODO remove in 0.7
static_assert(ALLOW_DEPRECATED_6, "Fix deprecation");
if (lparen)
{
if (expr->vasplat_expr.end || expr->vasplat_expr.start)
{
static_assert(ALLOW_DEPRECATED_6, "Fix deprecation");
SEMA_DEPRECATED(expr, "'$vasplat(...)' is deprecated, use '$vasplat[...]' instead.");
}
else
{
static_assert(ALLOW_DEPRECATED_6, "Fix deprecation");
SEMA_DEPRECATED(expr, "'$vasplat()' is deprecated, use '$vasplat' instead.");
}
}
Expand All @@ -494,11 +498,9 @@ Expr *parse_vasplat(ParseContext *c)
bool parse_arg_list(ParseContext *c, Expr ***result, TokenType param_end, bool vasplat)
{
*result = NULL;
bool has_splat = false;
while (1)
{
Expr *expr = NULL;
DesignatorElement **path;
SourceSpan start_span = c->span;

if (peek(c) == TOKEN_COLON && token_is_param_name(c->tok))
Expand All @@ -524,6 +526,7 @@ bool parse_arg_list(ParseContext *c, Expr ***result, TokenType param_end, bool v
CONSUME_OR_RET(TOKEN_EQ, false);
ASSIGN_EXPR_OR_RET(expr->named_argument_expr.value, parse_expr(c), false);
RANGE_EXTEND_PREV(expr);
static_assert(ALLOW_DEPRECATED_6, "Fix deprecation");
SEMA_DEPRECATED(expr, "Named arguments using the '.foo = expr' style are deprecated, please use 'foo: expr' instead.");
goto DONE;
}
Expand Down Expand Up @@ -587,7 +590,7 @@ bool parse_init_list(ParseContext *c, Expr ***result, TokenType param_end, bool
*splat = try_consume(c, TOKEN_ELLIPSIS);
}
ASSIGN_EXPR_OR_RET(expr, parse_expr(c), false);
DONE:
DONE:
vec_add(*result, expr);
if (!try_consume(c, TOKEN_COMMA))
{
Expand Down Expand Up @@ -654,15 +657,25 @@ Expr *parse_ct_expression_list(ParseContext *c, bool allow_decl)
}

/**
* type_expr ::= void | any | int | short ... etc
*
* @param c the context
* @param left must be null.
* @return Expr*
* @return Expr *
*/
static Expr *parse_type_identifier(ParseContext *c, Expr *left)
{
ASSERT(!left && "Unexpected left hand side");
return parse_type_expression_with_path(c, NULL);
}

/**
* splat_expr ::= '...' expr
*
* @param c the context
* @param left must be null.
* @return Expr *
*/
static Expr *parse_splat(ParseContext *c, Expr *left)
{
ASSERT(!left && "Unexpected left hand side");
Expand Down Expand Up @@ -696,6 +709,13 @@ static Expr *parse_type_expr(ParseContext *c, Expr *left)
return expr;
}

/**
* ct_stringify ::= $stringify '(' expr ')'
*
* @param c the context
* @param left must be null
* @return Expr *
*/
static Expr *parse_ct_stringify(ParseContext *c, Expr *left)
{
ASSERT(!left && "Unexpected left hand side");
Expand All @@ -713,15 +733,7 @@ static Expr *parse_ct_stringify(ParseContext *c, Expr *left)
RANGE_EXTEND_PREV(expr);
return expr;
}
size_t len = end - start;
const char *content = str_copy(start, len);
Expr *expr = expr_new(EXPR_CONST, start_span);
expr->const_expr.const_kind = CONST_STRING;
expr->const_expr.bytes.ptr = content;
expr->const_expr.bytes.len = len;
expr->type = type_string;
expr->resolve_status = RESOLVE_DONE;
return expr;
return expr_new_const_string(start_span, str_copy(start, end - start));
}

/**
Expand Down Expand Up @@ -872,8 +884,6 @@ static Expr *parse_grouping_expr(ParseContext *c, Expr *left)
* | initializer_values ',' initializer
* ;
*
* @param elements
* @return
*/
Expr *parse_initializer_list(ParseContext *c, Expr *left)
{
Expand Down Expand Up @@ -1247,6 +1257,7 @@ static Expr *parse_ct_concat_append(ParseContext *c, Expr *left)
{
ASSERT(!left && "Unexpected left hand side");
Expr *expr = EXPR_NEW_TOKEN(tok_is(c, TOKEN_CT_CONCATFN) ? EXPR_CT_CONCAT : EXPR_CT_APPEND);
static_assert(ALLOW_DEPRECATED_6, "Fix deprecation");
SEMA_DEPRECATED(expr, "'%s' is deprecated in favour of '+++'.", symstr(c));
advance(c);

Expand Down Expand Up @@ -1283,6 +1294,7 @@ static Expr *parse_ct_and_or(ParseContext *c, Expr *left)
ASSERT(!left && "Unexpected left hand side");
Expr *expr = EXPR_NEW_TOKEN(EXPR_CT_AND_OR);
expr->ct_and_or_expr.is_and = tok_is(c, TOKEN_CT_ANDFN);
static_assert(ALLOW_DEPRECATED_6, "Fix deprecation");
SEMA_DEPRECATED(expr, "The use of '%s' is deprecated in favour of '%s'.", symstr(c),
expr->ct_and_or_expr.is_and ? "&&&" : "|||");
advance(c);
Expand Down Expand Up @@ -1320,13 +1332,15 @@ static Expr *parse_ct_arg(ParseContext *c, Expr *left)
if (type != TOKEN_CT_VACOUNT)
{
// TODO remove in 0.7
static_assert(ALLOW_DEPRECATED_6, "Fix deprecation");
bool is_lparen = try_consume(c, TOKEN_LPAREN);
if (!is_lparen) CONSUME_OR_RET(TOKEN_LBRACKET, poisoned_expr);
ASSIGN_EXPRID_OR_RET(expr->ct_arg_expr.arg, parse_expr(c), poisoned_expr);
CONSUME_OR_RET(is_lparen ? TOKEN_RPAREN : TOKEN_RBRACKET, poisoned_expr);
// TODO remove in 0.7
if (is_lparen)
{
static_assert(ALLOW_DEPRECATED_6, "Fix deprecation");
SEMA_DEPRECATED(expr, "'%s(...)' is deprecated, use '%s[...]' instead.",
token_type_to_string(type), token_type_to_string(type));
}
Expand Down Expand Up @@ -1359,7 +1373,6 @@ static Expr *parse_identifier(ParseContext *c, Expr *left)
static Expr *parse_identifier_starting_expression(ParseContext *c, Expr *left)
{
ASSERT(!left && "Unexpected left hand side");
bool had_error;
Path *path;
if (!parse_path_prefix(c, &path)) return poisoned_expr;
switch (c->tok)
Expand Down Expand Up @@ -1696,7 +1709,7 @@ static void parse_hex(char *result_pointer, const char *data, const char *end)
{
int val, val2;
while ((val = char_hex_to_nibble(*(data++))) < 0) if (data == end) return;
while ((val2 = char_hex_to_nibble(*(data++))) < 0);
while ((val2 = char_hex_to_nibble(*(data++))) < 0) {}
*(data_current++) = (char)((val << 4) | val2);
}
}
Expand All @@ -1717,6 +1730,7 @@ static char base64_to_sextet(char c)
/**
* Parse hex, skipping over invalid characters.
* @param result_pointer ref to place to put the data
* @param result_pointer_end the end of the result data
* @param data start pointer
* @param end end pointer
*/
Expand All @@ -1728,9 +1742,9 @@ static void parse_base64(char *result_pointer, char *result_pointer_end, const c
{
int val, val2, val3, val4;
while ((val = base64_to_sextet(*(data++))) < 0) if (data == end) goto DONE;
while ((val2 = base64_to_sextet(*(data++))) < 0);
while ((val3 = base64_to_sextet(*(data++))) < 0);
while ((val4 = base64_to_sextet(*(data++))) < 0);
while ((val2 = base64_to_sextet(*(data++))) < 0) {}
while ((val3 = base64_to_sextet(*(data++))) < 0) {}
while ((val4 = base64_to_sextet(*(data++))) < 0) {}
uint32_t triplet = (uint32_t)((val << 3 * 6) + (val2 << 2 * 6) + (val3 << 6) + val4);
if (data_current < result_pointer_end) *(data_current++) = (char)((triplet >> 16) & 0xFF);
if (data_current < result_pointer_end) *(data_current++) = (char)((triplet >> 8) & 0xFF);
Expand Down
1 change: 1 addition & 0 deletions src/compiler/parse_global.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ static inline TypeInfo *parse_base_type(ParseContext *c)
// TODO remove in 0.7
if (is_lparen)
{
static_assert(ALLOW_DEPRECATED_6, "Fix deprecation");
SEMA_DEPRECATED(type_info, "'$vatype(...)' is deprecated, use '$vatype[...]' instead.");
}
return type_info;
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/sema_casts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,7 @@ static void cast_float_to_int(SemaContext *context, Expr *expr, Type *type)
*/
static void cast_int_to_enum(SemaContext *context, Expr *expr, Type *type)
{
static_assert(ALLOW_DEPRECATED_6, "Fix deprecation");
SEMA_DEPRECATED(expr, "Using casts to convert integers to enums is deprecated in favour of using 'MyEnum.from_ordinal(i)`.");
Type *canonical = type_flatten(type);
ASSERT(canonical->type_kind == TYPE_ENUM);
Expand Down Expand Up @@ -1642,6 +1643,7 @@ static void cast_int_to_float(SemaContext *context, Expr *expr, Type *type)

static void cast_enum_to_int(SemaContext *context, Expr* expr, Type *to_type)
{
static_assert(ALLOW_DEPRECATED_6, "Fix deprecation");
SEMA_DEPRECATED(expr, "Using casts to convert enums to integers is deprecated in favour of using 'the_enum.ordinal`.");
sema_expr_convert_enum_to_int(context, expr);
cast_int_to_int(context, expr, to_type);
Expand Down
49 changes: 18 additions & 31 deletions src/compiler/sema_decls.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ static inline bool sema_analyse_distinct(SemaContext *context, Decl *decl, bool

static CompilationUnit *unit_copy(Module *module, CompilationUnit *unit);

static Module *module_instantiate_generic(SemaContext *context, Module *module, Path *path, Expr **params,
SourceSpan from);
static Module *module_instantiate_generic(SemaContext *context, Module *module, Path *path, Expr **params);

static inline bool sema_analyse_enum_param(SemaContext *context, Decl *param);
static inline bool sema_analyse_enum(SemaContext *context, Decl *decl, bool *erase_decl);
Expand Down Expand Up @@ -1224,6 +1223,7 @@ static inline bool sema_analyse_signature(SemaContext *context, Signature *sig,
case VARDECL_PARAM_REF:
if ((i != 0 || !method_parent) && !is_deprecated)
{
static_assert(ALLOW_DEPRECATED_6, "Fix deprecation");
SEMA_DEPRECATED(param, "Reference macro arguments are deprecated.");
}
if (type_info && !type_is_pointer(param->type))
Expand Down Expand Up @@ -2687,6 +2687,7 @@ static bool sema_analyse_attribute(SemaContext *context, ResolvedAttrData *attr_
}
case ATTRIBUTE_ADHOC:
SEMA_DEPRECATED(attr, "'@adhoc' is deprecated.");
static_assert(ALLOW_DEPRECATED_6, "Fix deprecation");
return true;
case ATTRIBUTE_ALIGN:
if (!expr)
Expand Down Expand Up @@ -3385,7 +3386,7 @@ static inline Decl *sema_create_synthetic_main(SemaContext *context, Decl *decl,
default: UNREACHABLE
}
}
else if (is_wmain)
if (is_wmain)
{
switch (type)
{
Expand All @@ -3395,15 +3396,12 @@ static inline Decl *sema_create_synthetic_main(SemaContext *context, Decl *decl,
default: UNREACHABLE
}
}
else
switch (type)
{
switch (type)
{
case 0 : main_invoker = "@main_to_void_main_args"; goto NEXT;
case 1 : main_invoker = "@main_to_int_main_args"; goto NEXT;
case 2 : main_invoker = "@main_to_err_main_args"; goto NEXT;
default: UNREACHABLE
}
case 0: main_invoker = "@main_to_void_main_args"; goto NEXT;
case 1: main_invoker = "@main_to_int_main_args"; goto NEXT;
case 2: main_invoker = "@main_to_err_main_args"; goto NEXT;
default: UNREACHABLE
}
case MAIN_TYPE_NO_ARGS:
ASSERT(!is_wmain);
Expand Down Expand Up @@ -3487,6 +3485,7 @@ static inline bool sema_analyse_main_function(SemaContext *context, Decl *decl)
}
is_int_return = false;
is_err_return = true;
static_assert(ALLOW_DEPRECATED_6, "Fix deprecation");
SEMA_DEPRECATED(rtype_info, "Main functions with 'void!' returns is deprecated, use 'int' or 'void' instead.");
}

Expand Down Expand Up @@ -3534,10 +3533,7 @@ static inline bool sema_analyse_main_function(SemaContext *context, Decl *decl)
SEMA_NOTE(compiler.context.main, "The first one was found here.");
return false;
}
else
{
compiler.context.main = function;
}
compiler.context.main = function;
return true;
}

Expand Down Expand Up @@ -4258,8 +4254,7 @@ static CompilationUnit *unit_copy(Module *module, CompilationUnit *unit)
return copy;
}

static Module *module_instantiate_generic(SemaContext *context, Module *module, Path *path, Expr **params,
SourceSpan from)
static Module *module_instantiate_generic(SemaContext *context, Module *module, Path *path, Expr **params)
{
unsigned decls = 0;
Decl* params_decls[MAX_PARAMS];
Expand All @@ -4271,25 +4266,17 @@ static Module *module_instantiate_generic(SemaContext *context, Module *module,
Expr *param = params[i];
if (param->expr_kind != EXPR_TYPEINFO)
{
if (!is_value)
{
SEMA_ERROR(param, "Expected a type, not a value.");
return NULL;
}
if (!is_value) RETURN_NULL_SEMA_ERROR(param, "Expected a type, not a value.");
Decl *decl = decl_new_var(param_name, param->span, NULL, VARDECL_CONST);
decl->var.init_expr = param;
decl->type = param->type;
decl->resolve_status = RESOLVE_NOT_DONE;
params_decls[decls++] = decl;
continue;
}
if (is_value)
{
SEMA_ERROR(param, "Expected a value, not a type.");
return NULL;
}
if (is_value) RETURN_NULL_SEMA_ERROR(param, "Expected a value, not a type.");
TypeInfo *type_info = param->type_expr;
if (!sema_resolve_type_info(context, type_info, RESOLVE_TYPE_DEFAULT)) return false;
if (!sema_resolve_type_info(context, type_info, RESOLVE_TYPE_DEFAULT)) return NULL;
Decl *decl = decl_new_with_type(param_name, params[i]->span, DECL_TYPEDEF);
decl->resolve_status = RESOLVE_DONE;
ASSERT(type_info->resolve_status == RESOLVE_DONE);
Expand Down Expand Up @@ -4529,9 +4516,9 @@ Decl *sema_analyse_parameterized_identifier(SemaContext *c, Path *decl_path, con
path->module = path_string;
path->span = module->name->span;
path->len = scratch_buffer.len;
instantiated_module = module_instantiate_generic(c, module, path, params, span);
if (!sema_generate_parameterized_name_to_scratch(c, module, params, false, NULL)) return poisoned_decl;
instantiated_module = module_instantiate_generic(c, module, path, params);
if (!instantiated_module) return poisoned_decl;
if (!sema_generate_parameterized_name_to_scratch(c, module, params, false, NULL)) return poisoned_decl;
instantiated_module->generic_suffix = scratch_buffer_copy();
sema_analyze_stage(instantiated_module, stage > ANALYSIS_POST_REGISTER ? ANALYSIS_POST_REGISTER : stage);
}
Expand Down Expand Up @@ -4641,7 +4628,7 @@ static inline bool sema_analyse_define(SemaContext *context, Decl *decl, bool *e
return true;
}

bool sema_resolve_type_structure(SemaContext *context, Type *type, SourceSpan span)
bool sema_resolve_type_structure(SemaContext *context, Type *type)
{
RETRY:
switch (type->type_kind)
Expand Down
Loading

0 comments on commit b040736

Please sign in to comment.