From c2eb0f1fb7894003a894ac0bcc3216b7bb261e5e Mon Sep 17 00:00:00 2001 From: Maciej Piechotka Date: Wed, 21 Sep 2016 12:28:39 +0200 Subject: Move to .foreach methods where it does not impact readability https://bugzilla.gnome.org/show_bug.cgi?id=704754 --- ccode/valaccodeblock.vala | 13 +- ccode/valaccodecommaexpression.vala | 5 +- ccode/valaccodedeclaration.vala | 26 ++-- ccode/valaccodeenum.vala | 5 +- ccode/valaccodeexpressionstatement.vala | 5 +- ccode/valaccodefile.vala | 5 +- ccode/valaccodeforstatement.vala | 10 +- ccode/valaccodefragment.vala | 15 ++- ccode/valaccodefunction.vala | 10 +- ccode/valaccodefunctioncall.vala | 5 +- ccode/valaccodefunctiondeclarator.vala | 5 +- ccode/valaccodeinitializerlist.vala | 5 +- ccode/valaccodeoncesection.vala | 5 +- ccode/valaccodestruct.vala | 5 +- codegen/valaccodearraymodule.vala | 5 +- codegen/valaccodebasemodule.vala | 197 +++++++++++++++++------------ codegen/valaccodecompiler.vala | 22 ++-- codegen/valaccodecontrolflowmodule.vala | 52 ++++---- codegen/valaccodedelegatemodule.vala | 17 ++- codegen/valaccodemethodcallmodule.vala | 60 +++++---- codegen/valaccodemethodmodule.vala | 96 ++++++++------ codegen/valaccodestructmodule.vala | 12 +- codegen/valaclassregisterfunction.vala | 14 +- codegen/valagasyncmodule.vala | 35 +++-- codegen/valagdbusclientmodule.vala | 65 ++++++---- codegen/valagdbusmodule.vala | 46 ++++--- codegen/valagdbusservermodule.vala | 86 +++++++------ codegen/valagerrormodule.vala | 44 ++++--- codegen/valagirwriter.vala | 75 ++++++----- codegen/valagobjectmodule.vala | 66 +++++----- codegen/valagsignalmodule.vala | 35 +++-- codegen/valagtkmodule.vala | 10 +- codegen/valagtypemodule.vala | 153 +++++++++++++--------- codegen/valagvariantmodule.vala | 34 +++-- codegen/valainterfaceregisterfunction.vala | 5 +- codegen/valatyperegisterfunction.vala | 5 +- vala/valaarraycreationexpression.vala | 20 +-- vala/valaassignment.vala | 15 ++- vala/valabaseaccess.vala | 5 +- vala/valablock.vala | 15 ++- vala/valaclass.vala | 192 ++++++++++++++++------------ vala/valaclasstype.vala | 5 +- vala/valacodecontext.vala | 5 +- vala/valacodenode.vala | 5 +- vala/valacodewriter.vala | 132 +++++++++++-------- vala/valaconstructor.vala | 5 +- vala/valacreationmethod.vala | 50 +++++--- vala/valadatatype.vala | 12 +- vala/valadeclarationstatement.vala | 5 +- vala/valadelegate.vala | 53 ++++---- vala/valadelegatetype.vala | 10 +- vala/valaelementaccess.vala | 40 +++--- vala/valaenum.vala | 30 +++-- vala/valaerrordomain.vala | 20 +-- vala/valaflowanalyzer.vala | 175 ++++++++++++++----------- vala/valaforeachstatement.vala | 5 +- vala/valaforstatement.vala | 20 +-- vala/valagenieparser.vala | 140 ++++++++++++-------- vala/valagirparser.vala | 177 +++++++++++++++----------- vala/valainitializerlist.vala | 45 ++++--- vala/valainterface.vala | 129 +++++++++++-------- vala/valainterfacetype.vala | 5 +- vala/valalambdaexpression.vala | 17 ++- vala/valamarkupreader.vala | 4 +- vala/valamemberaccess.vala | 22 ++-- vala/valamethod.vala | 95 ++++++++------ vala/valamethodcall.vala | 87 +++++++------ vala/valamethodtype.vala | 7 +- vala/valanamespace.vala | 115 ++++++++++------- vala/valaobjectcreationexpression.vala | 72 ++++++----- vala/valaobjecttype.vala | 5 +- vala/valaobjecttypesymbol.vala | 5 +- vala/valaparser.vala | 120 +++++++++++------- vala/valaproperty.vala | 9 +- vala/valapropertyaccessor.vala | 5 +- vala/valasemanticanalyzer.vala | 10 +- vala/valasignal.vala | 20 +-- vala/valasignaltype.vala | 5 +- vala/valasourcefile.vala | 15 ++- vala/valastatementlist.vala | 10 +- vala/valastruct.vala | 72 ++++++----- vala/valastructvaluetype.vala | 5 +- vala/valaswitchsection.vala | 45 ++++--- vala/valaswitchstatement.vala | 15 ++- vala/valasymbolresolver.vala | 5 +- vala/valatemplate.vala | 5 +- vala/valatrystatement.vala | 35 +++-- vala/valatuple.vala | 10 +- vala/valaunresolvedtype.vala | 15 ++- 89 files changed, 1968 insertions(+), 1430 deletions(-) diff --git a/ccode/valaccodeblock.vala b/ccode/valaccodeblock.vala index 5c8f2c74d..c642e6b42 100644 --- a/ccode/valaccodeblock.vala +++ b/ccode/valaccodeblock.vala @@ -54,7 +54,7 @@ public class Vala.CCodeBlock : CCodeStatement { CCodeNode last_statement = null; writer.write_begin_block (); - foreach (CCodeNode statement in statements) { + statements.foreach ((statement) => { statement.write_declaration (writer); // determine last reachable statement @@ -64,16 +64,15 @@ public class Vala.CCodeBlock : CCodeStatement { || statement is CCodeContinueStatement || statement is CCodeBreakStatement) { last_statement = statement; } - } + return true; + }); - foreach (CCodeNode statement in statements) { + statements.foreach ((statement) => { statement.write (writer); // only output reachable code - if (statement == last_statement) { - break; - } - } + return statement != last_statement; + }); writer.write_end_block (); diff --git a/ccode/valaccodecommaexpression.vala b/ccode/valaccodecommaexpression.vala index 6010428e0..643c14c45 100644 --- a/ccode/valaccodecommaexpression.vala +++ b/ccode/valaccodecommaexpression.vala @@ -49,14 +49,15 @@ public class Vala.CCodeCommaExpression : CCodeExpression { bool first = true; writer.write_string ("("); - foreach (CCodeExpression expr in inner) { + inner.foreach ((expr) => { if (!first) { writer.write_string (", "); } else { first = false; } expr.write (writer); - } + return true; + }); writer.write_string (")"); } } diff --git a/ccode/valaccodedeclaration.vala b/ccode/valaccodedeclaration.vala index 4cbd86204..9dbcc840e 100644 --- a/ccode/valaccodedeclaration.vala +++ b/ccode/valaccodedeclaration.vala @@ -48,20 +48,18 @@ public class Vala.CCodeDeclaration : CCodeStatement { public override void write (CCodeWriter writer) { if ((modifiers & (CCodeModifiers.STATIC | CCodeModifiers.INTERNAL | CCodeModifiers.EXTERN)) == 0) { - foreach (CCodeDeclarator decl in declarators) { + declarators.foreach ((decl) => { decl.write_initialization (writer); - } + return true; + }); } } private bool has_initializer () { - foreach (CCodeDeclarator decl in declarators) { - var var_decl = decl as CCodeVariableDeclarator; - if (var_decl != null && var_decl.initializer == null) { - return false; - } - } - return true; + return declarators.foreach ((decl) => { + unowned CCodeVariableDeclarator var_decl = decl as CCodeVariableDeclarator; + return !(var_decl != null && var_decl.initializer == null); + }); } public override void write_declaration (CCodeWriter writer) { @@ -87,14 +85,15 @@ public class Vala.CCodeDeclaration : CCodeStatement { writer.write_string (" "); bool first = true; - foreach (CCodeDeclarator decl in declarators) { + declarators.foreach ((decl) => { if (!first) { writer.write_string (", "); } else { first = false; } decl.write (writer); - } + return true; + }); writer.write_string (";"); writer.write_newline (); @@ -112,14 +111,15 @@ public class Vala.CCodeDeclaration : CCodeStatement { writer.write_string (" "); bool first = true; - foreach (CCodeDeclarator decl in declarators) { + declarators.foreach ((decl) => { if (!first) { writer.write_string (", "); } else { first = false; } decl.write_declaration (writer); - } + return true; + }); if (CCodeModifiers.DEPRECATED in modifiers) { writer.write_string (" G_GNUC_DEPRECATED"); diff --git a/ccode/valaccodeenum.vala b/ccode/valaccodeenum.vala index f2a378879..4fba47e81 100644 --- a/ccode/valaccodeenum.vala +++ b/ccode/valaccodeenum.vala @@ -53,7 +53,7 @@ public class Vala.CCodeEnum : CCodeNode { writer.write_string ("enum "); writer.write_begin_block (); bool first = true; - foreach (CCodeEnumValue value in values) { + values.foreach ((value) => { if (!first) { writer.write_string (","); writer.write_newline (); @@ -61,7 +61,8 @@ public class Vala.CCodeEnum : CCodeNode { writer.write_indent (); value.write (writer); first = false; - } + return true; + }); if (!first) { writer.write_newline (); } diff --git a/ccode/valaccodeexpressionstatement.vala b/ccode/valaccodeexpressionstatement.vala index 57b2b2da4..fa2e855b3 100644 --- a/ccode/valaccodeexpressionstatement.vala +++ b/ccode/valaccodeexpressionstatement.vala @@ -41,9 +41,10 @@ public class Vala.CCodeExpressionStatement : CCodeStatement { // to improve code readability var ccomma = expression as CCodeCommaExpression; - foreach (CCodeExpression expr in ccomma.get_inner ()) { + ccomma.get_inner ().foreach ((expr) => { write_expression (writer, expr); - } + return true; + }); } else if (expression is CCodeParenthesizedExpression) { var cpar = expression as CCodeParenthesizedExpression; diff --git a/ccode/valaccodefile.vala b/ccode/valaccodefile.vala index 0b256e518..a191ef330 100644 --- a/ccode/valaccodefile.vala +++ b/ccode/valaccodefile.vala @@ -90,7 +90,7 @@ public class Vala.CCodeFile { } void get_symbols_from_fragment (List symbols, CCodeFragment fragment) { - foreach (CCodeNode node in fragment.get_children ()) { + fragment.get_children ().foreach ((node) => { if (node is CCodeFragment) { get_symbols_from_fragment (symbols, (CCodeFragment) node); } else { @@ -99,7 +99,8 @@ public class Vala.CCodeFile { symbols.add (func.name); } } - } + return true; + }); } static string get_define_for_filename (string filename) { diff --git a/ccode/valaccodeforstatement.vala b/ccode/valaccodeforstatement.vala index c4d14be95..9d7796b61 100644 --- a/ccode/valaccodeforstatement.vala +++ b/ccode/valaccodeforstatement.vala @@ -69,7 +69,7 @@ public class Vala.CCodeForStatement : CCodeStatement { writer.write_string ("for ("); first = true; - foreach (CCodeExpression init_expr in initializer) { + initializer.foreach ((init_expr) => { if (!first) { writer.write_string (", "); } else { @@ -78,7 +78,8 @@ public class Vala.CCodeForStatement : CCodeStatement { if (init_expr != null) { init_expr.write (writer); } - } + return true; + }); writer.write_string ("; "); if (condition != null) { @@ -87,7 +88,7 @@ public class Vala.CCodeForStatement : CCodeStatement { writer.write_string ("; "); first = true; - foreach (CCodeExpression it_expr in iterator) { + iterator.foreach ((it_expr) => { if (!first) { writer.write_string (", "); } else { @@ -96,7 +97,8 @@ public class Vala.CCodeForStatement : CCodeStatement { if (it_expr != null) { it_expr.write (writer); } - } + return true; + }); writer.write_string (")"); body.write (writer); diff --git a/ccode/valaccodefragment.vala b/ccode/valaccodefragment.vala index 0e229fffa..3d2d792d6 100644 --- a/ccode/valaccodefragment.vala +++ b/ccode/valaccodefragment.vala @@ -47,20 +47,23 @@ public class Vala.CCodeFragment : CCodeNode { } public override void write (CCodeWriter writer) { - foreach (CCodeNode node in children) { + children.foreach ((node) => { node.write (writer); - } + return true; + }); } public override void write_declaration (CCodeWriter writer) { - foreach (CCodeNode node in children) { + children.foreach ((node) => { node.write_declaration (writer); - } + return true; + }); } public override void write_combined (CCodeWriter writer) { - foreach (CCodeNode node in children) { + children.foreach ((node) => { node.write_combined (writer); - } + return true; + }); } } diff --git a/ccode/valaccodefunction.vala b/ccode/valaccodefunction.vala index 08d3876fb..5c2b2267a 100644 --- a/ccode/valaccodefunction.vala +++ b/ccode/valaccodefunction.vala @@ -93,9 +93,10 @@ public class Vala.CCodeFunction : CCodeNode { /* no deep copy for lists available yet * func.parameters = parameters.copy (); */ - foreach (CCodeParameter param in parameters) { + parameters.foreach ((param) => { func.parameters.add (param); - } + return true; + }); func.is_declaration = is_declaration; func.block = block; @@ -122,7 +123,7 @@ public class Vala.CCodeFunction : CCodeNode { int i = 0; int format_arg_index = -1; int args_index = -1; - foreach (CCodeParameter param in parameters) { + parameters.foreach ((param) => { if (i > 0) { writer.write_string (", "); } @@ -136,7 +137,8 @@ public class Vala.CCodeFunction : CCodeNode { format_arg_index = i - 1; } i++; - } + return true; + }); if (i == 0) { writer.write_string ("void"); } diff --git a/ccode/valaccodefunctioncall.vala b/ccode/valaccodefunctioncall.vala index e9e7d14c3..76906ff32 100644 --- a/ccode/valaccodefunctioncall.vala +++ b/ccode/valaccodefunctioncall.vala @@ -64,7 +64,7 @@ public class Vala.CCodeFunctionCall : CCodeExpression { writer.write_string (" ("); bool first = true; - foreach (CCodeExpression expr in arguments) { + arguments.foreach ((expr) => { if (!first) { writer.write_string (", "); } else { @@ -74,7 +74,8 @@ public class Vala.CCodeFunctionCall : CCodeExpression { if (expr != null) { expr.write (writer); } - } + return true; + }); writer.write_string (")"); } diff --git a/ccode/valaccodefunctiondeclarator.vala b/ccode/valaccodefunctiondeclarator.vala index 30f0c63b1..256da8045 100644 --- a/ccode/valaccodefunctiondeclarator.vala +++ b/ccode/valaccodefunctiondeclarator.vala @@ -59,7 +59,7 @@ public class Vala.CCodeFunctionDeclarator : CCodeDeclarator { int i = 0; int format_arg_index = -1; int args_index = -1; - foreach (CCodeParameter param in parameters) { + parameters.foreach ((param) => { if (i > 0) { writer.write_string (", "); } @@ -73,7 +73,8 @@ public class Vala.CCodeFunctionDeclarator : CCodeDeclarator { format_arg_index = i - 1; } i++; - } + return true; + }); writer.write_string (")"); diff --git a/ccode/valaccodeinitializerlist.vala b/ccode/valaccodeinitializerlist.vala index 26cb56e1d..a26603ba1 100644 --- a/ccode/valaccodeinitializerlist.vala +++ b/ccode/valaccodeinitializerlist.vala @@ -41,7 +41,7 @@ public class Vala.CCodeInitializerList : CCodeExpression { writer.write_string ("{"); bool first = true; - foreach (CCodeExpression expr in initializers) { + initializers.foreach ((expr) => { if (!first) { writer.write_string (", "); } else { @@ -51,7 +51,8 @@ public class Vala.CCodeInitializerList : CCodeExpression { if (expr != null) { expr.write (writer); } - } + return true; + }); writer.write_string ("}"); } diff --git a/ccode/valaccodeoncesection.vala b/ccode/valaccodeoncesection.vala index 10aa861cc..8223bcb8a 100644 --- a/ccode/valaccodeoncesection.vala +++ b/ccode/valaccodeoncesection.vala @@ -43,9 +43,10 @@ public class Vala.CCodeOnceSection : CCodeFragment { writer.write_string ("#define "); writer.write_string (define); writer.write_newline (); - foreach (CCodeNode node in get_children ()) { + get_children ().foreach ((node) => { node.write_combined (writer); - } + return true; + }); writer.write_indent (); writer.write_string ("#endif"); writer.write_newline (); diff --git a/ccode/valaccodestruct.vala b/ccode/valaccodestruct.vala index fce7fcba8..3da5aa231 100644 --- a/ccode/valaccodestruct.vala +++ b/ccode/valaccodestruct.vala @@ -65,9 +65,10 @@ public class Vala.CCodeStruct : CCodeNode { writer.write_string ("struct "); writer.write_string (name); writer.write_begin_block (); - foreach (CCodeDeclaration decl in declarations) { + declarations.foreach ((decl) => { decl.write_declaration (writer); - } + return true; + }); writer.write_end_block (); if (CCodeModifiers.DEPRECATED in modifiers) { diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala index 2b78bbc7d..d87140da9 100644 --- a/codegen/valaccodearraymodule.vala +++ b/codegen/valaccodearraymodule.vala @@ -63,7 +63,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { CCodeExpression cexpr = null; // iterate over each dimension - foreach (Expression size in expr.get_sizes ()) { + expr.get_sizes ().foreach ((size) => { CCodeExpression csize = get_cvalue (size); append_array_length (expr, csize); @@ -73,7 +73,8 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule { } else { cexpr = new CCodeBinaryExpression (CCodeBinaryOperator.MUL, cexpr, csize); } - } + return true; + }); // add extra item to have array NULL-terminated for all reference types if (expr.element_type.data_type != null && expr.element_type.data_type.is_reference_type ()) { diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index b9b15cd48..dc59abaef 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -489,13 +489,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { regex_type = new ObjectType ((Class) root_symbol.scope.lookup ("GLib").scope.lookup ("Regex")); if (context.module_init_method != null) { - foreach (Parameter parameter in context.module_init_method.get_parameters ()) { + in_plugin = !context.module_init_method.get_parameters ().foreach ((parameter) => { if (parameter.variable_type.data_type == type_module_type) { - in_plugin = true; module_init_param_name = parameter.name; - break; + return false; } - } + return true;; + }); if (!in_plugin) { Report.error (context.module_init_method.source_reference, "[ModuleInit] requires a parameter of type `GLib.TypeModule'"); } @@ -515,12 +515,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { /* we're only interested in non-pkg source files */ var source_files = context.get_source_files (); - foreach (SourceFile file in source_files) { + source_files.foreach ((file) => { if (file.file_type == SourceFileType.SOURCE || (context.header_filename != null && file.file_type == SourceFileType.FAST)) { file.accept (this); } - } + return true; + }); // generate symbols file for public API if (context.symbols_filename != null) { @@ -530,10 +531,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { return; } - foreach (string symbol in header_file.get_symbols ()) { + header_file.get_symbols ().foreach ((symbol) => { stream.puts (symbol); stream.putc ('\n'); - } + return true; + }); stream = null; } @@ -777,10 +779,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { var comments = source_file.get_comments(); if (comments != null) { - foreach (Comment comment in comments) { + comments.foreach ((comment) => { var ccomment = new CCodeComment (comment.content); cfile.add_comment (ccomment); - } + return true; + }); } if (!cfile.store (source_file.get_csource_filename (), source_file.filename, context.version_header, context.debug)) { @@ -800,7 +803,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { cenum.modifiers |= (en.version.deprecated ? CCodeModifiers.DEPRECATED : 0); int flag_shift = 0; - foreach (EnumValue ev in en.get_values ()) { + en.get_values ().foreach ((ev) => { CCodeEnumValue c_ev; if (ev.value == null) { c_ev = new CCodeEnumValue (get_ccode_name (ev)); @@ -814,7 +817,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } c_ev.modifiers |= (ev.version.deprecated ? CCodeModifiers.DEPRECATED : 0); cenum.add_value (c_ev); - } + return true; + }); decl_space.add_type_definition (cenum); decl_space.add_type_definition (new CCodeNewline ()); @@ -1143,9 +1147,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } } - foreach (var value in temp_ref_values) { + temp_ref_values.foreach ((value) => { ccode.add_expression (destroy_value (value)); - } + return true; + }); temp_ref_values.clear (); @@ -1181,9 +1186,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ccode.add_assignment (lhs, rhs); - foreach (var value in temp_ref_values) { + temp_ref_values.foreach ((value) => { ccode.add_expression (destroy_value (value)); - } + return true; + }); temp_ref_values.clear (); @@ -1459,9 +1465,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { generate_type_declaration (pointer_type.base_type, decl_space); } - foreach (DataType type_arg in type.get_type_arguments ()) { + type.get_type_arguments ().foreach ((type_arg) => { generate_type_declaration (type_arg, decl_space); - } + return true; + }); } public virtual void generate_class_struct_declaration (Class cl, CCodeFile decl_space) { @@ -1932,7 +1939,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { if (current_method != null) { // allow capturing generic type parameters - foreach (var type_param in current_method.get_type_parameters ()) { + current_method.get_type_parameters ().foreach ((type_param) => { string func_name; func_name = "%s_type".printf (type_param.name.down ()); @@ -1943,10 +1950,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { func_name = "%s_destroy_func".printf (type_param.name.down ()); data.add_field ("GDestroyNotify", func_name); - } + return true; + }); } } - foreach (var local in local_vars) { + local_vars.foreach ((local) => { if (local.captured) { generate_type_declaration (local.variable_type, cfile); @@ -1965,7 +1973,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } } } - } + return true; + }); var data_alloc = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_new0")); data_alloc.add_argument (new CCodeIdentifier (struct_name)); @@ -2005,12 +2014,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { if (current_method != null) { // allow capturing generic type parameters var suffices = new string[] {"type", "dup_func", "destroy_func"}; - foreach (var type_param in current_method.get_type_parameters ()) { + current_method.get_type_parameters ().foreach ((type_param) => { foreach (string suffix in suffices) { string func_name = "%s_%s".printf (type_param.name.down (), suffix); ccode.add_assignment (new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), func_name), get_variable_cexpression (func_name)); } - } + return true; + }); } } @@ -2018,11 +2028,12 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { var m = (Method) b.parent_symbol; // parameters are captured with the top-level block of the method - foreach (var param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { if (param.captured) { capture_parameter (param, data, block_id); } - } + return true; + }); if (m.coroutine) { // capture async data to allow invoking callback from inside closure @@ -2096,7 +2107,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { if (current_method != null) { // assign captured generic type parameters - foreach (var type_param in current_method.get_type_parameters ()) { + current_method.get_type_parameters ().foreach ((type_param) => { string func_name; func_name = "%s_type".printf (type_param.name.down ()); @@ -2110,7 +2121,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { func_name = "%s_destroy_func".printf (type_param.name.down ()); ccode.add_declaration ("GDestroyNotify", new CCodeVariableDeclarator (func_name)); ccode.add_assignment (new CCodeIdentifier (func_name), new CCodeMemberAccess.pointer (outer_block, func_name)); - } + return true; + }); } // free in reverse order @@ -2137,7 +2149,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { var m = (Method) b.parent_symbol; // parameters are captured with the top-level block of the method - foreach (var param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { if (param.captured) { var param_type = param.variable_type.copy (); if (!param_type.value_owned) { @@ -2158,7 +2170,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } } } - } + return true; + }); } else if (b.parent_symbol is PropertyAccessor) { var acc = (PropertyAccessor) b.parent_symbol; @@ -2209,11 +2222,12 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { cfile.add_function (unref_fun); } - foreach (Statement stmt in b.get_statements ()) { + b.get_statements ().foreach ((stmt) => { push_line (stmt.source_reference); stmt.emit (this); pop_line (); - } + return true; + }); // free in reverse order for (int i = local_vars.size - 1; i >= 0; i--) { @@ -2226,17 +2240,19 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { if (b.parent_symbol is Method) { var m = (Method) b.parent_symbol; - foreach (Parameter param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { if (!param.captured && !param.ellipsis && requires_destroy (param.variable_type) && param.direction == ParameterDirection.IN) { ccode.add_expression (destroy_parameter (param)); } else if (param.direction == ParameterDirection.OUT && !m.coroutine) { return_out_parameter (param); } - } + return true; + }); // check postconditions - foreach (var postcondition in m.get_postconditions ()) { + m.get_postconditions ().foreach ((postcondition) => { create_postcondition_statement (postcondition); - } + return true; + }); } else if (b.parent_symbol is PropertyAccessor) { var acc = (PropertyAccessor) b.parent_symbol; if (acc.value_parameter != null && !acc.value_parameter.captured && requires_destroy (acc.value_parameter.variable_type)) { @@ -2520,7 +2536,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { var clist = new CCodeInitializerList (); var field_it = st.get_fields ().iterator (); - foreach (Expression expr in list.get_initializers ()) { + list.get_initializers ().foreach ((expr) => { Field field = null; while (field == null) { field_it.next (); @@ -2546,7 +2562,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { clist.append (get_array_length_cvalue (expr.target_value, dim)); } } - } + return true; + }); set_cvalue (list, clist); } else { @@ -2554,7 +2571,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { var instance = create_temp_value (list.value_type, true, list); var field_it = st.get_fields ().iterator (); - foreach (Expression expr in list.get_initializers ()) { + list.get_initializers ().foreach ((expr) => { Field field = null; while (field == null) { field_it.next (); @@ -2566,15 +2583,17 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } store_field (field, instance, expr.target_value); - } + return true; + }); list.target_value = instance; } } else { var clist = new CCodeInitializerList (); - foreach (Expression expr in list.get_initializers ()) { + list.get_initializers ().foreach ((expr) => { clist.append (get_cvalue (expr)); - } + return true; + }); set_cvalue (list, clist); } } @@ -2807,10 +2826,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } bool has_instance_fields = false; - foreach (Field f in st.get_fields ()) { + st.get_fields ().foreach ((f) => { if (f.binding != MemberBinding.INSTANCE) { // we only compare instance fields - continue; + return true; } has_instance_fields = true; @@ -2840,7 +2859,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ccode.open_if (cexp); ccode.add_return (new CCodeConstant ("FALSE")); ccode.close (); - } + return true; + }); if (!has_instance_fields) { // either opaque structure or simple type @@ -3116,12 +3136,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { bool elements_require_free = false; CCodeExpression element_destroy_func_expression = null; - foreach (DataType type_arg in type.get_type_arguments ()) { + type.get_type_arguments ().foreach ((type_arg) => { elements_require_free = requires_destroy (type_arg); if (elements_require_free) { element_destroy_func_expression = get_destroy0_func_expression (type_arg); } - } + return true; + }); if (elements_require_free && element_destroy_func_expression is CCodeIdentifier) { return new CCodeIdentifier (generate_collection_free_wrapper (type, (CCodeIdentifier) element_destroy_func_expression)); @@ -3472,9 +3493,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { expr.target_value = store_temp_value (expr.target_value, expr); } - foreach (var value in temp_ref_values) { + temp_ref_values.foreach ((value) => { ccode.add_expression (destroy_value (value)); - } + return true; + }); temp_ref_values.clear (); } @@ -3518,9 +3540,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { /* free temporary objects and handle errors */ - foreach (var value in temp_ref_values) { + temp_ref_values.foreach ((value) => { ccode.add_expression (destroy_value (value)); - } + return true; + }); if (stmt.tree_can_fail && stmt.expression.tree_can_fail) { // simple case, no node breakdown necessary @@ -3582,11 +3605,12 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } private void append_param_free (Method m) { - foreach (Parameter param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { if (!param.captured && !param.ellipsis && requires_destroy (param.variable_type) && param.direction == ParameterDirection.IN) { ccode.add_expression (destroy_parameter (param)); } - } + return true; + }); } public bool variable_accessible_in_finally (LocalVariable local) { @@ -3718,21 +3742,21 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { if (current_method != null) { // check postconditions - foreach (Expression postcondition in current_method.get_postconditions ()) { + current_method.get_postconditions ().foreach ((postcondition) => { create_postcondition_statement (postcondition); - } + return true; + }); } if (current_method != null && !current_method.coroutine) { // assign values to output parameters if they are not NULL // otherwise, free the value if necessary - foreach (var param in current_method.get_parameters ()) { - if (param.direction != ParameterDirection.OUT) { - continue; + current_method.get_parameters ().foreach ((param) => { + if (param.direction == ParameterDirection.OUT) { + return_out_parameter (param); } - - return_out_parameter (param); - } + return true; + }); } // TODO: don't duplicate the code in CCodeMethodModule, we do this right now because it needs to be before return @@ -4426,10 +4450,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } } } - foreach (var type_arg in type.get_type_arguments ()) { + type.get_type_arguments ().foreach ((type_arg) => { check_type (type_arg); check_type_argument (type_arg); - } + return true; + }); } public void check_type_arguments (MemberAccess access) { @@ -4591,12 +4616,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } else { Parameter last_param = null; // FIXME: this doesn't take into account exception handling parameters - foreach (var param in current_method.get_parameters ()) { + current_method.get_parameters ().foreach ((param) => { if (param.ellipsis) { - break; + return false; } last_param = param; - } + return true; + }); int nParams = ccode.get_parameter_count (); if (nParams == 0 || !ccode.get_parameter (nParams - 1).ellipsis) { Report.error (expr.source_reference, "`va_list' used in method with fixed args"); @@ -4632,22 +4658,23 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { add_generic_type_arguments (in_arg_map, expr.type_reference.get_type_arguments (), expr); } else if (cl != null && get_ccode_simple_generics (m)) { int type_param_index = 0; - foreach (var type_arg in expr.type_reference.get_type_arguments ()) { + expr.type_reference.get_type_arguments ().foreach ((type_arg) => { if (requires_copy (type_arg)) { in_arg_map.set (get_param_pos (-1 + 0.1 * type_param_index + 0.03), get_destroy0_func_expression (type_arg)); } else { in_arg_map.set (get_param_pos (-1 + 0.1 * type_param_index + 0.03), new CCodeConstant ("NULL")); } type_param_index++; - } + return true; + }); } bool ellipsis = false; int i = 1; - int arg_pos; + int arg_pos = 0; Iterator params_it = params.iterator (); - foreach (Expression arg in expr.get_argument_list ()) { + expr.get_argument_list ().foreach ((arg) => { CCodeExpression cexpr = get_cvalue (arg); var carg_map = in_arg_map; @@ -4705,7 +4732,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { carg_map.set (arg_pos, cexpr); i++; - } + return true; + }); if (params_it.next ()) { var param = params_it.get (); @@ -4827,9 +4855,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { creation_call.add_argument (new CCodeIdentifier (get_ccode_upper_case_name (edomain))); creation_call.add_argument (new CCodeIdentifier (get_ccode_name (ecode))); - foreach (Expression arg in expr.get_argument_list ()) { + expr.get_argument_list ().foreach ((arg) => { creation_call.add_argument (get_cvalue (arg)); - } + return true; + }); creation_expr = creation_call; } else { @@ -4848,7 +4877,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ccode.add_assignment (instance, creation_expr); } - foreach (MemberInitializer init in expr.get_object_initializer ()) { + expr.get_object_initializer ().foreach ((init) => { if (init.symbol_reference is Field) { var f = (Field) init.symbol_reference; var instance_target_type = get_data_type_for_symbol ((TypeSymbol) f.parent_symbol); @@ -4869,7 +4898,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { ccode.add_expression (destroy_value (init.initializer.target_value)); } } - } + return true; + }); set_cvalue (expr, instance); } else if (creation_expr != null) { @@ -6539,13 +6569,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { push_function (function); var this_value = load_this_parameter (st); - foreach (Field f in st.get_fields ()) { + st.get_fields ().foreach ((f) => { if (f.binding == MemberBinding.INSTANCE) { if (requires_destroy (f.variable_type)) { ccode.add_expression (destroy_field (f, this_value)); } } - } + return true; + }); pop_function (); pop_context (); @@ -6569,19 +6600,20 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { push_function (function); var dest_struct = new GLibValue (get_data_type_for_symbol (st), new CCodeIdentifier ("(*dest)"), true); - foreach (Field f in st.get_fields ()) { + st.get_fields ().foreach ((f) => { if (f.binding == MemberBinding.INSTANCE) { var value = load_field (f, load_this_parameter ((TypeSymbol) st)); if (requires_copy (f.variable_type)) { value = copy_value (value, f); if (value == null) { // error case, continue to avoid critical - continue; + return true; } } store_field (f, dest_struct, value); } - } + return true; + }); pop_function (); pop_context (); @@ -6822,9 +6854,10 @@ internal class Vala.GLibValue : TargetValue { result.ctype = ctype; if (array_length_cvalues != null) { - foreach (var cexpr in array_length_cvalues) { + array_length_cvalues.foreach ((cexpr) => { result.append_array_length_cvalue (cexpr); - } + return true; + }); } result.array_size_cvalue = array_size_cvalue; result.array_null_terminated = array_null_terminated; diff --git a/codegen/valaccodecompiler.vala b/codegen/valaccodecompiler.vala index 52161b422..e45f9fb13 100644 --- a/codegen/valaccodecompiler.vala +++ b/codegen/valaccodecompiler.vala @@ -61,12 +61,13 @@ public class Vala.CCodeCompiler { } use_pkgconfig = true; pc += " gobject-2.0"; - foreach (string pkg in context.get_packages ()) { + context.get_packages ().foreach ((pkg) => { if (package_exists (pkg, pkg_config_command)) { use_pkgconfig = true; pc += " " + pkg; } - } + return true; + }); string pkgflags = ""; if (use_pkgconfig) { try { @@ -103,20 +104,22 @@ public class Vala.CCodeCompiler { /* we're only interested in non-pkg source files */ var source_files = context.get_source_files (); - foreach (SourceFile file in source_files) { + source_files.foreach ((file) => { if (file.file_type == SourceFileType.SOURCE) { cmdline += " " + Shell.quote (file.get_csource_filename ()); } - } + return true; + }); var c_source_files = context.get_c_source_files (); - foreach (string file in c_source_files) { + c_source_files.foreach ((file) => { cmdline += " " + Shell.quote (file); - } + return true; + }); // add libraries after source files to fix linking // with --as-needed and on Windows cmdline += " " + pkgflags.strip (); - foreach (string cc_option in cc_options) { + foreach (unowned string cc_option in cc_options) { cmdline += " " + Shell.quote (cc_option); } @@ -135,12 +138,13 @@ public class Vala.CCodeCompiler { } /* remove generated C source and header files */ - foreach (SourceFile file in source_files) { + source_files.foreach ((file) => { if (file.file_type == SourceFileType.SOURCE) { if (!context.save_csources) { FileUtils.unlink (file.get_csource_filename ()); } } - } + return true; + }); } } diff --git a/codegen/valaccodecontrolflowmodule.vala b/codegen/valaccodecontrolflowmodule.vala index 91268e7d1..ac596dfc4 100644 --- a/codegen/valaccodecontrolflowmodule.vala +++ b/codegen/valaccodecontrolflowmodule.vala @@ -61,22 +61,22 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule { int label_count = 0; - foreach (SwitchSection section in stmt.get_sections ()) { - if (section.has_default_label ()) { - continue; - } - - foreach (SwitchLabel label in section.get_labels ()) { - label.expression.emit (this); - var cexpr = get_cvalue (label.expression); - - if (is_constant_ccode_expression (cexpr)) { - var cname = "_tmp%d_label%d".printf (label_temp_id, label_count++); - - ccode.add_declaration (get_ccode_name (gquark_type), new CCodeVariableDeclarator (cname, czero), CCodeModifiers.STATIC); - } + stmt.get_sections ().foreach ((section) => { + if (!section.has_default_label ()) { + section.get_labels ().foreach ((label) => { + label.expression.emit (this); + var cexpr = get_cvalue (label.expression); + + if (is_constant_ccode_expression (cexpr)) { + var cname = "_tmp%d_label%d".printf (label_temp_id, label_count++); + + ccode.add_declaration (get_ccode_name (gquark_type), new CCodeVariableDeclarator (cname, czero), CCodeModifiers.STATIC); + } + return true; + }); } - } + return true; + }); ccode.add_expression (cinit); @@ -95,14 +95,14 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule { int n = 0; - foreach (SwitchSection section in stmt.get_sections ()) { + stmt.get_sections ().foreach ((section) => { if (section.has_default_label ()) { default_section = section; - continue; + return true; } CCodeBinaryExpression cor = null; - foreach (SwitchLabel label in section.get_labels ()) { + section.get_labels ().foreach ((label) => { label.expression.emit (this); var cexpr = get_cvalue (label.expression); @@ -128,7 +128,8 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule { } else { cor = new CCodeBinaryExpression (CCodeBinaryOperator.OR, cor, ccmp); } - } + return true; + }); if (n > 0) { ccode.else_if (cor); @@ -144,7 +145,8 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule { ccode.close (); n++; - } + return true; + }); if (default_section != null) { if (n > 0) { @@ -174,13 +176,14 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule { bool has_default = false; - foreach (SwitchSection section in stmt.get_sections ()) { + stmt.get_sections ().foreach ((section) => { if (section.has_default_label ()) { ccode.add_default (); has_default = true; } section.emit (this); - } + return true; + }); if (!has_default) { // silence C compiler @@ -335,11 +338,12 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule { ccode.close (); } - foreach (LocalVariable local in stmt.get_local_variables ()) { + stmt.get_local_variables ().foreach ((local) => { if (requires_destroy (local.variable_type)) { ccode.add_expression (destroy_local (local)); } - } + return true; + }); ccode.close (); } diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala index f1120ae9b..db8d77309 100644 --- a/codegen/valaccodedelegatemodule.vala +++ b/codegen/valaccodedelegatemodule.vala @@ -47,7 +47,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule { } var cfundecl = new CCodeFunctionDeclarator (get_ccode_name (d)); - foreach (Parameter param in d.get_parameters ()) { + d.get_parameters ().foreach ((param) => { var cparam = generate_parameter (param, decl_space, new HashMap (), null); cfundecl.add_parameter (cparam); @@ -79,7 +79,8 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule { } } } - } + return true; + }); if (get_ccode_array_length (d) && d.return_type is ArrayType) { // return array length if appropriate var array_type = (ArrayType) d.return_type; @@ -220,7 +221,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule { } var d_params = d.get_parameters (); - foreach (Parameter param in d_params) { + d_params.foreach ((param) => { if (dynamic_sig != null && param.variable_type is ArrayType && ((ArrayType) param.variable_type).element_type.data_type == string_type.data_type) { @@ -230,7 +231,8 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule { } generate_parameter (param, cfile, cparam_map, null); - } + return true; + }); if (get_ccode_array_length (d) && d.return_type is ArrayType) { // return array length if appropriate var array_type = (ArrayType) d.return_type; @@ -308,13 +310,13 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule { bool first = true; - foreach (Parameter param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { if (first && d.sender_type != null && m.get_parameters ().size == d.get_parameters ().size + 1) { // sender parameter carg_map.set (get_param_pos (get_ccode_pos (param)), new CCodeIdentifier ("_sender")); first = false; - continue; + return true; } CCodeExpression arg; @@ -355,7 +357,8 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule { } i++; - } + return true; + }); if (get_ccode_array_length (m) && m.return_type is ArrayType) { var array_type = (ArrayType) m.return_type; for (int dim = 1; dim <= array_type.rank; dim++) { diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala index b3e21a111..a9438521a 100644 --- a/codegen/valaccodemethodcallmodule.vala +++ b/codegen/valaccodemethodcallmodule.vala @@ -139,27 +139,29 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { if (!current_class.is_compact) { if (current_class != m.parent_symbol) { // chain up to base class - foreach (DataType base_type in current_class.get_base_types ()) { + current_class.get_base_types ().foreach ((base_type) => { if (base_type.data_type is Class) { - List type_parameters = null; + List? type_parameters = null; if (get_ccode_real_name (m) == "g_object_new") { // gobject-style chainup type_parameters = ((Class) base_type.data_type).get_type_parameters (); } add_generic_type_arguments (in_arg_map, base_type.get_type_arguments (), expr, true, type_parameters); - break; + return false; } - } + return true; + }); } else { // chain up to other constructor in same class int type_param_index = 0; var cl = (Class) m.parent_symbol; - foreach (TypeParameter type_param in cl.get_type_parameters ()) { + cl.get_type_parameters ().foreach ((type_param) => { in_arg_map.set (get_param_pos (0.1 * type_param_index + 0.01), new CCodeIdentifier ("%s_type".printf (type_param.name.down ()))); in_arg_map.set (get_param_pos (0.1 * type_param_index + 0.02), new CCodeIdentifier ("%s_dup_func".printf (type_param.name.down ()))); in_arg_map.set (get_param_pos (0.1 * type_param_index + 0.03), new CCodeIdentifier ("%s_destroy_func".printf (type_param.name.down ()))); type_param_index++; - } + return true; + }); } } else if (current_class.base_class == gsource_type) { // g_source_new @@ -267,17 +269,19 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { if (m.get_type_parameters ().size > 0) { // generic method int type_param_index = 0; - foreach (var type_arg in ma.get_type_arguments ()) { + ma.get_type_arguments ().foreach ((type_arg) => { in_arg_map.set (get_param_pos (get_ccode_generic_type_pos (m) + 0.01 * type_param_index), new CCodeIdentifier (get_ccode_name (type_arg))); type_param_index++; - } + return true; + }); } else { // method in generic type int type_param_index = 0; - foreach (var type_arg in ma.inner.value_type.get_type_arguments ()) { + ma.inner.value_type.get_type_arguments ().foreach ((type_arg) => { in_arg_map.set (get_param_pos (get_ccode_generic_type_pos (m) + 0.01 * type_param_index), new CCodeIdentifier (get_ccode_name (type_arg))); type_param_index++; - } + return true; + }); } } @@ -289,7 +293,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { } else if (m is DynamicMethod) { m.clear_parameters (); int param_nr = 1; - foreach (Expression arg in expr.get_argument_list ()) { + expr.get_argument_list ().foreach ((arg) => { var unary = arg as UnaryExpression; if (unary != null && unary.operator == UnaryOperator.OUT) { // out argument @@ -306,10 +310,12 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { m.add_parameter (new Parameter ("param%d".printf (param_nr), arg.value_type)); } param_nr++; - } - foreach (Parameter param in m.get_parameters ()) { + return true; + }); + m.get_parameters ().foreach ((param) => { param.accept (this); - } + return true; + }); generate_dynamic_method_wrapper ((DynamicMethod) m); } else if (m is CreationMethod && m.parent_symbol is Class) { ccode.add_assignment (get_this_cexpression (), new CCodeCastExpression (ccall, CCodeBaseModule.get_ccode_name (current_class) + "*")); @@ -325,14 +331,15 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { if (!current_class.is_compact && current_class.get_type_parameters ().size > 0) { /* type, dup func, and destroy func fields for generic types */ var suffices = new string[] {"type", "dup_func", "destroy_func"}; - foreach (TypeParameter type_param in current_class.get_type_parameters ()) { + current_class.get_type_parameters ().foreach ((type_param) => { var priv_access = new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"); foreach (string suffix in suffices) { var param_name = new CCodeIdentifier ("%s_%s".printf (type_param.name.down (), suffix)); ccode.add_assignment (new CCodeMemberAccess.pointer (priv_access, param_name.name), param_name); } - } + return true; + }); } // object chainup can't be used as expression ccall_expr = null; @@ -341,9 +348,9 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { bool ellipsis = false; int i = 1; - int arg_pos; + int arg_pos = 0; Iterator params_it = params.iterator (); - foreach (Expression arg in expr.get_argument_list ()) { + expr.get_argument_list ().foreach ((arg) => { CCodeExpression cexpr = get_cvalue (arg); var carg_map = in_arg_map; @@ -473,7 +480,8 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { } i++; - } + return true; + }); if (params_it.next ()) { var param = params_it.get (); @@ -817,20 +825,20 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { } params_it = params.iterator (); - foreach (Expression arg in expr.get_argument_list ()) { + expr.get_argument_list ().foreach ((arg) => { Parameter param = null; if (params_it.next ()) { param = params_it.get (); if (param.params_array || param.ellipsis) { // ignore ellipsis arguments as we currently don't use temporary variables for them - break; + return false; } } var unary = arg as UnaryExpression; if (unary == null || unary.operator != UnaryOperator.OUT) { - continue; + return true; } if (requires_destroy (unary.inner.value_type)) { @@ -849,7 +857,8 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { ccode.add_assignment (get_array_length_cvalue (unary.inner.target_value, 1), len_call); } - } + return true; + }); if (m is CreationMethod && m.parent_symbol is Class && current_class.base_class == gsource_type) { var cinitcall = new CCodeFunctionCall (new CCodeIdentifier ("%s_instance_init".printf (get_ccode_lower_case_name (current_class, null)))); @@ -877,10 +886,11 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule { push_function (function); ccode.open_switch (new CCodeConstant ("value")); - foreach (var enum_value in en.get_values ()) { + en.get_values ().foreach ((enum_value) => { ccode.add_case (new CCodeIdentifier (get_ccode_name (enum_value))); ccode.add_return (new CCodeConstant ("\""+get_ccode_name (enum_value)+"\"")); - } + return true; + }); ccode.close (); ccode.add_return (new CCodeConstant ("NULL")); diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala index 105ed967c..e766b2f79 100644 --- a/codegen/valaccodemethodmodule.vala +++ b/codegen/valaccodemethodmodule.vala @@ -111,9 +111,10 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { } if (m.get_error_types ().size > 0 || (m.base_method != null && m.base_method.get_error_types ().size > 0) || (m.base_interface_method != null && m.base_interface_method.get_error_types ().size > 0)) { - foreach (DataType error_type in m.get_error_types ()) { + m.get_error_types ().foreach ((error_type) => { generate_type_declaration (error_type, decl_space); - } + return true; + }); var cparam = new CCodeParameter ("error", "GError**"); cparam_map.set (get_param_pos (-1), cparam); @@ -261,25 +262,30 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { var cl = sym as Class; var iface = sym as Interface; if (ns != null) { - foreach (var ns_ns in ns.get_namespaces ()) { + ns.get_namespaces ().foreach ((ns_ns) => { register_plugin_types (ns_ns, registered_types); - } - foreach (var ns_cl in ns.get_classes ()) { + return true; + }); + ns.get_classes ().foreach ((ns_cl) => { register_plugin_types (ns_cl, registered_types); - } - foreach (var ns_iface in ns.get_interfaces ()) { + return true; + }); + ns.get_interfaces ().foreach ((ns_iface) => { register_plugin_types (ns_iface, registered_types); - } + return true; + }); } else if (cl != null) { register_plugin_type (cl, registered_types); - foreach (var cl_cl in cl.get_classes ()) { + cl.get_classes ().foreach ((cl_cl) => { register_plugin_types (cl_cl, registered_types); - } + return true; + }); } else if (iface != null) { register_plugin_type (iface, registered_types); - foreach (var iface_cl in iface.get_classes ()) { + iface.get_classes ().foreach ((iface_cl) => { register_plugin_types (iface_cl, registered_types); - } + return true; + }); } } @@ -300,9 +306,10 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { } // register base types first - foreach (var base_type in cl.get_base_types ()) { + cl.get_base_types ().foreach ((base_type) => { register_plugin_type ((ObjectTypeSymbol) base_type.data_type, registered_types); - } + return true; + }); } // Add function prototypes for required register-type-calls which are likely external @@ -371,9 +378,10 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { creturn_type = new VoidType (); } - foreach (Parameter param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { param.accept (this); - } + return true; + }); // do not declare overriding methods and interface implementations if ((m.is_abstract || m.is_virtual @@ -545,7 +553,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { } // allow capturing generic type parameters - foreach (var type_param in m.get_type_parameters ()) { + m.get_type_parameters ().foreach ((type_param) => { string func_name; func_name = "%s_type".printf (type_param.name.down ()); @@ -559,7 +567,8 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { func_name = "%s_destroy_func".printf (type_param.name.down ()); ccode.add_declaration ("GDestroyNotify", new CCodeVariableDeclarator (func_name)); ccode.add_assignment (new CCodeIdentifier (func_name), new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (block_id)), func_name)); - } + return true; + }); } else if (m.parent_symbol is Class && !m.coroutine) { var cl = (Class) m.parent_symbol; if (m.overrides || (m.base_interface_method != null && !m.is_abstract && !m.is_virtual)) { @@ -584,9 +593,9 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { } } - foreach (Parameter param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { if (param.ellipsis) { - break; + return false; } if (param.direction != ParameterDirection.OUT) { @@ -628,7 +637,8 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { } } } - } + return true; + }); if (!(m.return_type is VoidType) && !m.return_type.is_real_non_null_struct_type () && !m.coroutine) { var vardecl = new CCodeVariableDeclarator ("result", default_value_for_type (m.return_type, true)); @@ -651,7 +661,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { ccode.add_assignment (get_this_cexpression (), new CCodeCastExpression (ccall, get_ccode_name (cl) + "*")); /* type, dup func, and destroy func fields for generic types */ - foreach (TypeParameter type_param in current_class.get_type_parameters ()) { + current_class.get_type_parameters ().foreach ((type_param) => { CCodeIdentifier param_name; CCodeAssignment assign; @@ -668,7 +678,8 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { param_name = new CCodeIdentifier ("%s_destroy_func".printf (type_param.name.down ())); assign = new CCodeAssignment (new CCodeMemberAccess.pointer (priv_access, param_name.name), param_name); ccode.add_expression (assign); - } + return true; + }); } } else if (current_type_symbol is Class) { var cl = (Class) m.parent_symbol; @@ -707,9 +718,10 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { register_plugin_types (context.root, new HashSet ()); } - foreach (Expression precondition in m.get_preconditions ()) { + m.get_preconditions ().foreach ((precondition) => { create_precondition_statement (m, creturn_type, precondition); - } + return true; + }); } } @@ -997,7 +1009,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { // memory management for generic types int type_param_index = 0; var cl = (Class) m.parent_symbol; - foreach (TypeParameter type_param in cl.get_type_parameters ()) { + cl.get_type_parameters ().foreach ((type_param) => { cparam_map.set (get_param_pos (0.1 * type_param_index + 0.01), new CCodeParameter ("%s_type".printf (type_param.name.down ()), "GType")); cparam_map.set (get_param_pos (0.1 * type_param_index + 0.02), new CCodeParameter ("%s_dup_func".printf (type_param.name.down ()), "GBoxedCopyFunc")); cparam_map.set (get_param_pos (0.1 * type_param_index + 0.03), new CCodeParameter ("%s_destroy_func".printf (type_param.name.down ()), "GDestroyNotify")); @@ -1007,10 +1019,11 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { carg_map.set (get_param_pos (0.1 * type_param_index + 0.03), new CCodeIdentifier ("%s_destroy_func".printf (type_param.name.down ()))); } type_param_index++; - } + return true; + }); } else if (!m.closure && (direction & 1) == 1) { int type_param_index = 0; - foreach (var type_param in m.get_type_parameters ()) { + m.get_type_parameters ().foreach ((type_param) => { cparam_map.set (get_param_pos (0.1 * type_param_index + 0.01), new CCodeParameter ("%s_type".printf (type_param.name.down ()), "GType")); cparam_map.set (get_param_pos (0.1 * type_param_index + 0.02), new CCodeParameter ("%s_dup_func".printf (type_param.name.down ()), "GBoxedCopyFunc")); cparam_map.set (get_param_pos (0.1 * type_param_index + 0.03), new CCodeParameter ("%s_destroy_func".printf (type_param.name.down ()), "GDestroyNotify")); @@ -1020,24 +1033,26 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { carg_map.set (get_param_pos (0.1 * type_param_index + 0.03), new CCodeIdentifier ("%s_destroy_func".printf (type_param.name.down ()))); } type_param_index++; - } + return true; + }); } - foreach (Parameter param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { if (param.direction != ParameterDirection.OUT) { if ((direction & 1) == 0) { // no in parameters - continue; + return true; } } else { if ((direction & 2) == 0) { // no out parameters - continue; + return true; } } generate_parameter (param, decl_space, cparam_map, carg_map); - } + return true; + }); if ((direction & 2) != 0) { generate_method_result_declaration (m, decl_space, func, cparam_map, carg_map); @@ -1122,9 +1137,10 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { // add a typecheck statement for "self" create_method_type_check_statement (m, return_type, (TypeSymbol) m.parent_symbol, true, "self"); - foreach (Expression precondition in m.get_preconditions ()) { + m.get_preconditions ().foreach ((precondition) => { create_precondition_statement (m, return_type, precondition); - } + return true; + }); if (return_type is VoidType || return_type.is_real_non_null_struct_type ()) { ccode.add_expression (vcall); @@ -1138,9 +1154,10 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { } if (m.get_postconditions ().size > 0) { - foreach (Expression postcondition in m.get_postconditions ()) { + m.get_postconditions ().foreach ((postcondition) => { create_postcondition_statement (postcondition); - } + return true; + }); if (!(return_type is VoidType)) { ccode.add_return (new CCodeIdentifier ("result")); @@ -1267,14 +1284,15 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule { if (m.is_variadic ()) { int last_pos = -1; int second_last_pos = -1; - foreach (int pos in cparam_map.keys) { + cparam_map.keys.foreach ((pos) => { if (pos > last_pos) { second_last_pos = last_pos; last_pos = pos; } else if (pos > second_last_pos) { second_last_pos = pos; } - } + return true; + }); var va_start = new CCodeFunctionCall (new CCodeIdentifier ("va_start")); va_start.add_argument (new CCodeIdentifier ("_vala_va_list_obj")); diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala index 9457b3556..7c641b073 100644 --- a/codegen/valaccodestructmodule.vala +++ b/codegen/valaccodestructmodule.vala @@ -66,7 +66,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule { var instance_struct = new CCodeStruct ("_%s".printf (get_ccode_name (st))); instance_struct.modifiers |= (st.version.deprecated ? CCodeModifiers.DEPRECATED : 0); - foreach (Field f in st.get_fields ()) { + st.get_fields ().foreach ((f) => { if (f.binding == MemberBinding.INSTANCE) { generate_type_declaration (f.variable_type, decl_space); CCodeModifiers modifiers = (f.is_volatile ? CCodeModifiers.VOLATILE : 0) | (f.version.deprecated ? CCodeModifiers.DEPRECATED : 0); @@ -103,7 +103,8 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule { } } } - } + return true; + }); if (st.base_struct == null) { decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (get_ccode_name (st)), new CCodeVariableDeclarator (get_ccode_name (st)))); @@ -276,19 +277,20 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule { push_function (function); var dest_struct = new GLibValue (get_data_type_for_symbol (st), new CCodeIdentifier ("(*dest)"), true); - foreach (var f in st.get_fields ()) { + st.get_fields ().foreach ((f) => { if (f.binding == MemberBinding.INSTANCE) { var value = load_field (f, load_this_parameter ((TypeSymbol) st)); if (requires_copy (f.variable_type)) { value = copy_value (value, f); if (value == null) { // error case, continue to avoid critical - continue; + return true; } } store_field (f, dest_struct, value); } - } + return true; + }); pop_function (); diff --git a/codegen/valaclassregisterfunction.vala b/codegen/valaclassregisterfunction.vala index 01aa54c74..54d735097 100644 --- a/codegen/valaclassregisterfunction.vala +++ b/codegen/valaclassregisterfunction.vala @@ -153,9 +153,9 @@ public class Vala.ClassRegisterFunction : TypeRegisterFunction { public override CCodeFragment get_type_interface_init_declaration () { var frag = new CCodeFragment (); - foreach (DataType base_type in class_reference.get_base_types ()) { + class_reference.get_base_types ().foreach ((base_type) => { if (!(base_type.data_type is Interface)) { - continue; + return true; } var iface = (Interface) base_type.data_type; @@ -166,15 +166,16 @@ public class Vala.ClassRegisterFunction : TypeRegisterFunction { ctypedecl.modifiers = CCodeModifiers.STATIC; ctypedecl.add_declarator (new CCodeVariableDeclarator (iface_info_name, new CCodeConstant ("{ (GInterfaceInitFunc) %s_%s_interface_init, (GInterfaceFinalizeFunc) NULL, NULL}".printf (CCodeBaseModule.get_ccode_lower_case_name (class_reference), CCodeBaseModule.get_ccode_lower_case_name (iface))))); frag.append (ctypedecl); - } + return true; + }); return frag; } public override void get_type_interface_init_statements (CCodeBlock block, bool plugin) { - foreach (DataType base_type in class_reference.get_base_types ()) { + class_reference.get_base_types ().foreach ((base_type) => { if (!(base_type.data_type is Interface)) { - continue; + return true; } var iface = (Interface) base_type.data_type; @@ -194,7 +195,8 @@ public class Vala.ClassRegisterFunction : TypeRegisterFunction { reg_call.add_argument (new CCodeIdentifier ("&%s".printf (iface_info_name))); block.add_statement (new CCodeExpressionStatement (reg_call)); } - } + return true; + }); ((CCodeBaseModule) context.codegen).register_dbus_info (block, class_reference); } diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala index 73e86eacf..12d39dac1 100644 --- a/codegen/valagasyncmodule.vala +++ b/codegen/valagasyncmodule.vala @@ -53,7 +53,7 @@ public class Vala.GAsyncModule : GtkModule { } } - foreach (Parameter param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { bool is_unowned_delegate = param.variable_type is DelegateType && !param.variable_type.value_owned; var param_type = param.variable_type.copy (); @@ -76,13 +76,15 @@ public class Vala.GAsyncModule : GtkModule { } } } - } + return true; + }); - foreach (var type_param in m.get_type_parameters ()) { + m.get_type_parameters ().foreach ((type_param) => { data.add_field ("GType", "%s_type".printf (type_param.name.down ())); data.add_field ("GBoxedCopyFunc", "%s_dup_func".printf (type_param.name.down ())); data.add_field ("GDestroyNotify", "%s_destroy_func".printf (type_param.name.down ())); - } + return true; + }); if (!(m.return_type is VoidType)) { data.add_field (get_ccode_name (m.return_type), "result"); @@ -117,7 +119,7 @@ public class Vala.GAsyncModule : GtkModule { ccode.add_declaration (dataname + "*", new CCodeVariableDeclarator ("_data_", new CCodeIdentifier ("_data"))); - foreach (Parameter param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { if (!param.captured && param.direction != ParameterDirection.OUT) { var param_type = param.variable_type.copy (); if (!param_type.value_owned) { @@ -128,7 +130,8 @@ public class Vala.GAsyncModule : GtkModule { ccode.add_expression (destroy_parameter (param)); } } - } + return true; + }); if (requires_destroy (m.return_type)) { if (get_ccode_array_length (m) || !(m.return_type is ArrayType)) { @@ -302,7 +305,7 @@ public class Vala.GAsyncModule : GtkModule { } emit_context.push_symbol (m); - foreach (Parameter param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { if (param.direction != ParameterDirection.OUT) { // create copy if necessary as variables in async methods may need to be kept alive var old_captured = param.captured; @@ -324,17 +327,19 @@ public class Vala.GAsyncModule : GtkModule { param.captured = old_captured; } - } + return true; + }); emit_context.pop_symbol (); - foreach (var type_param in m.get_type_parameters ()) { + m.get_type_parameters ().foreach ((type_param) => { var type = "%s_type".printf (type_param.name.down ()); var dup_func = "%s_dup_func".printf (type_param.name.down ()); var destroy_func = "%s_destroy_func".printf (type_param.name.down ()); ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, type), new CCodeIdentifier (type)); ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, dup_func), new CCodeIdentifier (dup_func)); ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, destroy_func), new CCodeIdentifier (destroy_func)); - } + return true; + }); var ccall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_real_name (m) + "_co")); ccall.add_argument (data_var); @@ -632,14 +637,15 @@ public class Vala.GAsyncModule : GtkModule { } emit_context.push_symbol (m); - foreach (Parameter param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { if (param.direction != ParameterDirection.IN) { return_out_parameter (param); if (!(param.variable_type is ValueType) || param.variable_type.nullable) { ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, get_variable_cname (param.name)), new CCodeConstant ("NULL")); } } - } + return true; + }); emit_context.pop_symbol (); if (m is CreationMethod) { @@ -789,9 +795,10 @@ public class Vala.GAsyncModule : GtkModule { /* free temporary objects */ - foreach (var value in temp_ref_values) { + temp_ref_values.foreach ((value) => { ccode.add_expression (destroy_value (value)); - } + return true; + }); temp_ref_values.clear (); } diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala index bb38e8fe9..46edac992 100644 --- a/codegen/valagdbusclientmodule.vala +++ b/codegen/valagdbusclientmodule.vala @@ -68,11 +68,12 @@ public class Vala.GDBusClientModule : GDBusModule { void generate_proxy_interface_init (Interface main_iface, Interface iface) { // also generate proxy for prerequisites - foreach (var prereq in iface.get_prerequisites ()) { + iface.get_prerequisites ().foreach ((prereq) => { if (prereq.data_type is Interface) { generate_proxy_interface_init (main_iface, (Interface) prereq.data_type); } - } + return true; + }); string lower_cname = get_ccode_lower_case_prefix (main_iface) + "proxy"; @@ -81,9 +82,9 @@ public class Vala.GDBusClientModule : GDBusModule { push_function (proxy_iface_init); - foreach (Method m in iface.get_methods ()) { + iface.get_methods ().foreach ((m) => { if (!m.is_abstract) { - continue; + return true; } var vfunc_entry = new CCodeMemberAccess.pointer (new CCodeIdentifier ("iface"), get_ccode_vfunc_name (m)); @@ -94,11 +95,12 @@ public class Vala.GDBusClientModule : GDBusModule { vfunc_entry = new CCodeMemberAccess.pointer (new CCodeIdentifier ("iface"), get_ccode_finish_vfunc_name (m)); ccode.add_assignment (vfunc_entry, new CCodeIdentifier (generate_finish_dbus_proxy_method (main_iface, iface, m))); } - } + return true; + }); - foreach (Property prop in iface.get_properties ()) { + iface.get_properties ().foreach ((prop) => { if (!prop.is_abstract) { - continue; + return true; } if (prop.get_accessor != null) { @@ -109,7 +111,8 @@ public class Vala.GDBusClientModule : GDBusModule { var vfunc_entry = new CCodeMemberAccess.pointer (new CCodeIdentifier ("iface"), "set_" + prop.name); ccode.add_assignment (vfunc_entry, new CCodeIdentifier (generate_dbus_proxy_property_set (main_iface, iface, prop))); } - } + return true; + }); proxy_iface_init.modifiers = CCodeModifiers.STATIC; pop_function (); @@ -121,11 +124,12 @@ public class Vala.GDBusClientModule : GDBusModule { string result = ""; // also implement prerequisites - foreach (var prereq in iface.get_prerequisites ()) { + iface.get_prerequisites ().foreach ((prereq) => { if (prereq.data_type is Interface) { result += implement_interface (define_type, main_iface, (Interface) prereq.data_type); } - } + return true; + }); string interface_macro; @@ -456,7 +460,7 @@ public class Vala.GDBusClientModule : GDBusModule { ccall.add_argument (new CCodeIdentifier ("self")); ccall.add_argument (get_signal_canonical_constant (sig)); - foreach (Parameter param in sig.get_parameters ()) { + sig.get_parameters ().foreach ((param) => { var param_name = get_variable_cname (param.name); var owned_type = param.variable_type.copy (); owned_type.value_owned = true; @@ -482,11 +486,12 @@ public class Vala.GDBusClientModule : GDBusModule { } read_expression (param.variable_type, new CCodeIdentifier ("_arguments_iter"), new CCodeIdentifier (param_name), param); - } + return true; + }); ccode.add_expression (ccall); - foreach (Parameter param in sig.get_parameters ()) { + sig.get_parameters ().foreach ((param) => { var owned_type = param.variable_type.copy (); owned_type.value_owned = true; @@ -495,7 +500,8 @@ public class Vala.GDBusClientModule : GDBusModule { var local = new LocalVariable (owned_type, param.name); ccode.add_expression (destroy_local (local)); } - } + return true; + }); pop_function (); @@ -520,9 +526,9 @@ public class Vala.GDBusClientModule : GDBusModule { bool firstif = true; - foreach (Signal sig in sym.get_signals ()) { + sym.get_signals ().foreach ((sig) => { if (sig.access != SymbolAccessibility.PUBLIC) { - continue; + return true; } cfile.add_include ("string.h"); @@ -544,7 +550,8 @@ public class Vala.GDBusClientModule : GDBusModule { ccall.add_argument (new CCodeIdentifier ("parameters")); ccode.add_expression (ccall); - } + return true; + }); if (!firstif) { ccode.close (); } @@ -592,12 +599,13 @@ public class Vala.GDBusClientModule : GDBusModule { } // register errors - foreach (var error_type in m.get_error_types ()) { + m.get_error_types ().foreach ((error_type) => { var errtype = (ErrorType) error_type; if (errtype.error_domain != null) { ccode.add_expression (new CCodeIdentifier (get_ccode_upper_case_name (errtype.error_domain))); } - } + return true; + }); // build D-Bus message @@ -628,7 +636,7 @@ public class Vala.GDBusClientModule : GDBusModule { CCodeExpression cancellable = new CCodeConstant ("NULL"); - foreach (Parameter param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { if (param.direction == ParameterDirection.IN) { CCodeExpression expr = new CCodeIdentifier (get_variable_cname (param.name)); if (param.variable_type.is_real_struct_type ()) { @@ -637,17 +645,18 @@ public class Vala.GDBusClientModule : GDBusModule { if (param.variable_type is ObjectType && param.variable_type.data_type.get_full_name () == "GLib.Cancellable") { cancellable = expr; - continue; + return true; } if (param.variable_type is ObjectType && param.variable_type.data_type.get_full_name () == "GLib.BusName") { // ignore BusName sender parameters - continue; + return true; } send_dbus_value (param.variable_type, new CCodeIdentifier ("_arguments_builder"), expr, param); } - } + return true; + }); var builder_end = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_builder_end")); builder_end.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_arguments_builder"))); @@ -791,11 +800,12 @@ public class Vala.GDBusClientModule : GDBusModule { ccode.add_declaration ("gint", new CCodeVariableDeclarator ("_fd")); } - foreach (Parameter param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { if (param.direction == ParameterDirection.OUT) { has_result = true; } - } + return true; + }); if (has_result) { ccode.add_declaration ("GVariant", new CCodeVariableDeclarator ("*_reply")); @@ -810,7 +820,7 @@ public class Vala.GDBusClientModule : GDBusModule { iter_init.add_argument (new CCodeIdentifier ("_reply")); ccode.add_expression (iter_init); - foreach (Parameter param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { if (param.direction == ParameterDirection.OUT) { ccode.add_declaration (get_ccode_name (param.variable_type), new CCodeVariableDeclarator.zero ("_vala_%s".printf (param.name), default_value_for_type (param.variable_type, true))); @@ -845,7 +855,8 @@ public class Vala.GDBusClientModule : GDBusModule { ccode.close (); } } - } + return true; + }); if (!(m.return_type is VoidType)) { if (m.return_type.is_real_non_null_struct_type ()) { diff --git a/codegen/valagdbusmodule.vala b/codegen/valagdbusmodule.vala index 0a6404ad8..259d2c373 100644 --- a/codegen/valagdbusmodule.vala +++ b/codegen/valagdbusmodule.vala @@ -81,7 +81,7 @@ public class Vala.GDBusModule : GVariantModule { } var error_entries = new CCodeInitializerList (); - foreach (ErrorCode ecode in edomain.get_codes ()) { + edomain.get_codes ().foreach ((ecode) => { var ecode_dbus_name = get_dbus_name (ecode); if (ecode_dbus_name == null) { ecode_dbus_name = Symbol.lower_case_to_camel_case (ecode.name.down ()); @@ -91,7 +91,8 @@ public class Vala.GDBusModule : GVariantModule { error_entry.append (new CCodeIdentifier (get_ccode_name (ecode))); error_entry.append (new CCodeConstant ("\"%s.%s\"".printf (edomain_dbus_name, ecode_dbus_name))); error_entries.append (error_entry); - } + return true; + }); var cdecl = new CCodeDeclaration ("const GDBusErrorEntry"); cdecl.add_declarator (new CCodeVariableDeclarator (get_ccode_lower_case_name (edomain) + "_entries[]", error_entries)); @@ -263,24 +264,24 @@ public class Vala.GDBusModule : GVariantModule { CCodeExpression get_method_info (ObjectTypeSymbol sym) { var infos = new CCodeInitializerList (); - foreach (Method m in sym.get_methods ()) { + sym.get_methods ().foreach ((m) => { if (m is CreationMethod || m.binding != MemberBinding.INSTANCE || m.overrides || m.access != SymbolAccessibility.PUBLIC) { - continue; + return true; } if (!is_dbus_visible (m)) { - continue; + return true; } var in_args_info = new CCodeInitializerList (); var out_args_info = new CCodeInitializerList (); - foreach (Parameter param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { if (param.variable_type is ObjectType && param.variable_type.data_type.get_full_name () == "GLib.Cancellable") { - continue; + return true; } if (param.variable_type is ObjectType && param.variable_type.data_type.get_full_name () == "GLib.BusName") { - continue; + return true; } var info = new CCodeInitializerList (); @@ -298,7 +299,8 @@ public class Vala.GDBusModule : GVariantModule { } else { out_args_info.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_arg_info_" + m.name + "_" + param.name))); } - } + return true; + }); if (!(m.return_type is VoidType)) { var info = new CCodeInitializerList (); @@ -339,7 +341,8 @@ public class Vala.GDBusModule : GVariantModule { cfile.add_constant_declaration (cdecl); infos.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_method_info_" + m.name))); - } + return true; + }); infos.append (new CCodeConstant ("NULL")); @@ -354,17 +357,17 @@ public class Vala.GDBusModule : GVariantModule { CCodeExpression get_signal_info (ObjectTypeSymbol sym) { var infos = new CCodeInitializerList (); - foreach (Signal sig in sym.get_signals ()) { + sym.get_signals ().foreach ((sig) => { if (sig.access != SymbolAccessibility.PUBLIC) { - continue; + return true; } if (!is_dbus_visible (sig)) { - continue; + return true; } var args_info = new CCodeInitializerList (); - foreach (Parameter param in sig.get_parameters ()) { + sig.get_parameters ().foreach ((param) => { var info = new CCodeInitializerList (); info.append (new CCodeConstant ("-1")); info.append (new CCodeConstant ("\"%s\"".printf (param.name))); @@ -376,7 +379,8 @@ public class Vala.GDBusModule : GVariantModule { cfile.add_constant_declaration (cdecl); args_info.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_arg_info_" + get_ccode_name (sig) + "_" + param.name))); - } + return true; + }); args_info.append (new CCodeConstant ("NULL")); @@ -396,7 +400,8 @@ public class Vala.GDBusModule : GVariantModule { cfile.add_constant_declaration (cdecl); infos.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_signal_info_" + get_ccode_name (sig)))); - } + return true; + }); infos.append (new CCodeConstant ("NULL")); @@ -411,13 +416,13 @@ public class Vala.GDBusModule : GVariantModule { CCodeExpression get_property_info (ObjectTypeSymbol sym) { var infos = new CCodeInitializerList (); - foreach (Property prop in sym.get_properties ()) { + sym.get_properties ().foreach ((prop) => { if (prop.binding != MemberBinding.INSTANCE || prop.overrides || prop.access != SymbolAccessibility.PUBLIC) { - continue; + return true; } if (!is_dbus_visible (prop)) { - continue; + return true; } var info = new CCodeInitializerList (); @@ -440,7 +445,8 @@ public class Vala.GDBusModule : GVariantModule { cfile.add_constant_declaration (cdecl); infos.append (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_" + get_ccode_lower_case_prefix (sym) + "dbus_property_info_" + prop.name))); - } + return true; + }); infos.append (new CCodeConstant ("NULL")); diff --git a/codegen/valagdbusservermodule.vala b/codegen/valagdbusservermodule.vala index d0c87fd64..a4512b5cb 100644 --- a/codegen/valagdbusservermodule.vala +++ b/codegen/valagdbusservermodule.vala @@ -97,19 +97,19 @@ public class Vala.GDBusServerModule : GDBusClientModule { ccode.add_declaration ("gint", new CCodeVariableDeclarator ("_fd")); } - foreach (Parameter param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { string param_name = get_variable_cname (param.name); if (param.direction != ParameterDirection.IN) { - continue; + return true; } if (param.variable_type is ObjectType && param.variable_type.data_type.get_full_name () == "GLib.Cancellable") { - continue; + return true; } if (param.variable_type is ObjectType && param.variable_type.data_type.get_full_name () == "GLib.BusName") { // ignore BusName sender parameters - continue; + return true; } var owned_type = param.variable_type.copy (); @@ -154,15 +154,16 @@ public class Vala.GDBusServerModule : GDBusClientModule { ccode.close (); } - } + return true; + }); } - foreach (Parameter param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { string param_name = get_variable_cname (param.name); if (param.direction == ParameterDirection.IN && !ready) { if (param.variable_type is ObjectType && param.variable_type.data_type.get_full_name () == "GLib.Cancellable") { ccall.add_argument (new CCodeConstant ("NULL")); - continue; + return true; } if (param.variable_type is ObjectType && param.variable_type.data_type.get_full_name () == "GLib.BusName") { @@ -170,7 +171,7 @@ public class Vala.GDBusServerModule : GDBusClientModule { var sender = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_method_invocation_get_sender")); sender.add_argument (new CCodeIdentifier ("invocation")); ccall.add_argument (sender); - continue; + return true; } var st = param.variable_type.data_type as Struct; @@ -195,7 +196,8 @@ public class Vala.GDBusServerModule : GDBusClientModule { } } } - } + return true; + }); if (!m.coroutine || ready) { if (!(m.return_type is VoidType)) { @@ -270,9 +272,9 @@ public class Vala.GDBusServerModule : GDBusClientModule { ccode.add_assignment (new CCodeIdentifier ("_fd_list"), new CCodeFunctionCall (new CCodeIdentifier ("g_unix_fd_list_new"))); } - foreach (Parameter param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { if (param.direction != ParameterDirection.OUT) { - continue; + return true; } string param_name = get_variable_cname (param.name); @@ -291,7 +293,8 @@ public class Vala.GDBusServerModule : GDBusClientModule { } send_dbus_value (param.variable_type, new CCodeIdentifier ("_reply_builder"), new CCodeIdentifier (param_name), param); - } + return true; + }); if (!(m.return_type is VoidType)) { if (m.return_type.is_real_non_null_struct_type ()) { @@ -372,16 +375,16 @@ public class Vala.GDBusServerModule : GDBusClientModule { ccode.add_label ("_error"); } - foreach (Parameter param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { if ((param.direction == ParameterDirection.IN && !ready) || (param.direction == ParameterDirection.OUT && !no_reply && (!m.coroutine || ready))) { if (param.variable_type is ObjectType && param.variable_type.data_type.get_full_name () == "GLib.Cancellable") { - continue; + return true; } if (param.variable_type is ObjectType && param.variable_type.data_type.get_full_name () == "GLib.BusName") { // ignore BusName sender parameters - continue; + return true; } var owned_type = param.variable_type.copy (); @@ -393,7 +396,8 @@ public class Vala.GDBusServerModule : GDBusClientModule { ccode.add_expression (destroy_local (local)); } } - } + return true; + }); pop_function (); @@ -416,7 +420,7 @@ public class Vala.GDBusServerModule : GDBusClientModule { function.add_parameter (new CCodeParameter ("_sender", "GObject*")); - foreach (var param in sig.get_parameters ()) { + sig.get_parameters ().foreach ((param) => { // ensure ccodenode of parameter is set var cparam = generate_parameter (param, cfile, new HashMap (), null); @@ -427,7 +431,8 @@ public class Vala.GDBusServerModule : GDBusClientModule { function.add_parameter (new CCodeParameter (get_parameter_array_length_cname (param, dim), "int")); } } - } + return true; + }); function.add_parameter (new CCodeParameter ("_data", "gpointer*")); @@ -443,14 +448,15 @@ public class Vala.GDBusServerModule : GDBusClientModule { builder_init.add_argument (new CCodeIdentifier ("G_VARIANT_TYPE_TUPLE")); ccode.add_expression (builder_init); - foreach (Parameter param in sig.get_parameters ()) { + sig.get_parameters ().foreach ((param) => { string param_name = get_variable_cname (param.name); CCodeExpression expr = new CCodeIdentifier (param_name); if (param.variable_type.is_real_struct_type ()) { expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, expr); } write_expression (param.variable_type, new CCodeIdentifier ("_arguments_builder"), expr, param); - } + return true; + }); var builder_end = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_builder_end")); builder_end.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_arguments_builder"))); @@ -597,12 +603,12 @@ public class Vala.GDBusServerModule : GDBusClientModule { return; } - foreach (Signal sig in sym.get_signals ()) { + sym.get_signals ().foreach ((sig) => { if (sig.access != SymbolAccessibility.PUBLIC) { - continue; + return true; } if (!is_dbus_visible (sig)) { - continue; + return true; } if (connect) { @@ -620,7 +626,8 @@ public class Vala.GDBusServerModule : GDBusClientModule { disconnect_call.add_argument (new CCodeIdentifier ("data")); ccode.add_expression (disconnect_call); } - } + return true; + }); } void generate_interface_method_call_function (ObjectTypeSymbol sym) { @@ -643,13 +650,13 @@ public class Vala.GDBusServerModule : GDBusClientModule { bool first = true; - foreach (Method m in sym.get_methods ()) { + sym.get_methods ().foreach ((m) => { if (m is CreationMethod || m.binding != MemberBinding.INSTANCE || m.overrides || m.access != SymbolAccessibility.PUBLIC) { - continue; + return true; } if (!is_dbus_visible (m)) { - continue; + return true; } cfile.add_include ("string.h"); @@ -670,7 +677,8 @@ public class Vala.GDBusServerModule : GDBusClientModule { ccall.add_argument (new CCodeIdentifier ("parameters")); ccall.add_argument (new CCodeIdentifier ("invocation")); ccode.add_expression (ccall); - } + return true; + }); if (!first) { ccode.add_else (); @@ -712,16 +720,16 @@ public class Vala.GDBusServerModule : GDBusClientModule { bool firstif = true; - foreach (Property prop in sym.get_properties ()) { + sym.get_properties ().foreach ((prop) => { if (prop.binding != MemberBinding.INSTANCE || prop.overrides || prop.access != SymbolAccessibility.PUBLIC) { - continue; + return true; } if (!is_dbus_visible (prop)) { - continue; + return true; } if (prop.get_accessor == null) { - continue; + return true; } cfile.add_include ("string.h"); @@ -742,7 +750,8 @@ public class Vala.GDBusServerModule : GDBusClientModule { ccall.add_argument (new CCodeIdentifier ("object")); ccode.add_return (ccall); - } + return true; + }); if (!firstif) { ccode.close (); } @@ -776,16 +785,16 @@ public class Vala.GDBusServerModule : GDBusClientModule { bool firstif = true; - foreach (Property prop in sym.get_properties ()) { + sym.get_properties ().foreach ((prop) => { if (prop.binding != MemberBinding.INSTANCE || prop.overrides || prop.access != SymbolAccessibility.PUBLIC) { - continue; + return true; } if (!is_dbus_visible (prop)) { - continue; + return true; } if (prop.set_accessor == null) { - continue; + return true; } cfile.add_include ("string.h"); @@ -808,7 +817,8 @@ public class Vala.GDBusServerModule : GDBusClientModule { ccode.add_expression (ccall); ccode.add_return (new CCodeConstant ("TRUE")); - } + return true; + }); if (!firstif) { ccode.close (); } diff --git a/codegen/valagerrormodule.vala b/codegen/valagerrormodule.vala index 47056f17b..9e78b71bf 100644 --- a/codegen/valagerrormodule.vala +++ b/codegen/valagerrormodule.vala @@ -35,14 +35,15 @@ public class Vala.GErrorModule : CCodeDelegateModule { var cenum = new CCodeEnum (get_ccode_name (edomain)); - foreach (ErrorCode ecode in edomain.get_codes ()) { + edomain.get_codes ().foreach ((ecode) => { if (ecode.value == null) { cenum.add_value (new CCodeEnumValue (get_ccode_name (ecode))); } else { ecode.value.emit (this); cenum.add_value (new CCodeEnumValue (get_ccode_name (ecode), get_cvalue (ecode.value))); } - } + return true; + }); decl_space.add_type_definition (cenum); @@ -191,31 +192,34 @@ public class Vala.GErrorModule : CCodeDelegateModule { } var error_types = new ArrayList (); - foreach (DataType node_error_type in node.get_error_types ()) { + node.get_error_types ().foreach ((node_error_type) => { error_types.add (node_error_type); - } + return true; + }); bool has_general_catch_clause = false; if (!is_in_catch) { var handled_error_types = new ArrayList (); - foreach (CatchClause clause in current_try.get_catch_clauses ()) { + current_try.get_catch_clauses ().foreach ((clause) => { // keep track of unhandled error types - foreach (DataType node_error_type in error_types) { + error_types.foreach ((node_error_type) => { if (clause.error_type == null || node_error_type.compatible (clause.error_type)) { handled_error_types.add (node_error_type); } - } - foreach (DataType handled_error_type in handled_error_types) { + return true; + }); + handled_error_types.foreach ((handled_error_type) => { error_types.remove (handled_error_type); - } + return true; + }); handled_error_types.clear (); if (clause.error_type.equals (gerror_type)) { // general catch clause, this should be the last one has_general_catch_clause = true; ccode.add_goto (clause.clabel_name); - break; + return false; } else { var catch_type = clause.error_type as ErrorType; @@ -240,7 +244,8 @@ public class Vala.GErrorModule : CCodeDelegateModule { ccode.add_goto (clause.clabel_name); ccode.close (); } - } + return true; + }); } if (has_general_catch_clause) { @@ -262,11 +267,11 @@ public class Vala.GErrorModule : CCodeDelegateModule { // current method can fail, propagate error CCodeBinaryExpression ccond = null; - foreach (DataType error_type in current_method.get_error_types ()) { + current_method.get_error_types ().foreach ((error_type) => { // If GLib.Error is allowed we propagate everything if (error_type.equals (gerror_type)) { ccond = null; - break; + return false; } // Check the allowed error domains to propagate @@ -277,7 +282,8 @@ public class Vala.GErrorModule : CCodeDelegateModule { } else { ccond = new CCodeBinaryExpression (CCodeBinaryOperator.OR, ccond, domain_check); } - } + return true; + }); if (ccond != null) { ccode.open_if (ccond); @@ -309,19 +315,21 @@ public class Vala.GErrorModule : CCodeDelegateModule { current_try_id = this_try_id; is_in_catch = true; - foreach (CatchClause clause in stmt.get_catch_clauses ()) { + stmt.get_catch_clauses ().foreach ((clause) => { clause.clabel_name = "__catch%d_%s".printf (this_try_id, get_ccode_lower_case_name (clause.error_type)); - } + return true; + }); is_in_catch = false; stmt.body.emit (this); is_in_catch = true; - foreach (CatchClause clause in stmt.get_catch_clauses ()) { + stmt.get_catch_clauses ().foreach ((clause) => { current_catch = clause; ccode.add_goto ("__finally%d".printf (this_try_id)); clause.emit (this); - } + return true; + }); current_try = old_try; current_try_id = old_try_id; diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala index 5e656f0ce..3ebc51772 100644 --- a/codegen/valagirwriter.vala +++ b/codegen/valagirwriter.vala @@ -126,12 +126,13 @@ public class Vala.GIRWriter : CodeVisitor { private ArrayList externals = new ArrayList ((a, b) => { return a.equal (b); }); public void write_includes() { - foreach (var i in externals) { + externals.foreach ((i) => { if (i.ns != this.gir_namespace) { write_indent_stream (); stream.printf ("\n", i.ns, i.version); } - } + return true; + }); } @@ -183,15 +184,17 @@ public class Vala.GIRWriter : CodeVisitor { stream.puts (buffer.str); stream = null; - foreach (var ns in unannotated_namespaces) { + unannotated_namespaces.foreach ((ns) => { if (!our_namespaces.contains(ns)) { Report.warning (ns.source_reference, "Namespace %s does not have a GIR namespace and version annotation".printf (ns.name)); } - } - foreach (var ns in our_namespaces) { + return true; + }); + our_namespaces.foreach ((ns) => { ns.source_reference.file.gir_namespace = gir_namespace; ns.source_reference.file.gir_version = gir_version; - } + return true; + }); if (our_namespaces.size == 0) { Report.error (null, "No suitable namespace found to export for GIR"); @@ -325,13 +328,14 @@ public class Vala.GIRWriter : CodeVisitor { write_doc (get_class_comment (cl)); // write implemented interfaces - foreach (DataType base_type in cl.get_base_types ()) { + cl.get_base_types ().foreach ((base_type) => { var object_type = (ObjectType) base_type; if (object_type.type_symbol is Interface) { write_indent (); buffer.append_printf ("\n", gi_type_name (object_type.type_symbol)); } - } + return true; + }); write_annotations (cl); @@ -377,7 +381,7 @@ public class Vala.GIRWriter : CodeVisitor { write_indent (); buffer.append_printf ("\n"); - foreach (Method m in cl.get_methods ()) { + cl.get_methods ().foreach ((m) => { if (m.is_abstract || m.is_virtual) { write_indent (); if (m.coroutine) { @@ -412,9 +416,10 @@ public class Vala.GIRWriter : CodeVisitor { buffer.append_printf ("\n"); } } - } + return true; + }); - foreach (Signal sig in cl.get_signals ()) { + cl.get_signals ().foreach ((sig) => { if (sig.default_handler != null) { write_indent (); buffer.append_printf ("\n", sig.name); @@ -424,7 +429,8 @@ public class Vala.GIRWriter : CodeVisitor { write_indent (); buffer.append_printf ("\n"); } - } + return true; + }); indent--; write_indent (); @@ -518,10 +524,11 @@ public class Vala.GIRWriter : CodeVisitor { // write prerequisites if (iface.get_prerequisites ().size > 0) { - foreach (DataType base_type in iface.get_prerequisites ()) { + iface.get_prerequisites ().foreach ((base_type) => { write_indent (); buffer.append_printf ("\n", gi_type_name (((ObjectType) base_type).type_symbol)); - } + return true; + }); } write_annotations (iface); @@ -550,7 +557,7 @@ public class Vala.GIRWriter : CodeVisitor { write_indent (); buffer.append_printf ("\n"); - foreach (Method m in iface.get_methods ()) { + iface.get_methods ().foreach ((m) => { if (m.is_abstract || m.is_virtual) { if (m.coroutine) { string finish_name = m.name; @@ -584,9 +591,10 @@ public class Vala.GIRWriter : CodeVisitor { buffer.append_printf ("\n"); } } - } + return true; + }); - foreach (var prop in iface.get_properties ()) { + iface.get_properties ().foreach ((prop) => { if (prop.is_abstract || prop.is_virtual) { if (prop.get_accessor != null) { var m = prop.get_accessor.get_method (); @@ -610,7 +618,8 @@ public class Vala.GIRWriter : CodeVisitor { buffer.append_printf ("\n"); } } - } + return true; + }); indent--; write_indent (); @@ -623,9 +632,10 @@ public class Vala.GIRWriter : CodeVisitor { var nodes = this.deferred; this.deferred = new ArrayList(); - foreach (var node in nodes) { + nodes.foreach ((node) => { node.accept (this); - } + return true; + }); } private string? get_gir_name (Symbol symbol) { @@ -873,11 +883,12 @@ public class Vala.GIRWriter : CodeVisitor { index++; } - foreach (Parameter param in params) { + params.foreach ((param) => { index++; skip_implicit_params (param.variable_type, ref index, CCodeBaseModule.get_ccode_array_length (param)); - } + return true; + }); if (ret_is_struct) { index++; @@ -904,11 +915,12 @@ public class Vala.GIRWriter : CodeVisitor { write_param_or_return (instance_type, true, ref index, false, "self"); } - foreach (Parameter param in params) { + params.foreach ((param) => { write_param_or_return (param.variable_type, true, ref index, CCodeBaseModule.get_ccode_array_length (param), param.name, get_parameter_comment (param), param.direction); write_implicit_params (param.variable_type, ref index, CCodeBaseModule.get_ccode_array_length (param), param.name, param.direction); - } + return true; + }); if (ret_is_struct) { // struct returns are converted to parameters @@ -1238,9 +1250,10 @@ public class Vala.GIRWriter : CodeVisitor { if ((type.value_owned && delegate_type == null) || (constructor && !type.data_type.is_subtype_of (ginitiallyunowned_type))) { var any_owned = false; - foreach (var generic_arg in type.get_type_arguments ()) { + type.get_type_arguments ().foreach ((generic_arg) => { any_owned |= generic_arg.value_owned; - } + return true; + }); if (type.has_type_arguments () && !any_owned) { buffer.append_printf (" transfer-ownership=\"container\""); } else { @@ -1340,9 +1353,10 @@ public class Vala.GIRWriter : CodeVisitor { buffer.append_printf (">\n"); indent++; - foreach (DataType type_argument in type_arguments) { + type_arguments.foreach ((type_argument) => { write_type (type_argument); - } + return true; + }); indent--; write_indent (); @@ -1365,7 +1379,7 @@ public class Vala.GIRWriter : CodeVisitor { private void write_annotations (CodeNode node) { foreach (Attribute attr in node.attributes) { string name = camel_case_to_canonical (attr.name); - foreach (string arg_name in attr.args.keys) { + attr.args.keys.foreach ((arg_name) => { string value = attr.args.get (arg_name); if (value.has_prefix ("\"")) { // eval string @@ -1375,7 +1389,8 @@ public class Vala.GIRWriter : CodeVisitor { write_indent (); buffer.append_printf ("\n", name, camel_case_to_canonical (arg_name), value); - } + return true; + }); } } diff --git a/codegen/valagobjectmodule.vala b/codegen/valagobjectmodule.vala index 33bb87805..2f9ae12d1 100644 --- a/codegen/valagobjectmodule.vala +++ b/codegen/valagobjectmodule.vala @@ -74,7 +74,7 @@ public class Vala.GObjectModule : GTypeModule { } /* create type, dup_func, and destroy_func properties for generic types */ - foreach (TypeParameter type_param in cl.get_type_parameters ()) { + cl.get_type_parameters ().foreach ((type_param) => { string func_name, enum_value; CCodeConstant func_name_constant; CCodeFunctionCall cinst, cspec; @@ -129,13 +129,14 @@ public class Vala.GObjectModule : GTypeModule { cinst.add_argument (cspec); ccode.add_expression (cinst); prop_enum.add_value (new CCodeEnumValue (enum_value)); - } + return true; + }); /* create properties */ var props = cl.get_properties (); - foreach (Property prop in props) { + props.foreach ((prop) => { if (!is_gobject_property (prop)) { - continue; + return true; } if (prop.comment != null) { @@ -148,25 +149,20 @@ public class Vala.GObjectModule : GTypeModule { cinst.add_argument (get_param_spec (prop)); ccode.add_expression (cinst); - } + return true; + }); } private bool class_has_readable_properties (Class cl) { - foreach (Property prop in cl.get_properties ()) { - if (prop.get_accessor != null) { - return true; - } - } - return false; + return !cl.get_properties ().foreach ((prop) => { + return (prop.get_accessor == null); + }); } private bool class_has_writable_properties (Class cl) { - foreach (Property prop in cl.get_properties ()) { - if (prop.set_accessor != null) { - return true; - } - } - return false; + return !cl.get_properties ().foreach ((prop) => { + return (prop.set_accessor == null); + }); } private void add_guarded_expression (Symbol sym, CCodeExpression expression) { @@ -195,13 +191,13 @@ public class Vala.GObjectModule : GTypeModule { ccode.open_switch (new CCodeIdentifier ("property_id")); var props = cl.get_properties (); - foreach (Property prop in props) { + props.foreach ((prop) => { if (prop.get_accessor == null || prop.is_abstract) { - continue; + return true; } if (!is_gobject_property (prop)) { // don't register private properties - continue; + return true; } Property base_prop = prop; @@ -275,7 +271,8 @@ public class Vala.GObjectModule : GTypeModule { } } ccode.add_break (); - } + return true; + }); ccode.add_default (); emit_invalid_property_id_warn (); ccode.add_break (); @@ -303,12 +300,12 @@ public class Vala.GObjectModule : GTypeModule { ccode.open_switch (new CCodeIdentifier ("property_id")); var props = cl.get_properties (); - foreach (Property prop in props) { + props.foreach ((prop) => { if (prop.set_accessor == null || prop.is_abstract) { - continue; + return true; } if (!is_gobject_property (prop)) { - continue; + return true; } Property base_prop = prop; @@ -367,10 +364,11 @@ public class Vala.GObjectModule : GTypeModule { add_guarded_expression (prop, ccall); } ccode.add_break (); - } + return true; + }); /* type, dup func, and destroy func properties for generic types */ - foreach (TypeParameter type_param in cl.get_type_parameters ()) { + cl.get_type_parameters ().foreach ((type_param) => { string func_name, enum_value; CCodeMemberAccess cfield; CCodeFunctionCall cgetcall; @@ -401,7 +399,8 @@ public class Vala.GObjectModule : GTypeModule { cgetcall.add_argument (new CCodeIdentifier ("value")); ccode.add_assignment (cfield, cgetcall); ccode.add_break (); - } + return true; + }); ccode.add_default (); emit_invalid_property_id_warn (); ccode.add_break (); @@ -783,26 +782,27 @@ public class Vala.GObjectModule : GTypeModule { } else if (ma.symbol_reference == gobject_type) { // Object (...) chain up // check it's only used with valid properties - foreach (var arg in expr.get_argument_list ()) { + expr.get_argument_list ().foreach ((arg) => { var named_argument = arg as NamedArgument; if (named_argument == null) { Report.error (arg.source_reference, "Named argument expected"); - break; + return false; } var prop = SemanticAnalyzer.symbol_lookup_inherited (current_class, named_argument.name) as Property; if (prop == null) { Report.error (arg.source_reference, "Property `%s' not found in `%s'".printf (named_argument.name, current_class.get_full_name ())); - break; + return false; } if (!is_gobject_property (prop)) { Report.error (arg.source_reference, "Property `%s' not supported in Object (property: value) constructor chain up".printf (named_argument.name)); - break; + return false; } if (!arg.value_type.compatible (prop.property_type)) { Report.error (arg.source_reference, "Cannot convert from `%s' to `%s'".printf (arg.value_type.to_string (), prop.property_type.to_string ())); - break; + return false; } - } + return true; + }); } pop_line (); diff --git a/codegen/valagsignalmodule.vala b/codegen/valagsignalmodule.vala index 00c06c196..a8521806c 100644 --- a/codegen/valagsignalmodule.vala +++ b/codegen/valagsignalmodule.vala @@ -45,9 +45,10 @@ public class Vala.GSignalModule : GObjectModule { if (params == null || params.size == 0) { ret = ret + "_VOID"; } else { - foreach (Parameter p in params) { + params.foreach ((p) => { ret = "%s_%s".printf (ret, get_ccode_marshaller_type_name (p).replace (",", "_")); - } + return true; + }); } return ret; @@ -102,14 +103,15 @@ public class Vala.GSignalModule : GObjectModule { signature = signature + "VOID"; } else { bool first = true; - foreach (Parameter p in params) { + params.foreach ((p) => { if (first) { signature = signature + get_ccode_marshaller_type_name (p); first = false; } else { signature = "%s,%s".printf (signature, get_ccode_marshaller_type_name (p)); } - } + return true; + }); } return signature; @@ -194,9 +196,10 @@ public class Vala.GSignalModule : GObjectModule { sig.accept_children (this); // declare parameter type - foreach (Parameter p in sig.get_parameters ()) { + sig.get_parameters ().foreach ((p) => { generate_parameter (p, cfile, new HashMap (), null); - } + return true; + }); generate_marshaller (sig.get_parameters (), sig.return_type); } @@ -226,7 +229,7 @@ public class Vala.GSignalModule : GObjectModule { var callback_decl = new CCodeFunctionDeclarator (get_marshaller_function (params, return_type, "GMarshalFunc")); callback_decl.add_parameter (new CCodeParameter ("data1", "gpointer")); n_params = 1; - foreach (Parameter p in params) { + params.foreach ((p) => { callback_decl.add_parameter (new CCodeParameter ("arg_%d".printf (n_params), get_value_type_name_from_parameter (p))); n_params++; if (p.variable_type.is_array ()) { @@ -235,7 +238,8 @@ public class Vala.GSignalModule : GObjectModule { n_params++; } } - } + return true; + }); callback_decl.add_parameter (new CCodeParameter ("data2", "gpointer")); ccode.add_statement (new CCodeTypeDefinition (get_value_type_name_from_type_reference (return_type), callback_decl)); @@ -278,7 +282,7 @@ public class Vala.GSignalModule : GObjectModule { fc = new CCodeFunctionCall (new CCodeIdentifier ("callback")); fc.add_argument (new CCodeIdentifier ("data1")); i = 1; - foreach (Parameter p in params) { + params.foreach ((p) => { string get_value_function; bool is_array = p.variable_type.is_array (); if (p.direction != ParameterDirection.IN) { @@ -310,7 +314,8 @@ public class Vala.GSignalModule : GObjectModule { i++; } } - } + return true; + }); fc.add_argument (new CCodeIdentifier ("data2")); if (return_type.data_type != null || return_type.is_array ()) { @@ -421,15 +426,16 @@ public class Vala.GSignalModule : GObjectModule { } int params_len = 0; - foreach (Parameter param in params) { + params.foreach ((param) => { params_len++; if (param.variable_type.is_array ()) { params_len += ((ArrayType) param.variable_type).rank; } - } + return true; + }); csignew.add_argument (new CCodeConstant ("%d".printf (params_len))); - foreach (Parameter param in params) { + params.foreach ((param) => { if (param.variable_type.is_array ()) { if (((ArrayType) param.variable_type).element_type.data_type == string_type.data_type) { csignew.add_argument (new CCodeConstant ("G_TYPE_STRV")); @@ -448,7 +454,8 @@ public class Vala.GSignalModule : GObjectModule { } else { csignew.add_argument (new CCodeConstant (get_ccode_type_id (param.variable_type.data_type))); } - } + return true; + }); marshal_arg.name = marshaller; diff --git a/codegen/valagtkmodule.vala b/codegen/valagtkmodule.vala index d8f09720c..b408048cb 100644 --- a/codegen/valagtkmodule.vala +++ b/codegen/valagtkmodule.vala @@ -44,14 +44,16 @@ public class Vala.GtkModule : GSignalModule { } private void recurse_cclass_to_vala_map (Namespace ns) { - foreach (var cl in ns.get_classes()) { + ns.get_classes().foreach ((cl) => { if (!cl.is_compact) { cclass_to_vala_map.set (get_ccode_name (cl), cl); } - } - foreach (var inner in ns.get_namespaces()) { + return true; + }); + ns.get_namespaces().foreach ((inner) => { recurse_cclass_to_vala_map (inner); - } + return true; + }); } private void ensure_gresource_to_file_map () { diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala index 02050a5aa..9fc1966e0 100644 --- a/codegen/valagtypemodule.vala +++ b/codegen/valagtypemodule.vala @@ -201,12 +201,13 @@ public class Vala.GTypeModule : GErrorModule { // base class declaration generate_class_struct_declaration (cl.base_class, decl_space); } - foreach (DataType base_type in cl.get_base_types ()) { + cl.get_base_types ().foreach ((base_type) => { var iface = base_type.data_type as Interface; if (iface != null) { generate_interface_declaration (iface, decl_space); } - } + return true; + }); generate_class_declaration (cl, decl_space); @@ -245,19 +246,21 @@ public class Vala.GTypeModule : GErrorModule { } } - foreach (Method m in cl.get_methods ()) { + cl.get_methods ().foreach ((m) => { generate_virtual_method_declaration (m, decl_space, type_struct); - } + return true; + }); - foreach (Signal sig in cl.get_signals ()) { + cl.get_signals ().foreach ((sig) => { if (sig.default_handler != null) { generate_virtual_method_declaration (sig.default_handler, decl_space, type_struct); } - } + return true; + }); - foreach (Property prop in cl.get_properties ()) { + cl.get_properties ().foreach ((prop) => { if (!prop.is_abstract && !prop.is_virtual) { - continue; + return true; } generate_type_declaration (prop.property_type, decl_space); @@ -316,9 +319,10 @@ public class Vala.GTypeModule : GErrorModule { vdecl.add_declarator (vdeclarator); type_struct.add_declaration (vdecl); } - } + return true; + }); - foreach (Field f in cl.get_fields ()) { + cl.get_fields ().foreach ((f) => { if (f.access != SymbolAccessibility.PRIVATE) { CCodeModifiers modifiers = (f.is_volatile ? CCodeModifiers.VOLATILE : 0) | (f.version.deprecated ? CCodeModifiers.DEPRECATED : 0); if (f.binding == MemberBinding.INSTANCE) { @@ -360,7 +364,8 @@ public class Vala.GTypeModule : GErrorModule { type_struct.add_field (get_ccode_name (f.variable_type), get_ccode_name (f), modifiers); } } - } + return true; + }); if (!cl.is_compact || cl.base_class == null || is_gsource) { // derived compact classes do not have a struct @@ -417,7 +422,7 @@ public class Vala.GTypeModule : GErrorModule { if (is_gtypeinstance) { /* create type, dup_func, and destroy_func fields for generic types */ - foreach (TypeParameter type_param in cl.get_type_parameters ()) { + cl.get_type_parameters ().foreach ((type_param) => { string func_name; func_name = "%s_type".printf (type_param.name.down ()); @@ -428,11 +433,13 @@ public class Vala.GTypeModule : GErrorModule { func_name = "%s_destroy_func".printf (type_param.name.down ()); instance_priv_struct.add_field ("GDestroyNotify", func_name); - } + return true; + }); } - foreach (Field f in cl.get_fields ()) { + cl.get_fields ().foreach ((f) => { CCodeModifiers modifiers = (f.is_volatile ? CCodeModifiers.VOLATILE : 0) | (f.version.deprecated ? CCodeModifiers.DEPRECATED : 0); + if (f.binding == MemberBinding.INSTANCE) { if (f.access == SymbolAccessibility.PRIVATE) { generate_type_declaration (f.variable_type, decl_space); @@ -486,9 +493,10 @@ public class Vala.GTypeModule : GErrorModule { type_priv_struct.add_field (get_ccode_name (mutex_type), get_symbol_lock_name (get_ccode_name (f))); } } - } + return true; + }); - foreach (Property prop in cl.get_properties ()) { + cl.get_properties ().foreach ((prop) => { if (prop.binding == MemberBinding.INSTANCE) { if (prop.get_lock_used ()) { cl.has_private_fields = true; @@ -502,7 +510,8 @@ public class Vala.GTypeModule : GErrorModule { type_priv_struct.add_field (get_ccode_name (mutex_type), get_symbol_lock_name (prop.name)); } } - } + return true; + }); if (is_gtypeinstance) { if (cl.has_class_private_fields || has_class_locks) { @@ -654,11 +663,12 @@ public class Vala.GTypeModule : GErrorModule { add_class_finalize_function (cl); } - foreach (DataType base_type in cl.get_base_types ()) { + cl.get_base_types ().foreach ((base_type) => { if (base_type.data_type is Interface) { add_interface_init_function (cl, (Interface) base_type.data_type); } - } + return true; + }); add_instance_init_function (cl); @@ -1214,9 +1224,9 @@ public class Vala.GTypeModule : GErrorModule { } /* connect overridden methods */ - foreach (Method m in cl.get_methods ()) { + cl.get_methods ().foreach ((m) => { if (m.base_method == null) { - continue; + return true; } var base_type = (ObjectTypeSymbol) m.base_method.parent_symbol; @@ -1233,21 +1243,23 @@ public class Vala.GTypeModule : GErrorModule { ccode.add_assignment (new CCodeMemberAccess.pointer (ccast, get_ccode_finish_vfunc_name (m.base_method)), cfunc); } } - } + return true; + }); /* connect default signal handlers */ - foreach (Signal sig in cl.get_signals ()) { + cl.get_signals ().foreach ((sig) => { if (sig.default_handler == null) { - continue; + return true; } var ccast = new CCodeCastExpression (new CCodeIdentifier ("klass"), "%sClass *".printf (get_ccode_name (cl))); ccode.add_assignment (new CCodeMemberAccess.pointer (ccast, get_ccode_vfunc_name (sig.default_handler)), new CCodeIdentifier (get_ccode_real_name (sig.default_handler))); - } + return true; + }); /* connect overridden properties */ - foreach (Property prop in cl.get_properties ()) { + cl.get_properties ().foreach ((prop) => { if (prop.base_property == null) { - continue; + return true; } var base_type = prop.base_property.parent_symbol; @@ -1264,18 +1276,20 @@ public class Vala.GTypeModule : GErrorModule { ccode.add_assignment (new CCodeMemberAccess.pointer (ccast, "set_%s".printf (prop.name)), new CCodeIdentifier (cname)); } } - } + return true; + }); generate_class_init (cl); if (!cl.is_compact) { /* create signals */ - foreach (Signal sig in cl.get_signals ()) { + cl.get_signals ().foreach ((sig) => { if (sig.comment != null) { ccode.add_statement (new CCodeComment (sig.comment.content)); } ccode.add_expression (get_signal_creation (sig, cl)); - } + return true; + }); } pop_context (); @@ -1327,14 +1341,14 @@ public class Vala.GTypeModule : GErrorModule { ccall.add_argument (new CCodeIdentifier ("iface")); ccode.add_assignment (new CCodeIdentifier (parent_iface_var), ccall); - foreach (Method m in cl.get_methods ()) { + cl.get_methods ().foreach ((m) => { if (m.base_interface_method == null) { - continue; + return true; } var base_type = m.base_interface_method.parent_symbol; if (base_type != iface) { - continue; + return true; } var ciface = new CCodeIdentifier ("iface"); @@ -1356,10 +1370,11 @@ public class Vala.GTypeModule : GErrorModule { cfunc = cast_method_pointer (m.base_interface_method, cfunc, iface, 2); ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, get_ccode_finish_vfunc_name (m.base_interface_method)), cfunc); } - } + return true; + }); if (iface.get_attribute ("GenericAccessors") != null) { - foreach (TypeParameter p in iface.get_type_parameters ()) { + iface.get_type_parameters ().foreach ((p) => { GenericType p_type = new GenericType (p); DataType p_data_type = p_type.get_actual_type (get_data_type_for_symbol (cl), null, cl); @@ -1377,11 +1392,12 @@ public class Vala.GTypeModule : GErrorModule { "GDestroyNotify", get_destroy_func_expression (p_data_type), p, cl, iface); - } + return true; + }); } // connect inherited implementations - foreach (Method m in iface.get_methods ()) { + iface.get_methods ().foreach ((m) => { if (m.is_abstract) { Method cl_method = null; var base_class = cl; @@ -1407,16 +1423,17 @@ public class Vala.GTypeModule : GErrorModule { ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, get_ccode_vfunc_name (m)), cfunc); } } - } + return true; + }); - foreach (Property prop in cl.get_properties ()) { + cl.get_properties ().foreach ((prop) => { if (prop.base_interface_property == null) { - continue; + return true; } var base_type = (ObjectTypeSymbol) prop.base_interface_property.parent_symbol; if (base_type != iface) { - continue; + return true; } var ciface = new CCodeIdentifier ("iface"); @@ -1447,11 +1464,12 @@ public class Vala.GTypeModule : GErrorModule { ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, "set_%s".printf (prop.name)), cfunc); } } - } + return true; + }); - foreach (Property prop in iface.get_properties ()) { + iface.get_properties ().foreach ((prop) => { if (!prop.is_abstract) { - continue; + return true; } Property cl_prop = null; @@ -1489,7 +1507,8 @@ public class Vala.GTypeModule : GErrorModule { ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, "set_%s".printf (prop.name)), cfunc); } } - } + return true; + }); pop_function (); cfile.add_function (iface_init); @@ -1930,7 +1949,7 @@ public class Vala.GTypeModule : GErrorModule { return; } - foreach (DataType prerequisite in iface.get_prerequisites ()) { + iface.get_prerequisites ().foreach ((prerequisite) => { var prereq_cl = prerequisite.data_type as Class; var prereq_iface = prerequisite.data_type as Interface; if (prereq_cl != null) { @@ -1938,7 +1957,8 @@ public class Vala.GTypeModule : GErrorModule { } else if (prereq_iface != null) { generate_interface_declaration (prereq_iface, decl_space); } - } + return true; + }); var type_struct = new CCodeStruct ("_%s".printf (get_ccode_type_name (iface))); @@ -1962,7 +1982,7 @@ public class Vala.GTypeModule : GErrorModule { type_struct.add_field ("GTypeInterface", "parent_iface"); if (iface.get_attribute ("GenericAccessors") != null) { - foreach (TypeParameter p in iface.get_type_parameters ()) { + iface.get_type_parameters ().foreach ((p) => { string method_name = "get_%s_type".printf (p.name.down ()); var vdeclarator = new CCodeFunctionDeclarator (method_name); var this_type = get_data_type_for_symbol (iface); @@ -1989,10 +2009,11 @@ public class Vala.GTypeModule : GErrorModule { vdecl = new CCodeDeclaration ("GDestroyNotify"); vdecl.add_declarator (vdeclarator); type_struct.add_declaration (vdecl); - } + return true; + }); } - foreach (Symbol sym in iface.get_virtuals ()) { + iface.get_virtuals ().foreach ((sym) => { Method m; Signal sig; Property prop; @@ -2060,7 +2081,8 @@ public class Vala.GTypeModule : GErrorModule { } else { assert_not_reached (); } - } + return true; + }); decl_space.add_type_definition (type_struct); @@ -2139,10 +2161,10 @@ public class Vala.GTypeModule : GErrorModule { if (iface.is_subtype_of (gobject_type)) { /* create properties */ var props = iface.get_properties (); - foreach (Property prop in props) { + props.foreach ((prop) => { if (prop.is_abstract) { if (!is_gobject_property (prop)) { - continue; + return true; } if (prop.comment != null) { @@ -2155,30 +2177,33 @@ public class Vala.GTypeModule : GErrorModule { ccode.add_expression (cinst); } - } + return true; + }); } var ciface = new CCodeIdentifier ("iface"); /* connect default signal handlers */ - foreach (Signal sig in iface.get_signals ()) { + iface.get_signals ().foreach ((sig) => { if (sig.default_handler == null) { - continue; + return true; } var cname = get_ccode_real_name (sig.default_handler); ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, get_ccode_vfunc_name (sig.default_handler)), new CCodeIdentifier (cname)); - } + return true; + }); /* create signals */ - foreach (Signal sig in iface.get_signals ()) { + iface.get_signals ().foreach ((sig) => { if (sig.comment != null) { ccode.add_statement (new CCodeComment (sig.comment.content)); } ccode.add_expression (get_signal_creation (sig, iface)); - } + return true; + }); // connect default implementations - foreach (Method m in iface.get_methods ()) { + iface.get_methods ().foreach ((m) => { if (m.is_virtual) { var cname = get_ccode_real_name (m); ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, get_ccode_vfunc_name (m)), new CCodeIdentifier (cname)); @@ -2186,9 +2211,10 @@ public class Vala.GTypeModule : GErrorModule { ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, get_ccode_finish_vfunc_name (m)), new CCodeIdentifier (get_ccode_finish_real_name (m))); } } - } + return true; + }); - foreach (Property prop in iface.get_properties ()) { + iface.get_properties ().foreach ((prop) => { if (prop.is_virtual) { if (prop.get_accessor != null) { string cname = CCodeBaseModule.get_ccode_real_name (prop.get_accessor); @@ -2199,7 +2225,8 @@ public class Vala.GTypeModule : GErrorModule { ccode.add_assignment (new CCodeMemberAccess.pointer (ciface, "set_%s".printf (prop.name)), new CCodeIdentifier (cname)); } } - } + return true; + }); ccode.close (); diff --git a/codegen/valagvariantmodule.vala b/codegen/valagvariantmodule.vala index b50aca02c..d5ce8b886 100644 --- a/codegen/valagvariantmodule.vala +++ b/codegen/valagvariantmodule.vala @@ -101,11 +101,12 @@ public class Vala.GVariantModule : GAsyncModule { if (sig == null && st != null) { var str = new StringBuilder (); str.append_c ('('); - foreach (Field f in st.get_fields ()) { + st.get_fields ().foreach ((f) => { if (f.binding == MemberBinding.INSTANCE) { str.append (get_type_signature (f.variable_type, f)); } - } + return true; + }); str.append_c (')'); sig = str.str; } else if (sig == null && en != null) { @@ -119,12 +120,13 @@ public class Vala.GVariantModule : GAsyncModule { var type_args = datatype.get_type_arguments (); if (sig != null && "%s" in sig && type_args.size > 0) { string element_sig = ""; - foreach (DataType type_arg in type_args) { + type_args.foreach ((type_arg) => { var s = get_type_signature (type_arg); if (s != null) { element_sig += s; } - } + return true; + }); sig = sig.replace ("%s", element_sig); } @@ -220,7 +222,7 @@ public class Vala.GVariantModule : GAsyncModule { ccode.add_declaration (get_ccode_name (en), new CCodeVariableDeclarator.zero ("value", new CCodeConstant ("0"))); bool firstif = true; - foreach (EnumValue enum_value in en.get_values ()) { + en.get_values ().foreach ((enum_value) => { string dbus_value = get_dbus_value (enum_value, enum_value.name); var string_comparison = new CCodeFunctionCall (new CCodeIdentifier ("strcmp")); string_comparison.add_argument (new CCodeIdentifier ("str")); @@ -233,7 +235,8 @@ public class Vala.GVariantModule : GAsyncModule { ccode.else_if (cond); } ccode.add_assignment (new CCodeIdentifier ("value"), new CCodeIdentifier (get_ccode_name (enum_value))); - } + return true; + }); ccode.add_else (); var set_error = new CCodeFunctionCall (new CCodeIdentifier ("g_set_error")); @@ -360,15 +363,16 @@ public class Vala.GVariantModule : GAsyncModule { bool field_found = false;; - foreach (Field f in st.get_fields ()) { + st.get_fields ().foreach ((f) => { if (f.binding != MemberBinding.INSTANCE) { - continue; + return true; } field_found = true; read_expression (f.variable_type, new CCodeIdentifier (subiter_name), new CCodeMemberAccess (new CCodeIdentifier (temp_name), get_ccode_name (f)), f); - } + return true; + }); if (!field_found) { return null; @@ -555,12 +559,13 @@ public class Vala.GVariantModule : GAsyncModule { ccode.add_declaration ("const char *", new CCodeVariableDeclarator ("str")); ccode.open_switch (new CCodeIdentifier ("value")); - foreach (EnumValue enum_value in en.get_values ()) { + en.get_values ().foreach ((enum_value) => { string dbus_value = get_dbus_value (enum_value, enum_value.name); ccode.add_case (new CCodeIdentifier (get_ccode_name (enum_value))); ccode.add_assignment (new CCodeIdentifier ("str"), new CCodeConstant ("\"%s\"".printf (dbus_value))); ccode.add_break (); - } + return true; + }); ccode.close(); @@ -642,15 +647,16 @@ public class Vala.GVariantModule : GAsyncModule { bool field_found = false;; - foreach (Field f in st.get_fields ()) { + st.get_fields ().foreach ((f) => { if (f.binding != MemberBinding.INSTANCE) { - continue; + return true; } field_found = true; write_expression (f.variable_type, new CCodeIdentifier (builder_name), new CCodeMemberAccess (struct_expr, get_ccode_name (f)), f); - } + return true; + }); if (!field_found) { return null; diff --git a/codegen/valainterfaceregisterfunction.vala b/codegen/valainterfaceregisterfunction.vala index 0b900ea43..d2684f5cc 100644 --- a/codegen/valainterfaceregisterfunction.vala +++ b/codegen/valainterfaceregisterfunction.vala @@ -80,7 +80,7 @@ public class Vala.InterfaceRegisterFunction : TypeRegisterFunction { public override void get_type_interface_init_statements (CCodeBlock block, bool plugin) { /* register all prerequisites */ - foreach (DataType prereq_ref in interface_reference.get_prerequisites ()) { + interface_reference.get_prerequisites ().foreach ((prereq_ref) => { var prereq = prereq_ref.data_type; var func = new CCodeFunctionCall (new CCodeIdentifier ("g_type_interface_add_prerequisite")); @@ -88,7 +88,8 @@ public class Vala.InterfaceRegisterFunction : TypeRegisterFunction { func.add_argument (new CCodeIdentifier (CCodeBaseModule.get_ccode_type_id (prereq))); block.add_statement (new CCodeExpressionStatement (func)); - } + return true; + }); ((CCodeBaseModule) context.codegen).register_dbus_info (block, interface_reference); } diff --git a/codegen/valatyperegisterfunction.vala b/codegen/valatyperegisterfunction.vala index 5f8d2be0f..ce45c793f 100644 --- a/codegen/valatyperegisterfunction.vala +++ b/codegen/valatyperegisterfunction.vala @@ -161,13 +161,14 @@ public abstract class Vala.TypeRegisterFunction { var clist = new CCodeInitializerList (); /* or during visit time? */ CCodeInitializerList clist_ev = null; - foreach (EnumValue ev in en.get_values ()) { + en.get_values ().foreach ((ev) => { clist_ev = new CCodeInitializerList (); clist_ev.append (new CCodeConstant (CCodeBaseModule.get_ccode_name (ev))); clist_ev.append (new CCodeIdentifier ("\"%s\"".printf (CCodeBaseModule.get_ccode_name (ev)))); clist_ev.append (CCodeBaseModule.get_enum_value_canonical_cconstant (ev)); clist.append (clist_ev); - } + return true; + }); clist_ev = new CCodeInitializerList (); clist_ev.append (new CCodeConstant ("0")); diff --git a/vala/valaarraycreationexpression.vala b/vala/valaarraycreationexpression.vala index a43315788..ac61c7d29 100644 --- a/vala/valaarraycreationexpression.vala +++ b/vala/valaarraycreationexpression.vala @@ -94,9 +94,10 @@ public class Vala.ArrayCreationExpression : Expression { element_type.accept (visitor); } - foreach (Expression e in sizes) { + sizes.foreach ((e) => { e.accept (visitor); - } + return true; + }); if (initializer_list != null) { initializer_list.accept (visitor); @@ -196,9 +197,10 @@ public class Vala.ArrayCreationExpression : Expression { element_type.check (context); } - foreach (Expression e in sizes) { + sizes.foreach ((e) => { e.check (context); - } + return true; + }); var calc_sizes = new ArrayList (); if (initlist != null) { @@ -231,9 +233,10 @@ public class Vala.ArrayCreationExpression : Expression { /* this is an internal error because it is already handeld by the parser */ Report.error (source_reference, "internal error: initializer list expected"); } else { - foreach (Expression size in calc_sizes) { + calc_sizes.foreach ((size) => { append_size (size); - } + return true; + }); } } @@ -260,9 +263,10 @@ public class Vala.ArrayCreationExpression : Expression { } public override void emit (CodeGenerator codegen) { - foreach (Expression e in sizes) { + sizes.foreach ((e) => { e.emit (codegen); - } + return true; + }); if (initializer_list != null) { initializer_list.emit (codegen); diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala index 88e45ffda..ce09cd2e8 100644 --- a/vala/valaassignment.vala +++ b/vala/valaassignment.vala @@ -118,7 +118,7 @@ public class Vala.Assignment : Expression { int i = 0; ExpressionStatement stmt = null; - foreach (var expr in tuple.get_expressions ()) { + tuple.get_expressions ().foreach ((expr) => { if (stmt != null) { stmt.check (context); insert_statement (context.analyzer.insert_block, stmt); @@ -131,7 +131,8 @@ public class Vala.Assignment : Expression { stmt = new ExpressionStatement (assign, expr.source_reference); i++; - } + return true; + }); context.analyzer.replaced_nodes.add (this); parent_node.replace_expression (this, stmt.expression); @@ -203,9 +204,10 @@ public class Vala.Assignment : Expression { right.target_type = new DelegateType (sig.get_delegate (ma.inner.value_type, this)); } else if (ea.container.value_type.get_member ("set") is Method) { var set_call = new MethodCall (new MemberAccess (ea.container, "set", source_reference), source_reference); - foreach (Expression e in ea.get_indices ()) { + ea.get_indices ().foreach ((e) => { set_call.add_argument (e); - } + return true; + }); set_call.add_argument (right); parent_node.replace_expression (this, set_call); return set_call.check (context); @@ -285,14 +287,15 @@ public class Vala.Assignment : Expression { var right_ma = right as MemberAccess; if (dynamic_sig != null) { bool first = true; - foreach (Parameter param in dynamic_sig.handler.value_type.get_parameters ()) { + dynamic_sig.handler.value_type.get_parameters ().foreach ((param) => { if (first) { // skip sender parameter first = false; } else { dynamic_sig.add_parameter (param.copy ()); } - } + return true; + }); right.target_type = new DelegateType (sig.get_delegate (new ObjectType ((ObjectTypeSymbol) sig.parent_symbol), this)); } else if (!right.value_type.compatible (right.target_type)) { var delegate_type = (DelegateType) right.target_type; diff --git a/vala/valabaseaccess.vala b/vala/valabaseaccess.vala index 805854068..8d1fc877b 100644 --- a/vala/valabaseaccess.vala +++ b/vala/valabaseaccess.vala @@ -78,12 +78,13 @@ public class Vala.BaseAccess : Expression { Report.error (source_reference, "Base access invalid without base class"); return false; } else { - foreach (var base_type in context.analyzer.current_class.get_base_types ()) { + context.analyzer.current_class.get_base_types ().foreach ((base_type) => { if (base_type.data_type is Class) { value_type = base_type.copy (); value_type.value_owned = false; } - } + return true; + }); } symbol_reference = value_type.data_type; diff --git a/vala/valablock.vala b/vala/valablock.vala index 4064b6e90..dd367a7c6 100644 --- a/vala/valablock.vala +++ b/vala/valablock.vala @@ -153,18 +153,21 @@ public class Vala.Block : Symbol, Statement { statement_list[i].check (context); } - foreach (LocalVariable local in get_local_variables ()) { + get_local_variables ().foreach ((local) => { local.active = false; - } + return true; + }); - foreach (Constant constant in local_constants) { + local_constants.foreach ((constant) => { constant.active = false; - } + return true; + }); // use get_statements () instead of statement_list to not miss errors within StatementList objects - foreach (Statement stmt in get_statements ()) { + get_statements ().foreach ((stmt) => { add_error_types (stmt.get_error_types ()); - } + return true; + }); context.analyzer.current_symbol = old_symbol; context.analyzer.insert_block = old_insert_block; diff --git a/vala/valaclass.vala b/vala/valaclass.vala index 211c321dd..7dcd12276 100644 --- a/vala/valaclass.vala +++ b/vala/valaclass.vala @@ -462,38 +462,46 @@ public class Vala.Class : ObjectTypeSymbol { } public override void accept_children (CodeVisitor visitor) { - foreach (DataType type in base_types) { + base_types.foreach ((type) => { type.accept (visitor); - } + return true; + }); - foreach (TypeParameter p in get_type_parameters ()) { + get_type_parameters ().foreach ((p) => { p.accept (visitor); - } + return true; + }); /* process enums first to avoid order problems in C code */ - foreach (Enum en in enums) { + enums.foreach ((en) => { en.accept (visitor); - } + return true; + }); - foreach (Field f in fields) { + fields.foreach ((f) => { f.accept (visitor); - } + return true; + }); - foreach (Constant c in constants) { + constants.foreach ((c) => { c.accept (visitor); - } + return true; + }); - foreach (Method m in methods) { + methods.foreach ((m) => { m.accept (visitor); - } + return true; + }); - foreach (Property prop in properties) { + properties.foreach ((prop) => { prop.accept (visitor); - } + return true; + }); - foreach (Signal sig in signals) { + signals.foreach ((sig) => { sig.accept (visitor); - } + return true; + }); if (constructor != null) { constructor.accept (visitor); @@ -519,17 +527,20 @@ public class Vala.Class : ObjectTypeSymbol { class_destructor.accept (visitor); } - foreach (Class cl in classes) { + classes.foreach ((cl) => { cl.accept (visitor); - } + return true; + }); - foreach (Struct st in structs) { + structs.foreach ((st) => { st.accept (visitor); - } + return true; + }); - foreach (Delegate d in delegates) { + delegates.foreach ((d) => { d.accept (visitor); - } + return true; + }); } public override bool is_reference_type () { @@ -548,13 +559,12 @@ public class Vala.Class : ObjectTypeSymbol { return true; } - foreach (DataType base_type in base_types) { + return !base_types.foreach ((base_type) => { if (base_type.data_type != null && base_type.data_type.is_subtype_of (t)) { - return true; + return false; } - } - - return false; + return true; + }); } public override void replace_type (DataType old_type, DataType new_type) { @@ -568,19 +578,19 @@ public class Vala.Class : ObjectTypeSymbol { } private void get_all_prerequisites (Interface iface, List list) { - foreach (DataType prereq in iface.get_prerequisites ()) { + iface.get_prerequisites ().foreach ((prereq) => { TypeSymbol type = prereq.data_type; /* skip on previous errors */ if (type == null) { - continue; + return true; } list.add (type); if (type is Interface) { get_all_prerequisites ((Interface) type, list); - } - } + return true; + }); } private bool class_is_a (Class cl, TypeSymbol t) { @@ -588,17 +598,16 @@ public class Vala.Class : ObjectTypeSymbol { return true; } - foreach (DataType base_type in cl.get_base_types ()) { + return !cl.get_base_types ().foreach ((base_type) => { if (base_type.data_type is Class) { if (class_is_a ((Class) base_type.data_type, t)) { - return true; + return false; } } else if (base_type.data_type == t) { - return true; + return false; } - } - - return false; + return true; + }); } public override bool check (CodeContext context) { @@ -648,38 +657,46 @@ public class Vala.Class : ObjectTypeSymbol { } } - foreach (DataType type in base_types) { + base_types.foreach ((type) => { type.check (context); - } + return true; + }); - foreach (TypeParameter p in get_type_parameters ()) { + get_type_parameters ().foreach ((p) => { p.check (context); - } + return true; + }); /* process enums first to avoid order problems in C code */ - foreach (Enum en in enums) { + enums.foreach ((en) => { en.check (context); - } + return true; + }); - foreach (Field f in fields) { + fields.foreach ((f) => { f.check (context); - } + return true; + }); - foreach (Constant c in constants) { + constants.foreach ((c) => { c.check (context); - } + return true; + }); - foreach (Method m in methods) { + methods.foreach ((m) => { m.check (context); - } + return true; + }); - foreach (Property prop in properties) { + properties.foreach ((prop) => { prop.check (context); - } + return true; + }); - foreach (Signal sig in signals) { + signals.foreach ((sig) => { sig.check (context); - } + return true; + }); if (constructor != null) { constructor.check (context); @@ -705,66 +722,74 @@ public class Vala.Class : ObjectTypeSymbol { class_destructor.check (context); } - foreach (Class cl in classes) { + classes.foreach ((cl) => { cl.check (context); - } + return true; + }); - foreach (Struct st in structs) { + structs.foreach ((st) => { st.check (context); - } + return true; + }); - foreach (Delegate d in delegates) { + delegates.foreach ((d) => { d.check (context); - } + return true; + }); /* compact classes cannot implement interfaces */ if (is_compact) { - foreach (DataType base_type in get_base_types ()) { + get_base_types ().foreach ((base_type) => { if (base_type.data_type is Interface) { error = true; Report.error (source_reference, "compact classes `%s` may not implement interfaces".printf (get_full_name ())); } - } + return true; + }); if (!external && !external_package && base_class != null && base_class != context.analyzer.gsource_type) { - foreach (Field f in fields) { + fields.foreach ((f) => { if (f.binding == MemberBinding.INSTANCE) { error = true; Report.error (source_reference, "derived compact classes may not have instance fields"); - break; + return false; } - } + return true; + }); } } /* gather all prerequisites */ List prerequisites = new ArrayList (); - foreach (DataType base_type in get_base_types ()) { + get_base_types ().foreach ((base_type) => { if (base_type.data_type is Interface) { get_all_prerequisites ((Interface) base_type.data_type, prerequisites); } - } + return true; + }); /* check whether all prerequisites are met */ List missing_prereqs = new ArrayList (); - foreach (TypeSymbol prereq in prerequisites) { + prerequisites.foreach ((prereq) => { if (!class_is_a (this, prereq)) { missing_prereqs.insert (0, prereq.get_full_name ()); } - } + return true; + }); /* report any missing prerequisites */ if (missing_prereqs.size > 0) { error = true; string error_string = "%s: some prerequisites (".printf (get_full_name ()); bool first = true; - foreach (string s in missing_prereqs) { + missing_prereqs.foreach ((s) => { if (first) { error_string = "%s`%s'".printf (error_string, s); first = false; } else { error_string = "%s, `%s'".printf (error_string, s); } - } + return true; + }); error_string += ") are not met"; Report.error (source_reference, error_string); } @@ -772,13 +797,13 @@ public class Vala.Class : ObjectTypeSymbol { /* VAPI classes don't have to specify overridden methods */ if (source_type == SourceFileType.SOURCE) { /* all abstract symbols defined in base types have to be at least defined (or implemented) also in this type */ - foreach (DataType base_type in get_base_types ()) { + get_base_types ().foreach ((base_type) => { if (base_type.data_type is Interface) { Interface iface = (Interface) base_type.data_type; if (base_class != null && base_class.is_subtype_of (iface)) { // reimplementation of interface, class is not required to reimplement all methods - break; + return false; } /* We do not need to do expensive equality checking here since this is done @@ -786,7 +811,7 @@ public class Vala.Class : ObjectTypeSymbol { */ /* check methods */ - foreach (Method m in iface.get_methods ()) { + iface.get_methods ().foreach ((m) => { if (m.is_abstract) { var implemented = false; var base_class = this; @@ -807,10 +832,11 @@ public class Vala.Class : ObjectTypeSymbol { Report.error (source_reference, "`%s' does not implement interface method `%s'".printf (get_full_name (), m.get_full_name ())); } } - } + return true; + }); /* check properties */ - foreach (Property prop in iface.get_properties ()) { + iface.get_properties ().foreach ((prop) => { if (prop.is_abstract) { Symbol sym = null; var base_class = this; @@ -834,15 +860,17 @@ public class Vala.Class : ObjectTypeSymbol { Report.error (source_reference, "`%s' does not implement interface property `%s'".printf (get_full_name (), prop.get_full_name ())); } } - } + return true; + }); } - } + return true; + }); /* all abstract symbols defined in base classes have to be implemented in non-abstract classes */ if (!is_abstract) { var base_class = base_class; while (base_class != null && base_class.is_abstract) { - foreach (Method base_method in base_class.get_methods ()) { + base_class.get_methods ().foreach ((base_method) => { if (base_method.is_abstract) { var override_method = SemanticAnalyzer.symbol_lookup_inherited (this, base_method.name) as Method; if (override_method == null || !override_method.overrides) { @@ -850,8 +878,9 @@ public class Vala.Class : ObjectTypeSymbol { Report.error (source_reference, "`%s' does not implement abstract method `%s'".printf (get_full_name (), base_method.get_full_name ())); } } - } - foreach (Property base_property in base_class.get_properties ()) { + return true; + }); + base_class.get_properties ().foreach ((base_property) => { if (base_property.is_abstract) { var override_property = SemanticAnalyzer.symbol_lookup_inherited (this, base_property.name) as Property; if (override_property == null || !override_property.overrides) { @@ -859,7 +888,8 @@ public class Vala.Class : ObjectTypeSymbol { Report.error (source_reference, "`%s' does not implement abstract property `%s'".printf (get_full_name (), base_property.get_full_name ())); } } - } + return true; + }); base_class = base_class.base_class; } } diff --git a/vala/valaclasstype.vala b/vala/valaclasstype.vala index a0430a12c..04269ea14 100644 --- a/vala/valaclasstype.vala +++ b/vala/valaclasstype.vala @@ -43,9 +43,10 @@ public class Vala.ClassType : ReferenceType { result.is_dynamic = is_dynamic; result.floating_reference = floating_reference; - foreach (DataType arg in get_type_arguments ()) { + get_type_arguments ().foreach ((arg) => { result.add_type_argument (arg.copy ()); - } + return true; + }); return result; } diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala index 0b6a0aa66..d8efb213d 100644 --- a/vala/valacodecontext.vala +++ b/vala/valacodecontext.vala @@ -581,11 +581,12 @@ public class Vala.CodeContext { } stream.printf ("%s:", filename); - foreach (var src in source_files) { + source_files.foreach ((src) => { if (src.file_type == SourceFileType.FAST && src.used) { stream.printf (" %s", src.filename); } - } + return true; + }); stream.printf ("\n\n"); } diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala index 319b7613b..55b7526c5 100644 --- a/vala/valacodenode.vala +++ b/vala/valacodenode.vala @@ -102,9 +102,10 @@ public abstract class Vala.CodeNode { * or a child node */ public void add_error_types (List error_types) { - foreach (DataType error_type in error_types) { + error_types.foreach ((error_type) => { add_error_type (error_type); - } + return true; + }); } /** diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala index 3872b9b81..919a7679a 100644 --- a/vala/valacodewriter.vala +++ b/vala/valacodewriter.vala @@ -250,14 +250,15 @@ public class Vala.CodeWriter : CodeVisitor { write_string (" : "); bool first = true; - foreach (DataType base_type in base_types) { + base_types.foreach ((base_type) => { if (!first) { write_string (", "); } else { first = false; } write_type (base_type); - } + return true; + }); } write_begin_block (); @@ -286,14 +287,15 @@ public class Vala.CodeWriter : CodeVisitor { void visit_sorted (List symbols) { if (type != CodeWriterType.EXTERNAL) { // order of virtual methods matters for fast vapis - foreach (Symbol sym in symbols) { + symbols.foreach ((sym) => { sym.accept (this); - } + return true; + }); return; } var sorted_symbols = new ArrayList (); - foreach (Symbol sym in symbols) { + symbols.foreach ((sym) => { int left = 0; int right = sorted_symbols.size - 1; if (left > right || sym.name < sorted_symbols[left].name) { @@ -311,10 +313,12 @@ public class Vala.CodeWriter : CodeVisitor { } sorted_symbols.insert (left + 1, sym); } - } - foreach (Symbol sym in sorted_symbols) { + return true; + }); + sorted_symbols.foreach ((sym) => { sym.accept (this); - } + return true; + }); } public override void visit_struct (Struct st) { @@ -348,9 +352,10 @@ public class Vala.CodeWriter : CodeVisitor { current_scope = st.scope; - foreach (Field field in st.get_fields ()) { + st.get_fields ().foreach ((field) => { field.accept (this); - } + return true; + }); visit_sorted (st.get_constants ()); visit_sorted (st.get_methods ()); visit_sorted (st.get_properties ()); @@ -388,14 +393,15 @@ public class Vala.CodeWriter : CodeVisitor { write_string (" : "); bool first = true; - foreach (DataType prerequisite in prerequisites) { + prerequisites.foreach ((prerequisite) => { if (!first) { write_string (", "); } else { first = false; } write_type (prerequisite); - } + return true; + }); } write_begin_block (); @@ -439,7 +445,7 @@ public class Vala.CodeWriter : CodeVisitor { write_begin_block (); bool first = true; - foreach (EnumValue ev in en.get_values ()) { + en.get_values ().foreach ((ev) => { if (first) { first = false; } else { @@ -460,7 +466,8 @@ public class Vala.CodeWriter : CodeVisitor { write_string(" = "); ev.value.accept (this); } - } + return true; + }); if (!first) { if (en.get_methods ().size > 0 || en.get_constants ().size > 0) { @@ -470,12 +477,14 @@ public class Vala.CodeWriter : CodeVisitor { } current_scope = en.scope; - foreach (Method m in en.get_methods ()) { + en.get_methods ().foreach ((m) => { m.accept (this); - } - foreach (Constant c in en.get_constants ()) { + return true; + }); + en.get_constants ().foreach ((c) => { c.accept (this); - } + return true; + }); current_scope = current_scope.parent_scope; write_end_block (); @@ -504,7 +513,7 @@ public class Vala.CodeWriter : CodeVisitor { write_begin_block (); bool first = true; - foreach (ErrorCode ecode in edomain.get_codes ()) { + edomain.get_codes ().foreach ((ecode) => { if (first) { first = false; } else { @@ -520,7 +529,8 @@ public class Vala.CodeWriter : CodeVisitor { write_indent (); write_identifier (ecode.name); - } + return true; + }); if (!first) { if (edomain.get_methods ().size > 0) { @@ -530,9 +540,10 @@ public class Vala.CodeWriter : CodeVisitor { } current_scope = edomain.scope; - foreach (Method m in edomain.get_methods ()) { + edomain.get_methods ().foreach ((m) => { m.accept (this); - } + return true; + }); current_scope = current_scope.parent_scope; write_end_block (); @@ -613,7 +624,7 @@ public class Vala.CodeWriter : CodeVisitor { write_string (" throws "); bool first = true; - foreach (DataType type in error_domains) { + error_domains.foreach ((type) => { if (!first) { write_string (", "); } else { @@ -621,7 +632,8 @@ public class Vala.CodeWriter : CodeVisitor { } write_type (type); - } + return true; + }); } } @@ -629,14 +641,14 @@ public class Vala.CodeWriter : CodeVisitor { write_string ("("); int i = 1; - foreach (Parameter param in params) { + params.foreach ((param) => { if (i > 1) { write_string (", "); } if (param.ellipsis) { write_string ("..."); - continue; + return true; } write_attributes (param); @@ -672,7 +684,8 @@ public class Vala.CodeWriter : CodeVisitor { } i++; - } + return true; + }); write_string (")"); } @@ -906,9 +919,10 @@ public class Vala.CodeWriter : CodeVisitor { public override void visit_block (Block b) { write_begin_block (); - foreach (Statement stmt in b.get_statements ()) { + b.get_statements ().foreach ((stmt) => { stmt.accept (this); - } + return true; + }); write_end_block (); } @@ -941,7 +955,7 @@ public class Vala.CodeWriter : CodeVisitor { write_string ("{"); bool first = true; - foreach (Expression initializer in list.get_initializers ()) { + list.get_initializers ().foreach ((initializer) => { if (!first) { write_string (", "); } else { @@ -949,7 +963,8 @@ public class Vala.CodeWriter : CodeVisitor { } first = false; initializer.accept (this); - } + return true; + }); write_string (" }"); } @@ -980,9 +995,10 @@ public class Vala.CodeWriter : CodeVisitor { write_string (") {"); write_newline (); - foreach (SwitchSection section in stmt.get_sections ()) { + stmt.get_sections ().foreach ((section) => { section.accept (this); - } + return true; + }); write_indent (); write_string ("}"); @@ -990,9 +1006,10 @@ public class Vala.CodeWriter : CodeVisitor { } public override void visit_switch_section (SwitchSection section) { - foreach (SwitchLabel label in section.get_labels ()) { + section.get_labels ().foreach ((label) => { label.accept (this); - } + return true; + }); visit_block (section); } @@ -1042,26 +1059,28 @@ public class Vala.CodeWriter : CodeVisitor { write_string ("for ("); bool first = true; - foreach (Expression initializer in stmt.get_initializer ()) { + stmt.get_initializer ().foreach ((initializer) => { if (!first) { write_string (", "); } first = false; initializer.accept (this); - } + return true; + }); write_string ("; "); stmt.condition.accept (this); write_string ("; "); first = true; - foreach (Expression iterator in stmt.get_iterator ()) { + stmt.get_iterator ().foreach ((iterator) => { if (!first) { write_string (", "); } first = false; iterator.accept (this); - } + return true; + }); write_string (")"); stmt.body.accept (this); @@ -1120,9 +1139,10 @@ public class Vala.CodeWriter : CodeVisitor { write_indent (); write_string ("try"); stmt.body.accept (this); - foreach (var clause in stmt.get_catch_clauses ()) { + stmt.get_catch_clauses ().foreach ((clause) => { clause.accept (this); - } + return true; + }); if (stmt.finally_body != null) { write_string (" finally"); stmt.finally_body.accept (this); @@ -1164,14 +1184,15 @@ public class Vala.CodeWriter : CodeVisitor { write_string ("["); bool first = true; - foreach (Expression size in expr.get_sizes ()) { + expr.get_sizes ().foreach ((size) => { if (!first) { write_string (", "); } first = false; size.accept (this); - } + return true; + }); write_string ("]"); @@ -1218,14 +1239,15 @@ public class Vala.CodeWriter : CodeVisitor { write_string (" ("); bool first = true; - foreach (Expression arg in expr.get_argument_list ()) { + expr.get_argument_list ().foreach ((arg) => { if (!first) { write_string (", "); } first = false; arg.accept (this); - } + return true; + }); write_string (")"); } @@ -1235,14 +1257,15 @@ public class Vala.CodeWriter : CodeVisitor { write_string ("["); bool first = true; - foreach (Expression index in expr.get_indices ()) { + expr.get_indices ().foreach ((index) => { if (!first) { write_string (", "); } first = false; index.accept (this); - } + return true; + }); write_string ("]"); } @@ -1284,14 +1307,15 @@ public class Vala.CodeWriter : CodeVisitor { write_string (" ("); bool first = true; - foreach (Expression arg in expr.get_argument_list ()) { + expr.get_argument_list ().foreach ((arg) => { if (!first) { write_string (", "); } first = false; arg.accept (this); - } + return true; + }); write_string (")"); } @@ -1465,7 +1489,7 @@ public class Vala.CodeWriter : CodeVisitor { write_string ("("); var params = expr.get_parameters (); int i = 1; - foreach (var param in params) { + params.foreach ((param) => { if (i > 1) { write_string (", "); } @@ -1479,7 +1503,8 @@ public class Vala.CodeWriter : CodeVisitor { write_identifier (param.name); i++; - } + return true; + }); write_string (") =>"); if (expr.statement_body != null) { expr.statement_body.accept (this); @@ -1728,14 +1753,15 @@ public class Vala.CodeWriter : CodeVisitor { if (type_params.size > 0) { write_string ("<"); bool first = true; - foreach (TypeParameter type_param in type_params) { + type_params.foreach ((type_param) => { if (first) { first = false; } else { write_string (","); } write_identifier (type_param.name); - } + return true; + }); write_string (">"); } } diff --git a/vala/valaconstructor.vala b/vala/valaconstructor.vala index d16fc13a4..d16dbcae6 100644 --- a/vala/valaconstructor.vala +++ b/vala/valaconstructor.vala @@ -77,11 +77,12 @@ public class Vala.Constructor : Subroutine { body.check (context); } - foreach (DataType body_error_type in body.get_error_types ()) { + body.get_error_types ().foreach ((body_error_type) => { if (!((ErrorType) body_error_type).dynamic_error) { Report.warning (body_error_type.source_reference, "unhandled error `%s'".printf (body_error_type.to_string())); } - } + return true; + }); context.analyzer.current_symbol = context.analyzer.current_symbol.parent_symbol; diff --git a/vala/valacreationmethod.vala b/vala/valacreationmethod.vala index 451dd813d..3140a405b 100644 --- a/vala/valacreationmethod.vala +++ b/vala/valacreationmethod.vala @@ -56,21 +56,25 @@ public class Vala.CreationMethod : Method { } public override void accept_children (CodeVisitor visitor) { - foreach (Parameter param in get_parameters()) { + get_parameters ().foreach ((param) => { param.accept (visitor); - } + return true; + }); - foreach (DataType error_type in get_error_types ()) { + get_error_types ().foreach ((error_type) => { error_type.accept (visitor); - } + return true; + }); - foreach (Expression precondition in get_preconditions ()) { + get_preconditions ().foreach ((precondition) => { precondition.accept (visitor); - } + return true; + }); - foreach (Expression postcondition in get_postconditions ()) { + get_postconditions ().foreach ((postcondition) => { postcondition.accept (visitor); - } + return true; + }); if (body != null) { body.accept (visitor); @@ -99,21 +103,25 @@ public class Vala.CreationMethod : Method { } context.analyzer.current_symbol = this; - foreach (Parameter param in get_parameters()) { + get_parameters().foreach ((param) => { param.check (context); - } + return true; + }); - foreach (DataType error_type in get_error_types ()) { + get_error_types ().foreach ((error_type) => { error_type.check (context); - } + return true; + }); - foreach (Expression precondition in get_preconditions ()) { + get_preconditions ().foreach ((precondition) => { precondition.check (context); - } + return true; + }); - foreach (Expression postcondition in get_postconditions ()) { + get_postconditions ().foreach ((postcondition) => { postcondition.check (context); - } + return true; + }); if (body != null) { body.check (context); @@ -165,17 +173,19 @@ public class Vala.CreationMethod : Method { // check that all errors that can be thrown in the method body are declared if (body != null) { - foreach (DataType body_error_type in body.get_error_types ()) { + body.get_error_types ().foreach ((body_error_type) => { bool can_propagate_error = false; - foreach (DataType method_error_type in get_error_types ()) { + get_error_types ().foreach ((method_error_type) => { if (body_error_type.compatible (method_error_type)) { can_propagate_error = true; } - } + return true; + }); if (!can_propagate_error && !((ErrorType) body_error_type).dynamic_error) { Report.warning (body_error_type.source_reference, "unhandled error `%s'".printf (body_error_type.to_string())); } - } + return true; + }); } return !error; diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala index f3f9bf92a..647afd284 100644 --- a/vala/valadatatype.vala +++ b/vala/valadatatype.vala @@ -110,10 +110,11 @@ public abstract class Vala.DataType : CodeNode { } public override void accept_children (CodeVisitor visitor) { - if (type_argument_list != null && type_argument_list.size > 0) { - foreach (DataType type_arg in type_argument_list) { + if (type_argument_list != null) { + type_argument_list.foreach ((type_arg) => { type_arg.accept (visitor); - } + return true; + }); } } @@ -152,7 +153,7 @@ public abstract class Vala.DataType : CodeNode { if (type_args.size > 0) { s += "<"; bool first = true; - foreach (DataType type_arg in type_args) { + type_args.foreach ((type_arg) => { if (!first) { s += ","; } else { @@ -162,7 +163,8 @@ public abstract class Vala.DataType : CodeNode { s += "weak "; } s += type_arg.to_qualified_string (scope); - } + return true; + }); s += ">"; } if (nullable) { diff --git a/vala/valadeclarationstatement.vala b/vala/valadeclarationstatement.vala index f0a3d4161..ede2abdf8 100644 --- a/vala/valadeclarationstatement.vala +++ b/vala/valadeclarationstatement.vala @@ -73,13 +73,14 @@ public class Vala.DeclarationStatement : CodeNode, Statement { var local = declaration as LocalVariable; if (local != null && local.initializer != null) { - foreach (DataType error_type in local.initializer.get_error_types ()) { + local.initializer.get_error_types ().foreach ((error_type) => { // ensure we can trace back which expression may throw errors of this type var initializer_error_type = error_type.copy (); initializer_error_type.source_reference = local.initializer.source_reference; add_error_type (initializer_error_type); - } + return true; + }); } return !error; diff --git a/vala/valadelegate.vala b/vala/valadelegate.vala index 6f4ae3b7c..7a74b48b2 100644 --- a/vala/valadelegate.vala +++ b/vala/valadelegate.vala @@ -186,19 +186,11 @@ public class Vala.Delegate : TypeSymbol, Callable { } // method may throw less but not more errors than the delegate - foreach (DataType method_error_type in m.get_error_types ()) { - bool match = false; - foreach (DataType delegate_error_type in get_error_types ()) { - if (method_error_type.compatible (delegate_error_type)) { - match = true; - break; - } - } - - if (!match) { - return false; - } - } + m.get_error_types ().foreach ((method_error_type) => { + return get_error_types ().foreach ((delegate_error_type) => { + return !(method_error_type.compatible (delegate_error_type)); + }); + }); return true; } @@ -208,19 +200,22 @@ public class Vala.Delegate : TypeSymbol, Callable { } public override void accept_children (CodeVisitor visitor) { - foreach (TypeParameter p in type_parameters) { + type_parameters.foreach ((p) => { p.accept (visitor); - } + return true; + }); return_type.accept (visitor); - foreach (Parameter param in parameters) { + parameters.foreach ((param) => { param.accept (visitor); - } + return true; + }); - foreach (DataType error_type in get_error_types ()) { + get_error_types ().foreach ((error_type) => { error_type.accept (visitor); - } + return true; + }); } public override bool is_reference_type () { @@ -259,7 +254,7 @@ public class Vala.Delegate : TypeSymbol, Callable { string str = "("; int i = 1; - foreach (Parameter param in parameters) { + parameters.foreach ((param) => { if (i > 1) { str += ", "; } @@ -282,7 +277,8 @@ public class Vala.Delegate : TypeSymbol, Callable { str += param.variable_type.to_string (); i++; - } + return true; + }); str += ")"; @@ -302,19 +298,22 @@ public class Vala.Delegate : TypeSymbol, Callable { context.analyzer.current_source_file = source_reference.file; } - foreach (TypeParameter p in type_parameters) { + type_parameters.foreach ((p) => { p.check (context); - } + return true; + }); return_type.check (context); - foreach (Parameter param in parameters) { + parameters.foreach ((param) => { param.check (context); - } + return true; + }); - foreach (DataType error_type in get_error_types ()) { + get_error_types ().foreach ((error_type) => { error_type.check (context); - } + return true; + }); context.analyzer.current_source_file = old_source_file; diff --git a/vala/valadelegatetype.vala b/vala/valadelegatetype.vala index 221688dd8..5b65f7b2c 100644 --- a/vala/valadelegatetype.vala +++ b/vala/valadelegatetype.vala @@ -74,7 +74,7 @@ public class Vala.DelegateType : DataType { if (type_args.size > 0) { s += "<"; bool first = true; - foreach (DataType type_arg in type_args) { + type_args.foreach ((type_arg) => { if (!first) { s += ","; } else { @@ -84,7 +84,8 @@ public class Vala.DelegateType : DataType { s += "weak "; } s += type_arg.to_qualified_string (scope); - } + return true; + }); s += ">"; } if (nullable) { @@ -99,9 +100,10 @@ public class Vala.DelegateType : DataType { result.value_owned = value_owned; result.nullable = nullable; - foreach (DataType arg in get_type_arguments ()) { + get_type_arguments ().foreach ((arg) => { result.add_type_argument (arg.copy ()); - } + return true; + }); result.is_called_once = is_called_once; diff --git a/vala/valaelementaccess.vala b/vala/valaelementaccess.vala index 4fb44b8c4..d832ec283 100644 --- a/vala/valaelementaccess.vala +++ b/vala/valaelementaccess.vala @@ -70,9 +70,10 @@ public class Vala.ElementAccess : Expression { public override void accept_children (CodeVisitor visitor) { container.accept (visitor); - foreach (Expression e in indices) { + indices.foreach ((e) => { e.accept (visitor); - } + return true; + }); } public override void replace_expression (Expression old_node, Expression new_node) { @@ -88,12 +89,10 @@ public class Vala.ElementAccess : Expression { } public override bool is_pure () { - foreach (Expression index in indices) { - if (!index.is_pure ()) { - return false; - } - } - return container.is_pure (); + bool indices_pure = indices.foreach ((index) => { + return index.is_pure (); + }); + return indices_pure && container.is_pure (); } public override bool is_accessible (Symbol sym) { @@ -135,9 +134,10 @@ public class Vala.ElementAccess : Expression { get_indices ().get (0).target_type = context.analyzer.string_type.copy (); } - foreach (Expression index in get_indices ()) { + get_indices ().foreach ((index) => { index.check (context); - } + return true; + }); bool index_int_type_check = true; @@ -187,9 +187,10 @@ public class Vala.ElementAccess : Expression { var get_method = container.value_type.get_member ("get") as Method; if (get_method != null) { var get_call = new MethodCall (new MemberAccess (container, "get", source_reference), source_reference); - foreach (Expression e in get_indices ()) { + get_indices ().foreach ((e) => { get_call.add_argument (e); - } + return true; + }); get_call.formal_target_type = this.formal_target_type; get_call.target_type = this.target_type; parent_node.replace_expression (this, get_call); @@ -222,9 +223,10 @@ public class Vala.ElementAccess : Expression { public override void emit (CodeGenerator codegen) { container.emit (codegen); - foreach (Expression e in indices) { + indices.foreach ((e) => { e.emit (codegen); - } + return true; + }); codegen.visit_element_access (this); @@ -233,15 +235,17 @@ public class Vala.ElementAccess : Expression { public override void get_defined_variables (Collection collection) { container.get_defined_variables (collection); - foreach (Expression index in indices) { + indices.foreach ((index) => { index.get_defined_variables (collection); - } + return true; + }); } public override void get_used_variables (Collection collection) { container.get_used_variables (collection); - foreach (Expression index in indices) { + indices.foreach ((index) => { index.get_used_variables (collection); - } + return true; + }); } } diff --git a/vala/valaenum.vala b/vala/valaenum.vala index add510783..d571b2108 100644 --- a/vala/valaenum.vala +++ b/vala/valaenum.vala @@ -139,17 +139,20 @@ public class Vala.Enum : TypeSymbol { } public override void accept_children (CodeVisitor visitor) { - foreach (EnumValue value in values) { + values.foreach ((value) => { value.accept (visitor); - } + return true; + }); - foreach (Method m in methods) { + methods.foreach ((m) => { m.accept (visitor); - } + return true; + }); - foreach (Constant c in constants) { + constants.foreach ((c) => { c.accept (visitor); - } + return true; + }); } public override bool is_reference_type () { @@ -177,17 +180,20 @@ public class Vala.Enum : TypeSymbol { return false; } - foreach (EnumValue value in values) { + values.foreach ((value) => { value.check (context); - } + return true; + }); - foreach (Method m in methods) { + methods.foreach ((m) => { m.check (context); - } + return true; + }); - foreach (Constant c in constants) { + constants.foreach ((c) => { c.check (context); - } + return true; + }); context.analyzer.current_source_file = old_source_file; context.analyzer.current_symbol = old_symbol; diff --git a/vala/valaerrordomain.vala b/vala/valaerrordomain.vala index a73dcf84d..1c1ae45a9 100644 --- a/vala/valaerrordomain.vala +++ b/vala/valaerrordomain.vala @@ -94,13 +94,15 @@ public class Vala.ErrorDomain : TypeSymbol { } public override void accept_children (CodeVisitor visitor) { - foreach (ErrorCode ecode in codes) { + codes.foreach ((ecode) => { ecode.accept (visitor); - } + return true; + }); - foreach (Method m in methods) { + methods.foreach ((m) => { m.accept (visitor); - } + return true; + }); } public override bool is_reference_type () { @@ -114,13 +116,15 @@ public class Vala.ErrorDomain : TypeSymbol { checked = true; - foreach (ErrorCode ecode in codes) { + codes.foreach ((ecode) => { ecode.check (context); - } + return true; + }); - foreach (Method m in methods) { + methods.foreach ((m) => { m.check (context); - } + return true; + }); return !error; } diff --git a/vala/valaflowanalyzer.vala b/vala/valaflowanalyzer.vala index 9652c1537..d27c097ea 100644 --- a/vala/valaflowanalyzer.vala +++ b/vala/valaflowanalyzer.vala @@ -106,12 +106,12 @@ public class Vala.FlowAnalyzer : CodeVisitor { this.context = context; /* we're only interested in non-pkg source files */ - var source_files = context.get_source_files (); - foreach (SourceFile file in source_files) { + context.get_source_files ().foreach ((file) => { if (file.file_type == SourceFileType.SOURCE) { file.accept (this); } - } + return true; + }); } public override void visit_source_file (SourceFile source_file) { @@ -195,13 +195,14 @@ public class Vala.FlowAnalyzer : CodeVisitor { if (m is Method) { // ensure out parameters are defined at end of method - foreach (var param in ((Method) m).get_parameters ()) { + ((Method) m).get_parameters ().foreach ((param) => { if (param.direction == ParameterDirection.OUT) { var param_ma = new MemberAccess.simple (param.name, param.source_reference); param_ma.symbol_reference = param; m.return_block.add_node (param_ma); } - } + return true; + }); } current_block = new BasicBlock (); @@ -250,9 +251,10 @@ public class Vala.FlowAnalyzer : CodeVisitor { return; } current.postorder_visited = true; - foreach (BasicBlock succ in current.get_successors ()) { + current.get_successors ().foreach ((succ) => { depth_first_traverse (succ, list); - } + return true; + }); current.postorder_number = list.size; list.insert (0, current); } @@ -265,15 +267,15 @@ public class Vala.FlowAnalyzer : CodeVisitor { bool changed = true; while (changed) { changed = false; - foreach (BasicBlock block in block_list) { + block_list.foreach ((block) => { if (block == entry_block) { - continue; + return true; } // new immediate dominator BasicBlock new_idom = null; bool first = true; - foreach (BasicBlock pred in block.get_predecessors ()) { + block.get_predecessors ().foreach ((pred) => { if (idoms[pred.postorder_number] != null) { if (first) { new_idom = pred; @@ -282,22 +284,23 @@ public class Vala.FlowAnalyzer : CodeVisitor { new_idom = intersect (idoms, pred, new_idom); } } - } + return true; + }); if (idoms[block.postorder_number] != new_idom) { idoms[block.postorder_number] = new_idom; changed = true; } - } + return true; + }); } // build tree - foreach (BasicBlock block in block_list) { - if (block == entry_block) { - continue; + block_list.foreach ((block) => { + if (block != entry_block) { + idoms[block.postorder_number].add_child (block); } - - idoms[block.postorder_number].add_child (block); - } + return true; + }); } BasicBlock intersect (BasicBlock[] idoms, BasicBlock b1, BasicBlock b2) { @@ -316,41 +319,47 @@ public class Vala.FlowAnalyzer : CodeVisitor { for (int i = block_list.size - 1; i >= 0; i--) { var block = block_list[i]; - foreach (BasicBlock succ in block.get_successors ()) { + block.get_successors ().foreach ((succ) => { // if idom(succ) != block if (succ.parent != block) { block.add_dominator_frontier (succ); } - } + return true; + }); - foreach (BasicBlock child in block.get_children ()) { - foreach (BasicBlock child_frontier in child.get_dominator_frontier ()) { + block.get_children ().foreach ((child) => { + child.get_dominator_frontier ().foreach ((child_frontier) => { // if idom(child_frontier) != block if (child_frontier.parent != block) { block.add_dominator_frontier (child_frontier); } - } - } + return true; + }); + return true; + }); } } Map> get_assignment_map (List block_list, BasicBlock entry_block) { var map = new HashMap> (); - foreach (BasicBlock block in block_list) { + block_list.foreach ((block) => { var defined_variables = new ArrayList (); - foreach (CodeNode node in block.get_nodes ()) { + block.get_nodes ().foreach ((node) => { node.get_defined_variables (defined_variables); - } + return true; + }); - foreach (Variable variable in defined_variables) { + defined_variables.foreach ((variable) => { var block_set = map.get (variable); if (block_set == null) { block_set = new HashSet (); map.set (variable, block_set); } block_set.add (block); - } - } + return true; + }); + return true; + }); return map; } @@ -362,21 +371,23 @@ public class Vala.FlowAnalyzer : CodeVisitor { var added = new HashMap (); var phi = new HashMap (); - foreach (BasicBlock block in block_list) { + block_list.foreach ((block) => { added.set (block, 0); phi.set (block, 0); - } + return true; + }); - foreach (Variable variable in assign.keys) { + assign.keys.foreach ((variable) => { counter++; - foreach (BasicBlock block in assign.get (variable)) { + assign.get (variable).foreach ((block) => { work_list.add (block); added.set (block, counter); - } + return true; + }); while (work_list.size > 0) { BasicBlock block = work_list.get (0); work_list.remove_at (0); - foreach (BasicBlock frontier in block.get_dominator_frontier ()) { + block.get_dominator_frontier ().foreach ((frontier) => { int blockPhi = phi.get (frontier); if (blockPhi < counter) { frontier.add_phi_function (new PhiFunction (variable, frontier.get_predecessors ().size)); @@ -387,9 +398,11 @@ public class Vala.FlowAnalyzer : CodeVisitor { work_list.add (frontier); } } - } + return true; + }); } - } + return true; + }); } void check_variables (BasicBlock entry_block) { @@ -401,16 +414,17 @@ public class Vala.FlowAnalyzer : CodeVisitor { // check for variables used before initialization var used_vars_queue = new ArrayList (); - foreach (Variable variable in used_vars) { + used_vars.foreach ((variable) => { used_vars_queue.add (variable); - } + return true; + }); while (used_vars_queue.size > 0) { Variable used_var = used_vars_queue[0]; used_vars_queue.remove_at (0); PhiFunction phi = phi_functions.get (used_var); if (phi != null) { - foreach (Variable variable in phi.operands) { + phi.operands.foreach ((variable) => { if (variable == null) { if (used_var is LocalVariable) { Report.error (used_var.source_reference, "use of possibly unassigned local variable `%s'".printf (used_var.name)); @@ -418,30 +432,32 @@ public class Vala.FlowAnalyzer : CodeVisitor { // parameter Report.warning (used_var.source_reference, "use of possibly unassigned parameter `%s'".printf (used_var.name)); } - continue; + return true; } if (!(variable in used_vars)) { variable.source_reference = used_var.source_reference; used_vars.add (variable); used_vars_queue.add (variable); } - } + return true; + }); } } } void check_block_variables (BasicBlock block) { - foreach (PhiFunction phi in block.get_phi_functions ()) { + block.get_phi_functions ().foreach ((phi) => { Variable versioned_var = process_assignment (var_map, phi.original_variable); phi_functions.set (versioned_var, phi); - } + return true; + }); - foreach (CodeNode node in block.get_nodes ()) { + block.get_nodes ().foreach ((node) => { var used_variables = new ArrayList (); node.get_used_variables (used_variables); - foreach (Variable var_symbol in used_variables) { + used_variables.foreach ((var_symbol) => { var variable_stack = var_map.get (var_symbol); if (variable_stack == null || variable_stack.size == 0) { if (var_symbol is LocalVariable) { @@ -450,57 +466,67 @@ public class Vala.FlowAnalyzer : CodeVisitor { // parameter Report.warning (node.source_reference, "use of possibly unassigned parameter `%s'".printf (var_symbol.name)); } - continue; + return true; } var versioned_variable = variable_stack.get (variable_stack.size - 1); if (!(versioned_variable in used_vars)) { versioned_variable.source_reference = node.source_reference; } used_vars.add (versioned_variable); - } + return true; + }); var defined_variables = new ArrayList (); node.get_defined_variables (defined_variables); - foreach (Variable variable in defined_variables) { + defined_variables.foreach ((variable) => { process_assignment (var_map, variable); - } - } + return true; + }); + return true; + }); - foreach (BasicBlock succ in block.get_successors ()) { + block.get_successors ().foreach ((succ) => { int j = 0; - foreach (BasicBlock pred in succ.get_predecessors ()) { + succ.get_predecessors ().foreach ((pred) => { if (pred == block) { - break; + return false; } j++; - } + return true; + }); - foreach (PhiFunction phi in succ.get_phi_functions ()) { + succ.get_phi_functions ().foreach ((phi) => { var variable_stack = var_map.get (phi.original_variable); if (variable_stack != null && variable_stack.size > 0) { phi.operands.set (j, variable_stack.get (variable_stack.size - 1)); } - } - } + return true; + }); + return true; + }); - foreach (BasicBlock child in block.get_children ()) { + block.get_children ().foreach ((child) => { check_block_variables (child); - } + return true; + }); - foreach (PhiFunction phi in block.get_phi_functions ()) { + block.get_phi_functions ().foreach ((phi) => { var variable_stack = var_map.get (phi.original_variable); variable_stack.remove_at (variable_stack.size - 1); - } - foreach (CodeNode node in block.get_nodes ()) { + return true; + }); + block.get_nodes ().foreach ((node) => { var defined_variables = new ArrayList (); node.get_defined_variables (defined_variables); - foreach (Variable variable in defined_variables) { + defined_variables.foreach ((variable) => { var variable_stack = var_map.get (variable); variable_stack.remove_at (variable_stack.size - 1); - } - } + return true; + }); + return true; + }); } Variable process_assignment (Map> var_map, Variable var_symbol) { @@ -658,12 +684,13 @@ public class Vala.FlowAnalyzer : CodeVisitor { bool has_default_label = false; - foreach (SwitchSection section in stmt.get_sections ()) { + stmt.get_sections ().foreach ((section) => { current_block = new BasicBlock (); condition_block.connect (current_block); - foreach (Statement section_stmt in section.get_statements ()) { + section.get_statements ().foreach ((section_stmt) => { section_stmt.accept (this); - } + return true; + }); if (section.has_default_label ()) { has_default_label = true; @@ -678,7 +705,8 @@ public class Vala.FlowAnalyzer : CodeVisitor { current_block.connect (after_switch_block); } - } + return true; + }); if (!has_default_label) { condition_block.connect (after_switch_block); @@ -845,7 +873,7 @@ public class Vala.FlowAnalyzer : CodeVisitor { var last_block = current_block; // exceptional control flow - foreach (DataType error_data_type in node.get_error_types()) { + node.get_error_types().foreach ((error_data_type) => { var error_type = error_data_type as ErrorType; current_block = last_block; unreachable_reported = true; @@ -880,7 +908,8 @@ public class Vala.FlowAnalyzer : CodeVisitor { current_block = jump_target.last_block; } } - } + return true; + }); // normal control flow if (!always_fail) { diff --git a/vala/valaforeachstatement.vala b/vala/valaforeachstatement.vala index 4de3f52bd..9761f21b5 100644 --- a/vala/valaforeachstatement.vala +++ b/vala/valaforeachstatement.vala @@ -369,9 +369,10 @@ public class Vala.ForeachStatement : Block { body.check (context); - foreach (LocalVariable local in get_local_variables ()) { + get_local_variables ().foreach ((local) => { local.active = false; - } + return true; + }); context.analyzer.current_symbol = context.analyzer.current_symbol.parent_symbol; diff --git a/vala/valaforstatement.vala b/vala/valaforstatement.vala index ab80af520..0a5eb1e86 100644 --- a/vala/valaforstatement.vala +++ b/vala/valaforstatement.vala @@ -117,10 +117,11 @@ public class Vala.ForStatement : CodeNode, Statement { } public override void accept_children (CodeVisitor visitor) { - foreach (Expression init_expr in initializer) { + initializer.foreach ((init_expr) => { init_expr.accept (visitor); visitor.visit_end_full_expression (init_expr); - } + return true; + }); if (condition != null) { condition.accept (visitor); @@ -128,10 +129,11 @@ public class Vala.ForStatement : CodeNode, Statement { visitor.visit_end_full_expression (condition); } - foreach (Expression it_expr in iterator) { + iterator.foreach ((it_expr) => { it_expr.accept (visitor); visitor.visit_end_full_expression (it_expr); - } + return true; + }); body.accept (visitor); } @@ -152,9 +154,10 @@ public class Vala.ForStatement : CodeNode, Statement { var block = new Block (source_reference); // initializer - foreach (var init_expr in initializer) { + initializer.foreach ((init_expr) => { block.add_statement (new ExpressionStatement (init_expr, init_expr.source_reference)); - } + return true; + }); // do not generate if block if condition is always true if (condition == null || always_true (condition)) { @@ -175,9 +178,10 @@ public class Vala.ForStatement : CodeNode, Statement { block.add_statement (new DeclarationStatement (first_local, source_reference)); var iterator_block = new Block (source_reference); - foreach (var it_expr in iterator) { + iterator.foreach ((it_expr) => { iterator_block.add_statement (new ExpressionStatement (it_expr, it_expr.source_reference)); - } + return true; + }); var first_if = new IfStatement (new UnaryExpression (UnaryOperator.LOGICAL_NEGATION, new MemberAccess.simple (first_local.name, source_reference), source_reference), iterator_block, null, source_reference); body.insert_statement (0, first_if); diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala index df4f66e9b..956c92a21 100644 --- a/vala/valagenieparser.vala +++ b/vala/valagenieparser.vala @@ -555,9 +555,10 @@ public class Vala.Genie.Parser : CodeVisitor { type = new UnresolvedType.from_symbol (sym, get_src (begin)); if (type_arg_list != null) { - foreach (DataType type_arg in type_arg_list) { + type_arg_list.foreach ((type_arg) => { type.add_type_argument (type_arg); - } + return true; + }); } } @@ -770,9 +771,10 @@ public class Vala.Genie.Parser : CodeVisitor { List type_arg_list = parse_type_argument_list (true); var expr = new MemberAccess (null, id, get_src (begin)); if (type_arg_list != null) { - foreach (DataType type_arg in type_arg_list) { + type_arg_list.foreach ((type_arg) => { expr.add_type_argument (type_arg); - } + return true; + }); } return expr; } @@ -803,9 +805,10 @@ public class Vala.Genie.Parser : CodeVisitor { expect (TokenType.CLOSE_PARENS); if (expr_list.size != 1) { var tuple = new Tuple (); - foreach (Expression expr in expr_list) { + expr_list.foreach ((expr) => { tuple.add_expression (expr); - } + return true; + }); return tuple; } return expr_list.get (0); @@ -817,9 +820,10 @@ public class Vala.Genie.Parser : CodeVisitor { List type_arg_list = parse_type_argument_list (true); var expr = new MemberAccess (inner, id, get_src (begin)); if (type_arg_list != null) { - foreach (DataType type_arg in type_arg_list) { + type_arg_list.foreach ((type_arg) => { expr.add_type_argument (type_arg); - } + return true; + }); } return expr; } @@ -830,9 +834,10 @@ public class Vala.Genie.Parser : CodeVisitor { List type_arg_list = parse_type_argument_list (true); var expr = new MemberAccess.pointer (inner, id, get_src (begin)); if (type_arg_list != null) { - foreach (DataType type_arg in type_arg_list) { + type_arg_list.foreach ((type_arg) => { expr.add_type_argument (type_arg); - } + return true; + }); } return expr; } @@ -893,9 +898,10 @@ public class Vala.Genie.Parser : CodeVisitor { var print_expr = new MethodCall (expr, get_src (begin)); - foreach (Expression arg in arg_list) { + arg_list.foreach ((arg) => { print_expr.add_argument (arg); - } + return true; + }); return print_expr; @@ -917,9 +923,10 @@ public class Vala.Genie.Parser : CodeVisitor { var assert_expr = new MethodCall (expr, get_src (begin)); - foreach (Expression arg in arg_list) { + arg_list.foreach ((arg) => { assert_expr.add_argument (arg); - } + return true; + }); return assert_expr; @@ -939,18 +946,21 @@ public class Vala.Genie.Parser : CodeVisitor { var expr = new ObjectCreationExpression (member, get_src (begin)); expr.struct_creation = true; - foreach (Expression arg in arg_list) { + arg_list.foreach ((arg) => { expr.add_argument (arg); - } - foreach (MemberInitializer initializer in init_list) { + return true; + }); + init_list.foreach ((initializer) => { expr.add_member_initializer (initializer); - } + return true; + }); return expr; } else { var expr = new MethodCall (inner, get_src (begin)); - foreach (Expression arg in arg_list) { + arg_list.foreach ((arg) => { expr.add_argument (arg); - } + return true; + }); return expr; } } @@ -967,9 +977,10 @@ public class Vala.Genie.Parser : CodeVisitor { if (stop == null) { var expr = new ElementAccess (inner, get_src (begin)); - foreach (Expression index in index_list) { + index_list.foreach ((index) => { expr.append_index (index); - } + return true; + }); return expr; } else { return new SliceExpression (inner, index_list[0], stop, get_src (begin)); @@ -1053,12 +1064,14 @@ public class Vala.Genie.Parser : CodeVisitor { var init_list = parse_object_initializer (); var expr = new ObjectCreationExpression (member, get_src (begin)); - foreach (Expression arg in arg_list) { + arg_list.foreach ((arg) => { expr.add_argument (arg); - } - foreach (MemberInitializer initializer in init_list) { + return true; + }); + init_list.foreach ((initializer) => { expr.add_member_initializer (initializer); - } + return true; + }); return expr; } @@ -1105,9 +1118,10 @@ public class Vala.Genie.Parser : CodeVisitor { var expr = new ArrayCreationExpression (etype, size_specifier_list.size, initializer, get_src (begin)); if (size_specified) { - foreach (Expression size in size_specifier_list) { + size_specifier_list.foreach ((size) => { expr.append_size (size); - } + return true; + }); } return expr; } @@ -1604,9 +1618,10 @@ public class Vala.Genie.Parser : CodeVisitor { } - foreach (var param in params) { + params.foreach ((param) => { lambda.add_parameter (param); - } + return true; + }); return lambda; } @@ -2287,9 +2302,10 @@ public class Vala.Genie.Parser : CodeVisitor { finally_clause = parse_finally_clause (); } var stmt = new TryStatement (try_block, finally_clause, get_src (begin)); - foreach (CatchClause clause in catch_clauses) { + catch_clauses.foreach ((clause) => { stmt.add_catch_clause (clause); - } + return true; + }); return stmt; } @@ -2391,12 +2407,13 @@ public class Vala.Genie.Parser : CodeVisitor { void set_attributes (CodeNode node, List? attributes) { if (attributes != null) { - foreach (Attribute attr in (List) attributes) { + attributes.foreach ((attr) => { if (node.get_attribute (attr.name) != null) { Report.error (attr.source_reference, "duplicate attribute `%s`".printf (attr.name)); } node.attributes.append (attr); - } + return true; + }); } } @@ -2678,12 +2695,14 @@ public class Vala.Genie.Parser : CodeVisitor { cl.is_abstract = true; } set_attributes (cl, attrs); - foreach (TypeParameter type_param in type_param_list) { + type_param_list.foreach ((type_param) => { cl.add_type_parameter (type_param); - } - foreach (DataType base_type in base_types) { + return true; + }); + base_types.foreach ((base_type) => { cl.add_base_type (base_type); - } + return true; + }); class_name = cl.name; @@ -2957,14 +2976,16 @@ public class Vala.Genie.Parser : CodeVisitor { set_attributes (method, attrs); - foreach (TypeParameter type_param in type_param_list) { + type_param_list.foreach ((type_param) => { method.add_type_parameter (type_param); - } + return true; + }); - foreach (Parameter param in params) { + params.foreach ((param) => { method.add_parameter (param); - } + return true; + }); if (accept (TokenType.RAISES)) { do { @@ -3260,9 +3281,10 @@ public class Vala.Genie.Parser : CodeVisitor { set_attributes (sig, attrs); - foreach (Parameter formal_param in params) { + params.foreach ((formal_param) => { sig.add_parameter (formal_param); - } + return true; + }); if (!accept_terminator ()) { sig.body = parse_block (); @@ -3316,9 +3338,10 @@ public class Vala.Genie.Parser : CodeVisitor { st.access = get_access (sym.name); } set_attributes (st, attrs); - foreach (TypeParameter type_param in type_param_list) { + type_param_list.foreach ((type_param) => { st.add_type_parameter (type_param); - } + return true; + }); if (base_type != null) { st.base_type = base_type; } @@ -3381,12 +3404,14 @@ public class Vala.Genie.Parser : CodeVisitor { iface.external = true; } set_attributes (iface, attrs); - foreach (TypeParameter type_param in type_param_list) { + type_param_list.foreach ((type_param) => { iface.add_type_parameter (type_param); - } - foreach (DataType base_type in base_types) { + return true; + }); + base_types.foreach ((base_type) => { iface.add_prerequisite (base_type); - } + return true; + }); expect (TokenType.EOL); @@ -3781,13 +3806,15 @@ public class Vala.Genie.Parser : CodeVisitor { set_attributes (d, attrs); - foreach (TypeParameter type_param in type_param_list) { + type_param_list.foreach ((type_param) => { d.add_type_parameter (type_param); - } + return true; + }); - foreach (Parameter formal_param in params) { + params.foreach ((formal_param) => { d.add_parameter (formal_param); - } + return true; + }); @@ -3886,9 +3913,10 @@ public class Vala.Genie.Parser : CodeVisitor { List type_arg_list = parse_type_argument_list (false); expr = new MemberAccess (expr != null ? expr : base_expr, id, get_src (begin)); if (type_arg_list != null) { - foreach (DataType type_arg in type_arg_list) { + type_arg_list.foreach ((type_arg) => { expr.add_type_argument (type_arg); - } + return true; + }); } } while (accept (TokenType.DOT)); return expr; diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala index c3eff47b9..744dba2d2 100644 --- a/vala/valagirparser.vala +++ b/vala/valagirparser.vala @@ -117,11 +117,12 @@ public class Vala.GirParser : CodeVisitor { } public void add_sibling (Metadata metadata) { - foreach (var child in metadata.children) { + metadata.children.foreach ((child) => { add_child (child); - } + return true; + }); // merge arguments and take precedence - foreach (var key in metadata.args.keys) { + foreach (var key in metadata.args.keys) { // FIXME: Bug args[key] = metadata.args[key]; } } @@ -158,7 +159,7 @@ public class Vala.GirParser : CodeVisitor { public Metadata match_child (string name, string? selector = null) { var result = Metadata.empty; - foreach (var metadata in children) { + children.foreach ((metadata) => { if ((selector == null || metadata.selector == null || metadata.selector == selector) && metadata.pattern_spec.match_string (name)) { metadata.used = true; if (result == Metadata.empty) { @@ -175,7 +176,8 @@ public class Vala.GirParser : CodeVisitor { result = ms; } } - } + return true; + }); return result; } @@ -823,11 +825,12 @@ public class Vala.GirParser : CodeVisitor { if (symbol is Namespace && parent == parser.root) { // first process aliases since they have no assigned symbol - foreach (var node in members) { + members.foreach ((node) => { if (node.element_type == "alias") { parser.process_alias (node); } - } + return true; + }); // auto reparent namespace methods, allowing node removals for (int i=0; i < members.size; i++) { @@ -865,9 +868,10 @@ public class Vala.GirParser : CodeVisitor { } // process children - foreach (var node in members) { + members.foreach ((node) => { node.process (parser); - } + return true; + }); if (girdata != null) { // GIR node processing @@ -876,7 +880,7 @@ public class Vala.GirParser : CodeVisitor { parser.process_callable (this); var colliding = parent.lookup_all (name); - foreach (var node in colliding) { + colliding.foreach ((node) => { var sym = node.symbol; if (sym is Field && !(m.return_type is VoidType) && m.get_parameters().size == 0) { // assume method is getter @@ -919,7 +923,8 @@ public class Vala.GirParser : CodeVisitor { } } } - } + return true; + }); if (!(m is CreationMethod)) { if (metadata.has_argument (ArgumentType.DESTROYS_INSTANCE)) { m.set_attribute ("DestroysInstance", metadata.get_bool (ArgumentType.DESTROYS_INSTANCE)); @@ -941,7 +946,7 @@ public class Vala.GirParser : CodeVisitor { } } else if (symbol is Property) { var colliding = parent.lookup_all (name); - foreach (var node in colliding) { + colliding.foreach ((node) => { if (node.symbol is Signal) { // properties take precedence node.processed = true; @@ -950,7 +955,8 @@ public class Vala.GirParser : CodeVisitor { // getter in C, but not in Vala node.merged = true; } - } + return true; + }); var prop = (Property) symbol; @@ -971,21 +977,23 @@ public class Vala.GirParser : CodeVisitor { Node getter = null; var getters = parent.lookup_all ("get_%s".printf (name)); if (getters != null) { - foreach (var g in getters) { + getters.foreach ((g) => { if ((getter == null || !g.merged) && g.get_cname () == "%sget_%s".printf (parent.get_lower_case_cprefix (), name)) { getter = g; } - } + return true; + }); } Node setter = null; var setters = parent.lookup_all ("set_%s".printf (name)); if (setters != null) { - foreach (var s in setters) { + setters.foreach ((s) => { if ((setter == null || !s.merged) && s.get_cname () == "%sset_%s".printf (parent.get_lower_case_cprefix (), name)) { setter = s; } - } + return true; + }); } prop.set_attribute ("NoAccessorMethod", false); @@ -998,11 +1006,12 @@ public class Vala.GirParser : CodeVisitor { prop.set_attribute ("NoAccessorMethod", true); } else { if (getter.name == name) { - foreach (var node in colliding) { + colliding.foreach ((node) => { if (node.symbol is Method) { node.merged = true; } - } + return true; + }); } prop.get_accessor.value_type.value_owned = m.return_type.value_owned; @@ -1123,7 +1132,7 @@ public class Vala.GirParser : CodeVisitor { } else if (symbol is Struct) { if (parent.symbol is ObjectTypeSymbol || parent.symbol is Struct) { // nested struct - foreach (var fn in members) { + members.foreach ((fn) => { var f = fn.symbol as Field; if (f != null) { if (f.binding == MemberBinding.INSTANCE) { @@ -1133,7 +1142,8 @@ public class Vala.GirParser : CodeVisitor { fn.name = f.name; parent.add_member (fn); } - } + return true; + }); merged = true; } else { // record for a gtype @@ -1214,7 +1224,7 @@ public class Vala.GirParser : CodeVisitor { } if (!(new_symbol && merged) && is_container (symbol)) { - foreach (var node in members) { + members.foreach ((node) => { if (this.deprecated_version > 0 && node.deprecated_version > 0) { if (this.deprecated_version <= node.deprecated_version) { node.deprecated = false; @@ -1235,7 +1245,9 @@ public class Vala.GirParser : CodeVisitor { if (node.new_symbol && !node.merged && !metadata.get_bool (ArgumentType.HIDDEN)) { add_symbol_to_container (symbol, node.symbol); } - } + + return true; + }); var cl = symbol as Class; if (cl != null && !cl.is_compact && cl.default_construction_method == null) { @@ -1313,30 +1325,32 @@ public class Vala.GirParser : CodeVisitor { root.process (this); - foreach (var metadata in metadata_roots) { + metadata_roots.foreach ((metadata) => { report_unused_metadata (metadata); - } + return true; + }); } void map_vala_to_gir () { - foreach (var source_file in context.get_source_files ()) { + context.get_source_files ().foreach ((source_file) => { string gir_namespace = source_file.gir_namespace; string gir_version = source_file.gir_version; Namespace ns = null; if (gir_namespace == null) { - foreach (var node in source_file.get_nodes ()) { + source_file.get_nodes ().foreach ((node) => { if (node is Namespace) { ns = (Namespace) node; gir_namespace = ns.get_attribute_string ("CCode", "gir_namespace"); if (gir_namespace != null) { gir_version = ns.get_attribute_string ("CCode", "gir_version"); - break; + return false; } } - } + return true; + }); } if (gir_namespace == null) { - continue; + return true; } provided_namespaces.add ("%s-%s".printf (gir_namespace, gir_version)); @@ -1346,13 +1360,15 @@ public class Vala.GirParser : CodeVisitor { set_symbol_mapping (gir_symbol, ns); } - foreach (var node in source_file.get_nodes ()) { + source_file.get_nodes ().foreach ((node) => { if (node.has_attribute_argument ("GIR", "name")) { var map_from = new UnresolvedSymbol (gir_symbol, node.get_attribute_string ("GIR", "name")); set_symbol_mapping (map_from, (Symbol) node); } - } - } + return true; + }); + return true; + }); } public override void visit_source_file (SourceFile source_file) { @@ -1530,20 +1546,21 @@ public class Vala.GirParser : CodeVisitor { void assume_parameter_names (Signal sig, Symbol sym, bool skip_first) { var iter = ((Callable) sym).get_parameters ().iterator (); bool first = true; - foreach (var param in sig.get_parameters ()) { + sig.get_parameters ().foreach ((param) => { if (!iter.next ()) { // unreachable for valid GIR - break; + return false; } if (skip_first && first) { if (!iter.next ()) { // unreachable for valid GIR - break; + return false; } first = false; } param.name = iter.get ().name; - } + return true; + }); } Node? find_invoker (Node node) { @@ -1560,13 +1577,14 @@ public class Vala.GirParser : CodeVisitor { continue; } var iter = invoker.get_parameters ().iterator (); - foreach (var param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { assert (iter.next ()); if (param.name != iter.get().name) { invoker = null; - break; + return false; } - } + return true; + }); if (invoker != null) { return n; } @@ -3476,20 +3494,21 @@ public class Vala.GirParser : CodeVisitor { } } - foreach (var child in metadata.children) { + metadata.children.foreach ((child) => { if (!child.used) { Report.warning (child.source_reference, "metadata never used"); } else { report_unused_metadata (child); } - } + return true; + }); } /* Post-parsing */ void resolve_gir_symbols () { // gir has simple namespaces, we won't get deeper than 2 levels here, except reparenting - foreach (var map_from in unresolved_gir_symbols) { + unresolved_gir_symbols.foreach ((map_from) => { while (map_from != null) { var map_to = unresolved_symbols_map[map_from]; if (map_to != null) { @@ -3514,7 +3533,8 @@ public class Vala.GirParser : CodeVisitor { } map_from = map_from.inner; } - } + return true; + }); } void create_new_namespaces () { @@ -3527,7 +3547,7 @@ public class Vala.GirParser : CodeVisitor { void resolve_type_arguments () { // box structs in type arguments - foreach (var element_type in unresolved_type_arguments) { + unresolved_type_arguments.foreach ((element_type) => { TypeSymbol sym = null; if (element_type is UnresolvedType) { sym = (TypeSymbol) resolve_symbol (root, ((UnresolvedType) element_type).unresolved_symbol); @@ -3538,7 +3558,8 @@ public class Vala.GirParser : CodeVisitor { if (st != null && !st.is_integer_type () && !st.is_floating_type ()) { element_type.nullable = true; } - } + return true; + }); } void process_interface (Node iface_node) { @@ -3546,7 +3567,7 @@ public class Vala.GirParser : CodeVisitor { ensure we have at least one instantiable prerequisite */ Interface iface = (Interface) iface_node.symbol; bool has_instantiable_prereq = false; - foreach (DataType prereq in iface.get_prerequisites ()) { + iface.get_prerequisites ().foreach ((prereq) => { Symbol sym = null; if (prereq is UnresolvedType) { var unresolved_symbol = ((UnresolvedType) prereq).unresolved_symbol; @@ -3556,9 +3577,10 @@ public class Vala.GirParser : CodeVisitor { } if (sym is Class) { has_instantiable_prereq = true; - break; + return false; } - } + return true; + }); if (!has_instantiable_prereq) { iface.add_prerequisite (new ObjectType ((ObjectTypeSymbol) glib_ns.scope.lookup ("Object"))); @@ -3685,11 +3707,12 @@ public class Vala.GirParser : CodeVisitor { } } else if (return_type is VoidType && parameters.size > 0) { int n_out_parameters = 0; - foreach (var info in parameters) { + parameters.foreach ((info) => { if (info.param.direction == ParameterDirection.OUT) { n_out_parameters++; } - } + return true; + }); if (n_out_parameters == 1) { ParameterInfo last_param = parameters[parameters.size-1]; @@ -3745,7 +3768,7 @@ public class Vala.GirParser : CodeVisitor { int i = 0, j=1; int last = -1; - foreach (ParameterInfo info in parameters) { + parameters.foreach ((info) => { if (s is Delegate && info.closure_idx == i) { var d = (Delegate) s; d.has_target = true; @@ -3776,11 +3799,12 @@ public class Vala.GirParser : CodeVisitor { info.vala_idx = (j - 1) + (i - last) * 0.1F; } i++; - } + return true; + }); - foreach (ParameterInfo info in parameters) { + parameters.foreach ((info) => { if (!info.keep) { - continue; + return true; } /* add_parameter sets carray_length_parameter_position and cdelegate_target_parameter_position @@ -3792,7 +3816,7 @@ public class Vala.GirParser : CodeVisitor { if (info.array_length_idx != -1) { if ((info.array_length_idx) >= parameters.size) { Report.error (info.param.source_reference, "invalid array_length index"); - continue; + return true; } set_array_ccode (info.param, parameters[info.array_length_idx]); } @@ -3800,7 +3824,7 @@ public class Vala.GirParser : CodeVisitor { if (info.closure_idx != -1) { if ((info.closure_idx) >= parameters.size) { Report.error (info.param.source_reference, "invalid closure index"); - continue; + return true; } if ("%g".printf (parameters[info.closure_idx].vala_idx) != "%g".printf (info.vala_idx + 0.1)) { info.param.set_attribute_double ("CCode", "delegate_target_pos", parameters[info.closure_idx].vala_idx); @@ -3809,7 +3833,7 @@ public class Vala.GirParser : CodeVisitor { if (info.destroy_idx != -1) { if (info.destroy_idx >= parameters.size) { Report.error (info.param.source_reference, "invalid destroy index"); - continue; + return true; } if ("%g".printf (parameters[info.destroy_idx].vala_idx) != "%g".printf (info.vala_idx + 0.2)) { info.param.set_attribute_double ("CCode", "destroy_notify_pos", parameters[info.destroy_idx].vala_idx); @@ -3838,7 +3862,8 @@ public class Vala.GirParser : CodeVisitor { info.param.variable_type.value_owned = (info.closure_idx != -1 && info.destroy_idx != -1); } } - } + return true;; + }); if (return_type is ArrayType && node.return_array_length_idx >= 0) { set_array_ccode (s, parameters[node.return_array_length_idx]); @@ -3929,14 +3954,15 @@ public class Vala.GirParser : CodeVisitor { if (nodes == null) { return; } - foreach (var n in nodes) { + nodes.foreach ((n) => { if (node != n) { n.process (this); } - } - foreach (var n in nodes) { + return true; + }); + nodes.foreach ((n) => { if (n.merged) { - continue; + return true; } var sym = n.symbol; if (sym is Signal) { @@ -3947,7 +3973,8 @@ public class Vala.GirParser : CodeVisitor { var prop = (Property) sym; prop.is_virtual = true; } - } + return true; + }); } void process_async_method (Node node) { @@ -3966,12 +3993,13 @@ public class Vala.GirParser : CodeVisitor { // check if the method is using non-standard finish method name if (finish_method_node == null) { var method_cname = node.get_finish_cname (); - foreach (var n in node.parent.members) { + node.parent.members.foreach ((n) => { if (n.symbol is Method && n.get_cname () == method_cname) { finish_method_node = n; - break; + return false; } - } + return true; + }); } Method method = m; @@ -3999,9 +4027,10 @@ public class Vala.GirParser : CodeVisitor { } else if (finish_method_base.has_prefix ("new_")) { method.name = m.name.substring ("new_".length); } - foreach (var param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { method.add_parameter (param); - } + return true; + }); node.symbol = method; } else { method.return_type = finish_method.return_type.copy (); @@ -4014,7 +4043,7 @@ public class Vala.GirParser : CodeVisitor { } } - foreach (var param in finish_method.get_parameters ()) { + finish_method.get_parameters ().foreach ((param) => { if (param.direction == ParameterDirection.OUT) { var async_param = param.copy (); if (method.scope.lookup (param.name) != null) { @@ -4023,11 +4052,13 @@ public class Vala.GirParser : CodeVisitor { } method.add_parameter (async_param); } - } + return true; + }); - foreach (DataType error_type in finish_method.get_error_types ()) { + finish_method.get_error_types ().foreach ((error_type) => { method.add_error_type (error_type.copy ()); - } + return true; + }); finish_method_node.processed = true; finish_method_node.merged = true; } diff --git a/vala/valainitializerlist.vala b/vala/valainitializerlist.vala index c1f97ca3e..3d7d9cbeb 100644 --- a/vala/valainitializerlist.vala +++ b/vala/valainitializerlist.vala @@ -67,9 +67,10 @@ public class Vala.InitializerList : Expression { } public override void accept_children (CodeVisitor visitor) { - foreach (Expression expr in initializers) { + initializers.foreach ((expr) => { expr.accept (visitor); - } + return true; + }); } public override void accept (CodeVisitor visitor) { @@ -79,21 +80,15 @@ public class Vala.InitializerList : Expression { } public override bool is_constant () { - foreach (Expression initializer in initializers) { - if (!initializer.is_constant ()) { - return false; - } - } - return true; + return initializers.foreach ((initializer) => { + return initializer.is_constant (); + }); } public override bool is_pure () { - foreach (Expression initializer in initializers) { - if (!initializer.is_pure ()) { - return false; - } - } - return true; + return initializers.foreach ((initializer) => { + return initializer.is_pure (); + }); } public override bool is_accessible (Symbol sym) { @@ -157,9 +152,10 @@ public class Vala.InitializerList : Expression { inner_target_type = array_type.element_type.copy (); } - foreach (Expression e in get_initializers ()) { + get_initializers ().foreach ((e) => { e.target_type = inner_target_type; - } + return true; + }); } else if (target_type.data_type is Struct) { /* initializer is used as struct initializer */ var st = (Struct) target_type.data_type; @@ -194,16 +190,17 @@ public class Vala.InitializerList : Expression { return false; } - foreach (Expression expr in initializers) { + initializers.foreach ((expr) => { expr.check (context); - } + return true; + }); bool error = false; - foreach (Expression e in get_initializers ()) { + get_initializers ().foreach ((e) => { if (e.value_type == null) { error = true; Report.error (e.source_reference, "expression type not allowed as initializer"); - continue; + return false; } var unary = e as UnaryExpression; @@ -214,7 +211,8 @@ public class Vala.InitializerList : Expression { e.error = true; Report.error (e.source_reference, "Expected initializer of type `%s' but got `%s'".printf (e.target_type.to_string (), e.value_type.to_string ())); } - } + return true; + }); if (!error) { /* everything seems to be correct */ @@ -226,9 +224,10 @@ public class Vala.InitializerList : Expression { } public override void emit (CodeGenerator codegen) { - foreach (Expression expr in initializers) { + initializers.foreach ((expr) => { expr.emit (codegen); - } + return true; + }); codegen.visit_initializer_list (this); diff --git a/vala/valainterface.vala b/vala/valainterface.vala index 621c6e8ce..c93b27380 100644 --- a/vala/valainterface.vala +++ b/vala/valainterface.vala @@ -288,50 +288,61 @@ public class Vala.Interface : ObjectTypeSymbol { } public override void accept_children (CodeVisitor visitor) { - foreach (DataType type in prerequisites) { + prerequisites.foreach ((type) => { type.accept (visitor); - } + return true; + }); - foreach (TypeParameter p in get_type_parameters ()) { + get_type_parameters ().foreach ((p) => { p.accept (visitor); - } + return true; + }); /* process enums first to avoid order problems in C code */ - foreach (Enum en in enums) { + enums.foreach ((en) => { en.accept (visitor); - } + return true; + }); - foreach (Method m in methods) { + methods.foreach ((m) => { m.accept (visitor); - } + return true; + }); - foreach (Field f in fields) { + fields.foreach ((f) => { f.accept (visitor); - } + return true; + }); - foreach (Constant c in constants) { + constants.foreach ((c) => { c.accept (visitor); - } + return true; + }); - foreach (Property prop in properties) { + properties.foreach ((prop) => { prop.accept (visitor); - } + return true; + }); - foreach (Signal sig in signals) { + signals.foreach ((sig) => { sig.accept (visitor); - } + return true; + }); - foreach (Class cl in classes) { + classes.foreach ((cl) => { cl.accept (visitor); - } + return true; + }); - foreach (Struct st in structs) { + structs.foreach ((st) => { st.accept (visitor); - } + return true; + }); - foreach (Delegate d in delegates) { + delegates.foreach ((d) => { d.accept (visitor); - } + return true; + }); } public override bool is_reference_type () { @@ -343,13 +354,9 @@ public class Vala.Interface : ObjectTypeSymbol { return true; } - foreach (DataType prerequisite in prerequisites) { - if (prerequisite.data_type != null && prerequisite.data_type.is_subtype_of (t)) { - return true; - } - } - - return false; + return !prerequisites.foreach ((prerequisite) => { + return !(prerequisite.data_type != null && prerequisite.data_type.is_subtype_of (t)); + }); } public override void replace_type (DataType old_type, DataType new_type) { @@ -414,63 +421,74 @@ public class Vala.Interface : ObjectTypeSymbol { } } - foreach (DataType type in prerequisites) { + prerequisites.foreach ((type) => { type.check (context); - } + return true; + }); - foreach (TypeParameter p in get_type_parameters ()) { + get_type_parameters ().foreach ((p) => { p.check (context); - } + return true; + }); - foreach (Enum en in enums) { + enums.foreach ((en) => { en.check (context); - } + return true; + }); - foreach (Method m in methods) { + methods.foreach ((m) => { m.check (context); if (m.is_virtual || m.is_abstract) { virtuals.add (m); } - } + return true; + }); - foreach (Field f in fields) { + fields.foreach ((f) => { f.check (context); - } + return true; + }); - foreach (Constant c in constants) { + constants.foreach ((c) => { c.check (context); - } + return true; + }); - foreach (Signal sig in signals) { + signals.foreach ((sig) => { sig.check (context); if (sig.is_virtual) { virtuals.add (sig); } - } + return true; + }); - foreach (Property prop in properties) { + properties.foreach ((prop) => { prop.check (context); if (prop.is_virtual || prop.is_abstract) { virtuals.add (prop); } - } - - foreach (Class cl in classes) { + return true; + }); + + classes.foreach ((cl) => { cl.check (context); - } + return true; + }); - foreach (Struct st in structs) { + structs.foreach ((st) => { st.check (context); - } + return true; + }); - foreach (Delegate d in delegates) { + delegates.foreach ((d) => { d.check (context); - } + return true; + }); Map? positions = new HashMap (); bool ordered_seen = false; bool unordered_seen = false; - foreach (Symbol sym in virtuals) { + virtuals.foreach ((sym) => { int ordering = sym.get_attribute_integer ("CCode", "ordering", -1); if (ordering < -1) { Report.error (sym.source_reference, "%s: Invalid ordering".printf (sym.get_full_name ())); @@ -478,7 +496,7 @@ public class Vala.Interface : ObjectTypeSymbol { error = true; ordered_seen = true; unordered_seen = true; - continue; + return true; } bool ordered = ordering != -1; if (ordered && unordered_seen && !ordered_seen) { @@ -501,7 +519,8 @@ public class Vala.Interface : ObjectTypeSymbol { positions[ordering] = sym; } } - } + return true; + }); if (ordered_seen) { for (int i = 0; i < virtuals.size; i++) { Symbol? sym = positions[i]; diff --git a/vala/valainterfacetype.vala b/vala/valainterfacetype.vala index 3ca1a2c85..94fe02d6f 100644 --- a/vala/valainterfacetype.vala +++ b/vala/valainterfacetype.vala @@ -43,9 +43,10 @@ public class Vala.InterfaceType : ReferenceType { result.is_dynamic = is_dynamic; result.floating_reference = floating_reference; - foreach (DataType arg in get_type_arguments ()) { + get_type_arguments ().foreach ((arg) => { result.add_type_argument (arg.copy ()); - } + return true; + }); return result; } diff --git a/vala/valalambdaexpression.vala b/vala/valalambdaexpression.vala index d194eca6f..ef22c92c6 100644 --- a/vala/valalambdaexpression.vala +++ b/vala/valalambdaexpression.vala @@ -179,10 +179,10 @@ public class Vala.LambdaExpression : Expression { method.add_parameter (lambda_param); } - foreach (Parameter cb_param in cb.get_parameters ()) { + cb.get_parameters ().foreach ((cb_param) => { if (!lambda_param_it.next ()) { /* lambda expressions are allowed to have less parameters */ - break; + return false; } Parameter lambda_param = lambda_param_it.get (); @@ -194,7 +194,8 @@ public class Vala.LambdaExpression : Expression { lambda_param.variable_type = cb_param.variable_type.get_actual_type (target_type, null, this); method.add_parameter (lambda_param); - } + return true; + }); if (lambda_param_it.next ()) { /* lambda expressions may not expect more parameters */ @@ -203,9 +204,10 @@ public class Vala.LambdaExpression : Expression { return false; } - foreach (var error_type in cb.get_error_types ()) { + cb.get_error_types ().foreach ((error_type) => { method.add_error_type (error_type.copy ()); - } + return true; + }); if (expression_body != null) { var block = new Block (source_reference); @@ -226,12 +228,13 @@ public class Vala.LambdaExpression : Expression { // support use of generics in closures var m = context.analyzer.find_parent_method (context.analyzer.current_symbol); if (m != null) { - foreach (var type_param in m.get_type_parameters ()) { + m.get_type_parameters ().foreach ((type_param) => { method.add_type_parameter (new TypeParameter (type_param.name, type_param.source_reference)); method.closure = true; m.body.captured = true; - } + return true; + }); } /* lambda expressions should be usable like MemberAccess of a method */ diff --git a/vala/valamarkupreader.vala b/vala/valamarkupreader.vala index e06e331e4..21fbda622 100644 --- a/vala/valamarkupreader.vala +++ b/vala/valamarkupreader.vala @@ -72,9 +72,7 @@ public class Vala.MarkupReader { */ public Map get_attributes () { var result = new HashMap (); - foreach (var key in attributes.keys) { - result.set (key, attributes.get (key)); - } + result.set_all (attributes); return result; } diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala index c00f5fca5..380c37b46 100644 --- a/vala/valamemberaccess.vala +++ b/vala/valamemberaccess.vala @@ -126,9 +126,10 @@ public class Vala.MemberAccess : Expression { inner.accept (visitor); } - foreach (DataType type_arg in type_argument_list) { + type_argument_list.foreach ((type_arg) => { type_arg.accept (visitor); - } + return true; + }); } public override string to_string () { @@ -204,9 +205,10 @@ public class Vala.MemberAccess : Expression { inner.check (context); } - foreach (DataType type_arg in type_argument_list) { + type_argument_list.foreach ((type_arg) => { type_arg.check (context); - } + return true; + }); Symbol base_symbol = null; Parameter this_parameter = null; @@ -631,13 +633,14 @@ public class Vala.MemberAccess : Expression { // do not allow access to methods using generic type parameters // if instance type does not specify type arguments - foreach (var param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { var generic_type = param.variable_type as GenericType; if (generic_type != null && generic_type.type_parameter.parent_symbol is TypeSymbol) { generics = true; - break; + return false; } - } + return true; + }); var generic_type = m.return_type as GenericType; if (generic_type != null && generic_type.type_parameter.parent_symbol is TypeSymbol) { generics = true; @@ -810,9 +813,10 @@ public class Vala.MemberAccess : Expression { // support static methods in generic classes inner.value_type = new ObjectType ((ObjectTypeSymbol) m.parent_symbol); - foreach (var type_argument in inner_ma.type_argument_list) { + inner_ma.type_argument_list.foreach ((type_argument) => { inner.value_type.add_type_argument (type_argument); - } + return true; + }); } formal_value_type = context.analyzer.get_value_type_for_symbol (symbol_reference, lvalue); diff --git a/vala/valamethod.vala b/vala/valamethod.vala index 9988c6628..c821c96f9 100644 --- a/vala/valamethod.vala +++ b/vala/valamethod.vala @@ -236,21 +236,19 @@ public class Vala.Method : Subroutine, Callable { * Remove all parameters from this method. */ public void clear_parameters () { - foreach (Parameter param in parameters) { + parameters.foreach ((param) => { if (!param.ellipsis) { scope.remove (param.name); } - } + return true; + }); parameters.clear (); } public bool is_variadic () { - foreach (Parameter param in parameters) { - if (param.ellipsis) { - return true; - } - } - return false; + return !parameters.foreach ((param) => { + return !param.ellipsis; + }); } public override void accept (CodeVisitor visitor) { @@ -258,9 +256,10 @@ public class Vala.Method : Subroutine, Callable { } public override void accept_children (CodeVisitor visitor) { - foreach (TypeParameter p in get_type_parameters ()) { + get_type_parameters ().foreach ((p) => { p.accept (visitor); - } + return true; + }); if (base_interface_type != null) { base_interface_type.accept (visitor); @@ -270,28 +269,32 @@ public class Vala.Method : Subroutine, Callable { return_type.accept (visitor); } - foreach (Parameter param in parameters) { + parameters.foreach ((param) => { param.accept (visitor); - } + return true; + }); - foreach (DataType error_type in get_error_types ()) { + get_error_types ().foreach ((error_type) => { error_type.accept (visitor); - } + return true; + }); if (result_var != null) { result_var.accept (visitor); } if (preconditions != null) { - foreach (Expression precondition in preconditions) { + preconditions.foreach ((precondition) => { precondition.accept (visitor); - } + return true; + }); } if (postconditions != null) { - foreach (Expression postcondition in postconditions) { + postconditions.foreach ((postcondition) => { postcondition.accept (visitor); - } + return true; + }); } if (body != null) { @@ -322,11 +325,12 @@ public class Vala.Method : Subroutine, Callable { ObjectType object_type = null; if (parent_symbol is ObjectTypeSymbol) { object_type = new ObjectType ((ObjectTypeSymbol) parent_symbol); - foreach (TypeParameter type_parameter in object_type.type_symbol.get_type_parameters ()) { + object_type.type_symbol.get_type_parameters ().foreach ((type_parameter) => { var type_arg = new GenericType (type_parameter); type_arg.value_owned = true; object_type.add_type_argument (type_arg); - } + return true; + }); } if (this.get_type_parameters ().size < base_method.get_type_parameters ().size) { @@ -390,13 +394,12 @@ public class Vala.Method : Subroutine, Callable { /* this method may throw less but not more errors than the base method */ foreach (DataType method_error_type in get_error_types ()) { - bool match = false; - foreach (DataType base_method_error_type in base_method.get_error_types ()) { + bool match = !base_method.get_error_types ().foreach ((base_method_error_type) => { if (method_error_type.compatible (base_method_error_type)) { - match = true; - break; + return false; } - } + return true; + }); if (!match) { invalid_match = "incompatible error type `%s'".printf (method_error_type.to_string ()); @@ -753,15 +756,17 @@ public class Vala.Method : Subroutine, Callable { } if (preconditions != null) { - foreach (Expression precondition in preconditions) { + preconditions.foreach ((precondition) => { precondition.check (context); - } + return true; + }); } if (postconditions != null) { - foreach (Expression postcondition in postconditions) { + postconditions.foreach ((postcondition) => { postcondition.check (context); - } + return true; + }); } if (body != null) { @@ -840,18 +845,20 @@ public class Vala.Method : Subroutine, Callable { // check that all errors that can be thrown in the method body are declared if (body != null) { - foreach (DataType body_error_type in body.get_error_types ()) { + body.get_error_types ().foreach ((body_error_type) => { bool can_propagate_error = false; - foreach (DataType method_error_type in get_error_types ()) { + get_error_types ().foreach ((method_error_type) => { if (body_error_type.compatible (method_error_type)) { can_propagate_error = true; } - } + return true; + }); bool is_dynamic_error = body_error_type is ErrorType && ((ErrorType) body_error_type).dynamic_error; if (!can_propagate_error && !is_dynamic_error) { Report.warning (body_error_type.source_reference, "unhandled error `%s'".printf (body_error_type.to_string())); } - } + return true; + }); } if (is_possible_entry_point (context)) { @@ -948,13 +955,14 @@ public class Vala.Method : Subroutine, Callable { public int get_required_arguments () { int n = 0; - foreach (var param in parameters) { + parameters.foreach ((param) => { if (param.initializer != null || param.ellipsis) { // optional argument - break; + return false; } n++; - } + return true; + }); return n; } @@ -999,13 +1007,14 @@ public class Vala.Method : Subroutine, Callable { var params = new ArrayList (); Parameter ellipsis = null; - foreach (var param in parameters) { + parameters.foreach ((param) => { if (param.ellipsis) { ellipsis = param; } else if (param.direction == ParameterDirection.IN) { params.add (param); } - } + return true; + }); var callback_type = new DelegateType ((Delegate) glib_ns.scope.lookup ("AsyncReadyCallback")); callback_type.nullable = true; @@ -1039,11 +1048,12 @@ public class Vala.Method : Subroutine, Callable { result_param.set_attribute_double ("CCode", "pos", 0.1); params.add (result_param); - foreach (var param in parameters) { + parameters.foreach ((param) => { if (param.direction == ParameterDirection.OUT) { params.add (param); } - } + return true; + }); return params; } @@ -1059,9 +1069,10 @@ public class Vala.Method : Subroutine, Callable { public void get_captured_variables (Collection variables) { if (captured_variables != null) { - foreach (var local in captured_variables) { + captured_variables.foreach ((local) => { variables.add (local); - } + return true; + }); } } diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala index cefc65131..5d137b1df 100644 --- a/vala/valamethodcall.vala +++ b/vala/valamethodcall.vala @@ -92,9 +92,10 @@ public class Vala.MethodCall : Expression { public override void accept_children (CodeVisitor visitor) { call.accept (visitor); - foreach (Expression expr in argument_list) { + argument_list.foreach ((expr) => { expr.accept (visitor); - } + return true; + }); } public override void replace_expression (Expression old_node, Expression new_node) { @@ -291,9 +292,10 @@ public class Vala.MethodCall : Expression { var struct_creation_expression = new ObjectCreationExpression ((MemberAccess) call, source_reference); struct_creation_expression.struct_creation = true; - foreach (Expression arg in get_argument_list ()) { + get_argument_list ().foreach ((arg) => { struct_creation_expression.add_argument (arg); - } + return true; + }); struct_creation_expression.target_type = target_type; context.analyzer.replaced_nodes.add (this); parent_node.replace_expression (this, struct_creation_expression); @@ -370,9 +372,9 @@ public class Vala.MethodCall : Expression { var args = get_argument_list (); Iterator arg_it = args.iterator (); - foreach (Parameter param in params) { + params.foreach ((param) => { if (param.ellipsis) { - break; + return false; } if (param.params_array) { @@ -384,7 +386,7 @@ public class Vala.MethodCall : Expression { arg.target_type = array_type.element_type; arg.target_type.value_owned = array_type.value_owned; } - break; + return false; } if (arg_it.next ()) { @@ -396,15 +398,17 @@ public class Vala.MethodCall : Expression { last_arg = arg; } - } + return true; + }); // concatenate stringified arguments for methods with attribute [Print] if (mtype is MethodType && ((MethodType) mtype).method_symbol.get_attribute ("Print") != null) { var template = new Template (source_reference); - foreach (Expression arg in argument_list) { + argument_list.foreach ((arg) => { arg.parent_node = null; template.add_expression (arg); - } + return true; + }); argument_list.clear (); add_argument (template); } @@ -423,12 +427,13 @@ public class Vala.MethodCall : Expression { // recreate iterator and skip to right position arg_it = argument_list.iterator (); - foreach (Parameter param in params) { + params.foreach ((param) => { if (param.ellipsis) { - break; + return false; } arg_it.next (); - } + return true; + }); } } else { // use instance as format string for string.printf (...) @@ -445,9 +450,10 @@ public class Vala.MethodCall : Expression { } } - foreach (Expression arg in get_argument_list ()) { + get_argument_list ().foreach ((arg) => { arg.check (context); - } + return true; + }); if (ret_type is VoidType) { // void return type @@ -483,7 +489,7 @@ public class Vala.MethodCall : Expression { if (m != null && m.coroutine && !is_yield_expression && ((MemberAccess) call).member_name != "end") { // .begin call of async method, no error can happen here } else { - foreach (DataType error_type in m.get_error_types ()) { + m.get_error_types ().foreach ((error_type) => { may_throw = true; // ensure we can trace back which expression may throw errors of this type @@ -491,7 +497,8 @@ public class Vala.MethodCall : Expression { call_error_type.source_reference = source_reference; add_error_type (call_error_type); - } + return true; + }); } if (m.returns_floating_reference) { value_type.floating_reference = true; @@ -504,14 +511,15 @@ public class Vala.MethodCall : Expression { if (dynamic_sig != null && dynamic_sig.handler != null) { dynamic_sig.return_type = dynamic_sig.handler.value_type.get_return_type ().copy (); bool first = true; - foreach (Parameter param in dynamic_sig.handler.value_type.get_parameters ()) { + dynamic_sig.handler.value_type.get_parameters ().foreach ((param) => { if (first) { // skip sender parameter first = false; } else { dynamic_sig.add_parameter (param.copy ()); } - } + return true; + }); dynamic_sig.handler.target_type = new DelegateType (dynamic_sig.get_delegate (new ObjectType ((ObjectTypeSymbol) dynamic_sig.parent_symbol), this)); } @@ -524,9 +532,9 @@ public class Vala.MethodCall : Expression { // infer type arguments from arguments arg_it = args.iterator (); - foreach (Parameter param in params) { + params.foreach ((param) => { if (param.ellipsis || param.params_array) { - break; + return false; } if (arg_it.next ()) { @@ -534,12 +542,13 @@ public class Vala.MethodCall : Expression { type_arg = param.variable_type.infer_type_argument (type_param, arg.value_type); if (type_arg != null) { - break; + return false; } arg.target_type = arg.formal_target_type.get_actual_type (target_object_type, method_type_args, this); } - } + return true; + }); // infer type arguments from expected return type if (type_arg == null && target_type != null) { @@ -557,9 +566,9 @@ public class Vala.MethodCall : Expression { // recalculate argument target types with new information arg_it = args.iterator (); - foreach (Parameter param in params) { + params.foreach ((param) => { if (param.ellipsis || param.params_array) { - break; + return false; } if (arg_it.next ()) { @@ -567,7 +576,8 @@ public class Vala.MethodCall : Expression { arg.target_type = arg.formal_target_type.get_actual_type (target_object_type, method_type_args, this); } - } + return true; + }); // recalculate return value type with new information value_type = formal_value_type.get_actual_type (target_object_type, method_type_args, this); @@ -584,7 +594,7 @@ public class Vala.MethodCall : Expression { // constructor var cl = (Class) ((ObjectType) mtype).type_symbol; var m = cl.default_construction_method; - foreach (DataType error_type in m.get_error_types ()) { + m.get_error_types ().foreach ((error_type) => { may_throw = true; // ensure we can trace back which expression may throw errors of this type @@ -592,10 +602,11 @@ public class Vala.MethodCall : Expression { call_error_type.source_reference = source_reference; add_error_type (call_error_type); - } + return true; + }); } else if (mtype is DelegateType) { var d = ((DelegateType) mtype).delegate_symbol; - foreach (DataType error_type in d.get_error_types ()) { + d.get_error_types ().foreach ((error_type) => { may_throw = true; // ensure we can trace back which expression may throw errors of this type @@ -603,7 +614,8 @@ public class Vala.MethodCall : Expression { call_error_type.source_reference = source_reference; add_error_type (call_error_type); - } + return true; + }); } if (!context.analyzer.check_arguments (this, mtype, params, get_argument_list ())) { @@ -666,9 +678,10 @@ public class Vala.MethodCall : Expression { call.emit (codegen); } - foreach (Expression expr in argument_list) { + argument_list.foreach ((expr) => { expr.emit (codegen); - } + return true; + }); codegen.visit_method_call (this); @@ -678,17 +691,19 @@ public class Vala.MethodCall : Expression { public override void get_defined_variables (Collection collection) { call.get_defined_variables (collection); - foreach (Expression arg in argument_list) { + argument_list.foreach ((arg) => { arg.get_defined_variables (collection); - } + return true; + }); } public override void get_used_variables (Collection collection) { call.get_used_variables (collection); - foreach (Expression arg in argument_list) { + argument_list.foreach ((arg) => { arg.get_used_variables (collection); - } + return true; + }); } public StringLiteral? get_format_literal () { diff --git a/vala/valamethodtype.vala b/vala/valamethodtype.vala index 9a492faeb..067592451 100644 --- a/vala/valamethodtype.vala +++ b/vala/valamethodtype.vala @@ -77,14 +77,14 @@ public class Vala.MethodType : DataType { var proto = "%s %s (".printf (get_return_type ().to_string (), this.to_string ()); int i = 1; - foreach (Parameter param in get_parameters ()) { + get_parameters ().foreach ((param) => { if (i > 1) { proto += ", "; } if (param.ellipsis) { proto += "..."; - continue; + return true; } if (param.direction == ParameterDirection.IN) { @@ -109,7 +109,8 @@ public class Vala.MethodType : DataType { } i++; - } + return true; + }); return proto + ")"; } diff --git a/vala/valanamespace.vala b/vala/valanamespace.vala index 47dd4eee1..d43f5bb5d 100644 --- a/vala/valanamespace.vala +++ b/vala/valanamespace.vala @@ -93,42 +93,54 @@ public class Vala.Namespace : Symbol { old_ns.source_reference = ns.source_reference; } - foreach (var using_directive in ns.using_directives) { + ns.using_directives.foreach ((using_directive) => { old_ns.add_using_directive (using_directive); - } - foreach (Namespace sub_ns in ns.get_namespaces ()) { + return true; + }); + ns.get_namespaces ().foreach ((sub_ns) => { old_ns.add_namespace (sub_ns); - } - foreach (Class cl in ns.get_classes ()) { + return true; + }); + ns.get_classes ().foreach ((cl) => { old_ns.add_class (cl); - } - foreach (Struct st in ns.get_structs ()) { + return true; + }); + ns.get_structs ().foreach ((st) => { old_ns.add_struct (st); - } - foreach (Interface iface in ns.get_interfaces ()) { + return true; + }); + ns.get_interfaces ().foreach ((iface) => { old_ns.add_interface (iface); - } - foreach (Delegate d in ns.get_delegates ()) { + return true; + }); + ns.get_delegates ().foreach ((d) => { old_ns.add_delegate (d); - } - foreach (Enum en in ns.get_enums ()) { + return true; + }); + ns.get_enums ().foreach ((en) => { old_ns.add_enum (en); - } - foreach (ErrorDomain ed in ns.get_error_domains ()) { + return true; + }); + ns.get_error_domains ().foreach ((ed) => { old_ns.add_error_domain (ed); - } - foreach (Constant c in ns.get_constants ()) { + return true; + }); + ns.get_constants ().foreach ((c) => { old_ns.add_constant (c); - } - foreach (Field f in ns.get_fields ()) { + return true; + }); + ns.get_fields ().foreach ((f) => { old_ns.add_field (f); - } - foreach (Method m in ns.get_methods ()) { + return true; + }); + ns.get_methods ().foreach ((m) => { old_ns.add_method (m); - } - foreach (Comment c in ns.get_comments ()) { + return true; + }); + ns.get_comments ().foreach ((c) => { old_ns.add_comment (c); - } + return true; + }); foreach (Attribute a in ns.attributes) { if (old_ns.get_attribute (a.name) == null) { old_ns.attributes.append(a); @@ -456,50 +468,61 @@ public class Vala.Namespace : Symbol { } public override void accept_children (CodeVisitor visitor) { - foreach (UsingDirective ns_ref in using_directives) { + using_directives.foreach ((ns_ref) => { ns_ref.accept (visitor); - } + return true; + }); - foreach (Namespace ns in namespaces) { + namespaces.foreach ((ns) => { ns.accept (visitor); - } + return true; + }); /* process enums first to avoid order problems in C code */ - foreach (Enum en in enums) { + enums.foreach ((en) => { en.accept (visitor); - } + return true; + }); - foreach (ErrorDomain edomain in error_domains) { + error_domains.foreach ((edomain) => { edomain.accept (visitor); - } + return true; + }); - foreach (Class cl in classes) { + classes.foreach ((cl) => { cl.accept (visitor); - } + return true; + }); - foreach (Interface iface in interfaces) { + interfaces.foreach ((iface) => { iface.accept (visitor); - } + return true; + }); - foreach (Struct st in structs) { + structs.foreach ((st) => { st.accept (visitor); - } + return true; + }); - foreach (Delegate d in delegates) { + delegates.foreach ((d) => { d.accept (visitor); - } + return true; + }); - foreach (Constant c in constants) { + constants.foreach ((c) => { c.accept (visitor); - } + return true; + }); - foreach (Field f in fields) { + fields.foreach ((f) => { f.accept (visitor); - } + return true; + }); - foreach (Method m in methods) { + methods.foreach ((m) => { m.accept (visitor); - } + return true; + }); } public override bool check (CodeContext context) { diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala index c4b119a44..ebf79170d 100644 --- a/vala/valaobjectcreationexpression.vala +++ b/vala/valaobjectcreationexpression.vala @@ -118,13 +118,15 @@ public class Vala.ObjectCreationExpression : Expression { member_name.accept (visitor); } - foreach (Expression arg in argument_list) { + argument_list.foreach ((arg) => { arg.accept (visitor); - } + return true; + }); - foreach (MemberInitializer init in object_initializer) { + object_initializer.foreach ((init) => { init.accept (visitor); - } + return true; + }); } public override void replace_expression (Expression old_node, Expression new_node) { @@ -236,9 +238,10 @@ public class Vala.ObjectCreationExpression : Expression { return false; } - foreach (DataType type_arg in type_args) { + type_args.foreach ((type_arg) => { type_reference.add_type_argument (type_arg); - } + return true; + }); } else { type = type_reference.data_type; } @@ -367,9 +370,9 @@ public class Vala.ObjectCreationExpression : Expression { var args = get_argument_list (); Iterator arg_it = args.iterator (); - foreach (Parameter param in m.get_parameters ()) { + m.get_parameters ().foreach ((param) => { if (param.ellipsis) { - break; + return false; } if (arg_it.next ()) { @@ -381,7 +384,8 @@ public class Vala.ObjectCreationExpression : Expression { last_arg = arg; } - } + return true; + }); // printf arguments if (m.printf_format) { @@ -413,13 +417,14 @@ public class Vala.ObjectCreationExpression : Expression { } } - foreach (Expression arg in args) { + args.foreach ((arg) => { arg.check (context); - } + return true; + }); context.analyzer.check_arguments (this, new MethodType (m), m.get_parameters (), args); - foreach (DataType error_type in m.get_error_types ()) { + m.get_error_types ().foreach ((error_type) => { may_throw = true; // ensure we can trace back which expression may throw errors of this type @@ -427,7 +432,8 @@ public class Vala.ObjectCreationExpression : Expression { call_error_type.source_reference = source_reference; add_error_type (call_error_type); - } + return true; + }); } else if (type_reference is ErrorType) { if (type_reference != null) { type_reference.check (context); @@ -437,13 +443,15 @@ public class Vala.ObjectCreationExpression : Expression { member_name.check (context); } - foreach (Expression arg in argument_list) { + argument_list.foreach ((arg) => { arg.check (context); - } + return true; + }); - foreach (MemberInitializer init in object_initializer) { + object_initializer.foreach ((init) => { init.check (context); - } + return true; + }); if (get_argument_list ().size == 0) { error = true; @@ -475,9 +483,10 @@ public class Vala.ObjectCreationExpression : Expression { } } - foreach (MemberInitializer init in get_object_initializer ()) { + get_object_initializer ().foreach ((init) => { context.analyzer.visit_member_initializer (init, type_reference); - } + return true; + }); if (may_throw) { if (parent_node is LocalVariable || parent_node is ExpressionStatement) { @@ -516,13 +525,15 @@ public class Vala.ObjectCreationExpression : Expression { } public override void emit (CodeGenerator codegen) { - foreach (Expression arg in argument_list) { + argument_list.foreach ((arg) => { arg.emit (codegen); - } + return true; + }); - foreach (MemberInitializer init in object_initializer) { + object_initializer.foreach ((init) => { init.emit (codegen); - } + return true; + }); codegen.visit_object_creation_expression (this); @@ -530,18 +541,21 @@ public class Vala.ObjectCreationExpression : Expression { } public override void get_defined_variables (Collection collection) { - foreach (Expression arg in argument_list) { + argument_list.foreach ((arg) => { arg.get_defined_variables (collection); - } + return true; + }); } public override void get_used_variables (Collection collection) { - foreach (Expression arg in argument_list) { + argument_list.foreach ((arg) => { arg.get_used_variables (collection); - } + return true; + }); - foreach (MemberInitializer init in object_initializer) { + object_initializer.foreach ((init) => { init.get_used_variables (collection); - } + return true; + }); } } diff --git a/vala/valaobjecttype.vala b/vala/valaobjecttype.vala index eccdbbddf..4748611f8 100644 --- a/vala/valaobjecttype.vala +++ b/vala/valaobjecttype.vala @@ -44,9 +44,10 @@ public class Vala.ObjectType : ReferenceType { result.is_dynamic = is_dynamic; result.floating_reference = floating_reference; - foreach (DataType arg in get_type_arguments ()) { + get_type_arguments ().foreach ((arg) => { result.add_type_argument (arg.copy ()); - } + return true; + }); return result; } diff --git a/vala/valaobjecttypesymbol.vala b/vala/valaobjecttypesymbol.vala index 14fc230da..e473695ae 100644 --- a/vala/valaobjecttypesymbol.vala +++ b/vala/valaobjecttypesymbol.vala @@ -71,11 +71,12 @@ public abstract class Vala.ObjectTypeSymbol : TypeSymbol { public ObjectType get_this_type () { var result = new ObjectType (this); - foreach (var type_parameter in get_type_parameters ()) { + get_type_parameters ().foreach ((type_parameter) => { var type_arg = new GenericType (type_parameter); type_arg.value_owned = true; result.add_type_argument (type_arg); - } + return true; + }); return result; } diff --git a/vala/valaparser.vala b/vala/valaparser.vala index 02677c686..415bf447c 100644 --- a/vala/valaparser.vala +++ b/vala/valaparser.vala @@ -464,9 +464,10 @@ public class Vala.Parser : CodeVisitor { type = new UnresolvedType.from_symbol (sym, get_src (begin)); if (type_arg_list != null) { - foreach (DataType type_arg in type_arg_list) { + type_arg_list.foreach ((type_arg) => { type.add_type_argument (type_arg); - } + return true; + }); } } @@ -683,9 +684,10 @@ public class Vala.Parser : CodeVisitor { var expr = new MemberAccess (null, id, get_src (begin)); expr.qualified = qualified; if (type_arg_list != null) { - foreach (DataType type_arg in type_arg_list) { + type_arg_list.foreach ((type_arg) => { expr.add_type_argument (type_arg); - } + return true; + }); } return expr; } @@ -703,9 +705,10 @@ public class Vala.Parser : CodeVisitor { expect (TokenType.CLOSE_PARENS); if (expr_list.size != 1) { var tuple = new Tuple (get_src (begin)); - foreach (Expression expr in expr_list) { + expr_list.foreach ((expr) => { tuple.add_expression (expr); - } + return true; + }); return tuple; } return expr_list.get (0); @@ -740,9 +743,10 @@ public class Vala.Parser : CodeVisitor { List type_arg_list = parse_type_argument_list (true); var expr = new MemberAccess (inner, id, get_src (begin)); if (type_arg_list != null) { - foreach (DataType type_arg in type_arg_list) { + type_arg_list.foreach ((type_arg) => { expr.add_type_argument (type_arg); - } + return true; + }); } return expr; } @@ -753,9 +757,10 @@ public class Vala.Parser : CodeVisitor { List type_arg_list = parse_type_argument_list (true); var expr = new MemberAccess.pointer (inner, id, get_src (begin)); if (type_arg_list != null) { - foreach (DataType type_arg in type_arg_list) { + type_arg_list.foreach ((type_arg) => { expr.add_type_argument (type_arg); - } + return true; + }); } return expr; } @@ -773,18 +778,21 @@ public class Vala.Parser : CodeVisitor { var expr = new ObjectCreationExpression (member, get_src (begin)); expr.struct_creation = true; - foreach (Expression arg in arg_list) { + arg_list.foreach ((arg) => { expr.add_argument (arg); - } - foreach (MemberInitializer initializer in init_list) { + return true; + }); + init_list.foreach ((initializer) => { expr.add_member_initializer (initializer); - } + return true; + }); return expr; } else { var expr = new MethodCall (inner, get_src (begin)); - foreach (Expression arg in arg_list) { + arg_list.foreach ((arg) => { expr.add_argument (arg); - } + return true; + }); return expr; } } @@ -801,9 +809,10 @@ public class Vala.Parser : CodeVisitor { if (stop == null) { var expr = new ElementAccess (inner, get_src (begin)); - foreach (Expression index in index_list) { + index_list.foreach ((index) => { expr.append_index (index); - } + return true; + }); return expr; } else { return new SliceExpression (inner, index_list[0], stop, get_src (begin)); @@ -878,12 +887,14 @@ public class Vala.Parser : CodeVisitor { var init_list = parse_object_initializer (); var expr = new ObjectCreationExpression (member, get_src (begin)); - foreach (Expression arg in arg_list) { + arg_list.foreach ((arg) => { expr.add_argument (arg); - } - foreach (MemberInitializer initializer in init_list) { + return true; + }); + init_list.foreach ((initializer) => { expr.add_member_initializer (initializer); - } + return true; + }); return expr; } @@ -953,9 +964,10 @@ public class Vala.Parser : CodeVisitor { } var expr = new ArrayCreationExpression (element_type, size_specifier_list.size, initializer, get_src (begin)); if (size_specified) { - foreach (Expression size in size_specifier_list) { + size_specifier_list.foreach ((size) => { expr.append_size (size); - } + return true; + }); } return expr; } @@ -1445,9 +1457,10 @@ public class Vala.Parser : CodeVisitor { var expr = parse_expression (); lambda = new LambdaExpression (expr, get_src (begin)); } - foreach (var param in params) { + params.foreach ((param) => { lambda.add_parameter (param); - } + return true; + }); return lambda; } @@ -1980,12 +1993,14 @@ public class Vala.Parser : CodeVisitor { var src = get_src (begin); var body = parse_embedded_statement ("for"); var stmt = new ForStatement (condition, body, src); - foreach (Expression init in initializer_list) { + initializer_list.foreach ((init) => { stmt.add_initializer (init); - } - foreach (Expression iter in iterator_list) { + return true; + }); + iterator_list.foreach ((iter) => { stmt.add_iterator (iter); - } + return true; + }); if (block != null) { block.add_statement (stmt); return block; @@ -2178,12 +2193,13 @@ public class Vala.Parser : CodeVisitor { void set_attributes (CodeNode node, List? attributes) { if (attributes != null) { - foreach (Attribute attr in (List) attributes) { + attributes.foreach ((attr) => { if (node.get_attribute (attr.name) != null) { Report.error (attr.source_reference, "duplicate attribute `%s`".printf (attr.name)); } node.attributes.append (attr); - } + return true; + }); } } @@ -2514,12 +2530,14 @@ public class Vala.Parser : CodeVisitor { cl.external = true; } set_attributes (cl, attrs); - foreach (TypeParameter type_param in type_param_list) { + type_param_list.foreach ((type_param) => { cl.add_type_parameter (type_param); - } - foreach (DataType base_type in base_types) { + return true; + }); + base_types.foreach ((base_type) => { cl.add_base_type (base_type); - } + return true; + }); parse_declarations (cl); @@ -2657,9 +2675,10 @@ public class Vala.Parser : CodeVisitor { } method.access = access; set_attributes (method, attrs); - foreach (TypeParameter type_param in type_param_list) { + type_param_list.foreach ((type_param) => { method.add_type_parameter (type_param); - } + return true; + }); if (ModifierFlags.STATIC in flags && ModifierFlags.CLASS in flags) { Report.error (method.source_reference, "only one of `static' or `class' may be specified"); } else if (ModifierFlags.STATIC in flags) { @@ -2977,9 +2996,10 @@ public class Vala.Parser : CodeVisitor { st.external = true; } set_attributes (st, attrs); - foreach (TypeParameter type_param in type_param_list) { + type_param_list.foreach ((type_param) => { st.add_type_parameter (type_param); - } + return true; + }); if (base_type != null) { st.base_type = base_type; } @@ -3020,12 +3040,14 @@ public class Vala.Parser : CodeVisitor { iface.external = true; } set_attributes (iface, attrs); - foreach (TypeParameter type_param in type_param_list) { + type_param_list.foreach ((type_param) => { iface.add_type_parameter (type_param); - } - foreach (DataType base_type in base_types) { + return true; + }); + base_types.foreach ((base_type) => { iface.add_prerequisite (base_type); - } + return true; + }); parse_declarations (iface); @@ -3367,9 +3389,10 @@ public class Vala.Parser : CodeVisitor { if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) { d.external = true; } - foreach (TypeParameter type_param in type_param_list) { + type_param_list.foreach ((type_param) => { d.add_type_parameter (type_param); - } + return true; + }); expect (TokenType.OPEN_PARENS); if (current () != TokenType.CLOSE_PARENS) { do { @@ -3495,9 +3518,10 @@ public class Vala.Parser : CodeVisitor { expr = new MemberAccess (expr != null ? expr : base_expr, id, get_src (begin)); expr.qualified = qualified; if (type_arg_list != null) { - foreach (DataType type_arg in type_arg_list) { + type_arg_list.foreach ((type_arg) => { expr.add_type_argument (type_arg); - } + return true; + }); } first = false; diff --git a/vala/valaproperty.vala b/vala/valaproperty.vala index bc6b18efc..0fb34aa7a 100644 --- a/vala/valaproperty.vala +++ b/vala/valaproperty.vala @@ -354,7 +354,7 @@ public class Vala.Property : Symbol, Lockable { private void find_base_interface_property (Class cl) { // FIXME report error if multiple possible base properties are found - foreach (DataType type in cl.get_base_types ()) { + cl.get_base_types ().foreach ((type) => { if (type.data_type is Interface) { var sym = type.data_type.scope.lookup (name); if (sym is Property) { @@ -364,15 +364,16 @@ public class Vala.Property : Symbol, Lockable { if (!compatible (base_property, out invalid_match)) { error = true; Report.error (source_reference, "Type and/or accessors of overriding property `%s' do not match overridden property `%s': %s.".printf (get_full_name (), base_property.get_full_name (), invalid_match)); - return; + return false; } _base_interface_property = base_property; - return; + return false; } } } - } + return true; + }); } public override bool check (CodeContext context) { diff --git a/vala/valapropertyaccessor.vala b/vala/valapropertyaccessor.vala index 81981b84a..bf561663c 100644 --- a/vala/valapropertyaccessor.vala +++ b/vala/valapropertyaccessor.vala @@ -191,11 +191,12 @@ public class Vala.PropertyAccessor : Subroutine { body.check (context); - foreach (DataType body_error_type in body.get_error_types ()) { + body.get_error_types ().foreach ((body_error_type) => { if (!((ErrorType) body_error_type).dynamic_error) { Report.warning (body_error_type.source_reference, "unhandled error `%s'".printf (body_error_type.to_string())); } - } + return true; + }); } context.analyzer.current_symbol = old_symbol; diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index f3b1a633d..f7e862937 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -369,11 +369,12 @@ public class Vala.SemanticAnalyzer : CodeVisitor { } if (type_parameters != null) { - foreach (var type_param in type_parameters) { + type_parameters.foreach ((type_param) => { var type_arg = new GenericType (type_param); type_arg.value_owned = true; type.add_type_argument (type_arg); - } + return true; + }); } return type; @@ -732,11 +733,12 @@ public class Vala.SemanticAnalyzer : CodeVisitor { } else { assert_not_reached (); } - foreach (DataType type_arg in base_type.get_type_arguments ()) { + base_type.get_type_arguments ().foreach ((type_arg) => { // resolve type argument specified in base type (possibly recursively for nested generic types) type_arg = type_arg.get_actual_type (instance_type, null, node_reference); instance_base_type.add_type_argument (type_arg); - } + return true; + }); return instance_base_type; } diff --git a/vala/valasignal.vala b/vala/valasignal.vala index d11180fb3..2a99ef8aa 100644 --- a/vala/valasignal.vala +++ b/vala/valasignal.vala @@ -119,7 +119,7 @@ public class Vala.Signal : Symbol, Lockable, Callable { bool is_generic = false; - foreach (Parameter param in parameters) { + parameters.foreach ((param) => { var actual_param = param.copy (); actual_param.variable_type = actual_param.variable_type.get_actual_type (sender_type, null, node_reference); generated_delegate.add_parameter (actual_param); @@ -127,13 +127,15 @@ public class Vala.Signal : Symbol, Lockable, Callable { if (actual_param.variable_type is GenericType) { is_generic = true; } - } + return true; + }); if (is_generic) { var cl = (ObjectTypeSymbol) parent_symbol; - foreach (var type_param in cl.get_type_parameters ()) { + cl.get_type_parameters ().foreach ((type_param) => { generated_delegate.add_type_parameter (new TypeParameter (type_param.name, type_param.source_reference)); - } + return true; + }); // parameter types must refer to the delegate type parameters // instead of to the class type parameters @@ -156,9 +158,10 @@ public class Vala.Signal : Symbol, Lockable, Callable { public override void accept_children (CodeVisitor visitor) { return_type.accept (visitor); - foreach (Parameter param in parameters) { + parameters.foreach ((param) => { param.accept (visitor); - } + return true; + }); if (default_handler == null && body != null) { body.accept (visitor); } else if (default_handler != null) { @@ -218,9 +221,10 @@ public class Vala.Signal : Symbol, Lockable, Callable { default_handler.body = body; - foreach (Parameter param in parameters) { + parameters.foreach ((param) => { default_handler.add_parameter (param); - } + return true; + }); var cl = parent_symbol as ObjectTypeSymbol; diff --git a/vala/valasignaltype.vala b/vala/valasignaltype.vala index 237a549d4..a6490df89 100644 --- a/vala/valasignaltype.vala +++ b/vala/valasignaltype.vala @@ -67,11 +67,12 @@ public class Vala.SignalType : DataType { result.value_owned = true; if (result.delegate_symbol.get_type_parameters ().size > 0) { - foreach (var type_param in type_sym.get_type_parameters ()) { + type_sym.get_type_parameters ().foreach ((type_param) => { var type_arg = new GenericType (type_param); type_arg.value_owned = true; result.add_type_argument (type_arg); - } + return true; + }); } return result; diff --git a/vala/valasourcefile.vala b/vala/valasourcefile.vala index 04dfeff4c..a8f63c194 100644 --- a/vala/valasourcefile.vala +++ b/vala/valasourcefile.vala @@ -199,9 +199,10 @@ public class Vala.SourceFile { // for correct symbol resolving var old_using_directives = current_using_directives; current_using_directives = new ArrayList (); - foreach (var using_directive in old_using_directives) { + old_using_directives.foreach ((using_directive) => { current_using_directives.add (using_directive); - } + return true; + }); current_using_directives.add (ns); } @@ -232,9 +233,10 @@ public class Vala.SourceFile { } public void accept_children (CodeVisitor visitor) { - foreach (CodeNode node in nodes) { + nodes.foreach ((node) => { node.accept (visitor); - } + return true; + }); } private string get_subdir () { @@ -382,9 +384,10 @@ public class Vala.SourceFile { } public bool check (CodeContext context) { - foreach (CodeNode node in nodes) { + nodes.foreach ((node) => { node.check (context); - } + return true; + }); return true; } } diff --git a/vala/valastatementlist.vala b/vala/valastatementlist.vala index 934227a1a..3319f929b 100644 --- a/vala/valastatementlist.vala +++ b/vala/valastatementlist.vala @@ -49,14 +49,16 @@ public class Vala.StatementList : CodeNode, Statement { } public override void accept (CodeVisitor visitor) { - foreach (Statement stmt in list) { + list.foreach ((stmt) => { stmt.accept (visitor); - } + return true; + }); } public override void emit (CodeGenerator codegen) { - foreach (Statement stmt in list) { + list.foreach ((stmt) => { stmt.emit (codegen); - } + return true; + }); } } diff --git a/vala/valastruct.vala b/vala/valastruct.vala index 21985d7af..fc008b615 100644 --- a/vala/valastruct.vala +++ b/vala/valastruct.vala @@ -273,25 +273,30 @@ public class Vala.Struct : TypeSymbol { base_type.accept (visitor); } - foreach (TypeParameter p in type_parameters) { + type_parameters.foreach ((p) => { p.accept (visitor); - } + return true; + }); - foreach (Field f in fields) { + fields.foreach ((f) => { f.accept (visitor); - } + return true; + }); - foreach (Constant c in constants) { + constants.foreach ((c) => { c.accept (visitor); - } + return true; + }); - foreach (Method m in methods) { + methods.foreach ((m) => { m.accept (visitor); - } + return true; + }); - foreach (Property prop in properties) { + properties.foreach ((prop) => { prop.accept (visitor); - } + return true; + }); } /** @@ -448,14 +453,10 @@ public class Vala.Struct : TypeSymbol { return true; } - foreach (Field f in fields) { - if (f.binding == MemberBinding.INSTANCE - && f.variable_type.is_disposable ()) { - return true; - } - } - - return false; + return !fields.foreach ((f) => { + return !(f.binding == MemberBinding.INSTANCE + && f.variable_type.is_disposable ()); + }); } bool is_recursive_value_type (DataType type) { @@ -465,11 +466,9 @@ public class Vala.Struct : TypeSymbol { if (st == this) { return true; } - foreach (Field f in st.fields) { - if (f.binding == MemberBinding.INSTANCE && is_recursive_value_type (f.variable_type)) { - return true; - } - } + return !st.fields.foreach ((f) => { + return !(f.binding == MemberBinding.INSTANCE && is_recursive_value_type (f.variable_type)); + }); } return false; } @@ -499,9 +498,10 @@ public class Vala.Struct : TypeSymbol { } } - foreach (TypeParameter p in type_parameters) { + type_parameters.foreach ((p) => { p.check (context); - } + return true; + }); foreach (Field f in fields) { f.check (context); @@ -519,30 +519,34 @@ public class Vala.Struct : TypeSymbol { } } - foreach (Constant c in constants) { + constants.foreach ((c) => { c.check (context); - } + return true; + }); - foreach (Method m in methods) { + methods.foreach ((m) => { m.check (context); - } + return true; + }); - foreach (Property prop in properties) { + properties.foreach ((prop) => { prop.check (context); - } + return true; + }); if (!external && !external_package) { if (base_type == null && get_fields ().size == 0 && !is_boolean_type () && !is_integer_type () && !is_floating_type ()) { error = true; Report.error (source_reference, "structs cannot be empty: %s".printf(name)); } else if (base_type != null) { - foreach (Field f in fields) { + fields.foreach ((f) => { if (f.binding == MemberBinding.INSTANCE) { error = true; Report.error (source_reference, "derived structs may not have instance fields"); - break; + return false; } - } + return true; + }); } } diff --git a/vala/valastructvaluetype.vala b/vala/valastructvaluetype.vala index 556162789..eae532b01 100644 --- a/vala/valastructvaluetype.vala +++ b/vala/valastructvaluetype.vala @@ -63,9 +63,10 @@ public class Vala.StructValueType : ValueType { result.value_owned = value_owned; result.nullable = nullable; - foreach (DataType arg in get_type_arguments ()) { + get_type_arguments ().foreach ((arg) => { result.add_type_argument (arg.copy ()); - } + return true; + }); return result; } diff --git a/vala/valaswitchsection.vala b/vala/valaswitchsection.vala index bf9932f04..fce1e7788 100644 --- a/vala/valaswitchsection.vala +++ b/vala/valaswitchsection.vala @@ -62,13 +62,9 @@ public class Vala.SwitchSection : Block { } public bool has_default_label () { - foreach (SwitchLabel label in labels) { - if (label.expression == null) { - return true; - } - } - - return false; + return !labels.foreach ((label) => { + return label.expression != null; + }); } public override void accept (CodeVisitor visitor) { @@ -76,13 +72,15 @@ public class Vala.SwitchSection : Block { } public override void accept_children (CodeVisitor visitor) { - foreach (SwitchLabel label in labels) { + labels.foreach ((label) => { label.accept (visitor); - } + return true; + }); - foreach (Statement st in get_statements ()) { + get_statements ().foreach ((st) => { st.accept (visitor); - } + return true; + }); } public override bool check (CodeContext context) { @@ -92,9 +90,10 @@ public class Vala.SwitchSection : Block { checked = true; - foreach (SwitchLabel label in get_labels ()) { + get_labels ().foreach ((label) => { label.check (context); - } + return true; + }); owner = context.analyzer.current_symbol.scope; @@ -103,18 +102,21 @@ public class Vala.SwitchSection : Block { context.analyzer.current_symbol = this; context.analyzer.insert_block = this; - foreach (Statement st in get_statements ()) { + get_statements ().foreach ((st) => { st.check (context); - } + return true; + }); - foreach (LocalVariable local in get_local_variables ()) { + get_local_variables ().foreach ((local) => { local.active = false; - } + return true; + }); // use get_statements () instead of statement_list to not miss errors within StatementList objects - foreach (Statement stmt in get_statements ()) { + get_statements ().foreach ((stmt) => { add_error_types (stmt.get_error_types ()); - } + return true; + }); context.analyzer.current_symbol = old_symbol; context.analyzer.insert_block = old_insert_block; @@ -123,9 +125,10 @@ public class Vala.SwitchSection : Block { } public override void emit (CodeGenerator codegen) { - foreach (SwitchLabel label in labels) { + labels.foreach ((label) => { label.emit (codegen); - } + return true; + }); base.emit (codegen); } diff --git a/vala/valaswitchstatement.vala b/vala/valaswitchstatement.vala index 9c382be89..f3a3024cc 100644 --- a/vala/valaswitchstatement.vala +++ b/vala/valaswitchstatement.vala @@ -82,9 +82,10 @@ public class Vala.SwitchStatement : CodeNode, Statement { visitor.visit_end_full_expression (expression); - foreach (SwitchSection section in sections) { + sections.foreach ((section) => { section.accept (visitor); - } + return true; + }); } public override void replace_expression (Expression old_node, Expression new_node) { @@ -119,11 +120,11 @@ public class Vala.SwitchStatement : CodeNode, Statement { expression.target_type.nullable = false; var labelset = new HashSet (); - foreach (SwitchSection section in sections) { + sections.foreach ((section) => { section.check (context); // check for duplicate literal case labels - foreach (SwitchLabel label in section.get_labels ()) { + section.get_labels ().foreach ((label) => { if (label.expression != null) { string? value = null; if (label.expression is StringLiteral) { @@ -139,9 +140,11 @@ public class Vala.SwitchStatement : CodeNode, Statement { Report.error (label.expression.source_reference, "Switch statement already contains this label"); } } - } + return true; + }); add_error_types (section.get_error_types ()); - } + return true; + }); return !error; } diff --git a/vala/valasymbolresolver.vala b/vala/valasymbolresolver.vala index 32c84e4c3..c44261d22 100644 --- a/vala/valasymbolresolver.vala +++ b/vala/valasymbolresolver.vala @@ -352,9 +352,10 @@ public class Vala.SymbolResolver : CodeVisitor { } type.is_dynamic = unresolved_type.is_dynamic; - foreach (DataType type_arg in unresolved_type.get_type_arguments ()) { + unresolved_type.get_type_arguments ().foreach ((type_arg) => { type.add_type_argument (type_arg); - } + return true; + }); return type; } diff --git a/vala/valatemplate.vala b/vala/valatemplate.vala index 5e27a7b8e..279872b89 100644 --- a/vala/valatemplate.vala +++ b/vala/valatemplate.vala @@ -33,9 +33,10 @@ public class Vala.Template : Expression { } public override void accept_children (CodeVisitor visitor) { - foreach (var expr in expression_list) { + expression_list.foreach ((expr) => { expr.accept (visitor); - } + return true; + }); } public void add_expression (Expression expr) { diff --git a/vala/valatrystatement.vala b/vala/valatrystatement.vala index 38000f516..59bee715e 100644 --- a/vala/valatrystatement.vala +++ b/vala/valatrystatement.vala @@ -95,9 +95,10 @@ public class Vala.TryStatement : CodeNode, Statement { public override void accept_children (CodeVisitor visitor) { body.accept (visitor); - foreach (CatchClause clause in catch_clauses) { + catch_clauses.foreach ((clause) => { clause.accept (visitor); - } + return true; + }); if (finally_body != null) { finally_body.accept (visitor); @@ -114,33 +115,39 @@ public class Vala.TryStatement : CodeNode, Statement { body.check (context); var error_types = new ArrayList (); - foreach (DataType body_error_type in body.get_error_types ()) { + body.get_error_types ().foreach ((body_error_type) => { error_types.add (body_error_type); - } + return true; + }); var handled_error_types = new ArrayList (); - foreach (CatchClause clause in catch_clauses) { - foreach (DataType body_error_type in error_types) { + catch_clauses.foreach ((clause) => { + error_types.foreach ((body_error_type) => { if (clause.error_type == null || body_error_type.compatible (clause.error_type)) { handled_error_types.add (body_error_type); } - } - foreach (DataType handled_error_type in handled_error_types) { + return true; + }); + handled_error_types.foreach ((handled_error_type) => { error_types.remove (handled_error_type); - } + return true; + }); handled_error_types.clear (); clause.check (context); - foreach (DataType body_error_type in clause.body.get_error_types ()) { + clause.body.get_error_types ().foreach ((body_error_type) => { error_types.add (body_error_type); - } - } + return true; + }); + return true; + }); if (finally_body != null) { finally_body.check (context); - foreach (DataType body_error_type in finally_body.get_error_types ()) { + finally_body.get_error_types ().foreach ((body_error_type) => { error_types.add (body_error_type); - } + return true; + }); } add_error_types (error_types); diff --git a/vala/valatuple.vala b/vala/valatuple.vala index d35795a39..4f51c3d66 100644 --- a/vala/valatuple.vala +++ b/vala/valatuple.vala @@ -33,9 +33,10 @@ public class Vala.Tuple : Expression { } public override void accept_children (CodeVisitor visitor) { - foreach (Expression expr in expression_list) { + expression_list.foreach ((expr) => { expr.accept (visitor); - } + return true; + }); } public override void accept (CodeVisitor visitor) { @@ -77,9 +78,10 @@ public class Vala.Tuple : Expression { } public override void emit (CodeGenerator codegen) { - foreach (Expression expr in expression_list) { + expression_list.foreach ((expr) => { expr.emit (codegen); - } + return true; + }); codegen.visit_tuple (this); diff --git a/vala/valaunresolvedtype.vala b/vala/valaunresolvedtype.vala index 527fa0a7d..9b55fd67e 100644 --- a/vala/valaunresolvedtype.vala +++ b/vala/valaunresolvedtype.vala @@ -61,9 +61,10 @@ public class Vala.UnresolvedType : DataType { type_ref.value_owned = true; var ma = (MemberAccess) expr; - foreach (DataType arg in ma.get_type_arguments ()) { + ma.get_type_arguments ().foreach ((arg) => { type_ref.add_type_argument (arg); - } + return true; + }); return type_ref; } @@ -79,9 +80,10 @@ public class Vala.UnresolvedType : DataType { result.is_dynamic = is_dynamic; result.unresolved_symbol = unresolved_symbol.copy (); - foreach (DataType arg in get_type_arguments ()) { + get_type_arguments ().foreach ((arg) => { result.add_type_argument (arg.copy ()); - } + return true; + }); return result; } @@ -93,7 +95,7 @@ public class Vala.UnresolvedType : DataType { if (type_args.size > 0) { s += "<"; bool first = true; - foreach (DataType type_arg in type_args) { + type_args.foreach ((type_arg) => { if (!first) { s += ","; } else { @@ -103,7 +105,8 @@ public class Vala.UnresolvedType : DataType { s += "weak "; } s += type_arg.to_qualified_string (scope); - } + return true; + }); s += ">"; } if (nullable) { -- cgit v1.2.1