1919from .expr_util import *
2020from .symtab import *
2121from .messages import *
22- from .output import out
22+ from .output import *
2323from .types import *
2424from .set import Set
2525from .slotsmeta import auto_init
@@ -316,11 +316,13 @@ def __init__(self, func):
316316 assert func .method .independent
317317 self .func = func
318318 self .method = func .method
319+ # SimpleSite wrapper to avoid linemarks being generated.
320+ self .site = SimpleSite (self .method .site .loc ())
319321
320322 def make_ref (self , ref , typ ):
321323 indexing = '' .join ([f'[_idx{ i } ]'
322324 for i in range (self .method .dimensions )])
323- return mkLit (self .method . site , f'_memo{ indexing } .{ ref } ' , typ )
325+ return mkLit (self .site , f'_memo{ indexing } .{ ref } ' , typ )
324326
325327 def prelude (self ):
326328 struct_body = '' .join (
@@ -331,10 +333,10 @@ def prelude(self):
331333 + [(f'p_{ name } ' , typ ) for (name , typ ) in self .func .outp ]))
332334 array_defs = '' .join ([f'[{ i } ]' for i in self .method .dimsizes ])
333335 struct_var_def = mkInline (
334- self .method . site ,
336+ self .site ,
335337 f'static struct {{{ struct_body } }} _memo{ array_defs } ;' )
336338 return [struct_var_def ] + memoization_common_prelude (
337- self .method .logname_anonymized (), self .method . site , self .func .outp ,
339+ self .method .logname_anonymized (), self .site , self .func .outp ,
338340 self .func .throws , self .make_ref )
339341 def exit_handler (self ):
340342 return MemoizedReturnExit (self .method .site , self .func .outp ,
@@ -347,16 +349,18 @@ class SharedIndependentMemoized(Memoization):
347349 def __init__ (self , method ):
348350 assert method .independent
349351 self .method = method
352+ # SimpleSite wrapper to avoid linemarks being generated.
353+ self .site = SimpleSite (self .method .site .loc ())
350354 def make_ref (self , ref , typ ):
351355 traitname = cident (self .method .trait .name )
352- return mkLit (self .method . site ,
356+ return mkLit (self .site ,
353357 f'((struct _{ traitname } *) _{ traitname } .trait)'
354358 + f'->_memo_outs_{ self .method .name } '
355359 + f'[_{ traitname } .id.encoded_index].{ ref } ' , typ )
356360 def prelude (self ):
357361 return memoization_common_prelude (
358- self .method .name , self .method . site , self .method .outp ,
359- self .method . throws , self . make_ref )
362+ self .method .name , self .site , self .method .outp , self . method . throws ,
363+ self .make_ref )
360364 def exit_handler (self ):
361365 return MemoizedReturnExit (self .method .site , self .method .outp ,
362366 self .method .throws , self .make_ref )
@@ -1925,7 +1929,7 @@ def codegen_statement(tree, *args):
19251929
19261930@statement_dispatcher
19271931def stmt_compound (stmt , location , scope ):
1928- [stmt_asts ] = stmt .args
1932+ [stmt_asts , rbrace_site ] = stmt .args
19291933 if (logging .show_porting and stmt .site .dml_version () == (1 , 2 )
19301934 and not stmt .site .filename ().endswith ('dml-builtins.dml' )):
19311935 method = location .method ()
@@ -1942,7 +1946,8 @@ def stmt_compound(stmt, location, scope):
19421946 ret .site ))
19431947 lscope = Symtab (scope )
19441948 statements = codegen_statements (stmt_asts , location , lscope )
1945- return [mkCompound (stmt .site , declarations (lscope ) + statements )]
1949+ return [mkCompound (stmt .site , declarations (lscope ) + statements ,
1950+ rbrace_site )]
19461951
19471952def check_shadowing (scope , name , site ):
19481953 if (dml .globals .dml_version == (1 , 2 )
@@ -2197,7 +2202,7 @@ def stmt_null(stmt, location, scope):
21972202
21982203@statement_dispatcher
21992204def stmt_if (stmt , location , scope ):
2200- [cond_ast , truebranch , falsebranch ] = stmt .args
2205+ [cond_ast , truebranch , falsebranch , else_site ] = stmt .args
22012206 cond = as_bool (codegen_expression (cond_ast , location , scope ))
22022207 if cond .constant and stmt .site .dml_version () == (1 , 2 ):
22032208 if (logging .show_porting
@@ -2212,8 +2217,7 @@ def stmt_if(stmt, location, scope):
22122217 if errors :
22132218 report (PHASH (stmt .site ))
22142219 if falsebranch :
2215- report (PHASHELSE (dmlparse .end_site (truebranch .site ),
2216- 'else' ))
2220+ report (PHASHELSE (else_site , 'else' ))
22172221 if (not falsebranch and cond_ast .kind == 'binop'
22182222 and cond_ast .args [1 ] == '&&' ):
22192223 lh = as_bool (codegen_expression (cond_ast .args [0 ], location , scope ))
@@ -2234,7 +2238,7 @@ def stmt_if(stmt, location, scope):
22342238 fbranch = codegen_statement (falsebranch , location , scope )
22352239 else :
22362240 fbranch = None
2237- return [ctree .If (stmt .site , cond , tbranch , fbranch )]
2241+ return [ctree .If (stmt .site , cond , tbranch , fbranch , else_site )]
22382242
22392243@statement_dispatcher
22402244def stmt_hashif (stmt , location , scope ):
@@ -3219,7 +3223,7 @@ def stmt_switch(stmt, location, scope):
32193223 with CLoopContext ():
32203224 if stmt .site .dml_version () != (1 , 2 ):
32213225 assert body_ast .kind == 'compound'
3222- [stmt_asts ] = body_ast .args
3226+ [stmt_asts , rbrace_site ] = body_ast .args
32233227 stmts = codegen_statements (stmt_asts , location , scope )
32243228 if (not stmts
32253229 or not isinstance (stmts [0 ], (ctree .Case , ctree .Default ))):
@@ -3257,7 +3261,7 @@ def stmt_switch(stmt, location, scope):
32573261 body_stmts .append (mkSubsequentCases (
32583262 subsequent_cases [0 ].site , subsequent_cases , default_found ))
32593263
3260- body = ctree .Compound (body_ast .site , body_stmts )
3264+ body = ctree .Compound (body_ast .site , body_stmts , rbrace_site )
32613265 else :
32623266 body = codegen_statement (body_ast , location , scope )
32633267
@@ -3608,15 +3612,15 @@ def codegen_inline(site, meth_node, indices, inargs, outargs,
36083612 code , post )
36093613 else :
36103614 assert meth_node .astcode .kind == 'compound'
3611- [subs ] = meth_node .astcode .args
3615+ [subs , rbrace_site ] = meth_node .astcode .args
36123616 location = Location (meth_node , indices )
36133617 exit_handler = GotoExit_dml14 (outargs )
36143618 with exit_handler :
36153619 code = codegen_statements (subs , location , param_scope )
36163620 decls = declarations (param_scope )
36173621 post = ([mkLabel (site , exit_handler .label )]
36183622 if exit_handler .used else [])
3619- body = mkCompound (site , decls + code )
3623+ body = mkCompound (site , decls + code , rbrace_site )
36203624 if meth_node .outp and body .control_flow ().fallthrough :
36213625 report (ENORET (meth_node .astcode .site ))
36223626 return mkInlinedMethod (site , meth_node , decls , code , post )
@@ -3772,7 +3776,7 @@ def codegen_method_func(func):
37723776 method .parent , indices ,
37733777 [mkLit (method .site , n , t ) for (n , t ) in func .inp ],
37743778 [mkLit (method .site , "*%s" % n , t ) for (n , t ) in func .outp ],
3775- method .site )
3779+ SimpleSite ( method .site . loc ()) )
37763780 inline_scope = MethodParamScope (global_scope )
37773781 for (name , e ) in func .inp :
37783782 if dml .globals .dml_version == (1 , 2 ) and (
@@ -3894,10 +3898,8 @@ def prelude():
38943898 # manually deconstruct compound AST node, to make sure
38953899 # top-level locals share scope with parameters
38963900 assert ast .kind == 'compound'
3897- [subs ] = ast .args
3901+ [subs , _ ] = ast .args
38983902 with fail_handler , exit_handler :
3899- # TODO The linemarks for the prelude will point to the method
3900- # declaration, which is not optimal, but should be fine.
39013903 body = prelude ()
39023904 body .extend (codegen_statements (subs , location , fnscope ))
39033905 code = mkCompound (site , body )
@@ -3907,7 +3909,8 @@ def prelude():
39073909 else :
39083910 code = mkCompound (site ,
39093911 body + [codegen_exit (rbrace_site ,
3910- [])])
3912+ [])],
3913+ rbrace_site )
39113914 to_return = code
39123915 return to_return
39133916
0 commit comments