Commit 62f362b0 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

fix unary expressions add visit_block method add visit methods for

2006-05-16  Jürg Billeter  <j@bitron.ch>

	* vala/parser.y: fix unary expressions
	* vala/valacodegenerator.vala: add visit_block method
	* vala/valacodevisitor.vala: add visit methods for statements,
	  expressions, and literals
	* vala/valaassignment.vala: add accept method
	* vala/valabinaryexpression.vala: add accept method
	* vala/valablock.vala: add accept method
	* vala/valabooleanliteral.vala: add accept method
	* vala/valacastexpression.vala: add accept method
	* vala/valacharacterliteral.vala: add accept method
	* vala/valaconditionalexpression.vala: add accept method
	* vala/valaconstant.vala: visit code containers after child elements
	* vala/valadeclarationstatement.vala: add accept method
	* vala/valaemptystatement.vala: add accept method
	* vala/valaexpressionstatement.vala: add accept method
	* vala/valafield.vala: visit code containers after child elements
	* vala/valaforeachstatement.vala: add accept method
	* vala/valaformalparameter.vala: add accept method
	* vala/valaforstatement.vala: add accept method
	* vala/valaifstatement.vala: add accept method
	* vala/valaintegerliteral.vala: add accept method
	* vala/valainvocationexpression.vala: add accept method
	* vala/valaliteralexpression.vala: add accept method
	* vala/valamemberaccess.vala: add accept method
	* vala/valamethod.vala: add accept method
	* vala/valanullliteral.vala: add accept method
	* vala/valaobjectcreationexpression.vala: add accept method
	* vala/valaparenthesizedexpression.vala: add accept method
	* vala/valapostfixexpression.vala: add accept method
	* vala/valareturnstatement.vala: add accept method
	* vala/valasimplename.vala: add accept method
	* vala/valastringliteral.vala: add accept method
	* vala/valaunaryexpression.vala: fix constructor, add accept method
	* vala/valawhilestatement.vala: add accept method
	* ccode/valaccodefunction.vala: renamed from CCodeMethod

svn path=/trunk/; revision=19
parent f0c3a37f
2006-05-16 Jürg Billeter <j@bitron.ch>
* vala/parser.y: fix unary expressions
* vala/valacodegenerator.vala: add visit_block method
* vala/valacodevisitor.vala: add visit methods for statements,
expressions, and literals
* vala/valaassignment.vala: add accept method
* vala/valabinaryexpression.vala: add accept method
* vala/valablock.vala: add accept method
* vala/valabooleanliteral.vala: add accept method
* vala/valacastexpression.vala: add accept method
* vala/valacharacterliteral.vala: add accept method
* vala/valaconditionalexpression.vala: add accept method
* vala/valaconstant.vala: visit code containers after child elements
* vala/valadeclarationstatement.vala: add accept method
* vala/valaemptystatement.vala: add accept method
* vala/valaexpressionstatement.vala: add accept method
* vala/valafield.vala: visit code containers after child elements
* vala/valaforeachstatement.vala: add accept method
* vala/valaformalparameter.vala: add accept method
* vala/valaforstatement.vala: add accept method
* vala/valaifstatement.vala: add accept method
* vala/valaintegerliteral.vala: add accept method
* vala/valainvocationexpression.vala: add accept method
* vala/valaliteralexpression.vala: add accept method
* vala/valamemberaccess.vala: add accept method
* vala/valamethod.vala: add accept method
* vala/valanullliteral.vala: add accept method
* vala/valaobjectcreationexpression.vala: add accept method
* vala/valaparenthesizedexpression.vala: add accept method
* vala/valapostfixexpression.vala: add accept method
* vala/valareturnstatement.vala: add accept method
* vala/valasimplename.vala: add accept method
* vala/valastringliteral.vala: add accept method
* vala/valaunaryexpression.vala: fix constructor, add accept method
* vala/valawhilestatement.vala: add accept method
* ccode/valaccodefunction.vala: renamed from CCodeMethod
2006-05-16 Jürg Billeter <j@bitron.ch>
* vala/parser.y: support logical AND and OR expressions, conditional
......
/* valaccodemethod.vala
/* valaccodefunction.vala
*
* Copyright (C) 2006 Jürg Billeter
*
......@@ -23,7 +23,7 @@
using GLib;
namespace Vala {
public class CCodeMethod : CCodeNode {
public class CCodeFunction : CCodeNode {
public readonly ref string name;
public CCodeModifiers modifiers;
public readonly ref string return_type;
......
......@@ -462,23 +462,23 @@ unary_expression
: primary_expression
| PLUS unary_expression
{
$$ = VALA_EXPRESSION (vala_unary_expression_new (VALA_UNARY_OPERATOR_PLUS, src(@1)));
$$ = VALA_EXPRESSION (vala_unary_expression_new (VALA_UNARY_OPERATOR_PLUS, $2, src(@1)));
}
| MINUS unary_expression
{
$$ = VALA_EXPRESSION (vala_unary_expression_new (VALA_UNARY_OPERATOR_MINUS, src(@1)));
$$ = VALA_EXPRESSION (vala_unary_expression_new (VALA_UNARY_OPERATOR_MINUS, $2, src(@1)));
}
| OP_NEG unary_expression
{
$$ = VALA_EXPRESSION (vala_unary_expression_new (VALA_UNARY_OPERATOR_LOGICAL_NEGATION, src(@1)));
$$ = VALA_EXPRESSION (vala_unary_expression_new (VALA_UNARY_OPERATOR_LOGICAL_NEGATION, $2, src(@1)));
}
| REF unary_expression
{
$$ = VALA_EXPRESSION (vala_unary_expression_new (VALA_UNARY_OPERATOR_REF, src(@1)));
$$ = VALA_EXPRESSION (vala_unary_expression_new (VALA_UNARY_OPERATOR_REF, $2, src(@1)));
}
| OUT unary_expression
{
$$ = VALA_EXPRESSION (vala_unary_expression_new (VALA_UNARY_OPERATOR_OUT, src(@1)));
$$ = VALA_EXPRESSION (vala_unary_expression_new (VALA_UNARY_OPERATOR_OUT, $2, src(@1)));
}
| cast_expression
;
......
......@@ -31,5 +31,12 @@ namespace Vala {
public static ref Assignment new (Expression left, Expression right, SourceReference source) {
return (new Assignment (left = left, right = right, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
left.accept (visitor);
right.accept (visitor);
visitor.visit_assignment (this);
}
}
}
......@@ -32,6 +32,13 @@ namespace Vala {
public static ref BinaryExpression new (BinaryOperator op, Expression left, Expression right, SourceReference source) {
return (new BinaryExpression (operator = op, left = left, right = right, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
left.accept (visitor);
right.accept (visitor);
visitor.visit_binary_expression (this);
}
}
public enum BinaryOperator {
......
......@@ -30,5 +30,13 @@ namespace Vala {
public static Block# @new (List<Statement> statement_list, SourceReference source) {
return (new Block (statement_list = statement_list, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
foreach (Statement stmt in statement_list) {
stmt.accept (visitor);
}
visitor.visit_block (this);
}
}
}
......@@ -27,8 +27,12 @@ namespace Vala {
public readonly bool value;
public readonly SourceReference# source_reference;
public static BooleanLiteral# @new (bool b, SourceReference source) {
public static ref BooleanLiteral new (bool b, SourceReference source) {
return (new BooleanLiteral (value = b, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
visitor.visit_boolean_literal (this);
}
}
}
......@@ -31,5 +31,12 @@ namespace Vala {
public static CastExpression# @new (Expression inner, TypeReference type, SourceReference source) {
return (new CastExpression (inner = inner, type_reference = type, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
inner.accept (visitor);
type_reference.accept (visitor);
visitor.visit_cast_expression (this);
}
}
}
......@@ -30,5 +30,9 @@ namespace Vala {
public static CharacterLiteral# @new (string c, SourceReference source) {
return (new CharacterLiteral (value = c, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
visitor.visit_character_literal (this);
}
}
}
......@@ -35,6 +35,7 @@ namespace Vala {
CCodeStruct# instance_struct;
CCodeStruct# class_struct;
ref CCodeFunction function;
ref CCodeBlock block;
TypeReference reference; // dummy for dependency resolution
......@@ -117,20 +118,28 @@ namespace Vala {
}
public override void visit_method (Method m) {
CCodeMethod cmethod_decl = new CCodeMethod (name = m.name, return_type = "void");
CCodeMethod cmethod_def = new CCodeMethod (name = m.name, return_type = "void");
var cmethod_decl = new CCodeFunction (name = m.name, return_type = "void");
function = new CCodeFunction (name = m.name, return_type = "void");
if (m.access == MemberAccessibility.PUBLIC) {
header_type_member_declaration.append (cmethod_decl);
} else {
cmethod_decl.modifiers |= CCodeModifiers.STATIC;
cmethod_def.modifiers |= CCodeModifiers.STATIC;
function.modifiers |= CCodeModifiers.STATIC;
source_type_member_declaration.append (cmethod_decl);
}
if (m.source_reference.comment != null) {
source_type_member_definition.append (new CCodeComment (text = m.source_reference.comment));
}
source_type_member_definition.append (cmethod_def);
source_type_member_definition.append (function);
}
public override void visit_block (Block b) {
var cblock = new CCodeBlock ();
if (function.block == null) {
function.block = cblock;
}
}
}
}
......@@ -71,5 +71,80 @@ namespace Vala {
public virtual void visit_type_reference (TypeReference type) {
}
public virtual void visit_block (Block b) {
}
public virtual void visit_empty_statement (EmptyStatement stmt) {
}
public virtual void visit_declaration_statement (DeclarationStatement stmt) {
}
public virtual void visit_expression_statement (ExpressionStatement stmt) {
}
public virtual void visit_if_statement (IfStatement stmt) {
}
public virtual void visit_while_statement (WhileStatement stmt) {
}
public virtual void visit_for_statement (ForStatement stmt) {
}
public virtual void visit_foreach_statement (ForeachStatement stmt) {
}
public virtual void visit_return_statement (ReturnStatement stmt) {
}
public virtual void visit_boolean_literal (BooleanLiteral expr) {
}
public virtual void visit_character_literal (CharacterLiteral expr) {
}
public virtual void visit_integer_literal (IntegerLiteral expr) {
}
public virtual void visit_string_literal (StringLiteral expr) {
}
public virtual void visit_null_literal (NullLiteral expr) {
}
public virtual void visit_literal_expression (LiteralExpression expr) {
}
public virtual void visit_simple_name (SimpleName expr) {
}
public virtual void visit_member_access (MemberAccess expr) {
}
public virtual void visit_invocation_expression (ObjectCreationExpression expr) {
}
public virtual void visit_postfix_expression (PostfixExpression expr) {
}
public virtual void visit_object_creation_expression (ObjectCreationExpression expr) {
}
public virtual void visit_unary_expression (UnaryExpression expr) {
}
public virtual void visit_cast_expression (CastExpression expr) {
}
public virtual void visit_binary_expression (BinaryExpression expr) {
}
public virtual void visit_conditional_expression (ConditionalExpression expr) {
}
public virtual void visit_assignment (Assignment a) {
}
}
}
......@@ -32,5 +32,13 @@ namespace Vala {
public static ref ConditionalExpression new (Expression cond, Expression true_expr, Expression false_expr, SourceReference source) {
return (new ConditionalExpression (condition = cond, true_expression = true_expr, false_expression = false_expr, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
condition.accept (visitor);
true_expression.accept (visitor);
false_expression.accept (visitor);
visitor.visit_conditional_expression (this);
}
}
}
......@@ -35,9 +35,9 @@ namespace Vala {
}
public override void accept (CodeVisitor visitor) {
visitor.visit_constant (this);
type_reference.accept (visitor);
visitor.visit_constant (this);
}
}
}
......@@ -30,5 +30,9 @@ namespace Vala {
public static DeclarationStatement# @new (LocalVariableDeclaration decl, SourceReference source) {
return (new DeclarationStatement (declaration = decl, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
visitor.visit_declaration_statement (this);
}
}
}
......@@ -29,5 +29,9 @@ namespace Vala {
public static EmptyStatement# @new (SourceReference source) {
return (new EmptyStatement (source_reference = source));
}
public override void accept (CodeVisitor visitor) {
visitor.visit_empty_statement (this);
}
}
}
......@@ -30,5 +30,11 @@ namespace Vala {
public static ExpressionStatement# @new (Expression expr, SourceReference source) {
return (new ExpressionStatement (expression = expr, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
visitor.visit_expression_statement (this);
expression.accept (visitor);
}
}
}
......@@ -35,9 +35,9 @@ namespace Vala {
}
public override void accept (CodeVisitor visitor) {
visitor.visit_field (this);
type_reference.accept (visitor);
visitor.visit_field (this);
}
}
}
......@@ -33,5 +33,13 @@ namespace Vala {
public static ForeachStatement# @new (TypeReference type, string id, Expression col, Statement body, SourceReference source) {
return (new ForeachStatement (type_reference = type, variable_name = id, collection = col, body = body, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
type_reference.accept (visitor);
collection.accept (visitor);
body.accept (visitor);
visitor.visit_foreach_statement (this);
}
}
}
......@@ -31,5 +31,9 @@ namespace Vala {
public static ref FormalParameter new (string name, TypeReference type, SourceReference source) {
return (new FormalParameter (name = name, type_reference = type, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
type_reference.accept (visitor);
}
}
}
......@@ -24,14 +24,27 @@ using GLib;
namespace Vala {
public class ForStatement : Statement {
public readonly List<StatementExpression#># initializer;
public readonly ref List<ref Expression> initializer;
public readonly Expression# condition;
public readonly List<StatementExpression#># iterator;
public readonly ref List<ref Expression> iterator;
public readonly Statement# body;
public readonly SourceReference# source_reference;
public static ForStatement# @new (List<StatementExpression> init, Expression cond, List<StatementExpression> iter, Statement body, SourceReference source) {
return (new ForStatement (initializer = init, condition = cond, iterator = iter, body = body, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
foreach (Expression init_expr in initializer) {
init_expr.accept (visitor);
}
condition.accept (visitor);
foreach (Expression it_expr in iterator) {
it_expr.accept (visitor);
}
body.accept (visitor);
visitor.visit_for_statement (this);
}
}
}
......@@ -32,5 +32,15 @@ namespace Vala {
public static IfStatement# @new (Expression cond, Statement true_stmt, Statement false_stmt, SourceReference source) {
return (new IfStatement (condition = cond, true_statement = true_stmt, false_statement = false_stmt, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
condition.accept (visitor);
true_statement.accept (visitor);
if (false_statement != null) {
false_statement.accept (visitor);
}
visitor.visit_if_statement (this);
}
}
}
......@@ -30,5 +30,9 @@ namespace Vala {
public static IntegerLiteral# @new (string i, SourceReference source) {
return (new IntegerLiteral (value = i, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
visitor.visit_integer_literal (this);
}
}
}
......@@ -31,5 +31,14 @@ namespace Vala {
public static InvocationExpression# @new (Expression call, List<Expression> argument_list, SourceReference source) {
return (new InvocationExpression (call = call, argument_list = argument_list, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
call.accept (visitor);
foreach (Expression expr in argument_list) {
expr.accept (visitor);
}
visitor.visit_invocation_expression (this);
}
}
}
......@@ -30,5 +30,11 @@ namespace Vala {
public static LiteralExpression# @new (Literal literal, SourceReference source) {
return (new LiteralExpression (literal = literal, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
literal.accept (visitor);
visitor.visit_literal_expression (this);
}
}
}
......@@ -31,5 +31,11 @@ namespace Vala {
public static ref MemberAccess new (Expression inner, string member, SourceReference source) {
return new MemberAccess (inner = inner, member_name = member, source_reference = source);
}
public override void accept (CodeVisitor visitor) {
inner.accept (visitor);
visitor.visit_member_access (this);
}
}
}
......@@ -50,6 +50,10 @@ namespace Vala {
public override void accept (CodeVisitor visitor) {
visitor.visit_method (this);
if (body != null) {
body.accept (visitor);
}
}
public string get_cname () {
......
......@@ -29,5 +29,9 @@ namespace Vala {
public static NullLiteral# @new (SourceReference source) {
return (new NullLiteral (source_reference = source));
}
public override void accept (CodeVisitor visitor) {
visitor.visit_null_literal (this);
}
}
}
......@@ -31,5 +31,11 @@ namespace Vala {
public static ObjectCreationExpression# @new (TypeReference type, List<NamedArgument> named_argument_list, SourceReference source) {
return (new ObjectCreationExpression (type_reference = type, named_argument_list = named_argument_list, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
type_reference.accept (visitor);
visitor.visit_object_creation_expression (this);
}
}
}
......@@ -30,5 +30,9 @@ namespace Vala {
public static ParenthesizedExpression# @new (Expression inner, SourceReference source) {
return (new ParenthesizedExpression (inner = inner, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
inner.accept (visitor);
}
}
}
......@@ -31,5 +31,11 @@ namespace Vala {
public static 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);
}
}
}
......@@ -30,5 +30,13 @@ namespace Vala {
public static ReturnStatement# @new (Expression result, SourceReference source) {
return (new ReturnStatement (return_expression = result, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
if (return_expression != null) {
return_expression.accept (visitor);
}
visitor.visit_return_statement (this);
}
}
}
......@@ -30,5 +30,9 @@ namespace Vala {
public static SimpleName# @new (string s, List type_argument_list, SourceReference source) {
return (new SimpleName (name = s, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
visitor.visit_simple_name (this);
}
}
}
......@@ -37,5 +37,9 @@ namespace Vala {
/* unescape string */
return noquotes.compress ();
}
public override void accept (CodeVisitor visitor) {
visitor.visit_string_literal (this);
}
}
}
......@@ -25,9 +25,17 @@ using GLib;
namespace Vala {
public class UnaryExpression : Expression {
public readonly UnaryOperator operator;
public readonly ref Expression inner;
public readonly ref SourceReference source_reference;
public static UnaryExpression# @new (UnaryOperator op, SourceReference source) {
return (new UnaryExpression (operator = op));
public static ref UnaryExpression new (UnaryOperator op, Expression inner, SourceReference source) {
return (new UnaryExpression (operator = op, inner = inner, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
inner.accept (visitor);
visitor.visit_unary_expression (this);
}
}
......
......@@ -31,5 +31,12 @@ namespace Vala {
public static WhileStatement# @new (Expression cond, Statement body, SourceReference source) {
return (new WhileStatement (condition = cond, body = body, source_reference = source));
}
public override void accept (CodeVisitor visitor) {
condition.accept (visitor);
body.accept (visitor);
visitor.visit_while_statement (this);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment