35 * IR base for accessing/indexing nodes. 36 * 37 * @see AccessNode 38 * @see IndexNode 39 */ 40 @Immutable 41 public abstract class BaseNode extends Expression implements FunctionCall, Optimistic { 42 private static final long serialVersionUID = 1L; 43 44 /** Base Node. */ 45 protected final Expression base; 46 47 private final boolean isFunction; 48 49 /** Callsite type for this node, if overridden optimistically or conservatively depending on coercion */ 50 protected final Type type; 51 52 /** Program point id */ 53 protected final int programPoint; 54 55 /** 56 * Constructor 57 * 58 * @param token token 59 * @param finish finish 60 * @param base base node 61 * @param isFunction is this a function 62 */ 63 public BaseNode(final long token, final int finish, final Expression base, final boolean isFunction) { 64 super(token, base.getStart(), finish); 65 this.base = base; 66 this.isFunction = isFunction; 67 this.type = null; 68 this.programPoint = INVALID_PROGRAM_POINT; 69 } 70 71 /** 72 * Copy constructor for immutable nodes 73 * @param baseNode node to inherit from 74 * @param base base 75 * @param isFunction is this a function 76 * @param callSiteType the callsite type for this base node, either optimistic or conservative 77 * @param programPoint program point id 78 */ 79 protected BaseNode(final BaseNode baseNode, final Expression base, final boolean isFunction, final Type callSiteType, final int programPoint) { 80 super(baseNode); 81 this.base = base; 82 this.isFunction = isFunction; 83 this.type = callSiteType; 84 this.programPoint = programPoint; 85 } 86 87 /** 88 * Get the base node for this access 89 * @return the base node 90 */ 91 public Expression getBase() { 92 return base; 93 } 94 95 @Override 96 public boolean isFunction() { 97 return isFunction; 98 } 99 100 @Override 101 public Type getType() { 102 return type == null ? getMostPessimisticType() : type; 103 } 104 119 120 @Override 121 public boolean canBeOptimistic() { 122 return true; 123 } 124 125 /** 126 * Return true if this node represents an index operation normally represented as {@link IndexNode}. 127 * @return true if an index access. 128 */ 129 public boolean isIndex() { 130 return isTokenType(TokenType.LBRACKET); 131 } 132 133 /** 134 * Mark this node as being the callee operand of a {@link CallNode}. 135 * @return a base node identical to this one in all aspects except with its function flag set. 136 */ 137 public abstract BaseNode setIsFunction(); 138 139 } | 35 * IR base for accessing/indexing nodes. 36 * 37 * @see AccessNode 38 * @see IndexNode 39 */ 40 @Immutable 41 public abstract class BaseNode extends Expression implements FunctionCall, Optimistic { 42 private static final long serialVersionUID = 1L; 43 44 /** Base Node. */ 45 protected final Expression base; 46 47 private final boolean isFunction; 48 49 /** Callsite type for this node, if overridden optimistically or conservatively depending on coercion */ 50 protected final Type type; 51 52 /** Program point id */ 53 protected final int programPoint; 54 55 /** Super property access. */ 56 private final boolean isSuper; 57 58 /** 59 * Constructor 60 * 61 * @param token token 62 * @param finish finish 63 * @param base base node 64 * @param isFunction is this a function 65 * @param isSuper is this a super property access 66 */ 67 public BaseNode(final long token, final int finish, final Expression base, final boolean isFunction, final boolean isSuper) { 68 super(token, base.getStart(), finish); 69 this.base = base; 70 this.isFunction = isFunction; 71 this.type = null; 72 this.programPoint = INVALID_PROGRAM_POINT; 73 this.isSuper = isSuper; 74 } 75 76 /** 77 * Copy constructor for immutable nodes 78 * @param baseNode node to inherit from 79 * @param base base 80 * @param isFunction is this a function 81 * @param callSiteType the callsite type for this base node, either optimistic or conservative 82 * @param programPoint program point id 83 * @param isSuper is this a super property access 84 */ 85 protected BaseNode(final BaseNode baseNode, final Expression base, final boolean isFunction, final Type callSiteType, final int programPoint, final boolean isSuper) { 86 super(baseNode); 87 this.base = base; 88 this.isFunction = isFunction; 89 this.type = callSiteType; 90 this.programPoint = programPoint; 91 this.isSuper = isSuper; 92 } 93 94 /** 95 * Get the base node for this access 96 * @return the base node 97 */ 98 public Expression getBase() { 99 return base; 100 } 101 102 @Override 103 public boolean isFunction() { 104 return isFunction; 105 } 106 107 @Override 108 public Type getType() { 109 return type == null ? getMostPessimisticType() : type; 110 } 111 126 127 @Override 128 public boolean canBeOptimistic() { 129 return true; 130 } 131 132 /** 133 * Return true if this node represents an index operation normally represented as {@link IndexNode}. 134 * @return true if an index access. 135 */ 136 public boolean isIndex() { 137 return isTokenType(TokenType.LBRACKET); 138 } 139 140 /** 141 * Mark this node as being the callee operand of a {@link CallNode}. 142 * @return a base node identical to this one in all aspects except with its function flag set. 143 */ 144 public abstract BaseNode setIsFunction(); 145 146 /** 147 * @return {@code true} if a SuperProperty access. 148 */ 149 public boolean isSuper() { 150 return isSuper; 151 } 152 153 /** 154 * Mark this node as being a SuperProperty access. 155 * 156 * @return a base node identical to this one in all aspects except with its super flag set. 157 */ 158 public abstract BaseNode setIsSuper(); 159 } |