1/*
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package jdk.nashorn.internal.ir;
27
28import java.io.Serializable;
29import java.util.List;
30import jdk.nashorn.internal.codegen.CompileUnit;
31
32/**
33 * An interface for splittable expressions.
34 */
35public interface Splittable {
36
37    /**
38     * Get a list of split ranges for this splittable expression, or null
39     * if the expression should not be split.
40     *
41     * @return a list of split ranges
42     */
43    List<SplitRange> getSplitRanges();
44
45    /**
46     * A SplitRange is a range in a splittable expression. It defines the
47     * boundaries of the split range and provides a compile unit for code generation.
48     */
49    final class SplitRange implements CompileUnitHolder, Serializable {
50        private static final long serialVersionUID = 1L;
51
52        /** Compile unit associated with the postsets range. */
53        private final CompileUnit compileUnit;
54
55        /** postsets range associated with the unit (hi not inclusive). */
56        private final int low, high;
57
58        /**
59         * Constructor
60         * @param compileUnit compile unit
61         * @param low lowest array index in unit
62         * @param high highest array index in unit + 1
63         */
64        public SplitRange(final CompileUnit compileUnit, final int low, final int high) {
65            this.compileUnit = compileUnit;
66            this.low   = low;
67            this.high   = high;
68        }
69
70        /**
71         * Get the high index position of the ArrayUnit (exclusive)
72         * @return high index position
73         */
74        public int getHigh() {
75            return high;
76        }
77
78        /**
79         * Get the low index position of the ArrayUnit (inclusive)
80         * @return low index position
81         */
82        public int getLow() {
83            return low;
84        }
85
86        /**
87         * The array compile unit
88         * @return array compile unit
89         */
90        @Override
91        public CompileUnit getCompileUnit() {
92            return compileUnit;
93        }
94    }
95}
96