Add unselector_expr

This commit is contained in:
gingerBill
2018-03-04 11:06:59 +00:00
parent 584dffea14
commit 105de7705a
6 changed files with 23 additions and 22 deletions

View File

@@ -1353,10 +1353,7 @@ void check_is_expressible(Checker *c, Operand *o, Type *type) {
bool check_is_not_addressable(Checker *c, Operand *o) {
if (o->mode == Addressing_OptionalOk) {
AstNode *expr = unparen_expr(o->expr);
while (expr->kind == AstNode_SelectorExpr) {
expr = expr->SelectorExpr.selector;
}
AstNode *expr = unselector_expr(o->expr);
if (expr->kind != AstNode_TypeAssertion) {
return true;
}

View File

@@ -714,10 +714,7 @@ Entity *entity_of_node(CheckerInfo *i, AstNode *expr) {
return entity_of_ident(i, expr);
case_end;
case_ast_node(se, SelectorExpr, expr);
AstNode *s = se->selector;
while (s->kind == AstNode_SelectorExpr) {
s = s->SelectorExpr.selector;
}
AstNode *s = unselector_expr(se->selector);
if (s->kind == AstNode_Ident) {
return entity_of_ident(i, s);
}
@@ -3113,10 +3110,10 @@ void check_parsed_files(Checker *c) {
TIME_SECTION("add type information");
// Add "Basic" type information
for (isize i = 0; i < gb_count_of(basic_types)-1; i++) {
for (isize i = 0; i < Basic_COUNT; i++) {
Type *t = &basic_types[i];
if (t->Basic.size > 0 &&
t->Basic.kind != Basic_llvm_bool) {
(t->Basic.flags & BasicFlag_LLVM) == 0) {
add_type_info_type(c, t);
}
}
@@ -3133,7 +3130,7 @@ void check_parsed_files(Checker *c) {
}
}
TIME_SECTION("check entry poiny");
TIME_SECTION("check entry point");
if (!build_context.is_dll) {
Scope *s = c->info.init_scope;
GB_ASSERT(s != nullptr);

View File

@@ -30,11 +30,8 @@ struct TypeAndValue {
// ExprInfo stores information used for "untyped" expressions
struct ExprInfo {
AddressingMode mode;
Type * type; // Type_Basic
ExactValue value;
bool is_lhs; // Debug info
struct ExprInfo : TypeAndValue {
bool is_lhs; // Debug info
};
gb_inline ExprInfo make_expr_info(AddressingMode mode, Type *type, ExactValue value, bool is_lhs) {

View File

@@ -4164,11 +4164,8 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
String procedure = proc->entity->token.string;
TokenPos pos = ast_node_token(ce->proc).pos;
if (ce->args.count > 0) {
AstNode *ident = ce->args[0];;
while (ident->kind == AstNode_SelectorExpr) {
ident = ident->SelectorExpr.selector;
}
AstNode *ident = unselector_expr(ce->args[0]);
GB_ASSERT(ident->kind == AstNode_Ident);
Entity *e = entity_of_ident(proc->module->info, ident);
GB_ASSERT(e != nullptr);

View File

@@ -1410,6 +1410,17 @@ AstNode *unparen_expr(AstNode *node) {
}
}
AstNode *unselector_expr(AstNode *node) {
node = unparen_expr(node);
if (node == nullptr) {
return nullptr;
}
while (node->kind == AstNode_SelectorExpr) {
node = node->SelectorExpr.selector;
}
return node;
}
AstNode *parse_value(AstFile *f);
Array<AstNode *> parse_element_list(AstFile *f) {

View File

@@ -63,6 +63,8 @@ enum BasicFlag {
BasicFlag_Rune = GB_BIT(7),
BasicFlag_Untyped = GB_BIT(8),
BasicFlag_LLVM = GB_BIT(10),
BasicFlag_Numeric = BasicFlag_Integer | BasicFlag_Float | BasicFlag_Complex,
BasicFlag_Ordered = BasicFlag_Integer | BasicFlag_Float | BasicFlag_String | BasicFlag_Pointer | BasicFlag_Rune,
BasicFlag_ConstantType = BasicFlag_Boolean | BasicFlag_Numeric | BasicFlag_String | BasicFlag_Pointer | BasicFlag_Rune,
@@ -244,7 +246,7 @@ void selection_add_index(Selection *s, isize index) {
gb_global Type basic_types[] = {
{Type_Basic, {Basic_Invalid, 0, 0, STR_LIT("invalid type")}},
{Type_Basic, {Basic_llvm_bool, BasicFlag_Boolean, 1, STR_LIT("llvm bool")}},
{Type_Basic, {Basic_llvm_bool, BasicFlag_Boolean | BasicFlag_LLVM, 1, STR_LIT("llvm bool")}},
{Type_Basic, {Basic_bool, BasicFlag_Boolean, 1, STR_LIT("bool")}},
{Type_Basic, {Basic_b8, BasicFlag_Boolean, 1, STR_LIT("b8")}},