コード例 #1
0
def new_set(
    *,
    stype: s_types.Type,
    ctx: context.ContextLevel,
    ircls: Type[irast.Set] = irast.Set,
    **kwargs: Any,
) -> irast.Set:
    """Create a new ir.Set instance with given attributes.

    Absolutely all ir.Set instances must be created using this
    constructor.
    """
    if (stype not in ctx.type_rewrites
            and isinstance(stype, s_objtypes.ObjectType)
            and ctx.env.options.apply_query_rewrites
            and (filters := stype.get_access_policy_filters(ctx.env.schema))):
        qry = qlast.SelectQuery(result=qlast.Path(
            steps=[s_utils.name_to_ast_ref(stype.get_name(ctx.env.schema))]), )
        for f in filters:
            assert isinstance(f.qlast, qlast.Expr)
            qry.where = astutils.extend_binop(qry.where, f.qlast)

        with ctx.detached() as subctx:
            subctx.expr_exposed = False
            # This is a global rewrite operation that is done once
            # per type, and so we don't really care if we're in a
            # temporary scope or not.
            subctx.path_scope = subctx.env.path_scope.root
            subctx.in_temp_scope = False
            # Put a placeholder to prevent recursion.
            subctx.type_rewrites[stype] = irast.Set()
            filtered_set = dispatch.compile(qry, ctx=subctx)
            assert isinstance(filtered_set, irast.Set)
            subctx.type_rewrites[stype] = filtered_set
コード例 #2
0
ファイル: setgen.py プロジェクト: joe2hpimn/edgedb
def new_set(*, stype: s_types.Type, ctx: context.ContextLevel,
            **kwargs) -> irast.Set:
    """Create a new ir.Set instance with given attributes.

    Absolutely all ir.Set instances must be created using this
    constructor.
    """
    typeref = irtyputils.type_to_typeref(ctx.env.schema, stype)
    ir_set = irast.Set(typeref=typeref, **kwargs)
    ctx.env.set_types[ir_set] = stype
    return ir_set