164
165 /**
166 * Fetch String value of node.
167 *
168 * @return String value of node.
169 */
170 public String getString() {
171 return JSType.toString(value);
172 }
173
174 /**
175 * Fetch Object value of node.
176 *
177 * @return Object value of node.
178 */
179 public Object getObject() {
180 return value;
181 }
182
183 /**
184 * Test if the value is a string.
185 *
186 * @return True if value is a string.
187 */
188 public boolean isString() {
189 return value instanceof String;
190 }
191
192 /**
193 * Test if tha value is a number
194 *
195 * @return True if value is a number
196 */
197 public boolean isNumeric() {
198 return value instanceof Number;
199 }
200
201 /**
202 * Assist in IR navigation.
203 *
590
591 /**
592 * Array literal node class.
593 */
594 @Immutable
595 public static final class ArrayLiteralNode extends LiteralNode<Expression[]> implements LexicalContextNode {
596 private static final long serialVersionUID = 1L;
597
598 /** Array element type. */
599 private final Type elementType;
600
601 /** Preset constant array. */
602 private final Object presets;
603
604 /** Indices of array elements requiring computed post sets. */
605 private final int[] postsets;
606
607 /** Sub units with indexes ranges, in which to split up code generation, for large literals */
608 private final List<ArrayUnit> units;
609
610 /**
611 * An ArrayUnit is a range in an ArrayLiteral. ArrayLiterals can
612 * be split if they are too large, for bytecode generation reasons
613 */
614 public static final class ArrayUnit implements CompileUnitHolder, Serializable {
615 private static final long serialVersionUID = 1L;
616
617 /** Compile unit associated with the postsets range. */
618 private final CompileUnit compileUnit;
619
620 /** postsets range associated with the unit (hi not inclusive). */
621 private final int lo, hi;
622
623 /**
624 * Constructor
625 * @param compileUnit compile unit
626 * @param lo lowest array index in unit
627 * @param hi highest array index in unit + 1
628 */
629 public ArrayUnit(final CompileUnit compileUnit, final int lo, final int hi) {
817 this.units = null;
818 }
819
820 /**
821 * Copy constructor
822 * @param node source array literal node
823 */
824 private ArrayLiteralNode(final ArrayLiteralNode node, final Expression[] value, final Type elementType, final int[] postsets, final Object presets, final List<ArrayUnit> units) {
825 super(node, value);
826 this.elementType = elementType;
827 this.postsets = postsets;
828 this.presets = presets;
829 this.units = units;
830 }
831
832 /**
833 * Returns a list of array element expressions. Note that empty array elements manifest themselves as
834 * null.
835 * @return a list of array element expressions.
836 */
837 public List<Expression> getElementExpressions() {
838 return Collections.unmodifiableList(Arrays.asList(value));
839 }
840
841 /**
842 * Setter that initializes all code generation meta data for an
843 * ArrayLiteralNode. This acts a setter, so the return value may
844 * return a new node and must be handled
845 *
846 * @param lc lexical context
847 * @return new array literal node with postsets, presets and element types initialized
848 */
849 @Override
850 public ArrayLiteralNode initialize(final LexicalContext lc) {
851 return Node.replaceInLexicalContext(lc, this, ArrayLiteralInitializer.initialize(this));
852 }
853
854 /**
855 * Get the array element type as Java format, e.g. [I
856 * @return array element type
|
164
165 /**
166 * Fetch String value of node.
167 *
168 * @return String value of node.
169 */
170 public String getString() {
171 return JSType.toString(value);
172 }
173
174 /**
175 * Fetch Object value of node.
176 *
177 * @return Object value of node.
178 */
179 public Object getObject() {
180 return value;
181 }
182
183 /**
184 * Test if the value is an array
185 *
186 * @return True if value is an array
187 */
188 public boolean isArray() {
189 return false;
190 }
191
192 public List<Expression> getElementExpressions() {
193 return null;
194 }
195
196 /**
197 * Test if the value is a boolean.
198 *
199 * @return True if value is a boolean.
200 */
201 public boolean isBoolean() {
202 return value instanceof Boolean;
203 }
204
205 /**
206 * Test if the value is a string.
207 *
208 * @return True if value is a string.
209 */
210 public boolean isString() {
211 return value instanceof String;
212 }
213
214 /**
215 * Test if tha value is a number
216 *
217 * @return True if value is a number
218 */
219 public boolean isNumeric() {
220 return value instanceof Number;
221 }
222
223 /**
224 * Assist in IR navigation.
225 *
612
613 /**
614 * Array literal node class.
615 */
616 @Immutable
617 public static final class ArrayLiteralNode extends LiteralNode<Expression[]> implements LexicalContextNode {
618 private static final long serialVersionUID = 1L;
619
620 /** Array element type. */
621 private final Type elementType;
622
623 /** Preset constant array. */
624 private final Object presets;
625
626 /** Indices of array elements requiring computed post sets. */
627 private final int[] postsets;
628
629 /** Sub units with indexes ranges, in which to split up code generation, for large literals */
630 private final List<ArrayUnit> units;
631
632 @Override
633 public boolean isArray() {
634 return true;
635 }
636
637
638 /**
639 * An ArrayUnit is a range in an ArrayLiteral. ArrayLiterals can
640 * be split if they are too large, for bytecode generation reasons
641 */
642 public static final class ArrayUnit implements CompileUnitHolder, Serializable {
643 private static final long serialVersionUID = 1L;
644
645 /** Compile unit associated with the postsets range. */
646 private final CompileUnit compileUnit;
647
648 /** postsets range associated with the unit (hi not inclusive). */
649 private final int lo, hi;
650
651 /**
652 * Constructor
653 * @param compileUnit compile unit
654 * @param lo lowest array index in unit
655 * @param hi highest array index in unit + 1
656 */
657 public ArrayUnit(final CompileUnit compileUnit, final int lo, final int hi) {
845 this.units = null;
846 }
847
848 /**
849 * Copy constructor
850 * @param node source array literal node
851 */
852 private ArrayLiteralNode(final ArrayLiteralNode node, final Expression[] value, final Type elementType, final int[] postsets, final Object presets, final List<ArrayUnit> units) {
853 super(node, value);
854 this.elementType = elementType;
855 this.postsets = postsets;
856 this.presets = presets;
857 this.units = units;
858 }
859
860 /**
861 * Returns a list of array element expressions. Note that empty array elements manifest themselves as
862 * null.
863 * @return a list of array element expressions.
864 */
865 @Override
866 public List<Expression> getElementExpressions() {
867 return Collections.unmodifiableList(Arrays.asList(value));
868 }
869
870 /**
871 * Setter that initializes all code generation meta data for an
872 * ArrayLiteralNode. This acts a setter, so the return value may
873 * return a new node and must be handled
874 *
875 * @param lc lexical context
876 * @return new array literal node with postsets, presets and element types initialized
877 */
878 @Override
879 public ArrayLiteralNode initialize(final LexicalContext lc) {
880 return Node.replaceInLexicalContext(lc, this, ArrayLiteralInitializer.initialize(this));
881 }
882
883 /**
884 * Get the array element type as Java format, e.g. [I
885 * @return array element type
|