    {-# LANGUAGE OverloadedLists #-}
    {-# LANGUAGE TypeFamilies #-}

    module Language.C99.Util.IsList where

    import GHC.Exts

    import Language.C99.AST

    error_emptylist :: [Char] -> a
    error_emptylist [Char]
    name = [Char] -> a
    forall a. HasCallStack => [Char] -> a
    error ([Char] -> a) -> [Char] -> a
    forall a b. (a -> b) -> a -> b
    $ [Char]
    "Empty " [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    name [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    " is not allowed"

    instance IsList TypeQualList where
      type Item TypeQualList = TypeQual
      fromList :: [Item TypeQualList] -> TypeQualList
    fromList []     = [Char] -> TypeQualList
    forall {a}. [Char] -> a
    error_emptylist [Char]
    "TypeQualList"
      fromList (Item TypeQualList
    x:[Item TypeQualList]
    xs) = (TypeQualList -> TypeQual -> TypeQualList)
    -> TypeQualList -> [TypeQual] -> TypeQualList
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl TypeQualList -> TypeQual -> TypeQualList
    TypeQualCons (TypeQual -> TypeQualList
    TypeQualBase Item TypeQualList
    TypeQual
    x) [Item TypeQualList]
    [TypeQual]
    xs
      toList :: TypeQualList -> [Item TypeQualList]
    toList = TypeQualList -> [Item TypeQualList]
    TypeQualList -> [TypeQual]
    forall a. HasCallStack => a
    undefined

    instance IsList StructDeclnList where
      type Item StructDeclnList = StructDecln
      fromList :: [Item StructDeclnList] -> StructDeclnList
    fromList []     = [Char] -> StructDeclnList
    forall {a}. [Char] -> a
    error_emptylist [Char]
    "StructDeclnList"
      fromList (Item StructDeclnList
    x:[Item StructDeclnList]
    xs) = (StructDeclnList -> StructDecln -> StructDeclnList)
    -> StructDeclnList -> [StructDecln] -> StructDeclnList
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl StructDeclnList -> StructDecln -> StructDeclnList
    StructDeclnCons (StructDecln -> StructDeclnList
    StructDeclnBase Item StructDeclnList
    StructDecln
    x) [Item StructDeclnList]
    [StructDecln]
    xs
      toList :: StructDeclnList -> [Item StructDeclnList]
    toList = StructDeclnList -> [Item StructDeclnList]
    StructDeclnList -> [StructDecln]
    forall a. HasCallStack => a
    undefined

    instance IsList ArgExprList where
      type Item ArgExprList = AssignExpr
      fromList :: [Item ArgExprList] -> ArgExprList
    fromList []     = [Char] -> ArgExprList
    forall {a}. [Char] -> a
    error_emptylist [Char]
    "ArgExprList"
      fromList (Item ArgExprList
    x:[Item ArgExprList]
    xs) = (ArgExprList -> AssignExpr -> ArgExprList)
    -> ArgExprList -> [AssignExpr] -> ArgExprList
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl ArgExprList -> AssignExpr -> ArgExprList
    ArgExprListCons (AssignExpr -> ArgExprList
    ArgExprListBase Item ArgExprList
    AssignExpr
    x) [Item ArgExprList]
    [AssignExpr]
    xs

    instance IsList InitList where
      type Item InitList = Init
      fromList :: [Item InitList] -> InitList
    fromList []     = [Char] -> InitList
    forall {a}. [Char] -> a
    error_emptylist [Char]
    "InitExprList"
      fromList (Item InitList
    x:[Item InitList]
    xs) = (InitList -> Init -> InitList) -> InitList -> [Init] -> InitList
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl InitList -> Init -> InitList
    step InitList
    base [Item InitList]
    [Init]
    xs where
        base :: InitList
    base      = Maybe Design -> Init -> InitList
    InitBase Maybe Design
    forall a. Maybe a
    Nothing Item InitList
    Init
    x
        step :: InitList -> Init -> InitList
    step InitList
    ys Init
    y = InitList -> Maybe Design -> Init -> InitList
    InitCons InitList
    ys Maybe Design
    forall a. Maybe a
    Nothing Init
    y

    instance IsList BlockItemList where
      type Item BlockItemList = BlockItem
      fromList :: [Item BlockItemList] -> BlockItemList
    fromList []     = [Char] -> BlockItemList
    forall {a}. [Char] -> a
    error_emptylist [Char]
    "BlockItemList"
      fromList (Item BlockItemList
    x:[Item BlockItemList]
    xs) = (BlockItemList -> BlockItem -> BlockItemList)
    -> BlockItemList -> [BlockItem] -> BlockItemList
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl BlockItemList -> BlockItem -> BlockItemList
    BlockItemCons (BlockItem -> BlockItemList
    BlockItemBase Item BlockItemList
    BlockItem
    x) [Item BlockItemList]
    [BlockItem]
    xs

    instance IsList TransUnit where
      type Item TransUnit = ExtDecln
      fromList :: [Item TransUnit] -> TransUnit
    fromList []     = [Char] -> TransUnit
    forall {a}. [Char] -> a
    error_emptylist [Char]
    "TransUnit"
      fromList (Item TransUnit
    x:[Item TransUnit]
    xs) = (TransUnit -> ExtDecln -> TransUnit)
    -> TransUnit -> [ExtDecln] -> TransUnit
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl TransUnit -> ExtDecln -> TransUnit
    TransUnitCons (ExtDecln -> TransUnit
    TransUnitBase Item TransUnit
    ExtDecln
    x) [Item TransUnit]
    [ExtDecln]
    xs

    instance IsList DeclnList where
      type Item DeclnList = Decln
      fromList :: [Item DeclnList] -> DeclnList
    fromList []     = [Char] -> DeclnList
    forall {a}. [Char] -> a
    error_emptylist [Char]
    "DeclnList"
      fromList (Item DeclnList
    x:[Item DeclnList]
    xs) = (DeclnList -> Decln -> DeclnList)
    -> DeclnList -> [Decln] -> DeclnList
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl DeclnList -> Decln -> DeclnList
    DeclnCons (Decln -> DeclnList
    DeclnBase Item DeclnList
    Decln
    x) [Item DeclnList]
    [Decln]
    xs

    hcharseq :: [HChar] -> HCharSeq
    hcharseq :: [HChar] -> HCharSeq
    hcharseq []     = [Char] -> HCharSeq
    forall {a}. [Char] -> a
    error_emptylist [Char]
    "HCharSeq"
    hcharseq (HChar
    x:[HChar]
    xs) = (HCharSeq -> HChar -> HCharSeq) -> HCharSeq -> [HChar] -> HCharSeq
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl HCharSeq -> HChar -> HCharSeq
    HCharCons (HChar -> HCharSeq
    HCharBase HChar
    x) [HChar]
    xs

    qcharseq :: [QChar] -> QCharSeq
    qcharseq :: [QChar] -> QCharSeq
    qcharseq []     = [Char] -> QCharSeq
    forall {a}. [Char] -> a
    error_emptylist [Char]
    "QCharSeq"
    qcharseq (QChar
    x:[QChar]
    xs) = (QCharSeq -> QChar -> QCharSeq) -> QCharSeq -> [QChar] -> QCharSeq
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl QCharSeq -> QChar -> QCharSeq
    QCharCons (QChar -> QCharSeq
    QCharBase QChar
    x) [QChar]
    xs

    group :: [GroupPart] -> Group
    group :: [GroupPart] -> Group
    group []     = [Char] -> Group
    forall {a}. [Char] -> a
    error_emptylist [Char]
    "HCharSeq"
    group (GroupPart
    x:[GroupPart]
    xs) = (Group -> GroupPart -> Group) -> Group -> [GroupPart] -> Group
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl Group -> GroupPart -> Group
    GroupCons (GroupPart -> Group
    GroupBase GroupPart
    x) [GroupPart]
    xs

    pptokens :: [PreprocToken] -> PPTokens
    pptokens :: [PreprocToken] -> PPTokens
    pptokens []     = [Char] -> PPTokens
    forall {a}. [Char] -> a
    error_emptylist [Char]
    "PPTokens"
    pptokens (PreprocToken
    x:[PreprocToken]
    xs) = (PPTokens -> PreprocToken -> PPTokens)
    -> PPTokens -> [PreprocToken] -> PPTokens
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl PPTokens -> PreprocToken -> PPTokens
    PPTokensCons (PreprocToken -> PPTokens
    PPTokensBase PreprocToken
    x) [PreprocToken]
    xs

    paramlist :: [ParamDecln] -> ParamList
    paramlist :: [ParamDecln] -> ParamList
    paramlist []     = [Char] -> ParamList
    forall {a}. [Char] -> a
    error_emptylist [Char]
    "ParamList"
    paramlist (ParamDecln
    x:[ParamDecln]
    xs) = (ParamList -> ParamDecln -> ParamList)
    -> ParamList -> [ParamDecln] -> ParamList
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl ParamList -> ParamDecln -> ParamList
    ParamCons (ParamDecln -> ParamList
    ParamBase ParamDecln
    x) [ParamDecln]
    xs

    voidparamlist :: [ParamDecln] -> ParamList
    voidparamlist :: [ParamDecln] -> ParamList
    voidparamlist [] =
      [ParamDecln] -> ParamList
    paramlist [DeclnSpecs -> Maybe DirectAbstractDeclr -> ParamDecln
    ParamDeclnAbstract (TypeSpec -> Maybe DeclnSpecs -> DeclnSpecs
    DeclnSpecsType TypeSpec
    TVoid Maybe DeclnSpecs
    forall a. Maybe a
    Nothing) Maybe DirectAbstractDeclr
    forall a. Maybe a
    Nothing]
    voidparamlist [ParamDecln]
    xs = [ParamDecln] -> ParamList
    paramlist [ParamDecln]
    xs