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 | package com.google.devtools.build.lib.syntax; |
| 15 | |
brandjon | e2ffd5d | 2017-06-27 18:14:54 +0200 | [diff] [blame] | 16 | import java.io.IOException; |
| 17 | |
janakr | 76de1ad | 2018-03-03 11:12:36 -0800 | [diff] [blame] | 18 | /** Syntax node for an integer literal. */ |
laurentlb | f2854bd | 2017-08-16 12:43:15 +0200 | [diff] [blame] | 19 | public final class IntegerLiteral extends Expression { |
| 20 | private final int value; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 21 | |
Googler | e0c5e62 | 2019-08-09 15:10:14 -0700 | [diff] [blame] | 22 | IntegerLiteral(int value) { |
laurentlb | f2854bd | 2017-08-16 12:43:15 +0200 | [diff] [blame] | 23 | 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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | @Override |
brandjon | e2ffd5d | 2017-06-27 18:14:54 +0200 | [diff] [blame] | 36 | public void prettyPrint(Appendable buffer) throws IOException { |
laurentlb | f2854bd | 2017-08-16 12:43:15 +0200 | [diff] [blame] | 37 | buffer.append(String.valueOf(value)); |
brandjon | e2ffd5d | 2017-06-27 18:14:54 +0200 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | @Override |
Googler | 4ace465 | 2019-09-16 07:47:08 -0700 | [diff] [blame] | 41 | public void accept(NodeVisitor visitor) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 42 | visitor.visit(this); |
| 43 | } |
laurentlb | af682d1 | 2017-08-24 20:32:02 +0200 | [diff] [blame] | 44 | |
| 45 | @Override |
| 46 | public Kind kind() { |
| 47 | return Kind.INTEGER_LITERAL; |
| 48 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 49 | } |