Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 2 | // |
| 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 | |
| 15 | package com.google.devtools.build.lib.syntax; |
| 16 | |
janakr | 76de1ad | 2018-03-03 11:12:36 -0800 | [diff] [blame^] | 17 | import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; |
brandjon | e2ffd5d | 2017-06-27 18:14:54 +0200 | [diff] [blame] | 18 | import java.io.IOException; |
Florian Weikert | db8b867 | 2015-11-09 13:26:24 +0000 | [diff] [blame] | 19 | |
janakr | 76de1ad | 2018-03-03 11:12:36 -0800 | [diff] [blame^] | 20 | /** Syntax node for an assignment statement. */ |
| 21 | @AutoCodec |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 22 | public final class AssignmentStatement extends Statement { |
| 23 | |
Laurent Le Brun | 0242382 | 2015-03-19 10:12:49 +0000 | [diff] [blame] | 24 | private final LValue lvalue; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 25 | |
| 26 | private final Expression expression; |
| 27 | |
| 28 | /** |
| 29 | * Constructs an assignment: "lvalue := value". |
| 30 | */ |
brandjon | 540aac6 | 2017-06-12 23:08:09 +0200 | [diff] [blame] | 31 | public AssignmentStatement(LValue lvalue, Expression expression) { |
| 32 | this.lvalue = lvalue; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 33 | this.expression = expression; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Returns the LHS of the assignment. |
| 38 | */ |
Laurent Le Brun | 0242382 | 2015-03-19 10:12:49 +0000 | [diff] [blame] | 39 | public LValue getLValue() { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 40 | return lvalue; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Returns the RHS of the assignment. |
| 45 | */ |
| 46 | public Expression getExpression() { |
| 47 | return expression; |
| 48 | } |
| 49 | |
| 50 | @Override |
brandjon | e2ffd5d | 2017-06-27 18:14:54 +0200 | [diff] [blame] | 51 | 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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | @Override |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 60 | public void accept(SyntaxTreeVisitor visitor) { |
| 61 | visitor.visit(this); |
| 62 | } |
laurentlb | af682d1 | 2017-08-24 20:32:02 +0200 | [diff] [blame] | 63 | |
| 64 | @Override |
| 65 | public Kind kind() { |
| 66 | return Kind.ASSIGNMENT; |
| 67 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 68 | } |