66
66
import static com .oracle .graal .python .nodes .ErrorMessages .TAKES_EXACTLY_D_ARGUMENTS_D_GIVEN ;
67
67
import static com .oracle .graal .python .nodes .PGuards .isInteger ;
68
68
import static com .oracle .graal .python .nodes .PGuards .isNoValue ;
69
+ import static com .oracle .graal .python .nodes .SpecialAttributeNames .__ABSTRACTMETHODS__ ;
69
70
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__BASICSIZE__ ;
70
71
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__CLASSCELL__ ;
71
72
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__DICTOFFSET__ ;
180
181
import com .oracle .graal .python .builtins .objects .type .PythonBuiltinClass ;
181
182
import com .oracle .graal .python .builtins .objects .type .PythonClass ;
182
183
import com .oracle .graal .python .builtins .objects .type .PythonManagedClass ;
184
+ import com .oracle .graal .python .builtins .objects .type .TypeFlags ;
183
185
import com .oracle .graal .python .builtins .objects .type .TypeNodes ;
184
186
import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetBestBaseClassNode ;
185
187
import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetItemsizeNode ;
190
192
import com .oracle .graal .python .nodes .BuiltinNames ;
191
193
import com .oracle .graal .python .nodes .ErrorMessages ;
192
194
import com .oracle .graal .python .nodes .PGuards ;
195
+ import com .oracle .graal .python .nodes .PNodeWithContext ;
196
+ import com .oracle .graal .python .nodes .PRaiseNode ;
193
197
import com .oracle .graal .python .nodes .SpecialAttributeNames ;
194
198
import com .oracle .graal .python .nodes .SpecialMethodNames ;
195
199
import com .oracle .graal .python .nodes .attributes .GetAttributeNode ;
199
203
import com .oracle .graal .python .nodes .attributes .ReadAttributeFromObjectNode ;
200
204
import com .oracle .graal .python .nodes .attributes .SetAttributeNode ;
201
205
import com .oracle .graal .python .nodes .attributes .WriteAttributeToObjectNode ;
206
+ import com .oracle .graal .python .nodes .builtins .ListNodes ;
202
207
import com .oracle .graal .python .nodes .builtins .TupleNodes ;
203
208
import com .oracle .graal .python .nodes .call .CallNode ;
204
209
import com .oracle .graal .python .nodes .call .special .LookupAndCallTernaryNode ;
@@ -1629,11 +1634,34 @@ public abstract static class ObjectNode extends PythonVarargsBuiltinNode {
1629
1634
@ Child private SplitArgsNode splitArgsNode ;
1630
1635
@ Child private LookupAttributeInMRONode lookupInit ;
1631
1636
@ Child private LookupAttributeInMRONode lookupNew ;
1637
+ @ Child private ReportAbstractClassNode reportAbstractClassNode ;
1632
1638
@ CompilationFinal private ValueProfile profileInit ;
1633
1639
@ CompilationFinal private ValueProfile profileNew ;
1634
1640
@ CompilationFinal private ValueProfile profileInitFactory ;
1635
1641
@ CompilationFinal private ValueProfile profileNewFactory ;
1636
1642
1643
+ abstract static class ReportAbstractClassNode extends PNodeWithContext {
1644
+ public abstract PException execute (VirtualFrame frame , Object type );
1645
+
1646
+ @ Specialization
1647
+ static PException report (VirtualFrame frame , Object type ,
1648
+ @ CachedLibrary (limit = "2" ) PythonObjectLibrary lib ,
1649
+ @ Cached ReadAttributeFromObjectNode readAttributeFromObjectNode ,
1650
+ @ Cached CastToJavaStringNode cast ,
1651
+ @ Cached ListNodes .ConstructListNode constructListNode ,
1652
+ @ Cached PRaiseNode raiseNode ) {
1653
+ PList list = constructListNode .execute (readAttributeFromObjectNode .execute (type , __ABSTRACTMETHODS__ ));
1654
+ int methodCount = lib .lengthWithFrame (list , frame );
1655
+ lib .lookupAndCallRegularMethod (list , frame , "sort" );
1656
+ String joined = cast .execute (lib .lookupAndCallRegularMethod (", " , frame , "join" , list ));
1657
+ throw raiseNode .raise (TypeError , "Can't instantiate abstract class %N with abstract method%s %s" , type , methodCount > 1 ? "s" : "" , joined );
1658
+ }
1659
+
1660
+ public static ReportAbstractClassNode create () {
1661
+ return BuiltinConstructorsFactory .ObjectNodeFactory .ReportAbstractClassNodeGen .create ();
1662
+ }
1663
+ }
1664
+
1637
1665
@ Override
1638
1666
public final Object varArgExecute (VirtualFrame frame , @ SuppressWarnings ("unused" ) Object self , Object [] arguments , PKeyword [] keywords ) throws VarargsBuiltinDirectInvocationNotSupported {
1639
1667
if (splitArgsNode == null ) {
@@ -1644,8 +1672,11 @@ public final Object varArgExecute(VirtualFrame frame, @SuppressWarnings("unused"
1644
1672
}
1645
1673
1646
1674
@ Specialization (guards = {"!self.needsNativeAllocation()" })
1647
- Object doManagedObject (PythonManagedClass self , Object [] varargs , PKeyword [] kwargs ) {
1675
+ Object doManagedObject (VirtualFrame frame , PythonManagedClass self , Object [] varargs , PKeyword [] kwargs ) {
1648
1676
checkExcessArgs (self , varargs , kwargs );
1677
+ if (self .isAbstractClass ()) {
1678
+ throw getReportAbstractClassNode ().execute (frame , self );
1679
+ }
1649
1680
return factory ().createPythonObject (self );
1650
1681
}
1651
1682
@@ -1656,16 +1687,23 @@ Object doBuiltinTypeType(PythonBuiltinClassType self, Object[] varargs, PKeyword
1656
1687
}
1657
1688
1658
1689
@ Specialization (guards = "self.needsNativeAllocation()" )
1659
- Object doNativeObjectIndirect (PythonManagedClass self , Object [] varargs , PKeyword [] kwargs ,
1690
+ Object doNativeObjectIndirect (VirtualFrame frame , PythonManagedClass self , Object [] varargs , PKeyword [] kwargs ,
1660
1691
@ Cached ("create()" ) GetMroNode getMroNode ) {
1661
1692
checkExcessArgs (self , varargs , kwargs );
1693
+ if (self .isAbstractClass ()) {
1694
+ throw getReportAbstractClassNode ().execute (frame , self );
1695
+ }
1662
1696
Object nativeBaseClass = findFirstNativeBaseClass (getMroNode .execute (self ));
1663
1697
return callNativeGenericNewNode (nativeBaseClass , varargs , kwargs );
1664
1698
}
1665
1699
1666
1700
@ Specialization (guards = "isNativeClass(self)" )
1667
- Object doNativeObjectIndirect (Object self , Object [] varargs , PKeyword [] kwargs ) {
1701
+ Object doNativeObjectDirect (VirtualFrame frame , Object self , Object [] varargs , PKeyword [] kwargs ,
1702
+ @ Cached TypeNodes .GetTypeFlagsNode getTypeFlagsNode ) {
1668
1703
checkExcessArgs (self , varargs , kwargs );
1704
+ if ((getTypeFlagsNode .execute (self ) & TypeFlags .IS_ABSTRACT ) != 0 ) {
1705
+ throw getReportAbstractClassNode ().execute (frame , self );
1706
+ }
1669
1707
return callNativeGenericNewNode (self , varargs , kwargs );
1670
1708
}
1671
1709
@@ -1750,6 +1788,14 @@ private void checkExcessArgs(Object type, Object[] varargs, PKeyword[] kwargs) {
1750
1788
}
1751
1789
}
1752
1790
}
1791
+
1792
+ private ReportAbstractClassNode getReportAbstractClassNode () {
1793
+ if (reportAbstractClassNode == null ) {
1794
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
1795
+ reportAbstractClassNode = insert (ReportAbstractClassNode .create ());
1796
+ }
1797
+ return reportAbstractClassNode ;
1798
+ }
1753
1799
}
1754
1800
1755
1801
// range(stop)
0 commit comments