blob: 2cb85c18d8c4ed13664b0b3e485681cc5e872383 [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.
14package com.google.devtools.build.lib.syntax;
15
brandjone2ffd5d2017-06-27 18:14:54 +020016import java.io.IOException;
17
janakr76de1ad2018-03-03 11:12:36 -080018/** Syntax node for an integer literal. */
laurentlbf2854bd2017-08-16 12:43:15 +020019public final class IntegerLiteral extends Expression {
20 private final int value;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010021
Googlere0c5e622019-08-09 15:10:14 -070022 IntegerLiteral(int value) {
laurentlbf2854bd2017-08-16 12:43:15 +020023 this.value = value;
24 }
25
26 public int getValue() {
27 return value;
28 }
29
30 @Override
31 Object doEval(Environment env) {
32 return value;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010033 }
34
35 @Override
brandjone2ffd5d2017-06-27 18:14:54 +020036 public void prettyPrint(Appendable buffer) throws IOException {
laurentlbf2854bd2017-08-16 12:43:15 +020037 buffer.append(String.valueOf(value));
brandjone2ffd5d2017-06-27 18:14:54 +020038 }
39
40 @Override
Googler4ace4652019-09-16 07:47:08 -070041 public void accept(NodeVisitor visitor) {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010042 visitor.visit(this);
43 }
laurentlbaf682d12017-08-24 20:32:02 +020044
45 @Override
46 public Kind kind() {
47 return Kind.INTEGER_LITERAL;
48 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010049}