nashorn/src/jdk/nashorn/internal/codegen/MapTuple.java
author attila
Wed, 26 Feb 2014 13:17:57 +0100
changeset 24719 f726e9d67629
child 24751 ccbd9cd3f720
permissions -rw-r--r--
8035820: Optimistic recompilation Reviewed-by: hannesw, jlaskey, sundar Contributed-by: attila.szegedi@oracle.com, marcus.lagergren@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
     1
/*
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
     4
 *
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    10
 *
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    15
 * accompanied this code).
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    16
 *
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    20
 *
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    23
 * questions.
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    24
 */
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    25
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    26
package jdk.nashorn.internal.codegen;
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    27
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    28
import static jdk.nashorn.internal.codegen.ObjectClassGenerator.OBJECT_FIELDS_ONLY;
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    29
import jdk.nashorn.internal.ir.Symbol;
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    30
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    31
/**
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    32
 * A tuple of values used for map creation
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    33
 * @param <T> value type
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    34
 */
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    35
class MapTuple<T> {
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    36
    final String key;
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    37
    final Symbol symbol;
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    38
    final T      value;
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    39
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    40
    MapTuple(final String key, final Symbol symbol) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    41
        this(key, symbol, null);
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    42
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    43
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    44
    MapTuple(final String key, final Symbol symbol, final T value) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    45
        this.key    = key;
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    46
        this.symbol = symbol;
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    47
        this.value  = value;
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    48
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    49
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    50
    public Class<?> getValueType() {
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    51
        return OBJECT_FIELDS_ONLY ? Object.class : null; //until proven otherwise we are undefined, see NASHORN-592 int.class;
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    52
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    53
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    54
    boolean isPrimitive() {
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    55
        return !OBJECT_FIELDS_ONLY && getValueType().isPrimitive() && getValueType() != boolean.class;
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    56
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    57
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    58
    @Override
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    59
    public String toString() {
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    60
        return "[key=" + key + ", symbol=" + symbol + ", value=" + value + " (" + (value == null ? "null" : value.getClass().getSimpleName()) +")]";
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    61
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents:
diff changeset
    62
}