--- /dev/null
+/* valaccodeformalparameter.vala
+ *
+ * Copyright (C) 2006 Jürg Billeter
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Jürg Billeter <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+ public class 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);
+ }
+ }
+}
public string name { get; construct; }
public CCodeModifiers modifiers;
public string return_type { get; construct; }
- List<string> parameters;
+ List<CCodeFormalParameter> parameters;
public CCodeBlock block;
- public void add_parameter (string type, string name) {
- parameters.append ("%s %s".printf (type, name));
+ 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 (" (");
- foreach (string parameter in parameters) {
- writer.write_string (parameter);
+
+ 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 (";");
--- /dev/null
+/* valaccodememberaccess.vala
+ *
+ * Copyright (C) 2006 Jürg Billeter
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Jürg Billeter <j@bitron.ch>
+ */
+
+using GLib;
+
+namespace Vala {
+ public class 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);
+ }
+ }
+}
CCodeBlock block;
TypeReference reference; // dummy for dependency resolution
+ Symbol dummy_symbol; // dummy for dependency resolution
public void emit (CodeContext context) {
context.accept (this);
function.modifiers |= CCodeModifiers.STATIC;
source_type_member_declaration.append (cmethod_decl);
}
+
+ if (m.instance) {
+ var st = (Struct) m.symbol.parent_symbol.node;
+ var this_type = new TypeReference ();
+ this_type.type = st;
+ var cparam = new CCodeFormalParameter (type_name = this_type.get_cname (), name = "self");
+ cmethod_decl.add_parameter (cparam);
+ function.add_parameter (cparam);
+ }
+
+ foreach (FormalParameter param in m.get_parameters ()) {
+ cmethod_decl.add_parameter ((CCodeFormalParameter) param.ccodenode);
+ function.add_parameter ((CCodeFormalParameter) param.ccodenode);
+ }
if (m.body != null) {
function.block = m.body.ccodenode;
source_type_member_definition.append (function);
}
+ public override void visit_formal_parameter (FormalParameter p) {
+ p.ccodenode = new CCodeFormalParameter (type_name = p.type_reference.get_cname (), name = p.name);
+ }
public override void visit_end_block (Block b) {
var cblock = new CCodeBlock ();
if (expr.symbol_reference.node is Method) {
var m = (Method) expr.symbol_reference.node;
expr.ccodenode = new CCodeIdentifier (name = m.get_cname ());
+ } else if (expr.symbol_reference.node is Field) {
+ var f = (Field) expr.symbol_reference.node;
+ expr.ccodenode = new CCodeMemberAccess (inner = new CCodeIdentifier (name = "self"), member_name = f.name, is_pointer = true);
} else {
expr.ccodenode = new CCodeIdentifier (name = expr.name);
}
public override void visit_invocation_expression (InvocationExpression expr) {
var ccall = new CCodeFunctionCall (call = (CCodeExpression) expr.call.ccodenode);
+ var m = (Method) expr.call.symbol_reference.node;
+ if (m.instance) {
+ CCodeExpression instance;
+ if (expr.call is SimpleName) {
+ instance = new CCodeIdentifier (name = "self");
+ } else if (expr.call is MemberAccess) {
+ instance = ((MemberAccess) expr.call).inner.ccodenode;
+ } else {
+ stderr.printf ("internal error: unsupported method invocation\n");
+ }
+ ccall.add_argument (instance);
+ }
+
foreach (Expression arg in expr.argument_list) {
ccall.add_argument ((CCodeExpression) arg.ccodenode);
}
parameters.append (param);
}
+ public ref List<FormalParameter> get_parameters () {
+ return parameters.copy ();
+ }
+
public override void accept (CodeVisitor visitor) {
visitor.visit_begin_method (this);
VALA_OP_TYPE_AND,
VALA_OP_TYPE_BITWISE_AND,
VALA_OP_TYPE_OR,
+ VALA_OP_TYPE_BITWISE_OR,
};
struct _ValaContext {
case VALA_OP_TYPE_OR:
cop = "||";
break;
+ case VALA_OP_TYPE_BITWISE_OR:
+ cop = "|";
+ break;
}
fprintf (generator->c_file, " %s ", cop);
vala_code_generator_process_expression (generator, expr->op.right);
%token SEMICOLON ";"
%token HASH "#"
+%token ASSIGN_BITWISE_OR "|="
+
%token OP_INC "++"
%token OP_DEC "--"
%token OP_EQ "=="
%token OP_NEG "!"
%token OP_OR "||"
%token OP_AND "&&"
+%token BITWISE_OR "|"
%token BITWISE_AND "&"
%token ASSIGN "="
%type <expression> equality_expression
%type <expression> relational_expression
%type <expression> and_expression
+%type <expression> inclusive_or_expression
%type <expression> conditional_and_expression
%type <expression> conditional_or_expression
%type <expression> post_increment_expression
}
;
-conditional_and_expression
+inclusive_or_expression
: and_expression
- | conditional_and_expression OP_AND and_expression
+ | inclusive_or_expression BITWISE_OR and_expression
+ {
+ $$ = g_new0 (ValaExpression, 1);
+ $$->type = VALA_EXPRESSION_TYPE_OPERATION;
+ $$->location = current_location (@1);
+ $$->op.left = $1;
+ $$->op.type = VALA_OP_TYPE_BITWISE_OR;
+ $$->op.right = $3;
+ }
+ ;
+
+conditional_and_expression
+ : inclusive_or_expression
+ | conditional_and_expression OP_AND inclusive_or_expression
{
$$ = g_new0 (ValaExpression, 1);
$$->type = VALA_EXPRESSION_TYPE_OPERATION;
;
assignment
- : primary_expression ASSIGN expression
+ : primary_expression assignment_operator expression
{
$$ = g_new0 (ValaExpression, 1);
$$->type = VALA_EXPRESSION_TYPE_ASSIGNMENT;
}
;
+assignment_operator
+ : ASSIGN
+ | ASSIGN_BITWISE_OR
+ ;
+
selection_statement
: if_statement
{
";" { uploc; return SEMICOLON; }
"#" { uploc; return HASH; }
+"|=" { uploc; return ASSIGN_BITWISE_OR; }
+
"++" { uploc; return OP_INC; }
"--" { uploc; return OP_DEC; }
"==" { uploc; return OP_EQ; }
"&&" { uploc; return OP_AND; }
"&" { uploc; return BITWISE_AND; }
"||" { uploc; return OP_OR; }
+"|" { uploc; return BITWISE_OR; }
"=" { uploc; return ASSIGN; }
"+" { uploc; return PLUS; }