2007-07-13 Jürg Billeter <j@bitron.ch>
+ * vala/valacatchclause.vala, vala/valacodevisitor.vala,
+ vala/valamemorymanager.vala, vala/valasemanticanalyzer.vala,
+ vala/valasymbolbuilder.vala, vala/valasymbolresolver.vala,
+ vala/valathrowstatement.vala, vala/valatrystatement.vala,
+ gobject/valacodegenerator.vala: move iteration of throw statements,
+ try statements, and catch clauses from accept to accept_children
+ method, fixes nested try statements
+ * gobject/valacodegenerator.vala: clear unhandled error instead of
+ returning from the current function
+ * vala/valasemanticanalyzer.vala: generic pointer is compatible with
+ generic pointer
+ * vapi/glib-2.0.vala: add some more default values
+
+2007-07-13 Jürg Billeter <j@bitron.ch>
+
* vala/parser.y, gobject/valacodegenerator.vala: support multi-
dimensional arrays
HashTable<string,bool> c_keywords;
private int next_temp_var_id = 0;
+ private int current_try_id = 0;
private int next_try_id = 0;
private bool in_creation_method = false;
private bool current_method_inner_error = false;
ccritical.add_argument (new CCodeConstant ("__LINE__"));
ccritical.add_argument (new CCodeMemberAccess.pointer (new CCodeIdentifier ("inner_error"), "message"));
cprint_frag.append (new CCodeExpressionStatement (ccritical));
- if (current_return_type != null && current_return_type.data_type != null) {
- cprint_frag.append (new CCodeReturnStatement (default_value_for_type (current_return_type.data_type)));
- } else {
- cprint_frag.append (new CCodeReturnStatement ());
- }
+ var cclear = new CCodeFunctionCall (new CCodeIdentifier ("g_clear_error"));
+ cclear.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("inner_error")));
+ cprint_frag.append (new CCodeExpressionStatement (cclear));
if (current_try != null) {
// surrounding try found
var ccond = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeMemberAccess.pointer (new CCodeIdentifier ("inner_error"), "domain"), new CCodeIdentifier (clause.type_reference.data_type.get_upper_case_cname ()));
var cgoto_block = new CCodeBlock ();
- cgoto_block.add_statement (new CCodeGotoStatement ("__catch%d_%s".printf (next_try_id, clause.type_reference.data_type.get_lower_case_cname ())));
+ cgoto_block.add_statement (new CCodeGotoStatement ("__catch%d_%s".printf (current_try_id, clause.type_reference.data_type.get_lower_case_cname ())));
cerror_block.add_statement (new CCodeIfStatement (ccond, cgoto_block));
}
- // print critical message and return if no catch clause matches
+ // print critical message if no catch clause matches
cerror_block.add_statement (cprint_frag);
// check error domain if expression failed
cfrag.append (new CCodeIfStatement (ccond, cerror_block));
} else {
+ // TODO improve check and move to semantic analyzer
Report.warning (node.source_reference, "unhandled error");
- cfrag.append (cprint_frag);
+
+ var cerror_block = new CCodeBlock ();
+ // print critical message
+ cerror_block.add_statement (cprint_frag);
+
+ // check error domain if expression failed
+ var ccond = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, new CCodeIdentifier ("inner_error"), new CCodeConstant ("NULL"));
+
+ cfrag.append (new CCodeIfStatement (ccond, cerror_block));
}
}
}
}
- public override void visit_end_throw_statement (ThrowStatement! stmt) {
+ public override void visit_throw_statement (ThrowStatement! stmt) {
+ stmt.accept_children (this);
+
var cfrag = new CCodeFragment ();
cfrag.append (new CCodeExpressionStatement ((CCodeExpression) stmt.error_expression.ccodenode));
stmt.ccodenode = cfrag;
}
- public override void visit_begin_try_statement (TryStatement! stmt) {
+ public override void visit_try_statement (TryStatement! stmt) {
+ var old_try = current_try;
+ var old_try_id = current_try_id;
current_try = stmt;
- }
+ current_try_id = next_try_id++;
- public override void visit_end_try_statement (TryStatement! stmt) {
- current_try = null;
+ stmt.accept_children (this);
var cfrag = new CCodeFragment ();
cfrag.append (stmt.body.ccodenode);
foreach (CatchClause clause in stmt.get_catch_clauses ()) {
- cfrag.append (new CCodeGotoStatement ("__finally%d".printf (next_try_id)));
+ cfrag.append (new CCodeGotoStatement ("__finally%d".printf (current_try_id)));
cfrag.append (clause.ccodenode);
}
- cfrag.append (new CCodeLabel ("__finally%d".printf (next_try_id)));
+ cfrag.append (new CCodeLabel ("__finally%d".printf (current_try_id)));
if (stmt.finally_body != null) {
cfrag.append (stmt.finally_body.ccodenode);
} else {
stmt.ccodenode = cfrag;
- next_try_id++;
+ current_try = old_try;
+ current_try_id = old_try_id;
}
- public override void visit_end_catch_clause (CatchClause! clause) {
+ public override void visit_catch_clause (CatchClause! clause) {
+ clause.accept_children (this);
+
var cfrag = new CCodeFragment ();
- cfrag.append (new CCodeLabel ("__catch%d_%s".printf (next_try_id, clause.type_reference.data_type.get_lower_case_cname ())));
+ cfrag.append (new CCodeLabel ("__catch%d_%s".printf (current_try_id, clause.type_reference.data_type.get_lower_case_cname ())));
var cblock = new CCodeBlock ();
}
public override void accept (CodeVisitor! visitor) {
- visitor.visit_begin_catch_clause (this);
+ visitor.visit_catch_clause (this);
+ }
+ public override void accept_children (CodeVisitor! visitor) {
type_reference.accept (visitor);
body.accept (visitor);
-
- visitor.visit_end_catch_clause (this);
}
}
}
/**
- * Visit operation called at beginning of throw statements.
+ * Visit operation called for throw statements.
*
* @param stmt a throw statement
*/
- public virtual void visit_begin_throw_statement (ThrowStatement! stmt) {
+ public virtual void visit_throw_statement (ThrowStatement! stmt) {
}
/**
- * Visit operation called at end of throw statements.
- *
- * @param stmt a throw statement
- */
- public virtual void visit_end_throw_statement (ThrowStatement! stmt) {
- }
-
- /**
- * Visit operation called at beginning of try statements.
+ * Visit operation called for try statements.
*
* @param stmt a try statement
*/
- public virtual void visit_begin_try_statement (TryStatement! stmt) {
+ public virtual void visit_try_statement (TryStatement! stmt) {
}
/**
- * Visit operation called at end of try statements.
- *
- * @param stmt a try statement
- */
- public virtual void visit_end_try_statement (TryStatement! stmt) {
- }
-
- /**
- * Visit operation called at beginning of catch clauses.
+ * Visit operation called for catch clauses.
*
* @param clause a catch cluase
*/
- public virtual void visit_begin_catch_clause (CatchClause! clause) {
+ public virtual void visit_catch_clause (CatchClause! clause) {
}
/**
- * Visit operation called at end of catch clauses.
- *
- * @param clause a catch clause
- */
- public virtual void visit_end_catch_clause (CatchClause! clause) {
- }
-
- /**
* Visit operation called for lock statements before the body has been visited.
*
* @param stmt a lock statement
}
}
+ public override void visit_throw_statement (ThrowStatement! stmt) {
+ stmt.accept_children (this);
+ }
+
+ public override void visit_try_statement (TryStatement! stmt) {
+ stmt.accept_children (this);
+ }
+
+ public override void visit_catch_clause (CatchClause! clause) {
+ clause.accept_children (this);
+ }
+
public override void visit_member_access (MemberAccess! expr) {
if (expr.inner != null) {
visit_possibly_leaked_expression (expr.inner);
}
}
- public override void visit_begin_catch_clause (CatchClause! clause) {
+ public override void visit_throw_statement (ThrowStatement! stmt) {
+ stmt.accept_children (this);
+ }
+
+ public override void visit_try_statement (TryStatement! stmt) {
+ stmt.accept_children (this);
+ }
+
+ public override void visit_catch_clause (CatchClause! clause) {
if (clause.type_reference.data_type != null) {
current_source_file.add_symbol_dependency (clause.type_reference.data_type.symbol, SourceFileDependencyType.SOURCE);
}
clause.variable_declarator.symbol = new Symbol (clause.variable_declarator);
clause.body.symbol.add (clause.variable_name, clause.variable_declarator.symbol);
+
+ clause.accept_children (this);
}
/**
expression_type.data_type.is_reference_type () ||
expression_type.data_type is Pointer ||
expression_type.data_type is Array ||
- expression_type.data_type is Callback) {
+ expression_type.data_type is Callback ||
+ expression_type.data_type == pointer_type) {
return true;
}
current_symbol = current_symbol.parent_symbol;
}
+ public override void visit_try_statement (TryStatement! stmt) {
+ stmt.accept_children (this);
+ }
+
+ public override void visit_catch_clause (CatchClause! clause) {
+ clause.accept_children (this);
+ }
+
public override void visit_begin_block (Block! b) {
b.symbol = new Symbol (b);
b.symbol.parent_symbol = current_symbol;
type.transfers_ownership = false;
}
}
+
+ public override void visit_throw_statement (ThrowStatement! stmt) {
+ stmt.accept_children (this);
+ }
+
+ public override void visit_try_statement (TryStatement! stmt) {
+ stmt.accept_children (this);
+ }
+
+ public override void visit_catch_clause (CatchClause! clause) {
+ clause.accept_children (this);
+ }
}
*/
public ThrowStatement (construct Expression! error_expression, construct SourceReference source_reference = null) {
}
-
+
public override void accept (CodeVisitor! visitor) {
- visitor.visit_begin_throw_statement (this);
+ visitor.visit_throw_statement (this);
+ }
+ public override void accept_children (CodeVisitor! visitor) {
if (error_expression != null) {
error_expression.accept (visitor);
visitor.visit_end_full_expression (error_expression);
}
-
- visitor.visit_end_throw_statement (this);
}
public override void replace (CodeNode! old_node, CodeNode! new_node) {
}
public override void accept (CodeVisitor! visitor) {
- visitor.visit_begin_try_statement (this);
+ visitor.visit_try_statement (this);
+ }
+ public override void accept_children (CodeVisitor! visitor) {
body.accept (visitor);
foreach (CatchClause clause in catch_clauses) {
clause.accept (visitor);
}
-
- visitor.visit_end_try_statement (this);
}
}
/* Character Set Conversions */
- public static string convert (string! str, long len, string! to_codeset, string! from_codeset, out int bytes_read, out int bytes_written) throws ConvertError;
+ public static string convert (string! str, long len, string! to_codeset, string! from_codeset, out int bytes_read = null, out int bytes_written = null) throws ConvertError;
public struct IConv {
[CCode (cname = "g_iconv_open")]
[CCode (cprefix = "g_file_", cheader_filename = "glib/gstdio.h")]
public struct FileUtils {
- public static bool get_contents (string! filename, out string contents, out long length) throws FileError;
- public static bool set_contents (string! filename, string contents, long length) throws FileError;
+ public static bool get_contents (string! filename, out string contents, out long length = null) throws FileError;
+ public static bool set_contents (string! filename, string contents, long length = -1) throws FileError;
public static bool test (string filename, FileTest test);
public static int open_tmp (string tmpl, out string name_used) throws FileError;
public static string read_link (string filename) throws FileError;
[ReferenceType (free_function = "g_dir_close")]
public struct Dir {
- public static Dir open (string filename, uint _flags) throws FileError;
+ public static Dir open (string filename, uint _flags = 0) throws FileError;
public weak string read_name ();
[CCode (cname = "g_mkdir")]