module Language.C.Analysis.TypeUtils (
integral,
floating,
simplePtr,
uint16_tType,
uint32_tType,
uint64_tType,
size_tType,
ptrDiffType,
boolType,
voidType,
voidPtr,
constVoidPtr,
charPtr,
constCharPtr,
stringType,
valistType,
isIntegralType,
isFloatingType,
isPointerType,
isScalarType,
isFunctionType,
typeQuals,
typeQualsUpd,
typeAttrs,
typeAttrsUpd,
baseType,
derefTypeDef,
deepDerefTypeDef,
canonicalType,
sameType,
getIntType,
getFloatType
) where
import Language.C.Analysis.SemRep
import Language.C.Data.Node (CNode(..))
import Language.C.Syntax.AST (CExpression (..), CConstant (..))
import Language.C.Syntax.Constants
integral :: IntType -> Type
integral :: IntType -> Type
integral IntType
ty = TypeName -> TypeQuals -> Attributes -> Type
DirectType (IntType -> TypeName
TyIntegral IntType
ty) TypeQuals
noTypeQuals Attributes
noAttributes
floating :: FloatType -> Type
floating :: FloatType -> Type
floating FloatType
ty = TypeName -> TypeQuals -> Attributes -> Type
DirectType (FloatType -> TypeName
TyFloating FloatType
ty) TypeQuals
noTypeQuals Attributes
noAttributes
simplePtr :: Type -> Type
simplePtr :: Type -> Type
simplePtr Type
t = Type -> TypeQuals -> Attributes -> Type
PtrType Type
t TypeQuals
noTypeQuals []
constPtr :: Type -> Type
constPtr :: Type -> Type
constPtr Type
t = Type -> TypeQuals -> Attributes -> Type
PtrType Type
t (TypeQuals
noTypeQuals { constant = True }) []
uint16_tType :: Type
uint16_tType :: Type
uint16_tType = IntType -> Type
integral IntType
TyUShort
uint32_tType :: Type
uint32_tType :: Type
uint32_tType = IntType -> Type
integral IntType
TyUInt
uint64_tType :: Type
uint64_tType :: Type
uint64_tType = IntType -> Type
integral IntType
TyULLong
size_tType :: Type
size_tType :: Type
size_tType = IntType -> Type
integral IntType
TyInt
ptrDiffType :: Type
ptrDiffType :: Type
ptrDiffType = IntType -> Type
integral IntType
TyInt
boolType :: Type
boolType :: Type
boolType = IntType -> Type
integral IntType
TyInt
voidType :: Type
voidType :: Type
voidType = TypeName -> TypeQuals -> Attributes -> Type
DirectType TypeName
TyVoid TypeQuals
noTypeQuals Attributes
noAttributes
voidPtr :: Type
voidPtr :: Type
voidPtr = Type -> Type
simplePtr Type
voidType
constVoidPtr :: Type
constVoidPtr :: Type
constVoidPtr = Type -> Type
constPtr Type
voidType
charPtr :: Type
charPtr :: Type
charPtr = Type -> Type
simplePtr (IntType -> Type
integral IntType
TyChar)
constCharPtr :: Type
constCharPtr :: Type
constCharPtr = Type -> Type
constPtr (IntType -> Type
integral IntType
TyChar)
stringType :: Type
stringType :: Type
stringType = Type -> ArraySize -> TypeQuals -> Attributes -> Type
ArrayType
(TypeName -> TypeQuals -> Attributes -> Type
DirectType (IntType -> TypeName
TyIntegral IntType
TyChar)
(TypeQuals
noTypeQuals { constant = True })
Attributes
noAttributes)
(Bool -> ArraySize
UnknownArraySize Bool
False)
TypeQuals
noTypeQuals
[]
valistType :: Type
valistType :: Type
valistType = TypeName -> TypeQuals -> Attributes -> Type
DirectType (BuiltinType -> TypeName
TyBuiltin BuiltinType
TyVaList) TypeQuals
noTypeQuals Attributes
noAttributes
isIntegralType :: Type -> Bool
isIntegralType :: Type -> Bool
isIntegralType (DirectType (TyIntegral IntType
_) TypeQuals
_ Attributes
_) = Bool
True
isIntegralType (DirectType (TyEnum EnumTypeRef
_) TypeQuals
_ Attributes
_) = Bool
True
isIntegralType Type
_ = Bool
False
isFloatingType :: Type -> Bool
isFloatingType :: Type -> Bool
isFloatingType (DirectType (TyFloating FloatType
_) TypeQuals
_ Attributes
_) = Bool
True
isFloatingType Type
_ = Bool
False
isPointerType :: Type -> Bool
isPointerType :: Type -> Bool
isPointerType (PtrType Type
_ TypeQuals
_ Attributes
_) = Bool
True
isPointerType (ArrayType Type
_ ArraySize
_ TypeQuals
_ Attributes
_) = Bool
True
isPointerType Type
_ = Bool
False
isScalarType :: Type -> Bool
isScalarType :: Type -> Bool
isScalarType Type
t = Type -> Bool
isIntegralType Type
t Bool -> Bool -> Bool
|| Type -> Bool
isPointerType Type
t Bool -> Bool -> Bool
|| Type -> Bool
isFloatingType Type
t
isFunctionType :: Type -> Bool
isFunctionType :: Type -> Bool
isFunctionType Type
ty =
case Type
ty of TypeDefType (TypeDefRef Ident
_ Type
actual_ty NodeInfo
_) TypeQuals
_ Attributes
_ -> Type -> Bool
isFunctionType Type
actual_ty
FunctionType FunType
_ Attributes
_ -> Bool
True
Type
_ -> Bool
False
typeQuals :: Type -> TypeQuals
typeQuals :: Type -> TypeQuals
typeQuals (DirectType TypeName
_ TypeQuals
q Attributes
_) = TypeQuals
q
typeQuals (PtrType Type
_ TypeQuals
q Attributes
_) = TypeQuals
q
typeQuals (ArrayType Type
_ ArraySize
_ TypeQuals
q Attributes
_) = TypeQuals
q
typeQuals (FunctionType FunType
_ Attributes
_) = TypeQuals
noTypeQuals
typeQuals (TypeDefType (TypeDefRef Ident
_ Type
t NodeInfo
_) TypeQuals
q Attributes
_) = TypeQuals -> TypeQuals -> TypeQuals
mergeTypeQuals TypeQuals
q (Type -> TypeQuals
typeQuals Type
t)
typeQualsUpd :: (TypeQuals -> TypeQuals) -> Type -> Type
typeQualsUpd :: (TypeQuals -> TypeQuals) -> Type -> Type
typeQualsUpd TypeQuals -> TypeQuals
f Type
ty =
case Type
ty of DirectType TypeName
ty_name TypeQuals
ty_quals Attributes
ty_attrs -> TypeName -> TypeQuals -> Attributes -> Type
DirectType TypeName
ty_name (TypeQuals -> TypeQuals
f TypeQuals
ty_quals) Attributes
ty_attrs
PtrType Type
ty_inner TypeQuals
ty_quals Attributes
ty_attrs -> Type -> TypeQuals -> Attributes -> Type
PtrType Type
ty_inner (TypeQuals -> TypeQuals
f TypeQuals
ty_quals) Attributes
ty_attrs
ArrayType Type
ty_inner ArraySize
sz TypeQuals
ty_quals Attributes
ty_attrs -> Type -> ArraySize -> TypeQuals -> Attributes -> Type
ArrayType Type
ty_inner ArraySize
sz (TypeQuals -> TypeQuals
f TypeQuals
ty_quals) Attributes
ty_attrs
FunctionType FunType
ty_inner Attributes
ty_attrs -> FunType -> Attributes -> Type
FunctionType FunType
ty_inner Attributes
ty_attrs
TypeDefType TypeDefRef
ty_ref TypeQuals
ty_quals Attributes
ty_attrs -> TypeDefRef -> TypeQuals -> Attributes -> Type
TypeDefType TypeDefRef
ty_ref (TypeQuals -> TypeQuals
f TypeQuals
ty_quals) Attributes
ty_attrs
typeAttrs :: Type -> Attributes
typeAttrs :: Type -> Attributes
typeAttrs (DirectType TypeName
_ TypeQuals
_ Attributes
a) = Attributes
a
typeAttrs (PtrType Type
_ TypeQuals
_ Attributes
a) = Attributes
a
typeAttrs (ArrayType Type
_ ArraySize
_ TypeQuals
_ Attributes
a) = Attributes
a
typeAttrs (FunctionType FunType
_ Attributes
a) = Attributes
a
typeAttrs (TypeDefType (TypeDefRef Ident
_ Type
t NodeInfo
_) TypeQuals
_ Attributes
a) = Attributes -> Attributes -> Attributes
mergeAttributes Attributes
a (Type -> Attributes
typeAttrs Type
t)
typeAttrsUpd :: (Attributes -> Attributes) -> Type -> Type
typeAttrsUpd :: (Attributes -> Attributes) -> Type -> Type
typeAttrsUpd Attributes -> Attributes
f Type
ty =
case Type
ty of DirectType TypeName
ty_name TypeQuals
ty_quals Attributes
ty_attrs -> TypeName -> TypeQuals -> Attributes -> Type
DirectType TypeName
ty_name TypeQuals
ty_quals (Attributes -> Attributes
f Attributes
ty_attrs)
PtrType Type
ty_inner TypeQuals
ty_quals Attributes
ty_attrs -> Type -> TypeQuals -> Attributes -> Type
PtrType Type
ty_inner TypeQuals
ty_quals (Attributes -> Attributes
f Attributes
ty_attrs)
ArrayType Type
ty_inner ArraySize
sz TypeQuals
ty_quals Attributes
ty_attrs -> Type -> ArraySize -> TypeQuals -> Attributes -> Type
ArrayType Type
ty_inner ArraySize
sz TypeQuals
ty_quals (Attributes -> Attributes
f Attributes
ty_attrs)
FunctionType FunType
ty_inner Attributes
ty_attrs -> FunType -> Attributes -> Type
FunctionType FunType
ty_inner (Attributes -> Attributes
f Attributes
ty_attrs)
TypeDefType TypeDefRef
ty_ref TypeQuals
ty_quals Attributes
ty_attrs -> TypeDefRef -> TypeQuals -> Attributes -> Type
TypeDefType TypeDefRef
ty_ref TypeQuals
ty_quals (Attributes -> Attributes
f Attributes
ty_attrs)
baseType :: Type -> Type
baseType :: Type -> Type
baseType (PtrType Type
t TypeQuals
_ Attributes
_) = Type
t
baseType (ArrayType Type
t ArraySize
_ TypeQuals
_ Attributes
_) = Type
t
baseType Type
_ = [Char] -> Type
forall a. HasCallStack => [Char] -> a
error [Char]
"base of non-pointer type"
derefTypeDef :: Type -> Type
derefTypeDef :: Type -> Type
derefTypeDef (TypeDefType (TypeDefRef Ident
_ Type
t NodeInfo
_) TypeQuals
q Attributes
a) =
((Attributes -> Attributes) -> Type -> Type
typeAttrsUpd (Attributes -> Attributes -> Attributes
mergeAttributes Attributes
a) (Type -> Type) -> (Type -> Type) -> Type -> Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TypeQuals -> TypeQuals) -> Type -> Type
typeQualsUpd (TypeQuals -> TypeQuals -> TypeQuals
mergeTypeQuals TypeQuals
q))
(Type -> Type
derefTypeDef Type
t)
derefTypeDef Type
ty = Type
ty
deepDerefTypeDef :: Type -> Type
deepDerefTypeDef :: Type -> Type
deepDerefTypeDef (PtrType Type
t TypeQuals
quals Attributes
attrs) =
Type -> TypeQuals -> Attributes -> Type
PtrType (Type -> Type
deepDerefTypeDef Type
t) TypeQuals
quals Attributes
attrs
deepDerefTypeDef (ArrayType Type
t ArraySize
size TypeQuals
quals Attributes
attrs) =
Type -> ArraySize -> TypeQuals -> Attributes -> Type
ArrayType (Type -> Type
deepDerefTypeDef Type
t) ArraySize
size TypeQuals
quals Attributes
attrs
deepDerefTypeDef (FunctionType (FunType Type
rt [ParamDecl]
params Bool
varargs) Attributes
attrs) =
FunType -> Attributes -> Type
FunctionType (Type -> [ParamDecl] -> Bool -> FunType
FunType (Type -> Type
deepDerefTypeDef Type
rt) [ParamDecl]
params Bool
varargs) Attributes
attrs
deepDerefTypeDef (FunctionType (FunTypeIncomplete Type
rt) Attributes
attrs) =
FunType -> Attributes -> Type
FunctionType (Type -> FunType
FunTypeIncomplete (Type -> Type
deepDerefTypeDef Type
rt)) Attributes
attrs
deepDerefTypeDef (TypeDefType (TypeDefRef Ident
_ Type
t NodeInfo
_) TypeQuals
q Attributes
a) =
((Attributes -> Attributes) -> Type -> Type
typeAttrsUpd (Attributes -> Attributes -> Attributes
mergeAttributes Attributes
a) (Type -> Type) -> (Type -> Type) -> Type -> Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TypeQuals -> TypeQuals) -> Type -> Type
typeQualsUpd (TypeQuals -> TypeQuals -> TypeQuals
mergeTypeQuals TypeQuals
q))
(Type -> Type
deepDerefTypeDef Type
t)
deepDerefTypeDef Type
t = Type
t
isVariablyModifiedType :: Type -> Bool
isVariablyModifiedType :: Type -> Bool
isVariablyModifiedType Type
t =
case Type -> Type
derefTypeDef Type
t of
TypeDefType {} -> [Char] -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"impossible: derefTypeDef t returned a TypeDefType"
DirectType {} -> Bool
False
PtrType Type
ptr_ty TypeQuals
_ Attributes
_ -> Type -> Bool
isVariablyModifiedType Type
ptr_ty
ArrayType Type
_ ArraySize
sz TypeQuals
_ Attributes
_ -> ArraySize -> Bool
isVariableArraySize ArraySize
sz
FunctionType {} -> Bool
False
where
isVariableArraySize :: ArraySize -> Bool
isVariableArraySize :: ArraySize -> Bool
isVariableArraySize (UnknownArraySize Bool
isStarred) = Bool
isStarred
isVariableArraySize (ArraySize Bool
isStatic Expr
e) = Bool
isStatic Bool -> Bool -> Bool
|| Expr -> Bool
isConstantSize Expr
e
isConstantSize :: Expr -> Bool
isConstantSize :: Expr -> Bool
isConstantSize (CConst (CIntConst {})) = Bool
True
isConstantSize Expr
_ = Bool
False
sameType :: Type -> Type -> Bool
sameType :: Type -> Type -> Bool
sameType Type
t1 Type
t2 =
Bool -> Bool
not (Type -> Bool
isVariablyModifiedType Type
t1 Bool -> Bool -> Bool
|| Type -> Bool
isVariablyModifiedType Type
t2) Bool -> Bool -> Bool
&& Bool
sameType'
where
sameType' :: Bool
sameType' =
case (Type -> Type
derefTypeDef Type
t1, Type -> Type
derefTypeDef Type
t2) of
(TypeDefType {}, Type
_) -> [Char] -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"impossible: derefTypeDef t1 returned a TypeDefType"
(Type
_, TypeDefType {}) -> [Char] -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"impossible: derefTypeDef t2 returned a TypeDefType"
(DirectType TypeName
tn1 TypeQuals
q1 Attributes
_a1, DirectType TypeName
tn2 TypeQuals
q2 Attributes
_a2) ->
TypeName -> TypeName -> Bool
sameTypeName TypeName
tn1 TypeName
tn2 Bool -> Bool -> Bool
&& TypeQuals -> TypeQuals -> Bool
sameQuals TypeQuals
q1 TypeQuals
q2
(PtrType Type
pt1 TypeQuals
q1 Attributes
_a1, PtrType Type
pt2 TypeQuals
q2 Attributes
_a2) ->
Type -> Type -> Bool
sameType Type
pt1 Type
pt2 Bool -> Bool -> Bool
&& TypeQuals -> TypeQuals -> Bool
sameQuals TypeQuals
q1 TypeQuals
q2
(ArrayType Type
at1 ArraySize
sz1 TypeQuals
q1 Attributes
_a1, ArrayType Type
at2 ArraySize
sz2 TypeQuals
q2 Attributes
_a2) ->
Type -> Type -> Bool
sameType Type
at1 Type
at2 Bool -> Bool -> Bool
&& ArraySize -> ArraySize -> Bool
sameArraySize ArraySize
sz1 ArraySize
sz2 Bool -> Bool -> Bool
&& TypeQuals -> TypeQuals -> Bool
sameQuals TypeQuals
q1 TypeQuals
q2
(FunctionType FunType
ft1 Attributes
_a1, FunctionType FunType
ft2 Attributes
_a2) ->
FunType -> FunType -> Bool
sameFunType FunType
ft1 FunType
ft2
(Type, Type)
_ -> Bool
False
sameTypeName :: TypeName -> TypeName -> Bool
sameTypeName :: TypeName -> TypeName -> Bool
sameTypeName TypeName
t1 TypeName
t2 =
case (TypeName
t1, TypeName
t2) of
(TypeName
TyVoid, TypeName
TyVoid) -> Bool
True
(TyIntegral IntType
i1, TyIntegral IntType
i2) -> IntType
i1 IntType -> IntType -> Bool
forall a. Eq a => a -> a -> Bool
== IntType
i2
(TyFloating FloatType
f1, TyFloating FloatType
f2) -> FloatType
f1 FloatType -> FloatType -> Bool
forall a. Eq a => a -> a -> Bool
== FloatType
f2
(TyComplex FloatType
f1, TyComplex FloatType
f2) -> FloatType
f1 FloatType -> FloatType -> Bool
forall a. Eq a => a -> a -> Bool
== FloatType
f2
(TyComp CompTypeRef
ctr1, TyComp CompTypeRef
ctr2) -> CompTypeRef -> CompTypeRef -> Bool
sameCompTypeRef CompTypeRef
ctr1 CompTypeRef
ctr2
(TyEnum EnumTypeRef
etr1, TyEnum EnumTypeRef
etr2) -> EnumTypeRef -> EnumTypeRef -> Bool
sameEnumTypeRef EnumTypeRef
etr1 EnumTypeRef
etr2
(TyBuiltin BuiltinType
b1, TyBuiltin BuiltinType
b2) -> BuiltinType -> BuiltinType -> Bool
sameBuiltinType BuiltinType
b1 BuiltinType
b2
(TypeName, TypeName)
_ -> Bool
False
sameBuiltinType :: BuiltinType -> BuiltinType -> Bool
sameBuiltinType :: BuiltinType -> BuiltinType -> Bool
sameBuiltinType BuiltinType
TyVaList BuiltinType
TyVaList = Bool
True
sameBuiltinType BuiltinType
TyAny BuiltinType
TyAny = Bool
False
sameBuiltinType BuiltinType
_ BuiltinType
_ = Bool
False
sameCompTypeRef :: CompTypeRef -> CompTypeRef -> Bool
sameCompTypeRef :: CompTypeRef -> CompTypeRef -> Bool
sameCompTypeRef (CompTypeRef SUERef
sue1 CompTyKind
kind1 NodeInfo
_) (CompTypeRef SUERef
sue2 CompTyKind
kind2 NodeInfo
_) =
SUERef
sue1 SUERef -> SUERef -> Bool
forall a. Eq a => a -> a -> Bool
== SUERef
sue2 Bool -> Bool -> Bool
&& CompTyKind
kind1 CompTyKind -> CompTyKind -> Bool
forall a. Eq a => a -> a -> Bool
== CompTyKind
kind2
sameEnumTypeRef :: EnumTypeRef -> EnumTypeRef -> Bool
sameEnumTypeRef :: EnumTypeRef -> EnumTypeRef -> Bool
sameEnumTypeRef (EnumTypeRef SUERef
sue1 NodeInfo
_) (EnumTypeRef SUERef
sue2 NodeInfo
_) = SUERef
sue1 SUERef -> SUERef -> Bool
forall a. Eq a => a -> a -> Bool
== SUERef
sue2
sameFunType :: FunType -> FunType -> Bool
sameFunType :: FunType -> FunType -> Bool
sameFunType (FunType Type
rt1 [ParamDecl]
params1 Bool
isVar1) (FunType Type
rt2 [ParamDecl]
params2 Bool
isVar2) =
Type -> Type -> Bool
sameType Type
rt1 Type
rt2 Bool -> Bool -> Bool
&& [ParamDecl] -> [ParamDecl] -> Bool
sameParamDecls [ParamDecl]
params1 [ParamDecl]
params2 Bool -> Bool -> Bool
&& Bool
isVar1 Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
isVar2
where
sameParamDecls :: [ParamDecl] -> [ParamDecl] -> Bool
sameParamDecls :: [ParamDecl] -> [ParamDecl] -> Bool
sameParamDecls [ParamDecl]
param_list1 [ParamDecl]
param_list2 =
[ParamDecl] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [ParamDecl]
param_list1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== [ParamDecl] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [ParamDecl]
param_list2
Bool -> Bool -> Bool
&& [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and ((ParamDecl -> ParamDecl -> Bool)
-> [ParamDecl] -> [ParamDecl] -> [Bool]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith ParamDecl -> ParamDecl -> Bool
sameParamDecl [ParamDecl]
param_list1 [ParamDecl]
param_list2)
sameParamDecl :: ParamDecl -> ParamDecl -> Bool
sameParamDecl :: ParamDecl -> ParamDecl -> Bool
sameParamDecl ParamDecl
p1 ParamDecl
p2 = Type -> Type -> Bool
sameType (ParamDecl -> Type
forall n. Declaration n => n -> Type
declType ParamDecl
p1) (ParamDecl -> Type
forall n. Declaration n => n -> Type
declType ParamDecl
p2)
sameFunType (FunTypeIncomplete Type
rt1) (FunTypeIncomplete Type
rt2) =
Type -> Type -> Bool
sameType Type
rt1 Type
rt2
sameFunType FunType
_ FunType
_ = Bool
False
sameArraySize :: ArraySize -> ArraySize -> Bool
sameArraySize :: ArraySize -> ArraySize -> Bool
sameArraySize (UnknownArraySize Bool
isStar1) (UnknownArraySize Bool
isStar2) = Bool
isStar1 Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
isStar2
sameArraySize (ArraySize Bool
s1 Expr
e1) (ArraySize Bool
s2 Expr
e2) = Bool
s1 Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
s2 Bool -> Bool -> Bool
&& Expr -> Expr -> Bool
sizeEqual Expr
e1 Expr
e2
where
sizeEqual :: Expr -> Expr -> Bool
sizeEqual :: Expr -> Expr -> Bool
sizeEqual (CConst (CIntConst CInteger
i1 NodeInfo
_)) (CConst (CIntConst CInteger
i2 NodeInfo
_)) = CInteger
i1 CInteger -> CInteger -> Bool
forall a. Eq a => a -> a -> Bool
== CInteger
i2
sizeEqual Expr
oe1 Expr
oe2 = Expr -> NodeInfo
forall a. CNode a => a -> NodeInfo
nodeInfo Expr
oe1 NodeInfo -> NodeInfo -> Bool
forall a. Eq a => a -> a -> Bool
== Expr -> NodeInfo
forall a. CNode a => a -> NodeInfo
nodeInfo Expr
oe2
sameArraySize ArraySize
_ ArraySize
_ = Bool
False
sameQuals :: TypeQuals -> TypeQuals -> Bool
sameQuals :: TypeQuals -> TypeQuals -> Bool
sameQuals (TypeQuals {constant :: TypeQuals -> Bool
constant = Bool
c1, volatile :: TypeQuals -> Bool
volatile = Bool
v1, restrict :: TypeQuals -> Bool
restrict = Bool
r1})
(TypeQuals {constant :: TypeQuals -> Bool
constant = Bool
c2, volatile :: TypeQuals -> Bool
volatile = Bool
v2, restrict :: TypeQuals -> Bool
restrict = Bool
r2}) =
Bool
c1 Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
c2 Bool -> Bool -> Bool
&& Bool
v1 Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
v2 Bool -> Bool -> Bool
&& Bool
r1 Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
r2
canonicalType :: Type -> Type
canonicalType :: Type -> Type
canonicalType Type
t =
case Type -> Type
deepDerefTypeDef Type
t of
FunctionType FunType
ft Attributes
attrs -> Type -> Type
simplePtr (FunType -> Attributes -> Type
FunctionType FunType
ft Attributes
attrs)
Type
t' -> Type
t'
testFlags :: Enum f => [f] -> Flags f -> Bool
testFlags :: forall f. Enum f => [f] -> Flags f -> Bool
testFlags [f]
flags Flags f
fi = (f -> Bool) -> [f] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (f -> Flags f -> Bool
forall f. Enum f => f -> Flags f -> Bool
`testFlag` Flags f
fi) [f]
flags
getIntType :: Flags CIntFlag -> IntType
getIntType :: Flags CIntFlag -> IntType
getIntType Flags CIntFlag
flags | [CIntFlag] -> Flags CIntFlag -> Bool
forall f. Enum f => [f] -> Flags f -> Bool
testFlags [CIntFlag
FlagLongLong, CIntFlag
FlagUnsigned] Flags CIntFlag
flags = IntType
TyULLong
| CIntFlag -> Flags CIntFlag -> Bool
forall f. Enum f => f -> Flags f -> Bool
testFlag CIntFlag
FlagLongLong Flags CIntFlag
flags = IntType
TyLLong
| [CIntFlag] -> Flags CIntFlag -> Bool
forall f. Enum f => [f] -> Flags f -> Bool
testFlags [CIntFlag
FlagLong, CIntFlag
FlagUnsigned] Flags CIntFlag
flags = IntType
TyULong
| CIntFlag -> Flags CIntFlag -> Bool
forall f. Enum f => f -> Flags f -> Bool
testFlag CIntFlag
FlagLong Flags CIntFlag
flags = IntType
TyLong
| CIntFlag -> Flags CIntFlag -> Bool
forall f. Enum f => f -> Flags f -> Bool
testFlag CIntFlag
FlagUnsigned Flags CIntFlag
flags = IntType
TyUInt
| Bool
otherwise = IntType
TyInt
getFloatType :: String -> FloatType
getFloatType :: [Char] -> FloatType
getFloatType [Char]
fs | [Char] -> Char
forall a. HasCallStack => [a] -> a
last [Char]
fs Char -> [Char] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char
'f', Char
'F'] = FloatType
TyFloat
| [Char] -> Char
forall a. HasCallStack => [a] -> a
last [Char]
fs Char -> [Char] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char
'l', Char
'L'] = FloatType
TyLDouble
| Bool
otherwise = FloatType
TyDouble