From 4389522e22fd84f191829619df6a247098870733 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrg=20Billeter?= Date: Tue, 16 May 2006 20:46:25 +0000 Subject: [PATCH] fix multi-line comments basic statement and expression handling support MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2006-05-16 Jürg Billeter * vala/scanner.l: fix multi-line comments * vala/valacodegenerator.vala: basic statement and expression handling * vala/valacodevisitor.vala: support variable declaration * vala/valasymbolbuilder.vala: adapt to visitor changes * vala/valaclass.vala: remove members already available in Struct * vala/valacodenode.vala: add ccodenode field * vala/valadeclarationstatement.vala: visit declaration * vala/valaexpressionstatement.vala: visit code containers after child elements * vala/valalocalvariabledeclaration.vala: add accept method * vala/valamethod.vala: add begin and end visit events * vala/valanamespace.vala: add lower_case_cprefix * vala/valastruct.vala: define get_upper_case_cname method * vala/valatype.vala: declare get_upper_case_cname method * vala/valatypereference.vala: add get_upper_case_cname method * vala/valavariabledeclarator.vala: add accept method * ccode/valaccodewriter.vala: formatting fixes * ccode/valaccodeassignment.vala * ccode/valaccodebinaryexpression.vala * ccode/valaccodeblock.vala: use CCodeStatement * ccode/valaccodeconstant.vala * ccode/valaccodedeclarationstatement.vala * ccode/valaccodeemptystatement.vala * ccode/valaccodeexpression.vala * ccode/valaccodeexpressionstatement.vala * ccode/valaccodeforstatement.vala * ccode/valaccodefunction.vala: formatting fixes * ccode/valaccodefunctioncall.vala * ccode/valaccodeidentifier.vala * ccode/valaccodeifstatement.vala * ccode/valaccodereturnstatement.vala * ccode/valaccodestatement.vala * ccode/valaccodestruct.vala: formatting fixes * ccode/valaccodevariabledeclarator.vala * bindings/GLib.vala: extend string types * valac/context.c: resolve types in named argument list in object creation expression svn path=/trunk/; revision=20 --- vala/ChangeLog | 40 +++++++ vala/bindings/GLib.vala | 14 ++- vala/ccode/valaccodeassignment.vala | 40 +++++++ vala/ccode/valaccodebinaryexpression.vala | 39 +++++++ vala/ccode/valaccodeblock.vala | 12 +- vala/ccode/valaccodeconstant.vala | 33 ++++++ vala/ccode/valaccodedeclarationstatement.vala | 55 ++++++++++ vala/ccode/valaccodeemptystatement.vala | 33 ++++++ vala/ccode/valaccodeexpression.vala | 28 +++++ vala/ccode/valaccodeexpressionstatement.vala | 38 +++++++ vala/ccode/valaccodeforstatement.vala | 81 ++++++++++++++ vala/ccode/valaccodefunction.vala | 5 +- vala/ccode/valaccodefunctioncall.vala | 54 +++++++++ vala/ccode/valaccodeidentifier.vala | 33 ++++++ vala/ccode/valaccodeifstatement.vala | 50 +++++++++ vala/ccode/valaccodereturnstatement.vala | 41 +++++++ vala/ccode/valaccodestatement.vala | 28 +++++ vala/ccode/valaccodestruct.vala | 10 +- vala/ccode/valaccodevariabledeclarator.vala | 39 +++++++ vala/ccode/valaccodewriter.vala | 21 +++- vala/vala/scanner.l | 2 +- vala/vala/valaclass.vala | 8 +- vala/vala/valacodegenerator.vala | 152 +++++++++++++++++++++++++- vala/vala/valacodenode.vala | 1 + vala/vala/valacodevisitor.vala | 13 ++- vala/vala/valadeclarationstatement.vala | 2 + vala/vala/valaexpressionstatement.vala | 4 +- vala/vala/valalocalvariabledeclaration.vala | 22 +++- vala/vala/valamethod.vala | 4 +- vala/vala/valanamespace.vala | 35 ++++-- vala/vala/valastruct.vala | 28 ++++- vala/vala/valasymbolbuilder.vala | 2 +- vala/vala/valatype.vala | 1 + vala/vala/valatypereference.vala | 7 +- vala/vala/valavariabledeclarator.vala | 16 ++- vala/valac/context.c | 4 + 36 files changed, 947 insertions(+), 48 deletions(-) create mode 100644 vala/ccode/valaccodeassignment.vala create mode 100644 vala/ccode/valaccodebinaryexpression.vala create mode 100644 vala/ccode/valaccodeconstant.vala create mode 100644 vala/ccode/valaccodedeclarationstatement.vala create mode 100644 vala/ccode/valaccodeemptystatement.vala create mode 100644 vala/ccode/valaccodeexpression.vala create mode 100644 vala/ccode/valaccodeexpressionstatement.vala create mode 100644 vala/ccode/valaccodeforstatement.vala create mode 100644 vala/ccode/valaccodefunctioncall.vala create mode 100644 vala/ccode/valaccodeidentifier.vala create mode 100644 vala/ccode/valaccodeifstatement.vala create mode 100644 vala/ccode/valaccodereturnstatement.vala create mode 100644 vala/ccode/valaccodestatement.vala create mode 100644 vala/ccode/valaccodevariabledeclarator.vala diff --git a/vala/ChangeLog b/vala/ChangeLog index 1a4c924..b08cb2d 100644 --- a/vala/ChangeLog +++ b/vala/ChangeLog @@ -1,5 +1,45 @@ 2006-05-16 Jürg Billeter + * vala/scanner.l: fix multi-line comments + * vala/valacodegenerator.vala: basic statement and expression handling + * vala/valacodevisitor.vala: support variable declaration + * vala/valasymbolbuilder.vala: adapt to visitor changes + * vala/valaclass.vala: remove members already available in Struct + * vala/valacodenode.vala: add ccodenode field + * vala/valadeclarationstatement.vala: visit declaration + * vala/valaexpressionstatement.vala: visit code containers after child + elements + * vala/valalocalvariabledeclaration.vala: add accept method + * vala/valamethod.vala: add begin and end visit events + * vala/valanamespace.vala: add lower_case_cprefix + * vala/valastruct.vala: define get_upper_case_cname method + * vala/valatype.vala: declare get_upper_case_cname method + * vala/valatypereference.vala: add get_upper_case_cname method + * vala/valavariabledeclarator.vala: add accept method + * ccode/valaccodewriter.vala: formatting fixes + * ccode/valaccodeassignment.vala + * ccode/valaccodebinaryexpression.vala + * ccode/valaccodeblock.vala: use CCodeStatement + * ccode/valaccodeconstant.vala + * ccode/valaccodedeclarationstatement.vala + * ccode/valaccodeemptystatement.vala + * ccode/valaccodeexpression.vala + * ccode/valaccodeexpressionstatement.vala + * ccode/valaccodeforstatement.vala + * ccode/valaccodefunction.vala: formatting fixes + * ccode/valaccodefunctioncall.vala + * ccode/valaccodeidentifier.vala + * ccode/valaccodeifstatement.vala + * ccode/valaccodereturnstatement.vala + * ccode/valaccodestatement.vala + * ccode/valaccodestruct.vala: formatting fixes + * ccode/valaccodevariabledeclarator.vala + * bindings/GLib.vala: extend string types + * valac/context.c: resolve types in named argument list in object + creation expression + +2006-05-16 Jürg Billeter + * vala/parser.y: fix unary expressions * vala/valacodegenerator.vala: add visit_block method * vala/valacodevisitor.vala: add visit methods for statements, diff --git a/vala/bindings/GLib.vala b/vala/bindings/GLib.vala index ec1904e..ee8ad1e 100644 --- a/vala/bindings/GLib.vala +++ b/vala/bindings/GLib.vala @@ -100,6 +100,10 @@ public struct string { public bool has_suffix (string suffix); [CCode (cname = "g_strdup_printf")] public ref string printf (string args); + [CCode (cname = "g_ascii_strup")] + public ref string up (long len /* = -1 */); + [CCode (cname = "g_ascii_strdown")] + public ref string down (long len /* = -1 */); [CCode (cname = "g_strconcat")] public ref string concat (string string2); [CCode (cname = "g_strdup")] @@ -264,5 +268,13 @@ namespace GLib { [CCode (cname = "g_str_equal")] public static GLib.EqualFunc str_equal; - + [ReferenceType ()] + public struct String { + public static ref String new (string init); + public static void append_c (char c); + + public ref string str; + public long len; + public long allocated_len; + } } diff --git a/vala/ccode/valaccodeassignment.vala b/vala/ccode/valaccodeassignment.vala new file mode 100644 index 0000000..fc622d5 --- /dev/null +++ b/vala/ccode/valaccodeassignment.vala @@ -0,0 +1,40 @@ +/* valaccodeassignment.vala + * + * Copyright (C) 2006 Jürg Billeter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jürg Billeter + */ + +using GLib; + +namespace Vala { + public class CCodeAssignment : CCodeExpression { + public readonly ref CCodeExpression left; + public readonly ref CCodeExpression right; + + public override void write (CCodeWriter writer) { + if (left != null) { + left.write (writer); + } + writer.write_string (" = "); + if (right != null) { + right.write (writer); + } + } + } +} diff --git a/vala/ccode/valaccodebinaryexpression.vala b/vala/ccode/valaccodebinaryexpression.vala new file mode 100644 index 0000000..ddaed5e --- /dev/null +++ b/vala/ccode/valaccodebinaryexpression.vala @@ -0,0 +1,39 @@ +/* valaccodebinaryexpression.vala + * + * Copyright (C) 2006 Jürg Billeter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jürg Billeter + */ + +using GLib; + +namespace Vala { + public class CCodeBinaryExpression : CCodeExpression { + public readonly ref CCodeExpression left; + public readonly ref CCodeExpression right; + + public override void write (CCodeWriter writer) { + if (left != null) { + left.write (writer); + } + if (right != null) { + right.write (writer); + } + } + } +} diff --git a/vala/ccode/valaccodeblock.vala b/vala/ccode/valaccodeblock.vala index 32a0fd4..ae79a7d 100644 --- a/vala/ccode/valaccodeblock.vala +++ b/vala/ccode/valaccodeblock.vala @@ -23,8 +23,8 @@ using GLib; namespace Vala { - public class CCodeBlock : CCodeNode { - List# statements; + public class CCodeBlock : CCodeStatement { + ref List statements; public void add_statement (string statement) { statements.append (statement); @@ -32,10 +32,10 @@ namespace Vala { public override void write (CCodeWriter writer) { writer.write_begin_block (); - foreach (string statement in statements) { - writer.write_indent (); - writer.write_string (statement); - writer.write_string (";\n"); + foreach (CCodeStatement statement in statements) { + if (statement != null) { + statement.write (writer); + } } writer.write_end_block (); } diff --git a/vala/ccode/valaccodeconstant.vala b/vala/ccode/valaccodeconstant.vala new file mode 100644 index 0000000..1f0f41b --- /dev/null +++ b/vala/ccode/valaccodeconstant.vala @@ -0,0 +1,33 @@ +/* valaccodeconstant.vala + * + * Copyright (C) 2006 Jürg Billeter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jürg Billeter + */ + +using GLib; + +namespace Vala { + public class CCodeConstant : CCodeExpression { + public readonly ref string name; + + public override void write (CCodeWriter writer) { + writer.write_string (name); + } + } +} diff --git a/vala/ccode/valaccodedeclarationstatement.vala b/vala/ccode/valaccodedeclarationstatement.vala new file mode 100644 index 0000000..8843c39 --- /dev/null +++ b/vala/ccode/valaccodedeclarationstatement.vala @@ -0,0 +1,55 @@ +/* valaccodedeclarationstatement.vala + * + * Copyright (C) 2006 Jürg Billeter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jürg Billeter + */ + +using GLib; + +namespace Vala { + public class CCodeDeclarationStatement : CCodeStatement { + public readonly ref string type_name; + ref List variable_declarators; + + public void add_declarator (CCodeVariableDeclarator decl) { + variable_declarators.append (decl); + } + + public override void write (CCodeWriter writer) { + writer.write_indent (); + if (type_name != null) { + writer.write_string (type_name); + } + writer.write_string (" "); + + bool first = true; + foreach (CCodeVariableDeclarator decl in variable_declarators) { + if (!first) { + writer.write_string (", "); + } else { + first = false; + } + decl.write (writer); + } + + writer.write_string (";"); + writer.write_newline (); + } + } +} diff --git a/vala/ccode/valaccodeemptystatement.vala b/vala/ccode/valaccodeemptystatement.vala new file mode 100644 index 0000000..4b8df11 --- /dev/null +++ b/vala/ccode/valaccodeemptystatement.vala @@ -0,0 +1,33 @@ +/* valaccodeemptystatement.vala + * + * Copyright (C) 2006 Jürg Billeter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jürg Billeter + */ + +using GLib; + +namespace Vala { + public class CCodeEmptyStatement : CCodeStatement { + public override void write (CCodeWriter writer) { + writer.write_indent (); + writer.write_string (";"); + writer.write_newline (); + } + } +} diff --git a/vala/ccode/valaccodeexpression.vala b/vala/ccode/valaccodeexpression.vala new file mode 100644 index 0000000..2298b7e --- /dev/null +++ b/vala/ccode/valaccodeexpression.vala @@ -0,0 +1,28 @@ +/* valaccodeexpression.vala + * + * Copyright (C) 2006 Jürg Billeter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jürg Billeter + */ + +using GLib; + +namespace Vala { + public abstract class CCodeExpression : CCodeNode { + } +} diff --git a/vala/ccode/valaccodeexpressionstatement.vala b/vala/ccode/valaccodeexpressionstatement.vala new file mode 100644 index 0000000..9764eb3 --- /dev/null +++ b/vala/ccode/valaccodeexpressionstatement.vala @@ -0,0 +1,38 @@ +/* valaccodeexpressionstatement.vala + * + * Copyright (C) 2006 Jürg Billeter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jürg Billeter + */ + +using GLib; + +namespace Vala { + public class CCodeExpressionStatement : CCodeStatement { + public readonly ref CCodeExpression expression; + + public override void write (CCodeWriter writer) { + writer.write_indent (); + if (expression != null) { + expression.write (writer); + } + writer.write_string (";"); + writer.write_newline (); + } + } +} diff --git a/vala/ccode/valaccodeforstatement.vala b/vala/ccode/valaccodeforstatement.vala new file mode 100644 index 0000000..e7b6831 --- /dev/null +++ b/vala/ccode/valaccodeforstatement.vala @@ -0,0 +1,81 @@ +/* valaccodeforstatement.vala + * + * Copyright (C) 2006 Jürg Billeter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jürg Billeter + */ + +using GLib; + +namespace Vala { + public class CCodeForStatement : CCodeStatement { + public readonly ref CCodeExpression condition; + public readonly ref CCodeStatement body; + + ref List initializer; + ref List iterator; + + public void add_initializer (CCodeExpression expr) { + initializer.append (expr); + } + + public void add_iterator (CCodeExpression expr) { + iterator.append (expr); + } + + public override void write (CCodeWriter writer) { + bool first; + + writer.write_indent (); + writer.write_string ("for ("); + + first = true; + foreach (CCodeExpression init_expr in initializer) { + if (!first) { + writer.write_string (", "); + } else { + first = false; + } + if (init_expr != null) { + init_expr.write (writer); + } + } + + writer.write_string ("; "); + if (condition != null) { + condition.write (writer); + } + writer.write_string ("; "); + + first = true; + foreach (CCodeExpression it_expr in iterator) { + if (!first) { + writer.write_string (", "); + } else { + first = false; + } + if (it_expr != null) { + it_expr.write (writer); + } + } + + writer.write_string (")"); + body.write (writer); + } + } +} diff --git a/vala/ccode/valaccodefunction.vala b/vala/ccode/valaccodefunction.vala index 42753db..eda8a19 100644 --- a/vala/ccode/valaccodefunction.vala +++ b/vala/ccode/valaccodefunction.vala @@ -35,6 +35,7 @@ namespace Vala { } public override void write (CCodeWriter writer) { + writer.write_newline (); if ((modifiers & CCodeModifiers.STATIC) == CCodeModifiers.STATIC) { writer.write_string ("static "); } @@ -47,10 +48,12 @@ namespace Vala { } writer.write_string (")"); if (block == null) { - writer.write_string (";\n"); + writer.write_string (";"); } else { + writer.write_newline (); block.write (writer); } + writer.write_newline (); } } } diff --git a/vala/ccode/valaccodefunctioncall.vala b/vala/ccode/valaccodefunctioncall.vala new file mode 100644 index 0000000..b6ce0ac --- /dev/null +++ b/vala/ccode/valaccodefunctioncall.vala @@ -0,0 +1,54 @@ +/* valaccodefunctioncall.vala + * + * Copyright (C) 2006 Jürg Billeter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jürg Billeter + */ + +using GLib; + +namespace Vala { + public class CCodeFunctionCall : CCodeExpression { + public readonly ref CCodeExpression call; + ref List arguments; + + public void add_argument (CCodeExpression expr) { + arguments.append (expr); + } + + public override void write (CCodeWriter writer) { + call.write (writer); + writer.write_string (" ("); + + bool first = true; + foreach (CCodeExpression expr in arguments) { + if (!first) { + writer.write_string (", "); + } else { + first = false; + } + + if (expr != null) { + expr.write (writer); + } + } + + writer.write_string (")"); + } + } +} diff --git a/vala/ccode/valaccodeidentifier.vala b/vala/ccode/valaccodeidentifier.vala new file mode 100644 index 0000000..d9a98aa --- /dev/null +++ b/vala/ccode/valaccodeidentifier.vala @@ -0,0 +1,33 @@ +/* valaccodeidentifier.vala + * + * Copyright (C) 2006 Jürg Billeter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jürg Billeter + */ + +using GLib; + +namespace Vala { + public class CCodeIdentifier : CCodeExpression { + public readonly ref string name; + + public override void write (CCodeWriter writer) { + writer.write_string (name); + } + } +} diff --git a/vala/ccode/valaccodeifstatement.vala b/vala/ccode/valaccodeifstatement.vala new file mode 100644 index 0000000..a3c584e --- /dev/null +++ b/vala/ccode/valaccodeifstatement.vala @@ -0,0 +1,50 @@ +/* valaccodeifstatement.vala + * + * Copyright (C) 2006 Jürg Billeter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jürg Billeter + */ + +using GLib; + +namespace Vala { + public class CCodeIfStatement : CCodeStatement { + public readonly ref CCodeExpression condition; + public readonly ref CCodeStatement true_statement; + public readonly ref CCodeStatement false_statement; + + public override void write (CCodeWriter writer) { + writer.write_indent (); + writer.write_string ("if ("); + if (condition != null) { + condition.write (writer); + } + writer.write_string (")"); + true_statement.write (writer); + if (false_statement != null) { + if (writer.bol) { + writer.write_indent (); + writer.write_string ("else "); + } else { + writer.write_string (" else "); + } + false_statement.write (writer); + } + } + } +} diff --git a/vala/ccode/valaccodereturnstatement.vala b/vala/ccode/valaccodereturnstatement.vala new file mode 100644 index 0000000..7af7fad --- /dev/null +++ b/vala/ccode/valaccodereturnstatement.vala @@ -0,0 +1,41 @@ +/* valaccodereturnstatement.vala + * + * Copyright (C) 2006 Jürg Billeter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jürg Billeter + */ + +using GLib; + +namespace Vala { + public class CCodeReturnStatement : CCodeStatement { + public readonly ref CCodeExpression return_expression; + + public override void write (CCodeWriter writer) { + writer.write_indent (); + writer.write_string ("return "); + + if (return_expression != null) { + return_expression.write (writer); + } + + writer.write_string (";"); + writer.write_newline (); + } + } +} diff --git a/vala/ccode/valaccodestatement.vala b/vala/ccode/valaccodestatement.vala new file mode 100644 index 0000000..f78184e --- /dev/null +++ b/vala/ccode/valaccodestatement.vala @@ -0,0 +1,28 @@ +/* valaccodestatement.vala + * + * Copyright (C) 2006 Jürg Billeter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jürg Billeter + */ + +using GLib; + +namespace Vala { + public abstract class CCodeStatement : CCodeNode { + } +} diff --git a/vala/ccode/valaccodestruct.vala b/vala/ccode/valaccodestruct.vala index 0295cc3..7e0f2c6 100644 --- a/vala/ccode/valaccodestruct.vala +++ b/vala/ccode/valaccodestruct.vala @@ -24,8 +24,8 @@ using GLib; namespace Vala { public class CCodeStruct : CCodeNode { - public readonly string# name; - List# fields; + public readonly ref string name; + ref List fields; public void add_field (string type, string name) { fields.append ("%s %s".printf (type, name)); @@ -38,10 +38,12 @@ namespace Vala { foreach (string field in fields) { writer.write_indent (); writer.write_string (field); - writer.write_string (";\n"); + writer.write_string (";"); + writer.write_newline (); } writer.write_end_block (); - writer.write_string (";\n"); + writer.write_string (";"); + writer.write_newline (); } } } diff --git a/vala/ccode/valaccodevariabledeclarator.vala b/vala/ccode/valaccodevariabledeclarator.vala new file mode 100644 index 0000000..06819d5 --- /dev/null +++ b/vala/ccode/valaccodevariabledeclarator.vala @@ -0,0 +1,39 @@ +/* valaccodevariabledeclarator.vala + * + * Copyright (C) 2006 Jürg Billeter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Author: + * Jürg Billeter + */ + +using GLib; + +namespace Vala { + public class CCodeVariableDeclarator : CCodeNode { + public readonly ref string name; + public readonly ref CCodeExpression initializer; + + public override void write (CCodeWriter writer) { + writer.write_string (name); + + if (initializer != null) { + writer.write_string (" = "); + initializer.write (writer); + } + } + } +} diff --git a/vala/ccode/valaccodewriter.vala b/vala/ccode/valaccodewriter.vala index f542c9e..c728c45 100644 --- a/vala/ccode/valaccodewriter.vala +++ b/vala/ccode/valaccodewriter.vala @@ -27,6 +27,8 @@ namespace Vala { public readonly File# stream; int indent; + /* at begin of line */ + public bool bol = true; public void close () { stream.close (); @@ -34,17 +36,34 @@ namespace Vala { public void write_indent () { int i; + + if (!bol) { + stream.putc ('\n'); + } + for (i = 0; i < indent; i++) { stream.putc ('\t'); } + + bol = false; } public void write_string (string s) { stream.printf ("%s", s); + bol = false; + } + + public void write_newline () { + stream.putc ('\n'); + bol = true; } public void write_begin_block () { - stream.printf (" {\n"); + if (!bol) { + stream.putc (' '); + } + stream.putc ('{'); + write_newline (); indent++; } diff --git a/vala/vala/scanner.l b/vala/vala/scanner.l index 2cd2400..9db687a 100644 --- a/vala/vala/scanner.l +++ b/vala/vala/scanner.l @@ -49,7 +49,7 @@ literal ({literal_integer}|{literal_character}|{literal_string}) "/*" { uploc; BEGIN (IN_COMMENT); } [^*\n]* { uploc; yymore (); } -"*"+[^/\n]* { uploc; yymore (); } +"*"+[^*/\n]* { uploc; yymore (); } \n { yylloc->first_line = yylloc->last_line = yylineno; yylloc->first_column = 1; yylloc->last_column = 0; yymore (); } "*/" { uploc; BEGIN (INITIAL); yytext[strlen (yytext) - 2] = '\0'; vala_parser_push_comment (parser, g_strdup (yytext)); } diff --git a/vala/vala/valaclass.vala b/vala/vala/valaclass.vala index 5da2fbf..607e93e 100644 --- a/vala/vala/valaclass.vala +++ b/vala/vala/valaclass.vala @@ -24,11 +24,9 @@ using GLib; namespace Vala { public class Class : Struct { - public readonly string# name; public readonly SourceReference# source_reference; - public Namespace @namespace; - public static Class# @new (string name, SourceReference source) { + public static ref Class new (string name, SourceReference source) { return (new Class (name = name, source_reference = source)); } @@ -39,10 +37,6 @@ namespace Vala { visitor.visit_end_class (this); } - - public override string get_cname () { - return name; - } public override bool is_reference_type () { return true; diff --git a/vala/vala/valacodegenerator.vala b/vala/vala/valacodegenerator.vala index d428618..fee4496 100644 --- a/vala/vala/valacodegenerator.vala +++ b/vala/vala/valacodegenerator.vala @@ -117,7 +117,7 @@ namespace Vala { instance_struct.add_field (f.type_reference.get_cname (), f.name); } - public override void visit_method (Method m) { + public override void visit_end_method (Method m) { var cmethod_decl = new CCodeFunction (name = m.name, return_type = "void"); function = new CCodeFunction (name = m.name, return_type = "void"); @@ -128,6 +128,11 @@ namespace Vala { function.modifiers |= CCodeModifiers.STATIC; source_type_member_declaration.append (cmethod_decl); } + + if (m.body != null) { + function.block = m.body.ccodenode; + } + if (m.source_reference.comment != null) { source_type_member_definition.append (new CCodeComment (text = m.source_reference.comment)); } @@ -137,9 +142,150 @@ namespace Vala { public override void visit_block (Block b) { var cblock = new CCodeBlock (); - if (function.block == null) { - function.block = cblock; + + foreach (Statement stmt in b.statement_list) { + cblock.add_statement ((CCodeStatement) stmt.ccodenode); + } + + b.ccodenode = cblock; + } + + public override void visit_empty_statement (EmptyStatement stmt) { + stmt.ccodenode = new CCodeEmptyStatement (); + } + + public override void visit_declaration_statement (DeclarationStatement stmt) { + /* not yet handled var declarations */ + if (stmt.declaration.type_reference == null) { + return; + } + + var cdecl = new CCodeDeclarationStatement (type_name = stmt.declaration.type_reference.get_cname ()); + + foreach (VariableDeclarator decl in stmt.declaration.variable_declarators) { + cdecl.add_declarator ((CCodeVariableDeclarator) decl.ccodenode); + } + + stmt.ccodenode = cdecl; + } + + public override void visit_variable_declarator (VariableDeclarator decl) { + if (decl.initializer != null) { + decl.ccodenode = new CCodeVariableDeclarator (name = decl.name, initializer = decl.initializer.ccodenode); + } else { + decl.ccodenode = new CCodeVariableDeclarator (name = decl.name); + } + } + + public override void visit_expression_statement (ExpressionStatement stmt) { + stmt.ccodenode = new CCodeExpressionStatement (expression = (CCodeExpression) stmt.expression.ccodenode); + } + + public override void visit_if_statement (IfStatement stmt) { + if (stmt.false_statement != null) { + stmt.ccodenode = new CCodeIfStatement (condition = (CCodeExpression) stmt.condition.ccodenode, true_statement = (CCodeStatement) stmt.true_statement.ccodenode, false_statement = (CCodeStatement) stmt.false_statement.ccodenode); + } else { + stmt.ccodenode = new CCodeIfStatement (condition = (CCodeExpression) stmt.condition.ccodenode, true_statement = (CCodeStatement) stmt.true_statement.ccodenode); + } + } + + public override void visit_for_statement (ForStatement stmt) { + var cfor = new CCodeForStatement (condition = (CCodeExpression) stmt.condition.ccodenode, body = (CCodeStatement) stmt.body.ccodenode); + + foreach (Expression init_expr in stmt.initializer) { + cfor.add_initializer ((CCodeExpression) init_expr.ccodenode); + } + + foreach (Expression it_expr in stmt.iterator) { + cfor.add_iterator ((CCodeExpression) it_expr.ccodenode); + } + + stmt.ccodenode = cfor; + } + + public override void visit_return_statement (ReturnStatement stmt) { + if (stmt.return_expression == null) { + stmt.ccodenode = new CCodeReturnStatement (); + } else { + stmt.ccodenode = new CCodeReturnStatement (return_expression = (CCodeExpression) stmt.return_expression.ccodenode); + } + } + + public override void visit_boolean_literal (BooleanLiteral expr) { + if (expr.value) { + expr.ccodenode = new CCodeConstant (name = "TRUE"); + } else { + expr.ccodenode = new CCodeConstant (name = "FALSE"); + } + } + + public override void visit_character_literal (CharacterLiteral expr) { + expr.ccodenode = new CCodeConstant (name = expr.value); + } + + public override void visit_integer_literal (IntegerLiteral expr) { + expr.ccodenode = new CCodeConstant (name = expr.value); + } + + public override void visit_string_literal (StringLiteral expr) { + expr.ccodenode = new CCodeConstant (name = expr.value); + } + + public override void visit_null_literal (NullLiteral expr) { + expr.ccodenode = new CCodeConstant (name = "NULL"); + } + + public override void visit_literal_expression (LiteralExpression expr) { + expr.ccodenode = expr.literal.ccodenode; + } + + public override void visit_simple_name (SimpleName expr) { + /* local variable */ + expr.ccodenode = new CCodeIdentifier (name = expr.name); + } + + public override void visit_member_access (MemberAccess expr) { + expr.ccodenode = new CCodeIdentifier (name = expr.member_name); + } + + public override void visit_invocation_expression (InvocationExpression expr) { + var ccall = new CCodeFunctionCall (call = (CCodeExpression) expr.call.ccodenode); + + foreach (Expression arg in expr.argument_list) { + ccall.add_argument ((CCodeExpression) arg.ccodenode); + } + + expr.ccodenode = ccall; + } + + public override void visit_object_creation_expression (ObjectCreationExpression expr) { + var ccall = new CCodeFunctionCall (call = new CCodeIdentifier (name = "g_object_new")); + + ccall.add_argument (new CCodeConstant (name = expr.type_reference.get_upper_case_cname ("TYPE_"))); + + foreach (NamedArgument arg in expr.named_argument_list) { + ccall.add_argument (new CCodeConstant (name = "\"%s\"".printf (arg.name))); + ccall.add_argument ((CCodeExpression) arg.argument.ccodenode); } + ccall.add_argument (new CCodeConstant (name = "NULL")); + + expr.ccodenode = ccall; + } + + public override void visit_unary_expression (UnaryExpression expr) { + expr.ccodenode = expr.inner.ccodenode; + } + + public override void visit_cast_expression (CastExpression expr) { + expr.ccodenode = expr.inner.ccodenode; + } + + public override void visit_binary_expression (BinaryExpression expr) { + expr.ccodenode = new CCodeBinaryExpression (left = expr.left.ccodenode, right = expr.right.ccodenode); + } + + public override void visit_assignment (Assignment a) { + a.ccodenode = new CCodeAssignment (left = (CCodeExpression) a.left.ccodenode, right = (CCodeExpression) a.right.ccodenode); } } } diff --git a/vala/vala/valacodenode.vala b/vala/vala/valacodenode.vala index 616867e..7706154 100644 --- a/vala/vala/valacodenode.vala +++ b/vala/vala/valacodenode.vala @@ -26,6 +26,7 @@ namespace Vala { public abstract class CodeNode { public Symbol# symbol; public ref List attributes; + public ref CCodeNode ccodenode; public abstract void accept (CodeVisitor visitor); } diff --git a/vala/vala/valacodevisitor.vala b/vala/vala/valacodevisitor.vala index b31d183..98694c8 100644 --- a/vala/vala/valacodevisitor.vala +++ b/vala/vala/valacodevisitor.vala @@ -57,7 +57,10 @@ namespace Vala { public virtual void visit_field (Field f) { } - public virtual void visit_method (Method m) { + public virtual void visit_begin_method (Method m) { + } + + public virtual void visit_end_method (Method m) { } public virtual void visit_property (Property prop) { @@ -81,6 +84,12 @@ namespace Vala { public virtual void visit_declaration_statement (DeclarationStatement stmt) { } + public virtual void visit_local_variable_declaration (LocalVariableDeclaration decl) { + } + + public virtual void visit_variable_declarator (VariableDeclarator decl) { + } + public virtual void visit_expression_statement (ExpressionStatement stmt) { } @@ -123,7 +132,7 @@ namespace Vala { public virtual void visit_member_access (MemberAccess expr) { } - public virtual void visit_invocation_expression (ObjectCreationExpression expr) { + public virtual void visit_invocation_expression (InvocationExpression expr) { } public virtual void visit_postfix_expression (PostfixExpression expr) { diff --git a/vala/vala/valadeclarationstatement.vala b/vala/vala/valadeclarationstatement.vala index e59530f..c6134fd 100644 --- a/vala/vala/valadeclarationstatement.vala +++ b/vala/vala/valadeclarationstatement.vala @@ -32,6 +32,8 @@ namespace Vala { } public override void accept (CodeVisitor visitor) { + declaration.accept (visitor); + visitor.visit_declaration_statement (this); } } diff --git a/vala/vala/valaexpressionstatement.vala b/vala/vala/valaexpressionstatement.vala index 0b5eda3..57a9d52 100644 --- a/vala/vala/valaexpressionstatement.vala +++ b/vala/vala/valaexpressionstatement.vala @@ -32,9 +32,9 @@ namespace Vala { } public override void accept (CodeVisitor visitor) { - visitor.visit_expression_statement (this); - expression.accept (visitor); + + visitor.visit_expression_statement (this); } } } diff --git a/vala/vala/valalocalvariabledeclaration.vala b/vala/vala/valalocalvariabledeclaration.vala index aae5680..1356c22 100644 --- a/vala/vala/valalocalvariabledeclaration.vala +++ b/vala/vala/valalocalvariabledeclaration.vala @@ -24,16 +24,28 @@ using GLib; namespace Vala { public class LocalVariableDeclaration : CodeNode { - public readonly TypeReference# type_reference; - public readonly List# variable_declarators; - public readonly SourceReference# source_reference; + public readonly ref TypeReference type_reference; + public readonly ref List variable_declarators; + public readonly ref SourceReference source_reference; - public static LocalVariableDeclaration# @new (TypeReference type, List declarators, SourceReference source) { + public static ref LocalVariableDeclaration new (TypeReference type, List declarators, SourceReference source) { return (new LocalVariableDeclaration (type_reference = type, variable_declarators = declarators, source_reference = source)); } - public static LocalVariableDeclaration# new_var (List declarators, SourceReference source) { + public static ref LocalVariableDeclaration new_var (List declarators, SourceReference source) { return (new LocalVariableDeclaration (variable_declarators = declarators, source_reference = source)); } + + public override void accept (CodeVisitor visitor) { + if (type_reference != null) { + type_reference.accept (visitor); + } + + foreach (VariableDeclarator decl in variable_declarators) { + decl.accept (visitor); + } + + visitor.visit_local_variable_declaration (this); + } } } diff --git a/vala/vala/valamethod.vala b/vala/vala/valamethod.vala index 62d15b8..94f0849 100644 --- a/vala/vala/valamethod.vala +++ b/vala/vala/valamethod.vala @@ -49,11 +49,13 @@ namespace Vala { } public override void accept (CodeVisitor visitor) { - visitor.visit_method (this); + visitor.visit_begin_method (this); if (body != null) { body.accept (visitor); } + + visitor.visit_end_method (this); } public string get_cname () { diff --git a/vala/vala/valanamespace.vala b/vala/vala/valanamespace.vala index 1aa4228..2766b1b 100644 --- a/vala/vala/valanamespace.vala +++ b/vala/vala/valanamespace.vala @@ -24,15 +24,17 @@ using GLib; namespace Vala { public class Namespace : CodeNode { - public readonly string# name; - public readonly SourceReference# source_reference; + public readonly ref string name; + public readonly ref SourceReference source_reference; - List# classes; - List# structs; - List# enums; - List# fields; + ref List classes; + ref List structs; + ref List enums; + ref List fields; - public static Namespace# @new (string name, SourceReference source) { + public ref string lower_case_cprefix; + + public static ref Namespace new (string name, SourceReference source) { return (new Namespace (name = name, source_reference = source)); } @@ -86,5 +88,24 @@ namespace Vala { visitor.visit_end_namespace (this); } + + public static ref string camel_case_to_lower_case (string camel_case) { + return camel_case.down (-1); + } + + public string get_lower_case_cprefix () { + if (lower_case_cprefix == null) { + if (name == null) { + lower_case_cprefix = ""; + } else { + lower_case_cprefix = "%s_".printf (camel_case_to_lower_case (name)); + } + } + return lower_case_cprefix; + } + + public void set_lower_case_cprefix (string cprefix) { + this.lower_case_cprefix = cprefix; + } } } diff --git a/vala/vala/valastruct.vala b/vala/vala/valastruct.vala index 6fa2de2..d08b05b 100644 --- a/vala/vala/valastruct.vala +++ b/vala/vala/valastruct.vala @@ -33,6 +33,8 @@ namespace Vala { List# methods; public ref string cname; + public ref string lower_case_csuffix; + bool reference_type; public static Struct# new (string name, SourceReference source) { return (new Struct (name = name, source_reference = source)); @@ -85,9 +87,31 @@ namespace Vala { public void set_cname (string cname) { this.cname = cname; } + + public string get_lower_case_csuffix () { + if (lower_case_csuffix == null) { + lower_case_csuffix = Namespace.camel_case_to_lower_case (name); + } + return lower_case_csuffix; + } + + public void set_lower_case_csuffix (string csuffix) { + this.lower_case_csuffix = csuffix; + } + + public ref string get_lower_case_cname (string infix) { + if (infix == null) { + infix = ""; + } + return "%s%s%s".printf (@namespace.get_lower_case_cprefix (), infix, get_lower_case_csuffix ()); + } + + public override ref string get_upper_case_cname (string infix) { + return get_lower_case_cname (infix).up (-1); + } public override bool is_reference_type () { - return false; + return reference_type; } void process_ccode_attribute (Attribute a) { @@ -108,6 +132,8 @@ namespace Vala { foreach (Attribute a in attributes) { if (a.name.cmp ("CCode") == 0) { process_ccode_attribute (a); + } else if (a.name.cmp ("ReferenceType") == 0) { + reference_type = true; } } } diff --git a/vala/vala/valasymbolbuilder.vala b/vala/vala/valasymbolbuilder.vala index 23d5845..77d2eec 100644 --- a/vala/vala/valasymbolbuilder.vala +++ b/vala/vala/valasymbolbuilder.vala @@ -85,7 +85,7 @@ namespace Vala { f.parent_type.symbol.add (f.name, f.symbol); } - public override void visit_method (Method m) { + public override void visit_begin_method (Method m) { if (m.parent_type.symbol.lookup (m.name) != null) { // TODO: raise error stderr.printf ("symbol conflict\n"); diff --git a/vala/vala/valatype.vala b/vala/vala/valatype.vala index f484242..0c987ea 100644 --- a/vala/vala/valatype.vala +++ b/vala/vala/valatype.vala @@ -26,5 +26,6 @@ namespace Vala { public abstract class Type_ : CodeNode { public abstract string get_cname (); public abstract bool is_reference_type (); + public abstract string get_upper_case_cname (string infix); } } diff --git a/vala/vala/valatypereference.vala b/vala/vala/valatypereference.vala index a1d67d9..6d8f315 100644 --- a/vala/vala/valatypereference.vala +++ b/vala/vala/valatypereference.vala @@ -90,7 +90,7 @@ namespace Vala { visitor.visit_type_reference (this); } - public string# get_cname () { + public ref string get_cname () { string ptr; string arr; if (type_parameter == null && !type.is_reference_type () && !is_ref) { @@ -111,8 +111,13 @@ namespace Vala { return "gpointer".concat (ptr, arr, null); } else { /* raise error */ + stderr.printf ("error: unresolved type reference\n"); return null; } } + + public ref string get_upper_case_cname (string infix) { + return type.get_upper_case_cname (infix); + } } } diff --git a/vala/vala/valavariabledeclarator.vala b/vala/vala/valavariabledeclarator.vala index 41d0818..55cfca6 100644 --- a/vala/vala/valavariabledeclarator.vala +++ b/vala/vala/valavariabledeclarator.vala @@ -24,12 +24,20 @@ using GLib; namespace Vala { public class VariableDeclarator : CodeNode { - public readonly string# name; - public readonly Expression# initializer; - public readonly SourceReference# source_reference; + public readonly ref string name; + public readonly ref Expression initializer; + public readonly ref SourceReference source_reference; - public static VariableDeclarator# @new (string name, Expression init, SourceReference source) { + public static ref VariableDeclarator new (string name, Expression init, SourceReference source) { return (new VariableDeclarator (name = name, initializer = init, source_reference = source)); } + + public override void accept (CodeVisitor visitor) { + if (initializer != null) { + initializer.accept (visitor); + } + + visitor.visit_variable_declarator (this); + } } } diff --git a/vala/valac/context.c b/vala/valac/context.c index 2990926..3af613b 100644 --- a/vala/valac/context.c +++ b/vala/valac/context.c @@ -447,6 +447,10 @@ vala_context_resolve_types_in_expression (ValaContext *context, ValaNamespace *n break; case VALA_EXPRESSION_TYPE_OBJECT_CREATION: vala_context_resolve_type_reference (context, namespace, NULL, expr->object_creation.type); + for (l = expr->object_creation.named_argument_list; l != NULL; l = l->next) { + ValaNamedArgument *na = l->data; + vala_context_resolve_types_in_expression (context, namespace, na->expression); + } break; case VALA_EXPRESSION_TYPE_PARENTHESIZED: vala_context_resolve_types_in_expression (context, namespace, expr->inner); -- 2.7.4