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
def derive_ptr(ptr: s_pointers.Pointer, source: s_sources.Source, target: Optional[s_types.Type] = None, *qualifiers: str, derived_name: Optional[sn.SchemaName] = None, derived_name_quals: Optional[Sequence[str]] = (), derived_name_base: Optional[str] = None, preserve_shape: bool = False, preserve_path_id: bool = False, is_insert: bool = False, is_update: bool = False, inheritance_merge: bool = True, attrs: Optional[Dict[str, Any]] = None, ctx: context.ContextLevel) -> s_pointers.Pointer: if derived_name is None and ctx.derived_target_module: derived_name = derive_view_name(stype=ptr, derived_name_quals=derived_name_quals, derived_name_base=derived_name_base, ctx=ctx) if ptr.get_name(ctx.env.schema) == derived_name: qualifiers = qualifiers + (ctx.aliases.get('d'), ) ctx.env.schema, derived = ptr.derive_ref( ctx.env.schema, source, *qualifiers, target=target, name=derived_name, inheritance_merge=inheritance_merge, inheritance_refdicts={'pointers'}, mark_derived=True, transient=True, preserve_path_id=preserve_path_id, attrs=attrs) if not ptr.generic(ctx.env.schema): if isinstance(derived, s_sources.Source): ptr = cast(s_links.Link, ptr) scls_pointers = ptr.get_pointers(ctx.env.schema) derived_own_pointers = derived.get_pointers(ctx.env.schema) for pn, ptr in derived_own_pointers.items(ctx.env.schema): # This is a view of a view. Make sure query-level # computable expressions for pointers are carried over. src_ptr = scls_pointers.get(ctx.env.schema, pn) # mypy somehow loses the type argument in the # "pointers" ObjectIndex. assert isinstance(src_ptr, s_pointers.Pointer) computable_data = ctx.source_map.get(src_ptr) if computable_data is not None: ctx.source_map[ptr] = computable_data if preserve_shape and ptr in ctx.env.view_shapes: ctx.env.view_shapes[derived] = ctx.env.view_shapes[ptr] ctx.env.created_schema_objects.add(derived) return derived
def derive_ptr(ptr: s_pointers.Pointer, source: s_sources.Source, target: typing.Optional[s_types.Type] = None, *qualifiers, derived_name: typing.Optional[sn.SchemaName] = None, derived_name_quals: typing.Optional[typing.Sequence[str]] = (), derived_name_base: typing.Optional[str] = None, preserve_shape: bool = False, preserve_path_id: bool = False, is_insert: bool = False, is_update: bool = False, inheritance_merge: bool = True, attrs: typing.Optional[dict] = None, ctx: context.ContextLevel) -> s_pointers.Pointer: if derived_name is None and ctx.derived_target_module: derived_name = derive_view_name(stype=ptr, derived_name_quals=derived_name_quals, derived_name_base=derived_name_base, ctx=ctx) if ptr.get_name(ctx.env.schema) == derived_name: qualifiers = qualifiers + (ctx.aliases.get('d'), ) ctx.env.schema, derived = ptr.derive_ref( ctx.env.schema, source, target, *qualifiers, name=derived_name, inheritance_merge=inheritance_merge, refdict_whitelist={'pointers'}, mark_derived=True, preserve_path_id=preserve_path_id, attrs=attrs) if not ptr.generic(ctx.env.schema): if isinstance(derived, s_sources.Source): ptr = typing.cast(s_links.Link, ptr) scls_pointers = ptr.get_pointers(ctx.env.schema) derived_own_pointers = derived.get_pointers(ctx.env.schema) for pn, ptr in derived_own_pointers.items(ctx.env.schema): # This is a view of a view. Make sure query-level # computable expressions for pointers are carried over. src_ptr = scls_pointers.get(ctx.env.schema, pn) computable_data = ctx.source_map.get(src_ptr) if computable_data is not None: ctx.source_map[ptr] = computable_data if preserve_shape and ptr in ctx.env.view_shapes: ctx.env.view_shapes[derived] = ctx.env.view_shapes[ptr] return derived
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