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 Type ( Kind, mkArrowKind, boxedTypeKind, openTypeKind )
47 import IdInfo ( exactArity, InlinePragInfo(..) )
48 import PrimOp ( CCall(..), CCallTarget(..) )
51 import RnMonad ( ParsedIface(..), ExportItem, IfaceDeprecs )
52 import HscTypes ( WhetherHasOrphans, IsBootInterface, GenAvailInfo(..),
53 ImportVersion, WhatsImported(..),
56 import RdrName ( RdrName, mkRdrUnqual, mkSysQual, mkSysUnqual )
57 import Name ( OccName )
58 import OccName ( mkSysOccFS,
59 tcName, varName, ipName, dataName, clsName, tvName, uvName,
62 import Module ( ModuleName, PackageName, mkSysModuleNameFS, mkModule )
63 import SrcLoc ( SrcLoc )
64 import CmdLineOpts ( opt_InPackage, opt_IgnoreIfacePragmas )
66 import List ( insert )
67 import Class ( DefMeth (..) )
70 import FastString ( tailFS )
75 %monad { P }{ thenP }{ returnP }
76 %lexer { lexer } { ITeof }
80 'case' { ITcase } -- Haskell keywords
83 'default' { ITdefault }
84 'deriving' { ITderiving }
94 'instance' { ITinstance }
97 'newtype' { ITnewtype }
99 'qualified' { ITqualified }
104 'forall' { ITforall } -- GHC extension keywords
105 'foreign' { ITforeign }
106 'export' { ITexport }
108 'dynamic' { ITdynamic }
109 'unsafe' { ITunsafe }
111 'stdcall' { ITstdcallconv }
112 'ccall' { ITccallconv }
114 '__interface' { ITinterface } -- interface keywords
115 '__export' { IT__export }
116 '__depends' { ITdepends }
117 '__forall' { IT__forall }
118 '__letrec' { ITletrec }
119 '__coerce' { ITcoerce }
120 '__inline_me' { ITinlineMe }
121 '__inline_call'{ ITinlineCall }
122 '__DEFAULT' { ITdefaultbranch }
124 '__integer' { ITinteger_lit }
125 '__float' { ITfloat_lit }
126 '__word' { ITword_lit }
127 '__int64' { ITint64_lit }
128 '__word64' { ITword64_lit }
129 '__rational' { ITrational_lit }
130 '__addr' { ITaddr_lit }
131 '__label' { ITlabel_lit }
132 '__litlit' { ITlit_lit }
133 '__string' { ITstring_lit }
134 '__ccall' { ITccall $$ }
136 '__sccC' { ITsccAllCafs }
139 '__fuall' { ITfuall }
142 '__P' { ITspecialise }
144 '__U' { ITunfold $$ }
145 '__S' { ITstrict $$ }
148 '__D' { ITdeprecated }
150 '..' { ITdotdot } -- reserved symbols
163 '/\\' { ITbiglam } -- GHC-extension symbols
165 '{' { ITocurly } -- special symbols
167 '{|' { ITocurlybar } -- special symbols
168 '|}' { ITccurlybar } -- special symbols
178 VARID { ITvarid $$ } -- identifiers
180 VARSYM { ITvarsym $$ }
181 CONSYM { ITconsym $$ }
182 QVARID { ITqvarid $$ }
183 QCONID { ITqconid $$ }
184 QVARSYM { ITqvarsym $$ }
185 QCONSYM { ITqconsym $$ }
187 IPVARID { ITipvarid $$ } -- GHC extension
189 PRAGMA { ITpragma $$ }
192 STRING { ITstring $$ }
193 INTEGER { ITinteger $$ }
194 RATIONAL { ITrational $$ }
195 CLITLIT { ITlitlit $$ }
197 UNKNOWN { ITunknown $$ }
200 -- iface_stuff is the main production.
201 -- It recognises (a) a whole interface file
202 -- (b) a type (so that type sigs can be parsed lazily)
203 -- (c) the IdInfo part of a signature (same reason)
205 iface_stuff :: { IfaceStuff }
206 iface_stuff : iface { PIface $1 }
208 | id_info { PIdInfo $1 }
209 | rules_and_deprecs { PRulesAndDeprecs $1 }
211 iface :: { ParsedIface }
212 iface : '__interface' package mod_name
214 orphans checkVersion 'where'
220 rules_and_deprecs_part
222 pi_mod = mkModule $3 $2, -- Module itself
223 pi_vers = $4, -- Module version
225 pi_exports = (fst $5, $9), -- Exports
226 pi_usages = $10, -- Usages
227 pi_fixity = $11, -- Fixies
228 pi_insts = $12, -- Local instances
229 pi_decls = $13, -- Decls
230 pi_rules = (snd $5,fst $14), -- Rules
231 pi_deprecs = snd $14 -- Deprecations
234 -- Versions for exports and rules (optional)
235 sub_versions :: { (Version,Version) }
236 : '[' version version ']' { ($2,$3) }
237 | {- empty -} { (initialVersion, initialVersion) }
239 --------------------------------------------------------------------------
241 import_part :: { [ImportVersion OccName] }
243 | import_decl import_part { $1 : $2 }
245 import_decl :: { ImportVersion OccName }
246 import_decl : 'import' mod_name orphans is_boot whats_imported ';'
247 { ({-mkSysModuleNameFS-} $2, $3, $4, $5) }
249 orphans :: { WhetherHasOrphans }
253 is_boot :: { IsBootInterface }
257 whats_imported :: { WhatsImported OccName }
258 whats_imported : { NothingAtAll }
259 | '::' version { Everything $2 }
260 | '::' version version name_version_pairs version { Specifically $2 (Just $3) $4 $5 }
262 name_version_pairs :: { [(OccName, Version)] }
263 name_version_pairs : { [] }
264 | name_version_pair name_version_pairs { $1 : $2 }
266 name_version_pair :: { (OccName, Version) }
267 name_version_pair : var_occ version { ($1, $2) }
268 | tc_occ version { ($1, $2) }
271 --------------------------------------------------------------------------
273 exports_part :: { [ExportItem] }
274 exports_part : { [] }
275 | '__export' mod_name entities ';'
276 exports_part { ({-mkSysModuleNameFS-} $2, $3) : $5 }
278 entities :: { [RdrAvailInfo] }
280 | entity entities { $1 : $2 }
282 entity :: { RdrAvailInfo }
283 entity : var_occ { Avail $1 }
284 | tc_occ { AvailTC $1 [$1] }
285 | tc_occ '|' stuff_inside { AvailTC $1 $3 }
286 | tc_occ stuff_inside { AvailTC $1 (insert $1 $2) }
287 -- The 'insert' is important. The stuff_inside is sorted, and
288 -- insert keeps it that way. This is important when comparing
289 -- against the new interface file, which has the stuff in sorted order
290 -- If they differ, we'll bump the module number when it's unnecessary
292 stuff_inside :: { [OccName] }
293 stuff_inside : '{' val_occs '}' { $2 }
295 val_occ :: { OccName }
299 val_occs :: { [OccName] }
301 | val_occ val_occs { $1 : $2 }
304 --------------------------------------------------------------------------
306 fix_decl_part :: { [RdrNameFixitySig] }
307 fix_decl_part : {- empty -} { [] }
308 | fix_decls ';' { $1 }
310 fix_decls :: { [RdrNameFixitySig] }
312 | fix_decl fix_decls { $1 : $2 }
314 fix_decl :: { RdrNameFixitySig }
315 fix_decl : src_loc fixity prec var_or_data_name { FixitySig $4 (Fixity $3 $2) $1 }
317 fixity :: { FixityDirection }
318 fixity : 'infixl' { InfixL }
319 | 'infixr' { InfixR }
323 prec : INTEGER { fromInteger $1 }
325 -----------------------------------------------------------------------------
327 csigs :: { [RdrNameSig] }
329 | 'where' '{' csigs1 '}' { $3 }
331 csigs1 :: { [RdrNameSig] }
333 | csig ';' csigs1 { $1 : $3 }
335 csig :: { RdrNameSig }
336 csig : src_loc var_name '::' type { mkClassOpSig NoDefMeth $2 $4 $1 }
337 | src_loc var_name '=' '::' type { mkClassOpSig (DefMeth (error "DefMeth") )
339 | src_loc var_name ';' '::' type { mkClassOpSig GenDefMeth $2 $5 $1 }
341 --------------------------------------------------------------------------
343 instance_decl_part :: { [RdrNameInstDecl] }
344 instance_decl_part : {- empty -} { [] }
345 | instance_decl_part inst_decl { $2 : $1 }
347 inst_decl :: { RdrNameInstDecl }
348 inst_decl : src_loc 'instance' type '=' var_name ';'
350 EmptyMonoBinds {- No bindings -}
351 [] {- No user pragmas -}
352 (Just $5) {- Dfun id -}
356 --------------------------------------------------------------------------
358 decls_part :: { [(Version, RdrNameTyClDecl)] }
361 | opt_version decl ';' decls_part { ($1,$2):$4 }
363 decl :: { RdrNameTyClDecl }
364 decl : src_loc var_name '::' type maybe_idinfo
365 { IfaceSig $2 $4 ($5 $2) $1 }
366 | src_loc 'type' tc_name tv_bndrs '=' type
367 { TySynonym $3 $4 $6 $1 }
368 | src_loc 'data' opt_decl_context tc_name tv_bndrs constrs
369 { mkTyData DataType $3 $4 $5 $6 (length $6) Nothing $1 }
370 | src_loc 'newtype' opt_decl_context tc_name tv_bndrs newtype_constr
371 { mkTyData NewType $3 $4 $5 $6 1 Nothing $1 }
372 | src_loc 'class' opt_decl_context tc_name tv_bndrs fds csigs
373 { mkClassDecl $3 $4 $5 $6 $7 EmptyMonoBinds $1 }
375 maybe_idinfo :: { RdrName -> [HsIdInfo RdrName] }
376 maybe_idinfo : {- empty -} { \_ -> [] }
377 | pragma { \x -> if opt_IgnoreIfacePragmas then []
379 POk _ (PIdInfo id_info) -> id_info
380 PFailed err -> pprPanic "IdInfo parse failed"
384 If a signature decl is being loaded, and opt_IgnoreIfacePragmas is on,
385 we toss away unfolding information.
387 Also, if the signature is loaded from a module we're importing from source,
388 we do the same. This is to avoid situations when compiling a pair of mutually
389 recursive modules, peering at unfolding info in the interface file of the other,
390 e.g., you compile A, it looks at B's interface file and may as a result change
391 its interface file. Hence, B is recompiled, maybe changing its interface file,
392 which will the unfolding info used in A to become invalid. Simple way out is to
393 just ignore unfolding info.
395 [Jan 99: I junked the second test above. If we're importing from an hi-boot
396 file there isn't going to *be* any pragma info. The above comment
397 dates from a time where we picked up a .hi file first if it existed.]
400 pragma :: { ParseResult IfaceStuff }
401 pragma : src_loc PRAGMA { parseIface $2 PState{ bol = 0#, atbol = 1#,
407 -----------------------------------------------------------------------------
409 rules_and_deprecs_part :: { ([RdrNameRuleDecl], IfaceDeprecs) }
410 rules_and_deprecs_part : {- empty -} { ([], Nothing) }
411 | pragma { case $1 of
412 POk _ (PRulesAndDeprecs rds) -> rds
413 PFailed err -> pprPanic "Rules/Deprecations parse failed" err
416 rules_and_deprecs :: { ([RdrNameRuleDecl], IfaceDeprecs) }
417 rules_and_deprecs : rule_prag deprec_prag { ($1, $2) }
420 -----------------------------------------------------------------------------
422 rule_prag :: { [RdrNameRuleDecl] }
423 rule_prag : {- empty -} { [] }
426 rules :: { [RdrNameRuleDecl] }
428 | rule ';' rules { $1:$3 }
430 rule :: { RdrNameRuleDecl }
431 rule : src_loc STRING rule_forall qvar_name
432 core_args '=' core_expr { IfaceRule $2 $3 $4 $5 $7 $1 }
434 rule_forall :: { [UfBinder RdrName] }
435 rule_forall : '__forall' '{' core_bndrs '}' { $3 }
437 -----------------------------------------------------------------------------
439 deprec_prag :: { IfaceDeprecs }
440 deprec_prag : {- empty -} { Nothing }
441 | '__D' deprecs { Just $2 }
443 deprecs :: { Either DeprecTxt [(RdrName,DeprecTxt)] }
444 deprecs : STRING { Left $1 }
445 | deprec_list { Right $1 }
447 deprec_list :: { [(RdrName,DeprecTxt)] }
448 deprec_list : deprec { [$1] }
449 | deprec ';' deprec_list { $1 : $3 }
451 deprec :: { (RdrName,DeprecTxt) }
452 deprec : deprec_name STRING { ($1, $2) }
454 deprec_name :: { RdrName }
458 -----------------------------------------------------------------------------
460 version :: { Version }
461 version : INTEGER { fromInteger $1 }
463 opt_version :: { Version }
464 opt_version : version { $1 }
465 | {- empty -} { initialVersion }
467 opt_decl_context :: { RdrNameContext }
468 opt_decl_context : { [] }
469 | context '=>' { $1 }
471 ----------------------------------------------------------------------------
473 constrs :: { [RdrNameConDecl] {- empty for handwritten abstract -} }
475 | '=' constrs1 { $2 }
477 constrs1 :: { [RdrNameConDecl] }
478 constrs1 : constr { [$1] }
479 | constr '|' constrs1 { $1 : $3 }
481 constr :: { RdrNameConDecl }
482 constr : src_loc ex_stuff data_name batypes { mk_con_decl $3 $2 (VanillaCon $4) $1 }
483 | src_loc ex_stuff data_name '{' fields1 '}' { mk_con_decl $3 $2 (RecCon $5) $1 }
484 -- We use "data_fs" so as to include ()
486 newtype_constr :: { [RdrNameConDecl] {- Not allowed to be empty -} }
487 newtype_constr : src_loc '=' ex_stuff data_name atype { [mk_con_decl $4 $3 (VanillaCon [Unbanged $5]) $1] }
488 | src_loc '=' ex_stuff data_name '{' var_name '::' atype '}'
489 { [mk_con_decl $4 $3 (RecCon [([$6], Unbanged $8)]) $1] }
491 ex_stuff :: { ([HsTyVarBndr RdrName], RdrNameContext) }
492 ex_stuff : { ([],[]) }
493 | '__forall' tv_bndrs opt_context '=>' { ($2,$3) }
495 batypes :: { [RdrNameBangType] }
497 | batype batypes { $1 : $2 }
499 batype :: { RdrNameBangType }
500 batype : atype { Unbanged $1 }
501 | '!' atype { Banged $2 }
502 | '!' '!' atype { Unpacked $3 }
504 fields1 :: { [([RdrName], RdrNameBangType)] }
505 fields1 : field { [$1] }
506 | field ',' fields1 { $1 : $3 }
508 field :: { ([RdrName], RdrNameBangType) }
509 field : var_names1 '::' type { ($1, Unbanged $3) }
510 | var_names1 '::' '!' type { ($1, Banged $4) }
511 | var_names1 '::' '!' '!' type { ($1, Unpacked $5) }
512 --------------------------------------------------------------------------
514 type :: { RdrNameHsType }
515 type : '__fuall' fuall '=>' type { mkHsUsForAllTy $2 $4 }
516 | '__forall' tv_bndrs
517 opt_context '=>' type { mkHsForAllTy (Just $2) $3 $5 }
518 | btype '->' type { HsFunTy $1 $3 }
521 fuall :: { [RdrName] }
522 fuall : '[' uv_bndrs ']' { $2 }
524 opt_context :: { RdrNameContext }
528 context :: { RdrNameContext }
529 context : '(' context_list1 ')' { $2 }
530 | '{' context_list1 '}' { $2 } -- Backward compatibility
532 context_list1 :: { RdrNameContext }
533 context_list1 : class { [$1] }
534 | class ',' context_list1 { $1 : $3 }
536 class :: { HsPred RdrName }
537 class : qcls_name atypes { (HsPClass $1 $2) }
538 | ipvar_name '::' type { (HsPIParam $1 $3) }
540 types0 :: { [RdrNameHsType] {- Zero or more -} }
541 types0 : {- empty -} { [ ] }
545 types2 :: { [RdrNameHsType] {- Two or more -} }
546 types2 : type ',' type { [$1,$3] }
547 | type ',' types2 { $1 : $3 }
549 btype :: { RdrNameHsType }
551 | btype atype { HsAppTy $1 $2 }
552 | '__u' usage atype { HsUsgTy $2 $3 }
554 usage :: { HsUsageAnn RdrName }
555 usage : '-' { HsUsOnce }
557 | uv_name { HsUsVar $1 }
559 atype :: { RdrNameHsType }
560 atype : qtc_name { HsTyVar $1 }
561 | tv_name { HsTyVar $1 }
562 | '(' ')' { HsTupleTy (mkHsTupCon tcName Boxed []) [] }
563 | '(' types2 ')' { HsTupleTy (mkHsTupCon tcName Boxed $2) $2 }
564 | '(#' types0 '#)' { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
565 | '[' type ']' { HsListTy $2 }
566 | '{' qcls_name atypes '}' { mkHsDictTy $2 $3 }
567 | '{' ipvar_name '::' type '}' { mkHsIParamTy $2 $4 }
568 | '(' type ')' { $2 }
570 atypes :: { [RdrNameHsType] {- Zero or more -} }
572 | atype atypes { $1 : $2 }
573 ---------------------------------------------------------------------
574 package :: { PackageName }
576 | {- empty -} { opt_InPackage } -- Useful for .hi-boot files,
577 -- which can omit the package Id
578 -- Module loops are always within a package
580 mod_name :: { ModuleName }
581 : CONID { mkSysModuleNameFS $1 }
584 ---------------------------------------------------
585 var_fs :: { EncodedFS }
588 | 'as' { SLIT("as") }
589 | 'qualified' { SLIT("qualified") }
590 | 'hiding' { SLIT("hiding") }
591 | 'forall' { SLIT("forall") }
592 | 'foreign' { SLIT("foreign") }
593 | 'export' { SLIT("export") }
594 | 'label' { SLIT("label") }
595 | 'dynamic' { SLIT("dynamic") }
596 | 'unsafe' { SLIT("unsafe") }
597 | 'with' { SLIT("with") }
598 | 'ccall' { SLIT("ccall") }
599 | 'stdcall' { SLIT("stdcall") }
601 qvar_fs :: { (EncodedFS, EncodedFS) }
605 var_occ :: { OccName }
606 : var_fs { mkSysOccFS varName $1 }
608 var_name :: { RdrName }
609 var_name : var_occ { mkRdrUnqual $1 }
611 qvar_name :: { RdrName }
612 qvar_name : var_name { $1 }
613 | qvar_fs { mkSysQual varName $1 }
615 ipvar_name :: { RdrName }
616 : IPVARID { mkSysUnqual ipName (tailFS $1) }
618 var_names :: { [RdrName] }
620 | var_name var_names { $1 : $2 }
622 var_names1 :: { [RdrName] }
623 var_names1 : var_name var_names { $1 : $2 }
625 ---------------------------------------------------
626 -- For some bizarre reason,
627 -- (,,,) is dealt with by the parser
628 -- Foo.(,,,) is dealt with by the lexer
631 data_fs :: { EncodedFS }
635 qdata_fs :: { (EncodedFS, EncodedFS) }
639 data_occ :: { OccName }
640 : data_fs { mkSysOccFS dataName $1 }
642 data_name :: { RdrName }
643 : data_occ { mkRdrUnqual $1 }
645 qdata_name :: { RdrName }
646 qdata_name : data_name { $1 }
647 | qdata_fs { mkSysQual dataName $1 }
649 var_or_data_name :: { RdrName }
653 ---------------------------------------------------
654 tc_fs :: { EncodedFS }
657 tc_occ :: { OccName }
658 : tc_fs { mkSysOccFS tcName $1 }
660 tc_name :: { RdrName }
661 : tc_occ { mkRdrUnqual $1 }
663 qtc_name :: { RdrName }
665 | qdata_fs { mkSysQual tcName $1 }
667 ---------------------------------------------------
668 cls_name :: { RdrName }
669 : data_fs { mkSysUnqual clsName $1 }
671 qcls_name :: { RdrName }
673 | qdata_fs { mkSysQual clsName $1 }
675 ---------------------------------------------------
676 uv_name :: { RdrName }
677 : VARID { mkSysUnqual uvName $1 }
679 uv_bndr :: { RdrName }
682 uv_bndrs :: { [RdrName] }
684 | uv_bndr uv_bndrs { $1 : $2 }
686 ---------------------------------------------------
687 tv_name :: { RdrName }
688 : VARID { mkSysUnqual tvName $1 }
689 | VARSYM { mkSysUnqual tvName $1 {- Allow t2 as a tyvar -} }
691 tv_bndr :: { HsTyVarBndr RdrName }
692 : tv_name '::' akind { IfaceTyVar $1 $3 }
693 | tv_name { IfaceTyVar $1 boxedTypeKind }
695 tv_bndrs :: { [HsTyVarBndr RdrName] }
696 tv_bndrs : tv_bndrs1 { $1 }
697 | '[' tv_bndrs1 ']' { $2 } -- Backward compatibility
699 tv_bndrs1 :: { [HsTyVarBndr RdrName] }
701 | tv_bndr tv_bndrs1 { $1 : $2 }
703 ---------------------------------------------------
704 fds :: { [([RdrName], [RdrName])] }
706 | '|' fds1 { reverse $2 }
708 fds1 :: { [([RdrName], [RdrName])] }
709 : fds1 ',' fd { $3 : $1 }
712 fd :: { ([RdrName], [RdrName]) }
713 : varids0 '->' varids0 { (reverse $1, reverse $3) }
715 varids0 :: { [RdrName] }
717 | varids0 tv_name { $2 : $1 }
719 ---------------------------------------------------
722 | akind '->' kind { mkArrowKind $1 $3 }
725 : VARSYM { if $1 == SLIT("*") then
727 else if $1 == SLIT("?") then
729 else panic "ParseInterface: akind"
731 | '(' kind ')' { $2 }
733 --------------------------------------------------------------------------
735 id_info :: { [HsIdInfo RdrName] }
736 : id_info_item { [$1] }
737 | id_info_item id_info { $1 : $2 }
739 id_info_item :: { HsIdInfo RdrName }
740 : '__A' INTEGER { HsArity (exactArity (fromInteger $2)) }
741 | '__U' inline_prag core_expr { HsUnfold $2 $3 }
742 | '__M' { HsCprInfo }
743 | '__S' { HsStrictness (mkStrictnessInfo $1) }
744 | '__C' { HsNoCafRefs }
745 | '__P' qvar_name { HsWorker $2 }
747 inline_prag :: { InlinePragInfo }
748 : {- empty -} { NoInlinePragInfo }
749 | '[' from_prag phase ']' { IMustNotBeINLINEd $2 $3 }
751 from_prag :: { Bool }
752 : {- empty -} { True }
755 phase :: { Maybe Int }
756 : {- empty -} { Nothing }
757 | INTEGER { Just (fromInteger $1) }
759 -------------------------------------------------------
760 core_expr :: { UfExpr RdrName }
761 core_expr : '\\' core_bndrs '->' core_expr { foldr UfLam $4 $2 }
762 | 'case' core_expr 'of' var_name
763 '{' core_alts '}' { UfCase $2 $4 $6 }
765 | 'let' '{' core_val_bndr '=' core_expr
766 '}' 'in' core_expr { UfLet (UfNonRec $3 $5) $8 }
767 | '__letrec' '{' rec_binds '}'
768 'in' core_expr { UfLet (UfRec $3) $6 }
770 | '__litlit' STRING atype { UfLitLit $2 $3 }
774 fexpr :: { UfExpr RdrName }
775 fexpr : fexpr core_arg { UfApp $1 $2 }
776 | scc core_aexpr { UfNote (UfSCC $1) $2 }
777 | '__inline_me' core_aexpr { UfNote UfInlineMe $2 }
778 | '__inline_call' core_aexpr { UfNote UfInlineCall $2 }
779 | '__coerce' atype core_aexpr { UfNote (UfCoerce $2) $3 }
782 core_arg :: { UfExpr RdrName }
783 : '@' atype { UfType $2 }
786 core_args :: { [UfExpr RdrName] }
788 | core_arg core_args { $1 : $2 }
790 core_aexpr :: { UfExpr RdrName } -- Atomic expressions
791 core_aexpr : qvar_name { UfVar $1 }
792 | qdata_name { UfVar $1 }
794 | core_lit { UfLit $1 }
795 | '(' core_expr ')' { $2 }
797 | '(' ')' { UfTuple (mkHsTupCon dataName Boxed []) [] }
798 | '(' comma_exprs2 ')' { UfTuple (mkHsTupCon dataName Boxed $2) $2 }
799 | '(#' comma_exprs0 '#)' { UfTuple (mkHsTupCon dataName Unboxed $2) $2 }
801 | '{' '__ccall' ccall_string type '}'
803 (is_dyn, is_casm, may_gc) = $2
805 target | is_dyn = DynamicTarget (error "CCall dyn target bogus unique")
806 | otherwise = StaticTarget $3
808 ccall = CCall target is_casm may_gc cCallConv
814 comma_exprs0 :: { [UfExpr RdrName] } -- Zero or more
815 comma_exprs0 : {- empty -} { [ ] }
816 | core_expr { [ $1 ] }
817 | comma_exprs2 { $1 }
819 comma_exprs2 :: { [UfExpr RdrName] } -- Two or more
820 comma_exprs2 : core_expr ',' core_expr { [$1,$3] }
821 | core_expr ',' comma_exprs2 { $1 : $3 }
823 rec_binds :: { [(UfBinder RdrName, UfExpr RdrName)] }
825 | core_val_bndr '=' core_expr ';' rec_binds { ($1,$3) : $5 }
827 core_alts :: { [UfAlt RdrName] }
829 | core_alt ';' core_alts { $1 : $3 }
831 core_alt :: { UfAlt RdrName }
832 core_alt : core_pat '->' core_expr { (fst $1, snd $1, $3) }
834 core_pat :: { (UfConAlt RdrName, [RdrName]) }
835 core_pat : core_lit { (UfLitAlt $1, []) }
836 | '__litlit' STRING atype { (UfLitLitAlt $2 $3, []) }
837 | qdata_name core_pat_names { (UfDataAlt $1, $2) }
838 | '(' ')' { (UfTupleAlt (mkHsTupCon dataName Boxed []), []) }
839 | '(' comma_var_names1 ')' { (UfTupleAlt (mkHsTupCon dataName Boxed $2), $2) }
840 | '(#' comma_var_names1 '#)' { (UfTupleAlt (mkHsTupCon dataName Unboxed $2), $2) }
841 | '__DEFAULT' { (UfDefault, []) }
842 | '(' core_pat ')' { $2 }
844 core_pat_names :: { [RdrName] }
845 core_pat_names : { [] }
846 | core_pat_name core_pat_names { $1 : $2 }
848 -- Tyvar names and variable names live in different name spaces
849 -- so they need to be signalled separately. But we don't record
850 -- types or kinds in a pattern; we work that out from the type
851 -- of the case scrutinee
852 core_pat_name :: { RdrName }
853 core_pat_name : var_name { $1 }
856 comma_var_names1 :: { [RdrName] } -- One or more
857 comma_var_names1 : var_name { [$1] }
858 | var_name ',' comma_var_names1 { $1 : $3 }
860 core_lit :: { Literal }
861 core_lit : integer { mkMachInt $1 }
862 | CHAR { MachChar $1 }
863 | STRING { MachStr $1 }
864 | rational { MachDouble $1 }
865 | '__word' integer { mkMachWord $2 }
866 | '__word64' integer { mkMachWord64 $2 }
867 | '__int64' integer { mkMachInt64 $2 }
868 | '__float' rational { MachFloat $2 }
869 | '__addr' integer { MachAddr $2 }
870 | '__label' STRING { MachLabel $2 }
872 integer :: { Integer }
874 | '-' INTEGER { (-$2) }
876 rational :: { Rational }
878 | '-' RATIONAL { (-$2) }
880 core_bndr :: { UfBinder RdrName }
881 core_bndr : core_val_bndr { $1 }
882 | core_tv_bndr { $1 }
884 core_bndrs :: { [UfBinder RdrName] }
886 | core_bndr core_bndrs { $1 : $2 }
888 core_val_bndr :: { UfBinder RdrName }
889 core_val_bndr : var_name '::' atype { UfValBinder $1 $3 }
891 core_tv_bndr :: { UfBinder RdrName }
892 core_tv_bndr : '@' tv_name '::' akind { UfTyBinder $2 $4 }
893 | '@' tv_name { UfTyBinder $2 boxedTypeKind }
895 ccall_string :: { FAST_STRING }
901 ------------------------------------------------------------------------
902 scc :: { CostCentre }
903 : '__sccC' '{' mod_name '}' { AllCafsCC $3 }
904 | '__scc' '{' cc_name mod_name cc_dup cc_caf '}'
905 { NormalCC { cc_name = $3, cc_mod = $4,
906 cc_is_dupd = $5, cc_is_caf = $6 } }
908 cc_name :: { EncodedFS }
912 cc_dup :: { IsDupdCC }
913 cc_dup : { OriginalCC }
916 cc_caf :: { IsCafCC }
920 -------------------------------------------------------------------
922 src_loc :: { SrcLoc }
923 src_loc : {% getSrcLocP }
925 -- Check the project version: this makes sure
926 -- that the project version (e.g. 407) in the interface
927 -- file is the same as that for the compiler that's reading it
928 checkVersion :: { () }
929 : {-empty-} {% checkVersion Nothing }
930 | INTEGER {% checkVersion (Just (fromInteger $1)) }
932 -------------------------------------------------------------------
937 happyError buf PState{ loc = loc } = PFailed (ifaceParseErr buf loc)
939 data IfaceStuff = PIface ParsedIface
940 | PIdInfo [HsIdInfo RdrName]
941 | PType RdrNameHsType
942 | PRulesAndDeprecs ([RdrNameRuleDecl], IfaceDeprecs)
944 mk_con_decl name (ex_tvs, ex_ctxt) details loc = mkConDecl name ex_tvs ex_ctxt details loc