aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-01-28 16:45:17 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-01-28 16:45:17 -0700
commitbb4f7835286f047fc596715101ee0318c8e7f924 (patch)
tree4860d7b895c592e11ca32f451a256e4720d956ba /src/analyze.cpp
parent13220ccb51b7d2cf7b8d72a662eece95784116c3 (diff)
downloadzig-bb4f7835286f047fc596715101ee0318c8e7f924.tar.gz
zig-bb4f7835286f047fc596715101ee0318c8e7f924.zip
ability to refer to member function directly
See #14
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index abc161ce72..cd743710e2 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -27,6 +27,7 @@ static TypeTableEntry *analyze_error_literal_expr(CodeGen *g, ImportTableEntry *
static TypeTableEntry *analyze_block_expr(CodeGen *g, ImportTableEntry *import, BlockContext *context,
TypeTableEntry *expected_type, AstNode *node);
static TypeTableEntry *resolve_expr_const_val_as_void(CodeGen *g, AstNode *node);
+static TypeTableEntry *resolve_expr_const_val_as_fn(CodeGen *g, AstNode *node, FnTableEntry *fn);
static void detect_top_level_decl_deps(CodeGen *g, ImportTableEntry *import, AstNode *node);
static AstNode *first_executing_node(AstNode *node) {
@@ -1895,13 +1896,23 @@ static TypeTableEntry *analyze_field_access_expr(CodeGen *g, ImportTableEntry *i
return g->builtin_types.entry_invalid;
}
} else if (struct_type->id == TypeTableEntryIdMetaType) {
- TypeTableEntry *enum_type = resolve_type(g, struct_expr_node);
+ TypeTableEntry *child_type = resolve_type(g, struct_expr_node);
- if (enum_type->id == TypeTableEntryIdInvalid) {
+ if (child_type->id == TypeTableEntryIdInvalid) {
return g->builtin_types.entry_invalid;
- } else if (enum_type->id == TypeTableEntryIdEnum) {
- return analyze_enum_value_expr(g, import, context, node, nullptr, enum_type, field_name);
- } else if (enum_type->id == TypeTableEntryIdPureError) {
+ } else if (child_type->id == TypeTableEntryIdEnum) {
+ return analyze_enum_value_expr(g, import, context, node, nullptr, child_type, field_name);
+ } else if (child_type->id == TypeTableEntryIdStruct) {
+ auto entry = child_type->data.structure.fn_table.maybe_get(field_name);
+ if (entry) {
+ return resolve_expr_const_val_as_fn(g, node, entry->value);
+ } else {
+ add_node_error(g, node,
+ buf_sprintf("struct '%s' has no function called '%s'",
+ buf_ptr(&child_type->name), buf_ptr(field_name)));
+ return g->builtin_types.entry_invalid;
+ }
+ } else if (child_type->id == TypeTableEntryIdPureError) {
return analyze_error_literal_expr(g, import, context, node, field_name);
} else {
add_node_error(g, node,