1313
1414from . import objects , crep , ctree , ast , int_register , logging , serialize
1515from . import dmlparse , output
16- from . import breaking_changes as compat
16+ from . import breaking_changes
1717from .logging import *
1818from .expr import *
1919from .ctree import *
@@ -1101,7 +1101,7 @@ def subast_has_dollar(expr_ast):
11011101@expression_dispatcher
11021102def expr_unop (tree , location , scope ):
11031103 [op , rh_ast ] = tree .args
1104- if (compat . dml12_misc in dml . globals . enabled_compat
1104+ if (not breaking_changes . dml12_remove_misc_quirks . enabled
11051105 and op == 'sizeof' and rh_ast .kind == 'variable_dml12' ):
11061106 var = rh_ast .args [0 ]
11071107 if var in typedefs and scope .lookup (var ) is None :
@@ -1142,7 +1142,7 @@ def expr_unop(tree, location, scope):
11421142 return ctree .AddressOfMethod (tree .site , func )
11431143 raise rh .exc ()
11441144 if op == '!' :
1145- if compat . dml12_not in dml . globals . enabled_compat :
1145+ if not breaking_changes . dml12_not_typecheck . enabled :
11461146 t = rh .ctype ()
11471147 if isinstance (safe_realtype (t ), TInt ) and subast_has_dollar (rh_ast ):
11481148 # A previous bug caused DMLC to permit expressions on
@@ -1164,7 +1164,7 @@ def expr_unop(tree, location, scope):
11641164 elif op == 'post++' : return mkPostInc (tree .site , rh )
11651165 elif op == 'post--' : return mkPostDec (tree .site , rh )
11661166 elif op == 'sizeof' :
1167- if (compat . dml12_misc not in dml . globals . enabled_compat
1167+ if (breaking_changes . dml12_remove_misc_quirks . enabled
11681168 and not rh .addressable ):
11691169 raise ERVAL (rh .site , 'sizeof' )
11701170 return codegen_sizeof (tree .site , rh )
@@ -1464,8 +1464,8 @@ def eval_type(asttype, site, location, scope, extern=False, typename=None,
14641464 (member_struct_defs , member_type ) = eval_type (
14651465 type_ast , msite , location , scope , extern )
14661466 if isinstance (member_type , TFunction ):
1467- if (compat . function_in_extern_struct
1468- in dml . globals . enabled_compat
1467+ if (not ( breaking_changes
1468+ . dml_forbid_function_in_extern_struct . enabled )
14691469 and extern ):
14701470 member_type = TPtr (member_type )
14711471 else :
@@ -1535,7 +1535,7 @@ def eval_type(asttype, site, location, scope, extern=False, typename=None,
15351535 else :
15361536 raise expr .exc ()
15371537 elif (not expr .addressable
1538- and compat . dml12_misc not in dml . globals . enabled_compat ):
1538+ and breaking_changes . dml12_remove_misc_quirks . enabled ):
15391539 raise ERVAL (expr .site , 'typeof' )
15401540 else :
15411541 etype = expr .ctype ().clone ()
@@ -1662,7 +1662,7 @@ def declaration(self):
16621662
16631663 def with_expr (self , expr ):
16641664 assert (self .typ is None
1665- or compat . dml12_inline in dml . globals . enabled_compat )
1665+ or not breaking_changes . dml12_disable_inline_constants . enabled )
16661666 return MethodInParam (self .site , self .ident , self .typ , expr )
16671667
16681668 def with_type (self , typ ):
@@ -2049,7 +2049,7 @@ def convert_decl(decl_ast):
20492049 name = ident_ast .args [0 ] if ident_ast .kind == 'variable' else None
20502050 if (name is not None
20512051 and dml .globals .dml_version == (1 , 2 )
2052- and compat . dml12_misc not in dml . globals . enabled_compat ):
2052+ and breaking_changes . dml12_remove_misc_quirks . enabled ):
20532053 check_varname (stmt .site , name )
20542054 (struct_decls , etype ) = eval_type (asttype , stmt .site , location , scope )
20552055 stmts .extend (mkStructDefinition (site , t ) for (site , t ) in struct_decls )
@@ -2679,7 +2679,7 @@ def stmt_assert(stmt, location, scope):
26792679@statement_dispatcher
26802680def stmt_goto (stmt , location , scope ):
26812681 [label ] = stmt .args
2682- if compat . dml12_goto not in dml . globals . enabled_compat :
2682+ if breaking_changes . dml12_remove_goto . enabled :
26832683 report (ESYNTAX (stmt .site , 'goto' , 'goto statement not allowed' ))
26842684 return [mkGoto (stmt .site , label )]
26852685
@@ -2773,11 +2773,11 @@ def stmt_log(stmt, location, scope):
27732773 and (not level .constant or level .value != 1 ))
27742774
27752775 # This correction must be done independently of
2776- # compat.meaningless_log_levels , otherwise existing usages of
2776+ # breaking_changes.dml_meaningless_log_levels , otherwise existing usages of
27772777 # e.g. log error, 2: "..." will become noops
27782778 if bad_error_level :
27792779 adjusted_level = mkIntegerLiteral (site , 1 )
2780- if compat . meaningless_log_levels not in dml . globals . enabled_compat :
2780+ if breaking_changes . dml_restrict_log_levels . enabled :
27812781 if bad_error_level :
27822782 report (ELLEV (level .site , "1" ))
27832783 elif level .constant and not (1 <= level .value <= 4 ):
@@ -2793,9 +2793,9 @@ def stmt_log(stmt, location, scope):
27932793 logobj = log_object (site , location .node , location .indices )
27942794 else :
27952795 identity = TraitObjIdentity (site , lookup_var (site , scope , "this" ))
2796- logobj = (log_object (site , dml . globals . device , () )
2797- if compat . shared_logs_on_device in dml . globals . enabled_compat
2798- else PortObjectFromObjIdentity (site , identity ))
2796+ logobj = (PortObjectFromObjIdentity (site , identity )
2797+ if breaking_changes . dml_shared_logs_locally . enabled
2798+ else log_object (site , dml . globals . device , () ))
27992799
28002800 log_wrapper = lambda stmt : stmt
28012801
@@ -2806,8 +2806,7 @@ def stmt_log(stmt, location, scope):
28062806 later_level .value == level .value ):
28072807 report (WREDUNDANTLEVEL (site ))
28082808 if (error_logkind
2809- and (compat .meaningless_log_levels
2810- not in dml .globals .enabled_compat )):
2809+ and breaking_changes .dml_restrict_log_levels .enabled ):
28112810 if not later_level .constant or later_level .value not in {1 , 5 }:
28122811 report (ELLEV (later_level .site , "a 1 or 5 constant" ))
28132812 adjusted_later_level = mkIntegerLiteral (site , 1 )
@@ -3225,7 +3224,7 @@ def stmt_select(stmt, location, scope):
32253224 if_chain = mkIf (cond .site , cond , stmt , if_chain )
32263225 return [if_chain ]
32273226 raise lst .exc ()
3228- elif (compat . dml12_misc in dml . globals . enabled_compat
3227+ elif (not breaking_changes . dml12_remove_misc_quirks . enabled
32293228 and isinstance (lst .ctype (), TVector )
32303229 and itername is not None ):
32313230 itervar = lookup_var (stmt .site , scope , itername )
@@ -3501,17 +3500,20 @@ def common_inline(site, method, indices, inargs, outargs):
35013500
35023501 if dml .globals .debuggable :
35033502 if method .fully_typed and (
3504- compat . dml12_inline not in dml . globals . enabled_compat
3503+ breaking_changes . dml12_disable_inline_constants . enabled
35053504 or all (not arg .constant for arg in inargs )):
35063505 # call method instead of inlining it
35073506 func = method_instance (method )
35083507 else :
35093508 # create a specialized method instance based on parameter
35103509 # types, and call that
35113510 intypes = tuple (
3512- arg if ((p .typ is None
3513- or compat .dml12_inline in dml .globals .enabled_compat )
3514- and (arg .constant or undefined (arg )))
3511+ arg if (
3512+ (p .typ is None
3513+ or not (
3514+ breaking_changes
3515+ .dml12_disable_inline_constants .enabled ))
3516+ and (arg .constant or undefined (arg )))
35153517 else methfunc_param (p .typ , arg )
35163518 for (p , arg ) in zip (method .inp , inargs ))
35173519 outtypes = tuple (methfunc_param (ptype , arg )
@@ -3763,7 +3765,8 @@ def codegen_inline(site, meth_node, indices, inargs, outargs,
37633765 param_scope .add (ExpressionSymbol (p .ident , arg , arg .site ))
37643766 elif arg .constant and (
37653767 p .inlined
3766- or compat .dml12_inline in dml .globals .enabled_compat ):
3768+ or not (breaking_changes
3769+ .dml12_disable_inline_constants .enabled )):
37673770 # Constants must be passed directly to
37683771 # provide constant folding. Other values are stored in a
37693772 # local variable to improve type checking and variable
@@ -3979,7 +3982,7 @@ def codegen_method_func(func):
39793982 e = p .expr
39803983 if (p .ident is not None
39813984 and dml .globals .dml_version == (1 , 2 )
3982- and compat . dml12_misc not in dml . globals . enabled_compat ):
3985+ and breaking_changes . dml12_remove_misc_quirks . enabled ):
39833986 check_varname (p .site , p .ident )
39843987 if e and p .ident is not None :
39853988 inlined_arg = (
@@ -4104,8 +4107,7 @@ def prelude():
41044107 with fail_handler , exit_handler :
41054108 body = ([mkIndicesAssert (site , location .node ,
41064109 location .indices )]
4107- if ((compat .no_method_index_asserts
4108- not in dml .globals .enabled_compat )
4110+ if (breaking_changes .dml_range_check_method_indices .enabled
41094111 and location .method () and location .node .dimsizes )
41104112 else [])
41114113 body .extend (prelude ())
@@ -4201,7 +4203,7 @@ def codegen_call(site, meth_node, indices, inargs, outargs):
42014203 if (site .dml_version () == (1 , 2 ) and logging .show_porting ):
42024204 report_pevent_data_arg (meth_node , site , inargs )
42034205
4204- if compat . dml12_misc in dml . globals . enabled_compat :
4206+ if not breaking_changes . dml12_remove_misc_quirks . enabled :
42054207 # For backward compatibility. See bug 21367.
42064208 inargs = [mkCast (site , arg , TPtr (TNamed ('char' )))
42074209 if isinstance (arg , StringConstant ) else arg
0 commit comments