1 /*
2  * Copyright (c) 2005, 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.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 package jdk.test.lib.jittester.arrays;
25 
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.stream.Collectors;
29 import jdk.test.lib.jittester.IRNode;
30 import jdk.test.lib.jittester.Literal;
31 import jdk.test.lib.jittester.VariableDeclaration;
32 import jdk.test.lib.jittester.types.TypeArray;
33 import jdk.test.lib.jittester.visitors.Visitor;
34 
35 public class ArrayCreation extends IRNode {
36     private final VariableDeclaration variable;
37     private final TypeArray array;
38     private final List<Byte> dims;
39 
ArrayCreation(VariableDeclaration var, TypeArray array, ArrayList<IRNode> dimensionSizeExpressions)40     public ArrayCreation(VariableDeclaration var, TypeArray array, ArrayList<IRNode> dimensionSizeExpressions) {
41         super(array);
42         this.variable = var;
43         this.array = array;
44         addChildren(dimensionSizeExpressions);
45         this.dims = dimensionSizeExpressions.stream()
46                 .map(d -> {
47                     if (d instanceof Literal) {
48                         Literal n = (Literal) d;
49                         return (Byte)n.getValue();
50                     }
51                     return (byte)0;
52                 })
53                 .collect(Collectors.toList());
54         TypeArray type = (TypeArray) variable.getVariableInfo().type;
55         type.setDimentions(dims);
56     }
57 
getArrayType()58     public TypeArray getArrayType() {
59         return array;
60     }
61 
62     @Override
accept(Visitor<T> v)63     public<T> T accept(Visitor<T> v) {
64         return v.visit(this);
65     }
66 
getDimensionSize(int dimensionIndex)67     public byte getDimensionSize(int dimensionIndex) {
68         return dims.get(dimensionIndex);
69     }
70 
getDimensionsCount()71     public int getDimensionsCount() {
72         return dims.size();
73     }
74 
getVariable()75     public VariableDeclaration getVariable() {
76         return variable;
77     }
78 }
79