Bugfixes, remove the cast_ptr function

This commit is contained in:
Nathan Braswell
2016-04-19 06:04:22 -04:00
parent cf46fb13af
commit 04d2af4168
7 changed files with 29 additions and 57 deletions

View File

@@ -586,11 +586,9 @@ obj c_generator (Object) {
var declaration = ast_declaration_statement_ptr(temp_ident, null<ast_node>())
// have to pass false to the declaration generator, so can't do it through generate_statement
to_ret.pre = generate_declaration_statement(declaration, enclosing_object, enclosing_func, defer_stack, false).one_string() + ";\n"
if ((function_return_type->is_object() || temp_ident_type->is_object()) &&
( (!function_return_type->is_ref && !function_return_type->equality(temp_ident_type, false)) ||
(function_return_type->is_ref && !function_return_type->equality(temp_ident_type->clone_with_decreased_indirection(), false)) ) )
if ((function_return_type->is_object() || return_value_type->is_object()) && !function_return_type->equality(return_value_type, false))
// note the clone with decreased indirection because of the clone with increased indirection above
error(string("return type does not match: ") + function_return_type->to_string() + ", " + temp_ident_type->to_string());
error(string("return type does not match: ") + function_return_type->to_string() + ", " + return_value_type->to_string());
if (!function_return_type->is_ref && return_value_type->indirection == 0 && (return_value_type->is_adt() || (return_value_type->is_object() && has_method(return_value_type->type_def, "copy_construct", vector(return_value_type->clone_with_indirection(1)))))) {
to_ret.pre += generate_statement(ast_statement_ptr(make_method_call(temp_ident, "copy_construct", vector(make_operator_call("&", vector(return_value))))), enclosing_object, enclosing_func, defer_stack).one_string()
} else {

View File

@@ -1,28 +0,0 @@
fun to_char<T>(in: T) : char {
var out:char
__if_comp__ __C__ {
simple_passthrough(in = in: out = out:) """
char out = (char) in;
"""
}
return out;
}
fun to_int<T>(in: T) : int {
var out:int
__if_comp__ __C__ {
simple_passthrough(in = in: out = out:) """
int out = (int) in;
"""
}
return out;
}
fun cast_ptr<T,U>(in: T):U {
var out:U
simple_passthrough(in:out:) """
void* out = in;
"""
return out
}

View File

@@ -4,7 +4,6 @@ import string
import mem
import set
import util
import conversions
import serialize
fun regex(in: *char):regex {
@@ -24,7 +23,7 @@ obj regexState (Object) {
return this
}
fun construct(): *regexState {
return construct(conversions::to_char(0))
return construct((0) cast char)
}
fun copy_construct(old:*regexState): void {
character = old->character
@@ -58,7 +57,7 @@ obj regex (Object, Serializable) {
var beginningAndEnd = compile(regexStringIn)
// init our begin, and the end state as the next state of each end
begin = beginningAndEnd.first
var end = mem::new<regexState>()->construct(conversions::to_char(1))
var end = mem::new<regexState>()->construct((1) cast char)
beginningAndEnd.second.for_each(fun(it: *regexState): void { it->next_states.add(end); })
return this
}

View File

@@ -1,5 +1,4 @@
import vector
import conversions
import mem
import util
@@ -8,7 +7,7 @@ fun serialize<T(Serializable)>(it: T): vector::vector<char> {
}
fun serialize<T>(it: T): vector::vector<char> {
var char_data = conversions::cast_ptr<*T,*char>(&it)
var char_data = (&it) cast *char
var toRet = vector::vector<char>()
for (var i = 0; i < mem::sizeof<T>(); i++;)
toRet.add(char_data[i])
@@ -20,7 +19,7 @@ fun unserialize<T>(it: ref vector::vector<char>): T {
return unserialize<T>(it, 0).first
}
fun unserialize<T>(it: ref vector::vector<char>, pos: int): util::pair<T,int> {
return util::make_pair(*conversions::cast_ptr<*char,*T>(it.getBackingMemory()+pos), pos + mem::sizeof<T>())
return util::make_pair(*(it.getBackingMemory()+pos) cast *T, pos + mem::sizeof<T>())
}
fun unserialize<T(Serializable)>(it: ref vector::vector<char>, pos: int): util::pair<T,int> {
var toRet: T