blob: 2286f44d2aede175b16c76ca97834fc99bd56504 [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2014 The Bazel Authors. All rights reserved.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package com.google.devtools.build.lib.syntax;
16
janakr76de1ad2018-03-03 11:12:36 -080017import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
brandjone2ffd5d2017-06-27 18:14:54 +020018import java.io.IOException;
Florian Weikertdb8b8672015-11-09 13:26:24 +000019
janakr76de1ad2018-03-03 11:12:36 -080020/** Syntax node for an assignment statement. */
21@AutoCodec
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010022public final class AssignmentStatement extends Statement {
23
Laurent Le Brun02423822015-03-19 10:12:49 +000024 private final LValue lvalue;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010025
26 private final Expression expression;
27
28 /**
29 * Constructs an assignment: "lvalue := value".
30 */
brandjon540aac62017-06-12 23:08:09 +020031 public AssignmentStatement(LValue lvalue, Expression expression) {
32 this.lvalue = lvalue;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010033 this.expression = expression;
34 }
35
36 /**
37 * Returns the LHS of the assignment.
38 */
Laurent Le Brun02423822015-03-19 10:12:49 +000039 public LValue getLValue() {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010040 return lvalue;
41 }
42
43 /**
44 * Returns the RHS of the assignment.
45 */
46 public Expression getExpression() {
47 return expression;
48 }
49
50 @Override
brandjone2ffd5d2017-06-27 18:14:54 +020051 public void prettyPrint(Appendable buffer, int indentLevel) throws IOException {
52 printIndent(buffer, indentLevel);
53 lvalue.prettyPrint(buffer, indentLevel);
54 buffer.append(" = ");
55 expression.prettyPrint(buffer, indentLevel);
56 buffer.append('\n');
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010057 }
58
59 @Override
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010060 public void accept(SyntaxTreeVisitor visitor) {
61 visitor.visit(this);
62 }
laurentlbaf682d12017-08-24 20:32:02 +020063
64 @Override
65 public Kind kind() {
66 return Kind.ASSIGNMENT;
67 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010068}