1 {- Notes about the syntax of interface files
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, IfaceStuff(..) ) where
33 #include "HsVersions.h"
35 import HsSyn -- quite a bit of stuff
36 import RdrHsSyn -- oodles of synonyms
37 import HsTypes ( mkHsForAllTy, mkHsUsForAllTy, mkHsTupCon )
39 import Demand ( mkStrictnessInfo )
40 import Literal ( Literal(..), mkMachInt, mkMachInt64, mkMachWord, mkMachWord64 )
41 import BasicTypes ( Fixity(..), FixityDirection(..),
42 NewOrData(..), Version, initialVersion, Boxity(..)
44 import CostCentre ( CostCentre(..), IsCafCC(..), IsDupdCC(..) )
45 import CallConv ( cCallConv )
46 import HsPragmas ( noDataPragmas, noClassPragmas )
47 import Type ( Kind, mkArrowKind, boxedTypeKind, openTypeKind, UsageAnn(..) )
48 import IdInfo ( ArityInfo, exactArity, CprInfo(..), InlinePragInfo(..) )
49 import PrimOp ( CCall(..), CCallTarget(..) )
52 import RnMonad ( ImportVersion, ParsedIface(..), WhatsImported(..),
53 RdrNamePragma, ExportItem, RdrAvailInfo, GenAvailInfo(..),
54 WhetherHasOrphans, IsBootInterface
56 import RdrName ( RdrName, mkRdrUnqual, mkSysQual, mkSysUnqual, mkRdrNameWkr )
57 import Name ( OccName, Provenance )
58 import OccName ( mkSysOccFS,
59 tcName, varName, ipName, dataName, clsName, tvName, uvName,
62 import Module ( ModuleName, PackageName, mkSysModuleFS, mkModule )
63 import SrcLoc ( SrcLoc )
64 import CmdLineOpts ( opt_InPackage )
66 import List ( insert )
69 import FastString ( tailFS )
74 %monad { P }{ thenP }{ returnP }
75 %lexer { lexer } { ITeof }
79 'case' { ITcase } -- Haskell keywords
82 'default' { ITdefault }
83 'deriving' { ITderiving }
93 'instance' { ITinstance }
96 'newtype' { ITnewtype }
98 'qualified' { ITqualified }
103 'forall' { ITforall } -- GHC extension keywords
104 'foreign' { ITforeign }
105 'export' { ITexport }
107 'dynamic' { ITdynamic }
108 'unsafe' { ITunsafe }
110 'stdcall' { ITstdcallconv }
111 'ccall' { ITccallconv }
113 '__interface' { ITinterface } -- interface keywords
114 '__export' { IT__export }
115 '__depends' { ITdepends }
116 '__forall' { IT__forall }
117 '__letrec' { ITletrec }
118 '__coerce' { ITcoerce }
119 '__inline_me' { ITinlineMe }
120 '__inline_call'{ ITinlineCall }
121 '__DEFAULT' { ITdefaultbranch }
123 '__integer' { ITinteger_lit }
124 '__float' { ITfloat_lit }
125 '__word' { ITword_lit }
126 '__int64' { ITint64_lit }
127 '__word64' { ITword64_lit }
128 '__rational' { ITrational_lit }
129 '__addr' { ITaddr_lit }
130 '__label' { ITlabel_lit }
131 '__litlit' { ITlit_lit }
132 '__string' { ITstring_lit }
133 '__ccall' { ITccall $$ }
135 '__sccC' { ITsccAllCafs }
138 '__fuall' { ITfuall }
141 '__P' { ITspecialise }
143 '__U' { ITunfold $$ }
144 '__S' { ITstrict $$ }
147 '__D' { ITdeprecated }
149 '..' { ITdotdot } -- reserved symbols
162 '/\\' { ITbiglam } -- GHC-extension symbols
164 '{' { ITocurly } -- special symbols
175 VARID { ITvarid $$ } -- identifiers
177 VARSYM { ITvarsym $$ }
178 CONSYM { ITconsym $$ }
179 QVARID { ITqvarid $$ }
180 QCONID { ITqconid $$ }
181 QVARSYM { ITqvarsym $$ }
182 QCONSYM { ITqconsym $$ }
184 IPVARID { ITipvarid $$ } -- GHC extension
186 PRAGMA { ITpragma $$ }
189 STRING { ITstring $$ }
190 INTEGER { ITinteger $$ }
191 RATIONAL { ITrational $$ }
192 CLITLIT { ITlitlit $$ }
194 UNKNOWN { ITunknown $$ }
197 -- iface_stuff is the main production.
198 -- It recognises (a) a whole interface file
199 -- (b) a type (so that type sigs can be parsed lazily)
200 -- (c) the IdInfo part of a signature (same reason)
202 iface_stuff :: { IfaceStuff }
203 iface_stuff : iface { PIface $1 }
205 | id_info { PIdInfo $1 }
206 | '__R' rules { PRules $2 }
207 | '__D' deprecs { PDeprecs $2 }
210 iface :: { ParsedIface }
211 iface : '__interface' package mod_name
213 orphans checkVersion 'where'
221 pi_mod = mkModule $3 $2, -- Module itself
222 pi_vers = $4, -- Module version
224 pi_exports = $9, -- Exports
225 pi_usages = $10, -- Usages
226 pi_fixity = (fst $5,$11), -- Fixies
227 pi_insts = $12, -- Local instances
228 pi_decls = $13, -- Decls
229 pi_rules = (snd $5,fst $14), -- Rules
230 pi_deprecs = snd $14 -- Deprecations
233 -- Versions for fixities and rules (optional)
234 sub_versions :: { (Version,Version) }
235 : '[' version version ']' { ($2,$3) }
236 | {- empty -} { (initialVersion, initialVersion) }
238 --------------------------------------------------------------------------
240 import_part :: { [ImportVersion OccName] }
242 | import_decl import_part { $1 : $2 }
244 import_decl :: { ImportVersion OccName }
245 import_decl : 'import' mod_name orphans is_boot whats_imported ';'
246 { (mkSysModuleFS $2, $3, $4, $5) }
248 orphans :: { WhetherHasOrphans }
252 is_boot :: { IsBootInterface }
256 whats_imported :: { WhatsImported OccName }
257 whats_imported : { NothingAtAll }
258 | '::' version { Everything $2 }
259 | '::' version version version name_version_pairs { Specifically $2 $3 $4 $5 }
261 name_version_pairs :: { [(OccName, Version)] }
262 name_version_pairs : { [] }
263 | name_version_pair name_version_pairs { $1 : $2 }
265 name_version_pair :: { (OccName, Version) }
266 name_version_pair : var_occ version { ($1, $2) }
267 | tc_occ version { ($1, $2) }
270 --------------------------------------------------------------------------
272 exports_part :: { [ExportItem] }
273 exports_part : { [] }
274 | '__export' mod_name entities ';'
275 exports_part { (mkSysModuleFS $2, $3) : $5 }
277 entities :: { [RdrAvailInfo] }
279 | entity entities { $1 : $2 }
281 entity :: { RdrAvailInfo }
282 entity : var_occ { Avail $1 }
283 | tc_occ { AvailTC $1 [$1] }
284 | tc_occ '|' stuff_inside { AvailTC $1 $3 }
285 | tc_occ stuff_inside { AvailTC $1 (insert $1 $2) }
286 -- The 'insert' is important. The stuff_inside is sorted, and
287 -- insert keeps it that way. This is important when comparing
288 -- against the new interface file, which has the stuff in sorted order
289 -- If they differ, we'll bump the module number when it's unnecessary
291 stuff_inside :: { [OccName] }
292 stuff_inside : '{' val_occs '}' { $2 }
294 val_occ :: { OccName }
298 val_occs :: { [OccName] }
300 | val_occ val_occs { $1 : $2 }
303 --------------------------------------------------------------------------
305 fix_decl_part :: { [RdrNameFixitySig] }
306 fix_decl_part : {- empty -} { [] }
307 | fix_decls ';' { $1 }
309 fix_decls :: { [RdrNameFixitySig] }
311 | fix_decl fix_decls { $1 : $2 }
313 fix_decl :: { RdrNameFixitySig }
314 fix_decl : src_loc fixity prec var_or_data_name { FixitySig $4 (Fixity $3 $2) $1 }
316 fixity :: { FixityDirection }
317 fixity : 'infixl' { InfixL }
318 | 'infixr' { InfixR }
322 prec : INTEGER { fromInteger $1 }
324 -----------------------------------------------------------------------------
326 csigs :: { [RdrNameSig] }
328 | 'where' '{' csigs1 '}' { $3 }
330 csigs1 :: { [RdrNameSig] }
332 | csig ';' csigs1 { $1 : $3 }
334 csig :: { RdrNameSig }
335 csig : src_loc var_name '::' type { mkClassOpSig False $2 $4 $1 }
336 | src_loc var_name '=' '::' type { mkClassOpSig True $2 $5 $1 }
338 --------------------------------------------------------------------------
340 instance_decl_part :: { [RdrNameInstDecl] }
341 instance_decl_part : {- empty -} { [] }
342 | instance_decl_part inst_decl { $2 : $1 }
344 inst_decl :: { RdrNameInstDecl }
345 inst_decl : src_loc 'instance' type '=' var_name ';'
347 EmptyMonoBinds {- No bindings -}
348 [] {- No user pragmas -}
349 (Just $5) {- Dfun id -}
353 --------------------------------------------------------------------------
355 decls_part :: { [(Version, RdrNameHsDecl)] }
358 | opt_version decl ';' decls_part { ($1,$2):$4 }
360 decl :: { RdrNameHsDecl }
361 decl : src_loc var_name '::' type maybe_idinfo
362 { SigD (IfaceSig $2 $4 ($5 $2) $1) }
363 | src_loc 'type' tc_name tv_bndrs '=' type
364 { TyClD (TySynonym $3 $4 $6 $1) }
365 | src_loc 'data' opt_decl_context tc_name tv_bndrs constrs
366 { TyClD (TyData DataType $3 $4 $5 $6 (length $6) Nothing noDataPragmas $1) }
367 | src_loc 'newtype' opt_decl_context tc_name tv_bndrs newtype_constr
368 { TyClD (TyData NewType $3 $4 $5 $6 1 Nothing noDataPragmas $1) }
369 | src_loc 'class' opt_decl_context tc_name tv_bndrs fds csigs
370 { TyClD (mkClassDecl $3 $4 $5 $6 $7 EmptyMonoBinds
373 maybe_idinfo :: { RdrName -> [HsIdInfo RdrName] }
374 maybe_idinfo : {- empty -} { \_ -> [] }
375 | pragma { \x -> case $1 of
376 POk _ (PIdInfo id_info) -> id_info
378 pprPanic "IdInfo parse failed"
382 pragma :: { ParseResult IfaceStuff }
383 pragma : src_loc PRAGMA { parseIface $2 PState{ bol = 0#, atbol = 1#,
389 -----------------------------------------------------------------------------
391 rules_and_deprecs :: { ([RdrNameRuleDecl], [RdrNameDeprecation]) }
392 rules_and_deprecs : {- empty -} { ([], []) }
393 | rules_and_deprecs rule_or_deprec
395 append2 (xs1,ys1) (xs2,ys2) =
396 (xs1 `app` xs2, ys1 `app` ys2)
397 xs `app` [] = xs -- performance paranoia
398 xs `app` ys = xs ++ ys
402 rule_or_deprec :: { ([RdrNameRuleDecl], [RdrNameDeprecation]) }
403 rule_or_deprec : pragma { case $1 of
404 POk _ (PRules rules) -> (rules,[])
405 POk _ (PDeprecs deprecs) -> ([],deprecs)
406 PFailed err -> pprPanic "Rules/Deprecations parse failed" err
409 -----------------------------------------------------------------------------
411 rules :: { [RdrNameRuleDecl] }
413 | rule ';' rules { $1:$3 }
415 rule :: { RdrNameRuleDecl }
416 rule : src_loc STRING rule_forall qvar_name
417 core_args '=' core_expr { IfaceRule $2 $3 $4 $5 $7 $1 }
419 rule_forall :: { [UfBinder RdrName] }
420 rule_forall : '__forall' '{' core_bndrs '}' { $3 }
422 -----------------------------------------------------------------------------
424 deprecs :: { [RdrNameDeprecation] }
425 deprecs : {- empty -} { [] }
426 | deprec ';' deprecs { $1 : $3 }
428 deprec :: { RdrNameDeprecation }
429 deprec : src_loc STRING { Deprecation (IEModuleContents undefined) $2 $1 }
430 | src_loc deprec_name STRING { Deprecation $2 $3 $1 }
432 -- SUP: TEMPORARY HACK
433 deprec_name :: { RdrNameIE }
434 : var_name { IEVar $1 }
435 | data_name { IEThingAbs $1 }
437 -----------------------------------------------------------------------------
439 version :: { Version }
440 version : INTEGER { fromInteger $1 }
442 opt_version :: { Version }
443 opt_version : version { $1 }
444 | {- empty -} { initialVersion }
446 opt_decl_context :: { RdrNameContext }
447 opt_decl_context : { [] }
448 | context '=>' { $1 }
450 ----------------------------------------------------------------------------
452 constrs :: { [RdrNameConDecl] {- empty for handwritten abstract -} }
454 | '=' constrs1 { $2 }
456 constrs1 :: { [RdrNameConDecl] }
457 constrs1 : constr { [$1] }
458 | constr '|' constrs1 { $1 : $3 }
460 constr :: { RdrNameConDecl }
461 constr : src_loc ex_stuff data_name batypes { mk_con_decl $3 $2 (VanillaCon $4) $1 }
462 | src_loc ex_stuff data_name '{' fields1 '}' { mk_con_decl $3 $2 (RecCon $5) $1 }
463 -- We use "data_fs" so as to include ()
465 newtype_constr :: { [RdrNameConDecl] {- Not allowed to be empty -} }
466 newtype_constr : src_loc '=' ex_stuff data_name atype { [mk_con_decl $4 $3 (VanillaCon [Unbanged $5]) $1] }
467 | src_loc '=' ex_stuff data_name '{' var_name '::' atype '}'
468 { [mk_con_decl $4 $3 (RecCon [([$6], Unbanged $8)]) $1] }
470 ex_stuff :: { ([HsTyVarBndr RdrName], RdrNameContext) }
471 ex_stuff : { ([],[]) }
472 | '__forall' tv_bndrs opt_context '=>' { ($2,$3) }
474 batypes :: { [RdrNameBangType] }
476 | batype batypes { $1 : $2 }
478 batype :: { RdrNameBangType }
479 batype : atype { Unbanged $1 }
480 | '!' atype { Banged $2 }
481 | '!' '!' atype { Unpacked $3 }
483 fields1 :: { [([RdrName], RdrNameBangType)] }
484 fields1 : field { [$1] }
485 | field ',' fields1 { $1 : $3 }
487 field :: { ([RdrName], RdrNameBangType) }
488 field : var_names1 '::' type { ($1, Unbanged $3) }
489 | var_names1 '::' '!' type { ($1, Banged $4) }
490 | var_names1 '::' '!' '!' type { ($1, Unpacked $5) }
491 --------------------------------------------------------------------------
493 type :: { RdrNameHsType }
494 type : '__fuall' fuall '=>' type { mkHsUsForAllTy $2 $4 }
495 | '__forall' tv_bndrs
496 opt_context '=>' type { mkHsForAllTy (Just $2) $3 $5 }
497 | btype '->' type { HsFunTy $1 $3 }
500 fuall :: { [RdrName] }
501 fuall : '[' uv_bndrs ']' { $2 }
503 opt_context :: { RdrNameContext }
507 context :: { RdrNameContext }
508 context : '(' context_list1 ')' { $2 }
509 | '{' context_list1 '}' { $2 } -- Backward compatibility
511 context_list1 :: { RdrNameContext }
512 context_list1 : class { [$1] }
513 | class ',' context_list1 { $1 : $3 }
515 class :: { HsPred RdrName }
516 class : qcls_name atypes { (HsPClass $1 $2) }
517 | ipvar_name '::' type { (HsPIParam $1 $3) }
519 types0 :: { [RdrNameHsType] {- Zero or more -} }
520 types0 : {- empty -} { [ ] }
524 types2 :: { [RdrNameHsType] {- Two or more -} }
525 types2 : type ',' type { [$1,$3] }
526 | type ',' types2 { $1 : $3 }
528 btype :: { RdrNameHsType }
530 | btype atype { HsAppTy $1 $2 }
531 | '__u' usage atype { HsUsgTy $2 $3 }
533 usage :: { HsUsageAnn RdrName }
534 usage : '-' { HsUsOnce }
536 | uv_name { HsUsVar $1 }
538 atype :: { RdrNameHsType }
539 atype : qtc_name { HsTyVar $1 }
540 | tv_name { HsTyVar $1 }
541 | '(' ')' { HsTupleTy (mkHsTupCon tcName Boxed []) [] }
542 | '(' types2 ')' { HsTupleTy (mkHsTupCon tcName Boxed $2) $2 }
543 | '(#' types0 '#)' { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
544 | '[' type ']' { HsListTy $2 }
545 | '{' qcls_name atypes '}' { mkHsDictTy $2 $3 }
546 | '{' ipvar_name '::' type '}' { mkHsIParamTy $2 $4 }
547 | '(' type ')' { $2 }
549 atypes :: { [RdrNameHsType] {- Zero or more -} }
551 | atype atypes { $1 : $2 }
552 ---------------------------------------------------------------------
553 package :: { PackageName }
555 | {- empty -} { opt_InPackage } -- Useful for .hi-boot files,
556 -- which can omit the package Id
557 -- Module loops are always within a package
559 mod_name :: { ModuleName }
560 : CONID { mkSysModuleFS $1 }
563 ---------------------------------------------------
564 var_fs :: { EncodedFS }
567 | 'as' { SLIT("as") }
568 | 'qualified' { SLIT("qualified") }
569 | 'hiding' { SLIT("hiding") }
570 | 'forall' { SLIT("forall") }
571 | 'foreign' { SLIT("foreign") }
572 | 'export' { SLIT("export") }
573 | 'label' { SLIT("label") }
574 | 'dynamic' { SLIT("dynamic") }
575 | 'unsafe' { SLIT("unsafe") }
576 | 'with' { SLIT("with") }
577 | 'ccall' { SLIT("ccall") }
578 | 'stdcall' { SLIT("stdcall") }
580 qvar_fs :: { (EncodedFS, EncodedFS) }
584 var_occ :: { OccName }
585 : var_fs { mkSysOccFS varName $1 }
587 var_name :: { RdrName }
588 var_name : var_occ { mkRdrUnqual $1 }
590 qvar_name :: { RdrName }
591 qvar_name : var_name { $1 }
592 | qvar_fs { mkSysQual varName $1 }
594 ipvar_name :: { RdrName }
595 : IPVARID { mkSysUnqual ipName (tailFS $1) }
597 var_names :: { [RdrName] }
599 | var_name var_names { $1 : $2 }
601 var_names1 :: { [RdrName] }
602 var_names1 : var_name var_names { $1 : $2 }
604 ---------------------------------------------------
605 -- For some bizarre reason,
606 -- (,,,) is dealt with by the parser
607 -- Foo.(,,,) is dealt with by the lexer
610 data_fs :: { EncodedFS }
614 qdata_fs :: { (EncodedFS, EncodedFS) }
618 data_occ :: { OccName }
619 : data_fs { mkSysOccFS dataName $1 }
621 data_name :: { RdrName }
622 : data_occ { mkRdrUnqual $1 }
624 qdata_name :: { RdrName }
625 qdata_name : data_name { $1 }
626 | qdata_fs { mkSysQual dataName $1 }
628 qdata_names :: { [RdrName] }
630 | qdata_name qdata_names { $1 : $2 }
632 var_or_data_name :: { RdrName }
636 ---------------------------------------------------
637 tc_fs :: { EncodedFS }
640 tc_occ :: { OccName }
641 : tc_fs { mkSysOccFS tcName $1 }
643 tc_name :: { RdrName }
644 : tc_occ { mkRdrUnqual $1 }
646 qtc_name :: { RdrName }
648 | qdata_fs { mkSysQual tcName $1 }
650 ---------------------------------------------------
651 cls_name :: { RdrName }
652 : data_fs { mkSysUnqual clsName $1 }
654 qcls_name :: { RdrName }
656 | qdata_fs { mkSysQual clsName $1 }
658 ---------------------------------------------------
659 uv_name :: { RdrName }
660 : VARID { mkSysUnqual uvName $1 }
662 uv_bndr :: { RdrName }
665 uv_bndrs :: { [RdrName] }
667 | uv_bndr uv_bndrs { $1 : $2 }
669 ---------------------------------------------------
670 tv_name :: { RdrName }
671 : VARID { mkSysUnqual tvName $1 }
672 | VARSYM { mkSysUnqual tvName $1 {- Allow t2 as a tyvar -} }
674 tv_bndr :: { HsTyVarBndr RdrName }
675 : tv_name '::' akind { IfaceTyVar $1 $3 }
676 | tv_name { IfaceTyVar $1 boxedTypeKind }
678 tv_bndrs :: { [HsTyVarBndr RdrName] }
679 tv_bndrs : tv_bndrs1 { $1 }
680 | '[' tv_bndrs1 ']' { $2 } -- Backward compatibility
682 tv_bndrs1 :: { [HsTyVarBndr RdrName] }
684 | tv_bndr tv_bndrs1 { $1 : $2 }
686 ---------------------------------------------------
687 fds :: { [([RdrName], [RdrName])] }
689 | '|' fds1 { reverse $2 }
691 fds1 :: { [([RdrName], [RdrName])] }
692 : fds1 ',' fd { $3 : $1 }
695 fd :: { ([RdrName], [RdrName]) }
696 : varids0 '->' varids0 { (reverse $1, reverse $3) }
698 varids0 :: { [RdrName] }
700 | varids0 tv_name { $2 : $1 }
702 ---------------------------------------------------
705 | akind '->' kind { mkArrowKind $1 $3 }
708 : VARSYM { if $1 == SLIT("*") then
710 else if $1 == SLIT("?") then
712 else panic "ParseInterface: akind"
714 | '(' kind ')' { $2 }
716 --------------------------------------------------------------------------
718 id_info :: { [HsIdInfo RdrName] }
720 | id_info_item id_info { $1 : $2 }
722 id_info_item :: { HsIdInfo RdrName }
723 : '__A' INTEGER { HsArity (exactArity (fromInteger $2)) }
724 | '__U' inline_prag core_expr { HsUnfold $2 $3 }
725 | '__M' { HsCprInfo }
726 | '__S' { HsStrictness (mkStrictnessInfo $1) }
727 | '__C' { HsNoCafRefs }
728 | '__P' qvar_name { HsWorker $2 }
730 inline_prag :: { InlinePragInfo }
731 : {- empty -} { NoInlinePragInfo }
732 | '[' from_prag phase ']' { IMustNotBeINLINEd $2 $3 }
734 from_prag :: { Bool }
735 : {- empty -} { True }
738 phase :: { Maybe Int }
739 : {- empty -} { Nothing }
740 | INTEGER { Just (fromInteger $1) }
742 -------------------------------------------------------
743 core_expr :: { UfExpr RdrName }
744 core_expr : '\\' core_bndrs '->' core_expr { foldr UfLam $4 $2 }
745 | 'case' core_expr 'of' var_name
746 '{' core_alts '}' { UfCase $2 $4 $6 }
748 | 'let' '{' core_val_bndr '=' core_expr
749 '}' 'in' core_expr { UfLet (UfNonRec $3 $5) $8 }
750 | '__letrec' '{' rec_binds '}'
751 'in' core_expr { UfLet (UfRec $3) $6 }
753 | '__litlit' STRING atype { UfLitLit $2 $3 }
757 fexpr :: { UfExpr RdrName }
758 fexpr : fexpr core_arg { UfApp $1 $2 }
759 | scc core_aexpr { UfNote (UfSCC $1) $2 }
760 | '__inline_me' core_aexpr { UfNote UfInlineMe $2 }
761 | '__inline_call' core_aexpr { UfNote UfInlineCall $2 }
762 | '__coerce' atype core_aexpr { UfNote (UfCoerce $2) $3 }
765 core_arg :: { UfExpr RdrName }
766 : '@' atype { UfType $2 }
769 core_args :: { [UfExpr RdrName] }
771 | core_arg core_args { $1 : $2 }
773 core_aexpr :: { UfExpr RdrName } -- Atomic expressions
774 core_aexpr : qvar_name { UfVar $1 }
775 | qdata_name { UfVar $1 }
777 | core_lit { UfLit $1 }
778 | '(' core_expr ')' { $2 }
780 | '(' ')' { UfTuple (mkHsTupCon dataName Boxed []) [] }
781 | '(' comma_exprs2 ')' { UfTuple (mkHsTupCon dataName Boxed $2) $2 }
782 | '(#' comma_exprs0 '#)' { UfTuple (mkHsTupCon dataName Unboxed $2) $2 }
784 | '{' '__ccall' ccall_string type '}'
786 (is_dyn, is_casm, may_gc) = $2
788 target | is_dyn = DynamicTarget (error "CCall dyn target bogus unique")
789 | otherwise = StaticTarget $3
791 ccall = CCall target is_casm may_gc cCallConv
797 comma_exprs0 :: { [UfExpr RdrName] } -- Zero or more
798 comma_exprs0 : {- empty -} { [ ] }
799 | core_expr { [ $1 ] }
800 | comma_exprs2 { $1 }
802 comma_exprs2 :: { [UfExpr RdrName] } -- Two or more
803 comma_exprs2 : core_expr ',' core_expr { [$1,$3] }
804 | core_expr ',' comma_exprs2 { $1 : $3 }
806 rec_binds :: { [(UfBinder RdrName, UfExpr RdrName)] }
808 | core_val_bndr '=' core_expr ';' rec_binds { ($1,$3) : $5 }
810 core_alts :: { [UfAlt RdrName] }
812 | core_alt ';' core_alts { $1 : $3 }
814 core_alt :: { UfAlt RdrName }
815 core_alt : core_pat '->' core_expr { (fst $1, snd $1, $3) }
817 core_pat :: { (UfConAlt RdrName, [RdrName]) }
818 core_pat : core_lit { (UfLitAlt $1, []) }
819 | '__litlit' STRING atype { (UfLitLitAlt $2 $3, []) }
820 | qdata_name core_pat_names { (UfDataAlt $1, $2) }
821 | '(' ')' { (UfTupleAlt (mkHsTupCon dataName Boxed []), []) }
822 | '(' comma_var_names1 ')' { (UfTupleAlt (mkHsTupCon dataName Boxed $2), $2) }
823 | '(#' comma_var_names1 '#)' { (UfTupleAlt (mkHsTupCon dataName Unboxed $2), $2) }
824 | '__DEFAULT' { (UfDefault, []) }
825 | '(' core_pat ')' { $2 }
827 core_pat_names :: { [RdrName] }
828 core_pat_names : { [] }
829 | core_pat_name core_pat_names { $1 : $2 }
831 -- Tyvar names and variable names live in different name spaces
832 -- so they need to be signalled separately. But we don't record
833 -- types or kinds in a pattern; we work that out from the type
834 -- of the case scrutinee
835 core_pat_name :: { RdrName }
836 core_pat_name : var_name { $1 }
839 comma_var_names1 :: { [RdrName] } -- One or more
840 comma_var_names1 : var_name { [$1] }
841 | var_name ',' comma_var_names1 { $1 : $3 }
843 core_lit :: { Literal }
844 core_lit : integer { mkMachInt $1 }
845 | CHAR { MachChar $1 }
846 | STRING { MachStr $1 }
847 | rational { MachDouble $1 }
848 | '__word' integer { mkMachWord $2 }
849 | '__word64' integer { mkMachWord64 $2 }
850 | '__int64' integer { mkMachInt64 $2 }
851 | '__float' rational { MachFloat $2 }
852 | '__addr' integer { MachAddr $2 }
853 | '__label' STRING { MachLabel $2 }
855 integer :: { Integer }
857 | '-' INTEGER { (-$2) }
859 rational :: { Rational }
861 | '-' RATIONAL { (-$2) }
863 core_bndr :: { UfBinder RdrName }
864 core_bndr : core_val_bndr { $1 }
865 | core_tv_bndr { $1 }
867 core_bndrs :: { [UfBinder RdrName] }
869 | core_bndr core_bndrs { $1 : $2 }
871 core_val_bndr :: { UfBinder RdrName }
872 core_val_bndr : var_name '::' atype { UfValBinder $1 $3 }
874 core_tv_bndr :: { UfBinder RdrName }
875 core_tv_bndr : '@' tv_name '::' akind { UfTyBinder $2 $4 }
876 | '@' tv_name { UfTyBinder $2 boxedTypeKind }
878 ccall_string :: { FAST_STRING }
884 ------------------------------------------------------------------------
885 scc :: { CostCentre }
886 : '__sccC' '{' mod_name '}' { AllCafsCC $3 }
887 | '__scc' '{' cc_name mod_name cc_dup cc_caf '}'
888 { NormalCC { cc_name = $3, cc_mod = $4,
889 cc_is_dupd = $5, cc_is_caf = $6 } }
891 cc_name :: { EncodedFS }
895 cc_dup :: { IsDupdCC }
896 cc_dup : { OriginalCC }
899 cc_caf :: { IsCafCC }
903 -------------------------------------------------------------------
905 src_loc :: { SrcLoc }
906 src_loc : {% getSrcLocP }
908 -- Check the project version: this makes sure
909 -- that the project version (e.g. 407) in the interface
910 -- file is the same as that for the compiler that's reading it
911 checkVersion :: { () }
912 : {-empty-} {% checkVersion Nothing }
913 | INTEGER {% checkVersion (Just (fromInteger $1)) }
915 -------------------------------------------------------------------
920 happyError buf PState{ loc = loc } = PFailed (ifaceParseErr buf loc)
922 data IfaceStuff = PIface ParsedIface
923 | PIdInfo [HsIdInfo RdrName]
924 | PType RdrNameHsType
925 | PRules [RdrNameRuleDecl]
926 | PDeprecs [RdrNameDeprecation]
928 mk_con_decl name (ex_tvs, ex_ctxt) details loc = mkConDecl name ex_tvs ex_ctxt details loc