equal
deleted
inserted
replaced
657 |
657 |
658 /** |
658 /** |
659 * Copy constructor |
659 * Copy constructor |
660 * @param node source array literal node |
660 * @param node source array literal node |
661 */ |
661 */ |
662 protected ArrayLiteralNode(final ArrayLiteralNode node) { |
662 private ArrayLiteralNode(final ArrayLiteralNode node, final Node[] value) { |
663 super(node); |
663 super(node, value); |
664 this.elementType = node.elementType; |
664 this.elementType = node.elementType; |
|
665 this.presets = node.presets; |
|
666 this.postsets = node.postsets; |
|
667 this.units = node.units; |
665 } |
668 } |
666 |
669 |
667 /** |
670 /** |
668 * Compute things like widest element type needed. Internal use from compiler only |
671 * Compute things like widest element type needed. Internal use from compiler only |
669 */ |
672 */ |
748 if (node == null) { |
751 if (node == null) { |
749 elementType = elementType.widest(Type.OBJECT); //no way to represent undefined as number |
752 elementType = elementType.widest(Type.OBJECT); //no way to represent undefined as number |
750 break; |
753 break; |
751 } |
754 } |
752 |
755 |
753 final Symbol symbol = node.getSymbol(); |
756 assert node.getSymbol() != null; //don't run this on unresolved nodes or you are in trouble |
754 assert symbol != null; //don't run this on unresolved nodes or you are in trouble |
757 Type symbolType = node.getSymbol().getSymbolType(); |
755 Type symbolType = symbol.getSymbolType(); |
|
756 if (symbolType.isUnknown()) { |
758 if (symbolType.isUnknown()) { |
757 symbolType = Type.OBJECT; |
759 symbolType = Type.OBJECT; |
758 } |
760 } |
759 |
761 |
760 if (symbolType.isBoolean()) { |
762 if (symbolType.isBoolean()) { |
811 public Type getElementType() { |
813 public Type getElementType() { |
812 return elementType; |
814 return elementType; |
813 } |
815 } |
814 |
816 |
815 /** |
817 /** |
816 * Get indices of arrays containing computed post sets |
818 * Get indices of arrays containing computed post sets. post sets |
|
819 * are things like non literals e.g. "x+y" instead of i or 17 |
817 * @return post set indices |
820 * @return post set indices |
818 */ |
821 */ |
819 public int[] getPostsets() { |
822 public int[] getPostsets() { |
820 return postsets; |
823 return postsets; |
821 } |
824 } |
847 } |
850 } |
848 |
851 |
849 @Override |
852 @Override |
850 public Node accept(final NodeVisitor visitor) { |
853 public Node accept(final NodeVisitor visitor) { |
851 if (visitor.enterLiteralNode(this)) { |
854 if (visitor.enterLiteralNode(this)) { |
852 for (int i = 0; i < value.length; i++) { |
855 final List<Node> oldValue = Arrays.asList(value); |
853 final Node element = value[i]; |
856 final List<Node> newValue = Node.accept(visitor, Node.class, oldValue); |
854 if (element != null) { |
857 return visitor.leaveLiteralNode(oldValue != newValue ? setValue(newValue) : this); |
855 value[i] = element.accept(visitor); |
|
856 } |
|
857 } |
|
858 return visitor.leaveLiteralNode(this); |
|
859 } |
858 } |
860 return this; |
859 return this; |
|
860 } |
|
861 |
|
862 private ArrayLiteralNode setValue(final List<Node> value) { |
|
863 return new ArrayLiteralNode(this, value.toArray(new Node[value.size()])); |
861 } |
864 } |
862 |
865 |
863 @Override |
866 @Override |
864 public void toString(final StringBuilder sb) { |
867 public void toString(final StringBuilder sb) { |
865 sb.append('['); |
868 sb.append('['); |