module alloy/A_TypCtxStructFull -- Model a full TypeCtx with all the structural -- constraints represented and enforced including -- attribute types of ValConst (primitive values) -- and ValRef (foreign key pointers) /* Semantic consistenty properties checked are: 0. Each Primitive, Root and Entity object has a single word label. 1. Each Primitive, Root and Entity object has a full entity name that is the concatenation of the labels in order from Root to each sub-type Entity, each pair of labels separated by ".". This is analogous to a full file system path name for a file or directory. 1. The relationship between full names and Root, Primitive, Entity definitions is an identity. 4. Therefore, in the set of sub-types for every Entity and Root, the single word labels are unique. 2. Every Entity has one super type 3. The super type for every Entity is defined within its own type context, no external super types. 4. Root and Primitive types have no super type 5. No cycle of super-type references for any Entity 6. Unique attribute key names within an entity (not modeled) 7. No attribute cycle following Entity definitions for non-reference target types (transitive closure). 8. No duplicate attribute names for any Entity in the set of attribute names of itself and the union of it super types. (not modeled) Therefore: - - For a given Entity or Root, */ -- Value type for attributes or data fields abstract sig ValTyp {} -- A reference to an Entity sig ValRef extends ValTyp { ref: one Entity } -- A constant value, a primitive (Int, Real, Text, Blob) sig ValConst extends ValTyp {} -- Attribute: a data field within an EType sig Attr { typdef: one ValTyp } -- An Entity defines a data type abstract sig Entity {} -- An ERoot is the bottom element in a single type tree hierarchy. sig ERoot extends Entity {} -- A data type and its content attributes sig EType extends Entity { sup: one Entity, -- The super type of this EType attrs: some Attr -- The names of the attribute fields } { this != sup -- No reflexive super type definition } -- TypeCtx contains super-type trees of ETypes -- with each tree rooted in its own ERoot. sig TypeCtx { types: some EType, -- Entity type definitions root: some ERoot -- The set of roots in the TypeCtx }{ -- All paths through sup from EType must end at ERoot all t: types | one r : root | r in t.^sup } fact { -- Each EType and ERoot is in one TypeCtx only all disj tc, tc_: TypeCtx | (no (tc.types & tc_.types)) and (no (tc.root & tc_.root)) -- Each ERoot and EType must be part of a single TypeCtx, not free all r: ERoot | one tc: TypeCtx | r in tc.root all t: EType | one tc: TypeCtx | t in tc.types -- No unattached Attr or ValTyp all a: Attr | a in EType.attrs all vt: ValTyp | vt in Attr.typdef -- For the model, separate Attr definitions between types all disj e, e_: EType | no (e.attrs & e_.attrs) -- No bare ERoot: must have at least one subtype EType all r: ERoot | some t: EType | t.sup = r } pred show { some ValConst } run show for 4 but exactly 1 TypeCtx run show for 6 but exactly 1 TypeCtx run show for 4 but exactly 1 TypeCtx, exactly 3 EType run show for 6 but exactly 1 TypeCtx, exactly 3 EType