blob: d252299dbc5e37380e7530f858e98d978f7d6778 [file] [log] [blame]
Vladimir Moskva8d610c62016-09-15 14:36:41 +00001// Copyright 2014 The Bazel Authors. All rights reserved.
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.
14package com.google.devtools.build.lib.syntax;
15
laurentlb9b96c0b2018-02-12 02:53:19 -080016import javax.annotation.Nullable;
Vladimir Moskva8d610c62016-09-15 14:36:41 +000017
brandjon990622b2017-07-11 19:56:45 +020018/** Syntax node for a slice expression, e.g. obj[:len(obj):2]. */
Vladimir Moskva8d610c62016-09-15 14:36:41 +000019public final class SliceExpression extends Expression {
20
brandjon990622b2017-07-11 19:56:45 +020021 private final Expression object;
laurentlb9b96c0b2018-02-12 02:53:19 -080022 @Nullable private final Expression start;
23 @Nullable private final Expression end;
24 @Nullable private final Expression step;
Vladimir Moskva8d610c62016-09-15 14:36:41 +000025
Googlere0c5e622019-08-09 15:10:14 -070026 SliceExpression(Expression object, Expression start, Expression end, Expression step) {
brandjon990622b2017-07-11 19:56:45 +020027 this.object = object;
Vladimir Moskva8d610c62016-09-15 14:36:41 +000028 this.start = start;
29 this.end = end;
30 this.step = step;
31 }
32
33 public Expression getObject() {
brandjon990622b2017-07-11 19:56:45 +020034 return object;
Vladimir Moskva8d610c62016-09-15 14:36:41 +000035 }
36
laurentlb9b96c0b2018-02-12 02:53:19 -080037 public @Nullable Expression getStart() {
Vladimir Moskva8d610c62016-09-15 14:36:41 +000038 return start;
39 }
40
laurentlb9b96c0b2018-02-12 02:53:19 -080041 public @Nullable Expression getEnd() {
Vladimir Moskva8d610c62016-09-15 14:36:41 +000042 return end;
43 }
44
laurentlb9b96c0b2018-02-12 02:53:19 -080045 public @Nullable Expression getStep() {
Vladimir Moskva8d610c62016-09-15 14:36:41 +000046 return step;
47 }
48
49 @Override
Googler4ace4652019-09-16 07:47:08 -070050 public void accept(NodeVisitor visitor) {
Vladimir Moskva8d610c62016-09-15 14:36:41 +000051 visitor.visit(this);
52 }
laurentlbaf682d12017-08-24 20:32:02 +020053
54 @Override
55 public Kind kind() {
56 return Kind.SLICE;
57 }
Vladimir Moskva8d610c62016-09-15 14:36:41 +000058}