mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-30 09:54:45 +00:00
#const value procedure parameters; $N for polymorphic array lengths
This commit is contained in:
@@ -126,8 +126,9 @@ enum FieldFlag {
|
||||
FieldFlag_using = 1<<1,
|
||||
FieldFlag_no_alias = 1<<2,
|
||||
FieldFlag_c_vararg = 1<<3,
|
||||
FieldFlag_const = 1<<4,
|
||||
|
||||
FieldFlag_Signature = FieldFlag_ellipsis|FieldFlag_using|FieldFlag_no_alias|FieldFlag_c_vararg,
|
||||
FieldFlag_Signature = FieldFlag_ellipsis|FieldFlag_using|FieldFlag_no_alias|FieldFlag_c_vararg|FieldFlag_const,
|
||||
FieldFlag_Struct = FieldFlag_using,
|
||||
};
|
||||
|
||||
@@ -3314,6 +3315,10 @@ AstNode *parse_proc_type(AstFile *f, Token proc_token) {
|
||||
is_generic = true;
|
||||
break;
|
||||
}
|
||||
if (f->flags&FieldFlag_const) {
|
||||
is_generic = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3357,6 +3362,7 @@ enum FieldPrefixKind {
|
||||
FieldPrefix_Using,
|
||||
FieldPrefix_NoAlias,
|
||||
FieldPrefix_CVarArg,
|
||||
FieldPrefix_Const,
|
||||
};
|
||||
|
||||
FieldPrefixKind is_token_field_prefix(AstFile *f) {
|
||||
@@ -3367,15 +3373,17 @@ FieldPrefixKind is_token_field_prefix(AstFile *f) {
|
||||
case Token_using:
|
||||
return FieldPrefix_Using;
|
||||
|
||||
|
||||
case Token_Hash: {
|
||||
advance_token(f);
|
||||
switch (f->curr_token.kind) {
|
||||
case Token_Ident:
|
||||
if (f->curr_token.string == "no_alias") {
|
||||
return FieldPrefix_NoAlias;
|
||||
}
|
||||
if (f->curr_token.string == "c_vararg") {
|
||||
} else if (f->curr_token.string == "c_vararg") {
|
||||
return FieldPrefix_CVarArg;
|
||||
} else if (f->curr_token.string == "const") {
|
||||
return FieldPrefix_Const;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -3389,6 +3397,7 @@ u32 parse_field_prefixes(AstFile *f) {
|
||||
i32 using_count = 0;
|
||||
i32 no_alias_count = 0;
|
||||
i32 c_vararg_count = 0;
|
||||
i32 const_count = 0;
|
||||
|
||||
for (;;) {
|
||||
FieldPrefixKind kind = is_token_field_prefix(f);
|
||||
@@ -3396,20 +3405,23 @@ u32 parse_field_prefixes(AstFile *f) {
|
||||
break;
|
||||
}
|
||||
switch (kind) {
|
||||
case FieldPrefix_Using: using_count += 1; advance_token(f); break;
|
||||
case FieldPrefix_NoAlias: no_alias_count += 1; advance_token(f); break;
|
||||
case FieldPrefix_CVarArg: c_vararg_count += 1; advance_token(f); break;
|
||||
case FieldPrefix_Using: using_count += 1; advance_token(f); break;
|
||||
case FieldPrefix_NoAlias: no_alias_count += 1; advance_token(f); break;
|
||||
case FieldPrefix_CVarArg: c_vararg_count += 1; advance_token(f); break;
|
||||
case FieldPrefix_Const: const_count += 1; advance_token(f); break;
|
||||
}
|
||||
}
|
||||
if (using_count > 1) syntax_error(f->curr_token, "Multiple `using` in this field list");
|
||||
if (no_alias_count > 1) syntax_error(f->curr_token, "Multiple `#no_alias` in this field list");
|
||||
if (c_vararg_count > 1) syntax_error(f->curr_token, "Multiple `#c_vararg` in this field list");
|
||||
if (const_count > 1) syntax_error(f->curr_token, "Multiple `$` in this field list");
|
||||
|
||||
|
||||
u32 field_flags = 0;
|
||||
if (using_count > 0) field_flags |= FieldFlag_using;
|
||||
if (no_alias_count > 0) field_flags |= FieldFlag_no_alias;
|
||||
if (c_vararg_count > 0) field_flags |= FieldFlag_c_vararg;
|
||||
if (const_count > 0) field_flags |= FieldFlag_const;
|
||||
return field_flags;
|
||||
}
|
||||
|
||||
@@ -3431,6 +3443,10 @@ u32 check_field_prefixes(AstFile *f, isize name_count, u32 allowed_flags, u32 se
|
||||
syntax_error(f->curr_token, "`#c_vararg` is not allowed within this field list");
|
||||
set_flags &= ~FieldFlag_c_vararg;
|
||||
}
|
||||
if ((allowed_flags&FieldFlag_const) == 0 && (set_flags&FieldFlag_const)) {
|
||||
syntax_error(f->curr_token, "`$` is not allowed within this field list");
|
||||
set_flags &= ~FieldFlag_const;
|
||||
}
|
||||
return set_flags;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user