{-# LANGUAGE BangPatterns, OverloadedStrings, TupleSections #-}
{-|
Module      : Htcc.Parser.AST.Var.Init
Description : The C languge parser and AST constructor
Copyright   : (c) roki, 2019
License     : MIT
Maintainer  : falgon53@yahoo.co.jp
Stability   : experimental
Portability : POSIX

The C languge parser and AST constructor
-}
module Htcc.Parser.AST.Var.Init (
    Assign,
    validAssign,
    varInit
) where

import           Control.Conditional                             (ifM)
import           Control.Monad                                   (forM)
import           Control.Monad.Fix                               (fix)
import           Control.Monad.State                             (gets, put)
import           Control.Monad.Trans                             (lift)
import           Control.Monad.Trans.State                       (evalStateT)
import           Data.Bits                                       (Bits)
import qualified Data.ByteString                                 as B
import           Data.Foldable                                   (Foldable (..))
import           Data.List                                       (isPrefixOf,
                                                                  sortBy)
import qualified Data.Map.Strict                                 as M
import           Data.Maybe                                      (fromJust,
                                                                  fromMaybe,
                                                                  isNothing)
import qualified Data.Sequence                                   as SQ
import           Data.Tuple.Extra                                (dupe, first,
                                                                  second, snd3)
import           Prelude                                         hiding
                                                                  (toInteger)
import           Safe                                            (headMay)

import qualified Htcc.CRules.Types                               as CT
import           Htcc.Parser.AST.Core                            (ATKind (..),
                                                                  ATree (..),
                                                                  Treealizable (..),
                                                                  atAssign,
                                                                  atExprStmt,
                                                                  atMemberAcc,
                                                                  atNumLit,
                                                                  atUnary)
import           Htcc.Parser.AST.DeduceKind
import           Htcc.Parser.AST.Type                            (ASTConstruction,
                                                                  ASTState)
import           Htcc.Parser.ConstructionData
import           Htcc.Parser.ConstructionData.Scope.ManagedScope (ASTError)
import           Htcc.Parser.ConstructionData.Scope.Utils        (internalCE)
import           Htcc.Parser.Utils
import qualified Htcc.Tokenizer                                  as HT
import           Htcc.Utils                                      (dropSnd3,
                                                                  fou4, fst4,
                                                                  maybeToRight,
                                                                  second3, snd4,
                                                                  swap, thd4,
                                                                  tshow)
import           Htcc.Utils.CompilationState                     (isSatisfied,
                                                                  itemCWhen)

{-# INLINE validAssign #-}
-- | Check for valid substitutions
validAssign :: Eq i => HT.TokenLC i -> ATree i -> Either (ASTError i) (ATree i)
validAssign :: TokenLC i -> ATree i -> Either (ASTError i) (ATree i)
validAssign errPlaceholder :: TokenLC i
errPlaceholder x :: ATree i
x@(ATNode _ t :: StorageClass i
t _ _)
    | StorageClass i -> TypeKind i
forall (a :: * -> *) i. TypeKindBase a => a i -> TypeKind i
CT.toTypeKind StorageClass i
t TypeKind i -> TypeKind i -> Bool
forall a. Eq a => a -> a -> Bool
== TypeKind i
forall i. TypeKind i
CT.CTVoid = ASTError i -> Either (ASTError i) (ATree i)
forall a b. a -> Either a b
Left ("void value not ignored as it ought to be", TokenLC i
errPlaceholder)
    | Bool
otherwise = ATree i -> Either (ASTError i) (ATree i)
forall a b. b -> Either a b
Right ATree i
x
validAssign errPlaceholder :: TokenLC i
errPlaceholder _ = ASTError i -> Either (ASTError i) (ATree i)
forall a b. a -> Either a b
Left ("Expected to assign", TokenLC i
errPlaceholder)

desgNode :: (Num i, Ord i, Show i) => HT.TokenLC i -> ATree i -> [CT.Desg i]-> ConstructionData i -> Either (ASTError i) (ATree i)
desgNode :: TokenLC i
-> ATree i
-> [Desg i]
-> ConstructionData i
-> Either (ASTError i) (ATree i)
desgNode ident :: TokenLC i
ident rhs :: ATree i
rhs desg :: [Desg i]
desg sc :: ConstructionData i
sc = (ATree i -> ATree i)
-> Either (ASTError i) (ATree i) -> Either (ASTError i) (ATree i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ATree i -> ATree i
forall i. ATree i -> ATree i
atExprStmt (ATree i -> ATree i) -> (ATree i -> ATree i) -> ATree i -> ATree i
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ATree i -> ATree i -> ATree i) -> ATree i -> ATree i -> ATree i
forall a b c. (a -> b -> c) -> b -> a -> c
flip ATree i -> ATree i -> ATree i
forall i. ATree i -> ATree i -> ATree i
atAssign ATree i
rhs) (Either (ASTError i) (ATree i) -> Either (ASTError i) (ATree i))
-> Either (ASTError i) (ATree i) -> Either (ASTError i) (ATree i)
forall a b. (a -> b) -> a -> b
$ ((Desg i
  -> Either (ASTError i) (ATree i) -> Either (ASTError i) (ATree i))
 -> [Desg i] -> Either (ASTError i) (ATree i))
-> [Desg i]
-> (Desg i
    -> Either (ASTError i) (ATree i) -> Either (ASTError i) (ATree i))
-> Either (ASTError i) (ATree i)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((Desg i
 -> Either (ASTError i) (ATree i) -> Either (ASTError i) (ATree i))
-> Either (ASTError i) (ATree i)
-> [Desg i]
-> Either (ASTError i) (ATree i)
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
`foldr` Either (ASTError i) (ATree i)
ntRightLVarTree) [Desg i]
desg ((Desg i
  -> Either (ASTError i) (ATree i) -> Either (ASTError i) (ATree i))
 -> Either (ASTError i) (ATree i))
-> (Desg i
    -> Either (ASTError i) (ATree i) -> Either (ASTError i) (ATree i))
-> Either (ASTError i) (ATree i)
forall a b. (a -> b) -> a -> b
$ \idx :: Desg i
idx acc :: Either (ASTError i) (ATree i)
acc -> case Desg i
idx of
    CT.DesgIdx idx' :: i
idx' -> do
        ATree i
at <- Either (ASTError i) (ATree i)
acc
        ATree i
nd <- Maybe (ATree i) -> Either (ASTError i) (ATree i)
forall x. Maybe x -> Either (ASTError i) x
ntRightInvalidInitList (Maybe (ATree i) -> Either (ASTError i) (ATree i))
-> Maybe (ATree i) -> Either (ASTError i) (ATree i)
forall a b. (a -> b) -> a -> b
$ ATree i -> ATree i -> Maybe (ATree i)
forall i.
(Eq i, Ord i, Show i) =>
ATree i -> ATree i -> Maybe (ATree i)
addKind ATree i
at (ATree i -> Maybe (ATree i)) -> ATree i -> Maybe (ATree i)
forall a b. (a -> b) -> a -> b
$ i -> ATree i
forall i. i -> ATree i
atNumLit i
idx'
        (StorageClass i -> ATree i -> ATree i)
-> ATree i -> StorageClass i -> ATree i
forall a b c. (a -> b -> c) -> b -> a -> c
flip (ATKind i -> StorageClass i -> ATree i -> ATree i
forall i. ATKind i -> StorageClass i -> ATree i -> ATree i
atUnary ATKind i
forall a. ATKind a
ATDeref) ATree i
nd (StorageClass i -> ATree i)
-> Either (ASTError i) (StorageClass i)
-> Either (ASTError i) (ATree i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (StorageClass i) -> Either (ASTError i) (StorageClass i)
forall x. Maybe x -> Either (ASTError i) x
ntRightInvalidInitList (StorageClass i -> Maybe (StorageClass i)
forall a. CType a => a -> Maybe a
CT.deref (ATree i -> StorageClass i
forall a. ATree a -> StorageClass a
atype ATree i
nd))
    CT.DesgMem mem :: StructMember i
mem -> StructMember i -> ATree i -> ATree i
forall i. StructMember i -> ATree i -> ATree i
atMemberAcc StructMember i
mem (ATree i -> ATree i)
-> Either (ASTError i) (ATree i) -> Either (ASTError i) (ATree i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Either (ASTError i) (ATree i)
acc
    where
        ntRightInvalidInitList :: Maybe x -> Either (ASTError i) x
ntRightInvalidInitList = ASTError i -> forall x. Maybe x -> Either (ASTError i) x
forall e. e -> Maybe ~> Either e
maybeToRight ("invalid initializer-list", TokenLC i
forall i. Num i => TokenLC i
HT.emptyToken)
        ntRightLVarTree :: Either (ASTError i) (ATree i)
ntRightLVarTree = LVar i -> ATree i
forall (a :: * -> *) i. Treealizable a => a i -> ATree i
treealize (LVar i -> ATree i)
-> Either (ASTError i) (LVar i) -> Either (ASTError i) (ATree i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ASTError i -> Maybe (LVar i) -> Either (ASTError i) (LVar i)
forall e. e -> Maybe ~> Either e
maybeToRight (Text
internalCE, TokenLC i
forall i. Num i => TokenLC i
HT.emptyToken) (Text -> ConstructionData i -> Maybe (LVar i)
forall i. Text -> ConstructionData i -> Maybe (LVar i)
lookupLVar (Token i -> Text
forall a. Show a => a -> Text
tshow (Token i -> Text) -> Token i -> Text
forall a b. (a -> b) -> a -> b
$ TokenLC i -> Token i
forall a b. (a, b) -> b
snd TokenLC i
ident) ConstructionData i
sc)

initZero :: (Num i, Ord i, Show i, Enum i) => CT.TypeKind i -> HT.TokenLC i -> [CT.Desg i] -> ConstructionData i -> Either (ASTError i) [ATree i]
initZero :: TypeKind i
-> TokenLC i
-> [Desg i]
-> ConstructionData i
-> Either (ASTError i) [ATree i]
initZero (CT.CTArray n :: Natural
n t :: TypeKind i
t) ident :: TokenLC i
ident desg :: [Desg i]
desg sc :: ConstructionData i
sc = ([[ATree i]] -> [ATree i])
-> Either (ASTError i) [[ATree i]] -> Either (ASTError i) [ATree i]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [[ATree i]] -> [ATree i]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (Either (ASTError i) [[ATree i]] -> Either (ASTError i) [ATree i])
-> Either (ASTError i) [[ATree i]] -> Either (ASTError i) [ATree i]
forall a b. (a -> b) -> a -> b
$ [i]
-> (i -> Either (ASTError i) [ATree i])
-> Either (ASTError i) [[ATree i]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [0..Natural -> i
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Natural -> Natural
forall a. Enum a => a -> a
pred Natural
n)] ((i -> Either (ASTError i) [ATree i])
 -> Either (ASTError i) [[ATree i]])
-> (i -> Either (ASTError i) [ATree i])
-> Either (ASTError i) [[ATree i]]
forall a b. (a -> b) -> a -> b
$ ([Desg i] -> ConstructionData i -> Either (ASTError i) [ATree i])
-> ConstructionData i -> [Desg i] -> Either (ASTError i) [ATree i]
forall a b c. (a -> b -> c) -> b -> a -> c
flip (TypeKind i
-> TokenLC i
-> [Desg i]
-> ConstructionData i
-> Either (ASTError i) [ATree i]
forall i.
(Num i, Ord i, Show i, Enum i) =>
TypeKind i
-> TokenLC i
-> [Desg i]
-> ConstructionData i
-> Either (ASTError i) [ATree i]
initZero TypeKind i
t TokenLC i
ident) ConstructionData i
sc ([Desg i] -> Either (ASTError i) [ATree i])
-> (i -> [Desg i]) -> i -> Either (ASTError i) [ATree i]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Desg i -> [Desg i] -> [Desg i]
forall a. a -> [a] -> [a]
:[Desg i]
desg) (Desg i -> [Desg i]) -> (i -> Desg i) -> i -> [Desg i]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. i -> Desg i
forall i. i -> Desg i
CT.DesgIdx
initZero _ ident :: TokenLC i
ident desg :: [Desg i]
desg sc :: ConstructionData i
sc = (ATree i -> [ATree i] -> [ATree i]
forall a. a -> [a] -> [a]
:[]) (ATree i -> [ATree i])
-> Either (ASTError i) (ATree i) -> Either (ASTError i) [ATree i]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TokenLC i
-> ATree i
-> [Desg i]
-> ConstructionData i
-> Either (ASTError i) (ATree i)
forall i.
(Num i, Ord i, Show i) =>
TokenLC i
-> ATree i
-> [Desg i]
-> ConstructionData i
-> Either (ASTError i) (ATree i)
desgNode TokenLC i
ident (i -> ATree i
forall i. i -> ATree i
atNumLit 0) [Desg i]
desg ConstructionData i
sc

-- | needs parameters for Assign
type Assign i = [HT.TokenLC i] -> ATree i -> ConstructionData i -> ASTConstruction i

-- Designator initialization processing loop
-- Returns the consumed token list, the constructed tree, ConstructionData and the number of elements specified in designator
initLoop :: (Bits i, Integral i, Read i, Show i) =>
    Assign i -> CT.StorageClass i -> HT.TokenLC i -> [CT.Desg i] -> SQ.Seq (ATree i) -> HT.TokenLC i -> ASTState i ([HT.TokenLC i], SQ.Seq (ATree i), ConstructionData i, i)
initLoop :: Assign i
-> StorageClass i
-> TokenLC i
-> [Desg i]
-> Seq (ATree i)
-> TokenLC i
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
initLoop callback :: Assign i
callback t' :: StorageClass i
t' ident :: TokenLC i
ident desg :: [Desg i]
desg ai :: Seq (ATree i)
ai c :: TokenLC i
c = do
    ([TokenLC i], Seq (ATree i), ConstructionData i, i)
rs <- Seq (ATree i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
initLoop' Seq (ATree i)
ai
    (ConstructionData i -> Element [TokenLC i] -> ConstructionData i)
-> (Element [TokenLC i] -> Bool)
-> CompilationState
     (ConstructionData i) [TokenLC i] i (Maybe (Element [TokenLC i]))
forall mono cd i.
(MonoFoldable mono, IsSequence mono) =>
(cd -> Element mono -> cd)
-> (Element mono -> Bool)
-> CompilationState cd mono i (Maybe (Element mono))
itemCWhen ConstructionData i -> Element [TokenLC i] -> ConstructionData i
forall a b. a -> b -> a
const ((Token i -> Token i -> Bool
forall a. Eq a => a -> a -> Bool
==Text -> Token i
forall i. Text -> Token i
HT.TKReserved "}") (Token i -> Bool) -> (TokenLC i -> Token i) -> TokenLC i -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TokenLC i -> Token i
forall a b. (a, b) -> b
snd) StateT
  (ConstructionData i, [TokenLC i])
  (Either (ASTError i))
  (Maybe (TokenLC i))
-> (Maybe (TokenLC i)
    -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> (TokenLC i
    -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> Maybe (TokenLC i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Either
  (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Either
   (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i, i)
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b. (a -> b) -> a -> b
$ ASTError i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b. a -> Either a b
Left ("expected '}' token for '{'", TokenLC i
c)) (ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> TokenLC i
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b. a -> b -> a
const (ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
 -> TokenLC i
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> TokenLC i
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b. (a -> b) -> a -> b
$ Seq (ATree i)
-> i
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall i.
Seq (ATree i)
-> i
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
retCur (([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> Seq (ATree i)
forall a b c d. (a, b, c, d) -> b
snd4 ([TokenLC i], Seq (ATree i), ConstructionData i, i)
rs) (([TokenLC i], Seq (ATree i), ConstructionData i, i) -> i
forall a b c d. (a, b, c, d) -> d
fou4 ([TokenLC i], Seq (ATree i), ConstructionData i, i)
rs))
    where
        isEnd :: [(a, Token i)] -> Bool
isEnd = (Bool -> Bool -> Bool) -> (Bool, Bool) -> Bool
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Bool -> Bool -> Bool
(||) ((Bool, Bool) -> Bool)
-> ([(a, Token i)] -> (Bool, Bool)) -> [(a, Token i)] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Token i] -> Bool) -> ([Token i], Bool) -> (Bool, Bool)
forall a a' b. (a -> a') -> (a, b) -> (a', b)
first ([Token i] -> [Token i] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf [Text -> Token i
forall i. Text -> Token i
HT.TKReserved "}"]) (([Token i], Bool) -> (Bool, Bool))
-> ([(a, Token i)] -> ([Token i], Bool))
-> [(a, Token i)]
-> (Bool, Bool)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Token i] -> Bool) -> ([Token i], [Token i]) -> ([Token i], Bool)
forall b b' a. (b -> b') -> (a, b) -> (a, b')
second ([Token i] -> [Token i] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf [Text -> Token i
forall i. Text -> Token i
HT.TKReserved ",", Text -> Token i
forall i. Text -> Token i
HT.TKReserved "}"]) (([Token i], [Token i]) -> ([Token i], Bool))
-> ([(a, Token i)] -> ([Token i], [Token i]))
-> [(a, Token i)]
-> ([Token i], Bool)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Token i] -> ([Token i], [Token i])
forall a. a -> (a, a)
dupe ([Token i] -> ([Token i], [Token i]))
-> ([(a, Token i)] -> [Token i])
-> [(a, Token i)]
-> ([Token i], [Token i])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((a, Token i) -> Token i) -> [(a, Token i)] -> [Token i]
forall a b. (a -> b) -> [a] -> [b]
map (a, Token i) -> Token i
forall a b. (a, b) -> b
snd

        retCur :: SQ.Seq (ATree i) -> i -> ASTState i ([HT.TokenLC i], SQ.Seq (ATree i), ConstructionData i, i)
        retCur :: Seq (ATree i)
-> i
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
retCur ai' :: Seq (ATree i)
ai' n :: i
n = ([TokenLC i]
 -> ConstructionData i
 -> ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ([TokenLC i], ConstructionData i)
-> ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (,Seq (ATree i)
ai',,i
n) (([TokenLC i], ConstructionData i)
 -> ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> StateT
     (ConstructionData i, [TokenLC i])
     (Either (ASTError i))
     ([TokenLC i], ConstructionData i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((ConstructionData i, [TokenLC i])
 -> ([TokenLC i], ConstructionData i))
-> StateT
     (ConstructionData i, [TokenLC i])
     (Either (ASTError i))
     ([TokenLC i], ConstructionData i)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (ConstructionData i, [TokenLC i])
-> ([TokenLC i], ConstructionData i)
forall a b. (a, b) -> (b, a)
swap

        initLoop' :: Seq (ATree i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
initLoop' ai' :: Seq (ATree i)
ai' = case StorageClass i -> TypeKind i
forall (a :: * -> *) i. TypeKindBase a => a i -> TypeKind i
CT.toTypeKind StorageClass i
t' of
            CT.CTArray _ _ -> (((i, Seq (ATree i))
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> (i, Seq (ATree i))
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b. (a -> b) -> a -> b
$ (0, Seq (ATree i)
ai')) (((i, Seq (ATree i))
  -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ((((i, Seq (ATree i))
      -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
     -> (i, Seq (ATree i))
     -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
    -> (i, Seq (ATree i))
    -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> (((i, Seq (ATree i))
     -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
    -> (i, Seq (ATree i))
    -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (((i, Seq (ATree i))
  -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
 -> (i, Seq (ATree i))
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> (i, Seq (ATree i))
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a. (a -> a) -> a
fix ((((i, Seq (ATree i))
   -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
  -> (i, Seq (ATree i))
  -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> (((i, Seq (ATree i))
     -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
    -> (i, Seq (ATree i))
    -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b. (a -> b) -> a -> b
$ \f :: (i, Seq (ATree i))
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
f (!i
idx, rl :: Seq (ATree i)
rl) -> do
                Either
  (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
rs <- ([TokenLC i]
 -> ConstructionData i
 -> Either
      (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i))
-> ([TokenLC i], ConstructionData i)
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (Assign i
-> TokenLC i
-> Seq (ATree i)
-> [Desg i]
-> StorageClass i
-> [TokenLC i]
-> ConstructionData i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall i.
(Bits i, Integral i, Read i, Show i) =>
Assign i
-> TokenLC i
-> Seq (ATree i)
-> [Desg i]
-> StorageClass i
-> [TokenLC i]
-> ConstructionData i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
desgInit Assign i
callback TokenLC i
ident Seq (ATree i)
rl (i -> Desg i
forall i. i -> Desg i
CT.DesgIdx i
idxDesg i -> [Desg i] -> [Desg i]
forall a. a -> [a] -> [a]
:[Desg i]
desg) (StorageClass i
 -> [TokenLC i]
 -> ConstructionData i
 -> Either
      (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i))
-> StorageClass i
-> [TokenLC i]
-> ConstructionData i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall a b. (a -> b) -> a -> b
$ Maybe (StorageClass i) -> StorageClass i
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe (StorageClass i) -> StorageClass i)
-> Maybe (StorageClass i) -> StorageClass i
forall a b. (a -> b) -> a -> b
$ StorageClass i -> Maybe (StorageClass i)
forall a. CType a => a -> Maybe a
CT.deref StorageClass i
t') (([TokenLC i], ConstructionData i)
 -> Either
      (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i))
-> StateT
     (ConstructionData i, [TokenLC i])
     (Either (ASTError i))
     ([TokenLC i], ConstructionData i)
-> StateT
     (ConstructionData i, [TokenLC i])
     (Either (ASTError i))
     (Either
        (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((ConstructionData i, [TokenLC i])
 -> ([TokenLC i], ConstructionData i))
-> StateT
     (ConstructionData i, [TokenLC i])
     (Either (ASTError i))
     ([TokenLC i], ConstructionData i)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (ConstructionData i, [TokenLC i])
-> ([TokenLC i], ConstructionData i)
forall a b. (a, b) -> (b, a)
swap
                ((([TokenLC i], Seq (ATree i), ConstructionData i)
  -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
 -> Either
      (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
-> (([TokenLC i], Seq (ATree i), ConstructionData i)
    -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((ASTError i
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> (([TokenLC i], Seq (ATree i), ConstructionData i)
    -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Either
  (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Either
   (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i, i)
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> (ASTError i
    -> Either
         (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ASTError i
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ASTError i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b. a -> Either a b
Left)) Either
  (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
rs ((([TokenLC i], Seq (ATree i), ConstructionData i)
  -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> (([TokenLC i], Seq (ATree i), ConstructionData i)
    -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b. (a -> b) -> a -> b
$ \rs' :: ([TokenLC i], Seq (ATree i), ConstructionData i)
rs' -> do
                    (ConstructionData i, [TokenLC i])
-> StateT
     (ConstructionData i, [TokenLC i]) (Either (ASTError i)) ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put (([TokenLC i], ConstructionData i)
-> (ConstructionData i, [TokenLC i])
forall a b. (a, b) -> (b, a)
swap (([TokenLC i], ConstructionData i)
 -> (ConstructionData i, [TokenLC i]))
-> ([TokenLC i], ConstructionData i)
-> (ConstructionData i, [TokenLC i])
forall a b. (a -> b) -> a -> b
$ ([TokenLC i], Seq (ATree i), ConstructionData i)
-> ([TokenLC i], ConstructionData i)
forall a b c. (a, b, c) -> (a, c)
dropSnd3 ([TokenLC i], Seq (ATree i), ConstructionData i)
rs')
                    StateT (ConstructionData i, [TokenLC i]) (Either (ASTError i)) Bool
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall bool (m :: * -> *) a.
(ToBool bool, Monad m) =>
m bool -> m a -> m a -> m a
ifM (Bool -> Bool -> Bool
(||) (Bool -> Bool -> Bool)
-> StateT
     (ConstructionData i, [TokenLC i]) (Either (ASTError i)) Bool
-> StateT
     (ConstructionData i, [TokenLC i])
     (Either (ASTError i))
     (Bool -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([TokenLC i] -> Bool)
-> StateT
     (ConstructionData i, [TokenLC i]) (Either (ASTError i)) Bool
forall mono cd i. (mono -> Bool) -> CompilationState cd mono i Bool
isSatisfied [TokenLC i] -> Bool
forall a. [(a, Token i)] -> Bool
isEnd StateT
  (ConstructionData i, [TokenLC i])
  (Either (ASTError i))
  (Bool -> Bool)
-> StateT
     (ConstructionData i, [TokenLC i]) (Either (ASTError i)) Bool
-> StateT
     (ConstructionData i, [TokenLC i]) (Either (ASTError i)) Bool
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Maybe (TokenLC i) -> Bool
forall a. Maybe a -> Bool
isNothing (Maybe (TokenLC i) -> Bool)
-> StateT
     (ConstructionData i, [TokenLC i])
     (Either (ASTError i))
     (Maybe (TokenLC i))
-> StateT
     (ConstructionData i, [TokenLC i]) (Either (ASTError i)) Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ConstructionData i -> Element [TokenLC i] -> ConstructionData i)
-> (Element [TokenLC i] -> Bool)
-> CompilationState
     (ConstructionData i) [TokenLC i] i (Maybe (Element [TokenLC i]))
forall mono cd i.
(MonoFoldable mono, IsSequence mono) =>
(cd -> Element mono -> cd)
-> (Element mono -> Bool)
-> CompilationState cd mono i (Maybe (Element mono))
itemCWhen ConstructionData i -> Element [TokenLC i] -> ConstructionData i
forall a b. a -> b -> a
const ((Token i -> Token i -> Bool
forall a. Eq a => a -> a -> Bool
==Text -> Token i
forall i. Text -> Token i
HT.TKReserved ",") (Token i -> Bool) -> (TokenLC i -> Token i) -> TokenLC i -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TokenLC i -> Token i
forall a b. (a, b) -> b
snd))) (Seq (ATree i)
-> i
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall i.
Seq (ATree i)
-> i
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
retCur (([TokenLC i], Seq (ATree i), ConstructionData i) -> Seq (ATree i)
forall a b c. (a, b, c) -> b
snd3 ([TokenLC i], Seq (ATree i), ConstructionData i)
rs') (i
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> i
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b. (a -> b) -> a -> b
$ i -> i
forall a. Enum a => a -> a
succ i
idx) (ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b. (a -> b) -> a -> b
$ (i, Seq (ATree i))
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
f (i -> i
forall a. Enum a => a -> a
succ i
idx, ([TokenLC i], Seq (ATree i), ConstructionData i) -> Seq (ATree i)
forall a b c. (a, b, c) -> b
snd3 ([TokenLC i], Seq (ATree i), ConstructionData i)
rs')
            CT.CTStruct mems :: Map Text (StructMember i)
mems -> ((([StructMember i], Seq (ATree i), i)
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ([StructMember i], Seq (ATree i), i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b. (a -> b) -> a -> b
$ (Map Text (StructMember i) -> [StructMember i]
forall k a. Map k a -> [a]
M.elems Map Text (StructMember i)
mems, Seq (ATree i)
ai', 0)) ((([StructMember i], Seq (ATree i), i)
  -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> (((([StructMember i], Seq (ATree i), i)
      -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
     -> ([StructMember i], Seq (ATree i), i)
     -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
    -> ([StructMember i], Seq (ATree i), i)
    -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ((([StructMember i], Seq (ATree i), i)
     -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
    -> ([StructMember i], Seq (ATree i), i)
    -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((([StructMember i], Seq (ATree i), i)
  -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
 -> ([StructMember i], Seq (ATree i), i)
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ([StructMember i], Seq (ATree i), i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a. (a -> a) -> a
fix (((([StructMember i], Seq (ATree i), i)
   -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
  -> ([StructMember i], Seq (ATree i), i)
  -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ((([StructMember i], Seq (ATree i), i)
     -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
    -> ([StructMember i], Seq (ATree i), i)
    -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b. (a -> b) -> a -> b
$ \f :: ([StructMember i], Seq (ATree i), i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
f (mems' :: [StructMember i]
mems', rl :: Seq (ATree i)
rl, len :: i
len) -> if [StructMember i] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [StructMember i]
mems' then Seq (ATree i)
-> i
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall i.
Seq (ATree i)
-> i
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
retCur Seq (ATree i)
ai' i
len else do
                Either
  (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
rs <- ([TokenLC i]
 -> ConstructionData i
 -> Either
      (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i))
-> ([TokenLC i], ConstructionData i)
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (Assign i
-> TokenLC i
-> Seq (ATree i)
-> [Desg i]
-> StorageClass i
-> [TokenLC i]
-> ConstructionData i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall i.
(Bits i, Integral i, Read i, Show i) =>
Assign i
-> TokenLC i
-> Seq (ATree i)
-> [Desg i]
-> StorageClass i
-> [TokenLC i]
-> ConstructionData i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
desgInit Assign i
callback TokenLC i
ident Seq (ATree i)
rl (StructMember i -> Desg i
forall i. StructMember i -> Desg i
CT.DesgMem ([StructMember i] -> StructMember i
forall a. [a] -> a
head [StructMember i]
mems')Desg i -> [Desg i] -> [Desg i]
forall a. a -> [a] -> [a]
:[Desg i]
desg) (StorageClass i
 -> [TokenLC i]
 -> ConstructionData i
 -> Either
      (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i))
-> StorageClass i
-> [TokenLC i]
-> ConstructionData i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall a b. (a -> b) -> a -> b
$ TypeKind i -> StorageClass i
forall i. TypeKind i -> StorageClass i
CT.SCAuto (TypeKind i -> StorageClass i) -> TypeKind i -> StorageClass i
forall a b. (a -> b) -> a -> b
$ StructMember i -> TypeKind i
forall i. StructMember i -> TypeKind i
CT.smType ([StructMember i] -> StructMember i
forall a. [a] -> a
head [StructMember i]
mems')) (([TokenLC i], ConstructionData i)
 -> Either
      (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i))
-> StateT
     (ConstructionData i, [TokenLC i])
     (Either (ASTError i))
     ([TokenLC i], ConstructionData i)
-> StateT
     (ConstructionData i, [TokenLC i])
     (Either (ASTError i))
     (Either
        (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((ConstructionData i, [TokenLC i])
 -> ([TokenLC i], ConstructionData i))
-> StateT
     (ConstructionData i, [TokenLC i])
     (Either (ASTError i))
     ([TokenLC i], ConstructionData i)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (ConstructionData i, [TokenLC i])
-> ([TokenLC i], ConstructionData i)
forall a b. (a, b) -> (b, a)
swap
                ((([TokenLC i], Seq (ATree i), ConstructionData i)
  -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
 -> Either
      (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
-> (([TokenLC i], Seq (ATree i), ConstructionData i)
    -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((ASTError i
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> (([TokenLC i], Seq (ATree i), ConstructionData i)
    -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Either
  (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Either
   (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i, i)
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> (ASTError i
    -> Either
         (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ASTError i
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ASTError i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b. a -> Either a b
Left)) Either
  (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
rs ((([TokenLC i], Seq (ATree i), ConstructionData i)
  -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> (([TokenLC i], Seq (ATree i), ConstructionData i)
    -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b. (a -> b) -> a -> b
$ \rs' :: ([TokenLC i], Seq (ATree i), ConstructionData i)
rs' -> do
                    (ConstructionData i, [TokenLC i])
-> StateT
     (ConstructionData i, [TokenLC i]) (Either (ASTError i)) ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put (([TokenLC i], ConstructionData i)
-> (ConstructionData i, [TokenLC i])
forall a b. (a, b) -> (b, a)
swap (([TokenLC i], ConstructionData i)
 -> (ConstructionData i, [TokenLC i]))
-> ([TokenLC i], ConstructionData i)
-> (ConstructionData i, [TokenLC i])
forall a b. (a -> b) -> a -> b
$ ([TokenLC i], Seq (ATree i), ConstructionData i)
-> ([TokenLC i], ConstructionData i)
forall a b c. (a, b, c) -> (a, c)
dropSnd3 ([TokenLC i], Seq (ATree i), ConstructionData i)
rs')
                    StateT (ConstructionData i, [TokenLC i]) (Either (ASTError i)) Bool
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall bool (m :: * -> *) a.
(ToBool bool, Monad m) =>
m bool -> m a -> m a -> m a
ifM (Bool -> Bool -> Bool
(||) (Bool -> Bool -> Bool)
-> StateT
     (ConstructionData i, [TokenLC i]) (Either (ASTError i)) Bool
-> StateT
     (ConstructionData i, [TokenLC i])
     (Either (ASTError i))
     (Bool -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([TokenLC i] -> Bool)
-> StateT
     (ConstructionData i, [TokenLC i]) (Either (ASTError i)) Bool
forall mono cd i. (mono -> Bool) -> CompilationState cd mono i Bool
isSatisfied [TokenLC i] -> Bool
forall a. [(a, Token i)] -> Bool
isEnd StateT
  (ConstructionData i, [TokenLC i])
  (Either (ASTError i))
  (Bool -> Bool)
-> StateT
     (ConstructionData i, [TokenLC i]) (Either (ASTError i)) Bool
-> StateT
     (ConstructionData i, [TokenLC i]) (Either (ASTError i)) Bool
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Maybe (TokenLC i) -> Bool
forall a. Maybe a -> Bool
isNothing (Maybe (TokenLC i) -> Bool)
-> StateT
     (ConstructionData i, [TokenLC i])
     (Either (ASTError i))
     (Maybe (TokenLC i))
-> StateT
     (ConstructionData i, [TokenLC i]) (Either (ASTError i)) Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ConstructionData i -> Element [TokenLC i] -> ConstructionData i)
-> (Element [TokenLC i] -> Bool)
-> CompilationState
     (ConstructionData i) [TokenLC i] i (Maybe (Element [TokenLC i]))
forall mono cd i.
(MonoFoldable mono, IsSequence mono) =>
(cd -> Element mono -> cd)
-> (Element mono -> Bool)
-> CompilationState cd mono i (Maybe (Element mono))
itemCWhen ConstructionData i -> Element [TokenLC i] -> ConstructionData i
forall a b. a -> b -> a
const ((Token i -> Token i -> Bool
forall a. Eq a => a -> a -> Bool
==Text -> Token i
forall i. Text -> Token i
HT.TKReserved ",") (Token i -> Bool) -> (TokenLC i -> Token i) -> TokenLC i -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TokenLC i -> Token i
forall a b. (a, b) -> b
snd))) (Seq (ATree i)
-> i
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall i.
Seq (ATree i)
-> i
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
retCur (([TokenLC i], Seq (ATree i), ConstructionData i) -> Seq (ATree i)
forall a b c. (a, b, c) -> b
snd3 ([TokenLC i], Seq (ATree i), ConstructionData i)
rs') (i
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> i
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b. (a -> b) -> a -> b
$ i -> i
forall a. Enum a => a -> a
succ i
len) (ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b. (a -> b) -> a -> b
$ ([StructMember i], Seq (ATree i), i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
f ([StructMember i] -> [StructMember i]
forall a. [a] -> [a]
tail [StructMember i]
mems', ([TokenLC i], Seq (ATree i), ConstructionData i) -> Seq (ATree i)
forall a b c. (a, b, c) -> b
snd3 ([TokenLC i], Seq (ATree i), ConstructionData i)
rs', i -> i
forall a. Enum a => a -> a
succ i
len)
            _ -> Either
  (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Either
   (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i, i)
 -> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i))
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b. (a -> b) -> a -> b
$ ASTError i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall a b. a -> Either a b
Left (Text
internalCE, TokenLC i
forall i. Num i => TokenLC i
HT.emptyToken)

-- For initializer-list.
-- For example, the declaration @int x[2][2] = { { 1, 2 }, { 3, 4 } };@ is converted to @x[2][2]; x[0][0] = 1; x[0][1] = 2; x[1][0] = 3; x[1][1] = 4;@.
desgInit :: (Bits i, Integral i, Read i, Show i) =>
    Assign i -> HT.TokenLC i -> SQ.Seq (ATree i) -> [CT.Desg i] -> CT.StorageClass i -> [HT.TokenLC i] -> ConstructionData i ->
    Either (ASTError i) ([HT.TokenLC i], SQ.Seq (ATree i), ConstructionData i)
desgInit :: Assign i
-> TokenLC i
-> Seq (ATree i)
-> [Desg i]
-> StorageClass i
-> [TokenLC i]
-> ConstructionData i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
desgInit callback :: Assign i
callback ident :: TokenLC i
ident ai :: Seq (ATree i)
ai desg :: [Desg i]
desg t' :: StorageClass i
t' xs' :: [TokenLC i]
xs' scp :: ConstructionData i
scp
    -- initializer-string
    | StorageClass i -> Bool
forall (a :: * -> *) i. TypeKindBase a => a i -> Bool
CT.isArray StorageClass i
t' Bool -> Bool -> Bool
&& Bool -> (StorageClass i -> Bool) -> Maybe (StorageClass i) -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False ((TypeKind i -> TypeKind i -> Bool
forall a. Eq a => a -> a -> Bool
==TypeKind i
forall i. TypeKind i
CT.CTChar) (TypeKind i -> Bool)
-> (StorageClass i -> TypeKind i) -> StorageClass i -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StorageClass i -> TypeKind i
forall (a :: * -> *) i. TypeKindBase a => a i -> TypeKind i
CT.toTypeKind) (StorageClass i -> Maybe (StorageClass i)
forall a. CType a => a -> Maybe a
CT.deref StorageClass i
t') Bool -> Bool -> Bool
&& Bool -> (TokenLC i -> Bool) -> Maybe (TokenLC i) -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False (Token i -> Bool
forall i. Token i -> Bool
HT.isTKString (Token i -> Bool) -> (TokenLC i -> Token i) -> TokenLC i -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TokenLC i -> Token i
forall a b. (a, b) -> b
snd) ([TokenLC i] -> Maybe (TokenLC i)
forall a. [a] -> Maybe a
headMay [TokenLC i]
xs') = if StorageClass i -> Bool
forall (a :: * -> *) i. IncompleteBase a => a i -> Bool
CT.isIncompleteArray StorageClass i
t' then
        case TokenLC i -> Token i
forall a b. (a, b) -> b
snd ([TokenLC i] -> TokenLC i
forall a. [a] -> a
head [TokenLC i]
xs') of
            (HT.TKString s :: ByteString
s) -> let newt :: StorageClass i
newt = Int -> StorageClass i
forall a. Integral a => a -> StorageClass i
arTypeFromLen (ByteString -> Int
B.length ByteString
s) in StorageClass i
-> TokenLC i
-> ConstructionData i
-> Either (ASTError i) (ATree i, ConstructionData i)
forall i.
(Integral i, Bits i) =>
StorageClass i
-> TokenLC i
-> ConstructionData i
-> Either (ASTError i) (ATree i, ConstructionData i)
addLVar StorageClass i
newt TokenLC i
ident ConstructionData i
scp Either (ASTError i) (ATree i, ConstructionData i)
-> ((ATree i, ConstructionData i)
    -> Either
         (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i))
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Assign i
-> TokenLC i
-> Seq (ATree i)
-> [Desg i]
-> StorageClass i
-> [TokenLC i]
-> ConstructionData i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall i.
(Bits i, Integral i, Read i, Show i) =>
Assign i
-> TokenLC i
-> Seq (ATree i)
-> [Desg i]
-> StorageClass i
-> [TokenLC i]
-> ConstructionData i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
desgInit Assign i
callback TokenLC i
ident Seq (ATree i)
ai [Desg i]
desg StorageClass i
newt [TokenLC i]
xs' (ConstructionData i
 -> Either
      (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i))
-> ((ATree i, ConstructionData i) -> ConstructionData i)
-> (ATree i, ConstructionData i)
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ATree i, ConstructionData i) -> ConstructionData i
forall a b. (a, b) -> b
snd
            _ -> ASTError i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall a b. a -> Either a b
Left (Text
internalCE, TokenLC i
forall i. Num i => TokenLC i
HT.emptyToken) -- should not reach here
        else case (TokenLC i -> Token i
forall a b. (a, b) -> b
snd ([TokenLC i] -> TokenLC i
forall a. [a] -> a
head [TokenLC i]
xs'), StorageClass i -> TypeKind i
forall (a :: * -> *) i. TypeKindBase a => a i -> TypeKind i
CT.toTypeKind StorageClass i
t') of
            (HT.TKString s :: ByteString
s, CT.CTArray n :: Natural
n _) -> let s' :: ByteString
s' = ByteString
s ByteString -> ByteString -> ByteString
`B.append` [Word8] -> ByteString
B.pack (Int -> Word8 -> [Word8]
forall a. Int -> a -> [a]
replicate (Natural -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Natural
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int -> Int
forall a. Enum a => a -> a
pred (ByteString -> Int
B.length ByteString
s)) (Word8 -> [Word8]) -> Word8 -> [Word8]
forall a b. (a -> b) -> a -> b
$ Int -> Word8
forall a. Enum a => Int -> a
toEnum 0) in
                ([ATree i] -> ([TokenLC i], Seq (ATree i), ConstructionData i))
-> Either (ASTError i) [ATree i]
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (([TokenLC i] -> [TokenLC i]
forall a. [a] -> [a]
tail [TokenLC i]
xs',, if Natural -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Natural
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int -> Int
forall a. Enum a => a -> a
pred (ByteString -> Int
B.length ByteString
s) then Text -> TokenLC i -> ConstructionData i -> ConstructionData i
forall i.
Text -> TokenLC i -> ConstructionData i -> ConstructionData i
pushWarn "initializer-string for char array is too long" ([TokenLC i] -> TokenLC i
forall a. [a] -> a
head [TokenLC i]
xs') ConstructionData i
scp else ConstructionData i
scp) (Seq (ATree i) -> ([TokenLC i], Seq (ATree i), ConstructionData i))
-> ([ATree i] -> Seq (ATree i))
-> [ATree i]
-> ([TokenLC i], Seq (ATree i), ConstructionData i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                    (Seq (ATree i)
ai Seq (ATree i) -> Seq (ATree i) -> Seq (ATree i)
forall a. Seq a -> Seq a -> Seq a
SQ.><) (Seq (ATree i) -> Seq (ATree i))
-> ([ATree i] -> Seq (ATree i)) -> [ATree i] -> Seq (ATree i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ATree i] -> Seq (ATree i)
forall a. [a] -> Seq a
SQ.fromList) (Either (ASTError i) [ATree i]
 -> Either
      (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i))
-> Either (ASTError i) [ATree i]
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall a b. (a -> b) -> a -> b
$ ((ATree i, [Desg i]) -> Either (ASTError i) (ATree i))
-> [(ATree i, [Desg i])] -> Either (ASTError i) [ATree i]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (((ConstructionData i -> Either (ASTError i) (ATree i))
 -> ConstructionData i -> Either (ASTError i) (ATree i))
-> ConstructionData i
-> (ConstructionData i -> Either (ASTError i) (ATree i))
-> Either (ASTError i) (ATree i)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (ConstructionData i -> Either (ASTError i) (ATree i))
-> ConstructionData i -> Either (ASTError i) (ATree i)
forall a. a -> a
id ConstructionData i
scp ((ConstructionData i -> Either (ASTError i) (ATree i))
 -> Either (ASTError i) (ATree i))
-> ((ATree i, [Desg i])
    -> ConstructionData i -> Either (ASTError i) (ATree i))
-> (ATree i, [Desg i])
-> Either (ASTError i) (ATree i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ATree i
 -> [Desg i] -> ConstructionData i -> Either (ASTError i) (ATree i))
-> (ATree i, [Desg i])
-> ConstructionData i
-> Either (ASTError i) (ATree i)
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (TokenLC i
-> ATree i
-> [Desg i]
-> ConstructionData i
-> Either (ASTError i) (ATree i)
forall i.
(Num i, Ord i, Show i) =>
TokenLC i
-> ATree i
-> [Desg i]
-> ConstructionData i
-> Either (ASTError i) (ATree i)
desgNode TokenLC i
ident)) ([(ATree i, [Desg i])] -> Either (ASTError i) [ATree i])
-> [(ATree i, [Desg i])] -> Either (ASTError i) [ATree i]
forall a b. (a -> b) -> a -> b
$ (Word8 -> [Desg i] -> (ATree i, [Desg i]))
-> [Word8] -> [[Desg i]] -> [(ATree i, [Desg i])]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith ((([Desg i] -> (ATree i, [Desg i]))
 -> ([Desg i] -> [Desg i]) -> [Desg i] -> (ATree i, [Desg i]))
-> ([Desg i] -> [Desg i])
-> ([Desg i] -> (ATree i, [Desg i]))
-> [Desg i]
-> (ATree i, [Desg i])
forall a b c. (a -> b -> c) -> b -> a -> c
flip ([Desg i] -> (ATree i, [Desg i]))
-> ([Desg i] -> [Desg i]) -> [Desg i] -> (ATree i, [Desg i])
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) ([Desg i] -> [Desg i] -> [Desg i]
forall a. [a] -> [a] -> [a]
++[Desg i]
desg) (([Desg i] -> (ATree i, [Desg i]))
 -> [Desg i] -> (ATree i, [Desg i]))
-> (Word8 -> [Desg i] -> (ATree i, [Desg i]))
-> Word8
-> [Desg i]
-> (ATree i, [Desg i])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (,) (ATree i -> [Desg i] -> (ATree i, [Desg i]))
-> (Word8 -> ATree i) -> Word8 -> [Desg i] -> (ATree i, [Desg i])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. i -> ATree i
forall i. i -> ATree i
atNumLit (i -> ATree i) -> (Word8 -> i) -> Word8 -> ATree i
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> i
forall a b. (Integral a, Num b) => a -> b
fromIntegral) (ByteString -> [Word8]
B.unpack ByteString
s') ([[Desg i]] -> [(ATree i, [Desg i])])
-> [[Desg i]] -> [(ATree i, [Desg i])]
forall a b. (a -> b) -> a -> b
$
                        ([Desg i] -> [Desg i] -> Ordering) -> [[Desg i]] -> [[Desg i]]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy ((([Desg i] -> Ordering)
 -> ([Desg i] -> [Desg i]) -> [Desg i] -> Ordering)
-> ([Desg i] -> [Desg i])
-> ([Desg i] -> Ordering)
-> [Desg i]
-> Ordering
forall a b c. (a -> b -> c) -> b -> a -> c
flip ([Desg i] -> Ordering)
-> ([Desg i] -> [Desg i]) -> [Desg i] -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) [Desg i] -> [Desg i]
forall a. [a] -> [a]
reverse (([Desg i] -> Ordering) -> [Desg i] -> Ordering)
-> ([Desg i] -> [Desg i] -> Ordering)
-> [Desg i]
-> [Desg i]
-> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Desg i] -> [Desg i] -> Ordering
forall a. Ord a => a -> a -> Ordering
compare ([Desg i] -> [Desg i] -> Ordering)
-> ([Desg i] -> [Desg i]) -> [Desg i] -> [Desg i] -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Desg i] -> [Desg i]
forall a. [a] -> [a]
reverse) ([[Desg i]] -> [[Desg i]]) -> [[Desg i]] -> [[Desg i]]
forall a b. (a -> b) -> a -> b
$ TypeKind i -> [[Desg i]]
forall i. Integral i => TypeKind i -> [[Desg i]]
CT.accessibleIndices (TypeKind i -> [[Desg i]]) -> TypeKind i -> [[Desg i]]
forall a b. (a -> b) -> a -> b
$ StorageClass i -> TypeKind i
forall (a :: * -> *) i. TypeKindBase a => a i -> TypeKind i
CT.toTypeKind StorageClass i
t'
            _ -> ASTError i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall a b. a -> Either a b
Left (Text
internalCE, TokenLC i
forall i. Num i => TokenLC i
HT.emptyToken) -- should not reach here
    -- Non-string initializer-list
    | StorageClass i -> Bool
forall (a :: * -> *) i. TypeKindBase a => a i -> Bool
CT.isArray StorageClass i
t' = case [TokenLC i]
xs' of -- incomplete dattara takeExps de kazeru
        -- Zero initialization
        (_, HT.TKReserved "{"):(_, HT.TKReserved "}"):ds :: [TokenLC i]
ds -> ([ATree i] -> ([TokenLC i], Seq (ATree i), ConstructionData i))
-> Either (ASTError i) [ATree i]
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (([TokenLC i]
ds,, ConstructionData i
scp) (Seq (ATree i) -> ([TokenLC i], Seq (ATree i), ConstructionData i))
-> ([ATree i] -> Seq (ATree i))
-> [ATree i]
-> ([TokenLC i], Seq (ATree i), ConstructionData i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Seq (ATree i)
ai Seq (ATree i) -> Seq (ATree i) -> Seq (ATree i)
forall a. Seq a -> Seq a -> Seq a
SQ.><) (Seq (ATree i) -> Seq (ATree i))
-> ([ATree i] -> Seq (ATree i)) -> [ATree i] -> Seq (ATree i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ATree i] -> Seq (ATree i)
forall a. [a] -> Seq a
SQ.fromList) (Either (ASTError i) [ATree i]
 -> Either
      (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i))
-> Either (ASTError i) [ATree i]
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall a b. (a -> b) -> a -> b
$
            ([Desg i] -> Either (ASTError i) (ATree i))
-> [[Desg i]] -> Either (ASTError i) [ATree i]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (([Desg i] -> ConstructionData i -> Either (ASTError i) (ATree i))
-> ConstructionData i -> [Desg i] -> Either (ASTError i) (ATree i)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (TokenLC i
-> ATree i
-> [Desg i]
-> ConstructionData i
-> Either (ASTError i) (ATree i)
forall i.
(Num i, Ord i, Show i) =>
TokenLC i
-> ATree i
-> [Desg i]
-> ConstructionData i
-> Either (ASTError i) (ATree i)
desgNode TokenLC i
ident (ATree i
 -> [Desg i] -> ConstructionData i -> Either (ASTError i) (ATree i))
-> ATree i
-> [Desg i]
-> ConstructionData i
-> Either (ASTError i) (ATree i)
forall a b. (a -> b) -> a -> b
$ i -> ATree i
forall i. i -> ATree i
atNumLit 0) ConstructionData i
scp ([Desg i] -> Either (ASTError i) (ATree i))
-> ([Desg i] -> [Desg i])
-> [Desg i]
-> Either (ASTError i) (ATree i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Desg i] -> [Desg i] -> [Desg i]
forall a. [a] -> [a] -> [a]
++[Desg i]
desg)) ([[Desg i]] -> Either (ASTError i) [ATree i])
-> [[Desg i]] -> Either (ASTError i) [ATree i]
forall a b. (a -> b) -> a -> b
$ TypeKind i -> [[Desg i]]
forall i. Integral i => TypeKind i -> [[Desg i]]
CT.accessibleIndices (TypeKind i -> [[Desg i]]) -> TypeKind i -> [[Desg i]]
forall a b. (a -> b) -> a -> b
$ StorageClass i -> TypeKind i
forall (a :: * -> *) i. TypeKindBase a => a i -> TypeKind i
CT.toTypeKind StorageClass i
t'
        -- The specified initializer-list of initialization elements
        c :: TokenLC i
c@(_, HT.TKReserved "{"):ds :: [TokenLC i]
ds
            | StorageClass i -> Bool
forall (a :: * -> *) i. IncompleteBase a => a i -> Bool
CT.isIncompleteArray StorageClass i
t' -> [TokenLC i] -> Either (ASTError i) (StorageClass i)
toComplete (TokenLC i
cTokenLC i -> [TokenLC i] -> [TokenLC i]
forall a. a -> [a] -> [a]
:[TokenLC i]
ds) Either (ASTError i) (StorageClass i)
-> (StorageClass i
    -> Either
         (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i))
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \newt :: StorageClass i
newt -> StorageClass i
-> TokenLC i
-> ConstructionData i
-> Either (ASTError i) (ATree i, ConstructionData i)
forall i.
(Integral i, Bits i) =>
StorageClass i
-> TokenLC i
-> ConstructionData i
-> Either (ASTError i) (ATree i, ConstructionData i)
addLVar StorageClass i
newt TokenLC i
ident ConstructionData i
scp Either (ASTError i) (ATree i, ConstructionData i)
-> ((ATree i, ConstructionData i)
    -> Either
         (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i))
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Assign i
-> TokenLC i
-> Seq (ATree i)
-> [Desg i]
-> StorageClass i
-> [TokenLC i]
-> ConstructionData i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall i.
(Bits i, Integral i, Read i, Show i) =>
Assign i
-> TokenLC i
-> Seq (ATree i)
-> [Desg i]
-> StorageClass i
-> [TokenLC i]
-> ConstructionData i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
desgInit Assign i
callback TokenLC i
ident Seq (ATree i)
ai [Desg i]
desg StorageClass i
newt [TokenLC i]
xs' (ConstructionData i
 -> Either
      (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i))
-> ((ATree i, ConstructionData i) -> ConstructionData i)
-> (ATree i, ConstructionData i)
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ATree i, ConstructionData i) -> ConstructionData i
forall a b. (a, b) -> b
snd
            | Bool
otherwise -> case StorageClass i -> TypeKind i
forall (a :: * -> *) i. TypeKindBase a => a i -> TypeKind i
CT.toTypeKind StorageClass i
t' of
                CT.CTArray n :: Natural
n bt :: TypeKind i
bt -> do
                    ([TokenLC i], Seq (ATree i), ConstructionData i, i)
rs <- StateT
  (ConstructionData i, [TokenLC i])
  (Either (ASTError i))
  ([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> (ConstructionData i, [TokenLC i])
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
evalStateT (Assign i
-> StorageClass i
-> TokenLC i
-> [Desg i]
-> Seq (ATree i)
-> TokenLC i
-> StateT
     (ConstructionData i, [TokenLC i])
     (Either (ASTError i))
     ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall i.
(Bits i, Integral i, Read i, Show i) =>
Assign i
-> StorageClass i
-> TokenLC i
-> [Desg i]
-> Seq (ATree i)
-> TokenLC i
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
initLoop Assign i
callback StorageClass i
t' TokenLC i
ident [Desg i]
desg Seq (ATree i)
ai TokenLC i
c) (ConstructionData i
scp, [TokenLC i]
ds)
                    ([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> Either (ASTError i) [[ATree i]]
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall (f :: * -> *) (t :: * -> *) a c d.
(Functor f, Foldable t) =>
(a, Seq (ATree i), c, d)
-> f (t [ATree i]) -> f (a, Seq (ATree i), c)
zeroResult ([TokenLC i], Seq (ATree i), ConstructionData i, i)
rs (Either (ASTError i) [[ATree i]]
 -> Either
      (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i))
-> Either (ASTError i) [[ATree i]]
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall a b. (a -> b) -> a -> b
$ [i]
-> (i -> Either (ASTError i) [ATree i])
-> Either (ASTError i) [[ATree i]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [i -> i
forall a b. (Integral a, Num b) => a -> b
fromIntegral (([TokenLC i], Seq (ATree i), ConstructionData i, i) -> i
forall a b c d. (a, b, c, d) -> d
fou4 ([TokenLC i], Seq (ATree i), ConstructionData i, i)
rs)..i -> i
forall a. Enum a => a -> a
pred (i -> i) -> i -> i
forall a b. (a -> b) -> a -> b
$ Natural -> i
forall a b. (Integral a, Num b) => a -> b
fromIntegral Natural
n] ((i -> Either (ASTError i) [ATree i])
 -> Either (ASTError i) [[ATree i]])
-> (i -> Either (ASTError i) [ATree i])
-> Either (ASTError i) [[ATree i]]
forall a b. (a -> b) -> a -> b
$ \idx :: i
idx -> TypeKind i
-> TokenLC i
-> [Desg i]
-> ConstructionData i
-> Either (ASTError i) [ATree i]
forall i.
(Num i, Ord i, Show i, Enum i) =>
TypeKind i
-> TokenLC i
-> [Desg i]
-> ConstructionData i
-> Either (ASTError i) [ATree i]
initZero TypeKind i
bt TokenLC i
ident (i -> Desg i
forall i. i -> Desg i
CT.DesgIdx i
idxDesg i -> [Desg i] -> [Desg i]
forall a. a -> [a] -> [a]
:[Desg i]
desg) (([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> ConstructionData i
forall a b c d. (a, b, c, d) -> c
thd4 ([TokenLC i], Seq (ATree i), ConstructionData i, i)
rs)
                _ -> ASTError i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall a b. a -> Either a b
Left (Text
internalCE, TokenLC i
forall i. Num i => TokenLC i
HT.emptyToken)
        _ ->  ASTError i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall a b. a -> Either a b
Left ("expected { initializer-list } or { initializer-list , }", if Bool -> Bool
not ([TokenLC i] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TokenLC i]
xs') then [TokenLC i] -> TokenLC i
forall a. [a] -> a
head [TokenLC i]
xs' else TokenLC i
forall i. Num i => TokenLC i
HT.emptyToken)
    -- struct initializer
    | StorageClass i -> Bool
forall (a :: * -> *) i. TypeKindBase a => a i -> Bool
CT.isCTStruct StorageClass i
t' = case ([TokenLC i]
xs', StorageClass i -> TypeKind i
forall (a :: * -> *) i. TypeKindBase a => a i -> TypeKind i
CT.toTypeKind StorageClass i
t') of
        ((_, HT.TKReserved "{"):(_, HT.TKReserved "}"):ds :: [TokenLC i]
ds, CT.CTStruct mems :: Map Text (StructMember i)
mems) -> ([[ATree i]] -> ([TokenLC i], Seq (ATree i), ConstructionData i))
-> Either (ASTError i) [[ATree i]]
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (([TokenLC i]
ds,,ConstructionData i
scp) (Seq (ATree i) -> ([TokenLC i], Seq (ATree i), ConstructionData i))
-> ([[ATree i]] -> Seq (ATree i))
-> [[ATree i]]
-> ([TokenLC i], Seq (ATree i), ConstructionData i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Seq (ATree i)
ai Seq (ATree i) -> Seq (ATree i) -> Seq (ATree i)
forall a. Seq a -> Seq a -> Seq a
SQ.><) (Seq (ATree i) -> Seq (ATree i))
-> ([[ATree i]] -> Seq (ATree i)) -> [[ATree i]] -> Seq (ATree i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ATree i] -> Seq (ATree i)
forall a. [a] -> Seq a
SQ.fromList ([ATree i] -> Seq (ATree i))
-> ([[ATree i]] -> [ATree i]) -> [[ATree i]] -> Seq (ATree i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[ATree i]] -> [ATree i]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat) (Either (ASTError i) [[ATree i]]
 -> Either
      (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i))
-> Either (ASTError i) [[ATree i]]
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall a b. (a -> b) -> a -> b
$ [StructMember i]
-> (StructMember i -> Either (ASTError i) [ATree i])
-> Either (ASTError i) [[ATree i]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM (Map Text (StructMember i) -> [StructMember i]
forall k a. Map k a -> [a]
M.elems Map Text (StructMember i)
mems) ((StructMember i -> Either (ASTError i) [ATree i])
 -> Either (ASTError i) [[ATree i]])
-> (StructMember i -> Either (ASTError i) [ATree i])
-> Either (ASTError i) [[ATree i]]
forall a b. (a -> b) -> a -> b
$ \mem :: StructMember i
mem ->
            TypeKind i
-> TokenLC i
-> [Desg i]
-> ConstructionData i
-> Either (ASTError i) [ATree i]
forall i.
(Num i, Ord i, Show i, Enum i) =>
TypeKind i
-> TokenLC i
-> [Desg i]
-> ConstructionData i
-> Either (ASTError i) [ATree i]
initZero (StructMember i -> TypeKind i
forall i. StructMember i -> TypeKind i
CT.smType StructMember i
mem) TokenLC i
ident (StructMember i -> Desg i
forall i. StructMember i -> Desg i
CT.DesgMem StructMember i
memDesg i -> [Desg i] -> [Desg i]
forall a. a -> [a] -> [a]
:[Desg i]
desg) ConstructionData i
scp
        (c :: TokenLC i
c@(_, HT.TKReserved "{"):ds :: [TokenLC i]
ds, CT.CTStruct mems :: Map Text (StructMember i)
mems) -> do
            ([TokenLC i], Seq (ATree i), ConstructionData i, i)
rs <- StateT
  (ConstructionData i, [TokenLC i])
  (Either (ASTError i))
  ([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> (ConstructionData i, [TokenLC i])
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
evalStateT (Assign i
-> StorageClass i
-> TokenLC i
-> [Desg i]
-> Seq (ATree i)
-> TokenLC i
-> StateT
     (ConstructionData i, [TokenLC i])
     (Either (ASTError i))
     ([TokenLC i], Seq (ATree i), ConstructionData i, i)
forall i.
(Bits i, Integral i, Read i, Show i) =>
Assign i
-> StorageClass i
-> TokenLC i
-> [Desg i]
-> Seq (ATree i)
-> TokenLC i
-> ASTState i ([TokenLC i], Seq (ATree i), ConstructionData i, i)
initLoop Assign i
callback StorageClass i
t' TokenLC i
ident [Desg i]
desg Seq (ATree i)
ai TokenLC i
c) (ConstructionData i
scp, [TokenLC i]
ds)
            ([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> Either (ASTError i) [[ATree i]]
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall (f :: * -> *) (t :: * -> *) a c d.
(Functor f, Foldable t) =>
(a, Seq (ATree i), c, d)
-> f (t [ATree i]) -> f (a, Seq (ATree i), c)
zeroResult ([TokenLC i], Seq (ATree i), ConstructionData i, i)
rs (Either (ASTError i) [[ATree i]]
 -> Either
      (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i))
-> Either (ASTError i) [[ATree i]]
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall a b. (a -> b) -> a -> b
$ [StructMember i]
-> (StructMember i -> Either (ASTError i) [ATree i])
-> Either (ASTError i) [[ATree i]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM (Int -> [StructMember i] -> [StructMember i]
forall a. Int -> [a] -> [a]
drop (i -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (i -> Int) -> i -> Int
forall a b. (a -> b) -> a -> b
$ ([TokenLC i], Seq (ATree i), ConstructionData i, i) -> i
forall a b c d. (a, b, c, d) -> d
fou4 ([TokenLC i], Seq (ATree i), ConstructionData i, i)
rs) (Map Text (StructMember i) -> [StructMember i]
forall k a. Map k a -> [a]
M.elems Map Text (StructMember i)
mems)) ((StructMember i -> Either (ASTError i) [ATree i])
 -> Either (ASTError i) [[ATree i]])
-> (StructMember i -> Either (ASTError i) [ATree i])
-> Either (ASTError i) [[ATree i]]
forall a b. (a -> b) -> a -> b
$ \mem :: StructMember i
mem -> TypeKind i
-> TokenLC i
-> [Desg i]
-> ConstructionData i
-> Either (ASTError i) [ATree i]
forall i.
(Num i, Ord i, Show i, Enum i) =>
TypeKind i
-> TokenLC i
-> [Desg i]
-> ConstructionData i
-> Either (ASTError i) [ATree i]
initZero (StructMember i -> TypeKind i
forall i. StructMember i -> TypeKind i
CT.smType StructMember i
mem) TokenLC i
ident (StructMember i -> Desg i
forall i. StructMember i -> Desg i
CT.DesgMem StructMember i
memDesg i -> [Desg i] -> [Desg i]
forall a. a -> [a] -> [a]
:[Desg i]
desg) (([TokenLC i], Seq (ATree i), ConstructionData i, i)
-> ConstructionData i
forall a b c d. (a, b, c, d) -> c
thd4 ([TokenLC i], Seq (ATree i), ConstructionData i, i)
rs)
        _ ->  ASTError i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall a b. a -> Either a b
Left ("expected { initializer-list } or { initializer-list , }", if Bool -> Bool
not ([TokenLC i] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TokenLC i]
xs') then [TokenLC i] -> TokenLC i
forall a. [a] -> a
head [TokenLC i]
xs' else TokenLC i
forall i. Num i => TokenLC i
HT.emptyToken)
    -- For a element
    | Bool
otherwise = Assign i
callback [TokenLC i]
xs' ATree i
forall a. ATree a
ATEmpty ConstructionData i
scp Either (ASTError i) (ASTSuccess i)
-> (ASTSuccess i
    -> Either
         (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i))
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(ds :: [TokenLC i]
ds, at :: ATree i
at, scp''' :: ConstructionData i
scp''') -> ([TokenLC i]
ds,,ConstructionData i
scp''') (Seq (ATree i) -> ([TokenLC i], Seq (ATree i), ConstructionData i))
-> (ATree i -> Seq (ATree i))
-> ATree i
-> ([TokenLC i], Seq (ATree i), ConstructionData i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Seq (ATree i)
ai Seq (ATree i) -> ATree i -> Seq (ATree i)
forall a. Seq a -> a -> Seq a
SQ.|>) (ATree i -> ([TokenLC i], Seq (ATree i), ConstructionData i))
-> Either (ASTError i) (ATree i)
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TokenLC i
-> ATree i
-> [Desg i]
-> ConstructionData i
-> Either (ASTError i) (ATree i)
forall i.
(Num i, Ord i, Show i) =>
TokenLC i
-> ATree i
-> [Desg i]
-> ConstructionData i
-> Either (ASTError i) (ATree i)
desgNode TokenLC i
ident ATree i
at [Desg i]
desg ConstructionData i
scp'''
    where
        {-# INLINE zeroResult #-}
        zeroResult :: (a, Seq (ATree i), c, d)
-> f (t [ATree i]) -> f (a, Seq (ATree i), c)
zeroResult rs :: (a, Seq (ATree i), c, d)
rs = (t [ATree i] -> (a, Seq (ATree i), c))
-> f (t [ATree i]) -> f (a, Seq (ATree i), c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (((a, Seq (ATree i), c, d) -> a
forall a b c d. (a, b, c, d) -> a
fst4 (a, Seq (ATree i), c, d)
rs,,(a, Seq (ATree i), c, d) -> c
forall a b c d. (a, b, c, d) -> c
thd4 (a, Seq (ATree i), c, d)
rs) (Seq (ATree i) -> (a, Seq (ATree i), c))
-> (t [ATree i] -> Seq (ATree i))
-> t [ATree i]
-> (a, Seq (ATree i), c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Seq (ATree i)
ai Seq (ATree i) -> Seq (ATree i) -> Seq (ATree i)
forall a. Seq a -> Seq a -> Seq a
SQ.><) (Seq (ATree i) -> Seq (ATree i))
-> (t [ATree i] -> Seq (ATree i)) -> t [ATree i] -> Seq (ATree i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((a, Seq (ATree i), c, d) -> Seq (ATree i)
forall a b c d. (a, b, c, d) -> b
snd4 (a, Seq (ATree i), c, d)
rs Seq (ATree i) -> Seq (ATree i) -> Seq (ATree i)
forall a. Seq a -> Seq a -> Seq a
SQ.><) (Seq (ATree i) -> Seq (ATree i))
-> (t [ATree i] -> Seq (ATree i)) -> t [ATree i] -> Seq (ATree i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ATree i] -> Seq (ATree i)
forall a. [a] -> Seq a
SQ.fromList ([ATree i] -> Seq (ATree i))
-> (t [ATree i] -> [ATree i]) -> t [ATree i] -> Seq (ATree i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t [ATree i] -> [ATree i]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat)

        {-# INLINE toComplete #-}
        toComplete :: [TokenLC i] -> Either (ASTError i) (StorageClass i)
toComplete ds' :: [TokenLC i]
ds' = Either (ASTError i) (Either (TokenLC i) ([TokenLC i], [TokenLC i]))
-> (Either (TokenLC i) ([TokenLC i], [TokenLC i])
    -> Either (ASTError i) (StorageClass i))
-> Either (ASTError i) (StorageClass i)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
(>>=)
            (ASTError i
-> Maybe (Either (TokenLC i) ([TokenLC i], [TokenLC i]))
-> Either
     (ASTError i) (Either (TokenLC i) ([TokenLC i], [TokenLC i]))
forall e. e -> Maybe ~> Either e
maybeToRight ("expected { initializer-list } or { initializer-list , }", if Bool -> Bool
not ([TokenLC i] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TokenLC i]
xs') then [TokenLC i] -> TokenLC i
forall a. [a] -> a
head [TokenLC i]
xs' else TokenLC i
forall i. Num i => TokenLC i
HT.emptyToken) (Text
-> Text
-> [TokenLC i]
-> Maybe (Either (TokenLC i) ([TokenLC i], [TokenLC i]))
forall i.
(Integral i, Read i, Show i) =>
Text
-> Text
-> [TokenLC i]
-> Maybe (Either (TokenLC i) ([TokenLC i], [TokenLC i]))
takeBrace "{" "}" [TokenLC i]
ds')) ((Either (TokenLC i) ([TokenLC i], [TokenLC i])
  -> Either (ASTError i) (StorageClass i))
 -> Either (ASTError i) (StorageClass i))
-> (Either (TokenLC i) ([TokenLC i], [TokenLC i])
    -> Either (ASTError i) (StorageClass i))
-> Either (ASTError i) (StorageClass i)
forall a b. (a -> b) -> a -> b
$
                (TokenLC i -> Either (ASTError i) (StorageClass i))
-> (([TokenLC i], [TokenLC i])
    -> Either (ASTError i) (StorageClass i))
-> Either (TokenLC i) ([TokenLC i], [TokenLC i])
-> Either (ASTError i) (StorageClass i)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (ASTError i -> Either (ASTError i) (StorageClass i)
forall a b. a -> Either a b
Left (ASTError i -> Either (ASTError i) (StorageClass i))
-> (TokenLC i -> ASTError i)
-> TokenLC i
-> Either (ASTError i) (StorageClass i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ("expected { initializer-list } or { initializer-list , }",)) ((([TokenLC i], [TokenLC i])
  -> Either (ASTError i) (StorageClass i))
 -> Either (TokenLC i) ([TokenLC i], [TokenLC i])
 -> Either (ASTError i) (StorageClass i))
-> (([TokenLC i], [TokenLC i])
    -> Either (ASTError i) (StorageClass i))
-> Either (TokenLC i) ([TokenLC i], [TokenLC i])
-> Either (ASTError i) (StorageClass i)
forall a b. (a -> b) -> a -> b
$ \(br :: [TokenLC i]
br, _) -> Int -> StorageClass i
forall a. Integral a => a -> StorageClass i
arTypeFromLen (Int -> StorageClass i)
-> ([[TokenLC i]] -> Int) -> [[TokenLC i]] -> StorageClass i
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[TokenLC i]] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([[TokenLC i]] -> StorageClass i)
-> Either (ASTError i) [[TokenLC i]]
-> Either (ASTError i) (StorageClass i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
                    ASTError i
-> Maybe [[TokenLC i]] -> Either (ASTError i) [[TokenLC i]]
forall e. e -> Maybe ~> Either e
maybeToRight (Text
internalCE, TokenLC i
forall i. Num i => TokenLC i
HT.emptyToken) ([TokenLC i] -> Maybe [[TokenLC i]]
forall i. Eq i => [TokenLC i] -> Maybe [[TokenLC i]]
takeExps ([TokenLC i] -> Maybe [[TokenLC i]])
-> [TokenLC i] -> Maybe [[TokenLC i]]
forall a b. (a -> b) -> a -> b
$ [(i -> i -> TokenLCNums i
forall i. i -> i -> TokenLCNums i
HT.TokenLCNums 0 0, Text -> Token i
forall i. Text -> Token i
HT.TKReserved "(")] [TokenLC i] -> [TokenLC i] -> [TokenLC i]
forall a. [a] -> [a] -> [a]
++ [TokenLC i] -> [TokenLC i]
forall a. [a] -> [a]
init ([TokenLC i] -> [TokenLC i]
forall a. [a] -> [a]
tail [TokenLC i]
br) [TokenLC i] -> [TokenLC i] -> [TokenLC i]
forall a. [a] -> [a] -> [a]
++ [(i -> i -> TokenLCNums i
forall i. i -> i -> TokenLCNums i
HT.TokenLCNums 0 0, Text -> Token i
forall i. Text -> Token i
HT.TKReserved ")")])

        {-# INLINE arTypeFromLen #-}
        arTypeFromLen :: a -> StorageClass i
arTypeFromLen len :: a
len = (StorageClass i, StorageClass i -> StorageClass i)
-> StorageClass i -> StorageClass i
forall a b. (a, b) -> b
snd (StorageClass i
-> (StorageClass i, StorageClass i -> StorageClass i)
forall a. CType a => a -> (a, a -> a)
CT.dctorArray StorageClass i
t') (StorageClass i -> StorageClass i)
-> StorageClass i -> StorageClass i
forall a b. (a -> b) -> a -> b
$ (TypeKind i -> TypeKind i) -> StorageClass i -> StorageClass i
forall (a :: * -> *) i j.
TypeKindBase a =>
(TypeKind i -> TypeKind j) -> a i -> a j
CT.mapTypeKind (Natural -> TypeKind i -> TypeKind i
forall i. Natural -> TypeKind i -> TypeKind i
CT.CTArray (a -> Natural
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
len) (TypeKind i -> TypeKind i)
-> (TypeKind i -> TypeKind i) -> TypeKind i -> TypeKind i
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe (TypeKind i) -> TypeKind i
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe (TypeKind i) -> TypeKind i)
-> (TypeKind i -> Maybe (TypeKind i)) -> TypeKind i -> TypeKind i
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TypeKind i -> Maybe (TypeKind i)
forall (a :: * -> *) i.
IncompleteBase a =>
a i -> Maybe (TypeKind i)
CT.fromIncompleteArray) StorageClass i
t'

varInit' :: (Read i, Show i, Integral i, Bits i) => Assign i -> CT.StorageClass i -> HT.TokenLC i -> [HT.TokenLC i] -> ATree i -> ConstructionData i -> ASTConstruction i
varInit' :: Assign i -> StorageClass i -> TokenLC i -> Assign i
varInit' callback :: Assign i
callback t :: StorageClass i
t ident :: TokenLC i
ident xs :: [TokenLC i]
xs lat :: ATree i
lat scp' :: ConstructionData i
scp'
    | StorageClass i -> Bool
forall (a :: * -> *) i. TypeKindBase a => a i -> Bool
CT.isArray StorageClass i
t Bool -> Bool -> Bool
|| StorageClass i -> Bool
forall (a :: * -> *) i. TypeKindBase a => a i -> Bool
CT.isCTStruct StorageClass i
t = (Seq (ATree i) -> ATree i)
-> ([TokenLC i], Seq (ATree i), ConstructionData i)
-> ([TokenLC i], ATree i, ConstructionData i)
forall b d a c. (b -> d) -> (a, b, c) -> (a, d, c)
second3 (\st :: Seq (ATree i)
st -> ATKind i -> StorageClass i -> ATree i -> ATree i -> ATree i
forall a.
ATKind a -> StorageClass a -> ATree a -> ATree a -> ATree a
ATNode ([ATree i] -> ATKind i
forall a. [ATree a] -> ATKind a
ATBlock ([ATree i] -> ATKind i) -> [ATree i] -> ATKind i
forall a b. (a -> b) -> a -> b
$ Seq (ATree i) -> [ATree i]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList Seq (ATree i)
st) (TypeKind i -> StorageClass i
forall i. TypeKind i -> StorageClass i
CT.SCUndef TypeKind i
forall i. TypeKind i
CT.CTUndef) ATree i
forall a. ATree a
ATEmpty ATree i
forall a. ATree a
ATEmpty) (([TokenLC i], Seq (ATree i), ConstructionData i)
 -> ([TokenLC i], ATree i, ConstructionData i))
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
-> Either (ASTError i) ([TokenLC i], ATree i, ConstructionData i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Assign i
-> TokenLC i
-> Seq (ATree i)
-> [Desg i]
-> StorageClass i
-> [TokenLC i]
-> ConstructionData i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
forall i.
(Bits i, Integral i, Read i, Show i) =>
Assign i
-> TokenLC i
-> Seq (ATree i)
-> [Desg i]
-> StorageClass i
-> [TokenLC i]
-> ConstructionData i
-> Either
     (ASTError i) ([TokenLC i], Seq (ATree i), ConstructionData i)
desgInit Assign i
callback TokenLC i
ident Seq (ATree i)
forall a. Seq a
SQ.empty [] StorageClass i
t [TokenLC i]
xs ConstructionData i
scp'
    | Bool
otherwise = do
        (ert :: [TokenLC i]
ert, erat :: ATree i
erat, ervar :: ConstructionData i
ervar) <- Assign i
callback [TokenLC i]
xs ATree i
forall a. ATree a
ATEmpty ConstructionData i
scp'
        ((ATree i -> ([TokenLC i], ATree i, ConstructionData i))
 -> Either (ASTError i) (ATree i)
 -> Either (ASTError i) ([TokenLC i], ATree i, ConstructionData i))
-> Either (ASTError i) (ATree i)
-> (ATree i -> ([TokenLC i], ATree i, ConstructionData i))
-> Either (ASTError i) ([TokenLC i], ATree i, ConstructionData i)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (ATree i -> ([TokenLC i], ATree i, ConstructionData i))
-> Either (ASTError i) (ATree i)
-> Either (ASTError i) ([TokenLC i], ATree i, ConstructionData i)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (TokenLC i -> ATree i -> Either (ASTError i) (ATree i)
forall i.
Eq i =>
TokenLC i -> ATree i -> Either (ASTError i) (ATree i)
validAssign ([TokenLC i] -> TokenLC i
forall i. Num i => [TokenLC i] -> TokenLC i
HT.altEmptyToken [TokenLC i]
ert) ATree i
erat) ((ATree i -> ([TokenLC i], ATree i, ConstructionData i))
 -> Either (ASTError i) ([TokenLC i], ATree i, ConstructionData i))
-> (ATree i -> ([TokenLC i], ATree i, ConstructionData i))
-> Either (ASTError i) ([TokenLC i], ATree i, ConstructionData i)
forall a b. (a -> b) -> a -> b
$ \erat' :: ATree i
erat' -> ([TokenLC i]
ert, ATree i -> ATree i
forall i. ATree i -> ATree i
atExprStmt (ATKind i -> StorageClass i -> ATree i -> ATree i -> ATree i
forall a.
ATKind a -> StorageClass a -> ATree a -> ATree a -> ATree a
ATNode ATKind i
forall a. ATKind a
ATAssign (ATree i -> StorageClass i
forall a. ATree a -> StorageClass a
atype ATree i
lat) ATree i
lat ATree i
erat'), ConstructionData i
ervar)

-- | Initializing local variables
varInit :: (Read i, Show i, Integral i, Bits i) => Assign i -> CT.StorageClass i -> HT.TokenLC i -> [HT.TokenLC i] -> ConstructionData i -> ASTConstruction i
varInit :: Assign i
-> StorageClass i
-> TokenLC i
-> [TokenLC i]
-> ConstructionData i
-> ASTConstruction i
varInit callback :: Assign i
callback t :: StorageClass i
t ident :: TokenLC i
ident token :: [TokenLC i]
token scp :: ConstructionData i
scp = StorageClass i
-> TokenLC i
-> ConstructionData i
-> Either (ASTError i) (ATree i, ConstructionData i)
forall i.
(Integral i, Bits i) =>
StorageClass i
-> TokenLC i
-> ConstructionData i
-> Either (ASTError i) (ATree i, ConstructionData i)
addLVar (StorageClass i -> Maybe (StorageClass i) -> StorageClass i
forall a. a -> Maybe a -> a
fromMaybe StorageClass i
t (Maybe (StorageClass i) -> StorageClass i)
-> Maybe (StorageClass i) -> StorageClass i
forall a b. (a -> b) -> a -> b
$ StorageClass i -> ConstructionData i -> Maybe (StorageClass i)
forall i.
StorageClass i -> ConstructionData i -> Maybe (StorageClass i)
incomplete StorageClass i
t ConstructionData i
scp) TokenLC i
ident ConstructionData i
scp Either (ASTError i) (ATree i, ConstructionData i)
-> ((ATree i, ConstructionData i) -> ASTConstruction i)
-> ASTConstruction i
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ATree i -> ConstructionData i -> ASTConstruction i)
-> (ATree i, ConstructionData i) -> ASTConstruction i
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (Assign i -> StorageClass i -> TokenLC i -> Assign i
forall i.
(Read i, Show i, Integral i, Bits i) =>
Assign i -> StorageClass i -> TokenLC i -> Assign i
varInit' Assign i
callback StorageClass i
t TokenLC i
ident [TokenLC i]
token)