Commit b9895f6d authored by Raffaele Sandrini's avatar Raffaele Sandrini Committed by Raffaele Sandrini

adapt visit initializer and visit array creation to external visitor check

2007-08-16  Raffaele Sandrini  <raffaele@sandrini.ch>

	* gobject/valacodegenerator.vala, vala/valacodevisitor.vala,
	  vala/valasemanticanalyzer.vala, vala/valasymbolresolver.vala:
	  adapt visit initializer and visit array creation to external visitor
	* vala/valamemorymanager.vala: check initializers of array creation
	  expressions for missing ref
	* vala/valaarraycreationexpression.vala, vala/valainitializerlist.vala:
	  change to external visitor

svn path=/trunk/; revision=469
parent 444d84be
2007-08-16 Raffaele Sandrini <raffaele@sandrini.ch>
* gobject/valacodegenerator.vala, vala/valacodevisitor.vala,
vala/valasemanticanalyzer.vala, vala/valasymbolresolver.vala:
adapt visit initializer and visit array creation to external visitor
* vala/valamemorymanager.vala: check initializers of array creation
expressions for missing ref
* vala/valaarraycreationexpression.vala, vala/valainitializerlist.vala:
change to external visitor
2007-08-15 Raffaele Sandrini <raffaele@sandrini.ch>
* vapi/Makefile.am: create gee-1.0 vapi; this makes it possible to
......
......@@ -870,7 +870,9 @@ public class Vala.CodeGenerator : CodeVisitor {
decl.active = true;
}
public override void visit_end_initializer_list (InitializerList! list) {
public override void visit_initializer_list (InitializerList! list) {
list.accept_children (this);
if (list.expected_type != null && list.expected_type.data_type is Array) {
/* TODO */
} else {
......@@ -1850,7 +1852,9 @@ public class Vala.CodeGenerator : CodeVisitor {
*
* @param expr an array creation expression
*/
public override void visit_end_array_creation_expression (ArrayCreationExpression! expr) {
public override void visit_array_creation_expression (ArrayCreationExpression! expr) {
expr.accept_children (this);
var gnew = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
gnew.add_argument (new CCodeIdentifier (expr.element_type.get_cname ()));
bool first = true;
......
......@@ -64,24 +64,22 @@ public class Vala.ArrayCreationExpression : Expression {
public ArrayCreationExpression (construct TypeReference element_type, construct int rank, construct InitializerList initializer_list, construct SourceReference source_reference) {
}
public override void accept (CodeVisitor! visitor) {
public override void accept_children (CodeVisitor! visitor) {
if (element_type != null) {
element_type.accept (visitor);
}
if (sizes != null) {
foreach (Expression e in sizes) {
e.accept (visitor);
}
foreach (Expression e in sizes) {
e.accept (visitor);
}
visitor.visit_begin_array_creation_expression (this);
if (initializer_list != null) {
initializer_list.accept (visitor);
}
visitor.visit_end_array_creation_expression (this);
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_array_creation_expression (this);
}
}
......@@ -264,15 +264,7 @@ public abstract class Vala.CodeVisitor {
*
* @param list an initializer list
*/
public virtual void visit_begin_initializer_list (InitializerList! list) {
}
/**
* Visit operation called for initializer lists
*
* @param list an initializer list
*/
public virtual void visit_end_initializer_list (InitializerList! list) {
public virtual void visit_initializer_list (InitializerList! list) {
}
/**
......@@ -418,21 +410,13 @@ public abstract class Vala.CodeVisitor {
*/
public virtual void visit_lock_statement (LockStatement! stmt) {
}
/**
* Visit operations called for array creation expresions.
*
* @param expr an array creation expression
*/
public virtual void visit_begin_array_creation_expression (ArrayCreationExpression! expr) {
}
/**
* Visit operations called for array creation expresions.
*
* @param expr an array creation expression
*/
public virtual void visit_end_array_creation_expression (ArrayCreationExpression! expr) {
public virtual void visit_array_creation_expression (ArrayCreationExpression! expr) {
}
/**
......
/* valainitializerlist.vala
*
* Copyright (C) 2006-2007 Jürg Billeter
* Copyright (C) 2006-2007 Jürg Billeter, Raffaele Sandrini
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -18,6 +18,7 @@
*
* Author:
* Jürg Billeter <j@bitron.ch>
* Raffaele Sandrini <raffaele@sandrini.ch>
*/
using GLib;
......@@ -55,14 +56,14 @@ public class Vala.InitializerList : Expression {
*/
public InitializerList (construct SourceReference source_reference) {
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_begin_initializer_list (this);
public override void accept_children (CodeVisitor! visitor) {
foreach (Expression expr in initializers) {
expr.accept (visitor);
}
visitor.visit_end_initializer_list (this);
}
public override void accept (CodeVisitor! visitor) {
visitor.visit_initializer_list (this);
}
}
......@@ -134,6 +134,10 @@ public class Vala.MemoryManager : CodeVisitor {
}
}
public override void visit_initializer_list (InitializerList! list) {
list.accept_children (this);
}
public override void visit_expression_statement (ExpressionStatement! stmt) {
visit_possibly_leaked_expression (stmt.expression);
}
......@@ -167,6 +171,14 @@ public class Vala.MemoryManager : CodeVisitor {
clause.accept_children (this);
}
public override void visit_array_creation_expression (ArrayCreationExpression! e) {
if (e.initializer_list != null) {
foreach (Expression init in e.initializer_list.get_initializers ()) {
visit_possibly_missing_copy_expression (init);
}
}
}
public override void visit_member_access (MemberAccess! expr) {
if (expr.inner != null) {
visit_possibly_leaked_expression (expr.inner);
......
......@@ -750,7 +750,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
*
* @param list an initializer list
*/
public override void visit_begin_initializer_list (InitializerList! list) {
public override void visit_initializer_list (InitializerList! list) {
if (list.expected_type != null && list.expected_type.data_type is Array) {
/* initializer is used as array initializer */
Array edt = (Array)list.expected_type.data_type;
......@@ -768,14 +768,9 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
e.expected_type = child_type.copy ();
}
}
}
/**
* Visit operation called for initializer lists
*
* @param list an initializer list
*/
public override void visit_end_initializer_list (InitializerList! list) {
list.accept_children (this);
if (list.expected_type != null && list.expected_type.data_type is Array) {
Array edt = (Array)list.expected_type.data_type;
var inits = list.get_initializers ();
......@@ -993,39 +988,45 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
((Lockable) stmt.resource.symbol_reference).set_lock_used (true);
}
public override void visit_begin_array_creation_expression (ArrayCreationExpression! expr) {
if (expr.initializer_list != null) {
expr.initializer_list.expected_type = expr.element_type.copy ();
expr.initializer_list.expected_type.data_type = expr.initializer_list.expected_type.data_type.get_array (expr.rank);
// FIXME: add element type to type_argument
}
}
/**
* Visit operations called for array creation expresions.
*
* @param expr an array creation expression
*/
public override void visit_end_array_creation_expression (ArrayCreationExpression! expr) {
public override void visit_array_creation_expression (ArrayCreationExpression! expr) {
Collection<Expression> size = expr.get_sizes ();
/* check for errors in the size list */
if (size != null) {
foreach (Expression e in size) {
if (e.static_type == null) {
/* return on previous error */
return;
} else if (!(e.static_type.data_type is Struct) || !((Struct) e.static_type.data_type).is_integer_type ()) {
expr.error = true;
Report.error (e.source_reference, "Expression of integer type expected");
}
}
if (expr.element_type != null) {
expr.element_type.accept (this);
}
foreach (Expression e in size) {
e.accept (this);
}
if (expr.initializer_list != null) {
expr.initializer_list.expected_type = expr.element_type.copy ();
expr.initializer_list.expected_type.data_type = expr.initializer_list.expected_type.data_type.get_array (expr.rank);
// FIXME: add element type to type_argument
expr.initializer_list.accept (this);
}
if (expr.error) {
/* check for errors in the size list */
foreach (Expression e in size) {
if (e.static_type == null) {
/* return on previous error */
return;
} else if (!(e.static_type.data_type is Struct) || !((Struct) e.static_type.data_type).is_integer_type ()) {
expr.error = true;
Report.error (e.source_reference, "Expression of integer type expected");
}
}
if (expr.error) {
return;
}
/* check for wrong elements inside the initializer */
if (expr.initializer_list != null && expr.initializer_list.static_type == null) {
return;
......
/* valasymbolresolver.vala
*
* Copyright (C) 2006-2007 Jürg Billeter
* Copyright (C) 2006-2007 Jürg Billeter, Raffaele Sandrini
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -18,6 +18,7 @@
*
* Author:
* Jürg Billeter <j@bitron.ch>
* Raffaele Sandrini <raffaele@sandrini.ch>
*/
using GLib;
......@@ -290,6 +291,10 @@ public class Vala.SymbolResolver : CodeVisitor {
decl.accept_children (this);
}
public override void visit_initializer_list (InitializerList! list) {
list.accept_children (this);
}
public override void visit_throw_statement (ThrowStatement! stmt) {
stmt.accept_children (this);
}
......@@ -301,4 +306,8 @@ public class Vala.SymbolResolver : CodeVisitor {
public override void visit_catch_clause (CatchClause! clause) {
clause.accept_children (this);
}
public override void visit_array_creation_expression (ArrayCreationExpression! e) {
e.accept_children (this);
}
}
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