Remove #const; Minor fixes

This commit is contained in:
gingerBill
2017-11-12 20:15:17 +00:00
parent dffa791607
commit f6a56c2f82
7 changed files with 25 additions and 304 deletions

View File

@@ -10,7 +10,6 @@ import "core:raw.odin"
//
// Import Name: snake_case (but prefer single word)
// Types: Ada_Case
// Union Variants: Ada_Case
// Enum Values: Ada_Case
// Procedures: snake_case
// Local Variables: snake_case

View File

@@ -341,21 +341,21 @@ Type *check_assignment_variable(Checker *c, Operand *lhs, Operand *rhs) {
return rhs->type;
}
enum SwitchTypeKind {
SwitchType_Invalid,
SwitchType_Union,
SwitchType_Any,
enum SwitchKind {
Switch_Invalid,
Switch_Union,
Switch_Any,
};
SwitchTypeKind check_valid_type_switch_type(Type *type) {
SwitchKind check_valid_type_switch_type(Type *type) {
type = type_deref(type);
if (is_type_union(type)) {
return SwitchType_Union;
return Switch_Union;
}
if (is_type_any(type)) {
return SwitchType_Any;
return Switch_Any;
}
return SwitchType_Invalid;
return Switch_Invalid;
}
void check_stmt_internal(Checker *c, AstNode *node, u32 flags);
@@ -1401,7 +1401,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
check_open_scope(c, node);
check_label(c, ss->label); // TODO(bill): What should the label's "scope" be?
SwitchTypeKind switch_type_kind = SwitchType_Invalid;
SwitchKind switch_kind = Switch_Invalid;
if (ss->tag->kind != AstNode_AssignStmt) {
error(ss->tag, "Expected an 'in' assignment for this type switch statement");
@@ -1423,8 +1423,8 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
check_expr(c, &x, rhs);
check_assignment(c, &x, nullptr, str_lit("type switch expression"));
switch_type_kind = check_valid_type_switch_type(x.type);
if (check_valid_type_switch_type(x.type) == SwitchType_Invalid) {
switch_kind = check_valid_type_switch_type(x.type);
if (check_valid_type_switch_type(x.type) == Switch_Invalid) {
gbString str = type_to_string(x.type);
error(x.expr, "Invalid type for this type switch expression, got '%s'", str);
gb_string_free(str);
@@ -1488,7 +1488,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
Operand y = {};
check_expr_or_type(c, &y, type_expr);
if (switch_type_kind == SwitchType_Union) {
if (switch_kind == Switch_Union) {
GB_ASSERT(is_type_union(bt));
bool tag_type_found = false;
for_array(i, bt->Union.variants) {
@@ -1505,7 +1505,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
continue;
}
case_type = y.type;
} else if (switch_type_kind == SwitchType_Any) {
} else if (switch_kind == Switch_Any) {
case_type = y.type;
} else {
GB_PANIC("Unknown type to type switch statement");

View File

@@ -1272,7 +1272,6 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari
Type *specialization = nullptr;
bool is_using = (p->flags&FieldFlag_using) != 0;
bool is_constant_value = (p->flags&FieldFlag_const) != 0;
if (type_expr == nullptr) {
@@ -1372,9 +1371,6 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari
if (type_expr->kind == AstNode_TypeType) {
error(default_value, "A type parameter may not have a default value");
continue;
} else if (is_constant_value) {
error(default_value, "A constant parameter may not have a default value");
continue;
} else {
Operand o = {};
if (default_value->kind == AstNode_BasicDirective &&
@@ -1448,17 +1444,6 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari
}
}
if (is_constant_value) {
if (is_type_param) {
error(param, "'$' is not needed for a 'type' parameter");
}
if (p->flags&FieldFlag_no_alias) {
error(param, "'#no_alias' can only be applied to variable fields of pointer type");
p->flags &= ~FieldFlag_no_alias; // Remove the flag
}
}
for_array(j, p->names) {
AstNode *name = p->names[j];
if (!ast_node_expect(name, AstNode_Ident)) {
@@ -1522,34 +1507,10 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari
}
}
if (is_constant_value) {
if (!is_type_constant_type(type)) {
gbString str = type_to_string(type);
error(params[i], "Invalid constant type, %s", str);
gb_string_free(str);
}
bool poly_const = true;
if (operands != nullptr) {
poly_const = false;
if (variables.count < operands->count) {
Operand op = (*operands)[variables.count];
if (op.mode != Addressing_Constant) {
error(op.expr, "Expected a constant parameter value");
} else {
value = op.value;
}
}
}
param = make_entity_const_param(c->allocator, scope, name->Ident.token, type, value, poly_const);
} else {
param = make_entity_param(c->allocator, scope, name->Ident.token, type, is_using, false);
param->Variable.default_value = value;
param->Variable.default_is_nil = default_is_nil;
param->Variable.default_is_location = default_is_location;
}
param = make_entity_param(c->allocator, scope, name->Ident.token, type, is_using, false);
param->Variable.default_value = value;
param->Variable.default_is_nil = default_is_nil;
param->Variable.default_is_location = default_is_location;
}
if (p->flags&FieldFlag_no_alias) {
param->flags |= EntityFlag_NoAlias;

View File

@@ -7175,8 +7175,8 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
Type *parent_type = ir_type(parent);
bool is_parent_ptr = is_type_pointer(ir_type(parent));
SwitchTypeKind switch_type_kind = check_valid_type_switch_type(ir_type(parent));
GB_ASSERT(switch_type_kind != SwitchType_Invalid);
SwitchKind switch_kind = check_valid_type_switch_type(ir_type(parent));
GB_ASSERT(switch_kind != Switch_Invalid);
irValue *parent_value = parent;
@@ -7187,7 +7187,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
irValue *tag_index = nullptr;
irValue *union_data = nullptr;
if (switch_type_kind == SwitchType_Union) {
if (switch_kind == Switch_Union) {
ir_emit_comment(proc, str_lit("get union's tag"));
tag_index = ir_emit_load(proc, ir_emit_union_tag_ptr(proc, parent_ptr));
union_data = ir_emit_conv(proc, parent_ptr, t_rawptr);
@@ -7220,11 +7220,11 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
next = ir_new_block(proc, nullptr, "typeswitch.next");
case_type = type_of_expr(proc->module->info, cc->list[type_index]);
irValue *cond = nullptr;
if (switch_type_kind == SwitchType_Union) {
if (switch_kind == Switch_Union) {
Type *ut = base_type(type_deref(parent_type));
irValue *variant_tag = ir_const_union_tag(proc->module->allocator, ut, case_type);
cond = ir_emit_comp(proc, Token_CmpEq, tag_index, variant_tag);
} else if (switch_type_kind == SwitchType_Any) {
} else if (switch_kind == Switch_Any) {
irValue *any_ti = ir_emit_load(proc, ir_emit_struct_ep(proc, parent_ptr, 1));
irValue *case_ti = ir_type_info(proc, case_type);
cond = ir_emit_comp(proc, Token_CmpEq, any_ti, case_ti);
@@ -7250,9 +7250,9 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
}
GB_ASSERT_MSG(is_type_pointer(ct), "%s", type_to_string(ct));
irValue *data = nullptr;
if (switch_type_kind == SwitchType_Union) {
if (switch_kind == Switch_Union) {
data = union_data;
} else if (switch_type_kind == SwitchType_Any) {
} else if (switch_kind == Switch_Any) {
irValue *any_data = ir_emit_load(proc, ir_emit_struct_ep(proc, parent_ptr, 0));
data = any_data;
}

View File

@@ -126,9 +126,8 @@ 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_const,
FieldFlag_Signature = FieldFlag_ellipsis|FieldFlag_using|FieldFlag_no_alias|FieldFlag_c_vararg,
FieldFlag_Struct = FieldFlag_using,
};
@@ -3292,10 +3291,6 @@ AstNode *parse_proc_type(AstFile *f, Token proc_token) {
is_generic = true;
break;
}
if (f->flags&FieldFlag_const) {
is_generic = true;
break;
}
}
@@ -3340,7 +3335,6 @@ enum FieldPrefixKind {
FieldPrefix_using,
FieldPrefix_no_alias,
FieldPrefix_c_var_arg,
FieldPrefix_const,
};
FieldPrefixKind is_token_field_prefix(AstFile *f) {
@@ -3359,8 +3353,6 @@ FieldPrefixKind is_token_field_prefix(AstFile *f) {
return FieldPrefix_no_alias;
} else if (f->curr_token.string == "c_vararg") {
return FieldPrefix_c_var_arg;
} else if (f->curr_token.string == "const") {
return FieldPrefix_const;
}
break;
}
@@ -3374,7 +3366,6 @@ 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);
@@ -3391,20 +3382,17 @@ u32 parse_field_prefixes(AstFile *f) {
case FieldPrefix_using: using_count += 1; advance_token(f); break;
case FieldPrefix_no_alias: no_alias_count += 1; advance_token(f); break;
case FieldPrefix_c_var_arg: 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 '#const' 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;
}
@@ -3426,10 +3414,6 @@ 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;
}

View File

@@ -1,221 +0,0 @@
gb_inline void print_indent(isize indent) {
while (indent --> 0)
gb_printf(" ");
}
void print_ast(AstNode *node, isize indent) {
if (node == nullptr)
return;
switch (node->kind) {
case AstNode_BasicLit:
print_indent(indent);
print_token(node->BasicLit);
break;
case AstNode_Ident:
print_indent(indent);
print_token(node->Ident);
break;
case AstNode_ProcLit:
print_indent(indent);
gb_printf("(proc lit)\n");
print_ast(node->ProcLit.type, indent+1);
print_ast(node->ProcLit.body, indent+1);
break;
case AstNode_CompoundLit:
print_indent(indent);
gb_printf("(compound lit)\n");
print_ast(node->CompoundLit.type, indent+1);
for_array(i, node->CompoundLit.elems) {
print_ast(node->CompoundLit.elems[i], indent+1);
}
break;
case AstNode_TagExpr:
print_indent(indent);
gb_printf("(tag)\n");
print_indent(indent+1);
print_token(node->TagExpr.name);
print_ast(node->TagExpr.expr, indent+1);
break;
case AstNode_UnaryExpr:
print_indent(indent);
print_token(node->UnaryExpr.op);
print_ast(node->UnaryExpr.expr, indent+1);
break;
case AstNode_BinaryExpr:
print_indent(indent);
print_token(node->BinaryExpr.op);
print_ast(node->BinaryExpr.left, indent+1);
print_ast(node->BinaryExpr.right, indent+1);
break;
case AstNode_CallExpr:
print_indent(indent);
gb_printf("(call)\n");
print_ast(node->CallExpr.proc, indent+1);
for_array(i, node->CallExpr.args) {
print_ast(node->CallExpr.args[i], indent+1);
}
break;
case AstNode_SelectorExpr:
print_indent(indent);
gb_printf(".\n");
print_ast(node->SelectorExpr.expr, indent+1);
print_ast(node->SelectorExpr.selector, indent+1);
break;
case AstNode_IndexExpr:
print_indent(indent);
gb_printf("([])\n");
print_ast(node->IndexExpr.expr, indent+1);
print_ast(node->IndexExpr.index, indent+1);
break;
case AstNode_DerefExpr:
print_indent(indent);
gb_printf("(deref)\n");
print_ast(node->DerefExpr.expr, indent+1);
break;
case AstNode_ExprStmt:
print_ast(node->ExprStmt.expr, indent);
break;
case AstNode_IncDecStmt:
print_indent(indent);
print_token(node->IncDecStmt.op);
print_ast(node->IncDecStmt.expr, indent+1);
break;
case AstNode_AssignStmt:
print_indent(indent);
print_token(node->AssignStmt.op);
for_array(i, node->AssignStmt.lhs) {
print_ast(node->AssignStmt.lhs[i], indent+1);
}
for_array(i, node->AssignStmt.rhs) {
print_ast(node->AssignStmt.rhs[i], indent+1);
}
break;
case AstNode_BlockStmt:
print_indent(indent);
gb_printf("(block)\n");
for_array(i, node->BlockStmt.stmts) {
print_ast(node->BlockStmt.stmts[i], indent+1);
}
break;
case AstNode_IfStmt:
print_indent(indent);
gb_printf("(if)\n");
print_ast(node->IfStmt.cond, indent+1);
print_ast(node->IfStmt.body, indent+1);
if (node->IfStmt.else_stmt) {
print_indent(indent);
gb_printf("(else)\n");
print_ast(node->IfStmt.else_stmt, indent+1);
}
break;
case AstNode_ReturnStmt:
print_indent(indent);
gb_printf("(return)\n");
for_array(i, node->ReturnStmt.results) {
print_ast(node->ReturnStmt.results[i], indent+1);
}
break;
case AstNode_ForStmt:
print_indent(indent);
gb_printf("(for)\n");
print_ast(node->ForStmt.init, indent+1);
print_ast(node->ForStmt.cond, indent+1);
print_ast(node->ForStmt.post, indent+1);
print_ast(node->ForStmt.body, indent+1);
break;
case AstNode_DeferStmt:
print_indent(indent);
gb_printf("(defer)\n");
print_ast(node->DeferStmt.stmt, indent+1);
break;
case AstNode_VarDecl:
print_indent(indent);
gb_printf("(decl:var)\n");
for_array(i, node->VarDecl.names) {
print_ast(node->VarDecl.names[i], indent+1);
}
print_ast(node->VarDecl.type, indent+1);
for_array(i, node->VarDecl.values) {
print_ast(node->VarDecl.values[i], indent+1);
}
break;
case AstNode_ConstDecl:
print_indent(indent);
gb_printf("(decl:const)\n");
for_array(i, node->VarDecl.names) {
print_ast(node->VarDecl.names[i], indent+1);
}
print_ast(node->VarDecl.type, indent+1);
for_array(i, node->VarDecl.values) {
print_ast(node->VarDecl.values[i], indent+1);
}
break;
case AstNode_ProcDecl:
print_indent(indent);
gb_printf("(decl:proc)\n");
print_ast(node->ProcDecl.type, indent+1);
print_ast(node->ProcDecl.body, indent+1);
break;
case AstNode_TypeDecl:
print_indent(indent);
gb_printf("(type)\n");
print_ast(node->TypeDecl.name, indent+1);
print_ast(node->TypeDecl.type, indent+1);
break;
case AstNode_ProcType:
print_indent(indent);
gb_printf("(type:proc)(%td -> %td)\n", node->ProcType.params.count, node->ProcType.results.count);
for_array(i, node->ProcType.params) {
print_ast(node->ProcType.params[i], indent+1);
}
if (node->ProcType.results.count > 0) {
print_indent(indent+1);
gb_printf("->\n");
for_array(i, node->ProcType.results) {
print_ast(node->ProcType.results[i], indent+1);
}
}
break;
case AstNode_Parameter:
for_array(i, node->Parameter.names) {
print_ast(node->Parameter.names[i], indent+1);
}
print_ast(node->Parameter.type, indent);
break;
case AstNode_PointerType:
print_indent(indent);
print_token(node->PointerType.token);
print_ast(node->PointerType.type, indent+1);
break;
case AstNode_ArrayType:
print_indent(indent);
gb_printf("[]\n");
print_ast(node->ArrayType.count, indent+1);
print_ast(node->ArrayType.elem, indent+1);
break;
case AstNode_StructType:
print_indent(indent);
gb_printf("(struct)\n");
for_array(i, node->StructType.decls) {
print_ast(node->StructType.decls[i], indent+1);
}
break;
}
// if (node->next)
// print_ast(node->next, indent);
}

View File

@@ -55,8 +55,6 @@ TOKEN_KIND(Token__AssignOpEnd, "_AssignOpEnd"), \
TOKEN_KIND(Token_ArrowRight, "->"), \
TOKEN_KIND(Token_ArrowLeft, "<-"), \
TOKEN_KIND(Token_DoubleArrowRight, "=>"), \
/* TOKEN_KIND(Token_Inc, "++"), */ \
/* TOKEN_KIND(Token_Dec, "--"), */ \
TOKEN_KIND(Token_Undef, "---"), \
\
TOKEN_KIND(Token__ComparisonBegin, "_ComparisonBegin"), \