1 {- Notes about the syntax of interface files -*-haskell-*-
2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 interface "edison" M 4 6 2 ! 406 Module M, version 4, from package 'edison',
6 Fixities version 6, rules version 2
7 Interface syntax version 406
8 ! means M contains orphans
12 import Foo ; To compile M I used nothing from Foo, but it's
13 below me in the hierarchy
15 import Foo ! @ ; Ditto, but the ! means that Foo contains orphans
16 and the @ means that Foo is a boot interface
18 import Foo :: 3 ; To compile M I used everything from Foo, which has
21 import Foo :: 3 2 6 a 1 b 3 c 7 ; To compile M I used Foo. It had
25 and some specific things besides.
31 module ParseIface ( parseIface, parseType, parseRules, parseIdInfo ) where
33 #include "HsVersions.h"
35 import HsSyn -- quite a bit of stuff
36 import RdrHsSyn -- oodles of synonyms
37 import HsTypes ( mkHsForAllTy, mkHsTupCon )
39 import Literal ( Literal(..), mkMachInt, mkMachInt64, mkMachWord, mkMachWord64 )
40 import BasicTypes ( Fixity(..), FixityDirection(..), StrictnessMark(..),
41 NewOrData(..), Version, initialVersion, Boxity(..),
42 Activation(..), IPName(..)
44 import CostCentre ( CostCentre(..), IsCafCC(..), IsDupdCC(..) )
45 import Type ( Kind, mkArrowKind, liftedTypeKind, openTypeKind, usageTypeKind )
46 import ForeignCall ( ForeignCall(..), CCallConv(..), CCallSpec(..), CCallTarget(..) )
49 import RnMonad ( ParsedIface(..), ExportItem, IfaceDeprecs )
50 import HscTypes ( WhetherHasOrphans, IsBootInterface, GenAvailInfo(..),
51 ImportVersion, WhatsImported(..),
54 import RdrName ( RdrName, mkRdrUnqual, mkIfaceOrig )
55 import Name ( OccName )
56 import OccName ( mkSysOccFS,
57 tcName, varName, dataName, clsName, tvName,
60 import Module ( ModuleName, PackageName, mkSysModuleNameFS )
61 import SrcLoc ( SrcLoc )
62 import CmdLineOpts ( opt_InPackage, opt_IgnoreIfacePragmas )
64 import Class ( DefMeth (..) )
67 import FastString ( tailFS )
70 %name parseIface iface
72 %name parseIdInfo id_info
73 %name parseRules rules_and_deprecs
76 %monad { P }{ thenP }{ returnP }
77 %lexer { lexer } { ITeof }
81 'case' { ITcase } -- Haskell keywords
90 'instance' { ITinstance }
92 'newtype' { ITnewtype }
94 'qualified' { ITqualified }
98 'forall' { ITforall } -- GHC extension keywords
99 'foreign' { ITforeign }
100 'export' { ITexport }
102 'dynamic' { ITdynamic }
103 'unsafe' { ITunsafe }
105 'stdcall' { ITstdcallconv }
106 'ccall' { ITccallconv }
108 '__interface' { ITinterface } -- interface keywords
109 '__export' { IT__export }
110 '__forall' { IT__forall }
111 '__letrec' { ITletrec }
112 '__coerce' { ITcoerce }
113 '__inline_me' { ITinlineMe }
114 '__inline_call'{ ITinlineCall }
115 '__DEFAULT' { ITdefaultbranch }
116 '__float' { ITfloat_lit }
117 '__word' { ITword_lit }
118 '__int64' { ITint64_lit }
119 '__word64' { ITword64_lit }
120 '__addr' { ITaddr_lit }
121 '__label' { ITlabel_lit }
122 '__litlit' { ITlit_lit }
123 '__ccall' { ITccall $$ }
125 '__sccC' { ITsccAllCafs }
130 '__P' { ITspecialise }
133 '__S' { ITstrict $$ }
135 '__D' { ITdeprecated }
148 '{' { ITocurly } -- special symbols
162 VARID { ITvarid $$ } -- identifiers
164 VARSYM { ITvarsym $$ }
165 QVARID { ITqvarid $$ }
166 QCONID { ITqconid $$ }
168 IPDUPVARID { ITdupipvarid $$ } -- GHC extension
169 IPSPLITVARID { ITsplitipvarid $$ } -- GHC extension
171 PRAGMA { ITpragma $$ }
174 STRING { ITstring $$ }
175 INTEGER { ITinteger $$ }
176 RATIONAL { ITrational $$ }
177 CLITLIT { ITlitlit $$ }
180 iface :: { ParsedIface }
181 iface : '__interface' package mod_name
183 orphans checkVersion 'where'
189 rules_and_deprecs_part
190 { let (rules,deprecs) = $14 () in
192 pi_mod = $3, -- Module name
193 pi_pkg = $2, -- Package name
194 pi_vers = $4, -- Module version
196 pi_exports = (fst $5, $9), -- Exports
197 pi_usages = $10, -- Usages
198 pi_fixity = $11, -- Fixies
199 pi_insts = $12, -- Local instances
200 pi_decls = $13, -- Decls
201 pi_rules = (snd $5,rules), -- Rules
202 pi_deprecs = deprecs -- Deprecations
205 -- Versions for exports and rules (optional)
206 sub_versions :: { (Version,Version) }
207 : '[' version version ']' { ($2,$3) }
208 | {- empty -} { (initialVersion, initialVersion) }
210 --------------------------------------------------------------------------
212 import_part :: { [ImportVersion OccName] }
214 | import_decl import_part { $1 : $2 }
216 import_decl :: { ImportVersion OccName }
217 import_decl : 'import' mod_name orphans is_boot whats_imported ';'
218 { ({-mkSysModuleNameFS-} $2, $3, $4, $5) }
220 orphans :: { WhetherHasOrphans }
224 is_boot :: { IsBootInterface }
228 whats_imported :: { WhatsImported OccName }
229 whats_imported : { NothingAtAll }
230 | '::' version { Everything $2 }
231 | '::' version version version name_version_pairs { Specifically $2 (Just $3) $5 $4 }
232 | '::' version version name_version_pairs { Specifically $2 Nothing $4 $3 }
234 name_version_pairs :: { [(OccName, Version)] }
235 name_version_pairs : { [] }
236 | name_version_pair name_version_pairs { $1 : $2 }
238 name_version_pair :: { (OccName, Version) }
239 name_version_pair : var_occ version { ($1, $2) }
240 | tc_occ version { ($1, $2) }
243 --------------------------------------------------------------------------
245 exports_part :: { [ExportItem] }
246 exports_part : { [] }
247 | '__export' mod_name entities ';'
248 exports_part { ({-mkSysModuleNameFS-} $2, $3) : $5 }
250 entities :: { [RdrAvailInfo] }
252 | entity entities { $1 : $2 }
254 entity :: { RdrAvailInfo }
255 entity : var_occ { Avail $1 }
256 | tc_occ { AvailTC $1 [$1] }
257 | tc_occ '|' stuff_inside { AvailTC $1 $3 }
258 | tc_occ stuff_inside { AvailTC $1 ($1:$2) }
259 -- Note that the "main name" comes at the beginning
261 stuff_inside :: { [OccName] }
262 stuff_inside : '{' val_occs '}' { $2 }
264 val_occ :: { OccName }
268 val_occs :: { [OccName] }
270 | val_occ val_occs { $1 : $2 }
273 --------------------------------------------------------------------------
275 fix_decl_part :: { [RdrNameFixitySig] }
276 fix_decl_part : {- empty -} { [] }
277 | fix_decls ';' { $1 }
279 fix_decls :: { [RdrNameFixitySig] }
281 | fix_decl fix_decls { $1 : $2 }
283 fix_decl :: { RdrNameFixitySig }
284 fix_decl : src_loc fixity prec var_or_data_name { FixitySig $4 (Fixity $3 $2) $1 }
286 fixity :: { FixityDirection }
287 fixity : 'infixl' { InfixL }
288 | 'infixr' { InfixR }
292 prec : INTEGER { fromInteger $1 }
294 -----------------------------------------------------------------------------
296 csigs :: { [RdrNameSig] }
298 | 'where' '{' csigs1 '}' { $3 }
300 csigs1 :: { [RdrNameSig] }
302 | csig ';' csigs1 { $1 : $3 }
304 csig :: { RdrNameSig }
305 csig : src_loc qvar_name '::' type { ClassOpSig $2 NoDefMeth $4 $1 }
306 | src_loc qvar_name ';' '::' type { ClassOpSig $2 GenDefMeth $5 $1 }
307 | src_loc qvar_name '=' '::' type { mkClassOpSigDM $2 $5 $1 }
309 --------------------------------------------------------------------------
311 instance_decl_part :: { [RdrNameInstDecl] }
312 instance_decl_part : {- empty -} { [] }
313 | instance_decl_part inst_decl { $2 : $1 }
315 inst_decl :: { RdrNameInstDecl }
316 inst_decl : src_loc 'instance' type '=' qvar_name ';'
318 EmptyMonoBinds {- No bindings -}
319 [] {- No user pragmas -}
320 (Just $5) {- Dfun id -}
324 --------------------------------------------------------------------------
326 decls_part :: { [(Version, RdrNameTyClDecl)] }
329 | opt_version decl ';' decls_part { ($1,$2):$4 }
331 decl :: { RdrNameTyClDecl }
332 decl : src_loc qvar_name '::' type maybe_idinfo
333 { IfaceSig $2 $4 ($5 $2) $1 }
334 | src_loc 'type' qtc_name tv_bndrs '=' type
335 { TySynonym $3 $4 $6 $1 }
336 | src_loc 'foreign' 'type' qtc_name
337 { ForeignType $4 Nothing DNType $1 }
338 | src_loc 'data' tycl_hdr constrs
339 { mkTyData DataType $3 $4 (length $4) Nothing $1 }
340 | src_loc 'newtype' tycl_hdr newtype_constr
341 { mkTyData NewType $3 $4 1 Nothing $1 }
342 | src_loc 'class' tycl_hdr fds csigs
343 { mkClassDecl $3 $4 $5 Nothing $1 }
345 tycl_hdr :: { (RdrNameContext, RdrName, [RdrNameHsTyVar]) }
346 : context '=>' qtc_name tv_bndrs { ($1, $3, $4) }
347 | qtc_name tv_bndrs { ([], $1, $2) }
349 maybe_idinfo :: { RdrName -> [HsIdInfo RdrName] }
350 maybe_idinfo : {- empty -} { \_ -> [] }
351 | pragma { \x -> if opt_IgnoreIfacePragmas then []
353 Just (POk _ id_info) -> id_info
354 Just (PFailed err) -> pprPanic "IdInfo parse failed"
358 If a signature decl is being loaded, and opt_IgnoreIfacePragmas is on,
359 we toss away unfolding information.
361 Also, if the signature is loaded from a module we're importing from source,
362 we do the same. This is to avoid situations when compiling a pair of mutually
363 recursive modules, peering at unfolding info in the interface file of the other,
364 e.g., you compile A, it looks at B's interface file and may as a result change
365 its interface file. Hence, B is recompiled, maybe changing its interface file,
366 which will the unfolding info used in A to become invalid. Simple way out is to
367 just ignore unfolding info.
369 [Jan 99: I junked the second test above. If we're importing from an hi-boot
370 file there isn't going to *be* any pragma info. The above comment
371 dates from a time where we picked up a .hi file first if it existed.]
374 pragma :: { Maybe (ParseResult [HsIdInfo RdrName]) }
375 pragma : src_loc PRAGMA { let exts = ExtFlags {glasgowExtsEF = True,
378 Just (parseIdInfo $2 (mkPState $1 exts))
381 -----------------------------------------------------------------------------
383 -- This production is lifted so that it doesn't get eagerly parsed when we
384 -- use happy --strict.
385 rules_and_deprecs_part :: { () -> ([RdrNameRuleDecl], IfaceDeprecs) }
386 rules_and_deprecs_part
387 : {- empty -} { \_ -> ([], Nothing) }
388 | src_loc PRAGMA { \_ -> let exts = ExtFlags {glasgowExtsEF = True,
390 in case parseRules $2 (mkPState $1 exts) of
392 PFailed err -> pprPanic "Rules/Deprecations parse failed" err
395 rules_and_deprecs :: { ([RdrNameRuleDecl], IfaceDeprecs) }
396 rules_and_deprecs : rule_prag deprec_prag { ($1, $2) }
399 -----------------------------------------------------------------------------
401 rule_prag :: { [RdrNameRuleDecl] }
402 rule_prag : {- empty -} { [] }
405 rules :: { [RdrNameRuleDecl] }
407 | rule ';' rules { $1:$3 }
409 rule :: { RdrNameRuleDecl }
410 rule : src_loc STRING activation rule_forall qvar_name
411 core_args '=' core_expr { IfaceRule $2 $3 $4 $5 $6 $8 $1 }
413 activation :: { Activation }
414 activation : {- empty -} { AlwaysActive }
415 | '[' INTEGER ']' { ActiveAfter (fromInteger $2) }
416 | '[' '~' INTEGER ']' { ActiveBefore (fromInteger $3) }
418 rule_forall :: { [UfBinder RdrName] }
419 rule_forall : '__forall' '{' core_bndrs '}' { $3 }
421 -----------------------------------------------------------------------------
423 deprec_prag :: { IfaceDeprecs }
424 deprec_prag : {- empty -} { Nothing }
425 | '__D' deprecs { Just $2 }
427 deprecs :: { Either DeprecTxt [(RdrName,DeprecTxt)] }
428 deprecs : STRING { Left $1 }
429 | deprec_list { Right $1 }
431 deprec_list :: { [(RdrName,DeprecTxt)] }
432 deprec_list : deprec { [$1] }
433 | deprec ';' deprec_list { $1 : $3 }
435 deprec :: { (RdrName,DeprecTxt) }
436 deprec : deprec_name STRING { ($1, $2) }
438 deprec_name :: { RdrName }
442 -----------------------------------------------------------------------------
444 version :: { Version }
445 version : INTEGER { fromInteger $1 }
447 opt_version :: { Version }
448 opt_version : version { $1 }
449 | {- empty -} { initialVersion }
452 ----------------------------------------------------------------------------
454 constrs :: { [RdrNameConDecl] {- empty for handwritten abstract -} }
456 | '=' constrs1 { $2 }
458 constrs1 :: { [RdrNameConDecl] }
459 constrs1 : constr { [$1] }
460 | constr '|' constrs1 { $1 : $3 }
462 constr :: { RdrNameConDecl }
463 constr : src_loc ex_stuff qdata_name batypes { mk_con_decl $3 $2 (VanillaCon $4) $1 }
464 | src_loc ex_stuff qdata_name '{' fields1 '}' { mk_con_decl $3 $2 (RecCon $5) $1 }
465 -- We use "data_fs" so as to include ()
467 newtype_constr :: { [RdrNameConDecl] {- Not allowed to be empty -} }
468 newtype_constr : src_loc '=' ex_stuff qdata_name atype { [mk_con_decl $4 $3 (VanillaCon [unbangedType $5]) $1] }
469 | src_loc '=' ex_stuff qdata_name '{' qvar_name '::' atype '}'
470 { [mk_con_decl $4 $3 (RecCon [([$6], unbangedType $8)]) $1] }
472 ex_stuff :: { ([HsTyVarBndr RdrName], RdrNameContext) }
473 ex_stuff : { ([],[]) }
474 | '__forall' tv_bndrs opt_context '=>' { ($2,$3) }
476 batypes :: { [RdrNameBangType] }
478 | batype batypes { $1 : $2 }
480 batype :: { RdrNameBangType }
481 batype : tatype { unbangedType $1 }
482 | '!' tatype { BangType MarkedStrict $2 }
483 | '!' '!' tatype { BangType MarkedUnboxed $3 }
485 fields1 :: { [([RdrName], RdrNameBangType)] }
486 fields1 : field { [$1] }
487 | field ',' fields1 { $1 : $3 }
489 field :: { ([RdrName], RdrNameBangType) }
490 field : qvar_names1 '::' ttype { ($1, unbangedType $3) }
491 | qvar_names1 '::' '!' ttype { ($1, BangType MarkedStrict $4) }
492 | qvar_names1 '::' '!' '!' ttype { ($1, BangType MarkedUnboxed $5) }
494 --------------------------------------------------------------------------
496 type :: { RdrNameHsType }
497 type : '__forall' tv_bndrs
498 opt_context '=>' type { mkHsForAllTy (Just $2) $3 $5 }
499 | btype '->' type { HsFunTy $1 $3 }
502 opt_context :: { RdrNameContext }
506 context :: { RdrNameContext }
507 context : '(' context_list1 ')' { $2 }
508 | '{' context_list1 '}' { $2 } -- Backward compatibility
510 context_list1 :: { RdrNameContext }
511 context_list1 : class { [$1] }
512 | class ',' context_list1 { $1 : $3 }
514 class :: { HsPred RdrName }
515 class : qcls_name atypes { (HsClassP $1 $2) }
516 | ipvar_name '::' type { (HsIParam $1 $3) }
518 types0 :: { [RdrNameHsType] {- Zero or more -} }
519 types0 : {- empty -} { [ ] }
523 types2 :: { [RdrNameHsType] {- Two or more -} }
524 types2 : type ',' type { [$1,$3] }
525 | type ',' types2 { $1 : $3 }
527 btype :: { RdrNameHsType }
529 | btype atype { HsAppTy $1 $2 }
531 atype :: { RdrNameHsType }
532 atype : qtc_name { HsTyVar $1 }
533 | tv_name { HsTyVar $1 }
536 | '(' ')' { HsTupleTy (mkHsTupCon tcName Boxed []) [] }
537 | '(' types2 ')' { HsTupleTy (mkHsTupCon tcName Boxed $2) $2 }
538 | '(#' types0 '#)' { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
539 | '[' type ']' { HsListTy $2 }
540 | '[:' type ':]' { HsPArrTy $2 }
541 | '{' qcls_name atypes '}' { mkHsDictTy $2 $3 }
542 | '{' ipvar_name '::' type '}' { mkHsIParamTy $2 $4 }
543 | '(' type ')' { $2 }
545 atypes :: { [RdrNameHsType] {- Zero or more -} }
547 | atype atypes { $1 : $2 }
548 --------------------------------------------------------------------------
550 -- versions of type/btype/atype that cant begin with '!' (or '.')
551 -- for use where the kind is definitely known NOT to be '$'
553 ttype :: { RdrNameHsType }
554 ttype : '__forall' tv_bndrs
555 opt_context '=>' type { mkHsForAllTy (Just $2) $3 $5 }
556 | tbtype '->' type { HsFunTy $1 $3 }
559 tbtype :: { RdrNameHsType }
560 tbtype : tatype { $1 }
561 | tbtype atype { HsAppTy $1 $2 }
563 tatype :: { RdrNameHsType }
564 tatype : qtc_name { HsTyVar $1 }
565 | tv_name { HsTyVar $1 }
566 | '(' ')' { HsTupleTy (mkHsTupCon tcName Boxed []) [] }
567 | '(' types2 ')' { HsTupleTy (mkHsTupCon tcName Boxed $2) $2 }
568 | '(#' types0 '#)' { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
569 | '[' type ']' { HsListTy $2 }
570 | '[:' type ':]' { HsPArrTy $2 }
571 | '{' qcls_name atypes '}' { mkHsDictTy $2 $3 }
572 | '{' ipvar_name '::' type '}' { mkHsIParamTy $2 $4 }
573 | '(' type ')' { $2 }
574 ---------------------------------------------------------------------
576 package :: { PackageName }
578 | {- empty -} { opt_InPackage }
579 -- Useful for .hi-boot files,
580 -- which can omit the package Id
581 -- Module loops are always within a package
583 mod_name :: { ModuleName }
584 : CONID { mkSysModuleNameFS $1 }
587 ---------------------------------------------------
588 var_fs :: { EncodedFS }
590 | 'as' { SLIT("as") }
591 | 'qualified' { SLIT("qualified") }
592 | 'hiding' { SLIT("hiding") }
593 | 'forall' { SLIT("forall") }
594 | 'foreign' { SLIT("foreign") }
595 | 'export' { SLIT("export") }
596 | 'label' { SLIT("label") }
597 | 'dynamic' { SLIT("dynamic") }
598 | 'unsafe' { SLIT("unsafe") }
599 | 'with' { SLIT("with") }
600 | 'ccall' { SLIT("ccall") }
601 | 'stdcall' { SLIT("stdcall") }
603 var_occ :: { OccName }
604 : var_fs { mkSysOccFS varName $1 }
606 var_name :: { RdrName }
607 var_name : var_occ { mkRdrUnqual $1 }
609 qvar_name :: { RdrName }
610 qvar_name : var_name { $1 }
611 | QVARID { mkIfaceOrig varName $1 }
613 ipvar_name :: { IPName RdrName }
614 : IPDUPVARID { Dupable (mkRdrUnqual (mkSysOccFS varName $1)) }
615 | IPSPLITVARID { Linear (mkRdrUnqual (mkSysOccFS varName $1)) }
617 qvar_names1 :: { [RdrName] }
618 qvar_names1 : qvar_name { [$1] }
619 | qvar_name qvar_names1 { $1 : $2 }
621 ---------------------------------------------------
623 data_occ :: { OccName }
624 : CONID { mkSysOccFS dataName $1 }
626 qdata_name :: { RdrName }
627 : data_occ { mkRdrUnqual $1 }
628 | QCONID { mkIfaceOrig dataName $1 }
630 var_or_data_name :: { RdrName }
634 ---------------------------------------------------
635 tc_occ :: { OccName }
636 : CONID { mkSysOccFS tcName $1 }
638 qtc_name :: { RdrName }
639 : tc_occ { mkRdrUnqual $1 }
640 | QCONID { mkIfaceOrig tcName $1 }
642 ---------------------------------------------------
643 qcls_name :: { RdrName }
644 : CONID { mkRdrUnqual (mkSysOccFS clsName $1) }
645 | QCONID { mkIfaceOrig clsName $1 }
647 ---------------------------------------------------
648 tv_name :: { RdrName }
649 : var_fs { mkRdrUnqual (mkSysOccFS tvName $1) }
651 tv_bndr :: { HsTyVarBndr RdrName }
652 : tv_name '::' akind { IfaceTyVar $1 $3 }
653 | tv_name { IfaceTyVar $1 liftedTypeKind }
655 tv_bndrs :: { [HsTyVarBndr RdrName] }
657 | '[' tv_bndrs1 ']' { $2 } -- Backward compatibility
659 tv_bndrs1 :: { [HsTyVarBndr RdrName] }
661 | tv_bndr tv_bndrs1 { $1 : $2 }
663 ---------------------------------------------------
664 fds :: { [([RdrName], [RdrName])] }
666 | '|' fds1 { reverse $2 }
668 fds1 :: { [([RdrName], [RdrName])] }
669 : fds1 ',' fd { $3 : $1 }
672 fd :: { ([RdrName], [RdrName]) }
673 : varids0 '->' varids0 { (reverse $1, reverse $3) }
675 varids0 :: { [RdrName] }
677 | varids0 tv_name { $2 : $1 }
679 ---------------------------------------------------
682 | akind '->' kind { mkArrowKind $1 $3 }
685 : VARSYM { if $1 == SLIT("*") then
687 else if $1 == SLIT("?") then
689 else if $1 == SLIT("\36") then
690 usageTypeKind -- dollar
691 else panic "ParseInterface: akind"
693 | '(' kind ')' { $2 }
695 --------------------------------------------------------------------------
697 id_info :: { [HsIdInfo RdrName] }
698 : id_info_item { [$1] }
699 | id_info_item id_info { $1 : $2 }
701 id_info_item :: { HsIdInfo RdrName }
702 : '__A' INTEGER { HsArity (fromInteger $2) }
703 | '__U' activation core_expr { HsUnfold $2 $3 }
704 | '__S' { HsStrictness $1 }
705 | '__C' { HsNoCafRefs }
706 | '__P' qvar_name INTEGER { HsWorker $2 (fromInteger $3) }
708 -------------------------------------------------------
709 core_expr :: { UfExpr RdrName }
710 core_expr : '\\' core_bndrs '->' core_expr { foldr UfLam $4 $2 }
711 | 'case' core_expr 'of' var_name
712 '{' core_alts '}' { UfCase $2 $4 $6 }
714 | 'let' '{' core_val_bndr '=' core_expr
715 '}' 'in' core_expr { UfLet (UfNonRec $3 $5) $8 }
716 | '__letrec' '{' rec_binds '}'
717 'in' core_expr { UfLet (UfRec $3) $6 }
719 | '__litlit' STRING atype { UfLitLit $2 $3 }
723 fexpr :: { UfExpr RdrName }
724 fexpr : fexpr core_arg { UfApp $1 $2 }
725 | scc core_aexpr { UfNote (UfSCC $1) $2 }
726 | '__inline_me' core_aexpr { UfNote UfInlineMe $2 }
727 | '__inline_call' core_aexpr { UfNote UfInlineCall $2 }
728 | '__coerce' atype core_aexpr { UfNote (UfCoerce $2) $3 }
731 core_arg :: { UfExpr RdrName }
732 : '@' atype { UfType $2 }
735 core_args :: { [UfExpr RdrName] }
737 | core_arg core_args { $1 : $2 }
739 core_aexpr :: { UfExpr RdrName } -- Atomic expressions
740 core_aexpr : qvar_name { UfVar $1 }
741 | qdata_name { UfVar $1 }
743 | core_lit { UfLit $1 }
744 | '(' core_expr ')' { $2 }
746 | '(' ')' { UfTuple (mkHsTupCon dataName Boxed []) [] }
747 | '(' comma_exprs2 ')' { UfTuple (mkHsTupCon dataName Boxed $2) $2 }
748 | '(#' comma_exprs0 '#)' { UfTuple (mkHsTupCon dataName Unboxed $2) $2 }
750 | '{' '__ccall' ccall_string type '}'
752 (is_dyn, is_casm, may_gc) = $2
754 target | is_dyn = DynamicTarget
755 | is_casm = CasmTarget $3
756 | otherwise = StaticTarget $3
758 ccall = CCallSpec target CCallConv may_gc
760 UfFCall (CCall ccall) $4
764 comma_exprs0 :: { [UfExpr RdrName] } -- Zero or more
765 comma_exprs0 : {- empty -} { [ ] }
766 | core_expr { [ $1 ] }
767 | comma_exprs2 { $1 }
769 comma_exprs2 :: { [UfExpr RdrName] } -- Two or more
770 comma_exprs2 : core_expr ',' core_expr { [$1,$3] }
771 | core_expr ',' comma_exprs2 { $1 : $3 }
773 rec_binds :: { [(UfBinder RdrName, UfExpr RdrName)] }
775 | core_val_bndr '=' core_expr ';' rec_binds { ($1,$3) : $5 }
777 core_alts :: { [UfAlt RdrName] }
779 | core_alt ';' core_alts { $1 : $3 }
781 core_alt :: { UfAlt RdrName }
782 core_alt : core_pat '->' core_expr { (fst $1, snd $1, $3) }
784 core_pat :: { (UfConAlt RdrName, [RdrName]) }
785 core_pat : core_lit { (UfLitAlt $1, []) }
786 | '__litlit' STRING atype { (UfLitLitAlt $2 $3, []) }
787 | qdata_name core_pat_names { (UfDataAlt $1, $2) }
788 | '(' ')' { (UfTupleAlt (mkHsTupCon dataName Boxed []), []) }
789 | '(' comma_var_names1 ')' { (UfTupleAlt (mkHsTupCon dataName Boxed $2), $2) }
790 | '(#' comma_var_names1 '#)' { (UfTupleAlt (mkHsTupCon dataName Unboxed $2), $2) }
791 | '__DEFAULT' { (UfDefault, []) }
792 | '(' core_pat ')' { $2 }
794 core_pat_names :: { [RdrName] }
795 core_pat_names : { [] }
796 | core_pat_name core_pat_names { $1 : $2 }
798 -- Tyvar names and variable names live in different name spaces
799 -- so they need to be signalled separately. But we don't record
800 -- types or kinds in a pattern; we work that out from the type
801 -- of the case scrutinee
802 core_pat_name :: { RdrName }
803 core_pat_name : var_name { $1 }
806 comma_var_names1 :: { [RdrName] } -- One or more
807 comma_var_names1 : var_name { [$1] }
808 | var_name ',' comma_var_names1 { $1 : $3 }
810 core_lit :: { Literal }
811 core_lit : integer { mkMachInt $1 }
812 | CHAR { MachChar $1 }
813 | STRING { MachStr $1 }
814 | rational { MachDouble $1 }
815 | '__word' integer { mkMachWord $2 }
816 | '__word64' integer { mkMachWord64 $2 }
817 | '__int64' integer { mkMachInt64 $2 }
818 | '__float' rational { MachFloat $2 }
819 | '__addr' integer { MachAddr $2 }
820 | '__label' STRING { MachLabel $2 }
822 integer :: { Integer }
824 | '-' INTEGER { (-$2) }
826 rational :: { Rational }
828 | '-' RATIONAL { (-$2) }
830 core_bndr :: { UfBinder RdrName }
831 core_bndr : core_val_bndr { $1 }
832 | core_tv_bndr { $1 }
834 core_bndrs :: { [UfBinder RdrName] }
836 | core_bndr core_bndrs { $1 : $2 }
838 core_val_bndr :: { UfBinder RdrName }
839 core_val_bndr : var_name '::' atype { UfValBinder $1 $3 }
841 core_tv_bndr :: { UfBinder RdrName }
842 core_tv_bndr : '@' tv_name '::' akind { UfTyBinder $2 $4 }
843 | '@' tv_name { UfTyBinder $2 liftedTypeKind }
845 ccall_string :: { FAST_STRING }
851 ------------------------------------------------------------------------
852 scc :: { CostCentre }
853 : '__sccC' '{' mod_name '}' { AllCafsCC $3 }
854 | '__scc' '{' cc_name mod_name cc_dup cc_caf '}'
855 { NormalCC { cc_name = $3, cc_mod = $4,
856 cc_is_dupd = $5, cc_is_caf = $6 } }
858 cc_name :: { EncodedFS }
862 cc_dup :: { IsDupdCC }
863 cc_dup : { OriginalCC }
866 cc_caf :: { IsCafCC }
870 -------------------------------------------------------------------
872 src_loc :: { SrcLoc }
873 src_loc : {% getSrcLocP }
875 -- Check the project version: this makes sure
876 -- that the project version (e.g. 407) in the interface
877 -- file is the same as that for the compiler that's reading it
878 checkVersion :: { () }
879 : {-empty-} {% checkVersion Nothing }
880 | INTEGER {% checkVersion (Just (fromInteger $1)) }
882 -------------------------------------------------------------------
887 happyError buf PState{ loc = loc } = PFailed (ifaceParseErr buf loc)
889 mk_con_decl name (ex_tvs, ex_ctxt) details loc = mkConDecl name ex_tvs ex_ctxt details loc