6666import static com .oracle .graal .python .nodes .ErrorMessages .TAKES_EXACTLY_D_ARGUMENTS_D_GIVEN ;
6767import static com .oracle .graal .python .nodes .PGuards .isInteger ;
6868import static com .oracle .graal .python .nodes .PGuards .isNoValue ;
69+ import static com .oracle .graal .python .nodes .SpecialAttributeNames .__ABSTRACTMETHODS__ ;
6970import static com .oracle .graal .python .nodes .SpecialAttributeNames .__BASICSIZE__ ;
7071import static com .oracle .graal .python .nodes .SpecialAttributeNames .__CLASSCELL__ ;
7172import static com .oracle .graal .python .nodes .SpecialAttributeNames .__DICTOFFSET__ ;
180181import com .oracle .graal .python .builtins .objects .type .PythonBuiltinClass ;
181182import com .oracle .graal .python .builtins .objects .type .PythonClass ;
182183import com .oracle .graal .python .builtins .objects .type .PythonManagedClass ;
184+ import com .oracle .graal .python .builtins .objects .type .TypeFlags ;
183185import com .oracle .graal .python .builtins .objects .type .TypeNodes ;
184186import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetBestBaseClassNode ;
185187import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetItemsizeNode ;
190192import com .oracle .graal .python .nodes .BuiltinNames ;
191193import com .oracle .graal .python .nodes .ErrorMessages ;
192194import com .oracle .graal .python .nodes .PGuards ;
195+ import com .oracle .graal .python .nodes .PNodeWithContext ;
196+ import com .oracle .graal .python .nodes .PRaiseNode ;
193197import com .oracle .graal .python .nodes .SpecialAttributeNames ;
194198import com .oracle .graal .python .nodes .SpecialMethodNames ;
195199import com .oracle .graal .python .nodes .attributes .GetAttributeNode ;
199203import com .oracle .graal .python .nodes .attributes .ReadAttributeFromObjectNode ;
200204import com .oracle .graal .python .nodes .attributes .SetAttributeNode ;
201205import com .oracle .graal .python .nodes .attributes .WriteAttributeToObjectNode ;
206+ import com .oracle .graal .python .nodes .builtins .ListNodes ;
202207import com .oracle .graal .python .nodes .builtins .TupleNodes ;
203208import com .oracle .graal .python .nodes .call .CallNode ;
204209import com .oracle .graal .python .nodes .call .special .LookupAndCallTernaryNode ;
@@ -1629,11 +1634,34 @@ public abstract static class ObjectNode extends PythonVarargsBuiltinNode {
16291634 @ Child private SplitArgsNode splitArgsNode ;
16301635 @ Child private LookupAttributeInMRONode lookupInit ;
16311636 @ Child private LookupAttributeInMRONode lookupNew ;
1637+ @ Child private ReportAbstractClassNode reportAbstractClassNode ;
16321638 @ CompilationFinal private ValueProfile profileInit ;
16331639 @ CompilationFinal private ValueProfile profileNew ;
16341640 @ CompilationFinal private ValueProfile profileInitFactory ;
16351641 @ CompilationFinal private ValueProfile profileNewFactory ;
16361642
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+
16371665 @ Override
16381666 public final Object varArgExecute (VirtualFrame frame , @ SuppressWarnings ("unused" ) Object self , Object [] arguments , PKeyword [] keywords ) throws VarargsBuiltinDirectInvocationNotSupported {
16391667 if (splitArgsNode == null ) {
@@ -1644,8 +1672,11 @@ public final Object varArgExecute(VirtualFrame frame, @SuppressWarnings("unused"
16441672 }
16451673
16461674 @ Specialization (guards = {"!self.needsNativeAllocation()" })
1647- Object doManagedObject (PythonManagedClass self , Object [] varargs , PKeyword [] kwargs ) {
1675+ Object doManagedObject (VirtualFrame frame , PythonManagedClass self , Object [] varargs , PKeyword [] kwargs ) {
16481676 checkExcessArgs (self , varargs , kwargs );
1677+ if (self .isAbstractClass ()) {
1678+ throw getReportAbstractClassNode ().execute (frame , self );
1679+ }
16491680 return factory ().createPythonObject (self );
16501681 }
16511682
@@ -1656,16 +1687,23 @@ Object doBuiltinTypeType(PythonBuiltinClassType self, Object[] varargs, PKeyword
16561687 }
16571688
16581689 @ Specialization (guards = "self.needsNativeAllocation()" )
1659- Object doNativeObjectIndirect (PythonManagedClass self , Object [] varargs , PKeyword [] kwargs ,
1690+ Object doNativeObjectIndirect (VirtualFrame frame , PythonManagedClass self , Object [] varargs , PKeyword [] kwargs ,
16601691 @ Cached ("create()" ) GetMroNode getMroNode ) {
16611692 checkExcessArgs (self , varargs , kwargs );
1693+ if (self .isAbstractClass ()) {
1694+ throw getReportAbstractClassNode ().execute (frame , self );
1695+ }
16621696 Object nativeBaseClass = findFirstNativeBaseClass (getMroNode .execute (self ));
16631697 return callNativeGenericNewNode (nativeBaseClass , varargs , kwargs );
16641698 }
16651699
16661700 @ 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 ) {
16681703 checkExcessArgs (self , varargs , kwargs );
1704+ if ((getTypeFlagsNode .execute (self ) & TypeFlags .IS_ABSTRACT ) != 0 ) {
1705+ throw getReportAbstractClassNode ().execute (frame , self );
1706+ }
16691707 return callNativeGenericNewNode (self , varargs , kwargs );
16701708 }
16711709
@@ -1750,6 +1788,14 @@ private void checkExcessArgs(Object type, Object[] varargs, PKeyword[] kwargs) {
17501788 }
17511789 }
17521790 }
1791+
1792+ private ReportAbstractClassNode getReportAbstractClassNode () {
1793+ if (reportAbstractClassNode == null ) {
1794+ CompilerDirectives .transferToInterpreterAndInvalidate ();
1795+ reportAbstractClassNode = insert (ReportAbstractClassNode .create ());
1796+ }
1797+ return reportAbstractClassNode ;
1798+ }
17531799 }
17541800
17551801 // range(stop)
0 commit comments