Skip to content

Commit 1db1253

Browse files
committed
added __NAME__, __QUALNAME__, __OBJCLASS__ to GetSetDescriptor
1 parent 2a998e6 commit 1db1253

File tree

1 file changed

+54
-4
lines changed

1 file changed

+54
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/getsetdescriptor/GetSetDescriptorTypeBuiltins.java

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262
import com.oracle.graal.python.nodes.PGuards;
6363
import com.oracle.graal.python.nodes.PNodeWithContext;
6464
import com.oracle.graal.python.nodes.PRaiseNode;
65+
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__NAME__;
66+
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__QUALNAME__;
67+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__OBJCLASS__;
68+
import com.oracle.graal.python.nodes.attributes.GetAttributeNode.GetFixedAttributeNode;
6569
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
6670
import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
6771
import com.oracle.graal.python.nodes.call.special.CallBinaryMethodNode;
@@ -96,13 +100,59 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
96100
@GenerateNodeFactory
97101
abstract static class GetSetReprNode extends PythonUnaryBuiltinNode {
98102
@Specialization
99-
Object repr(GetSetDescriptor descr) {
100-
return PythonUtils.format("<attribute '%s' of '%s' objects>", descr.getName(), GetNameNode.doSlowPath(descr.getType()));
103+
Object repr(GetSetDescriptor descr,
104+
@Cached GetNameNode getName) {
105+
return PythonUtils.format("<attribute '%s' of '%s' objects>", descr.getName(), getName.execute(descr.getType()));
101106
}
102107

103108
@Specialization
104-
Object repr(HiddenKeyDescriptor descr) {
105-
return PythonUtils.format("<attribute '%s' of '%s' objects>", descr.getKey(), GetNameNode.doSlowPath(descr.getType()));
109+
Object repr(HiddenKeyDescriptor descr,
110+
@Cached GetNameNode getName) {
111+
return PythonUtils.format("<attribute '%s' of '%s' objects>", descr.getKey(), getName.execute(descr.getType()));
112+
}
113+
}
114+
115+
@Builtin(name = __OBJCLASS__, minNumOfPositionalArgs = 1, isGetter = true)
116+
@GenerateNodeFactory
117+
public abstract static class ObjclassNode extends PythonUnaryBuiltinNode {
118+
@Specialization
119+
Object objclass(GetSetDescriptor self) {
120+
return self;
121+
}
122+
123+
@Specialization
124+
Object objclass(HiddenKeyDescriptor self) {
125+
return self;
126+
}
127+
}
128+
129+
@Builtin(name = __QUALNAME__, minNumOfPositionalArgs = 1, isGetter = true)
130+
@GenerateNodeFactory
131+
public abstract static class QualnameNode extends PythonUnaryBuiltinNode {
132+
@Specialization
133+
Object qualname(VirtualFrame frame, GetSetDescriptor self,
134+
@Cached("create(__QUALNAME__)") GetFixedAttributeNode readQualNameNode) {
135+
return PythonUtils.format("%s.%s", readQualNameNode.executeObject(frame, self.getType()), self.getName());
136+
}
137+
138+
@Specialization
139+
Object qualname(VirtualFrame frame, HiddenKeyDescriptor self,
140+
@Cached("create(__QUALNAME__)") GetFixedAttributeNode readQualNameNode) {
141+
return PythonUtils.format("%s.%s", readQualNameNode.executeObject(frame, self.getType()), self.getKey().getName());
142+
}
143+
}
144+
145+
@Builtin(name = __NAME__, minNumOfPositionalArgs = 1, isGetter = true)
146+
@GenerateNodeFactory
147+
public abstract static class NameNode extends PythonUnaryBuiltinNode {
148+
@Specialization
149+
Object qualname(GetSetDescriptor self) {
150+
return self.getName();
151+
}
152+
153+
@Specialization
154+
Object qualname(HiddenKeyDescriptor self) {
155+
return self.getKey().getName();
106156
}
107157
}
108158

0 commit comments

Comments
 (0)