Remove derived from context; Fix parsing issue for typeid specializations in record parameters; Fix runtime printing of types

This commit is contained in:
gingerBill
2019-03-31 11:58:54 +01:00
parent 564e85ee29
commit 1354f53d02
4 changed files with 37 additions and 29 deletions
+3 -1
View File
@@ -1528,6 +1528,8 @@ parse_field_list :: proc(p: ^Parser, follow: token.Kind, allowed_flags: ast.Fiel
return ok;
}
is_signature := (allowed_flags & Field_Flags_Signature_Params) == Field_Flags_Signature_Params;
any_polymorphic_names := check_procedure_name_list(p, names);
set_flags = check_field_flag_prefixes(p, len(names), allowed_flags, set_flags);
@@ -1538,7 +1540,7 @@ parse_field_list :: proc(p: ^Parser, follow: token.Kind, allowed_flags: ast.Fiel
if p.curr_tok.kind != token.Eq {
type = parse_var_type(p, allowed_flags);
tt := ast.unparen_expr(type);
if !any_polymorphic_names {
if is_signature && !any_polymorphic_names {
if ti, ok := tt.derived.(ast.Typeid_Type); ok && ti.specialization != nil {
error(p, tt.pos, "specialization of typeid is not allowed without polymorphic names");
}
+1
View File
@@ -220,6 +220,7 @@ Context :: struct {
thread_id: int,
user_data: any,
user_ptr: rawptr,
user_index: int,
derived: any, // May be used for derived data types
+30 -26
View File
@@ -223,6 +223,21 @@ print_type :: proc(fd: os.Handle, ti: ^Type_Info) {
print_type(fd, info.underlying);
}
os.write_byte(fd, ']');
case Type_Info_Opaque:
os.write_string(fd, "opaque ");
print_type(fd, info.elem);
case Type_Info_Simd_Vector:
if info.is_x86_mmx {
os.write_string(fd, "intrinsics.x86_mmx");
} else {
os.write_string(fd, "intrinsics.vector(");
print_u64(fd, u64(info.count));
os.write_string(fd, ", ");
print_type(fd, info.elem);
os.write_byte(fd, ')');
}
}
}
@@ -285,38 +300,27 @@ bounds_check_error :: proc "contextless" (file: string, line, column: int, index
handle_error(file, line, column, index, count);
}
slice_handle_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) {
fd := os.stderr;
print_caller_location(fd, Source_Code_Location{file, line, column, "", 0});
os.write_string(fd, " Invalid slice indices: ");
print_i64(fd, i64(lo));
os.write_string(fd, ":");
print_i64(fd, i64(hi));
os.write_string(fd, ":");
print_i64(fd, i64(len));
os.write_byte(fd, '\n');
debug_trap();
}
slice_expr_error_hi :: proc "contextless" (file: string, line, column: int, hi: int, len: int) {
if 0 <= hi && hi <= len do return;
handle_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) {
fd := os.stderr;
print_caller_location(fd, Source_Code_Location{file, line, column, "", 0});
os.write_string(fd, " Invalid slice indices: ");
print_i64(fd, i64(lo));
os.write_string(fd, ":");
print_i64(fd, i64(hi));
os.write_string(fd, ":");
print_i64(fd, i64(len));
os.write_byte(fd, '\n');
debug_trap();
}
handle_error(file, line, column, 0, hi, len);
slice_handle_error(file, line, column, 0, hi, len);
}
slice_expr_error_lo_hi :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) {
if 0 <= lo && lo <= len && lo <= hi && hi <= len do return;
handle_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) {
fd := os.stderr;
print_caller_location(fd, Source_Code_Location{file, line, column, "", 0});
os.write_string(fd, " Invalid slice indices: ");
print_i64(fd, i64(lo));
os.write_string(fd, ":");
print_i64(fd, i64(hi));
os.write_string(fd, ":");
print_i64(fd, i64(len));
os.write_byte(fd, '\n');
debug_trap();
}
handle_error(file, line, column, lo, hi, len);
slice_handle_error(file, line, column, lo, hi, len);
}
dynamic_array_expr_error :: proc "contextless" (file: string, line, column: int, low, high, max: int) {
+3 -2
View File
@@ -3024,6 +3024,7 @@ Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKi
isize total_name_count = 0;
bool allow_ellipsis = allowed_flags&FieldFlag_ellipsis;
bool seen_ellipsis = false;
bool is_signature = (allowed_flags & FieldFlag_Signature) == FieldFlag_Signature;
while (f->curr_token.kind != follow &&
f->curr_token.kind != Token_Colon &&
@@ -3064,7 +3065,7 @@ Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKi
if (f->curr_token.kind != Token_Eq) {
type = parse_var_type(f, allow_ellipsis, allow_typeid_token);
Ast *tt = unparen_expr(type);
if (!any_polymorphic_names && tt->kind == Ast_TypeidType && tt->TypeidType.specialization != nullptr) {
if (is_signature && !any_polymorphic_names && tt->kind == Ast_TypeidType && tt->TypeidType.specialization != nullptr) {
syntax_error(type, "Specialization of typeid is not allowed without polymorphic names");
}
}
@@ -3121,7 +3122,7 @@ Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKi
if (f->curr_token.kind != Token_Eq) {
type = parse_var_type(f, allow_ellipsis, allow_typeid_token);
Ast *tt = unparen_expr(type);
if (!any_polymorphic_names && tt->kind == Ast_TypeidType && tt->TypeidType.specialization != nullptr) {
if (is_signature && !any_polymorphic_names && tt->kind == Ast_TypeidType && tt->TypeidType.specialization != nullptr) {
syntax_error(type, "Specialization of typeid is not allowed without polymorphic names");
}
}