2006-07-08 Jürg Billeter <j@bitron.ch>
+ * 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 <j@bitron.ch>
+
* vala/valasemanticanalyzer.vala: don't allow access to private members
2006-07-08 Jürg Billeter <j@bitron.ch>
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
+}
using GLib;
-namespace Vala {
- public class CCodeBlock : CCodeStatement {
- List<CCodeNode> 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<CCodeNode> 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 ();
}
}
}
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 ();
}
}
using GLib;
-namespace Vala {
- public class CCodeCaseStatement : CCodeStatement {
- public CCodeExpression expression { get; construct; }
- List<CCodeStatement> 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<CCodeStatement> 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);
}
}
}
using GLib;
-namespace Vala {
- public class CCodeCommaExpression : CCodeExpression {
- public List<CCodeExpression> 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<CCodeExpression> 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 (")");
}
}
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);
}
}
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 (")");
}
}
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);
}
}
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 ();
}
}
using GLib;
-namespace Vala {
- public class CCodeDeclaration : CCodeStatement {
- public string type_name { get; construct; }
- public CCodeModifiers modifiers;
- List<CCodeDeclarator> 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<CCodeDeclarator> 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 ();
}
}
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 {
}
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 ();
}
}
using GLib;
-namespace Vala {
- public class CCodeEnum : CCodeNode {
- public string name { get; construct; }
- List<string> 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<string> 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 ();
}
}
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 ();
}
}
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);
}
}
using GLib;
-namespace Vala {
- public class CCodeForStatement : CCodeStatement {
- public CCodeExpression condition { get; construct; }
- public CCodeStatement body { get; construct; }
-
- List<CCodeExpression> initializer;
- List<CCodeExpression> 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<CCodeExpression> initializer;
+ private List<CCodeExpression> 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);
}
}
using GLib;
-namespace Vala {
- public class CCodeFragment : CCodeNode {
- public GLib.List<CCodeNode> 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<CCodeNode> 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<CCodeNode> get_children () {
+ return children.copy ();
+ }
+
+ public override void write (CCodeWriter! writer) {
+ foreach (CCodeNode node in children) {
+ node.write (writer);
}
}
}
using GLib;
-namespace Vala {
- public class CCodeFunction : CCodeNode {
- public string name { get; construct; }
- public CCodeModifiers modifiers;
- public string return_type { get; construct; }
- List<CCodeFormalParameter> 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<CCodeFormalParameter> 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 ();
}
}
using GLib;
-namespace Vala {
- public class CCodeFunctionCall : CCodeExpression {
- public CCodeExpression call { get; construct; }
- List<CCodeExpression> 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<CCodeExpression> 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 (")");
}
}
using GLib;
-namespace Vala {
- public class CCodeFunctionDeclarator : CCodeDeclarator {
- public string name { get; construct; }
- List<CCodeFormalParameter> 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<CCodeFormalParameter> 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 (")");
}
}
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);
}
}
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);
}
}
}
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 ();
}
}
using GLib;
-namespace Vala {
- public class CCodeInitializerList : CCodeExpression {
- List<CCodeExpression> 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<CCodeExpression> 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 ("}");
}
}
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 ();
}
}
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);
}
}
using GLib;
-namespace Vala {
- public enum /* flags */ CCodeModifiers {
- NONE,
- STATIC
- }
+public enum /* flags */ Vala.CCodeModifiers {
+ NONE,
+ STATIC
}
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 ();
}
}
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 ();
}
}
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 (")");
}
}
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 ();
}
}
using GLib;
-namespace Vala {
- public abstract class CCodeStatement : CCodeNode {
- }
+/**
+ * Represents a statement in the C code.
+ */
+public abstract class Vala.CCodeStatement : CCodeNode {
}
using GLib;
-namespace Vala {
- public class CCodeStruct : CCodeNode {
- public string name { get; construct; }
- List<CCodeDeclaration> 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<CCodeDeclaration> 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 ();
}
}
using GLib;
-namespace Vala {
- public class CCodeSwitchStatement : CCodeStatement {
- public CCodeExpression expression { get; construct; }
- List<CCodeCaseStatement> 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<CCodeCaseStatement> 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 ();
}
}
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
}
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);
}
}
}
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);
}
}
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 ();
}
}
}
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 {
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);
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;
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));
}
}
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);
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;
}
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;
}
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);
}
}
}
} 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;