-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconst.py
105 lines (98 loc) · 3.18 KB
/
const.py
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
# pyc2py - The smart python decompiler.
# Copyright (C) 2012 Centre National de la Recherche Scientifique
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Developper: Etienne Duble
# Contact me at: etienne _dot_ duble _at_ imag _dot_ fr
# kinds of indexes used to point to the
# next instruction
# values must reflect the order of clauses:
# IF_CLAUSE < ELSE_CLAUSE < END_OF_CONSTRUCT
# FOR_CLAUSE < END_OF_CONSTRUCT
NORMAL_FLOW = -1
IF_CLAUSE = 10
ELSE_CLAUSE = 11
TRY_CLAUSE = 12
EXCEPT_EXPRESSION_CLAUSE = 13
EXCEPT_CLAUSE = 14
FINALLY_CLAUSE = 15
FOR_CLAUSE = 16
WHILE_CLAUSE = 17
END_OF_CONSTRUCT = 18 # end of 'if', 'for', 'try' constructs
# constants used when we want to specify that an action
# must be performed in any clause, none of the clauses
# of a given construct, the 'FORWARD' or the 'JUMP 'clause only.
# The FORWARD and JUMP clauses are different depending on the
# construct (while or if-then-else) and the conditional jump
# used.
#
# (values must be different from the values of clauses above)
NO_CLAUSE = 0
ANY_CLAUSE = 1
FORWARD_CLAUSE = 2
JUMP_CLAUSE = 3
# constants needed to specify if a statement is complete
# or not, or 'candidate'.
# For example if we have a function call, f(), this is a
# candidate statement, because:
# - "f()" is a valid statement itself
# - but "g(f())" or "a = f()" are valid statements also
PARTIAL_STATEMENT = 0
COMPLETE_STATEMENT = 1
CANDIDATE_STATEMENT = 2
# data about branches and jumps
BRANCH_IS_OPTIONAL = {
IF_CLAUSE: False,
ELSE_CLAUSE: True,
TRY_CLAUSE: False,
EXCEPT_CLAUSE: False,
FINALLY_CLAUSE: True,
FOR_CLAUSE: False,
WHILE_CLAUSE: False,
EXCEPT_EXPRESSION_CLAUSE: True
}
CONDITIONAL_JUMPS_DESC = {
'JUMP_IF_TRUE' : { # python 2.6
'jump_cond' : True,
'pop_cond' : NO_CLAUSE,
'relative' : True
},
'JUMP_IF_FALSE' : { # python 2.6
'jump_cond' : False,
'pop_cond' : NO_CLAUSE,
'relative' : True
},
'POP_JUMP_IF_TRUE' : { # python 2.7
'jump_cond' : True,
'pop_cond' : ANY_CLAUSE,
'relative' : False
},
'POP_JUMP_IF_FALSE' : { # python 2.7
'jump_cond' : False,
'pop_cond' : ANY_CLAUSE,
'relative' : False
},
'JUMP_IF_TRUE_OR_POP' : { # python 2.7
'jump_cond' : True,
'pop_cond' : FORWARD_CLAUSE,
'relative' : False
},
'JUMP_IF_FALSE_OR_POP' : { # python 2.7
'jump_cond' : False,
'pop_cond' : FORWARD_CLAUSE,
'relative' : False
}
}
CONDITIONAL_JUMPS = CONDITIONAL_JUMPS_DESC.keys()