nashorn/src/jdk/nashorn/internal/ir/BaseNode.java
changeset 24719 f726e9d67629
parent 20928 3ff39d5c8c08
child 24751 ccbd9cd3f720
--- a/nashorn/src/jdk/nashorn/internal/ir/BaseNode.java	Tue Feb 25 18:56:10 2014 +0530
+++ b/nashorn/src/jdk/nashorn/internal/ir/BaseNode.java	Wed Feb 26 13:17:57 2014 +0100
@@ -25,6 +25,9 @@
 
 package jdk.nashorn.internal.ir;
 
+import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.INVALID_PROGRAM_POINT;
+
+import jdk.nashorn.internal.codegen.types.Type;
 import jdk.nashorn.internal.ir.annotations.Immutable;
 
 /**
@@ -34,13 +37,22 @@
  * @see IndexNode
  */
 @Immutable
-public abstract class BaseNode extends Expression implements FunctionCall {
+public abstract class BaseNode extends Expression implements FunctionCall, Optimistic {
 
     /** Base Node. */
     protected final Expression base;
 
     private final boolean isFunction;
 
+    /** Callsite type for this node, if overriden optimistically or conservatively depending on coercion */
+    protected final Type optimisticType;
+
+    /** Does this node have a callsite type, and it is optimistic rather than inferred from coercion semantics */
+    protected final boolean isOptimistic;
+
+    /** Program point id */
+    protected final int programPoint;
+
     /**
      * Constructor
      *
@@ -51,8 +63,11 @@
      */
     public BaseNode(final long token, final int finish, final Expression base, final boolean isFunction) {
         super(token, base.getStart(), finish);
-        this.base            = base;
-        this.isFunction      = isFunction;
+        this.base           = base;
+        this.isFunction     = isFunction;
+        this.optimisticType = null;
+        this.programPoint   = INVALID_PROGRAM_POINT;
+        this.isOptimistic   = false;
     }
 
     /**
@@ -60,11 +75,17 @@
      * @param baseNode node to inherit from
      * @param base base
      * @param isFunction is this a function
+     * @param callSiteType  the callsite type for this base node, either optimistic or conservative
+     * @param isOptimistic  is the callsite type optimistic rather than based on statically known coercion semantics
+     * @param programPoint  program point id
      */
-    protected BaseNode(final BaseNode baseNode, final Expression base, final boolean isFunction) {
+    protected BaseNode(final BaseNode baseNode, final Expression base, final boolean isFunction, final Type callSiteType, final boolean isOptimistic, final int programPoint) {
         super(baseNode);
-        this.base            = base;
-        this.isFunction      = isFunction;
+        this.base           = base;
+        this.isFunction     = isFunction;
+        this.optimisticType = callSiteType;
+        this.programPoint   = programPoint;
+        this.isOptimistic   = isOptimistic;
     }
 
     /**
@@ -80,6 +101,37 @@
         return isFunction;
     }
 
+    @Override
+    public final Type getType() {
+        return optimisticType == null ? super.getType() : optimisticType;
+    }
+
+    @Override
+    public int getProgramPoint() {
+        return programPoint;
+    }
+
+    @Override
+    public Type getMostOptimisticType() {
+        return Type.INT;
+    }
+
+    @Override
+    public Type getMostPessimisticType() {
+        return Type.OBJECT;
+    }
+
+    @Override
+    public boolean canBeOptimistic() {
+        return true;
+    }
+
+    @Override
+    public boolean isOptimistic() {
+        return isOptimistic;
+    }
+
+
     /**
      * Mark this node as being the callee operand of a {@link CallNode}.
      * @return a base node identical to this one in all aspects except with its function flag set.