Commit 3000b0d6 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter
Browse files

don't crash on already resolved type references support typeof expression

2006-10-24  Jürg Billeter  <j@bitron.ch>

	* vala/valasymbolresolver.vala: don't crash on already resolved type
	  references
	* vala/valasemanticanalyzer.vala: support typeof expression
	* vala/valacodegenerator.vala: improve support for null-terminated
	  arrays
	* vala/valainterfacewriter.vala: don't write type arguments for arrays

svn path=/trunk/; revision=146
parent 6b5baca1
2006-10-24 Jürg Billeter <j@bitron.ch>
* vala/valasymbolresolver.vala: don't crash on already resolved type
references
* vala/valasemanticanalyzer.vala: support typeof expression
* vala/valacodegenerator.vala: improve support for null-terminated
arrays
* vala/valainterfacewriter.vala: don't write type arguments for arrays
2006-10-08 Jürg Billeter <j@bitron.ch>
* vala/parser.y: support enum values
......
......@@ -1701,6 +1701,22 @@ public class Vala.CodeGenerator : CodeVisitor {
// FIXME: use C cast if debugging disabled
rhs = new InstanceCast (rhs, decl.type_reference.data_type);
}
if (decl.type_reference.data_type is Array) {
var ccomma = new CCodeCommaExpression ();
var temp_decl = get_temp_variable_declarator (decl.type_reference);
temp_vars.prepend (temp_decl);
ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (temp_decl.name), rhs));
var lhs_array_len = new CCodeIdentifier (get_array_length_cname (decl.name, 1));
var rhs_array_len = get_array_length_cexpression (decl.initializer, 1);
ccomma.append_expression (new CCodeAssignment (lhs_array_len, rhs_array_len));
ccomma.append_expression (new CCodeIdentifier (temp_decl.name));
rhs = ccomma;
}
} else if (decl.type_reference.data_type != null && decl.type_reference.data_type.is_reference_type ()) {
rhs = new CCodeConstant ("NULL");
}
......@@ -2048,7 +2064,15 @@ public class Vala.CodeGenerator : CodeVisitor {
cbody.add_statement (stmt.body.ccodenode);
var ccond = new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, new CCodeIdentifier (it_name), array_len);
var ccond_ind1 = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, array_len, new CCodeConstant ("-1"));
var ccond_ind2 = new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, new CCodeIdentifier (it_name), array_len);
var ccond_ind = new CCodeBinaryExpression (CCodeBinaryOperator.AND, ccond_ind1, ccond_ind2);
var ccond_term1 = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, array_len, new CCodeConstant ("-1"));
var ccond_term2 = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, new CCodeElementAccess ((CCodeExpression) stmt.collection.ccodenode, new CCodeIdentifier (it_name)), new CCodeConstant ("NULL"));
var ccond_term = new CCodeBinaryExpression (CCodeBinaryOperator.AND, ccond_term1, ccond_term2);
var ccond = new CCodeBinaryExpression (CCodeBinaryOperator.OR, new CCodeParenthesizedExpression (ccond_ind), new CCodeParenthesizedExpression (ccond_term));
var cfor = new CCodeForStatement (ccond, cbody);
cfor.add_initializer (new CCodeAssignment (new CCodeIdentifier (it_name), new CCodeConstant ("0")));
......
......@@ -242,7 +242,7 @@ public class Vala.InterfaceWriter : CodeVisitor {
write_string (f.type_reference.data_type.symbol.get_full_name ());
var type_args = f.type_reference.get_type_arguments ();
if (type_args != null) {
if (!(f.type_reference.data_type is Array) && type_args != null) {
write_string ("<");
foreach (TypeReference type_arg in type_args) {
if (!type_arg.takes_ownership) {
......@@ -289,7 +289,7 @@ public class Vala.InterfaceWriter : CodeVisitor {
write_string (param.type_reference.data_type.symbol.get_full_name ());
var type_args = param.type_reference.get_type_arguments ();
if (type_args != null) {
if (!(param.type_reference.data_type is Array) && type_args != null) {
write_string ("<");
foreach (TypeReference type_arg in type_args) {
if (type_arg.takes_ownership) {
......@@ -436,7 +436,7 @@ public class Vala.InterfaceWriter : CodeVisitor {
write_string (prop.type_reference.data_type.symbol.get_full_name ());
var type_args = prop.type_reference.get_type_arguments ();
if (type_args != null) {
if (!(prop.type_reference.data_type is Array) && type_args != null) {
write_string ("<");
foreach (TypeReference type_arg in type_args) {
if (!type_arg.takes_ownership) {
......
......@@ -43,6 +43,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
TypeReference bool_type;
TypeReference string_type;
TypeReference int_type;
TypeReference type_type;
DataType pointer_type;
DataType initially_unowned_type;
......@@ -74,6 +75,9 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
var glib_ns = root_symbol.lookup ("GLib");
initially_unowned_type = (DataType) glib_ns.lookup ("InitiallyUnowned").node;
type_type = new TypeReference ();
type_type.data_type = (DataType) glib_ns.lookup ("Type").node;
current_symbol = root_symbol;
context.accept (this);
......@@ -1131,6 +1135,10 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
check_arguments (expr, m.symbol, m.get_parameters (), expr.get_argument_list ());
}
}
public override void visit_typeof_expression (TypeofExpression! expr) {
expr.static_type = type_type;
}
private bool is_numeric_type (TypeReference! type) {
if (!(type.data_type is Struct)) {
......
......@@ -130,7 +130,7 @@ public class Vala.SymbolResolver : CodeVisitor {
}
public override void visit_type_reference (TypeReference! type) {
if (type.type_name == "void") {
if (type.type_name == null || type.type_name == "void") {
return;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment