2006-05-16 Jürg Billeter <j@bitron.ch>
+ * 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 <j@bitron.ch>
+
* vala/parser.y: fix unary expressions
* vala/valacodegenerator.vala: add visit_block method
* vala/valacodevisitor.vala: add visit methods for statements,
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")]
[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;
+ }
}
--- /dev/null
+/* 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 <j@bitron.ch>
+ */
+
+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);
+ }
+ }
+ }
+}
--- /dev/null
+/* 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 <j@bitron.ch>
+ */
+
+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);
+ }
+ }
+ }
+}
using GLib;
namespace Vala {
- public class CCodeBlock : CCodeNode {
- List<string#># statements;
+ public class CCodeBlock : CCodeStatement {
+ ref List<ref CCodeStatement> statements;
public void add_statement (string statement) {
statements.append (statement);
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 ();
}
--- /dev/null
+/* 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 <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+ public class CCodeConstant : CCodeExpression {
+ public readonly ref string name;
+
+ public override void write (CCodeWriter writer) {
+ writer.write_string (name);
+ }
+ }
+}
--- /dev/null
+/* 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 <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+ public class CCodeDeclarationStatement : CCodeStatement {
+ public readonly ref string type_name;
+ ref List<ref CCodeVariableDeclarator> 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 ();
+ }
+ }
+}
--- /dev/null
+/* 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 <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+ public class CCodeEmptyStatement : CCodeStatement {
+ public override void write (CCodeWriter writer) {
+ writer.write_indent ();
+ writer.write_string (";");
+ writer.write_newline ();
+ }
+ }
+}
--- /dev/null
+/* 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 <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+ public abstract class CCodeExpression : CCodeNode {
+ }
+}
--- /dev/null
+/* 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 <j@bitron.ch>
+ */
+
+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 ();
+ }
+ }
+}
--- /dev/null
+/* 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 <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+ public class CCodeForStatement : CCodeStatement {
+ public readonly ref CCodeExpression condition;
+ public readonly ref CCodeStatement body;
+
+ ref List<ref CCodeExpression> initializer;
+ ref List<ref CCodeExpression> 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);
+ }
+ }
+}
}
public override void write (CCodeWriter writer) {
+ writer.write_newline ();
if ((modifiers & CCodeModifiers.STATIC) == CCodeModifiers.STATIC) {
writer.write_string ("static ");
}
}
writer.write_string (")");
if (block == null) {
- writer.write_string (";\n");
+ writer.write_string (";");
} else {
+ writer.write_newline ();
block.write (writer);
}
+ writer.write_newline ();
}
}
}
--- /dev/null
+/* 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 <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+ public class CCodeFunctionCall : CCodeExpression {
+ public readonly ref CCodeExpression call;
+ ref List<ref CCodeExpression> 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 (")");
+ }
+ }
+}
--- /dev/null
+/* 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 <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+ public class CCodeIdentifier : CCodeExpression {
+ public readonly ref string name;
+
+ public override void write (CCodeWriter writer) {
+ writer.write_string (name);
+ }
+ }
+}
--- /dev/null
+/* 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 <j@bitron.ch>
+ */
+
+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);
+ }
+ }
+ }
+}
--- /dev/null
+/* 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 <j@bitron.ch>
+ */
+
+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 ();
+ }
+ }
+}
--- /dev/null
+/* 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 <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+ public abstract class CCodeStatement : CCodeNode {
+ }
+}
namespace Vala {
public class CCodeStruct : CCodeNode {
- public readonly string# name;
- List<string#># fields;
+ public readonly ref string name;
+ ref List<ref string> fields;
public void add_field (string type, string name) {
fields.append ("%s %s".printf (type, name));
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 ();
}
}
}
--- /dev/null
+/* 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 <j@bitron.ch>
+ */
+
+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);
+ }
+ }
+ }
+}
public readonly File# stream;
int indent;
+ /* at begin of line */
+ public bool bol = true;
public void close () {
stream.close ();
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++;
}
"/*" { uploc; BEGIN (IN_COMMENT); }
<IN_COMMENT>[^*\n]* { uploc; yymore (); }
-<IN_COMMENT>"*"+[^/\n]* { uploc; yymore (); }
+<IN_COMMENT>"*"+[^*/\n]* { uploc; yymore (); }
<IN_COMMENT>\n { yylloc->first_line = yylloc->last_line = yylineno; yylloc->first_column = 1; yylloc->last_column = 0; yymore (); }
<IN_COMMENT>"*/" { uploc; BEGIN (INITIAL); yytext[strlen (yytext) - 2] = '\0'; vala_parser_push_comment (parser, g_strdup (yytext)); }
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));
}
visitor.visit_end_class (this);
}
-
- public override string get_cname () {
- return name;
- }
public override bool is_reference_type () {
return true;
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");
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));
}
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);
}
}
}
public abstract class CodeNode {
public Symbol# symbol;
public ref List<ref Attribute> attributes;
+ public ref CCodeNode ccodenode;
public abstract void accept (CodeVisitor visitor);
}
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) {
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) {
}
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) {
}
public override void accept (CodeVisitor visitor) {
+ declaration.accept (visitor);
+
visitor.visit_declaration_statement (this);
}
}
}
public override void accept (CodeVisitor visitor) {
- visitor.visit_expression_statement (this);
-
expression.accept (visitor);
+
+ visitor.visit_expression_statement (this);
}
}
}
namespace Vala {
public class LocalVariableDeclaration : CodeNode {
- public readonly TypeReference# type_reference;
- public readonly List<VariableDeclarator#># variable_declarators;
- public readonly SourceReference# source_reference;
+ public readonly ref TypeReference type_reference;
+ public readonly ref List<ref VariableDeclarator> variable_declarators;
+ public readonly ref SourceReference source_reference;
- public static LocalVariableDeclaration# @new (TypeReference type, List<VariableDeclarator> declarators, SourceReference source) {
+ public static ref LocalVariableDeclaration new (TypeReference type, List<VariableDeclarator> declarators, SourceReference source) {
return (new LocalVariableDeclaration (type_reference = type, variable_declarators = declarators, source_reference = source));
}
- public static LocalVariableDeclaration# new_var (List<VariableDeclarator> declarators, SourceReference source) {
+ public static ref LocalVariableDeclaration new_var (List<VariableDeclarator> 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);
+ }
}
}
}
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 () {
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<Class#># classes;
- List<Struct#># structs;
- List<Enum#># enums;
- List<Field#># fields;
+ ref List<ref Class> classes;
+ ref List<ref Struct> structs;
+ ref List<ref Enum> enums;
+ ref List<ref Field> 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));
}
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;
+ }
}
}
List<Method#># 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));
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) {
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;
}
}
}
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");
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);
}
}
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) {
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);
+ }
}
}
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);
+ }
}
}
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);