@@ -240,6 +240,7 @@ data TypeConstructorDef = ADTypeConstructorDef TypeConstructorName [TypeVarName]
240240-- | Found in data constructors and type declarations: Left (Either Int Text) | Right Int
241241data TypeConstructor = ADTypeConstructor TypeConstructorName [TypeConstructor] |
242242 PrimitiveTypeConstructor TypeConstructorName AtomType |
243+ RelationAtomTypeConstructor AttributeExpr |
243244 TypeVariable TypeVarName
244245 deriving (Show, Generic, Binary, Eq, NFData)
245246
@@ -527,3 +528,42 @@ instance Hashable DatabaseContextFunction where
527528
528529instance Eq DatabaseContextFunction where
529530 f1 == f2 = dbcFuncName f1 == dbcFuncName f2
531+
532+attrTypeVars :: Attribute -> S.Set TypeVarName
533+attrTypeVars (Attribute _ aType) = case aType of
534+ IntAtomType -> S.empty
535+ IntegerAtomType -> S.empty
536+ DoubleAtomType -> S.empty
537+ TextAtomType -> S.empty
538+ DayAtomType -> S.empty
539+ DateTimeAtomType -> S.empty
540+ ByteStringAtomType -> S.empty
541+ BoolAtomType -> S.empty
542+ (IntervalAtomType atomtyp) -> atomTypeVars atomtyp
543+ (RelationAtomType attrs) -> S.unions (map attrTypeVars (V.toList attrs))
544+ (ConstructedAtomType _ tvMap) -> M.keysSet tvMap
545+ (TypeVariableType nam) -> S.singleton nam
546+
547+typeVars :: TypeConstructor -> S.Set TypeVarName
548+typeVars (PrimitiveTypeConstructor _ _) = S.empty
549+typeVars (ADTypeConstructor _ args) = S.unions (map typeVars args)
550+typeVars (TypeVariable v) = S.singleton v
551+typeVars (RelationAtomTypeConstructor attrExpr) = attrExprTypeVars attrExpr
552+
553+attrExprTypeVars :: AttributeExprBase a -> S.Set TypeVarName
554+attrExprTypeVars (AttributeAndTypeNameExpr _ tCons _) = typeVars tCons
555+attrExprTypeVars (NakedAttributeExpr attr) = attrTypeVars attr
556+
557+atomTypeVars :: AtomType -> S.Set TypeVarName
558+atomTypeVars IntAtomType = S.empty
559+atomTypeVars IntegerAtomType = S.empty
560+atomTypeVars DoubleAtomType = S.empty
561+atomTypeVars TextAtomType = S.empty
562+atomTypeVars DayAtomType = S.empty
563+atomTypeVars DateTimeAtomType = S.empty
564+atomTypeVars ByteStringAtomType = S.empty
565+atomTypeVars BoolAtomType = S.empty
566+atomTypeVars (IntervalAtomType aType) = atomTypeVars aType
567+atomTypeVars (RelationAtomType attrs) = S.unions (map attrTypeVars (V.toList attrs))
568+atomTypeVars (ConstructedAtomType _ tvMap) = M.keysSet tvMap
569+atomTypeVars (TypeVariableType nam) = S.singleton nam