-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathCodeFlag.java
More file actions
129 lines (114 loc) · 3.32 KB
/
Copy pathCodeFlag.java
File metadata and controls
129 lines (114 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package org.python.core;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
/**
* Represents flags that can be set on code objects.
*
* @author Tobias Ivarsson
*/
public enum CodeFlag {
/**
* Denotes that the code block uses fast locals.
*/
CO_OPTIMIZED(0x0001),
/**
* Denotes that a new dictionary should be created for the code block.
*/
CO_NEWLOCALS(0x0002),
/**
* The compiled code block has a varargs argument.
*/
CO_VARARGS(0x0004),
/**
* The compiled code block has a varkeyword argument.
*/
CO_VARKEYWORDS(0x0008),
/**
* The compiled code block is a generator code block.
*/
CO_GENERATOR(0x0020),
/**
* Denotes that nested scopes are enabled in the code block.
*/
CO_NESTED(0x0010),
/**
* The flag is set if there are no free or cell variables.
*/
CO_NOFREE(0x0040),
/**
* The CO_COROUTINE flag is set for coroutine functions (defined with
* ``async def`` keywords)
*/
CO_COROUTINE(0x0080),
CO_ITERABLE_COROUTINE(0x0100),
/**
* Denotes that generators are enabled in the code block.
* No longer used.
*/
CO_GENERATOR_ALLOWED(0x1000),
/**
* Standard division of integers returns float, truncating division needs to
* be enforced.
*/
CO_FUTURE_DIVISION(0x2000),
/**
* Absolute import.
*/
CO_FUTURE_ABSOLUTE_IMPORT(0x4000),
/**
* With statement.
*/
CO_FUTURE_WITH_STATEMENT(0x8000),
/**
* print function.
*/
CO_FUTURE_PRINT_FUNCTION(0x10000),
/**
* unicode literals.
*/
CO_FUTURE_UNICODE_LITERALS(0x20000),
CO_FUTURE_GENERATOR_STOP(0x80000);
public final int flag;
private static Iterable<CodeFlag> allFlags = Collections.unmodifiableList(Arrays.asList(values()));
private CodeFlag(int flag) {
this.flag = flag;
}
public boolean isFlagBitSetIn(int flags) {
return (flags & flag) != 0;
}
static Iterable<CodeFlag> parse(final int flags) {
return new Iterable<CodeFlag>() {
public Iterator<CodeFlag> iterator() {
return new Iterator<CodeFlag>() {
Iterator<CodeFlag> all = allFlags.iterator();
CodeFlag next = null;
public boolean hasNext() {
if (next != null) {
return true;
}
while (all.hasNext()) {
CodeFlag flag = all.next();
if (flag.isFlagBitSetIn(flags)) {
next = flag;
return true;
}
}
return false;
}
public CodeFlag next() {
if (hasNext()) try {
return next;
} finally {
next = null;
}
throw new IllegalStateException();
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
};
}
}