pub struct ModelBuilder { /* private fields */ }Expand description
Mutable model under construction. Entities are keyed: frontends that
meet the same symbol (tree-sitter, then SCIP) share one entity.
Relations are deduplicated on (from, kind, to, provenance); each
occurrence site is kept.
Ids passed to the setters must come from this builder.
Implementations§
Source§impl ModelBuilder
impl ModelBuilder
pub fn new() -> Self
Sourcepub fn from_model(model: &Model) -> Self
pub fn from_model(model: &Model) -> Self
A builder holding everything model holds, entity ids unchanged:
derived facts (analyses) can be added to a frozen model and the
result frozen again.
Sourcepub fn entity(&mut self, key: &str, kind: EntityKind, name: &str) -> EntityId
pub fn entity(&mut self, key: &str, kind: EntityKind, name: &str) -> EntityId
Entity with key, created with kind and name if absent. An
existing entity keeps its kind and name.
Sourcepub fn entity_of_kind(
&mut self,
key: &str,
kind: KindId,
name: &str,
) -> EntityId
pub fn entity_of_kind( &mut self, key: &str, kind: KindId, name: &str, ) -> EntityId
Like Self::entity with a fine kind from Self::define_kind.
pub fn get(&self, key: &str) -> Option<EntityId>
Sourcepub fn ids(&self) -> impl ExactSizeIterator<Item = EntityId> + use<>
pub fn ids(&self) -> impl ExactSizeIterator<Item = EntityId> + use<>
Ids of every entity, in creation order.
Sourcepub fn rekey(&mut self, id: EntityId, key: &str) -> Result<(), EntityId>
pub fn rekey(&mut self, id: EntityId, key: &str) -> Result<(), EntityId>
Gives id the key key (e.g. its SCIP symbol, found after a
syntactic frontend created it). Fails with the entity already
holding key, if another one does.
pub fn name(&self, id: EntityId) -> &str
pub fn parent(&self, id: EntityId) -> Option<EntityId>
pub fn file(&self, id: EntityId) -> Option<&str>
pub fn range(&self, id: EntityId) -> Option<Range>
pub fn name_range(&self, id: EntityId) -> Option<Range>
pub fn external(&self, id: EntityId) -> bool
pub fn key(&self, id: EntityId) -> &str
Sourcepub fn kind(&self, id: EntityId) -> EntityKind
pub fn kind(&self, id: EntityId) -> EntityKind
Archetype of the entity’s fine kind.
pub fn kind_id(&self, id: EntityId) -> KindId
Sourcepub fn set_kind(&mut self, id: EntityId, kind: EntityKind)
pub fn set_kind(&mut self, id: EntityId, kind: EntityKind)
Sets the archetype’s default (unrefined) kind.
pub fn set_kind_id(&mut self, id: EntityId, kind: KindId)
Sourcepub fn define_kind(
&mut self,
name: &str,
archetype: EntityKind,
traits: TraitMask,
fm3: Option<&str>,
) -> KindId
pub fn define_kind( &mut self, name: &str, archetype: EntityKind, traits: TraitMask, fm3: Option<&str>, ) -> KindId
Kind named name (get-or-create); see Metamodel::define.
Sourcepub fn set_kind_traits(&mut self, kind: KindId, traits: TraitMask)
pub fn set_kind_traits(&mut self, kind: KindId, traits: TraitMask)
Sets the traits of an existing kind, e.g. of an archetype’s default
kind (KindId::of(EntityKind::Class)).
Sourcepub fn set_kind_concept(
&mut self,
kind: KindId,
graphql_type: Option<&str>,
graphql_root: Option<&str>,
) -> bool
pub fn set_kind_concept( &mut self, kind: KindId, graphql_type: Option<&str>, graphql_root: Option<&str>, ) -> bool
Declares the GraphQL concept and root field names of a defined kind;
see Metamodel::set_concept.
pub fn metamodel(&self) -> &Metamodel
pub fn set_parent(&mut self, id: EntityId, parent: Option<EntityId>)
pub fn set_language(&mut self, id: EntityId, language: &LanguageId)
pub fn set_external(&mut self, id: EntityId, external: bool)
Sourcepub fn set_source(
&mut self,
id: EntityId,
file: &str,
range: Range,
name_range: Option<Range>,
)
pub fn set_source( &mut self, id: EntityId, file: &str, range: Range, name_range: Option<Range>, )
Where the entity is written; file relative to the analysed root.
pub fn set_prop(&mut self, id: EntityId, key: &str, value: impl Into<Value>)
pub fn props_mut(&mut self, id: EntityId) -> &mut Props
Sourcepub fn relate(
&mut self,
kind: &RelationKind,
from: EntityId,
to: EntityId,
provenance: Provenance,
)
pub fn relate( &mut self, kind: &RelationKind, from: EntityId, to: EntityId, provenance: Provenance, )
Asserts a relation without a site (inheritance read from metadata…).
Sourcepub fn occurrence(
&mut self,
kind: &RelationKind,
from: EntityId,
to: EntityId,
provenance: Provenance,
site: Range,
)
pub fn occurrence( &mut self, kind: &RelationKind, from: EntityId, to: EntityId, provenance: Provenance, site: Range, )
Asserts a relation at site, a range in from’s file: sites are
attributed to their innermost enclosing entity, so they share its file.
Sourcepub fn occurrence_flagged(
&mut self,
kind: &RelationKind,
from: EntityId,
to: EntityId,
provenance: Provenance,
site: Range,
flags: SiteFlags,
)
pub fn occurrence_flagged( &mut self, kind: &RelationKind, from: EntityId, to: EntityId, provenance: Provenance, site: Range, flags: SiteFlags, )
Like Self::occurrence with per-site flags (read/write, receiver).
The same site asserted twice keeps the union of its flags.