| ... |
... |
@@ -370,10 +370,6 @@ cua CanUpdateAnchor f = f |
|
370
|
370
|
cua CanUpdateAnchorOnly _ = return []
|
|
371
|
371
|
cua NoCanUpdateAnchor _ = return []
|
|
372
|
372
|
|
|
373
|
|
-enterAnn :: (Monad m, Monoid w, ExactPrint a) => Entry -> a -> EP w m a
|
|
374
|
|
-enterAnn = enterAnnWith exact setAnnotationAnchor
|
|
375
|
|
-
|
|
376
|
|
-{-# INLINE enterAnnWith #-}
|
|
377
|
373
|
-- | "Enter" an annotation, by using the associated 'anchor' field as
|
|
378
|
374
|
-- the new reference point for calculating all DeltaPos positions.
|
|
379
|
375
|
-- This is the heart of the exact printing process.
|
| ... |
... |
@@ -381,17 +377,14 @@ enterAnn = enterAnnWith exact setAnnotationAnchor |
|
381
|
377
|
-- This is combination of the ghc=exactprint Delta.withAST and
|
|
382
|
378
|
-- Print.exactPC functions and effectively does the delta processing
|
|
383
|
379
|
-- immediately followed by the print processing. JIT ghc-exactprint.
|
|
384
|
|
-enterAnnWith :: (Monad m, Monoid w, Typeable a, Typeable b) =>
|
|
385
|
|
- (a -> EP w m b) -> -- exact
|
|
386
|
|
- (b -> EpaLocation -> [TrailingAnn] -> EpAnnComments -> b) -> -- setAnnotationAnchor
|
|
387
|
|
- Entry -> a -> EP w m b
|
|
388
|
|
-enterAnnWith exactVia _ NoEntryVal a = do
|
|
|
380
|
+enterAnn :: (Monad m, Monoid w, ExactPrint a) => Entry -> a -> EP w m a
|
|
|
381
|
+enterAnn NoEntryVal a = do
|
|
389
|
382
|
p <- getPosP
|
|
390
|
383
|
debugM $ "enterAnn:starting:NO ANN:(p,a) =" ++ show (p, astId a)
|
|
391
|
|
- r <- exactVia a
|
|
|
384
|
+ r <- exact a
|
|
392
|
385
|
debugM $ "enterAnn:done:NO ANN:p =" ++ show (p, astId a)
|
|
393
|
386
|
return r
|
|
394
|
|
-enterAnnWith exactVia setAnnAnchor !(Entry anchor' trailing_anns cs flush canUpdateAnchor) a = do
|
|
|
387
|
+enterAnn !(Entry anchor' trailing_anns cs flush canUpdateAnchor) a = do
|
|
395
|
388
|
acceptSpan <- getAcceptSpan
|
|
396
|
389
|
setAcceptSpan False
|
|
397
|
390
|
case anchor' of
|
| ... |
... |
@@ -502,7 +495,7 @@ enterAnnWith exactVia setAnnAnchor !(Entry anchor' trailing_anns cs flush canUpd |
|
502
|
495
|
|
|
503
|
496
|
advance edp
|
|
504
|
497
|
debugM $ "enterAnn:exact a starting:" ++ show (showAst anchor')
|
|
505
|
|
- a' <- exactVia a
|
|
|
498
|
+ a' <- exact a
|
|
506
|
499
|
debugM $ "enterAnn:exact a done:" ++ show (showAst anchor')
|
|
507
|
500
|
|
|
508
|
501
|
-- Core recursive exactprint done, start end of Entry processing
|
| ... |
... |
@@ -556,8 +549,8 @@ enterAnnWith exactVia setAnnAnchor !(Entry anchor' trailing_anns cs flush canUpd |
|
556
|
549
|
EpaSpan s -> EpaDelta s edp []
|
|
557
|
550
|
_ -> EpaDelta noSrcSpan edp []
|
|
558
|
551
|
let r = case canUpdateAnchor of
|
|
559
|
|
- CanUpdateAnchor -> setAnnAnchor a' newAnchor trailing' (mkEpaComments priorCs postCs)
|
|
560
|
|
- CanUpdateAnchorOnly -> setAnnAnchor a' newAnchor [] emptyComments
|
|
|
552
|
+ CanUpdateAnchor -> setAnnotationAnchor a' newAnchor trailing' (mkEpaComments priorCs postCs)
|
|
|
553
|
+ CanUpdateAnchorOnly -> setAnnotationAnchor a' newAnchor [] emptyComments
|
|
561
|
554
|
NoCanUpdateAnchor -> a'
|
|
562
|
555
|
return r
|
|
563
|
556
|
|
| ... |
... |
@@ -3404,13 +3397,13 @@ instance ExactPrint (HsCmd GhcPs) where |
|
3404
|
3397
|
e' <- markAnnotated e
|
|
3405
|
3398
|
return (HsCmdLet (tkLet', tkIn') binds' e')
|
|
3406
|
3399
|
|
|
3407
|
|
- exact (HsCmdDo (an0,loc) (L l es)) = do
|
|
|
3400
|
+ exact (HsCmdDo (an0,loc) es) = do
|
|
3408
|
3401
|
debugM $ "HsCmdDo"
|
|
3409
|
3402
|
loc' <- printStringAtAA loc "do"
|
|
3410
|
3403
|
(an1,es') <- markAnnList' an0 $ do
|
|
3411
|
|
- ee <- mapM markAnnotated es
|
|
|
3404
|
+ ee <- markAnnotated es
|
|
3412
|
3405
|
return ee
|
|
3413
|
|
- return (HsCmdDo (an1,loc') (L l es'))
|
|
|
3406
|
+ return (HsCmdDo (an1,loc') es')
|
|
3414
|
3407
|
|
|
3415
|
3408
|
-- ---------------------------------------------------------------------
|
|
3416
|
3409
|
|
| ... |
... |
@@ -4264,26 +4257,13 @@ instance ExactPrint (ConDecl GhcPs) where |
|
4264
|
4257
|
epTokensToComments "(" ops
|
|
4265
|
4258
|
epTokensToComments ")" cps
|
|
4266
|
4259
|
|
|
4267
|
|
- -- Work around https://gitlab.haskell.org/ghc/ghc/-/issues/20558
|
|
4268
|
4260
|
outer_bndrs' <- case outer_bndrs of
|
|
4269
|
4261
|
L _ (HsOuterImplicit _) -> return outer_bndrs
|
|
4270
|
4262
|
_ -> markAnnotated outer_bndrs
|
|
4271
|
4263
|
|
|
4272
|
|
- (inner_bndrs', (mcxt', args', res_ty')) <- markGadtArgs inner_bndrs $ do
|
|
4273
|
|
- mcxt' <- markAnnotated mcxt
|
|
4274
|
|
- args' <-
|
|
4275
|
|
- case args of
|
|
4276
|
|
- (PrefixConGADT x args0) -> do
|
|
4277
|
|
- args0' <- mapM markAnnotated args0
|
|
4278
|
|
- return (PrefixConGADT x args0')
|
|
4279
|
|
- (RecConGADT (oc,cc,rarr) fields) -> do
|
|
4280
|
|
- oc' <- markEpToken oc
|
|
4281
|
|
- fields' <- markAnnotated fields
|
|
4282
|
|
- cc' <- markEpToken cc
|
|
4283
|
|
- rarr' <- markEpUniToken rarr
|
|
4284
|
|
- return (RecConGADT (oc',cc',rarr') fields')
|
|
4285
|
|
- res_ty' <- markAnnotated res_ty
|
|
4286
|
|
- return (mcxt', args', res_ty')
|
|
|
4264
|
+ let ib = toInnerBindings inner_bndrs (mcxt, args, res_ty)
|
|
|
4265
|
+ ib' <- markAnnotated ib
|
|
|
4266
|
+ let (inner_bndrs', (mcxt', args', res_ty')) = fromInnerBindings ib'
|
|
4287
|
4267
|
|
|
4288
|
4268
|
return (ConDeclGADT { con_g_ext = AnnConDeclGADT [] [] dcol'
|
|
4289
|
4269
|
, con_names = cons'
|
| ... |
... |
@@ -4293,43 +4273,54 @@ instance ExactPrint (ConDecl GhcPs) where |
|
4293
|
4273
|
, con_modifiers = mods'
|
|
4294
|
4274
|
, con_res_ty = res_ty', con_doc = doc })
|
|
4295
|
4275
|
|
|
4296
|
|
--- | Exact print the inner binders of a GADT signature.
|
|
4297
|
|
---
|
|
4298
|
|
--- It's that complicated because we need to mark comments/trailing anns
|
|
4299
|
|
--- stored inside `L` and mark closing parenthesis _after_ we mark inner
|
|
4300
|
|
--- type:
|
|
4301
|
|
---
|
|
4302
|
|
--- data T a b where
|
|
4303
|
|
--- MkT ::
|
|
4304
|
|
--- forall a. ( -- mark inside `markGadtArgs`
|
|
4305
|
|
--- forall b. some type -> T a b -- mark everything there
|
|
4306
|
|
--- ) -- mark inside `markGadtArgs`
|
|
4307
|
|
---
|
|
4308
|
|
--- We don't have the same problem for `HsArgPar` because we ignore it
|
|
4309
|
|
--- during exact-print, "Does not appear in original source"
|
|
4310
|
|
-markGadtArgs :: (Monad m, Monoid w, Typeable a)
|
|
4311
|
|
- => [LHsGadtTelescope GhcPs] -> EP w m a
|
|
4312
|
|
- -> EP w m ([LHsGadtTelescope GhcPs], a)
|
|
4313
|
|
-markGadtArgs args inner_action = go args
|
|
|
4276
|
+-- ---------------------------------------------------------------------
|
|
|
4277
|
+
|
|
|
4278
|
+data InnerBindings
|
|
|
4279
|
+ = InnerMore (LHsGadtTelescope GhcPs) InnerBindings
|
|
|
4280
|
+ | InnerDone (Maybe (LHsContext GhcPs), HsConDeclGADTDetails GhcPs, LHsType GhcPs)
|
|
|
4281
|
+
|
|
|
4282
|
+toInnerBindings :: [LHsGadtTelescope GhcPs]
|
|
|
4283
|
+ -> (Maybe (LHsContext GhcPs), HsConDeclGADTDetails GhcPs, LHsType GhcPs) -> InnerBindings
|
|
|
4284
|
+toInnerBindings [] inner = InnerDone inner
|
|
|
4285
|
+toInnerBindings (b:bs) inner = InnerMore b (toInnerBindings bs inner)
|
|
|
4286
|
+
|
|
|
4287
|
+fromInnerBindings :: InnerBindings -> ([LHsGadtTelescope GhcPs], (Maybe (LHsContext GhcPs), HsConDeclGADTDetails GhcPs, LHsType GhcPs))
|
|
|
4288
|
+fromInnerBindings = go []
|
|
4314
|
4289
|
where
|
|
4315
|
|
- go [] = do
|
|
4316
|
|
- r <- inner_action
|
|
4317
|
|
- return ([], r)
|
|
4318
|
|
- go (arg:xs) = enterAnnWith (exact_arg xs) setAnchor (entryFromLocatedA arg) arg
|
|
|
4290
|
+ go acc (InnerMore b n) = go (b:acc) n
|
|
|
4291
|
+ go acc (InnerDone x) = (acc,x)
|
|
4319
|
4292
|
|
|
4320
|
|
- exact_arg xs (L l (HsGadtForAll _ tele)) = do
|
|
4321
|
|
- tele' <- markAnnotated tele
|
|
4322
|
|
- (xs', r) <- go xs
|
|
4323
|
|
- return (L l (HsGadtForAll noExtField tele') : xs', r)
|
|
4324
|
|
- exact_arg xs (L l (HsGadtPar (lp, rp))) = do
|
|
4325
|
|
- lp' <- markEpToken lp
|
|
4326
|
|
- (xs', r) <- go xs
|
|
4327
|
|
- rp' <- markEpToken rp
|
|
4328
|
|
- return (L l (HsGadtPar (lp',rp')) : xs', r)
|
|
|
4293
|
+instance ExactPrint InnerBindings where
|
|
|
4294
|
+ getAnnotationEntry (InnerMore (L li _) _) = fromAnn li
|
|
|
4295
|
+ getAnnotationEntry (InnerDone _) = NoEntryVal
|
|
4329
|
4296
|
|
|
4330
|
|
- -- The binder just entered is the head of the returned list
|
|
4331
|
|
- setAnchor (arg':xs', r) anc ts cs = (setAnchorAn arg' anc ts cs : xs', r)
|
|
4332
|
|
- setAnchor ([], r) _ _ _ = ([], r)
|
|
|
4297
|
+ setAnnotationAnchor (InnerMore li n) anc ts cs = InnerMore (setAnchorAn li anc ts cs) n
|
|
|
4298
|
+ setAnnotationAnchor (InnerDone x) _ _ _ = InnerDone x
|
|
|
4299
|
+
|
|
|
4300
|
+ exact (InnerMore (L li (HsGadtForAll x tele)) n) = do
|
|
|
4301
|
+ tele' <- markAnnotated tele
|
|
|
4302
|
+ n' <- markAnnotated n
|
|
|
4303
|
+ return (InnerMore (L li (HsGadtForAll x tele')) n')
|
|
|
4304
|
+ exact (InnerMore (L l (HsGadtPar (lp, rp))) xs) = do
|
|
|
4305
|
+ lp' <- markEpToken lp
|
|
|
4306
|
+ xs' <- markAnnotated xs
|
|
|
4307
|
+ rp' <- markEpToken rp
|
|
|
4308
|
+ return (InnerMore (L l (HsGadtPar (lp',rp'))) xs')
|
|
|
4309
|
+ exact (InnerDone (mcxt, args, res_ty)) = do
|
|
|
4310
|
+ mcxt' <- markAnnotated mcxt
|
|
|
4311
|
+ args' <-
|
|
|
4312
|
+ case args of
|
|
|
4313
|
+ (PrefixConGADT x args0) -> do
|
|
|
4314
|
+ args0' <- mapM markAnnotated args0
|
|
|
4315
|
+ return (PrefixConGADT x args0')
|
|
|
4316
|
+ (RecConGADT (oc,cc,rarr) fields) -> do
|
|
|
4317
|
+ oc' <- markEpToken oc
|
|
|
4318
|
+ fields' <- markAnnotated fields
|
|
|
4319
|
+ cc' <- markEpToken cc
|
|
|
4320
|
+ rarr' <- markEpUniToken rarr
|
|
|
4321
|
+ return (RecConGADT (oc',cc',rarr') fields')
|
|
|
4322
|
+ res_ty' <- markAnnotated res_ty
|
|
|
4323
|
+ return (InnerDone (mcxt', args', res_ty'))
|
|
4333
|
4324
|
|
|
4334
|
4325
|
-- ---------------------------------------------------------------------
|
|
4335
|
4326
|
|
| ... |
... |
@@ -4508,10 +4499,10 @@ instance ExactPrint [LocatedA (StmtLR GhcPs GhcPs (LocatedA (HsCmd GhcPs)))] whe |
|
4508
|
4499
|
Just (initStmts, ls@(L _ (LastStmt _ _body _ _))) -> do
|
|
4509
|
4500
|
debugM $ "LocatedL [ExprLStmt: snocView"
|
|
4510
|
4501
|
ls' <- markAnnotated ls
|
|
4511
|
|
- initStmts' <- markAnnotated initStmts
|
|
|
4502
|
+ initStmts' <- mapM markAnnotated initStmts
|
|
4512
|
4503
|
return (initStmts' ++ [ls'])
|
|
4513
|
4504
|
_ -> do
|
|
4514
|
|
- stmts' <- markAnnotated stmts
|
|
|
4505
|
+ stmts' <- mapM markAnnotated stmts
|
|
4515
|
4506
|
return stmts'
|
|
4516
|
4507
|
|
|
4517
|
4508
|
instance ExactPrint [Located HsDocStringChunk] where
|