예제 #1
0
    def translate_pat_Call_constructor(self, ctx, pat, scrutinee_trans):
        scrutinee_trans_copy = astx.copy_node(scrutinee_trans)
        args, keywords = pat.args, pat.keywords
        idx = self.idx
        conditions = []
        binding_translations = _util.odict()
        for i, arg in enumerate(args):
            n = _util.odict_idx_of(idx, i)
            elt_scrutinee_trans = astx.make_Subscript_Num_Index(
                scrutinee_trans_copy, n)
            elt_condition, elt_binding_translations = ctx.translate_pat(
                arg, elt_scrutinee_trans)
            conditions.append(elt_condition)
            binding_translations.update(elt_binding_translations)

        for keyword in keywords:
            n = _util.odict_idx_of(idx, keyword.arg)
            elt_scrutinee_trans = astx.make_Subscript_Num_Index(
                scrutinee_trans_copy, n)
            elt_condition, elt_binding_translations = ctx.translate_pat(
                keyword.value, elt_scrutinee_trans)
            conditions.append(elt_condition)
            binding_translations.update(elt_binding_translations)

        condition = ast.BoolOp(op=ast.And(), values=conditions)

        return (condition, binding_translations)
예제 #2
0
파일: _product.py 프로젝트: cyrus-/tydy
    def translate_pat_Call_constructor(self, ctx, pat, scrutinee_trans):
        scrutinee_trans_copy = astx.copy_node(scrutinee_trans)
        args, keywords = pat.args, pat.keywords
        idx = self.idx
        conditions = []
        binding_translations = _util.odict()
        for i, arg in enumerate(args):
            n = _util.odict_idx_of(idx, i)
            elt_scrutinee_trans = astx.make_Subscript_Num_Index(
                scrutinee_trans_copy,
                n)
            elt_condition, elt_binding_translations = ctx.translate_pat(
                arg, elt_scrutinee_trans)
            conditions.append(elt_condition)
            binding_translations.update(elt_binding_translations)
        
        for keyword in keywords:
            n = _util.odict_idx_of(idx, keyword.arg)
            elt_scrutinee_trans = astx.make_Subscript_Num_Index(
                scrutinee_trans_copy,
                n)
            elt_condition, elt_binding_translations = ctx.translate_pat(
                keyword.value, elt_scrutinee_trans)
            conditions.append(elt_condition)
            binding_translations.update(elt_binding_translations)

        condition = ast.BoolOp(
            op=ast.And(),
            values=conditions)

        return (condition, binding_translations)
예제 #3
0
파일: _product.py 프로젝트: cyrus-/tydy
 def translate_Attribute(self, ctx, e):
     n = _util.odict_idx_of(self.idx, e.attr)
     return ast.copy_location(ast.Subscript(
         value=ctx.translate(e.value),
         slice=ast.Num(n=n),
         ctx=ast.Load()
     ), e)
예제 #4
0
 def translate_Subscript(self, ctx, e):
     value = e.value
     label = e.slice.value.label
     n = _util.odict_idx_of(self.idx, label)
     return ast.copy_location(
         ast.Subscript(value=ctx.translate(value),
                       slice=ast.Num(n=n),
                       ctx=ast.Load()), e)
예제 #5
0
파일: _product.py 프로젝트: cyrus-/tydy
 def translate_Subscript(self, ctx, e):
     value = e.value 
     label = e.slice.value.label
     n = _util.odict_idx_of(self.idx, label)
     return ast.copy_location(ast.Subscript(
         value=ctx.translate(value),
         slice=ast.Num(n=n),
         ctx=ast.Load()
     ), e)
예제 #6
0
    def translate_Call_constructor(self, ctx, e):
        args, keywords = e.args, e.keywords
        idx = self.idx

        elt_translation = []
        idx_mapping = []
        for i, arg in enumerate(args):
            elt_translation.append(ctx.translate(arg))
            n = _util.odict_idx_of(idx, i)
            idx_mapping.append(n)
        for keyword in keywords:
            label = keyword.arg
            value = keyword.value
            elt_translation.append(ctx.translate(value))
            n = _util.odict_idx_of(idx, label)
            idx_mapping.append(n)
        arg_translation = ast.Tuple(elts=elt_translation)

        return ast.copy_location(
            _labeled_translation(idx_mapping, arg_translation), e)
예제 #7
0
파일: _product.py 프로젝트: cyrus-/tydy
    def translate_Call_constructor(self, ctx, e):
        args, keywords = e.args, e.keywords
        idx = self.idx

        elt_translation = []
        idx_mapping = []
        for i, arg in enumerate(args):
            elt_translation.append(ctx.translate(arg))
            n = _util.odict_idx_of(idx, i)
            idx_mapping.append(n)
        for keyword in keywords:
            label = keyword.arg
            value = keyword.value
            elt_translation.append(ctx.translate(value))
            n = _util.odict_idx_of(idx, label)
            idx_mapping.append(n)
        arg_translation = ast.Tuple(elts=elt_translation)

        return ast.copy_location(_labeled_translation(idx_mapping, 
                                                      arg_translation), 
                                 e)
예제 #8
0
    def translate_Dict(self, ctx, e):
        keys, values = e.keys, e.values
        idx = self.idx
        elt_translation = []
        idx_mapping = []
        for key, value in zip(keys, values):
            label = key.label
            elt_translation.append(ctx.translate(value))
            i = _util.odict_idx_of(idx, label)
            idx_mapping.append(i)
        arg_translation = ast.Tuple(elts=elt_translation)

        return ast.copy_location(
            _labeled_translation(idx_mapping, arg_translation), e)
예제 #9
0
파일: _product.py 프로젝트: cyrus-/tydy
    def translate_Dict(self, ctx, e):
        keys, values = e.keys, e.values
        idx = self.idx
        elt_translation = []
        idx_mapping = []
        for key, value in zip(keys, values):
            label = key.label
            elt_translation.append(ctx.translate(value))
            i = _util.odict_idx_of(idx, label)
            idx_mapping.append(i)
        arg_translation = ast.Tuple(elts=elt_translation)

        return ast.copy_location(
            _labeled_translation(idx_mapping, arg_translation), 
            e)
예제 #10
0
 def translate_pat_Dict(self, ctx, pat, scrutinee_trans):
     scrutinee_trans_copy = astx.copy_node(scrutinee_trans)
     keys, values = pat.keys, pat.values
     idx = self.idx
     conditions = []
     binding_translations = _util.odict()
     for key, value in zip(keys, values):
         label = key.label
         n = _util.odict_idx_of(idx, label)
         elt_scrutinee_trans = astx.make_Subscript_Num_Index(
             scrutinee_trans_copy, n)
         elt_condition, elt_binding_translations = ctx.translate_pat(
             value, elt_scrutinee_trans)
         conditions.append(elt_condition)
         binding_translations.update(elt_binding_translations)
     condition = ast.BoolOp(op=ast.And(), values=conditions)
     return (condition, binding_translations)
예제 #11
0
파일: _product.py 프로젝트: cyrus-/tydy
 def translate_pat_Dict(self, ctx, pat, scrutinee_trans):
     scrutinee_trans_copy = astx.copy_node(scrutinee_trans)
     keys, values = pat.keys, pat.values
     idx = self.idx
     conditions = []
     binding_translations = _util.odict()
     for key, value in zip(keys, values):
         label = key.label
         n = _util.odict_idx_of(idx, label)
         elt_scrutinee_trans = astx.make_Subscript_Num_Index(
             scrutinee_trans_copy,
             n)
         elt_condition, elt_binding_translations = ctx.translate_pat(
             value, elt_scrutinee_trans)
         conditions.append(elt_condition)
         binding_translations.update(elt_binding_translations)
     condition = ast.BoolOp(
         op=ast.And(),
         values=conditions)
     return (condition, binding_translations)
예제 #12
0
 def translate_Attribute(self, ctx, e):
     n = _util.odict_idx_of(self.idx, e.attr)
     return ast.copy_location(
         ast.Subscript(value=ctx.translate(e.value),
                       slice=ast.Num(n=n),
                       ctx=ast.Load()), e)