Skip to content

Commit 30a5e71

Browse files
authored
Merge pull request #289 from boriel/bugfix/const_crash
Fix a crash in some const cases
2 parents ddc0ff8 + 3374bde commit 30a5e71

5 files changed

Lines changed: 763 additions & 3 deletions

File tree

api/optimize.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import types
1313
from api.debug import __DEBUG__
1414
from api.errmsg import warning_not_used
15+
import api.utils
1516

1617

1718
class ToVisit(object):
@@ -110,7 +111,8 @@ def visit_CHR(self, node):
110111
node = (yield self.generic_visit(node))
111112

112113
if all(chk.is_static(arg.value) for arg in node.operand):
113-
yield symbols.STRING(''.join(chr(x.value.value & 0xFF) for x in node.operand), node.lineno)
114+
yield symbols.STRING(''.join(
115+
chr(api.utils.get_final_value(x.value) & 0xFF) for x in node.operand), node.lineno)
114116
else:
115117
yield node
116118

api/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
from . import constants
88
from . import global_
99
from . import errmsg
10+
from . import check
11+
12+
import symbols
1013

1114

1215
__all__ = ['read_txt_file', 'open_file', 'sanitize_filename', 'flatten_list']
@@ -118,3 +121,12 @@ def save_object(key, obj):
118121

119122
def get_or_create(key, fn):
120123
return load_object(key) or save_object(key, fn())
124+
125+
126+
def get_final_value(symbol: symbols.SYMBOL):
127+
assert check.is_static(symbol)
128+
result = symbol
129+
while hasattr(result, 'value'):
130+
result = result.value
131+
132+
return result

symbols/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# ----------------------------------------------------------------------
1111

1212
# ---- AST Symbols ----
13+
from .symbol_ import Symbol as SYMBOL
1314
from .arglist import SymbolARGLIST as ARGLIST
1415
from .argument import SymbolARGUMENT as ARGUMENT
1516
from .arrayaccess import SymbolARRAYACCESS as ARRAYACCESS
@@ -51,6 +52,7 @@
5152
'ARRAYDECL',
5253
'ARRAYLOAD',
5354
'ASM',
55+
'BASICTYPE',
5456
'BINARY',
5557
'BLOCK',
5658
'BOUND',
@@ -61,20 +63,20 @@
6163
'FUNCCALL',
6264
'FUNCDECL',
6365
'FUNCTION',
66+
'LABEL',
6467
'NOP',
6568
'NUMBER',
6669
'PARAMDECL',
6770
'PARAMLIST',
6871
'SENTENCE',
6972
'STRING',
7073
'STRSLICE',
71-
'BASICTYPE',
74+
'SYMBOL',
7275
'TYPE',
7376
'TYPEREF',
7477
'TYPECAST',
7578
'UNARY',
7679
'VAR',
7780
'VARARRAY',
7881
'VARDECL',
79-
'LABEL',
8082
]

0 commit comments

Comments
 (0)