Change precedence order for types e.g. ^T(x) == ^(T(x))

This commit is contained in:
Ginger Bill
2017-07-13 16:20:07 +01:00
parent 03570275c1
commit b8697fb4ed
19 changed files with 1683 additions and 1442 deletions
+1 -1
View File
@@ -365,7 +365,7 @@ void init_entity_foreign_library(Checker *c, Entity *e) {
String name = ident->Ident.token.string;
Entity *found = scope_lookup_entity(c->context.scope, name);
if (found == nullptr) {
if (name == "_") {
if (is_blank_ident(name)) {
error(ident, "`_` cannot be used as a value type");
} else {
error(ident, "Undeclared name: %.*s", LIT(name));
+13 -15
View File
@@ -823,7 +823,7 @@ void check_record_field_decl(Checker *c, AstNode *decl, Array<Entity *> *fields,
Entity *e = make_entity_field(c->allocator, c->context.scope, name_token, type, is_using, cast(i32)fields->count);
e->identifier = name;
if (name_token.string == "_") {
if (is_blank_ident(name_token)) {
array_add(fields, e);
} else if (name_token.string == "__tag") {
error(name, "`__tag` is a reserved identifier for fields");
@@ -1223,7 +1223,7 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod
// NOTE(bill): Skip blank identifiers
if (name == "_") {
if (is_blank_ident(name)) {
continue;
} else if (name == "count") {
error(field, "`count` is a reserved identifier for enumerations");
@@ -1331,7 +1331,7 @@ void check_bit_field_type(Checker *c, Type *bit_field_type, Type *named_type, As
e->flags |= EntityFlag_BitFieldValue;
HashKey key = hash_string(name);
if (name != "_" &&
if (!is_blank_ident(name) &&
map_get(&entity_map, key) != nullptr) {
error(ident, "`%.*s` is already declared in this bit field", LIT(name));
} else {
@@ -1879,12 +1879,12 @@ Type *check_get_results(Checker *c, Scope *scope, AstNode *_results) {
for (isize i = 0; i < variable_index; i++) {
String x = variables[i]->token.string;
if (x.len == 0 || x == "_") {
if (x.len == 0 || is_blank_ident(x)) {
continue;
}
for (isize j = i+1; j < variable_index; j++) {
String y = variables[j]->token.string;
if (y.len == 0 || y == "_") {
if (y.len == 0 || is_blank_ident(y)) {
continue;
}
if (x == y) {
@@ -2162,7 +2162,7 @@ Entity *check_ident(Checker *c, Operand *o, AstNode *n, Type *named_type, Type *
Entity *e = scope_lookup_entity(c->context.scope, name);
if (e == nullptr) {
if (name == "_") {
if (is_blank_ident(name)) {
error(n, "`_` cannot be used as a value type");
} else {
error(n, "Undeclared name: %.*s", LIT(name));
@@ -2603,7 +2603,7 @@ bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type)
Type *elem = check_type(c, at->elem, nullptr);
i64 count = check_array_or_map_count(c, at->count, false);
if (count < 0) {
error(at->count, ".. can only be used in conjuction with compound literals");
error(at->count, "... can only be used in conjuction with compound literals");
count = 0;
}
#if 0
@@ -5735,7 +5735,7 @@ isize lookup_procedure_parameter(TypeProc *pt, String parameter_name) {
for (isize i = 0; i < param_count; i++) {
Entity *e = pt->params->Tuple.variables[i];
String name = e->token.string;
if (name == "_") {
if (is_blank_ident(name)) {
continue;
}
if (name == parameter_name) {
@@ -5749,7 +5749,7 @@ isize lookup_procedure_result(TypeProc *pt, String result_name) {
for (isize i = 0; i < result_count; i++) {
Entity *e = pt->results->Tuple.variables[i];
String name = e->token.string;
if (name == "_") {
if (is_blank_ident(name)) {
continue;
}
if (name == result_name) {
@@ -5818,7 +5818,7 @@ CALL_ARGUMENT_CHECKER(check_named_call_arguments) {
for (isize i = 0; i < param_count_to_check; i++) {
if (!visited[i]) {
Entity *e = pt->params->Tuple.variables[i];
if (e->token.string == "_") {
if (is_blank_ident(e->token)) {
continue;
}
if (e->kind == Entity_Variable) {
@@ -6664,7 +6664,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
bool all_fields_are_blank = true;
for (isize i = 0; i < t->Record.field_count; i++) {
Entity *field = t->Record.fields_in_src_order[i];
if (field->token.string != "_") {
if (!is_blank_ident(field->token)) {
all_fields_are_blank = false;
break;
}
@@ -6682,7 +6682,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
}
Entity *field = t->Record.fields_in_src_order[index];
if (!all_fields_are_blank && field->token.string == "_") {
if (!all_fields_are_blank && is_blank_ident(field->token)) {
// NOTE(bill): Ignore blank identifiers
continue;
}
@@ -7599,9 +7599,7 @@ gbString write_expr_to_string(gbString str, AstNode *node) {
if (field->names.count == 0) {
continue;
}
AstNode *name = field->names[0];
ast_node(n, Ident, name);
if (n->token.string != "_") {
if (!is_blank_ident(field->names[0])) {
has_name = true;
break;
}
+5 -6
View File
@@ -186,8 +186,7 @@ Type *check_assignment_variable(Checker *c, Operand *rhs, AstNode *lhs_node) {
AstNode *node = unparen_expr(lhs_node);
// NOTE(bill): Ignore assignments to `_`
if (node->kind == AstNode_Ident &&
node->Ident.token.string == "_") {
if (is_blank_ident(node)) {
add_entity_definition(&c->info, node, nullptr);
check_assignment(c, rhs, nullptr, str_lit("assignment to `_` identifier"));
if (rhs->mode == Addressing_Invalid) {
@@ -429,7 +428,7 @@ void check_label(Checker *c, AstNode *label) {
return;
}
String name = l->name->Ident.token.string;
if (name == "_") {
if (is_blank_ident(name)) {
error(l->name, "A label's name cannot be a blank identifier");
return;
}
@@ -884,7 +883,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
for (isize i = 0; i < result_count; i++) {
if (!visited[i]) {
Entity *e = pt->results->Tuple.variables[i];
if (e->token.string == "_") {
if (is_blank_ident(e->token)) {
continue;
}
GB_ASSERT(e->kind == Entity_Variable);
@@ -1133,7 +1132,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
String str = token.string;
Entity *found = nullptr;
if (str != "_") {
if (!is_blank_ident(str)) {
found = current_scope_lookup_entity(c->context.scope, str);
}
if (found == nullptr) {
@@ -1686,7 +1685,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
String str = token.string;
Entity *found = nullptr;
// NOTE(bill): Ignore assignments to `_`
if (str != "_") {
if (!is_blank_ident(str)) {
found = current_scope_lookup_entity(c->context.scope, str);
}
if (found == nullptr) {
+4 -4
View File
@@ -979,7 +979,7 @@ void add_type_and_value(CheckerInfo *i, AstNode *expression, AddressingMode mode
void add_entity_definition(CheckerInfo *i, AstNode *identifier, Entity *entity) {
GB_ASSERT(identifier != nullptr);
if (identifier->kind == AstNode_Ident) {
if (identifier->Ident.token.string == "_") {
if (is_blank_ident(identifier)) {
return;
}
HashKey key = hash_node(identifier);
@@ -994,7 +994,7 @@ bool add_entity(Checker *c, Scope *scope, AstNode *identifier, Entity *entity) {
return false;
}
String name = entity->token.string;
if (name != "_") {
if (!is_blank_ident(name)) {
Entity *ie = scope_insert_entity(scope, entity);
if (ie) {
TokenPos pos = ie->token.pos;
@@ -2202,7 +2202,7 @@ void check_import_entities(Checker *c, Map<Scope *> *file_scopes) {
}
} else {
String import_name = path_to_entity_name(id->import_name.string, id->fullpath);
if (import_name == "_") {
if (is_blank_ident(import_name)) {
error(token, "File name, %.*s, cannot be as an import name as it is not a valid identifier", LIT(id->import_name.string));
} else {
GB_ASSERT(id->import_name.pos.line != 0);
@@ -2254,7 +2254,7 @@ void check_import_entities(Checker *c, Map<Scope *> *file_scopes) {
String library_name = path_to_entity_name(fl->library_name.string, file_str);
if (library_name == "_") {
if (is_blank_ident(library_name)) {
error(spec, "File name, %.*s, cannot be as a library name as it is not a valid identifier", LIT(fl->library_name.string));
} else {
GB_ASSERT(fl->library_name.pos.line != 0);
+16 -15
View File
@@ -653,13 +653,6 @@ Type *ir_type(irValue *value) {
}
bool ir_is_blank_ident(AstNode *node) {
if (node->kind == AstNode_Ident) {
ast_node(i, Ident, node);
return is_blank_ident(i->token.string);
}
return false;
}
irInstr *ir_get_last_instr(irBlock *block) {
@@ -5001,7 +4994,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
case_end;
case_ast_node(i, Ident, expr);
if (ir_is_blank_ident(expr)) {
if (is_blank_ident(expr)) {
irAddr val = {};
return val;
}
@@ -5614,6 +5607,15 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
return ir_addr(v);
case_end;
case_ast_node(tc, TypeCast, expr);
Type *type = type_of_expr(proc->module->info, expr);
irValue *x = ir_build_expr(proc, tc->expr);
irValue *e = ir_emit_conv(proc, x, type);
irValue *v = ir_add_local_generated(proc, type);
ir_emit_store(proc, v, e);
return ir_addr(v);
case_end;
}
TokenPos token_pos = ast_node_token(expr).pos;
@@ -6143,7 +6145,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
if (vd->values.count == 0) { // declared and zero-initialized
for_array(i, vd->names) {
AstNode *name = vd->names[i];
if (!ir_is_blank_ident(name)) {
if (!is_blank_ident(name)) {
ir_add_local_for_identifier(proc, name, true);
}
}
@@ -6156,7 +6158,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
for_array(i, vd->names) {
AstNode *name = vd->names[i];
irAddr lval = ir_addr(nullptr);
if (!ir_is_blank_ident(name)) {
if (!is_blank_ident(name)) {
ir_add_local_for_identifier(proc, name, false);
lval = ir_build_addr(proc, name);
}
@@ -6200,7 +6202,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
for_array(i, as->lhs) {
AstNode *lhs = as->lhs[i];
irAddr lval = {};
if (!ir_is_blank_ident(lhs)) {
if (!is_blank_ident(lhs)) {
lval = ir_build_addr(proc, lhs);
}
array_add(&lvals, lval);
@@ -6498,10 +6500,10 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
Type *val_type = nullptr;
Type *idx_type = nullptr;
if (rs->value != nullptr && !ir_is_blank_ident(rs->value)) {
if (rs->value != nullptr && !is_blank_ident(rs->value)) {
val_type = type_of_expr(proc->module->info, rs->value);
}
if (rs->index != nullptr && !ir_is_blank_ident(rs->index)) {
if (rs->index != nullptr && !is_blank_ident(rs->index)) {
idx_type = type_of_expr(proc->module->info, rs->index);
}
@@ -7073,8 +7075,7 @@ void ir_begin_procedure_body(irProcedure *proc) {
}
Type *abi_type = proc->type->Proc.abi_compat_params[i];
if (e->token.string != "" &&
e->token.string != "_") {
if (e->token.string != "" && !is_blank_ident(e->token)) {
irValue *param = ir_add_param(proc, e, name, abi_type);
array_add(&proc->params, param);
}
+1 -2
View File
@@ -1580,8 +1580,7 @@ void ir_print_proc(irFileBuffer *f, irModule *m, irProcedure *proc) {
ir_fprintf(f, " noalias");
}
if (proc->body != nullptr) {
if (e->token.string != "" &&
e->token.string != "_") {
if (e->token.string != "" && !is_blank_ident(e->token)) {
ir_fprintf(f, " ");
ir_print_encoded_local(f, e->token.string);
} else {
+1558 -1315
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1476,7 +1476,7 @@ Entity *current_scope_lookup_entity(Scope *s, String name);
Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_name, bool is_type, Selection sel) {
GB_ASSERT(type_ != nullptr);
if (field_name == "_") {
if (is_blank_ident(field_name)) {
return empty_selection;
}