From: Jürg Billeter Date: Sat, 8 Jul 2006 21:08:06 +0000 (+0000) Subject: don't allow write access to read-only properties adapt to changes in X-Git-Tag: VALA_0_0_1~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3cf0fef29a7f7f4e2afea5bd332d08971e7b8016;p=thirdparty%2Fvala.git don't allow write access to read-only properties adapt to changes in 2006-07-08 Jürg Billeter * vala/valasemanticanalyzer.vala: don't allow write access to read-only properties * vala/valacodegenerator.vala: adapt to changes in CCodeFragment and CCommaExpression * vala/valapostfixexpression.vala, ccode/valaccodebinaryexpression.vala, ccode/valaccodeblock.vala, ccode/valaccodebreakstatement.vala, ccode/valaccodecasestatement.vala, ccode/valaccodecommaexpressoin.vala, ccode/valaccodecomment.vala, ccode/valaccodeconditionalexpression.vala, ccode/valaccodeconstant.vala, ccode/valaccodecontinuestatement.vala, ccode/valaccodedeclaration.vala, ccode/valaccodedeclarator.vala, ccode/valaccodeenum.vala, ccode/valaccodeemptystatement.vala, ccode/valaccodeexpressionstatement.vala, ccode/valaccodeformalparameter.vala, ccode/valaccodeforstatement.vala, ccode/valaccodefragment.vala, ccode/valaccodefunction.vala, ccode/valaccodefunctioncall.vala, ccode/valaccodefunctiondeclarator.vala, ccode/valaccodeidentifier.vala, ccode/valaccodeifstatement.vala, ccode/valaccodeincludedirective.vala, ccode/valaccodeinitializerlist.vala, ccode/valaccodemacroreplacement.vala, ccode/valaccodememberaccess.vala, ccode/valaccodemodifiers.vala, ccode/valaccodenewline.vala, ccode/valaccodeoncesection.vala, ccode/valaccodeparenthesizedexpression.vala, ccode/valaccodereturnstatement.vala, ccode/valaccodestatement.vala, ccode/valaccodestruct.vala, ccode/valaccodeswitchstatement.vala, ccode/valaccodeunaryexpression.vala, ccode/valaccodevariabledeclarator.vala, ccode/valaccodewhilestatement.vala, ccode/valaccodewriter.vala: add interface documentation, use implicit namespace specification svn path=/trunk/; revision=75 --- diff --git a/vala/ChangeLog b/vala/ChangeLog index 6a18aaf21..75f2204cc 100644 --- a/vala/ChangeLog +++ b/vala/ChangeLog @@ -1,3 +1,36 @@ +2006-07-08 Jürg Billeter + + * vala/valasemanticanalyzer.vala: don't allow write access to read-only + properties + * vala/valacodegenerator.vala: adapt to changes in CCodeFragment and + CCommaExpression + * vala/valapostfixexpression.vala, ccode/valaccodebinaryexpression.vala, + ccode/valaccodeblock.vala, ccode/valaccodebreakstatement.vala, + ccode/valaccodecasestatement.vala, + ccode/valaccodecommaexpressoin.vala, ccode/valaccodecomment.vala, + ccode/valaccodeconditionalexpression.vala, + ccode/valaccodeconstant.vala, ccode/valaccodecontinuestatement.vala, + ccode/valaccodedeclaration.vala, ccode/valaccodedeclarator.vala, + ccode/valaccodeenum.vala, ccode/valaccodeemptystatement.vala, + ccode/valaccodeexpressionstatement.vala, + ccode/valaccodeformalparameter.vala, ccode/valaccodeforstatement.vala, + ccode/valaccodefragment.vala, ccode/valaccodefunction.vala, + ccode/valaccodefunctioncall.vala, + ccode/valaccodefunctiondeclarator.vala, + ccode/valaccodeidentifier.vala, ccode/valaccodeifstatement.vala, + ccode/valaccodeincludedirective.vala, + ccode/valaccodeinitializerlist.vala, + ccode/valaccodemacroreplacement.vala, + ccode/valaccodememberaccess.vala, ccode/valaccodemodifiers.vala, + ccode/valaccodenewline.vala, ccode/valaccodeoncesection.vala, + ccode/valaccodeparenthesizedexpression.vala, + ccode/valaccodereturnstatement.vala, ccode/valaccodestatement.vala, + ccode/valaccodestruct.vala, ccode/valaccodeswitchstatement.vala, + ccode/valaccodeunaryexpression.vala, + ccode/valaccodevariabledeclarator.vala, + ccode/valaccodewhilestatement.vala, ccode/valaccodewriter.vala: add + interface documentation, use implicit namespace specification + 2006-07-08 Jürg Billeter * vala/valasemanticanalyzer.vala: don't allow access to private members diff --git a/vala/ccode/valaccodebinaryexpression.vala b/vala/ccode/valaccodebinaryexpression.vala index 894c8ea33..9fc063a3e 100644 --- a/vala/ccode/valaccodebinaryexpression.vala +++ b/vala/ccode/valaccodebinaryexpression.vala @@ -22,79 +22,91 @@ using GLib; -namespace Vala { - public class CCodeBinaryExpression : CCodeExpression { - public CCodeBinaryOperator operator { get; construct; } - public CCodeExpression left { get; construct; } - public CCodeExpression right { get; construct; } - - public override void write (CCodeWriter! writer) { - if (left != null) { - left.write (writer); - } - writer.write_string (" "); - if (operator == CCodeBinaryOperator.PLUS) { - writer.write_string ("+"); - } else if (operator == CCodeBinaryOperator.MINUS) { - writer.write_string ("-"); - } else if (operator == CCodeBinaryOperator.MUL) { - writer.write_string ("*"); - } else if (operator == CCodeBinaryOperator.DIV) { - writer.write_string ("/"); - } else if (operator == CCodeBinaryOperator.MOD) { - writer.write_string ("%"); - } else if (operator == CCodeBinaryOperator.SHIFT_LEFT) { - writer.write_string ("<<"); - } else if (operator == CCodeBinaryOperator.SHIFT_RIGHT) { - writer.write_string (">>"); - } else if (operator == CCodeBinaryOperator.LESS_THAN) { - writer.write_string ("<"); - } else if (operator == CCodeBinaryOperator.GREATER_THAN) { - writer.write_string (">"); - } else if (operator == CCodeBinaryOperator.LESS_THAN_OR_EQUAL) { - writer.write_string ("<="); - } else if (operator == CCodeBinaryOperator.GREATER_THAN_OR_EQUAL) { - writer.write_string (">="); - } else if (operator == CCodeBinaryOperator.EQUALITY) { - writer.write_string ("=="); - } else if (operator == CCodeBinaryOperator.INEQUALITY) { - writer.write_string ("!="); - } else if (operator == CCodeBinaryOperator.BITWISE_AND) { - writer.write_string ("&"); - } else if (operator == CCodeBinaryOperator.BITWISE_OR) { - writer.write_string ("|"); - } else if (operator == CCodeBinaryOperator.BITWISE_XOR) { - writer.write_string ("^"); - } else if (operator == CCodeBinaryOperator.AND) { - writer.write_string ("&&"); - } else if (operator == CCodeBinaryOperator.OR) { - writer.write_string ("||"); - } - writer.write_string (" "); - if (right != null) { - right.write (writer); - } - } - } +/** + * Represents an expression with two operands in C code. + */ +public class Vala.CCodeBinaryExpression : CCodeExpression { + /** + * The binary operator. + */ + public CCodeBinaryOperator operator { get; set; } + + /** + * The left operand. + */ + public CCodeExpression! left { get; set construct; } + + /** + * The right operand. + */ + public CCodeExpression! right { get; set construct; } - public enum CCodeBinaryOperator { - PLUS, - MINUS, - MUL, - DIV, - MOD, - SHIFT_LEFT, - SHIFT_RIGHT, - LESS_THAN, - GREATER_THAN, - LESS_THAN_OR_EQUAL, - GREATER_THAN_OR_EQUAL, - EQUALITY, - INEQUALITY, - BITWISE_AND, - BITWISE_OR, - BITWISE_XOR, - AND, - OR + public override void write (CCodeWriter! writer) { + if (left != null) { + left.write (writer); + } + writer.write_string (" "); + if (operator == CCodeBinaryOperator.PLUS) { + writer.write_string ("+"); + } else if (operator == CCodeBinaryOperator.MINUS) { + writer.write_string ("-"); + } else if (operator == CCodeBinaryOperator.MUL) { + writer.write_string ("*"); + } else if (operator == CCodeBinaryOperator.DIV) { + writer.write_string ("/"); + } else if (operator == CCodeBinaryOperator.MOD) { + writer.write_string ("%"); + } else if (operator == CCodeBinaryOperator.SHIFT_LEFT) { + writer.write_string ("<<"); + } else if (operator == CCodeBinaryOperator.SHIFT_RIGHT) { + writer.write_string (">>"); + } else if (operator == CCodeBinaryOperator.LESS_THAN) { + writer.write_string ("<"); + } else if (operator == CCodeBinaryOperator.GREATER_THAN) { + writer.write_string (">"); + } else if (operator == CCodeBinaryOperator.LESS_THAN_OR_EQUAL) { + writer.write_string ("<="); + } else if (operator == CCodeBinaryOperator.GREATER_THAN_OR_EQUAL) { + writer.write_string (">="); + } else if (operator == CCodeBinaryOperator.EQUALITY) { + writer.write_string ("=="); + } else if (operator == CCodeBinaryOperator.INEQUALITY) { + writer.write_string ("!="); + } else if (operator == CCodeBinaryOperator.BITWISE_AND) { + writer.write_string ("&"); + } else if (operator == CCodeBinaryOperator.BITWISE_OR) { + writer.write_string ("|"); + } else if (operator == CCodeBinaryOperator.BITWISE_XOR) { + writer.write_string ("^"); + } else if (operator == CCodeBinaryOperator.AND) { + writer.write_string ("&&"); + } else if (operator == CCodeBinaryOperator.OR) { + writer.write_string ("||"); + } + writer.write_string (" "); + if (right != null) { + right.write (writer); + } } } + +public enum Vala.CCodeBinaryOperator { + PLUS, + MINUS, + MUL, + DIV, + MOD, + SHIFT_LEFT, + SHIFT_RIGHT, + LESS_THAN, + GREATER_THAN, + LESS_THAN_OR_EQUAL, + GREATER_THAN_OR_EQUAL, + EQUALITY, + INEQUALITY, + BITWISE_AND, + BITWISE_OR, + BITWISE_XOR, + AND, + OR +} diff --git a/vala/ccode/valaccodeblock.vala b/vala/ccode/valaccodeblock.vala index 61819ab9b..3e593ce4e 100644 --- a/vala/ccode/valaccodeblock.vala +++ b/vala/ccode/valaccodeblock.vala @@ -22,30 +22,42 @@ using GLib; -namespace Vala { - public class CCodeBlock : CCodeStatement { - List statements; - public bool suppress_newline; - - public void prepend_statement (CCodeNode statement) { - statements.prepend (statement); - } - - public void add_statement (CCodeNode statement) { - /* allow generic nodes to include comments */ - statements.append (statement); +/** + * Represents a C code block. + */ +public class Vala.CCodeBlock : CCodeStatement { + /** + * Specifies whether a newline at the end of the block should be + * suppressed. + */ + public bool suppress_newline { get; set; } + + List statements; + + /** + * Prepend the specified statement to the list of statements. + */ + public void prepend_statement (CCodeNode! statement) { + statements.prepend (statement); + } + + /** + * Append the specified statement to the list of statements. + */ + public void add_statement (CCodeNode! statement) { + /* allow generic nodes to include comments */ + statements.append (statement); + } + + public override void write (CCodeWriter! writer) { + writer.write_begin_block (); + foreach (CCodeNode statement in statements) { + statement.write (writer); } - - public override void write (CCodeWriter! writer) { - writer.write_begin_block (); - foreach (CCodeNode statement in statements) { - statement.write (writer); - } - writer.write_end_block (); + writer.write_end_block (); - if (!suppress_newline) { - writer.write_newline (); - } + if (!suppress_newline) { + writer.write_newline (); } } } diff --git a/vala/ccode/valaccodebreakstatement.vala b/vala/ccode/valaccodebreakstatement.vala index 22e1fd2d5..3a2f0339e 100644 --- a/vala/ccode/valaccodebreakstatement.vala +++ b/vala/ccode/valaccodebreakstatement.vala @@ -22,12 +22,13 @@ using GLib; -namespace Vala { - public class CCodeBreakStatement : CCodeStatement { - public override void write (CCodeWriter! writer) { - writer.write_indent (); - writer.write_string ("break;"); - writer.write_newline (); - } +/** + * Represents a break statement in the C code. + */ +public class Vala.CCodeBreakStatement : CCodeStatement { + public override void write (CCodeWriter! writer) { + writer.write_indent (); + writer.write_string ("break;"); + writer.write_newline (); } } diff --git a/vala/ccode/valaccodecasestatement.vala b/vala/ccode/valaccodecasestatement.vala index 8ad468abd..55a75b79b 100644 --- a/vala/ccode/valaccodecasestatement.vala +++ b/vala/ccode/valaccodecasestatement.vala @@ -22,25 +22,35 @@ using GLib; -namespace Vala { - public class CCodeCaseStatement : CCodeStatement { - public CCodeExpression expression { get; construct; } - List statements; - - public void add_statement (CCodeStatement! stmt) { - statements.append (stmt); - } - - public override void write (CCodeWriter! writer) { - writer.write_indent (); - writer.write_string ("case "); - expression.write (writer); - writer.write_string (":"); - writer.write_newline (); +/** + * Represents a case block in a switch statement in C code. + */ +public class Vala.CCodeCaseStatement : CCodeStatement { + /** + * The case expression. + */ + public CCodeExpression! expression { get; set construct; } + + private List statements; + + /** + * Append the specified statement to this switch section. + * + * @param stmt a statement + */ + public void add_statement (CCodeStatement! stmt) { + statements.append (stmt); + } + + public override void write (CCodeWriter! writer) { + writer.write_indent (); + writer.write_string ("case "); + expression.write (writer); + writer.write_string (":"); + writer.write_newline (); - foreach (CCodeStatement stmt in statements) { - stmt.write (writer); - } + foreach (CCodeStatement stmt in statements) { + stmt.write (writer); } } } diff --git a/vala/ccode/valaccodecommaexpression.vala b/vala/ccode/valaccodecommaexpression.vala index a2bb424e7..7bce662fe 100644 --- a/vala/ccode/valaccodecommaexpression.vala +++ b/vala/ccode/valaccodecommaexpression.vala @@ -22,23 +22,33 @@ using GLib; -namespace Vala { - public class CCodeCommaExpression : CCodeExpression { - public List inner; - - public override void write (CCodeWriter! writer) { - bool first = true; - - writer.write_string ("("); - foreach (CCodeExpression expr in inner) { - if (!first) { - writer.write_string (", "); - } else { - first = false; - } - expr.write (writer); +/** + * Represents a comma separated expression list in the C code. + */ +public class Vala.CCodeCommaExpression : CCodeExpression { + private List inner; + + /** + * Appends the specified expression to the expression list. + * + * @param expr a C code expression + */ + public void append_expression (CCodeExpression! expr) { + inner.append (expr); + } + + public override void write (CCodeWriter! writer) { + bool first = true; + + writer.write_string ("("); + foreach (CCodeExpression expr in inner) { + if (!first) { + writer.write_string (", "); + } else { + first = false; } - writer.write_string (")"); + expr.write (writer); } + writer.write_string (")"); } } diff --git a/vala/ccode/valaccodecomment.vala b/vala/ccode/valaccodecomment.vala index a1eeb1424..885ce7e07 100644 --- a/vala/ccode/valaccodecomment.vala +++ b/vala/ccode/valaccodecomment.vala @@ -22,12 +22,16 @@ using GLib; -namespace Vala { - public class CCodeComment : CCodeNode { - public string text { get; construct; } - - public override void write (CCodeWriter! writer) { - writer.write_comment (text); - } +/** + * Represents a comment in the C code. + */ +public class Vala.CCodeComment : CCodeNode { + /** + * The text content of the comment. + */ + public string! text { get; set construct; } + + public override void write (CCodeWriter! writer) { + writer.write_comment (text); } } diff --git a/vala/ccode/valaccodeconditionalexpression.vala b/vala/ccode/valaccodeconditionalexpression.vala index 27a9b9658..4ee31e5f8 100644 --- a/vala/ccode/valaccodeconditionalexpression.vala +++ b/vala/ccode/valaccodeconditionalexpression.vala @@ -22,20 +22,32 @@ using GLib; -namespace Vala { - public class CCodeConditionalExpression : CCodeExpression { - public CCodeExpression condition { get; construct; } - public CCodeExpression true_expression { get; construct; } - public CCodeExpression false_expression { get; construct; } - - public override void write (CCodeWriter! writer) { - writer.write_string ("("); - condition.write (writer); - writer.write_string (" ? "); - true_expression.write (writer); - writer.write_string (" : "); - false_expression.write (writer); - writer.write_string (")"); - } +/** + * Represents a conditional expression in C code. + */ +public class Vala.CCodeConditionalExpression : CCodeExpression { + /** + * The condition. + */ + public CCodeExpression! condition { get; set construct; } + + /** + * The expression to be evaluated if the condition holds. + */ + public CCodeExpression! true_expression { get; set construct; } + + /** + * The expression to be evaluated if the condition doesn't hold. + */ + public CCodeExpression! false_expression { get; set construct; } + + public override void write (CCodeWriter! writer) { + writer.write_string ("("); + condition.write (writer); + writer.write_string (" ? "); + true_expression.write (writer); + writer.write_string (" : "); + false_expression.write (writer); + writer.write_string (")"); } } diff --git a/vala/ccode/valaccodeconstant.vala b/vala/ccode/valaccodeconstant.vala index 5142cbb4b..7ab527010 100644 --- a/vala/ccode/valaccodeconstant.vala +++ b/vala/ccode/valaccodeconstant.vala @@ -22,12 +22,16 @@ using GLib; -namespace Vala { - public class CCodeConstant : CCodeExpression { - public string name { get; construct; } - - public override void write (CCodeWriter! writer) { - writer.write_string (name); - } +/** + * A constant C expression. + */ +public class Vala.CCodeConstant : CCodeExpression { + /** + * The name of this constant. + */ + public string! name { get; set construct; } + + public override void write (CCodeWriter! writer) { + writer.write_string (name); } } diff --git a/vala/ccode/valaccodecontinuestatement.vala b/vala/ccode/valaccodecontinuestatement.vala index 299b421a6..02c65d961 100644 --- a/vala/ccode/valaccodecontinuestatement.vala +++ b/vala/ccode/valaccodecontinuestatement.vala @@ -22,12 +22,13 @@ using GLib; -namespace Vala { - public class CCodeContinueStatement : CCodeStatement { - public override void write (CCodeWriter! writer) { - writer.write_indent (); - writer.write_string ("continue;"); - writer.write_newline (); - } +/** + * Represents a continue statement in the C code. + */ +public class Vala.CCodeContinueStatement : CCodeStatement { + public override void write (CCodeWriter! writer) { + writer.write_indent (); + writer.write_string ("continue;"); + writer.write_newline (); } } diff --git a/vala/ccode/valaccodedeclaration.vala b/vala/ccode/valaccodedeclaration.vala index 51d9c30a4..d0db4406b 100644 --- a/vala/ccode/valaccodedeclaration.vala +++ b/vala/ccode/valaccodedeclaration.vala @@ -22,36 +22,50 @@ using GLib; -namespace Vala { - public class CCodeDeclaration : CCodeStatement { - public string type_name { get; construct; } - public CCodeModifiers modifiers; - List declarators; - - public void add_declarator (CCodeDeclarator! decl) { - declarators.append (decl); +/** + * Represents a local variable declaration in the C code. + */ +public class Vala.CCodeDeclaration : CCodeStatement { + /** + * The type of the local variable. + */ + public string! type_name { get; set construct; } + + /** + * The declaration modifier. + */ + public CCodeModifiers modifiers { get; set; } + + private List declarators; + + /** + * Adds the specified declarator to this declaration. + * + * @param decl a declarator + */ + public void add_declarator (CCodeDeclarator! decl) { + declarators.append (decl); + } + + public override void write (CCodeWriter! writer) { + writer.write_indent (); + if ((modifiers & CCodeModifiers.STATIC) == CCodeModifiers.STATIC) { + writer.write_string ("static "); } - - public override void write (CCodeWriter! writer) { - writer.write_indent (); - if ((modifiers & CCodeModifiers.STATIC) == CCodeModifiers.STATIC) { - writer.write_string ("static "); - } - writer.write_string (type_name); - writer.write_string (" "); - - bool first = true; - foreach (CCodeDeclarator decl in declarators) { - if (!first) { - writer.write_string (", "); - } else { - first = false; - } - decl.write (writer); + writer.write_string (type_name); + writer.write_string (" "); + + bool first = true; + foreach (CCodeDeclarator decl in declarators) { + if (!first) { + writer.write_string (", "); + } else { + first = false; } - - writer.write_string (";"); - writer.write_newline (); + decl.write (writer); } + + writer.write_string (";"); + writer.write_newline (); } } diff --git a/vala/ccode/valaccodedeclarator.vala b/vala/ccode/valaccodedeclarator.vala index c5478e264..8b63f0bfe 100644 --- a/vala/ccode/valaccodedeclarator.vala +++ b/vala/ccode/valaccodedeclarator.vala @@ -22,7 +22,8 @@ using GLib; -namespace Vala { - public abstract class CCodeDeclarator : CCodeNode { - } +/** + * Represents a variable or function pointer declarator in the C code. + */ +public abstract class Vala.CCodeDeclarator : CCodeNode { } diff --git a/vala/ccode/valaccodeemptystatement.vala b/vala/ccode/valaccodeemptystatement.vala index ecc76f886..54acc9626 100644 --- a/vala/ccode/valaccodeemptystatement.vala +++ b/vala/ccode/valaccodeemptystatement.vala @@ -22,12 +22,13 @@ using GLib; -namespace Vala { - public class CCodeEmptyStatement : CCodeStatement { - public override void write (CCodeWriter! writer) { - writer.write_indent (); - writer.write_string (";"); - writer.write_newline (); - } +/** + * Represents an empty statement in the C code. + */ +public class Vala.CCodeEmptyStatement : CCodeStatement { + public override void write (CCodeWriter! writer) { + writer.write_indent (); + writer.write_string (";"); + writer.write_newline (); } } diff --git a/vala/ccode/valaccodeenum.vala b/vala/ccode/valaccodeenum.vala index 5b747da9e..11b4424c1 100644 --- a/vala/ccode/valaccodeenum.vala +++ b/vala/ccode/valaccodeenum.vala @@ -22,38 +22,49 @@ using GLib; -namespace Vala { - public class CCodeEnum : CCodeNode { - public string name { get; construct; } - List values; - - public void add_value (string! name, string value = null) { - if (value == null) { - values.append (name); - } else { - values.append ("%s = %s".printf (name, value)); - } +/** + * Represents an enum in the C code. + */ +public class Vala.CCodeEnum : CCodeNode { + /** + * The name of this enum. + */ + public string! name { get; set construct; } + + private List values; + + /** + * Adds the specified value to this enum. + * + * @param name enum value name + * @param value optional numerical value + */ + public void add_value (string! name, string value = null) { + if (value == null) { + values.append (name); + } else { + values.append ("%s = %s".printf (name, value)); + } + } + + public override void write (CCodeWriter! writer) { + if (name != null) { + writer.write_string ("typedef "); } - - public override void write (CCodeWriter! writer) { - if (name != null) { - writer.write_string ("typedef "); - } - writer.write_string ("enum "); - writer.write_begin_block (); - foreach (string value in values) { - writer.write_indent (); - writer.write_string (value); - writer.write_string (","); - writer.write_newline (); - } - writer.write_end_block (); - if (name != null) { - writer.write_string (" "); - writer.write_string (name); - } - writer.write_string (";"); + writer.write_string ("enum "); + writer.write_begin_block (); + foreach (string value in values) { + writer.write_indent (); + writer.write_string (value); + writer.write_string (","); writer.write_newline (); } + writer.write_end_block (); + if (name != null) { + writer.write_string (" "); + writer.write_string (name); + } + writer.write_string (";"); + writer.write_newline (); } } diff --git a/vala/ccode/valaccodeexpressionstatement.vala b/vala/ccode/valaccodeexpressionstatement.vala index a4703bac4..a2bbec208 100644 --- a/vala/ccode/valaccodeexpressionstatement.vala +++ b/vala/ccode/valaccodeexpressionstatement.vala @@ -22,17 +22,21 @@ using GLib; -namespace Vala { - public class CCodeExpressionStatement : CCodeStatement { - public CCodeExpression expression { get; construct; } - - public override void write (CCodeWriter! writer) { - writer.write_indent (); - if (expression != null) { - expression.write (writer); - } - writer.write_string (";"); - writer.write_newline (); +/** + * Represents a C code statement that evaluates a given expression. + */ +public class Vala.CCodeExpressionStatement : CCodeStatement { + /** + * The expression to evaluate. + */ + public CCodeExpression! expression { get; set construct; } + + 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/valaccodeformalparameter.vala b/vala/ccode/valaccodeformalparameter.vala index 98bff0246..14eb8d8fc 100644 --- a/vala/ccode/valaccodeformalparameter.vala +++ b/vala/ccode/valaccodeformalparameter.vala @@ -22,15 +22,23 @@ using GLib; -namespace Vala { - public class CCodeFormalParameter : CCodeNode { - public string name { get; construct; } - public string type_name { get; construct; } - - public override void write (CCodeWriter! writer) { - writer.write_string (type_name); - writer.write_string (" "); - writer.write_string (name); - } +/** + * Represents a formal parameter in a C method signature. + */ +public class Vala.CCodeFormalParameter : CCodeNode { + /** + * The parameter name. + */ + public string! name { get; set construct; } + + /** + * The parameter type. + */ + public string! type_name { get; set construct; } + + public override void write (CCodeWriter! writer) { + writer.write_string (type_name); + writer.write_string (" "); + writer.write_string (name); } } diff --git a/vala/ccode/valaccodeforstatement.vala b/vala/ccode/valaccodeforstatement.vala index 98ca1042b..d7313e97a 100644 --- a/vala/ccode/valaccodeforstatement.vala +++ b/vala/ccode/valaccodeforstatement.vala @@ -22,60 +22,78 @@ using GLib; -namespace Vala { - public class CCodeForStatement : CCodeStatement { - public CCodeExpression condition { get; construct; } - public CCodeStatement body { get; construct; } - - List initializer; - List iterator; +/** + * Represents a for iteration statement in the C code. + */ +public class Vala.CCodeForStatement : CCodeStatement { + /** + * The loop condition. + */ + public CCodeExpression! condition { get; set construct; } + + /** + * The loop body. + */ + public CCodeStatement body { get; set; } + + private List initializer; + private List iterator; - public void add_initializer (CCodeExpression! expr) { - initializer.append (expr); - } + /** + * Appends the specified expression to the list of initializers. + * + * @param expr an initializer expression + */ + public void add_initializer (CCodeExpression! expr) { + initializer.append (expr); + } - public void add_iterator (CCodeExpression! expr) { - iterator.append (expr); - } + /** + * Appends the specified expression to the iterator. + * + * @param expr an iterator expression + */ + public void add_iterator (CCodeExpression! expr) { + iterator.append (expr); + } + + public override void write (CCodeWriter! writer) { + bool first; + + writer.write_indent (); + writer.write_string ("for ("); - 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); - } + 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 ("; "); + 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; } - 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); - } + if (it_expr != null) { + it_expr.write (writer); } - - writer.write_string (")"); - body.write (writer); } + + writer.write_string (")"); + body.write (writer); } } diff --git a/vala/ccode/valaccodefragment.vala b/vala/ccode/valaccodefragment.vala index eb616d808..01ed2d7ab 100644 --- a/vala/ccode/valaccodefragment.vala +++ b/vala/ccode/valaccodefragment.vala @@ -22,18 +22,33 @@ using GLib; -namespace Vala { - public class CCodeFragment : CCodeNode { - public GLib.List children { get; construct; } - - public void append (CCodeNode! node) { - _children.append (node); - } +/** + * Represents a container for C code nodes. + */ +public class Vala.CCodeFragment : CCodeNode { + private List children; + + /** + * Appends the specified code node to this code fragment. + * + * @param node a C code node + */ + public void append (CCodeNode! node) { + children.append (node); + } - public override void write (CCodeWriter! writer) { - foreach (CCodeNode node in children) { - node.write (writer); - } + /** + * Returns a copy of the list of children. + * + * @return children list + */ + public ref List get_children () { + return children.copy (); + } + + public override void write (CCodeWriter! writer) { + foreach (CCodeNode node in children) { + node.write (writer); } } } diff --git a/vala/ccode/valaccodefunction.vala b/vala/ccode/valaccodefunction.vala index a590fc51a..e8b2831d1 100644 --- a/vala/ccode/valaccodefunction.vala +++ b/vala/ccode/valaccodefunction.vala @@ -22,62 +22,89 @@ using GLib; -namespace Vala { - public class CCodeFunction : CCodeNode { - public string name { get; construct; } - public CCodeModifiers modifiers; - public string return_type { get; construct; } - List parameters; - public CCodeBlock block; - - public void add_parameter (CCodeFormalParameter!param) { - parameters.append (param); +/** + * Represents a function declaration in the C code. + */ +public class Vala.CCodeFunction : CCodeNode { + /** + * The name of this function. + */ + public string! name { get; set construct; } + + /** + * The function modifiers. + */ + public CCodeModifiers modifiers { get; set; } + + /** + * The function return type. + */ + public string! return_type { get; set construct; } + + /** + * The function body. + */ + public CCodeBlock block { get; set; } + + private List parameters; + + /** + * Appends the specified parameter to the list of function parameters. + * + * @param param a formal parameter + */ + public void add_parameter (CCodeFormalParameter! param) { + parameters.append (param); + } + + /** + * Returns a copy of this function. + * + * @return copied function + */ + public ref CCodeFunction! copy () { + var func = new CCodeFunction (name = name, return_type = return_type); + func.modifiers = modifiers; + + /* no deep copy for lists available yet + * func.parameters = parameters.copy (); + */ + foreach (CCodeFormalParameter param in parameters) { + func.parameters.append (param); } - public ref CCodeFunction! copy () { - var func = new CCodeFunction (name = name, return_type = return_type); - func.modifiers = modifiers; - - /* no deep copy for lists available yet - * func.parameters = parameters.copy (); - */ - foreach (CCodeFormalParameter param in parameters) { - func.parameters.append (param); - } - - func.block = block; - return func; + func.block = block; + return func; + } + + public override void write (CCodeWriter! writer) { + writer.write_indent (); + if ((modifiers & CCodeModifiers.STATIC) == CCodeModifiers.STATIC) { + writer.write_string ("static "); } + writer.write_string (return_type); + writer.write_string (" "); + writer.write_string (name); + writer.write_string (" ("); - public override void write (CCodeWriter! writer) { - writer.write_indent (); - if ((modifiers & CCodeModifiers.STATIC) == CCodeModifiers.STATIC) { - writer.write_string ("static "); - } - writer.write_string (return_type); - writer.write_string (" "); - writer.write_string (name); - writer.write_string (" ("); - - bool first = true; - foreach (CCodeFormalParameter param in parameters) { - if (!first) { - writer.write_string (", "); - } else { - first = false; - } - param.write (writer); - } - - writer.write_string (")"); - if (block == null) { - writer.write_string (";"); + bool first = true; + foreach (CCodeFormalParameter param in parameters) { + if (!first) { + writer.write_string (", "); } else { - writer.write_newline (); - block.write (writer); - writer.write_newline (); + first = false; } + param.write (writer); + } + + writer.write_string (")"); + if (block == null) { + writer.write_string (";"); + } else { + writer.write_newline (); + block.write (writer); writer.write_newline (); } + writer.write_newline (); } } diff --git a/vala/ccode/valaccodefunctioncall.vala b/vala/ccode/valaccodefunctioncall.vala index 4e0e6a061..351dcf046 100644 --- a/vala/ccode/valaccodefunctioncall.vala +++ b/vala/ccode/valaccodefunctioncall.vala @@ -22,33 +22,43 @@ using GLib; -namespace Vala { - public class CCodeFunctionCall : CCodeExpression { - public CCodeExpression call { get; construct; } - List arguments; - - public void add_argument (CCodeExpression! expr) { - arguments.append (expr); - } - - public override void write (CCodeWriter! writer) { - call.write (writer); - writer.write_string (" ("); +/** + * Represents a function call in the C code. + */ +public class Vala.CCodeFunctionCall : CCodeExpression { + /** + * The function to be called. + */ + public CCodeExpression call { get; set; } + + private List arguments; + + /** + * Appends the specified expression to the list of arguments. + * + * @param expr a C code expression + */ + 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); - } + 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 (")"); } + + writer.write_string (")"); } } diff --git a/vala/ccode/valaccodefunctiondeclarator.vala b/vala/ccode/valaccodefunctiondeclarator.vala index 9699057ab..9537a1514 100644 --- a/vala/ccode/valaccodefunctiondeclarator.vala +++ b/vala/ccode/valaccodefunctiondeclarator.vala @@ -22,31 +22,41 @@ using GLib; -namespace Vala { - public class CCodeFunctionDeclarator : CCodeDeclarator { - public string name { get; construct; } - List parameters; - - public void add_parameter (CCodeFormalParameter! param) { - parameters.append (param); - } +/** + * Represents a function pointer declarator in the C code. + */ +public class Vala.CCodeFunctionDeclarator : CCodeDeclarator { + /** + * The declarator name. + */ + public string! name { get; set construct; } + + private List parameters; + + /** + * Appends the specified parameter to the list of function parameters. + * + * @param param a formal parameter + */ + public void add_parameter (CCodeFormalParameter! param) { + parameters.append (param); + } + + public override void write (CCodeWriter! writer) { + writer.write_string ("(*"); + writer.write_string (name); + writer.write_string (") ("); - public override void write (CCodeWriter! writer) { - writer.write_string ("(*"); - writer.write_string (name); - writer.write_string (") ("); - - bool first = true; - foreach (CCodeFormalParameter param in parameters) { - if (!first) { - writer.write_string (", "); - } else { - first = false; - } - param.write (writer); + bool first = true; + foreach (CCodeFormalParameter param in parameters) { + if (!first) { + writer.write_string (", "); + } else { + first = false; } - - writer.write_string (")"); + param.write (writer); } + + writer.write_string (")"); } } diff --git a/vala/ccode/valaccodeidentifier.vala b/vala/ccode/valaccodeidentifier.vala index c99f0708d..6b15bceb6 100644 --- a/vala/ccode/valaccodeidentifier.vala +++ b/vala/ccode/valaccodeidentifier.vala @@ -22,12 +22,16 @@ using GLib; -namespace Vala { - public class CCodeIdentifier : CCodeExpression { - public string name { get; construct; } - - public override void write (CCodeWriter! writer) { - writer.write_string (name); - } +/** + * Represents a identifier in the C code. + */ +public class Vala.CCodeIdentifier : CCodeExpression { + /** + * The name of this identifier. + */ + public string! name { get; set construct; } + + public override void write (CCodeWriter! writer) { + writer.write_string (name); } } diff --git a/vala/ccode/valaccodeifstatement.vala b/vala/ccode/valaccodeifstatement.vala index 7d47d295f..f699da6a1 100644 --- a/vala/ccode/valaccodeifstatement.vala +++ b/vala/ccode/valaccodeifstatement.vala @@ -22,48 +22,65 @@ using GLib; -namespace Vala { - public class CCodeIfStatement : CCodeStatement { - public CCodeExpression condition { get; construct; } - public CCodeStatement true_statement { get; construct; } - public CCodeStatement false_statement { get; construct; } - public bool else_if; +/** + * Represents an if selection statement in the C code. + */ +public class Vala.CCodeIfStatement : CCodeStatement { + /** + * The boolean condition to evaluate. + */ + public CCodeExpression! condition { get; set construct; } + + /** + * The statement to be evaluated if the condition holds. + */ + public CCodeStatement! true_statement { get; set construct; } + + /** + * The optional statement to be evaluated if the condition doesn't hold. + */ + public CCodeStatement false_statement { get; set construct; } + + /** + * Specifies whether this if statement is part of an else if statement. + * This only affects the output formatting. + */ + public bool else_if { get; set; } + + public override void write (CCodeWriter! writer) { + if (!else_if) { + writer.write_indent (); + } else { + writer.write_string (" "); + } + writer.write_string ("if ("); + if (condition != null) { + condition.write (writer); + } + writer.write_string (")"); - public override void write (CCodeWriter! writer) { - if (!else_if) { + /* else shouldn't be on a separate line */ + if (false_statement != null && true_statement is CCodeBlock) { + var cblock = (CCodeBlock) true_statement; + cblock.suppress_newline = true; + } + + true_statement.write (writer); + if (false_statement != null) { + if (writer.bol) { writer.write_indent (); + writer.write_string ("else"); } else { - writer.write_string (" "); - } - writer.write_string ("if ("); - if (condition != null) { - condition.write (writer); + writer.write_string (" else"); } - writer.write_string (")"); - /* else shouldn't be on a separate line */ - if (false_statement != null && true_statement is CCodeBlock) { - var cblock = (CCodeBlock) true_statement; - cblock.suppress_newline = true; + /* else if should be on one line */ + if (false_statement is CCodeIfStatement) { + var cif = (CCodeIfStatement) false_statement; + cif.else_if = true; } - true_statement.write (writer); - if (false_statement != null) { - if (writer.bol) { - writer.write_indent (); - writer.write_string ("else"); - } else { - writer.write_string (" else"); - } - - /* else if should be on one line */ - if (false_statement is CCodeIfStatement) { - var cif = (CCodeIfStatement) false_statement; - cif.else_if = true; - } - - false_statement.write (writer); - } + false_statement.write (writer); } } } diff --git a/vala/ccode/valaccodeincludedirective.vala b/vala/ccode/valaccodeincludedirective.vala index 2bbaab0a2..0f38f9568 100644 --- a/vala/ccode/valaccodeincludedirective.vala +++ b/vala/ccode/valaccodeincludedirective.vala @@ -22,16 +22,20 @@ using GLib; -namespace Vala { - public class CCodeIncludeDirective : CCodeNode { - public string filename { get; construct; } - - public override void write (CCodeWriter! writer) { - writer.write_indent (); - writer.write_string ("#include <"); - writer.write_string (filename); - writer.write_string (">"); - writer.write_newline (); - } +/** + * Represents an include preprocessor directive in the C code. + */ +public class Vala.CCodeIncludeDirective : CCodeNode { + /** + * The file to be included. + */ + public string! filename { get; set construct; } + + public override void write (CCodeWriter! writer) { + writer.write_indent (); + writer.write_string ("#include <"); + writer.write_string (filename); + writer.write_string (">"); + writer.write_newline (); } } diff --git a/vala/ccode/valaccodeinitializerlist.vala b/vala/ccode/valaccodeinitializerlist.vala index df9a0b4c5..fcbe00590 100644 --- a/vala/ccode/valaccodeinitializerlist.vala +++ b/vala/ccode/valaccodeinitializerlist.vala @@ -22,31 +22,37 @@ using GLib; -namespace Vala { - public class CCodeInitializerList : CCodeExpression { - List initializers; - - public void append (CCodeExpression! expr) { - initializers.append (expr); - } - - public override void write (CCodeWriter! writer) { - writer.write_string ("{"); +/** + * Represents a struct or array initializer list in the C code. + */ +public class Vala.CCodeInitializerList : CCodeExpression { + private List initializers; + + /** + * Appends the specified expression to this initializer list. + * + * @param expr an expression + */ + public void append (CCodeExpression! expr) { + initializers.append (expr); + } + + public override void write (CCodeWriter! writer) { + writer.write_string ("{"); - bool first = true; - foreach (CCodeExpression expr in initializers) { - if (!first) { - writer.write_string (", "); - } else { - first = false; - } - - if (expr != null) { - expr.write (writer); - } + bool first = true; + foreach (CCodeExpression expr in initializers) { + if (!first) { + writer.write_string (", "); + } else { + first = false; + } + + if (expr != null) { + expr.write (writer); } - - writer.write_string ("}"); } + + writer.write_string ("}"); } } diff --git a/vala/ccode/valaccodemacroreplacement.vala b/vala/ccode/valaccodemacroreplacement.vala index bdab833a0..20b421db1 100644 --- a/vala/ccode/valaccodemacroreplacement.vala +++ b/vala/ccode/valaccodemacroreplacement.vala @@ -22,18 +22,26 @@ using GLib; -namespace Vala { - public class CCodeMacroReplacement : CCodeNode { - public string name { get; construct; } - public string replacement { get; construct; } - - public override void write (CCodeWriter! writer) { - writer.write_indent (); - writer.write_string ("#define "); - writer.write_string (name); - writer.write_string (" "); - writer.write_string (replacement); - writer.write_newline (); - } +/** + * Represents a preprocessor macro replacement definition in the C code. + */ +public class Vala.CCodeMacroReplacement : CCodeNode { + /** + * The name of this macro. + */ + public string! name { get; set construct; } + + /** + * The replacement of this macro. + */ + public string! replacement { get; set construct; } + + public override void write (CCodeWriter! writer) { + writer.write_indent (); + writer.write_string ("#define "); + writer.write_string (name); + writer.write_string (" "); + writer.write_string (replacement); + writer.write_newline (); } } diff --git a/vala/ccode/valaccodememberaccess.vala b/vala/ccode/valaccodememberaccess.vala index 2bd9176a9..e31775198 100644 --- a/vala/ccode/valaccodememberaccess.vala +++ b/vala/ccode/valaccodememberaccess.vala @@ -22,20 +22,32 @@ using GLib; -namespace Vala { - public class CCodeMemberAccess : CCodeExpression { - public CCodeExpression inner { get; construct; } - public string member_name { get; construct; } - public bool is_pointer { get; construct; } - - public override void write (CCodeWriter! writer) { - inner.write (writer); - if (is_pointer) { - writer.write_string ("->"); - } else { - writer.write_string ("."); - } - writer.write_string (member_name); +/** + * Represents an access to a struct member in the C code. + */ +public class Vala.CCodeMemberAccess : CCodeExpression { + /** + * The parent of the member. + */ + public CCodeExpression! inner { get; set construct; } + + /** + * The name of the member. + */ + public string! member_name { get; set construct; } + + /** + * Specifies whether the member access happens by pointer dereferencing. + */ + public bool is_pointer { get; set construct; } + + public override void write (CCodeWriter! writer) { + inner.write (writer); + if (is_pointer) { + writer.write_string ("->"); + } else { + writer.write_string ("."); } + writer.write_string (member_name); } } diff --git a/vala/ccode/valaccodemodifiers.vala b/vala/ccode/valaccodemodifiers.vala index 5825c0771..b54b867a0 100644 --- a/vala/ccode/valaccodemodifiers.vala +++ b/vala/ccode/valaccodemodifiers.vala @@ -22,9 +22,7 @@ using GLib; -namespace Vala { - public enum /* flags */ CCodeModifiers { - NONE, - STATIC - } +public enum /* flags */ Vala.CCodeModifiers { + NONE, + STATIC } diff --git a/vala/ccode/valaccodenewline.vala b/vala/ccode/valaccodenewline.vala index 81011d8c7..9cb36989d 100644 --- a/vala/ccode/valaccodenewline.vala +++ b/vala/ccode/valaccodenewline.vala @@ -22,10 +22,11 @@ using GLib; -namespace Vala { - public class CCodeNewline : CCodeNode { - public override void write (CCodeWriter! writer) { - writer.write_newline (); - } +/** + * Represents a line break in the C code. + */ +public class Vala.CCodeNewline : CCodeNode { + public override void write (CCodeWriter! writer) { + writer.write_newline (); } } diff --git a/vala/ccode/valaccodeoncesection.vala b/vala/ccode/valaccodeoncesection.vala index 94ed8310a..9cd993a2d 100644 --- a/vala/ccode/valaccodeoncesection.vala +++ b/vala/ccode/valaccodeoncesection.vala @@ -22,24 +22,28 @@ using GLib; -namespace Vala { - public class CCodeOnceSection : CCodeFragment { - public string define { get; construct; } - - public override void write (CCodeWriter! writer) { - writer.write_indent (); - writer.write_string ("#ifndef "); - writer.write_string (define); - writer.write_newline (); - writer.write_string ("#define "); - writer.write_string (define); - writer.write_newline (); - foreach (CCodeNode node in children) { - node.write (writer); - } - writer.write_indent (); - writer.write_string ("#endif"); - writer.write_newline (); +/** + * Represents a section that should only to processed once. + */ +public class Vala.CCodeOnceSection : CCodeFragment { + /** + * The name of the guarding define. + */ + public string! define { get; set construct; } + + public override void write (CCodeWriter! writer) { + writer.write_indent (); + writer.write_string ("#ifndef "); + writer.write_string (define); + writer.write_newline (); + writer.write_string ("#define "); + writer.write_string (define); + writer.write_newline (); + foreach (CCodeNode node in get_children ()) { + node.write (writer); } + writer.write_indent (); + writer.write_string ("#endif"); + writer.write_newline (); } } diff --git a/vala/ccode/valaccodeparenthesizedexpression.vala b/vala/ccode/valaccodeparenthesizedexpression.vala index a65c746db..e2770af49 100644 --- a/vala/ccode/valaccodeparenthesizedexpression.vala +++ b/vala/ccode/valaccodeparenthesizedexpression.vala @@ -22,16 +22,20 @@ using GLib; -namespace Vala { - public class CCodeParenthesizedExpression : CCodeExpression { - public CCodeExpression inner { get; construct; } +/** + * Represents a parenthesized expression in the C code. + */ +public class Vala.CCodeParenthesizedExpression : CCodeExpression { + /** + * The expression in the parenthesis. + */ + public CCodeExpression! inner { get; set construct; } + + public override void write (CCodeWriter! writer) { + writer.write_string ("("); - public override void write (CCodeWriter! writer) { - writer.write_string ("("); - - inner.write (writer); + inner.write (writer); - writer.write_string (")"); - } + writer.write_string (")"); } } diff --git a/vala/ccode/valaccodereturnstatement.vala b/vala/ccode/valaccodereturnstatement.vala index 0460219e0..e5d6d81f5 100644 --- a/vala/ccode/valaccodereturnstatement.vala +++ b/vala/ccode/valaccodereturnstatement.vala @@ -22,20 +22,25 @@ using GLib; -namespace Vala { - public class CCodeReturnStatement : CCodeStatement { - public CCodeExpression return_expression { get; construct; } - - 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 (); +/** + * Represents a return statement in the C code. + */ +public class Vala.CCodeReturnStatement : CCodeStatement { + /** + * The optional expression to return. + */ + public CCodeExpression return_expression { get; set; } + + public override void write (CCodeWriter! writer) { + writer.write_indent (); + writer.write_string ("return"); + + if (return_expression != null) { + writer.write_string (" "); + return_expression.write (writer); } + + writer.write_string (";"); + writer.write_newline (); } } diff --git a/vala/ccode/valaccodestatement.vala b/vala/ccode/valaccodestatement.vala index f78184e27..0b4021052 100644 --- a/vala/ccode/valaccodestatement.vala +++ b/vala/ccode/valaccodestatement.vala @@ -22,7 +22,8 @@ using GLib; -namespace Vala { - public abstract class CCodeStatement : CCodeNode { - } +/** + * Represents a statement in the C code. + */ +public abstract class Vala.CCodeStatement : CCodeNode { } diff --git a/vala/ccode/valaccodestruct.vala b/vala/ccode/valaccodestruct.vala index f3bc01a15..ce7ac54cd 100644 --- a/vala/ccode/valaccodestruct.vala +++ b/vala/ccode/valaccodestruct.vala @@ -22,31 +22,47 @@ using GLib; -namespace Vala { - public class CCodeStruct : CCodeNode { - public string name { get; construct; } - List declarations; - - public void add_declaration (CCodeDeclaration! decl) { - declarations.append (decl); - } - - public void add_field (string! type_name, string! name) { - var decl = new CCodeDeclaration (type_name = type_name); - decl.add_declarator (new CCodeVariableDeclarator (name = name)); - add_declaration (decl); - } - - public override void write (CCodeWriter! writer) { - writer.write_string ("struct "); - writer.write_string (name); - writer.write_begin_block (); - foreach (CCodeDeclaration decl in declarations) { - decl.write (writer); - } - writer.write_end_block (); - writer.write_string (";"); - writer.write_newline (); +/** + * Represents a struct declaration in the C code. + */ +public class Vala.CCodeStruct : CCodeNode { + /** + * The struct name. + */ + public string! name { get; set construct; } + + private List declarations; + + /** + * Adds the specified declaration as member to this struct. + * + * @param decl a variable declaration + */ + public void add_declaration (CCodeDeclaration! decl) { + declarations.append (decl); + } + + /** + * Adds a variable with the specified type and name to this struct. + * + * @param type_name field type + * @param name member name + */ + public void add_field (string! type_name, string! name) { + var decl = new CCodeDeclaration (type_name = type_name); + decl.add_declarator (new CCodeVariableDeclarator (name = name)); + add_declaration (decl); + } + + public override void write (CCodeWriter! writer) { + writer.write_string ("struct "); + writer.write_string (name); + writer.write_begin_block (); + foreach (CCodeDeclaration decl in declarations) { + decl.write (writer); } + writer.write_end_block (); + writer.write_string (";"); + writer.write_newline (); } } diff --git a/vala/ccode/valaccodeswitchstatement.vala b/vala/ccode/valaccodeswitchstatement.vala index ad0ea234e..818293d63 100644 --- a/vala/ccode/valaccodeswitchstatement.vala +++ b/vala/ccode/valaccodeswitchstatement.vala @@ -22,27 +22,37 @@ using GLib; -namespace Vala { - public class CCodeSwitchStatement : CCodeStatement { - public CCodeExpression expression { get; construct; } - List case_statements; +/** + * Represents a switch selection statement in the C code. + */ +public class Vala.CCodeSwitchStatement : CCodeStatement { + /** + * The switch expression. + */ + public CCodeExpression! expression { get; set construct; } + + private List case_statements; + + /** + * Adds the specified case statement to the list of switch sections. + * + * @param case_stmt a case statement + */ + public void add_case (CCodeCaseStatement! case_stmt) { + case_statements.append (case_stmt); + } + + public override void write (CCodeWriter! writer) { + writer.write_indent (); + writer.write_string ("switch ("); + expression.write (writer); + writer.write_string (")"); + writer.write_begin_block (); - public void add_case (CCodeCaseStatement! case_stmt) { - case_statements.append (case_stmt); + foreach (CCodeCaseStatement case_stmt in case_statements) { + case_stmt.write (writer); } - public override void write (CCodeWriter! writer) { - writer.write_indent (); - writer.write_string ("switch ("); - expression.write (writer); - writer.write_string (")"); - writer.write_begin_block (); - - foreach (CCodeCaseStatement case_stmt in case_statements) { - case_stmt.write (writer); - } - - writer.write_end_block (); - } + writer.write_end_block (); } } diff --git a/vala/ccode/valaccodeunaryexpression.vala b/vala/ccode/valaccodeunaryexpression.vala index d125441c8..bf18ae5af 100644 --- a/vala/ccode/valaccodeunaryexpression.vala +++ b/vala/ccode/valaccodeunaryexpression.vala @@ -22,41 +22,49 @@ using GLib; -namespace Vala { - public class CCodeUnaryExpression : CCodeExpression { - public CCodeUnaryOperator operator { get; construct; } - public CCodeExpression inner { get; construct; } - - public override void write (CCodeWriter! writer) { - if (operator == CCodeUnaryOperator.PLUS) { - writer.write_string ("+"); - } else if (operator == CCodeUnaryOperator.MINUS) { - writer.write_string ("-"); - } else if (operator == CCodeUnaryOperator.LOGICAL_NEGATION) { - writer.write_string ("!"); - } else if (operator == CCodeUnaryOperator.BITWISE_COMPLEMENT) { - writer.write_string ("~"); - } else if (operator == CCodeUnaryOperator.ADDRESS_OF) { - writer.write_string ("&"); - } +/** + * Represents an expression with one operand in the C code. + */ +public class Vala.CCodeUnaryExpression : CCodeExpression { + /** + * The unary operator. + */ + public CCodeUnaryOperator operator { get; set; } + + /** + * The operand. + */ + public CCodeExpression! inner { get; set construct; } + + public override void write (CCodeWriter! writer) { + if (operator == CCodeUnaryOperator.PLUS) { + writer.write_string ("+"); + } else if (operator == CCodeUnaryOperator.MINUS) { + writer.write_string ("-"); + } else if (operator == CCodeUnaryOperator.LOGICAL_NEGATION) { + writer.write_string ("!"); + } else if (operator == CCodeUnaryOperator.BITWISE_COMPLEMENT) { + writer.write_string ("~"); + } else if (operator == CCodeUnaryOperator.ADDRESS_OF) { + writer.write_string ("&"); + } - inner.write (writer); + inner.write (writer); - if (operator == CCodeUnaryOperator.POSTFIX_INCREMENT) { - writer.write_string ("++"); - } else if (operator == CCodeUnaryOperator.POSTFIX_DECREMENT) { - writer.write_string ("--"); - } + if (operator == CCodeUnaryOperator.POSTFIX_INCREMENT) { + writer.write_string ("++"); + } else if (operator == CCodeUnaryOperator.POSTFIX_DECREMENT) { + writer.write_string ("--"); } } - - public enum CCodeUnaryOperator { - PLUS, - MINUS, - LOGICAL_NEGATION, - BITWISE_COMPLEMENT, - ADDRESS_OF, - POSTFIX_INCREMENT, - POSTFIX_DECREMENT - } +} + +public enum Vala.CCodeUnaryOperator { + PLUS, + MINUS, + LOGICAL_NEGATION, + BITWISE_COMPLEMENT, + ADDRESS_OF, + POSTFIX_INCREMENT, + POSTFIX_DECREMENT } diff --git a/vala/ccode/valaccodevariabledeclarator.vala b/vala/ccode/valaccodevariabledeclarator.vala index c5cccaeb1..ae2fee482 100644 --- a/vala/ccode/valaccodevariabledeclarator.vala +++ b/vala/ccode/valaccodevariabledeclarator.vala @@ -22,18 +22,26 @@ using GLib; -namespace Vala { - public class CCodeVariableDeclarator : CCodeDeclarator { - public string name { get; construct; } - public CCodeExpression initializer { get; construct; } +/** + * Represents a variable declarator in the C code. + */ +public class Vala.CCodeVariableDeclarator : CCodeDeclarator { + /** + * The variable name. + */ + public string! name { get; set construct; } + + /** + * The optional initializer expression. + */ + public CCodeExpression initializer { get; set; } + + public override void write (CCodeWriter! writer) { + writer.write_string (name); - public override void write (CCodeWriter! writer) { - writer.write_string (name); - - if (initializer != null) { - writer.write_string (" = "); - initializer.write (writer); - } + if (initializer != null) { + writer.write_string (" = "); + initializer.write (writer); } } } diff --git a/vala/ccode/valaccodewhilestatement.vala b/vala/ccode/valaccodewhilestatement.vala index bc1f1b3c4..ce74ebd0c 100644 --- a/vala/ccode/valaccodewhilestatement.vala +++ b/vala/ccode/valaccodewhilestatement.vala @@ -22,20 +22,28 @@ using GLib; -namespace Vala { - public class CCodeWhileStatement : CCodeStatement { - public CCodeExpression condition { get; construct; } - public CCodeStatement body { get; construct; } - - public override void write (CCodeWriter! writer) { - writer.write_indent (); - writer.write_string ("while ("); +/** + * Represents a while iteration statement in the C code. + */ +public class Vala.CCodeWhileStatement : CCodeStatement { + /** + * The loop condition. + */ + public CCodeExpression! condition { get; set construct; } + + /** + * The loop body. + */ + public CCodeStatement body { get; set; } + + public override void write (CCodeWriter! writer) { + writer.write_indent (); + writer.write_string ("while ("); - condition.write (writer); + condition.write (writer); - writer.write_string (")"); + writer.write_string (")"); - body.write (writer); - } + body.write (writer); } } diff --git a/vala/ccode/valaccodewriter.vala b/vala/ccode/valaccodewriter.vala index b18e3b120..e444b3f0f 100644 --- a/vala/ccode/valaccodewriter.vala +++ b/vala/ccode/valaccodewriter.vala @@ -22,117 +22,159 @@ using GLib; -namespace Vala { - public class CCodeWriter { - string _filename; - string temp_filename; - bool file_exists; - public string filename { - get { - return _filename; - } - construct { - _filename = value; - file_exists = File.test (_filename, FileTest.EXISTS); - if (file_exists) { - temp_filename = "%s.valatmp".printf (_filename); - stream = File.open (temp_filename, "w"); - } else { - stream = File.open (_filename, "w"); - } - } +/** + * Represents a writer to write C source files. + */ +public class Vala.CCodeWriter { + /** + * Specifies the file to be written. + */ + public string filename { + get { + return _filename; } - - File stream; - - int indent; - /* at begin of line */ - public bool bol = true; - - public void close () { - stream = null; - + construct { + _filename = value; + file_exists = File.test (_filename, FileTest.EXISTS); if (file_exists) { - var changed = true; - - var old_file = MappedFile.new (_filename, false, null); - var new_file = MappedFile.new (temp_filename, false, null); - var len = old_file.get_length (); - if (len == new_file.get_length ()) { - if (Memory.cmp (old_file.get_contents (), new_file.get_contents (), len) == 0) { - changed = false; - } - } - old_file = null; - new_file = null; - - if (changed) { - File.rename (temp_filename, _filename); - } else { - File.unlink (temp_filename); - } + temp_filename = "%s.valatmp".printf (_filename); + stream = File.open (temp_filename, "w"); + } else { + stream = File.open (_filename, "w"); } } + } + + /** + * Specifies whether the output stream is at the beginning of a line. + */ + public bool bol { + get { + return _bol; + } + } + + private string _filename; + private string temp_filename; + private bool file_exists; + + private File stream; + + private int indent; + + /* at begin of line */ + private bool _bol = true; + + /** + * Closes the file. + */ + public void close () { + stream = null; - public void write_indent () { - int i; - - if (!bol) { - stream.putc ('\n'); + if (file_exists) { + var changed = true; + + var old_file = MappedFile.new (_filename, false, null); + var new_file = MappedFile.new (temp_filename, false, null); + var len = old_file.get_length (); + if (len == new_file.get_length ()) { + if (Memory.cmp (old_file.get_contents (), new_file.get_contents (), len) == 0) { + changed = false; + } } + old_file = null; + new_file = null; - for (i = 0; i < indent; i++) { - stream.putc ('\t'); + if (changed) { + File.rename (temp_filename, _filename); + } else { + File.unlink (temp_filename); } - - bol = false; - } - - public void write_string (string s) { - stream.printf ("%s", s); - bol = false; } + } + + /** + * Writes tabs according to the current indent level. + */ + public void write_indent () { + int i; - public void write_newline () { + if (!bol) { stream.putc ('\n'); - bol = true; } - public void write_begin_block () { - if (!bol) { - stream.putc (' '); - } else { - write_indent (); - } - stream.putc ('{'); - write_newline (); - indent++; + for (i = 0; i < indent; i++) { + stream.putc ('\t'); } - public void write_end_block () { - indent--; + _bol = false; + } + + /** + * Writes the specified string. + * + * @param s a string + */ + public void write_string (string! s) { + stream.printf ("%s", s); + _bol = false; + } + + /** + * Writes a newline. + */ + public void write_newline () { + stream.putc ('\n'); + _bol = true; + } + + /** + * Opens a new block, increasing the indent level. + */ + public void write_begin_block () { + if (!bol) { + stream.putc (' '); + } else { write_indent (); - stream.printf ("}"); } + stream.putc ('{'); + write_newline (); + indent++; + } + + /** + * Closes the current block, decreasing the indent level. + */ + public void write_end_block () { + assert (indent > 0); - public void write_comment (string text) { - write_indent (); - stream.printf ("/*"); - bool first = true; - - /* separate declaration due to missing memory management in foreach statements */ - var lines = text.split ("\n"); - - foreach (string line in lines) { - if (!first) { - write_indent (); - } else { - first = false; - } - stream.printf ("%s", line); + indent--; + write_indent (); + stream.printf ("}"); + } + + /** + * Writes the specified text as comment. + * + * @param text the comment text + */ + public void write_comment (string! text) { + write_indent (); + stream.printf ("/*"); + bool first = true; + + /* separate declaration due to missing memory management in foreach statements */ + var lines = text.split ("\n"); + + foreach (string line in lines) { + if (!first) { + write_indent (); + } else { + first = false; } - stream.printf ("*/"); - write_newline (); + stream.printf ("%s", line); } + stream.printf ("*/"); + write_newline (); } } diff --git a/vala/vala/valacodegenerator.vala b/vala/vala/valacodegenerator.vala index 4db3a6608..348353560 100644 --- a/vala/vala/valacodegenerator.vala +++ b/vala/vala/valacodegenerator.vala @@ -1131,7 +1131,7 @@ public class Vala.CodeGenerator : CodeVisitor { } if (stmt.ccodenode is CCodeFragment) { - foreach (CCodeStatement cstmt in ((CCodeFragment) stmt.ccodenode).children) { + foreach (CCodeStatement cstmt in ((CCodeFragment) stmt.ccodenode).get_children ()) { cblock.add_statement (cstmt); } } else { @@ -1262,14 +1262,14 @@ public class Vala.CodeGenerator : CodeVisitor { cunrefcall.add_argument (new CCodeIdentifier (name = "(GFunc) g_free")); } cunrefcall.add_argument (new CCodeConstant (name = "NULL")); - ccomma.inner.append (cunrefcall); + ccomma.append_expression (cunrefcall); } } else if (unref_function == "g_string_free") { ccall.add_argument (new CCodeConstant (name = "TRUE")); } - ccomma.inner.append (ccall); - ccomma.inner.append (new CCodeConstant (name = "NULL")); + ccomma.append_expression (ccall); + ccomma.append_expression (new CCodeConstant (name = "NULL")); var cassign = new CCodeAssignment (left = cvar, right = ccomma); @@ -1312,13 +1312,13 @@ public class Vala.CodeGenerator : CodeVisitor { expr.temp_vars.append (full_expr_decl); var expr_list = new CCodeCommaExpression (); - expr_list.inner.append (new CCodeAssignment (left = new CCodeIdentifier (name = full_expr_decl.name), right = expr.ccodenode)); + expr_list.append_expression (new CCodeAssignment (left = new CCodeIdentifier (name = full_expr_decl.name), right = expr.ccodenode)); foreach (VariableDeclarator decl in temp_ref_vars) { - expr_list.inner.append (get_unref_expression (new CCodeIdentifier (name = decl.name), decl.type_reference)); + expr_list.append_expression (get_unref_expression (new CCodeIdentifier (name = decl.name), decl.type_reference)); } - expr_list.inner.append (new CCodeIdentifier (name = full_expr_decl.name)); + expr_list.append_expression (new CCodeIdentifier (name = full_expr_decl.name)); expr.ccodenode = expr_list; @@ -1508,7 +1508,7 @@ public class Vala.CodeGenerator : CodeVisitor { foreach (VariableDeclarator decl in local_vars) { if (decl.symbol.active && decl.type_reference.type.is_reference_type () && decl.type_reference.is_lvalue_ref) { found = true; - ccomma.inner.append (get_unref_expression (new CCodeIdentifier (name = decl.name), decl.type_reference)); + ccomma.append_expression (get_unref_expression (new CCodeIdentifier (name = decl.name), decl.type_reference)); } } @@ -1527,14 +1527,14 @@ public class Vala.CodeGenerator : CodeVisitor { var return_expr_decl = get_temp_variable_declarator (expr.static_type); var ccomma = new CCodeCommaExpression (); - ccomma.inner.append (new CCodeAssignment (left = new CCodeIdentifier (name = return_expr_decl.name), right = expr.ccodenode)); + ccomma.append_expression (new CCodeAssignment (left = new CCodeIdentifier (name = return_expr_decl.name), right = expr.ccodenode)); if (!append_local_free_expr (current_symbol, ccomma, false)) { /* no local variables need to be freed */ return; } - ccomma.inner.append (new CCodeIdentifier (name = return_expr_decl.name)); + ccomma.append_expression (new CCodeIdentifier (name = return_expr_decl.name)); expr.ccodenode = ccomma; expr.temp_vars.append (return_expr_decl); @@ -1876,8 +1876,8 @@ public class Vala.CodeGenerator : CodeVisitor { ccall.add_argument (ctemp); var ccomma = new CCodeCommaExpression (); - ccomma.inner.append (new CCodeAssignment (left = ctemp, right = expr.ccodenode)); - ccomma.inner.append (new CCodeConditionalExpression (condition = cisnull, true_expression = ctemp, false_expression = ccall)); + ccomma.append_expression (new CCodeAssignment (left = ctemp, right = expr.ccodenode)); + ccomma.append_expression (new CCodeConditionalExpression (condition = cisnull, true_expression = ctemp, false_expression = ccall)); return ccomma; } @@ -2094,9 +2094,9 @@ public class Vala.CodeGenerator : CodeVisitor { var temp_decl = get_temp_variable_declarator (a.left.static_type); temp_vars.prepend (temp_decl); - ccomma.inner.append (new CCodeAssignment (left = new CCodeIdentifier (name = temp_decl.name), right = rhs)); - ccomma.inner.append (get_unref_expression ((CCodeExpression) a.left.ccodenode, a.left.static_type)); - ccomma.inner.append (new CCodeIdentifier (name = temp_decl.name)); + ccomma.append_expression (new CCodeAssignment (left = new CCodeIdentifier (name = temp_decl.name), right = rhs)); + ccomma.append_expression (get_unref_expression ((CCodeExpression) a.left.ccodenode, a.left.static_type)); + ccomma.append_expression (new CCodeIdentifier (name = temp_decl.name)); rhs = ccomma; } diff --git a/vala/vala/valapostfixexpression.vala b/vala/vala/valapostfixexpression.vala index 4ac29ea9e..db7082a65 100644 --- a/vala/vala/valapostfixexpression.vala +++ b/vala/vala/valapostfixexpression.vala @@ -22,19 +22,35 @@ using GLib; -namespace Vala { - public class PostfixExpression : Expression { - public Expression! inner { get; set construct; } - public bool increment { get; set; } +/** + * Represents a postfix increment or decrement expression. + */ +public class Vala.PostfixExpression : Expression { + /** + * The operand, must be a variable or a property. + */ + public Expression! inner { get; set construct; } + + /** + * Specifies whether value should be incremented or decremented. + */ + public bool increment { get; set; } - public static ref PostfixExpression! new (Expression! inner, bool inc, SourceReference source) { - return (new PostfixExpression (inner = inner, increment = inc, source_reference = source)); - } - - public override void accept (CodeVisitor! visitor) { - inner.accept (visitor); + /** + * Creates a new postfix expression. + * + * @param inner operand expression + * @param inc true for increment, false for decrement + * @param source reference to source code + * @return newly created postfix expression + */ + public static ref PostfixExpression! new (Expression! inner, bool inc, SourceReference source) { + return (new PostfixExpression (inner = inner, increment = inc, source_reference = source)); + } + + public override void accept (CodeVisitor! visitor) { + inner.accept (visitor); - visitor.visit_postfix_expression (this); - } + visitor.visit_postfix_expression (this); } } diff --git a/vala/vala/valasemanticanalyzer.vala b/vala/vala/valasemanticanalyzer.vala index 4b018bc7a..b192f3341 100644 --- a/vala/vala/valasemanticanalyzer.vala +++ b/vala/vala/valasemanticanalyzer.vala @@ -1077,6 +1077,12 @@ public class Vala.SemanticAnalyzer : CodeVisitor { } } else if (ma.symbol_reference.node is Property) { var prop = (Property) ma.symbol_reference.node; + + if (prop.set_accessor == null) { + ma.error = true; + Report.error (ma.source_reference, "Property `%s' is read-only".printf (prop.symbol.get_full_name ())); + return; + } } else if (ma.symbol_reference.node is VariableDeclarator && a.right.static_type == null) { var decl = (VariableDeclarator) ma.symbol_reference.node;