From 532b196639c40c4a8b350cd9c2e3cf3c6ffa77e2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrg=20Billeter?= Date: Thu, 27 Jul 2006 16:18:05 +0000 Subject: [PATCH] support CASE, DEFAULT, DO, and SWITCH support switch and do statements add MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2006-07-27 Jürg Billeter * vala/scanner.l: support CASE, DEFAULT, DO, and SWITCH * vala/parser.y: support switch and do statements * vala/valacodevisitor.vala: add support for switch and do statements * vala/valadostatement.vala * vala/valaswitchlabel.vala * vala/valaswitchsection.vala * vala/valaswitchstatement.vala * vala/valastatement.vala, vala/valasymbol.vala, vala/valaunaryexpression.vala, vala/valavariabledeclarator.vala, vala/valawhilestatement.vala: add interface documentation, use implicit namespace specification * vala/vala.h, vala/Makefile.am: update * vapi/glib-2.0.vala: don't use default keyword svn path=/trunk/; revision=86 --- vala/ChangeLog | 16 +++++ vala/vala/Makefile.am | 12 ++++ vala/vala/parser.y | 126 +++++++++++++++++++++++++++++++++- vala/vala/scanner.l | 4 ++ vala/vala/vala.h | 4 ++ vala/vala/valabinaryexpression.vala | 8 +-- vala/vala/valacodevisitor.vala | 32 +++++++++ vala/vala/valadostatement.vala | 60 ++++++++++++++++ vala/vala/valastatement.vala | 7 +- vala/vala/valaswitchlabel.vala | 64 +++++++++++++++++ vala/vala/valaswitchsection.vala | 80 +++++++++++++++++++++ vala/vala/valaswitchstatement.vala | 67 ++++++++++++++++++ vala/vala/valasymbol.vala | 113 ++++++++++++++++++++---------- vala/vala/valaunaryexpression.vala | 60 ++++++++++------ vala/vala/valavariabledeclarator.vala | 58 +++++++++++----- vala/vala/valawhilestatement.vala | 44 ++++++++---- vala/vapi/glib-2.0.vala | 2 +- 17 files changed, 656 insertions(+), 101 deletions(-) create mode 100644 vala/vala/valadostatement.vala create mode 100644 vala/vala/valaswitchlabel.vala create mode 100644 vala/vala/valaswitchsection.vala create mode 100644 vala/vala/valaswitchstatement.vala diff --git a/vala/ChangeLog b/vala/ChangeLog index 8913731..69d3867 100644 --- a/vala/ChangeLog +++ b/vala/ChangeLog @@ -1,5 +1,21 @@ 2006-07-27 Jürg Billeter + * vala/scanner.l: support CASE, DEFAULT, DO, and SWITCH + * vala/parser.y: support switch and do statements + * vala/valacodevisitor.vala: add support for switch and do statements + * vala/valadostatement.vala + * vala/valaswitchlabel.vala + * vala/valaswitchsection.vala + * vala/valaswitchstatement.vala + * vala/valastatement.vala, vala/valasymbol.vala, + vala/valaunaryexpression.vala, vala/valavariabledeclarator.vala, + vala/valawhilestatement.vala: add interface documentation, use + implicit namespace specification + * vala/vala.h, vala/Makefile.am: update + * vapi/glib-2.0.vala: don't use default keyword + +2006-07-27 Jürg Billeter + * vala/parser.y: support for loops with local variable declaration in initializer diff --git a/vala/vala/Makefile.am b/vala/vala/Makefile.am index 3001682..72a54e2 100644 --- a/vala/vala/Makefile.am +++ b/vala/vala/Makefile.am @@ -86,6 +86,9 @@ libvala_la_SOURCES = \ valadestructor.c \ valadestructor.h \ valadestructor.vala \ + valadostatement.c \ + valadostatement.h \ + valadostatement.vala \ valaemptystatement.c \ valaemptystatement.h \ valaemptystatement.vala \ @@ -230,6 +233,15 @@ libvala_la_SOURCES = \ valastruct.c \ valastruct.h \ valastruct.vala \ + valaswitchlabel.c \ + valaswitchlabel.h \ + valaswitchlabel.vala \ + valaswitchsection.c \ + valaswitchsection.h \ + valaswitchsection.vala \ + valaswitchstatement.c \ + valaswitchstatement.h \ + valaswitchstatement.vala \ valasymbolbuilder.c \ valasymbolbuilder.h \ valasymbolbuilder.vala \ diff --git a/vala/vala/parser.y b/vala/vala/parser.y index e011847..b94b076 100644 --- a/vala/vala/parser.y +++ b/vala/vala/parser.y @@ -91,6 +91,8 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg); ValaTypeParameter *type_parameter; ValaAttribute *attribute; ValaNamedArgument *named_argument; + ValaSwitchSection *switch_section; + ValaSwitchLabel *switch_label; } %token OPEN_BRACE "{" @@ -150,10 +152,13 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg); %token ABSTRACT "abstract" %token BREAK "break" %token CALLBACK "callback" +%token CASE "case" %token CLASS "class" %token CONST "const" %token CONSTRUCT "construct" %token CONTINUE "continue" +%token DEFAULT "default" +%token DO "do" %token ELSE "else" %token ENUM "enum" %token VALA_FALSE "false" @@ -173,11 +178,12 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg); %token PUBLIC "public" %token PRIVATE "private" %token REF "ref" +%token RETURN "return" %token SET "set" %token SIGNAL "signal" %token STATIC "static" %token STRUCT "struct" -%token RETURN "return" +%token SWITCH "switch" %token VALA_TRUE "true" %token TYPEOF "typeof" %token USING "using" @@ -245,8 +251,16 @@ static void yyerror (YYLTYPE *locp, ValaParser *parser, const char *msg); %type statement_expression %type selection_statement %type if_statement +%type switch_statement +%type switch_block +%type opt_switch_sections +%type switch_sections +%type switch_section +%type switch_labels +%type switch_label %type iteration_statement %type while_statement +%type do_statement %type for_statement %type opt_statement_expression_list %type statement_expression_list @@ -1107,7 +1121,7 @@ local_variable_declaration g_object_unref (src); for (l = $2; l != NULL; l = l->next) { ValaVariableDeclarator *decl = l->data; - decl->type_reference = g_object_ref ($1); + vala_variable_declarator_set_type_reference (decl, g_object_ref ($1)); vala_local_variable_declaration_add_declarator ($$, decl); g_object_unref (decl); } @@ -1200,6 +1214,7 @@ statement_expression selection_statement : if_statement + | switch_statement ; if_statement @@ -1222,8 +1237,102 @@ if_statement } ; +switch_statement + : comment SWITCH OPEN_PARENS expression CLOSE_PARENS switch_block + { + ValaSourceReference *src = src_com(@4, $1); + $$ = VALA_STATEMENT (vala_switch_statement_new ($4, src)); + g_object_unref ($4); + g_object_unref (src); + + if ($6 != NULL) { + GList *l; + for (l = $6; l != NULL; l = l->next) { + vala_switch_statement_add_section (VALA_SWITCH_STATEMENT ($$), l->data); + g_object_unref (l->data); + } + g_list_free ($6); + } + } + ; + +switch_block + : OPEN_BRACE opt_switch_sections CLOSE_BRACE + { + $$ = $2; + } + ; + +opt_switch_sections + : /* empty */ + { + $$ = NULL; + } + | switch_sections + ; + +switch_sections + : switch_section + { + $$ = g_list_append (NULL, $1); + } + | switch_sections switch_section + { + $$ = g_list_append ($1, $2); + } + ; + +switch_section + : comment switch_labels statement_list + { + ValaSourceReference *src = src_com(@2, $1); + $$ = vala_switch_section_new (src); + g_object_unref (src); + + GList *l; + for (l = $2; l != NULL; l = l->next) { + vala_switch_section_add_label ($$, l->data); + g_object_unref (l->data); + } + g_list_free ($2); + for (l = $3; l != NULL; l = l->next) { + vala_switch_section_add_statement ($$, l->data); + g_object_unref (l->data); + } + g_list_free ($3); + } + ; + +switch_labels + : switch_label + { + $$ = g_list_append (NULL, $1); + } + | switch_labels switch_label + { + $$ = g_list_append ($1, $2); + } + ; + +switch_label + : CASE expression COLON + { + ValaSourceReference *src = src(@2); + $$ = vala_switch_label_new ($2, src); + g_object_unref ($2); + g_object_unref (src); + } + | DEFAULT COLON + { + ValaSourceReference *src = src(@1); + $$ = vala_switch_label_new_default (src); + g_object_unref (src); + } + ; + iteration_statement : while_statement + | do_statement | for_statement | foreach_statement ; @@ -1239,6 +1348,17 @@ while_statement } ; +do_statement + : DO embedded_statement WHILE OPEN_PARENS expression CLOSE_PARENS SEMICOLON + { + ValaSourceReference *src = src(@1); + $$ = VALA_STATEMENT (vala_do_statement_new ($2, $5, src)); + g_object_unref ($2); + g_object_unref ($5); + g_object_unref (src); + } + ; + for_statement : FOR OPEN_PARENS opt_statement_expression_list SEMICOLON opt_expression SEMICOLON opt_statement_expression_list CLOSE_PARENS embedded_statement { @@ -1288,7 +1408,7 @@ for_statement if (init != NULL) { ValaSourceReference *decl_src = vala_code_node_get_source_reference (VALA_CODE_NODE (decl)); ValaMemberAccess *lhs = vala_member_access_new (NULL, vala_variable_declarator_get_name (decl), decl_src); - ValaAssignment *assign = vala_assignment_new (lhs, VALA_ASSIGNMENT_OPERATOR_SIMPLE, init, decl_src); + ValaAssignment *assign = vala_assignment_new (VALA_EXPRESSION (lhs), VALA_ASSIGNMENT_OPERATOR_SIMPLE, init, decl_src); g_object_unref (lhs); vala_for_statement_add_initializer (for_statement, VALA_EXPRESSION (assign)); g_object_unref (assign); diff --git a/vala/vala/scanner.l b/vala/vala/scanner.l index 1de09e1..f6faa9a 100644 --- a/vala/vala/scanner.l +++ b/vala/vala/scanner.l @@ -117,10 +117,13 @@ literal ({literal_integer}|{literal_real}|{literal_character}|{literal_string} "abstract" { uploc; return ABSTRACT; } "break" { uploc; return BREAK; } "callback" { uploc; return CALLBACK; } +"case" { uploc; return CASE; } "class" { uploc; return CLASS; } "const" { uploc; return CONST; } "construct" { uploc; return CONSTRUCT; } "continue" { uploc; return CONTINUE; } +"default" { uploc; return DEFAULT; } +"do" { uploc; return DO; } "else" { uploc; return ELSE; } "enum" { uploc; return ENUM; } "false" { uploc; return VALA_FALSE; } @@ -144,6 +147,7 @@ literal ({literal_integer}|{literal_real}|{literal_character}|{literal_string} "signal" { uploc; return SIGNAL; } "static" { uploc; return STATIC; } "struct" { uploc; return STRUCT; } +"switch" { uploc; return SWITCH; } "return" { uploc; return RETURN; } "true" { uploc; return VALA_TRUE; } "typeof" { uploc; return TYPEOF; } diff --git a/vala/vala/vala.h b/vala/vala/vala.h index 130edd3..68ee28e 100644 --- a/vala/vala/vala.h +++ b/vala/vala/vala.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -52,6 +53,9 @@ #include #include #include +#include +#include +#include #include #include #include diff --git a/vala/vala/valabinaryexpression.vala b/vala/vala/valabinaryexpression.vala index e4dc6a0..a019375 100644 --- a/vala/vala/valabinaryexpression.vala +++ b/vala/vala/valabinaryexpression.vala @@ -46,11 +46,11 @@ public class Vala.BinaryExpression : Expression { /** * Creates a new binary expression. * - * @param op binary operator - * @param left left operand - * @param right right operand + * @param op binary operator + * @param left left operand + * @param right right operand * @param source reference to source code - * @return newly created binary expression + * @return newly created binary expression */ public static ref BinaryExpression! new (BinaryOperator op, Expression! left, Expression! right, SourceReference source) { return (new BinaryExpression (operator = op, left = left, right = right, source_reference = source)); diff --git a/vala/vala/valacodevisitor.vala b/vala/vala/valacodevisitor.vala index deac316..7f1e982 100644 --- a/vala/vala/valacodevisitor.vala +++ b/vala/vala/valacodevisitor.vala @@ -396,6 +396,30 @@ public abstract class Vala.CodeVisitor { } /** + * Visit operation called for switch statements. + * + * @param stmt a switch statement + */ + public virtual void visit_switch_statement (SwitchStatement! stmt) { + } + + /** + * Visit operation called for switch sections. + * + * @param section a switch section + */ + public virtual void visit_switch_section (SwitchSection! section) { + } + + /** + * Visit operation called for switch label. + * + * @param label a switch label + */ + public virtual void visit_switch_label (SwitchLabel! label) { + } + + /** * Visit operation called for while statements. * * @param stmt an while statement @@ -404,6 +428,14 @@ public abstract class Vala.CodeVisitor { } /** + * Visit operation called for do statements. + * + * @param stmt a do statement + */ + public virtual void visit_do_statement (DoStatement! stmt) { + } + + /** * Visit operation called for for statements. * * @param stmt a for statement diff --git a/vala/vala/valadostatement.vala b/vala/vala/valadostatement.vala new file mode 100644 index 0000000..ac7160e --- /dev/null +++ b/vala/vala/valadostatement.vala @@ -0,0 +1,60 @@ +/* valadostatement.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; + +/** + * Represents a do iteration statement in the source code. + */ +public class Vala.DoStatement : Statement { + /** + * Specifies the loop body. + */ + public Statement body { get; set; } + + /** + * Specifies the loop condition. + */ + public Expression condition { get; set; } + + /** + * Creates a new do statement. + * + * @param cond loop condition + * @param body loop body + * @param source reference to source code + * @return newly created do statement + */ + public static ref DoStatement! new (Statement! body, Expression! cond, SourceReference source) { + return (new DoStatement (body = body, condition = cond, source_reference = source)); + } + + public override void accept (CodeVisitor! visitor) { + body.accept (visitor); + + condition.accept (visitor); + + visitor.visit_end_full_expression (condition); + + visitor.visit_do_statement (this); + } +} diff --git a/vala/vala/valastatement.vala b/vala/vala/valastatement.vala index 3e01a91..f38ea1a 100644 --- a/vala/vala/valastatement.vala +++ b/vala/vala/valastatement.vala @@ -22,7 +22,8 @@ using GLib; -namespace Vala { - public abstract class Statement : CodeNode { - } +/** + * Base class for all statement types. + */ +public abstract class Vala.Statement : CodeNode { } diff --git a/vala/vala/valaswitchlabel.vala b/vala/vala/valaswitchlabel.vala new file mode 100644 index 0000000..5696f56 --- /dev/null +++ b/vala/vala/valaswitchlabel.vala @@ -0,0 +1,64 @@ +/* valaswitchlabel.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; + +/** + * Represents a switch label in the source code. + */ +public class Vala.SwitchLabel : CodeNode { + /** + * Specifies the label expression. + */ + public Expression expression { get; set; } + + /** + * Creates a new switch case label. + * + * @param expr label expression + * @param source reference to source code + * @return newly created switch case label + */ + public static ref SwitchLabel! new (Expression expr, SourceReference source) { + return (new SwitchLabel (expression = expr, source_reference = source)); + } + + /** + * Creates a new switch default label. + * + * @param source reference to source code + * @return newly created switch default label + */ + public static ref SwitchLabel! new_default (SourceReference source) { + return (new SwitchLabel (source_reference = source)); + } + + public override void accept (CodeVisitor! visitor) { + if (expression != null) { + expression.accept (visitor); + + visitor.visit_end_full_expression (expression); + } + + visitor.visit_switch_label (this); + } +} diff --git a/vala/vala/valaswitchsection.vala b/vala/vala/valaswitchsection.vala new file mode 100644 index 0000000..53090a4 --- /dev/null +++ b/vala/vala/valaswitchsection.vala @@ -0,0 +1,80 @@ +/* valaswitchsection.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; + +/** + * Represents a switch section in the source code. + */ +public class Vala.SwitchSection : CodeNode { + private List labels; + private List statement_list; + + /** + * Creates a new switch section. + * + * @param source reference to source code + * @return newly created switch section + */ + public static ref SwitchSection! new (SourceReference source) { + return (new SwitchSection (source_reference = source)); + } + + /** + * Appends the specified label to the list of switch labels. + * + * @param label a switch label + */ + public void add_label (SwitchLabel! label) { + labels.append (label); + } + + /** + * Returns a copy of the list of switch labels. + * + * @return switch label list + */ + public ref List get_labels () { + return labels.copy (); + } + + /** + * Appends the specified statement to this switch section. + * + * @param stmt a statement + */ + public void add_statement (Statement! stmt) { + statement_list.append (stmt); + } + + public override void accept (CodeVisitor! visitor) { + foreach (SwitchLabel label in labels) { + label.accept (visitor); + } + + foreach (Statement st in statement_list) { + st.accept (visitor); + } + + visitor.visit_switch_section (this); + } +} diff --git a/vala/vala/valaswitchstatement.vala b/vala/vala/valaswitchstatement.vala new file mode 100644 index 0000000..1aeaa12 --- /dev/null +++ b/vala/vala/valaswitchstatement.vala @@ -0,0 +1,67 @@ +/* valaswitchstatement.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; + +/** + * Represents a switch selection statement in the source code. + */ +public class Vala.SwitchStatement : Statement { + /** + * Specifies the switch expression. + */ + public Expression! expression { get; set construct; } + + private List sections; + + /** + * Creates a new switch statement. + * + * @param expr switch expression + * @param source reference to source code + * @return newly created switch statement + */ + public static ref SwitchStatement! new (Expression! expr, SourceReference source) { + return (new SwitchStatement (expression = expr, source_reference = source)); + } + + /** + * Appends the specified section to the list of switch sections. + * + * @param section a switch section + */ + public void add_section (SwitchSection! section) { + sections.append (section); + } + + public override void accept (CodeVisitor! visitor) { + expression.accept (visitor); + + visitor.visit_end_full_expression (expression); + + foreach (SwitchSection section in sections) { + section.accept (visitor); + } + + visitor.visit_switch_statement (this); + } +} diff --git a/vala/vala/valasymbol.vala b/vala/vala/valasymbol.vala index 961c28b..90cad1d 100644 --- a/vala/vala/valasymbol.vala +++ b/vala/vala/valasymbol.vala @@ -22,47 +22,88 @@ using GLib; -namespace Vala { - public class Symbol { - HashTable symbol_table = HashTable.new_full (str_hash, str_equal, g_free, g_object_unref); - public weak CodeNode node { get; construct; } - public weak Symbol parent_symbol; - public string name; - - /* used for local variables not declared at the beginning of the - * block to determine which variables need to be freed before - * jump statements - */ - public bool active = true; - - public ref string get_full_name () { - if (parent_symbol == null) { - return name; - } - - if (name == null) { - return parent_symbol.get_full_name (); - } +/** + * Represents a node in the symbol tree. + */ +public class Vala.Symbol { + /** + * The code node that created this symbol, if applicable. + */ + public weak CodeNode node { get; set; } + + /** + * The parent of this symbol. + */ + public weak Symbol parent_symbol { get; set; } + + /** + * The symbol name. + */ + public string name { get; set; } - if (parent_symbol.get_full_name () == null) { - return name; - } - - return "%s.%s".printf (parent_symbol.get_full_name (), name); + /** + * Specifies whether this symbol is active. + * + * Symbols may become inactive when they only apply to a part of a + * scope. This is used for local variables not declared at the beginning + * of the block to determine which variables need to be freed before + * jump statements. + */ + public bool active { get; set; } + + private HashTable symbol_table = HashTable.new_full (str_hash, str_equal, g_free, g_object_unref); + + Symbol () { + active = true; + } + + /** + * Returns the fully expanded name of this symbol for use in + * human-readable messages. + * + * @return full name + */ + public ref string get_full_name () { + if (parent_symbol == null) { + return name; } - public void add (string s, Symbol sym) { - symbol_table.insert (s, sym); - sym.parent_symbol = this; - sym.name = s; + if (name == null) { + return parent_symbol.get_full_name (); + } + + if (parent_symbol.get_full_name () == null) { + return name; } - public Symbol lookup (string s) { - Symbol sym = symbol_table.lookup (s); - if (sym != null && !sym.active) { - sym = null; - } - return sym; + return "%s.%s".printf (parent_symbol.get_full_name (), name); + } + + /** + * Adds the specified symbol with the specified name to the symbol table + * of this symbol. + * + * @param name name for the specified symbol + * @param sym a symbol + */ + public void add (string! name, Symbol! sym) { + symbol_table.insert (name, sym); + sym.parent_symbol = this; + sym.name = name; + } + + /** + * Returns the symbol stored in the symbol table with the specified + * name. + * + * @param name name of the symbol to be returned + * @return found symbol or null + */ + public Symbol lookup (string! name) { + Symbol sym = symbol_table.lookup (name); + if (sym != null && !sym.active) { + sym = null; } + return sym; } } diff --git a/vala/vala/valaunaryexpression.vala b/vala/vala/valaunaryexpression.vala index cbb168b..95a5b9d 100644 --- a/vala/vala/valaunaryexpression.vala +++ b/vala/vala/valaunaryexpression.vala @@ -22,28 +22,46 @@ using GLib; -namespace Vala { - public class UnaryExpression : Expression { - public UnaryOperator operator { get; construct; } - public Expression inner { get; construct; } - - public static ref UnaryExpression new (UnaryOperator op, Expression inner, SourceReference source) { - return (new UnaryExpression (operator = op, inner = inner, source_reference = source)); - } - - public override void accept (CodeVisitor! visitor) { - inner.accept (visitor); - - visitor.visit_unary_expression (this); - } +/** + * Represents an expression with one operand in the source code. + * + * Supports +, -, !, ~, ref, out. + */ +public class Vala.UnaryExpression : Expression { + /** + * The unary operator. + */ + public UnaryOperator operator { get; set; } + + /** + * The operand. + */ + public Expression! inner { get; set construct; } + + /** + * Creates a new unary expression. + * + * @param op unary operator + * @param inner operand + * @param source reference to source code + * @return newly created binary expression + */ + public static ref UnaryExpression! new (UnaryOperator op, Expression! inner, SourceReference source) { + return (new UnaryExpression (operator = op, inner = inner, source_reference = source)); } - public enum UnaryOperator { - PLUS, - MINUS, - LOGICAL_NEGATION, - BITWISE_COMPLEMENT, - REF, - OUT + public override void accept (CodeVisitor! visitor) { + inner.accept (visitor); + + visitor.visit_unary_expression (this); } } + +public enum Vala.UnaryOperator { + PLUS, + MINUS, + LOGICAL_NEGATION, + BITWISE_COMPLEMENT, + REF, + OUT +} diff --git a/vala/vala/valavariabledeclarator.vala b/vala/vala/valavariabledeclarator.vala index 4da005c..e118cc7 100644 --- a/vala/vala/valavariabledeclarator.vala +++ b/vala/vala/valavariabledeclarator.vala @@ -22,28 +22,48 @@ using GLib; -namespace Vala { - public class VariableDeclarator : CodeNode { - public string name { get; construct; } - public Expression initializer { get; construct; } - public TypeReference type_reference; +/** + * Represents a variable declarator in the source code. + */ +public class Vala.VariableDeclarator : CodeNode { + /** + * The variable name. + */ + public string! name { get; set construct; } - public static ref VariableDeclarator new (string name, Expression init, SourceReference source) { - return (new VariableDeclarator (name = name, initializer = init, source_reference = source)); - } + /** + * The optional initializer expression. + */ + public Expression initializer { get; set; } + + /** + * The variable type. + */ + public TypeReference type_reference { get; set; } + + /** + * Creates a new variable declarator. + * + * @param name name of the variable + * @param init optional initializer expression + * @param source reference to source code + * @return newly created variable declarator + */ + 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); - public override void accept (CodeVisitor! visitor) { - if (initializer != null) { - initializer.accept (visitor); - - visitor.visit_end_full_expression (initializer); - } - - if (type_reference != null) { - type_reference.accept (visitor); - } + visitor.visit_end_full_expression (initializer); + } - visitor.visit_variable_declarator (this); + if (type_reference != null) { + type_reference.accept (visitor); } + + visitor.visit_variable_declarator (this); } } diff --git a/vala/vala/valawhilestatement.vala b/vala/vala/valawhilestatement.vala index c8724a1..4f12b3c 100644 --- a/vala/vala/valawhilestatement.vala +++ b/vala/vala/valawhilestatement.vala @@ -22,23 +22,39 @@ using GLib; -namespace Vala { - public class WhileStatement : Statement { - public Expression condition { get; construct; } - public Statement body { get; construct; } +/** + * Represents a while iteration statement in the source code. + */ +public class Vala.WhileStatement : Statement { + /** + * Specifies the loop condition. + */ + public Expression condition { get; set; } + + /** + * Specifies the loop body. + */ + public Statement body { get; set; } - public static ref WhileStatement new (Expression cond, Statement body, SourceReference source) { - return (new WhileStatement (condition = cond, body = body, source_reference = source)); - } + /** + * Creates a new while statement. + * + * @param cond loop condition + * @param body loop body + * @param source reference to source code + * @return newly created while statement + */ + public static ref WhileStatement! new (Expression! cond, Statement! body, SourceReference source) { + return (new WhileStatement (condition = cond, body = body, source_reference = source)); + } + + public override void accept (CodeVisitor! visitor) { + condition.accept (visitor); - public override void accept (CodeVisitor! visitor) { - condition.accept (visitor); - - visitor.visit_end_full_expression (condition); + visitor.visit_end_full_expression (condition); - body.accept (visitor); + body.accept (visitor); - visitor.visit_while_statement (this); - } + visitor.visit_while_statement (this); } } diff --git a/vala/vapi/glib-2.0.vala b/vala/vapi/glib-2.0.vala index b48662e..bdaf290 100644 --- a/vala/vapi/glib-2.0.vala +++ b/vala/vapi/glib-2.0.vala @@ -248,7 +248,7 @@ namespace GLib { [ReferenceType (dup_function = "g_main_context_ref", free_function = "g_main_context_unref")] public struct MainContext { public static ref MainContext new (); - public static MainContext default (); + public static MainContext @default (); public bool iteration (bool may_block); public bool pending (); public void wakeup (); -- 2.7.4