Ejemplo n.º 1
0
def derive_dummy_ptr(
    ptr: s_pointers.Pointer,
    *,
    ctx: context.ContextLevel,
) -> s_pointers.Pointer:
    stdobj = cast(s_objtypes.ObjectType, ctx.env.schema.get('std::Object'))
    derived_obj_name = stdobj.get_derived_name(ctx.env.schema,
                                               stdobj,
                                               module='__derived__')
    derived_obj = ctx.env.schema.get(derived_obj_name, None)
    if derived_obj is None:
        ctx.env.schema, derived_obj = stdobj.derive_subtype(
            ctx.env.schema, name=derived_obj_name)
        ctx.env.created_schema_objects.add(derived_obj)

    derived_name = ptr.get_derived_name(ctx.env.schema, derived_obj)

    derived: s_pointers.Pointer
    derived = cast(s_pointers.Pointer, ctx.env.schema.get(derived_name, None))
    if derived is None:
        ctx.env.schema, derived = ptr.derive_ref(ctx.env.schema,
                                                 derived_obj,
                                                 derived_obj,
                                                 attrs={
                                                     'cardinality':
                                                     qltypes.Cardinality.MANY,
                                                 },
                                                 name=derived_name,
                                                 mark_derived=True)
        ctx.env.created_schema_objects.add(derived)

    return derived
Ejemplo n.º 2
0
def derive_dummy_ptr(
    ptr: s_pointers.Pointer,
    *,
    ctx: context.ContextLevel,
) -> s_pointers.Pointer:
    stdobj = ctx.env.schema.get('std::BaseObject', type=s_objtypes.ObjectType)
    derived_obj_name = stdobj.get_derived_name(ctx.env.schema,
                                               stdobj,
                                               module='__derived__')
    derived_obj = ctx.env.schema.get(derived_obj_name,
                                     None,
                                     type=s_obj.QualifiedObject)
    if derived_obj is None:
        ctx.env.schema, derived_obj = stdobj.derive_subtype(
            ctx.env.schema, name=derived_obj_name)
        ctx.env.created_schema_objects.add(derived_obj)

    derived_name = ptr.get_derived_name(ctx.env.schema, derived_obj)

    derived: s_pointers.Pointer
    derived = cast(s_pointers.Pointer, ctx.env.schema.get(derived_name, None))
    if derived is None:
        ctx.env.schema, derived = ptr.derive_ref(
            ctx.env.schema,
            derived_obj,
            target=derived_obj,
            attrs={
                'cardinality': qltypes.SchemaCardinality.One,
            },
            name=derived_name,
            mark_derived=True,
            transient=True,
        )
        ctx.env.created_schema_objects.add(derived)

    return derived