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, 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
84 'default' { ITdefault }
85 'deriving' { ITderiving }
95 'instance' { ITinstance }
98 'newtype' { ITnewtype }
100 'qualified' { ITqualified }
105 'forall' { ITforall } -- GHC extension keywords
106 'foreign' { ITforeign }
107 'export' { ITexport }
109 'dynamic' { ITdynamic }
110 'unsafe' { ITunsafe }
112 'stdcall' { ITstdcallconv }
113 'ccall' { ITccallconv }
115 '__interface' { ITinterface } -- interface keywords
116 '__export' { IT__export }
117 '__depends' { ITdepends }
118 '__forall' { IT__forall }
119 '__letrec' { ITletrec }
120 '__coerce' { ITcoerce }
121 '__inline_me' { ITinlineMe }
122 '__inline_call'{ ITinlineCall }
123 '__DEFAULT' { ITdefaultbranch }
125 '__integer' { ITinteger_lit }
126 '__float' { ITfloat_lit }
127 '__word' { ITword_lit }
128 '__int64' { ITint64_lit }
129 '__word64' { ITword64_lit }
130 '__rational' { ITrational_lit }
131 '__addr' { ITaddr_lit }
132 '__label' { ITlabel_lit }
133 '__litlit' { ITlit_lit }
134 '__string' { ITstring_lit }
135 '__ccall' { ITccall $$ }
137 '__sccC' { ITsccAllCafs }
142 '__P' { ITspecialise }
145 '__S' { ITstrict $$ }
148 '__D' { ITdeprecated }
150 '..' { ITdotdot } -- reserved symbols
163 '{' { ITocurly } -- special symbols
165 '{|' { ITocurlybar } -- special symbols
166 '|}' { ITccurlybar } -- special symbols
177 VARID { ITvarid $$ } -- identifiers
179 VARSYM { ITvarsym $$ }
180 CONSYM { ITconsym $$ }
181 QVARID { ITqvarid $$ }
182 QCONID { ITqconid $$ }
183 QVARSYM { ITqvarsym $$ }
184 QCONSYM { ITqconsym $$ }
186 IPDUPVARID { ITdupipvarid $$ } -- GHC extension
187 IPSPLITVARID { ITsplitipvarid $$ } -- GHC extension
189 PRAGMA { ITpragma $$ }
192 STRING { ITstring $$ }
193 INTEGER { ITinteger $$ }
194 RATIONAL { ITrational $$ }
195 CLITLIT { ITlitlit $$ }
197 UNKNOWN { ITunknown $$ }
200 iface :: { ParsedIface }
201 iface : '__interface' package mod_name
203 orphans checkVersion 'where'
209 rules_and_deprecs_part
210 { let (rules,deprecs) = $14 () in
212 pi_mod = $3, -- Module name
213 pi_pkg = $2, -- Package name
214 pi_vers = $4, -- Module version
216 pi_exports = (fst $5, $9), -- Exports
217 pi_usages = $10, -- Usages
218 pi_fixity = $11, -- Fixies
219 pi_insts = $12, -- Local instances
220 pi_decls = $13, -- Decls
221 pi_rules = (snd $5,rules), -- Rules
222 pi_deprecs = deprecs -- Deprecations
225 -- Versions for exports and rules (optional)
226 sub_versions :: { (Version,Version) }
227 : '[' version version ']' { ($2,$3) }
228 | {- empty -} { (initialVersion, initialVersion) }
230 --------------------------------------------------------------------------
232 import_part :: { [ImportVersion OccName] }
234 | import_decl import_part { $1 : $2 }
236 import_decl :: { ImportVersion OccName }
237 import_decl : 'import' mod_name orphans is_boot whats_imported ';'
238 { ({-mkSysModuleNameFS-} $2, $3, $4, $5) }
240 orphans :: { WhetherHasOrphans }
244 is_boot :: { IsBootInterface }
248 whats_imported :: { WhatsImported OccName }
249 whats_imported : { NothingAtAll }
250 | '::' version { Everything $2 }
251 | '::' version version version name_version_pairs { Specifically $2 (Just $3) $5 $4 }
252 | '::' version version name_version_pairs { Specifically $2 Nothing $4 $3 }
254 name_version_pairs :: { [(OccName, Version)] }
255 name_version_pairs : { [] }
256 | name_version_pair name_version_pairs { $1 : $2 }
258 name_version_pair :: { (OccName, Version) }
259 name_version_pair : var_occ version { ($1, $2) }
260 | tc_occ version { ($1, $2) }
263 --------------------------------------------------------------------------
265 exports_part :: { [ExportItem] }
266 exports_part : { [] }
267 | '__export' mod_name entities ';'
268 exports_part { ({-mkSysModuleNameFS-} $2, $3) : $5 }
270 entities :: { [RdrAvailInfo] }
272 | entity entities { $1 : $2 }
274 entity :: { RdrAvailInfo }
275 entity : var_occ { Avail $1 }
276 | tc_occ { AvailTC $1 [$1] }
277 | tc_occ '|' stuff_inside { AvailTC $1 $3 }
278 | tc_occ stuff_inside { AvailTC $1 ($1:$2) }
279 -- Note that the "main name" comes at the beginning
281 stuff_inside :: { [OccName] }
282 stuff_inside : '{' val_occs '}' { $2 }
284 val_occ :: { OccName }
288 val_occs :: { [OccName] }
290 | val_occ val_occs { $1 : $2 }
293 --------------------------------------------------------------------------
295 fix_decl_part :: { [RdrNameFixitySig] }
296 fix_decl_part : {- empty -} { [] }
297 | fix_decls ';' { $1 }
299 fix_decls :: { [RdrNameFixitySig] }
301 | fix_decl fix_decls { $1 : $2 }
303 fix_decl :: { RdrNameFixitySig }
304 fix_decl : src_loc fixity prec var_or_data_name { FixitySig $4 (Fixity $3 $2) $1 }
306 fixity :: { FixityDirection }
307 fixity : 'infixl' { InfixL }
308 | 'infixr' { InfixR }
312 prec : INTEGER { fromInteger $1 }
314 -----------------------------------------------------------------------------
316 csigs :: { [RdrNameSig] }
318 | 'where' '{' csigs1 '}' { $3 }
320 csigs1 :: { [RdrNameSig] }
322 | csig ';' csigs1 { $1 : $3 }
324 csig :: { RdrNameSig }
325 csig : src_loc qvar_name '::' type { ClassOpSig $2 NoDefMeth $4 $1 }
326 | src_loc qvar_name ';' '::' type { ClassOpSig $2 GenDefMeth $5 $1 }
327 | src_loc qvar_name '=' '::' type { mkClassOpSigDM $2 $5 $1 }
329 --------------------------------------------------------------------------
331 instance_decl_part :: { [RdrNameInstDecl] }
332 instance_decl_part : {- empty -} { [] }
333 | instance_decl_part inst_decl { $2 : $1 }
335 inst_decl :: { RdrNameInstDecl }
336 inst_decl : src_loc 'instance' type '=' qvar_name ';'
338 EmptyMonoBinds {- No bindings -}
339 [] {- No user pragmas -}
340 (Just $5) {- Dfun id -}
344 --------------------------------------------------------------------------
346 decls_part :: { [(Version, RdrNameTyClDecl)] }
349 | opt_version decl ';' decls_part { ($1,$2):$4 }
351 decl :: { RdrNameTyClDecl }
352 decl : src_loc qvar_name '::' type maybe_idinfo
353 { IfaceSig $2 $4 ($5 $2) $1 }
354 | src_loc 'type' qtc_name tv_bndrs '=' type
355 { TySynonym $3 $4 $6 $1 }
356 | src_loc 'foreign' 'type' qtc_name
357 { ForeignType $4 Nothing DNType $1 }
358 | src_loc 'data' opt_decl_context qtc_name tv_bndrs constrs
359 { mkTyData DataType $3 $4 $5 $6 (length $6) Nothing $1 }
360 | src_loc 'newtype' opt_decl_context qtc_name tv_bndrs newtype_constr
361 { mkTyData NewType $3 $4 $5 $6 1 Nothing $1 }
362 | src_loc 'class' opt_decl_context qtc_name tv_bndrs fds csigs
363 { mkClassDecl $3 $4 $5 $6 $7 Nothing $1 }
365 maybe_idinfo :: { RdrName -> [HsIdInfo RdrName] }
366 maybe_idinfo : {- empty -} { \_ -> [] }
367 | pragma { \x -> if opt_IgnoreIfacePragmas then []
369 Just (POk _ id_info) -> id_info
370 Just (PFailed err) -> pprPanic "IdInfo parse failed"
374 If a signature decl is being loaded, and opt_IgnoreIfacePragmas is on,
375 we toss away unfolding information.
377 Also, if the signature is loaded from a module we're importing from source,
378 we do the same. This is to avoid situations when compiling a pair of mutually
379 recursive modules, peering at unfolding info in the interface file of the other,
380 e.g., you compile A, it looks at B's interface file and may as a result change
381 its interface file. Hence, B is recompiled, maybe changing its interface file,
382 which will the unfolding info used in A to become invalid. Simple way out is to
383 just ignore unfolding info.
385 [Jan 99: I junked the second test above. If we're importing from an hi-boot
386 file there isn't going to *be* any pragma info. The above comment
387 dates from a time where we picked up a .hi file first if it existed.]
390 pragma :: { Maybe (ParseResult [HsIdInfo RdrName]) }
391 pragma : src_loc PRAGMA { Just (parseIdInfo $2 PState{ bol = 0#, atbol = 1#,
397 -----------------------------------------------------------------------------
399 -- This production is lifted so that it doesn't get eagerly parsed when we
400 -- use happy --strict.
401 rules_and_deprecs_part :: { () -> ([RdrNameRuleDecl], IfaceDeprecs) }
402 rules_and_deprecs_part
403 : {- empty -} { \_ -> ([], Nothing) }
404 | src_loc PRAGMA { \_ -> case parseRules $2 PState{ bol = 0#, atbol = 1#,
409 PFailed err -> pprPanic "Rules/Deprecations parse failed" err
412 rules_and_deprecs :: { ([RdrNameRuleDecl], IfaceDeprecs) }
413 rules_and_deprecs : rule_prag deprec_prag { ($1, $2) }
416 -----------------------------------------------------------------------------
418 rule_prag :: { [RdrNameRuleDecl] }
419 rule_prag : {- empty -} { [] }
422 rules :: { [RdrNameRuleDecl] }
424 | rule ';' rules { $1:$3 }
426 rule :: { RdrNameRuleDecl }
427 rule : src_loc STRING activation rule_forall qvar_name
428 core_args '=' core_expr { IfaceRule $2 $3 $4 $5 $6 $8 $1 }
430 activation :: { Activation }
431 activation : {- empty -} { AlwaysActive }
432 | '[' INTEGER ']' { ActiveAfter (fromInteger $2) }
433 | '[' '~' INTEGER ']' { ActiveBefore (fromInteger $3) }
435 rule_forall :: { [UfBinder RdrName] }
436 rule_forall : '__forall' '{' core_bndrs '}' { $3 }
438 -----------------------------------------------------------------------------
440 deprec_prag :: { IfaceDeprecs }
441 deprec_prag : {- empty -} { Nothing }
442 | '__D' deprecs { Just $2 }
444 deprecs :: { Either DeprecTxt [(RdrName,DeprecTxt)] }
445 deprecs : STRING { Left $1 }
446 | deprec_list { Right $1 }
448 deprec_list :: { [(RdrName,DeprecTxt)] }
449 deprec_list : deprec { [$1] }
450 | deprec ';' deprec_list { $1 : $3 }
452 deprec :: { (RdrName,DeprecTxt) }
453 deprec : deprec_name STRING { ($1, $2) }
455 deprec_name :: { RdrName }
459 -----------------------------------------------------------------------------
461 version :: { Version }
462 version : INTEGER { fromInteger $1 }
464 opt_version :: { Version }
465 opt_version : version { $1 }
466 | {- empty -} { initialVersion }
468 opt_decl_context :: { RdrNameContext }
469 opt_decl_context : { [] }
470 | context '=>' { $1 }
472 ----------------------------------------------------------------------------
474 constrs :: { [RdrNameConDecl] {- empty for handwritten abstract -} }
476 | '=' constrs1 { $2 }
478 constrs1 :: { [RdrNameConDecl] }
479 constrs1 : constr { [$1] }
480 | constr '|' constrs1 { $1 : $3 }
482 constr :: { RdrNameConDecl }
483 constr : src_loc ex_stuff qdata_name batypes { mk_con_decl $3 $2 (VanillaCon $4) $1 }
484 | src_loc ex_stuff qdata_name '{' fields1 '}' { mk_con_decl $3 $2 (RecCon $5) $1 }
485 -- We use "data_fs" so as to include ()
487 newtype_constr :: { [RdrNameConDecl] {- Not allowed to be empty -} }
488 newtype_constr : src_loc '=' ex_stuff qdata_name atype { [mk_con_decl $4 $3 (VanillaCon [unbangedType $5]) $1] }
489 | src_loc '=' ex_stuff qdata_name '{' qvar_name '::' atype '}'
490 { [mk_con_decl $4 $3 (RecCon [([$6], unbangedType $8)]) $1] }
492 ex_stuff :: { ([HsTyVarBndr RdrName], RdrNameContext) }
493 ex_stuff : { ([],[]) }
494 | '__forall' tv_bndrs opt_context '=>' { ($2,$3) }
496 batypes :: { [RdrNameBangType] }
498 | batype batypes { $1 : $2 }
500 batype :: { RdrNameBangType }
501 batype : tatype { unbangedType $1 }
502 | '!' tatype { BangType MarkedStrict $2 }
503 | '!' '!' tatype { BangType MarkedUnboxed $3 }
505 fields1 :: { [([RdrName], RdrNameBangType)] }
506 fields1 : field { [$1] }
507 | field ',' fields1 { $1 : $3 }
509 field :: { ([RdrName], RdrNameBangType) }
510 field : qvar_names1 '::' ttype { ($1, unbangedType $3) }
511 | qvar_names1 '::' '!' ttype { ($1, BangType MarkedStrict $4) }
512 | qvar_names1 '::' '!' '!' ttype { ($1, BangType MarkedUnboxed $5) }
514 --------------------------------------------------------------------------
516 type :: { RdrNameHsType }
517 type : '__forall' tv_bndrs
518 opt_context '=>' type { mkHsForAllTy (Just $2) $3 $5 }
519 | btype '->' type { HsFunTy $1 $3 }
522 opt_context :: { RdrNameContext }
526 context :: { RdrNameContext }
527 context : '(' context_list1 ')' { $2 }
528 | '{' context_list1 '}' { $2 } -- Backward compatibility
530 context_list1 :: { RdrNameContext }
531 context_list1 : class { [$1] }
532 | class ',' context_list1 { $1 : $3 }
534 class :: { HsPred RdrName }
535 class : qcls_name atypes { (HsClassP $1 $2) }
536 | ipvar_name '::' type { (HsIParam $1 $3) }
538 types0 :: { [RdrNameHsType] {- Zero or more -} }
539 types0 : {- empty -} { [ ] }
543 types2 :: { [RdrNameHsType] {- Two or more -} }
544 types2 : type ',' type { [$1,$3] }
545 | type ',' types2 { $1 : $3 }
547 btype :: { RdrNameHsType }
549 | btype atype { HsAppTy $1 $2 }
550 | '__u' atype atype { HsUsageTy $2 $3 }
552 atype :: { RdrNameHsType }
553 atype : qtc_name { HsTyVar $1 }
554 | tv_name { HsTyVar $1 }
557 | '(' ')' { HsTupleTy (mkHsTupCon tcName Boxed []) [] }
558 | '(' types2 ')' { HsTupleTy (mkHsTupCon tcName Boxed $2) $2 }
559 | '(#' types0 '#)' { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
560 | '[' type ']' { HsListTy $2 }
561 | '{' qcls_name atypes '}' { mkHsDictTy $2 $3 }
562 | '{' ipvar_name '::' type '}' { mkHsIParamTy $2 $4 }
563 | '(' type ')' { $2 }
565 atypes :: { [RdrNameHsType] {- Zero or more -} }
567 | atype atypes { $1 : $2 }
568 --------------------------------------------------------------------------
570 -- versions of type/btype/atype that cant begin with '!' (or '.')
571 -- for use where the kind is definitely known NOT to be '$'
573 ttype :: { RdrNameHsType }
574 ttype : '__forall' tv_bndrs
575 opt_context '=>' type { mkHsForAllTy (Just $2) $3 $5 }
576 | tbtype '->' type { HsFunTy $1 $3 }
579 tbtype :: { RdrNameHsType }
580 tbtype : tatype { $1 }
581 | tbtype atype { HsAppTy $1 $2 }
582 | '__u' atype atype { HsUsageTy $2 $3 }
584 tatype :: { RdrNameHsType }
585 tatype : qtc_name { HsTyVar $1 }
586 | tv_name { HsTyVar $1 }
587 | '(' ')' { HsTupleTy (mkHsTupCon tcName Boxed []) [] }
588 | '(' types2 ')' { HsTupleTy (mkHsTupCon tcName Boxed $2) $2 }
589 | '(#' types0 '#)' { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
590 | '[' type ']' { HsListTy $2 }
591 | '{' qcls_name atypes '}' { mkHsDictTy $2 $3 }
592 | '{' ipvar_name '::' type '}' { mkHsIParamTy $2 $4 }
593 | '(' type ')' { $2 }
594 ---------------------------------------------------------------------
596 package :: { PackageName }
598 | {- empty -} { opt_InPackage }
599 -- Useful for .hi-boot files,
600 -- which can omit the package Id
601 -- Module loops are always within a package
603 mod_name :: { ModuleName }
604 : CONID { mkSysModuleNameFS $1 }
607 ---------------------------------------------------
608 var_fs :: { EncodedFS }
610 | 'as' { SLIT("as") }
611 | 'qualified' { SLIT("qualified") }
612 | 'hiding' { SLIT("hiding") }
613 | 'forall' { SLIT("forall") }
614 | 'foreign' { SLIT("foreign") }
615 | 'export' { SLIT("export") }
616 | 'label' { SLIT("label") }
617 | 'dynamic' { SLIT("dynamic") }
618 | 'unsafe' { SLIT("unsafe") }
619 | 'with' { SLIT("with") }
620 | 'ccall' { SLIT("ccall") }
621 | 'stdcall' { SLIT("stdcall") }
623 var_occ :: { OccName }
624 : var_fs { mkSysOccFS varName $1 }
626 var_name :: { RdrName }
627 var_name : var_occ { mkRdrUnqual $1 }
629 qvar_name :: { RdrName }
630 qvar_name : var_name { $1 }
631 | QVARID { mkIfaceOrig varName $1 }
633 ipvar_name :: { IPName RdrName }
634 : IPDUPVARID { Dupable (mkRdrUnqual (mkSysOccFS varName $1)) }
635 | IPSPLITVARID { Linear (mkRdrUnqual (mkSysOccFS varName $1)) }
637 qvar_names1 :: { [RdrName] }
638 qvar_names1 : qvar_name { [$1] }
639 | qvar_name qvar_names1 { $1 : $2 }
641 var_names :: { [RdrName] }
643 | var_name var_names { $1 : $2 }
645 var_names1 :: { [RdrName] }
646 var_names1 : var_name var_names { $1 : $2 }
648 ---------------------------------------------------
650 data_occ :: { OccName }
651 : CONID { mkSysOccFS dataName $1 }
653 qdata_name :: { RdrName }
654 : data_occ { mkRdrUnqual $1 }
655 | QCONID { mkIfaceOrig dataName $1 }
657 var_or_data_name :: { RdrName }
661 ---------------------------------------------------
662 tc_occ :: { OccName }
663 : CONID { mkSysOccFS tcName $1 }
665 qtc_name :: { RdrName }
666 : tc_occ { mkRdrUnqual $1 }
667 | QCONID { mkIfaceOrig tcName $1 }
669 ---------------------------------------------------
670 qcls_name :: { RdrName }
671 : CONID { mkRdrUnqual (mkSysOccFS clsName $1) }
672 | QCONID { mkIfaceOrig clsName $1 }
674 ---------------------------------------------------
675 tv_name :: { RdrName }
676 : var_fs { mkRdrUnqual (mkSysOccFS tvName $1) }
678 tv_bndr :: { HsTyVarBndr RdrName }
679 : tv_name '::' akind { IfaceTyVar $1 $3 }
680 | tv_name { IfaceTyVar $1 liftedTypeKind }
682 tv_bndrs :: { [HsTyVarBndr RdrName] }
684 | '[' tv_bndrs1 ']' { $2 } -- Backward compatibility
686 tv_bndrs1 :: { [HsTyVarBndr RdrName] }
688 | tv_bndr tv_bndrs1 { $1 : $2 }
690 ---------------------------------------------------
691 fds :: { [([RdrName], [RdrName])] }
693 | '|' fds1 { reverse $2 }
695 fds1 :: { [([RdrName], [RdrName])] }
696 : fds1 ',' fd { $3 : $1 }
699 fd :: { ([RdrName], [RdrName]) }
700 : varids0 '->' varids0 { (reverse $1, reverse $3) }
702 varids0 :: { [RdrName] }
704 | varids0 tv_name { $2 : $1 }
706 ---------------------------------------------------
709 | akind '->' kind { mkArrowKind $1 $3 }
712 : VARSYM { if $1 == SLIT("*") then
714 else if $1 == SLIT("?") then
716 else if $1 == SLIT("\36") then
717 usageTypeKind -- dollar
718 else panic "ParseInterface: akind"
720 | '(' kind ')' { $2 }
722 --------------------------------------------------------------------------
724 id_info :: { [HsIdInfo RdrName] }
725 : id_info_item { [$1] }
726 | id_info_item id_info { $1 : $2 }
728 id_info_item :: { HsIdInfo RdrName }
729 : '__A' INTEGER { HsArity (fromInteger $2) }
730 | '__U' activation core_expr { HsUnfold $2 $3 }
731 | '__S' { HsStrictness $1 }
732 | '__C' { HsNoCafRefs }
733 | '__P' qvar_name INTEGER { HsWorker $2 (fromInteger $3) }
735 -------------------------------------------------------
736 core_expr :: { UfExpr RdrName }
737 core_expr : '\\' core_bndrs '->' core_expr { foldr UfLam $4 $2 }
738 | 'case' core_expr 'of' var_name
739 '{' core_alts '}' { UfCase $2 $4 $6 }
741 | 'let' '{' core_val_bndr '=' core_expr
742 '}' 'in' core_expr { UfLet (UfNonRec $3 $5) $8 }
743 | '__letrec' '{' rec_binds '}'
744 'in' core_expr { UfLet (UfRec $3) $6 }
746 | '__litlit' STRING atype { UfLitLit $2 $3 }
750 fexpr :: { UfExpr RdrName }
751 fexpr : fexpr core_arg { UfApp $1 $2 }
752 | scc core_aexpr { UfNote (UfSCC $1) $2 }
753 | '__inline_me' core_aexpr { UfNote UfInlineMe $2 }
754 | '__inline_call' core_aexpr { UfNote UfInlineCall $2 }
755 | '__coerce' atype core_aexpr { UfNote (UfCoerce $2) $3 }
758 core_arg :: { UfExpr RdrName }
759 : '@' atype { UfType $2 }
762 core_args :: { [UfExpr RdrName] }
764 | core_arg core_args { $1 : $2 }
766 core_aexpr :: { UfExpr RdrName } -- Atomic expressions
767 core_aexpr : qvar_name { UfVar $1 }
768 | qdata_name { UfVar $1 }
770 | core_lit { UfLit $1 }
771 | '(' core_expr ')' { $2 }
773 | '(' ')' { UfTuple (mkHsTupCon dataName Boxed []) [] }
774 | '(' comma_exprs2 ')' { UfTuple (mkHsTupCon dataName Boxed $2) $2 }
775 | '(#' comma_exprs0 '#)' { UfTuple (mkHsTupCon dataName Unboxed $2) $2 }
777 | '{' '__ccall' ccall_string type '}'
779 (is_dyn, is_casm, may_gc) = $2
781 target | is_dyn = DynamicTarget
782 | is_casm = CasmTarget $3
783 | otherwise = StaticTarget $3
785 ccall = CCallSpec target CCallConv may_gc
787 UfFCall (CCall ccall) $4
791 comma_exprs0 :: { [UfExpr RdrName] } -- Zero or more
792 comma_exprs0 : {- empty -} { [ ] }
793 | core_expr { [ $1 ] }
794 | comma_exprs2 { $1 }
796 comma_exprs2 :: { [UfExpr RdrName] } -- Two or more
797 comma_exprs2 : core_expr ',' core_expr { [$1,$3] }
798 | core_expr ',' comma_exprs2 { $1 : $3 }
800 rec_binds :: { [(UfBinder RdrName, UfExpr RdrName)] }
802 | core_val_bndr '=' core_expr ';' rec_binds { ($1,$3) : $5 }
804 core_alts :: { [UfAlt RdrName] }
806 | core_alt ';' core_alts { $1 : $3 }
808 core_alt :: { UfAlt RdrName }
809 core_alt : core_pat '->' core_expr { (fst $1, snd $1, $3) }
811 core_pat :: { (UfConAlt RdrName, [RdrName]) }
812 core_pat : core_lit { (UfLitAlt $1, []) }
813 | '__litlit' STRING atype { (UfLitLitAlt $2 $3, []) }
814 | qdata_name core_pat_names { (UfDataAlt $1, $2) }
815 | '(' ')' { (UfTupleAlt (mkHsTupCon dataName Boxed []), []) }
816 | '(' comma_var_names1 ')' { (UfTupleAlt (mkHsTupCon dataName Boxed $2), $2) }
817 | '(#' comma_var_names1 '#)' { (UfTupleAlt (mkHsTupCon dataName Unboxed $2), $2) }
818 | '__DEFAULT' { (UfDefault, []) }
819 | '(' core_pat ')' { $2 }
821 core_pat_names :: { [RdrName] }
822 core_pat_names : { [] }
823 | core_pat_name core_pat_names { $1 : $2 }
825 -- Tyvar names and variable names live in different name spaces
826 -- so they need to be signalled separately. But we don't record
827 -- types or kinds in a pattern; we work that out from the type
828 -- of the case scrutinee
829 core_pat_name :: { RdrName }
830 core_pat_name : var_name { $1 }
833 comma_var_names1 :: { [RdrName] } -- One or more
834 comma_var_names1 : var_name { [$1] }
835 | var_name ',' comma_var_names1 { $1 : $3 }
837 core_lit :: { Literal }
838 core_lit : integer { mkMachInt $1 }
839 | CHAR { MachChar $1 }
840 | STRING { MachStr $1 }
841 | rational { MachDouble $1 }
842 | '__word' integer { mkMachWord $2 }
843 | '__word64' integer { mkMachWord64 $2 }
844 | '__int64' integer { mkMachInt64 $2 }
845 | '__float' rational { MachFloat $2 }
846 | '__addr' integer { MachAddr $2 }
847 | '__label' STRING { MachLabel $2 }
849 integer :: { Integer }
851 | '-' INTEGER { (-$2) }
853 rational :: { Rational }
855 | '-' RATIONAL { (-$2) }
857 core_bndr :: { UfBinder RdrName }
858 core_bndr : core_val_bndr { $1 }
859 | core_tv_bndr { $1 }
861 core_bndrs :: { [UfBinder RdrName] }
863 | core_bndr core_bndrs { $1 : $2 }
865 core_val_bndr :: { UfBinder RdrName }
866 core_val_bndr : var_name '::' atype { UfValBinder $1 $3 }
868 core_tv_bndr :: { UfBinder RdrName }
869 core_tv_bndr : '@' tv_name '::' akind { UfTyBinder $2 $4 }
870 | '@' tv_name { UfTyBinder $2 liftedTypeKind }
872 ccall_string :: { FAST_STRING }
878 ------------------------------------------------------------------------
879 scc :: { CostCentre }
880 : '__sccC' '{' mod_name '}' { AllCafsCC $3 }
881 | '__scc' '{' cc_name mod_name cc_dup cc_caf '}'
882 { NormalCC { cc_name = $3, cc_mod = $4,
883 cc_is_dupd = $5, cc_is_caf = $6 } }
885 cc_name :: { EncodedFS }
889 cc_dup :: { IsDupdCC }
890 cc_dup : { OriginalCC }
893 cc_caf :: { IsCafCC }
897 -------------------------------------------------------------------
899 src_loc :: { SrcLoc }
900 src_loc : {% getSrcLocP }
902 -- Check the project version: this makes sure
903 -- that the project version (e.g. 407) in the interface
904 -- file is the same as that for the compiler that's reading it
905 checkVersion :: { () }
906 : {-empty-} {% checkVersion Nothing }
907 | INTEGER {% checkVersion (Just (fromInteger $1)) }
909 -------------------------------------------------------------------
914 happyError buf PState{ loc = loc } = PFailed (ifaceParseErr buf loc)
916 mk_con_decl name (ex_tvs, ex_ctxt) details loc = mkConDecl name ex_tvs ex_ctxt details loc