Exemple #1
0
 def _create_is_same_expr(self, lhs: ir.Expr, rhs: ir.Expr):
     return ir.ClassMemberAccess(inner_expr=ir.TemplateInstantiation(
         template_expr=GlobalLiterals.STD_IS_SAME,
         args=(lhs, rhs),
         instantiation_might_trigger_static_asserts=False),
                                 expr_type=ir.BoolType(),
                                 member_name='value')
Exemple #2
0
    def transform_comparison_expr(self,
                                  comparison: ir.ComparisonExpr) -> ir.Expr:
        lhs = comparison.lhs
        rhs = comparison.rhs
        op = comparison.op

        lhs = self.transform_expr(lhs)
        rhs = self.transform_expr(rhs)

        if isinstance(lhs, ir.Literal) and isinstance(rhs, ir.Literal):
            if op == '==':
                return ir.Literal(lhs.value == rhs.value)
            if op == '!=':
                return ir.Literal(lhs.value != rhs.value)
            if op == '<':
                return ir.Literal(lhs.value < rhs.value)
            if op == '<=':
                return ir.Literal(lhs.value <= rhs.value)
            if op == '>':
                return ir.Literal(lhs.value > rhs.value)
            if op == '>=':
                return ir.Literal(lhs.value >= rhs.value)

        if op in ('==', '!=') and self._is_syntactically_equal(
                lhs, rhs) and not expr_can_trigger_static_asserts(lhs):
            if self._can_remove_subexpression(
                    lhs) and self._can_remove_subexpression(rhs):
                return {
                    '==': ir.Literal(True),
                    '!=': ir.Literal(False),
                }[op]

        if op in ('==', '!=') and isinstance(
                rhs, ir.Literal) and rhs.expr_type == ir.BoolType():
            rhs, lhs = lhs, rhs

        if op in ('==', '!=') and isinstance(
                lhs, ir.Literal) and lhs.expr_type == ir.BoolType():
            return {
                ('==', True): lambda: rhs,
                ('==', False): lambda: self.transform_expr(ir.NotExpr(rhs)),
                ('!=', True): lambda: self.transform_expr(ir.NotExpr(rhs)),
                ('!=', False): lambda: rhs,
            }[(op, lhs.value)]()

        return ir.ComparisonExpr(lhs, rhs, op)
Exemple #3
0
def _variadic_bool_arg_decl(name: str):
    return ir.TemplateArgDecl(expr_type=ir.BoolType(),
                              name=name,
                              is_variadic=True)
Exemple #4
0
def _variadic_bool_arg_type():
    return ir.TemplateArgType(expr_type=ir.BoolType(), is_variadic=True)
from _py2tmp.ir0 import ir
from _py2tmp.ir0 import select1st_literal
from _py2tmp.ir0_optimization._configuration_knobs import ConfigurationKnobs
from _py2tmp.ir0 import NameReplacementTransformation, ToplevelWriter, Transformation, \
    TemplateBodyWriter
from _py2tmp.ir0_optimization._compute_non_expanded_variadic_vars import compute_non_expanded_variadic_vars
from _py2tmp.ir0_optimization._local_optimizations import perform_local_optimizations_on_template_defn, \
    perform_local_optimizations_on_toplevel_elems
from _py2tmp.ir0_optimization._optimization_execution import apply_elem_optimization, describe_template_defns, \
    describe_toplevel_elems
from _py2tmp.ir0_optimization._replace_var_with_expr import replace_var_with_expr_in_template_body_elements, \
    VariadicVarReplacementNotPossibleException, replace_var_with_expr_in_expr
from _py2tmp.ir0_optimization._unify import unify_template_instantiation_with_definition

_select1st_type_and_name = [
    (ir.BoolType(), 'Bool'),
    (ir.Int64Type(), 'Int64'),
    (ir.TypeType(), 'Type'),
]

TEMPLATE_DEFNS_DEFINED_AS_IR0 = [
    ir.TemplateDefn(
        name='std::is_same',
        description='',
        result_element_names=['value'],
        args=[
            ir.TemplateArgDecl(
                name='T', expr_type=ir.TypeType(), is_variadic=False),
            ir.TemplateArgDecl(
                name='U', expr_type=ir.TypeType(), is_variadic=False)
        ],