Add support for variadic extern functions, as it turns out that you can't just specialize them with declarations. I.e., int a_func(int, ...) is different from int a_func(int, int) even if you only ever call a_func(1,2), etc. This commit is in preperation for moving to correcty variadic extern functions for the c stdlib (like printf, snprintf)

This commit is contained in:
Nathan Braswell
2016-05-19 23:17:32 -07:00
parent ce1afa45f4
commit cfcaff7887
6 changed files with 50 additions and 18 deletions

View File

@@ -285,8 +285,10 @@ obj adt_def (Object) {
return name == other.name && self_type == other.self_type && options == other.options && option_funcs == other.option_funcs && regular_funcs == other.regular_funcs
}
}
fun ast_function_ptr(name: string, type: *type, parameters: vector<*ast_node>, is_extern: bool): *ast_node {
var to_ret.construct(name, type, parameters, is_extern): function
fun ast_function_ptr(name: string, type: *type, parameters: vector<*ast_node>, is_extern: bool): *ast_node
return ast_function_ptr(name, type, parameters, is_extern, false)
fun ast_function_ptr(name: string, type: *type, parameters: vector<*ast_node>, is_extern: bool, is_variadic: bool): *ast_node {
var to_ret.construct(name, type, parameters, is_extern, is_variadic): function
var ptr = new<ast_node>()
ptr->copy_construct(&ast_node::function(to_ret))
return ptr
@@ -305,7 +307,8 @@ obj function (Object) {
var body_statement: *ast_node
var scope: map<string, vector<*ast_node>>
var is_extern: bool
fun construct(name_in: string, type_in: *type, parameters_in: vector<*ast_node>, is_extern_in: bool): *function {
var is_variadic: bool
fun construct(name_in: string, type_in: *type, parameters_in: vector<*ast_node>, is_extern_in: bool, is_variadic_in: bool): *function {
name.copy_construct(&name_in)
parameters.copy_construct(&parameters_in)
closed_variables.construct()
@@ -313,6 +316,7 @@ obj function (Object) {
type = type_in
body_statement = null<ast_node>()
is_extern = is_extern_in
is_variadic = is_variadic_in
return this
}
fun copy_construct(old: *function) {
@@ -323,6 +327,7 @@ obj function (Object) {
closed_variables.copy_construct(&old->closed_variables)
scope.copy_construct(&old->scope)
is_extern = old->is_extern
is_variadic = old->is_variadic
}
fun destruct() {
name.destruct()
@@ -335,7 +340,7 @@ obj function (Object) {
copy_construct(&other)
}
fun operator==(other: ref function): bool {
return name == name && type == other.type && parameters == other.parameters && body_statement == other.body_statement && closed_variables == other.closed_variables && is_extern == other.is_extern
return name == name && type == other.type && parameters == other.parameters && body_statement == other.body_statement && closed_variables == other.closed_variables && is_extern == other.is_extern && is_variadic == other.is_variadic
}
}
fun ast_template_ptr(name: string, syntax_node: *tree<symbol>, template_types: vector<string>, template_type_replacements: map<string, *type>, is_function: bool): *ast_node {