aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2015-12-09 01:03:04 -0700
committerAndrew Kelley <superjoe30@gmail.com>2015-12-09 01:03:04 -0700
commitdfda85e870df1b0620c418940db3b946fdd3d620 (patch)
tree94d4d7e158f62ee2cd153b002165bc3ef7aa7c47 /src/analyze.cpp
parent4eff5f114b463ddd887665129f2e1d29b0f13b7f (diff)
downloadzig-dfda85e870df1b0620c418940db3b946fdd3d620.tar.gz
zig-dfda85e870df1b0620c418940db3b946fdd3d620.zip
ability to call external variadic functions
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 4436457b01..e4c3b2ca7b 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -163,9 +163,12 @@ static TypeTableEntry *resolve_type(CodeGen *g, AstNode *node) {
{
resolve_type(g, node->data.type.child_type);
TypeTableEntry *child_type = node->data.type.child_type->codegen_node->data.type_node.entry;
+ assert(child_type);
if (child_type == g->builtin_types.entry_unreachable) {
add_node_error(g, node,
buf_create_from_str("pointer to unreachable not allowed"));
+ } else if (child_type->id == TypeTableEntryIdInvalid) {
+ return child_type;
}
type_node->entry = get_pointer_to_type(g, child_type, node->data.type.is_const);
return type_node->entry;
@@ -312,6 +315,10 @@ static void preview_function_declarations(CodeGen *g, ImportTableEntry *import,
skip = true;
}
}
+ if (proto_node->data.fn_proto.is_var_args) {
+ add_node_error(g, node,
+ buf_sprintf("variadic arguments only allowed in extern functions"));
+ }
if (!skip) {
FnTableEntry *fn_table_entry = allocate<FnTableEntry>(1);
fn_table_entry->import_entry = import;
@@ -743,7 +750,13 @@ static TypeTableEntry * analyze_expression(CodeGen *g, ImportTableEntry *import,
// count parameters
int expected_param_count = fn_proto->params.length;
int actual_param_count = node->data.fn_call_expr.params.length;
- if (expected_param_count != actual_param_count) {
+ if (fn_proto->is_var_args) {
+ if (actual_param_count < expected_param_count) {
+ add_node_error(g, node,
+ buf_sprintf("wrong number of arguments. Expected at least %d, got %d.",
+ expected_param_count, actual_param_count));
+ }
+ } else if (expected_param_count != actual_param_count) {
add_node_error(g, node,
buf_sprintf("wrong number of arguments. Expected %d, got %d.",
expected_param_count, actual_param_count));