Commit 7a498fd8 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

don't set parent_node in parser support string + operator set parent_node

2006-09-02  Jürg Billeter  <j@bitron.ch>

	* vala/parser.y: don't set parent_node in parser
	* vala/valasemanticanalyzer.vala: support string + operator
	* vala/valaassignment.vala, vala/valabinaryexpression.vala,
	  vala/valacastexpression.vala, vala/valacodenode.vala,
	  vala/valadostatement.vala, vala/valaexpressionstatement.vala,
	  vala/valaforeachstatement.vala, vala/valaforstatement.vala,
	  vala/valaifstatement.vala, vala/valainvocationexpression.vala,
	  vala/valamemberaccess.vala, vala/valaobjectcreationexpression.vala,
	  vala/valaparenthesizedexpression.vala, vala/valareturnstatement.vala,
	  vala/valaswitchstatement.vala, vala/valaunaryexpression.vala,
	  vala/valawhilestatement.vala: set parent_node of child nodes, add
	  replace method
	* vala/valanullliteral.vala: add default argument to construction method
	* tests/test-021.vala: test string + operator
	* tests/Makefile.am: update

svn path=/trunk/; revision=119
parent ae7fbc79
2006-09-02 Jürg Billeter <j@bitron.ch>
* vala/parser.y: don't set parent_node in parser
* vala/valasemanticanalyzer.vala: support string + operator
* vala/valaassignment.vala, vala/valabinaryexpression.vala,
vala/valacastexpression.vala, vala/valacodenode.vala,
vala/valadostatement.vala, vala/valaexpressionstatement.vala,
vala/valaforeachstatement.vala, vala/valaforstatement.vala,
vala/valaifstatement.vala, vala/valainvocationexpression.vala,
vala/valamemberaccess.vala, vala/valaobjectcreationexpression.vala,
vala/valaparenthesizedexpression.vala, vala/valareturnstatement.vala,
vala/valaswitchstatement.vala, vala/valaunaryexpression.vala,
vala/valawhilestatement.vala: set parent_node of child nodes, add
replace method
* vala/valanullliteral.vala: add default argument to construction method
* tests/test-021.vala: test string + operator
* tests/Makefile.am: update
2006-09-02 Jürg Billeter <j@bitron.ch>
* vala/scanner.l: support integer and floating point suffixes
......
......@@ -21,4 +21,5 @@ EXTRA_DIST = \
test-018.vala \
test-019.vala \
test-020.vala \
test-021.vala \
$(NULL)
using GLib;
class Maman.Foo {
static int main (string[] args) {
stdout.printf ("String + operator: 1");
stdout.printf (" 2" + " 3");
stdout.printf (" 4\n");
return 0;
}
}
......@@ -1352,7 +1352,6 @@ expression_statement
ValaSourceReference *src = src_com(@2, $1);
$$ = VALA_STATEMENT (vala_expression_statement_new ($2, src));
g_object_unref (src);
vala_code_node_set_parent_node (VALA_CODE_NODE ($2), VALA_CODE_NODE ($$));
g_object_unref ($2);
}
;
......
......@@ -31,7 +31,15 @@ public class Vala.Assignment : Expression {
/**
* Left hand side of the assignment.
*/
public Expression! left { get; set construct; }
public Expression! left {
get {
return _left;
}
set construct {
_left = value;
_left.parent_node = this;
}
}
/**
* Assignment operator.
......@@ -41,7 +49,18 @@ public class Vala.Assignment : Expression {
/**
* Right hand side of the assignment.
*/
public Expression! right { get; set construct; }
public Expression! right {
get {
return _right;
}
set construct {
_right = value;
_right.parent_node = this;
}
}
private Expression! _left;
private Expression! _right;
/**
* Creates a new assignment.
......@@ -68,6 +87,15 @@ public class Vala.Assignment : Expression {
visitor.visit_end_assignment (this);
}
public override void replace (CodeNode! old_node, CodeNode! new_node) {
if (left == old_node) {
left = new_node;
}
if (right == old_node) {
right = new_node;
}
}
}
public enum Vala.AssignmentOperator {
......
......@@ -36,12 +36,31 @@ public class Vala.BinaryExpression : Expression {
/**
* The left operand.
*/
public Expression! left { get; set construct; }
public Expression! left {
get {
return _left;
}
set construct {
_left = value;
_left.parent_node = this;
}
}
/**
* The right operand.
*/
public Expression! right { get; set construct; }
public Expression! right {
get {
return _right;
}
set construct {
_right = value;
_right.parent_node = this;
}
}
private Expression! _left;
private Expression! _right;
/**
* Creates a new binary expression.
......@@ -65,6 +84,15 @@ public class Vala.BinaryExpression : Expression {
visitor.visit_binary_expression (this);
}
public override void replace (CodeNode! old_node, CodeNode! new_node) {
if (left == old_node) {
left = new_node;
}
if (right == old_node) {
right = new_node;
}
}
}
public enum Vala.BinaryOperator {
......
......@@ -29,13 +29,23 @@ public class Vala.CastExpression : Expression {
/**
* The expression to be cast.
*/
public Expression! inner { get; set construct; }
public Expression! inner {
get {
return _inner;
}
set construct {
_inner = value;
_inner.parent_node = this;
}
}
/**
* The target type.
*/
public TypeReference! type_reference { get; set construct; }
private Expression! _inner;
/**
* Creates a new cast expression.
*
......@@ -55,4 +65,10 @@ public class Vala.CastExpression : Expression {
visitor.visit_cast_expression (this);
}
public override void replace (CodeNode! old_node, CodeNode! new_node) {
if (inner == old_node) {
inner = new_node;
}
}
}
......@@ -81,5 +81,8 @@ public abstract class Vala.CodeNode {
*/
public abstract void accept (CodeVisitor! visitor);
public virtual void replace (CodeNode! old_node, CodeNode! new_node) {
}
private CCodeNode _ccodenode;
}
......@@ -34,7 +34,17 @@ public class Vala.DoStatement : Statement {
/**
* Specifies the loop condition.
*/
public Expression condition { get; set; }
public Expression! condition {
get {
return _condition;
}
set construct {
_condition = value;
_condition.parent_node = this;
}
}
private Expression! _condition;
/**
* Creates a new do statement.
......@@ -59,4 +69,10 @@ public class Vala.DoStatement : Statement {
visitor.visit_do_statement (this);
}
public override void replace (CodeNode! old_node, CodeNode! new_node) {
if (condition == old_node) {
condition = new_node;
}
}
}
......@@ -30,7 +30,17 @@ public class Vala.ExpressionStatement : Statement {
/**
* Specifies the expression to evaluate.
*/
public Expression! expression { get; set construct; }
public Expression! expression {
get {
return _expression;
}
set construct {
_expression = value;
_expression.parent_node = this;
}
}
private Expression! _expression;
/**
* Creates a new expression statement.
......@@ -50,6 +60,12 @@ public class Vala.ExpressionStatement : Statement {
visitor.visit_expression_statement (this);
}
public override void replace (CodeNode! old_node, CodeNode! new_node) {
if (expression == old_node) {
expression = new_node;
}
}
public override int get_number_of_set_construction_parameters () {
if (expression is Assignment) {
var assign = (Assignment) expression;
......
......@@ -40,7 +40,15 @@ public class Vala.ForeachStatement : Statement {
/**
* Specifies the container.
*/
public Expression! collection { get; set construct; }
public Expression! collection {
get {
return _collection;
}
set construct {
_collection = value;
_collection.parent_node = this;
}
}
/**
* Specifies the loop body.
......@@ -52,6 +60,8 @@ public class Vala.ForeachStatement : Statement {
*/
public VariableDeclarator variable_declarator { get; set; }
private Expression! _collection;
/**
* Creates a new foreach statement.
*
......@@ -78,4 +88,10 @@ public class Vala.ForeachStatement : Statement {
visitor.visit_end_foreach_statement (this);
}
public override void replace (CodeNode! old_node, CodeNode! new_node) {
if (collection == old_node) {
collection = new_node;
}
}
}
......@@ -29,7 +29,15 @@ public class Vala.ForStatement : Statement {
/**
* Specifies the loop condition.
*/
public Expression condition { get; set; }
public Expression! condition {
get {
return _condition;
}
set construct {
_condition = value;
_condition.parent_node = this;
}
}
/**
* Specifies the loop body.
......@@ -39,6 +47,8 @@ public class Vala.ForStatement : Statement {
private List<Expression> initializer;
private List<Expression> iterator;
private Expression! _condition;
/**
* Creates a new for statement.
*
......@@ -106,4 +116,10 @@ public class Vala.ForStatement : Statement {
visitor.visit_for_statement (this);
}
public override void replace (CodeNode! old_node, CodeNode! new_node) {
if (condition == old_node) {
condition = new_node;
}
}
}
......@@ -29,7 +29,15 @@ public class Vala.IfStatement : Statement {
/**
* The boolean condition to evaluate.
*/
public Expression! condition { get; set construct; }
public Expression! condition {
get {
return _condition;
}
set construct {
_condition = value;
_condition.parent_node = this;
}
}
/**
* The statement to be evaluated if the condition holds.
......@@ -41,6 +49,8 @@ public class Vala.IfStatement : Statement {
*/
public Block false_statement { get; set construct; }
private Expression! _condition;
/**
* Creates a new if statement.
*
......@@ -68,4 +78,10 @@ public class Vala.IfStatement : Statement {
visitor.visit_if_statement (this);
}
public override void replace (CodeNode! old_node, CodeNode! new_node) {
if (condition == old_node) {
condition = new_node;
}
}
}
......@@ -29,7 +29,17 @@ public class Vala.InvocationExpression : Expression {
/**
* The method to call.
*/
public Expression! call { get; set construct; }
public Expression! call {
get {
return _call;
}
set construct {
_call = value;
_call.parent_node = this;
}
}
public Expression! _call;
private List<Expression> argument_list;
......@@ -52,6 +62,7 @@ public class Vala.InvocationExpression : Expression {
*/
public void add_argument (Expression! arg) {
argument_list.append (arg);
arg.parent_node = this;
}
/**
......@@ -74,4 +85,21 @@ public class Vala.InvocationExpression : Expression {
visitor.visit_end_invocation_expression (this);
}
public override void replace (CodeNode! old_node, CodeNode! new_node) {
if (call == old_node) {
call = new_node;
}
List l = argument_list.find (old_node);
if (l != null) {
if (new_node.parent_node != null) {
return;
}
argument_list.insert_before (l, new_node);
argument_list.remove_link (l);
new_node.parent_node = this;
}
}
}
......@@ -29,13 +29,24 @@ public class Vala.MemberAccess : Expression {
/**
* The parent of the member.
*/
public Expression inner { get; set; }
public Expression inner {
get {
return _inner;
}
set {
_inner = value;
if (_inner != null) {
_inner.parent_node = this;
}
}
}
/**
* The name of the member.
*/
public string! member_name { get; set construct; }
private Expression _inner;
private List<TypeReference> type_argument_list;
/**
......@@ -90,4 +101,10 @@ public class Vala.MemberAccess : Expression {
return "%s.%s".printf (inner.to_string (), member_name);
}
}
public override void replace (CodeNode! old_node, CodeNode! new_node) {
if (inner == old_node) {
inner = new_node;
}
}
}
......@@ -32,7 +32,7 @@ public class Vala.NullLiteral : Literal {
* @param source reference to source code
* @return newly created null literal
*/
public construct (SourceReference source) {
public construct (SourceReference source = null) {
source_reference = source;
}
......
......@@ -64,6 +64,7 @@ public class Vala.ObjectCreationExpression : Expression {
*/
public void add_argument (Expression! arg) {
argument_list.append (arg);
arg.parent_node = this;
}
/**
......@@ -92,4 +93,17 @@ public class Vala.ObjectCreationExpression : Expression {
visitor.visit_end_object_creation_expression (this);
}
public override void replace (CodeNode! old_node, CodeNode! new_node) {
List l = argument_list.find (old_node);
if (l != null) {
if (new_node.parent_node != null) {
return;
}
argument_list.insert_before (l, new_node);
argument_list.remove_link (l);
new_node.parent_node = this;
}
}
}
......@@ -29,7 +29,17 @@ public class Vala.ParenthesizedExpression : Expression {
/**
* The inner expression.
*/
public Expression! inner { get; set construct; }
public Expression! inner {
get {
return _inner;
}
set construct {
_inner = value;
_inner.parent_node = this;
}
}
private Expression! _inner;
/**
* Creates a new parenthesized expression.
......@@ -48,4 +58,10 @@ public class Vala.ParenthesizedExpression : Expression {
visitor.visit_parenthesized_expression (this);
}
public override void replace (CodeNode! old_node, CodeNode! new_node) {
if (inner == old_node) {
inner = new_node;
}
}
}
......@@ -29,7 +29,19 @@ public class Vala.ReturnStatement : Statement {
/**
* The optional expression to return.
*/
public Expression return_expression { get; set; }
public Expression return_expression {
get {
return _return_expression;
}
set {
_return_expression = value;
if (_return_expression != null) {
_return_expression.parent_node = this;
}
}
}
private Expression! _return_expression;
/**
* Creates a new return statement.
......@@ -52,4 +64,10 @@ public class Vala.ReturnStatement : Statement {
visitor.visit_return_statement (this);
}
public override void replace (CodeNode! old_node, CodeNode! new_node) {
if (return_expression == old_node) {
return_expression = new_node;
}
}
}
......@@ -1188,7 +1188,14 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
return;
}
expr.static_type = string_type;
/* string concatenation: convert to a.concat (b) */
var concat_call = new InvocationExpression (new MemberAccess (expr.left, "concat"));
concat_call.add_argument (expr.right);
expr.parent_node.replace (expr, concat_call);
concat_call.accept (this);
} else if (expr.operator == BinaryOperator.PLUS
|| expr.operator == BinaryOperator.MINUS
|| expr.operator == BinaryOperator.MUL
......
......@@ -29,8 +29,17 @@ public class Vala.SwitchStatement : Statement {
/**
* Specifies the switch expression.
*/
public Expression! expression { get; set construct; }
public Expression! expression {
get {
return _expression;
}
set construct {
_expression = value;
_expression.parent_node = this;
}
}
private Expression! _expression;
private List<SwitchSection> sections;
/**
......@@ -74,4 +83,10 @@ public class Vala.SwitchStatement : Statement {
visitor.visit_switch_statement (this);
}
public override void replace (CodeNode! old_node, CodeNode! new_node) {
if (expression == old_node) {
expression = new_node;
}
}
}
......@@ -36,8 +36,18 @@ public class Vala.UnaryExpression : Expression {
/**
* The operand.
*/
public Expression! inner { get; set construct; }
public Expression! inner {
get {
return _inner;
}
set construct {
_inner = value;
_inner.parent_node = this;
}
}
private Expression! _inner;
/**
* Creates a new unary expression.
*
......@@ -57,6 +67,12 @@ public class Vala.UnaryExpression : Expression {
visitor.visit_unary_expression (this);
}
public override void replace (CodeNode! old_node, CodeNode! new_node) {
if (inner == old_node) {
inner = new_node;
}
}
}
public enum Vala.UnaryOperator {
......
......@@ -29,13 +29,23 @@ public class Vala.WhileStatement : Statement {
/**
* Specifies the loop condition.
*/
public Expression condition { get; set; }
public Expression! condition {
get {
return _condition;
}
set construct {
_condition = value;
_condition.parent_node = this;
}
}
/**
* Specifies the loop body.
*/
public Statement body { get; set; }
private Expression! _condition;
/**
* Creates a new while statement.
*
......@@ -59,4 +69,10 @@ public class Vala.WhileStatement : Statement {
visitor.visit_while_statement (this);
}
public override void replace (CodeNode! old_node, CodeNode! new_node) {
if (condition == old_node) {
condition = new_node;
}
}
}
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