Skip to content

Commit 001d02f

Browse files
committed
Remove MethodsFlags
1 parent 4331530 commit 001d02f

File tree

15 files changed

+73
-1050
lines changed

15 files changed

+73
-1050
lines changed

graalpython/com.oracle.graal.python.cext/src/capi.c

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -374,86 +374,6 @@ int is_builtin_type(PyTypeObject *tp) {
374374
#undef PY_TRUFFLE_TYPE_UNIMPLEMENTED
375375
}
376376

377-
PyAPI_FUNC(int64_t) get_methods_flags(PyTypeObject *cls) {
378-
if (cls == NULL) {
379-
return 0;
380-
}
381-
382-
int64_t flags = 0;
383-
PyNumberMethods* number = cls->tp_as_number;
384-
if (number != NULL) {
385-
#define COMPUTE_FLAGS(NAME, BIT_IDX) flags |= ((number->NAME != NULL) * BIT_IDX);
386-
COMPUTE_FLAGS(nb_subtract, NB_SUBTRACT)
387-
COMPUTE_FLAGS(nb_multiply, NB_MULTIPLY)
388-
COMPUTE_FLAGS(nb_remainder, NB_REMAINDER)
389-
COMPUTE_FLAGS(nb_divmod, NB_DIVMOD)
390-
COMPUTE_FLAGS(nb_power, NB_POWER)
391-
COMPUTE_FLAGS(nb_negative, NB_NEGATIVE)
392-
COMPUTE_FLAGS(nb_positive, NB_POSITIVE)
393-
COMPUTE_FLAGS(nb_absolute, NB_ABSOLUTE)
394-
COMPUTE_FLAGS(nb_bool, NB_BOOL)
395-
COMPUTE_FLAGS(nb_invert, NB_INVERT)
396-
COMPUTE_FLAGS(nb_lshift, NB_LSHIFT)
397-
COMPUTE_FLAGS(nb_rshift, NB_RSHIFT)
398-
COMPUTE_FLAGS(nb_and, NB_AND)
399-
COMPUTE_FLAGS(nb_xor, NB_XOR)
400-
COMPUTE_FLAGS(nb_or, NB_OR)
401-
COMPUTE_FLAGS(nb_int, NB_INT)
402-
COMPUTE_FLAGS(nb_float, NB_FLOAT)
403-
COMPUTE_FLAGS(nb_inplace_add, NB_INPLACE_ADD)
404-
COMPUTE_FLAGS(nb_inplace_subtract, NB_INPLACE_SUBTRACT)
405-
COMPUTE_FLAGS(nb_inplace_multiply, NB_INPLACE_MULTIPLY)
406-
COMPUTE_FLAGS(nb_inplace_remainder, NB_INPLACE_REMAINDER)
407-
COMPUTE_FLAGS(nb_inplace_power, NB_INPLACE_POWER)
408-
COMPUTE_FLAGS(nb_inplace_lshift, NB_INPLACE_LSHIFT)
409-
COMPUTE_FLAGS(nb_inplace_rshift, NB_INPLACE_RSHIFT)
410-
COMPUTE_FLAGS(nb_inplace_and, NB_INPLACE_AND)
411-
COMPUTE_FLAGS(nb_inplace_xor, NB_INPLACE_XOR)
412-
COMPUTE_FLAGS(nb_inplace_or, NB_INPLACE_OR)
413-
COMPUTE_FLAGS(nb_floor_divide, NB_FLOOR_DIVIDE)
414-
COMPUTE_FLAGS(nb_true_divide, NB_TRUE_DIVIDE)
415-
COMPUTE_FLAGS(nb_inplace_floor_divide, NB_INPLACE_FLOOR_DIVIDE)
416-
COMPUTE_FLAGS(nb_inplace_true_divide, NB_INPLACE_TRUE_DIVIDE)
417-
COMPUTE_FLAGS(nb_index, NB_INDEX)
418-
COMPUTE_FLAGS(nb_matrix_multiply, NB_MATRIX_MULTIPLY)
419-
COMPUTE_FLAGS(nb_inplace_matrix_multiply, NB_INPLACE_MATRIX_MULTIPLY)
420-
#undef COMPUTE_FLAGS
421-
}
422-
423-
PySequenceMethods *sequence = cls->tp_as_sequence;
424-
if (sequence != NULL) {
425-
#define COMPUTE_FLAGS(NAME, BIT_IDX) flags |= ((sequence->NAME != NULL) * BIT_IDX);
426-
COMPUTE_FLAGS(sq_length, SQ_LENGTH)
427-
COMPUTE_FLAGS(sq_repeat, SQ_REPEAT)
428-
COMPUTE_FLAGS(sq_item, SQ_ITEM)
429-
COMPUTE_FLAGS(sq_ass_item, SQ_ASS_ITEM)
430-
COMPUTE_FLAGS(sq_contains, SQ_CONTAINS)
431-
COMPUTE_FLAGS(sq_inplace_concat, SQ_INPLACE_CONCAT)
432-
COMPUTE_FLAGS(sq_inplace_repeat, SQ_INPLACE_REPEAT)
433-
#undef COMPUTE_FLAGS
434-
}
435-
436-
PyMappingMethods *mapping = cls->tp_as_mapping;
437-
if (mapping != NULL) {
438-
#define COMPUTE_FLAGS(NAME, BIT_IDX) flags |= ((mapping->NAME != NULL) * BIT_IDX);
439-
COMPUTE_FLAGS(mp_length, MP_LENGTH)
440-
COMPUTE_FLAGS(mp_subscript, MP_SUBSCRIPT)
441-
COMPUTE_FLAGS(mp_ass_subscript, MP_ASS_SUBSCRIPT)
442-
#undef COMPUTE_FLAGS
443-
}
444-
445-
PyAsyncMethods *async = cls->tp_as_async;
446-
if (async != NULL) {
447-
#define COMPUTE_FLAGS(NAME, BIT_IDX) flags |= ((async->NAME != NULL) * BIT_IDX);
448-
COMPUTE_FLAGS(am_await, AM_AWAIT)
449-
COMPUTE_FLAGS(am_aiter, AM_AITER)
450-
COMPUTE_FLAGS(am_anext, AM_ANEXT)
451-
COMPUTE_FLAGS(am_send, AM_SEND)
452-
#undef COMPUTE_FLAGS
453-
}
454-
return flags;
455-
}
456-
457377
// not quite as in CPython, this assumes that x is already a double. The rest of
458378
// the implementation is in the Float constructor in Java
459379
PyAPI_FUNC(PyObject*) float_subtype_new(PyTypeObject *type, double x) {

graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/CApiBuiltinsProcessor.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
import javax.lang.model.type.DeclaredType;
7070
import javax.lang.model.type.TypeMirror;
7171
import javax.lang.model.util.AbstractAnnotationValueVisitor14;
72-
import javax.lang.model.util.ElementFilter;
7372
import javax.tools.Diagnostic.Kind;
7473
import javax.tools.StandardLocation;
7574

@@ -561,10 +560,8 @@ private void updateResource(String name, List<CApiBuiltinDesc> javaBuiltins, Lis
561560
/**
562561
* Generates the builtin specification in capi.h, which includes only the builtins implemented
563562
* in Java code. Additionally, it generates helpers for all "Py_get_" and "Py_set_" builtins.
564-
*
565-
* @param methodFlags
566563
*/
567-
private void generateCApiHeader(List<CApiBuiltinDesc> javaBuiltins, Map<String, Long> methodFlags) throws IOException {
564+
private void generateCApiHeader(List<CApiBuiltinDesc> javaBuiltins) throws IOException {
568565
List<String> lines = new ArrayList<>();
569566
lines.add("#define CAPI_BUILTINS \\");
570567
int id = 0;
@@ -603,12 +600,6 @@ private void generateCApiHeader(List<CApiBuiltinDesc> javaBuiltins, Map<String,
603600
}
604601
}
605602

606-
/*
607-
* Adding constants for methods flags checks in {@link
608-
* NativeCAPISymbol.FUN_GET_METHODS_FLAGS}
609-
*/
610-
lines.add("");
611-
methodFlags.entrySet().stream().sorted((a, b) -> a.getValue().compareTo(b.getValue())).forEach(e -> lines.add("#define " + e.getKey() + " " + e.getValue()));
612603
updateResource("capi.gen.h", javaBuiltins, lines);
613604
}
614605

@@ -862,21 +853,13 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
862853
List<String> constants = new ArrayList<>();
863854
List<String> fields = new ArrayList<>();
864855
List<String> structs = new ArrayList<>();
865-
Map<String, Long> methodFlags = new HashMap<>();
866856
for (var el : re.getElementsAnnotatedWith(CApiConstants.class)) {
867857
if (el.getKind() == ElementKind.ENUM) {
868858
for (var enumBit : el.getEnclosedElements()) {
869859
if (enumBit.getKind() == ElementKind.ENUM_CONSTANT) {
870860
constants.add(enumBit.getSimpleName().toString());
871861
}
872862
}
873-
} else if (el.getKind() == ElementKind.CLASS) {
874-
for (VariableElement field : ElementFilter.fieldsIn(el.getEnclosedElements())) {
875-
Object constantValue = field.getConstantValue();
876-
if (constantValue instanceof Long longValue) {
877-
methodFlags.put(field.getSimpleName().toString(), longValue);
878-
}
879-
}
880863
} else {
881864
processingEnv.getMessager().printError(CApiConstants.class.getSimpleName() + " is only applicable for enums.", el);
882865
}
@@ -911,7 +894,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
911894
if (trees != null) {
912895
// needs jdk.compiler
913896
generateCApiSource(allBuiltins, constants, fields, structs);
914-
generateCApiHeader(javaBuiltins, methodFlags);
897+
generateCApiHeader(javaBuiltins);
915898
}
916899
generateBuiltinRegistry(javaBuiltins);
917900
generateCApiAsserts(allBuiltins);

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/MethodFlagsTest.java

Lines changed: 0 additions & 129 deletions
This file was deleted.

0 commit comments

Comments
 (0)