|
73 | 73 | import com.oracle.graal.python.builtins.objects.list.PList;
|
74 | 74 | import com.oracle.graal.python.builtins.objects.slice.PSlice;
|
75 | 75 | import com.oracle.graal.python.builtins.objects.slice.PSlice.SliceInfo;
|
76 |
| -import com.oracle.graal.python.builtins.objects.str.StringBuiltinsFactory.TranslateNodeFactory.SpliceNodeGen; |
| 76 | +import com.oracle.graal.python.builtins.objects.str.StringBuiltinsFactory.SpliceNodeGen; |
77 | 77 | import com.oracle.graal.python.builtins.objects.tuple.PTuple;
|
78 | 78 | import com.oracle.graal.python.nodes.PNodeWithContext;
|
79 | 79 | import com.oracle.graal.python.nodes.SpecialMethodNames;
|
@@ -751,91 +751,91 @@ public String translate(String self, PDict table,
|
751 | 751 |
|
752 | 752 | return new String(translatedChars);
|
753 | 753 | }
|
| 754 | + } |
754 | 755 |
|
755 |
| - protected abstract static class SpliceNode extends PNodeWithContext { |
756 |
| - public static SpliceNode create() { |
757 |
| - return SpliceNodeGen.create(); |
758 |
| - } |
| 756 | + protected abstract static class SpliceNode extends PNodeWithContext { |
| 757 | + public static SpliceNode create() { |
| 758 | + return SpliceNodeGen.create(); |
| 759 | + } |
759 | 760 |
|
760 |
| - protected abstract char[] execute(char[] translatedChars, int i, Object translated); |
| 761 | + protected abstract char[] execute(char[] translatedChars, int i, Object translated); |
761 | 762 |
|
762 |
| - @Specialization |
763 |
| - char[] doInt(char[] translatedChars, int i, int translated, |
764 |
| - @Cached("create()") BranchProfile ovf) { |
765 |
| - char t = (char) translated; |
766 |
| - if (t != translated) { |
767 |
| - ovf.enter(); |
768 |
| - throw raiseError(); |
769 |
| - } |
770 |
| - translatedChars[i] = t; |
771 |
| - return translatedChars; |
| 763 | + @Specialization |
| 764 | + char[] doInt(char[] translatedChars, int i, int translated, |
| 765 | + @Cached("create()") BranchProfile ovf) { |
| 766 | + char t = (char) translated; |
| 767 | + if (t != translated) { |
| 768 | + ovf.enter(); |
| 769 | + throw raiseError(); |
772 | 770 | }
|
| 771 | + translatedChars[i] = t; |
| 772 | + return translatedChars; |
| 773 | + } |
773 | 774 |
|
774 |
| - @Specialization |
775 |
| - char[] doLong(char[] translatedChars, int i, long translated, |
776 |
| - @Cached("create()") BranchProfile ovf) { |
777 |
| - char t = (char) translated; |
778 |
| - if (t != translated) { |
779 |
| - ovf.enter(); |
780 |
| - throw raiseError(); |
781 |
| - } |
782 |
| - translatedChars[i] = t; |
783 |
| - return translatedChars; |
| 775 | + @Specialization |
| 776 | + char[] doLong(char[] translatedChars, int i, long translated, |
| 777 | + @Cached("create()") BranchProfile ovf) { |
| 778 | + char t = (char) translated; |
| 779 | + if (t != translated) { |
| 780 | + ovf.enter(); |
| 781 | + throw raiseError(); |
784 | 782 | }
|
| 783 | + translatedChars[i] = t; |
| 784 | + return translatedChars; |
| 785 | + } |
785 | 786 |
|
786 |
| - private PException raiseError() { |
787 |
| - return raise(ValueError, "character mapping must be in range(0x%s)", Integer.toHexString(Character.MAX_CODE_POINT + 1)); |
788 |
| - } |
| 787 | + private PException raiseError() { |
| 788 | + return raise(ValueError, "character mapping must be in range(0x%s)", Integer.toHexString(Character.MAX_CODE_POINT + 1)); |
| 789 | + } |
789 | 790 |
|
790 |
| - @Specialization |
791 |
| - char[] doPInt(char[] translatedChars, int i, PInt translated, |
792 |
| - @Cached("create()") BranchProfile ovf) { |
793 |
| - double doubleValue = translated.doubleValue(); |
794 |
| - char t = (char) doubleValue; |
795 |
| - if (t != doubleValue) { |
796 |
| - ovf.enter(); |
797 |
| - throw raiseError(); |
798 |
| - } |
799 |
| - translatedChars[i] = t; |
800 |
| - return translatedChars; |
| 791 | + @Specialization |
| 792 | + char[] doPInt(char[] translatedChars, int i, PInt translated, |
| 793 | + @Cached("create()") BranchProfile ovf) { |
| 794 | + double doubleValue = translated.doubleValue(); |
| 795 | + char t = (char) doubleValue; |
| 796 | + if (t != doubleValue) { |
| 797 | + ovf.enter(); |
| 798 | + throw raiseError(); |
801 | 799 | }
|
| 800 | + translatedChars[i] = t; |
| 801 | + return translatedChars; |
| 802 | + } |
802 | 803 |
|
803 |
| - @Specialization(guards = "translated.length() == 1") |
804 |
| - @TruffleBoundary |
805 |
| - char[] doStringChar(char[] translatedChars, int i, String translated) { |
806 |
| - translatedChars[i] = translated.charAt(0); |
807 |
| - return translatedChars; |
808 |
| - } |
| 804 | + @Specialization(guards = "translated.length() == 1") |
| 805 | + @TruffleBoundary |
| 806 | + char[] doStringChar(char[] translatedChars, int i, String translated) { |
| 807 | + translatedChars[i] = translated.charAt(0); |
| 808 | + return translatedChars; |
| 809 | + } |
809 | 810 |
|
810 |
| - @Specialization(guards = "translated.getValue().length() == 1") |
811 |
| - @TruffleBoundary |
812 |
| - char[] doPStringChar(char[] translatedChars, int i, PString translated) { |
813 |
| - translatedChars[i] = translated.getValue().charAt(0); |
814 |
| - return translatedChars; |
815 |
| - } |
| 811 | + @Specialization(guards = "translated.getValue().length() == 1") |
| 812 | + @TruffleBoundary |
| 813 | + char[] doPStringChar(char[] translatedChars, int i, PString translated) { |
| 814 | + translatedChars[i] = translated.getValue().charAt(0); |
| 815 | + return translatedChars; |
| 816 | + } |
816 | 817 |
|
817 |
| - @Specialization(replaces = "doStringChar") |
818 |
| - @TruffleBoundary |
819 |
| - char[] doString(char[] translatedChars, int i, String translated) { |
820 |
| - int transLen = translated.length(); |
821 |
| - if (transLen == 1) { |
822 |
| - translatedChars[i] = translated.charAt(0); |
823 |
| - } else if (transLen == 0) { |
824 |
| - int len = translatedChars.length; |
825 |
| - return Arrays.copyOf(translatedChars, len - 1); |
826 |
| - } else { |
827 |
| - int len = translatedChars.length; |
828 |
| - char[] copy = Arrays.copyOf(translatedChars, len + transLen - 1); |
829 |
| - translated.getChars(0, transLen, copy, i); |
830 |
| - return copy; |
831 |
| - } |
832 |
| - return translatedChars; |
| 818 | + @Specialization(replaces = "doStringChar") |
| 819 | + @TruffleBoundary |
| 820 | + char[] doString(char[] translatedChars, int i, String translated) { |
| 821 | + int transLen = translated.length(); |
| 822 | + if (transLen == 1) { |
| 823 | + translatedChars[i] = translated.charAt(0); |
| 824 | + } else if (transLen == 0) { |
| 825 | + int len = translatedChars.length; |
| 826 | + return Arrays.copyOf(translatedChars, len - 1); |
| 827 | + } else { |
| 828 | + int len = translatedChars.length; |
| 829 | + char[] copy = Arrays.copyOf(translatedChars, len + transLen - 1); |
| 830 | + translated.getChars(0, transLen, copy, i); |
| 831 | + return copy; |
833 | 832 | }
|
| 833 | + return translatedChars; |
| 834 | + } |
834 | 835 |
|
835 |
| - @Specialization(replaces = "doPStringChar") |
836 |
| - char[] doPString(char[] translatedChars, int i, PString translated) { |
837 |
| - return doString(translatedChars, i, translated.getValue()); |
838 |
| - } |
| 836 | + @Specialization(replaces = "doPStringChar") |
| 837 | + char[] doPString(char[] translatedChars, int i, PString translated) { |
| 838 | + return doString(translatedChars, i, translated.getValue()); |
839 | 839 | }
|
840 | 840 | }
|
841 | 841 |
|
|
0 commit comments