6468bdc576c160110031e688bd1e89e06343446f
[ghc-hetmet.git] / ghc / compiler / rename / ParseIface.y
1 {-      Notes about the syntax of interface files
2         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 The header
4 ~~~~~~~~~~
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
9
10 Import declarations
11 ~~~~~~~~~~~~~~~~~~~
12   import Foo ;                          To compile M I used nothing from Foo, but it's 
13                                         below me in the hierarchy
14
15   import Foo ! @ ;                      Ditto, but the ! means that Foo contains orphans
16                                         and        the @ means that Foo is a boot interface
17
18   import Foo :: 3 ;                     To compile M I used everything from Foo, which has 
19                                         module version 3
20
21   import Foo :: 3 2 6 a 1 b 3 c 7 ;     To compile M I used Foo.  It had 
22                                                 module version 3
23                                                 fixity version 2
24                                                 rules  version 6
25                                         and some specific things besides.
26
27 -}
28
29
30 {
31 module ParseIface ( parseIface, parseType, parseRules, parseIdInfo ) where
32
33 #include "HsVersions.h"
34
35 import HsSyn            -- quite a bit of stuff
36 import RdrHsSyn         -- oodles of synonyms
37 import HsTypes          ( mkHsForAllTy, mkHsTupCon )
38 import HsCore
39 import Literal          ( Literal(..), mkMachInt, mkMachInt64, mkMachWord, mkMachWord64 )
40 import BasicTypes       ( Fixity(..), FixityDirection(..), StrictnessMark(..),
41                           NewOrData(..), Version, initialVersion, Boxity(..),
42                           Activation(..)
43                         )
44 import CostCentre       ( CostCentre(..), IsCafCC(..), IsDupdCC(..) )
45 import Type             ( Kind, mkArrowKind, liftedTypeKind, openTypeKind, usageTypeKind )
46 import TypeRep          ( IPName(..) )
47 import ForeignCall      ( ForeignCall(..), CCallConv(..), CCallSpec(..), CCallTarget(..) )
48 import Lex              
49
50 import RnMonad          ( ParsedIface(..), ExportItem, IfaceDeprecs ) 
51 import HscTypes         ( WhetherHasOrphans, IsBootInterface, GenAvailInfo(..), 
52                           ImportVersion, WhatsImported(..),
53                           RdrAvailInfo )
54
55 import RdrName          ( RdrName, mkRdrUnqual, mkIfaceOrig )
56 import Name             ( OccName )
57 import OccName          ( mkSysOccFS,
58                           tcName, varName, dataName, clsName, tvName,
59                           EncodedFS 
60                         )
61 import Module           ( ModuleName, PackageName, mkSysModuleNameFS, mkModule )
62 import SrcLoc           ( SrcLoc )
63 import CmdLineOpts      ( opt_InPackage, opt_IgnoreIfacePragmas )
64 import Outputable
65 import Class            ( DefMeth (..) )
66
67 import GlaExts
68 import FastString       ( tailFS )
69 }
70
71 %name       parseIface      iface
72 %name       parseType       type
73 %name       parseIdInfo     id_info
74 %name       parseRules      rules_and_deprecs
75
76 %tokentype  { Token }
77 %monad      { P }{ thenP }{ returnP }
78 %lexer      { lexer } { ITeof }
79
80 %token
81  'as'           { ITas }
82  'case'         { ITcase }                      -- Haskell keywords
83  'class'        { ITclass } 
84  'data'         { ITdata } 
85  'default'      { ITdefault }
86  'deriving'     { ITderiving }
87  'do'           { ITdo }
88  'else'         { ITelse }
89  'hiding'       { IThiding }
90  'if'           { ITif }
91  'import'       { ITimport }
92  'in'           { ITin }
93  'infix'        { ITinfix }
94  'infixl'       { ITinfixl }
95  'infixr'       { ITinfixr }
96  'instance'     { ITinstance }
97  'let'          { ITlet }
98  'module'       { ITmodule }
99  'newtype'      { ITnewtype }
100  'of'           { ITof }
101  'qualified'    { ITqualified }
102  'then'         { ITthen }
103  'type'         { ITtype }
104  'where'        { ITwhere }
105
106  'forall'       { ITforall }                    -- GHC extension keywords
107  'foreign'      { ITforeign }
108  'export'       { ITexport }
109  'label'        { ITlabel } 
110  'dynamic'      { ITdynamic }
111  'unsafe'       { ITunsafe }
112  'with'         { ITwith }
113  'stdcall'      { ITstdcallconv }
114  'ccall'        { ITccallconv }
115
116  '__interface'  { ITinterface }                 -- interface keywords
117  '__export'     { IT__export }
118  '__depends'    { ITdepends }
119  '__forall'     { IT__forall }
120  '__letrec'     { ITletrec }
121  '__coerce'     { ITcoerce }
122  '__inline_me'  { ITinlineMe }
123  '__inline_call'{ ITinlineCall }
124  '__DEFAULT'    { ITdefaultbranch }
125  '__bot'        { ITbottom }
126  '__integer'    { ITinteger_lit }
127  '__float'      { ITfloat_lit }
128  '__word'       { ITword_lit }
129  '__int64'      { ITint64_lit }
130  '__word64'     { ITword64_lit }
131  '__rational'   { ITrational_lit }
132  '__addr'       { ITaddr_lit }
133  '__label'      { ITlabel_lit }
134  '__litlit'     { ITlit_lit }
135  '__string'     { ITstring_lit }
136  '__ccall'      { ITccall $$ }
137  '__scc'        { ITscc }
138  '__sccC'       { ITsccAllCafs }
139
140  '__u'          { ITusage }
141
142  '__A'          { ITarity }
143  '__P'          { ITspecialise }
144  '__C'          { ITnocaf }
145  '__U'          { ITunfold }
146  '__S'          { ITstrict $$ }
147  '__R'          { ITrules }
148  '__M'          { ITcprinfo }
149  '__D'          { ITdeprecated }
150
151  '..'           { ITdotdot }                    -- reserved symbols
152  '::'           { ITdcolon }
153  '='            { ITequal }
154  '\\'           { ITlam }
155  '|'            { ITvbar }
156  '<-'           { ITlarrow }
157  '->'           { ITrarrow }
158  '@'            { ITat }
159  '=>'           { ITdarrow }
160  '-'            { ITminus }
161  '!'            { ITbang }
162
163  '{'            { ITocurly }                    -- special symbols
164  '}'            { ITccurly }
165  '{|'           { ITocurlybar }                         -- special symbols
166  '|}'           { ITccurlybar }                         -- special symbols
167  '['            { ITobrack }
168  ']'            { ITcbrack }
169  '('            { IToparen }
170  ')'            { ITcparen }
171  '(#'           { IToubxparen }
172  '#)'           { ITcubxparen }
173  ';'            { ITsemi }
174  ','            { ITcomma }
175  '.'            { ITdot }
176
177  VARID          { ITvarid    $$ }               -- identifiers
178  CONID          { ITconid    $$ }
179  VARSYM         { ITvarsym   $$ }
180  CONSYM         { ITconsym   $$ }
181  QVARID         { ITqvarid   $$ }
182  QCONID         { ITqconid   $$ }
183  QVARSYM        { ITqvarsym  $$ }
184  QCONSYM        { ITqconsym  $$ }
185
186  IPDUPVARID     { ITdupipvarid   $$ }           -- GHC extension
187  IPSPLITVARID   { ITsplitipvarid $$ }           -- GHC extension
188
189  PRAGMA         { ITpragma   $$ }
190
191  CHAR           { ITchar     $$ }
192  STRING         { ITstring   $$ }
193  INTEGER        { ITinteger  $$ }
194  RATIONAL       { ITrational $$ }
195  CLITLIT        { ITlitlit   $$ }
196
197  UNKNOWN        { ITunknown  $$ }
198 %%
199
200 iface           :: { ParsedIface }
201 iface           : '__interface' package mod_name 
202                         version sub_versions
203                         orphans checkVersion 'where'
204                   exports_part
205                   import_part
206                   fix_decl_part
207                   instance_decl_part
208                   decls_part
209                   rules_and_deprecs_part
210                   { ParsedIface {
211                         pi_mod  = mkModule $3 $2,       -- Module itself
212                         pi_vers = $4,                   -- Module version
213                         pi_orphan  = $6,
214                         pi_exports = (fst $5, $9),      -- Exports
215                         pi_usages  = $10,               -- Usages
216                         pi_fixity  = $11,               -- Fixies
217                         pi_insts   = $12,               -- Local instances
218                         pi_decls   = $13,               -- Decls
219                         pi_rules   = (snd $5,fst $14),  -- Rules 
220                         pi_deprecs = snd $14            -- Deprecations 
221                    } }
222
223 -- Versions for exports and rules (optional)
224 sub_versions :: { (Version,Version) }
225         : '[' version version ']'               { ($2,$3) }
226         | {- empty -}                           { (initialVersion, initialVersion) }
227
228 --------------------------------------------------------------------------
229
230 import_part :: { [ImportVersion OccName] }
231 import_part :                                             { [] }
232             |  import_decl import_part                    { $1 : $2 }
233             
234 import_decl :: { ImportVersion OccName }
235 import_decl : 'import' mod_name orphans is_boot whats_imported ';'
236                         { ({-mkSysModuleNameFS-} $2, $3, $4, $5) }
237
238 orphans             :: { WhetherHasOrphans }
239 orphans             :                                           { False }
240                     | '!'                                       { True }
241
242 is_boot             :: { IsBootInterface }
243 is_boot             :                                           { False }
244                     | '@'                                       { True }
245
246 whats_imported      :: { WhatsImported OccName }
247 whats_imported      :                                                   { NothingAtAll }
248                     | '::' version                                      { Everything $2 }
249                     | '::' version version version name_version_pairs   { Specifically $2 (Just $3) $5 $4 }
250                     | '::' version version name_version_pairs           { Specifically $2 Nothing $4 $3 }
251
252 name_version_pairs  ::  { [(OccName, Version)] }
253 name_version_pairs  :                                           { [] }
254                     |  name_version_pair name_version_pairs     { $1 : $2 }
255
256 name_version_pair   ::  { (OccName, Version) }
257 name_version_pair   :  var_occ version                          { ($1, $2) }
258                     |  tc_occ  version                          { ($1, $2) }
259
260
261 --------------------------------------------------------------------------
262
263 exports_part    :: { [ExportItem] }
264 exports_part    :                                       { [] }
265                 | '__export' mod_name entities ';'
266                         exports_part                    { ({-mkSysModuleNameFS-} $2, $3) : $5 }
267
268 entities        :: { [RdrAvailInfo] }
269 entities        :                                       { [] }
270                 |  entity entities                      { $1 : $2 }
271
272 entity          :: { RdrAvailInfo }
273 entity          :  var_occ                              { Avail $1 }
274                 |  tc_occ                               { AvailTC $1 [$1] }
275                 |  tc_occ '|' stuff_inside              { AvailTC $1 $3 }
276                 |  tc_occ stuff_inside                  { AvailTC $1 ($1:$2) }
277                 -- Note that the "main name" comes at the beginning
278
279 stuff_inside    :: { [OccName] }
280 stuff_inside    :  '{' val_occs '}'                     { $2 }
281
282 val_occ         :: { OccName }
283                 :  var_occ              { $1 }
284                 |  data_occ             { $1 }
285
286 val_occs        :: { [OccName] }
287                 :  val_occ              { [$1] }
288                 |  val_occ val_occs     { $1 : $2 }
289
290
291 --------------------------------------------------------------------------
292
293 fix_decl_part :: { [RdrNameFixitySig] }
294 fix_decl_part : {- empty -}                             { [] }
295               | fix_decls ';'                           { $1 }
296
297 fix_decls     :: { [RdrNameFixitySig] }
298 fix_decls     :                                         { [] }
299               | fix_decl fix_decls                      { $1 : $2 }
300
301 fix_decl :: { RdrNameFixitySig }
302 fix_decl : src_loc fixity prec var_or_data_name         { FixitySig $4 (Fixity $3 $2) $1 }
303
304 fixity      :: { FixityDirection }
305 fixity      : 'infixl'                                  { InfixL }
306             | 'infixr'                                  { InfixR }
307             | 'infix'                                   { InfixN }
308    
309 prec        :: { Int }
310 prec        : INTEGER                                   { fromInteger $1 }
311
312 -----------------------------------------------------------------------------
313
314 csigs           :: { [RdrNameSig] }
315 csigs           :                               { [] }
316                 | 'where' '{' csigs1 '}'        { $3 }
317
318 csigs1          :: { [RdrNameSig] }
319 csigs1          :                               { [] }
320                 | csig ';' csigs1               { $1 : $3 }
321
322 csig            :: { RdrNameSig }
323 csig            :  src_loc qvar_name '::' type          { ClassOpSig $2 NoDefMeth $4 $1 }
324                 |  src_loc qvar_name ';' '::' type      { ClassOpSig $2 GenDefMeth $5 $1 }              
325                 |  src_loc qvar_name '=' '::' type      { mkClassOpSigDM $2 $5 $1 }
326
327 --------------------------------------------------------------------------
328
329 instance_decl_part :: { [RdrNameInstDecl] }
330 instance_decl_part : {- empty -}                       { [] }
331                    | instance_decl_part inst_decl      { $2 : $1 }
332
333 inst_decl       :: { RdrNameInstDecl }
334 inst_decl       :  src_loc 'instance' type '=' qvar_name ';'
335                         { InstDecl $3
336                                    EmptyMonoBinds       {- No bindings -}
337                                    []                   {- No user pragmas -}
338                                    (Just $5)            {- Dfun id -}
339                                    $1
340                         }
341
342 --------------------------------------------------------------------------
343
344 decls_part :: { [(Version, RdrNameTyClDecl)] }
345 decls_part 
346         :  {- empty -}                          { [] }
347         |  opt_version decl ';' decls_part              { ($1,$2):$4 }
348
349 decl    :: { RdrNameTyClDecl }
350 decl    : src_loc qvar_name '::' type maybe_idinfo
351                         { IfaceSig $2 $4 ($5 $2) $1 }
352         | src_loc 'type' qtc_name tv_bndrs '=' type                    
353                         { TySynonym $3 $4 $6 $1 }
354         | src_loc 'foreign' 'type' qtc_name                    
355                         { ForeignType $4 Nothing DNType $1 }
356         | src_loc 'data' opt_decl_context qtc_name tv_bndrs constrs            
357                         { mkTyData DataType $3 $4 $5 $6 (length $6) Nothing $1 }
358         | src_loc 'newtype' opt_decl_context qtc_name tv_bndrs newtype_constr
359                         { mkTyData NewType $3 $4 $5 $6 1 Nothing $1 }
360         | src_loc 'class' opt_decl_context qtc_name tv_bndrs fds csigs
361                         { mkClassDecl $3 $4 $5 $6 $7 Nothing $1 }
362
363 maybe_idinfo  :: { RdrName -> [HsIdInfo RdrName] }
364 maybe_idinfo  : {- empty -}     { \_ -> [] }
365               | pragma          { \x -> if opt_IgnoreIfacePragmas then [] 
366                                         else case $1 of
367                                                 POk _ id_info -> id_info
368                                                 PFailed err -> pprPanic "IdInfo parse failed" 
369                                                                         (vcat [ppr x, err])
370                                 }
371     {-
372       If a signature decl is being loaded, and opt_IgnoreIfacePragmas is on,
373       we toss away unfolding information.
374
375       Also, if the signature is loaded from a module we're importing from source,
376       we do the same. This is to avoid situations when compiling a pair of mutually
377       recursive modules, peering at unfolding info in the interface file of the other, 
378       e.g., you compile A, it looks at B's interface file and may as a result change
379       its interface file. Hence, B is recompiled, maybe changing its interface file,
380       which will the unfolding info used in A to become invalid. Simple way out is to
381       just ignore unfolding info.
382
383       [Jan 99: I junked the second test above.  If we're importing from an hi-boot
384        file there isn't going to *be* any pragma info.  The above comment
385        dates from a time where we picked up a .hi file first if it existed.]
386     -}
387
388 pragma  :: { ParseResult [HsIdInfo RdrName] }
389 pragma  : src_loc PRAGMA        { parseIdInfo $2 PState{ bol = 0#, atbol = 1#,
390                                                         context = [],
391                                                         glasgow_exts = 1#,
392                                                         loc = $1 }
393                                 }
394
395 -----------------------------------------------------------------------------
396
397 rules_and_deprecs_part :: { ([RdrNameRuleDecl], IfaceDeprecs) }
398 rules_and_deprecs_part : {- empty -}    { ([], Nothing) }
399                        | rules_prag     { case $1 of
400                                              POk _ rds -> rds
401                                              PFailed err -> pprPanic "Rules/Deprecations parse failed" err
402                                         }
403
404 rules_prag :: { ParseResult ([RdrNameRuleDecl], IfaceDeprecs) }
405 rules_prag : src_loc PRAGMA     { parseRules $2 PState{ bol = 0#, atbol = 1#,
406                                                         context = [],
407                                                         glasgow_exts = 1#,
408                                                         loc = $1 }
409                                 }
410
411 rules_and_deprecs :: { ([RdrNameRuleDecl], IfaceDeprecs) }
412 rules_and_deprecs : rule_prag deprec_prag       { ($1, $2) }
413
414  
415 -----------------------------------------------------------------------------
416
417 rule_prag :: { [RdrNameRuleDecl] }
418 rule_prag : {- empty -}                 { [] }
419           | '__R' rules                 { $2 }
420
421 rules      :: { [RdrNameRuleDecl] }
422            : {- empty -}        { [] }
423            | rule ';' rules     { $1:$3 }
424
425 rule       :: { RdrNameRuleDecl }
426 rule       : src_loc STRING activation rule_forall qvar_name 
427              core_args '=' core_expr    { IfaceRule $2 $3 $4 $5 $6 $8 $1 } 
428
429 activation :: { Activation }
430 activation : {- empty -}                { AlwaysActive }
431            | '[' INTEGER ']'            { ActiveAfter (fromInteger $2) }
432
433 rule_forall     :: { [UfBinder RdrName] }
434 rule_forall     : '__forall' '{' core_bndrs '}' { $3 }
435                   
436 -----------------------------------------------------------------------------
437
438 deprec_prag     :: { IfaceDeprecs }
439 deprec_prag     : {- empty -}           { Nothing }
440                 | '__D' deprecs         { Just $2 } 
441
442 deprecs         :: { Either DeprecTxt [(RdrName,DeprecTxt)] }
443 deprecs         : STRING                { Left $1 }
444                 | deprec_list           { Right $1 }
445
446 deprec_list     :: { [(RdrName,DeprecTxt)] }
447 deprec_list     : deprec                        { [$1] }
448                 | deprec ';' deprec_list        { $1 : $3 }
449
450 deprec          :: { (RdrName,DeprecTxt) }
451 deprec          : deprec_name STRING    { ($1, $2) }
452
453 deprec_name     :: { RdrName }
454                 : qvar_name             { $1 }
455                 | qtc_name              { $1 }
456
457 -----------------------------------------------------------------------------
458
459 version         :: { Version }
460 version         :  INTEGER                      { fromInteger $1 }
461
462 opt_version     :: { Version }
463 opt_version     : version                       { $1 }
464                 | {- empty -}                   { initialVersion }
465         
466 opt_decl_context  :: { RdrNameContext }
467 opt_decl_context  :                             { [] }
468                   | context '=>'                { $1 }
469
470 ----------------------------------------------------------------------------
471
472 constrs         :: { [RdrNameConDecl] {- empty for handwritten abstract -} }
473                 :                       { [] }
474                 | '=' constrs1          { $2 }
475
476 constrs1        :: { [RdrNameConDecl] }
477 constrs1        :  constr               { [$1] }
478                 |  constr '|' constrs1  { $1 : $3 }
479
480 constr          :: { RdrNameConDecl }
481 constr          :  src_loc ex_stuff qdata_name batypes          { mk_con_decl $3 $2 (VanillaCon $4) $1 }
482                 |  src_loc ex_stuff qdata_name '{' fields1 '}'  { mk_con_decl $3 $2 (RecCon $5)     $1 }
483                 -- We use "data_fs" so as to include ()
484
485 newtype_constr  :: { [RdrNameConDecl] {- Not allowed to be empty -} }
486 newtype_constr  : src_loc '=' ex_stuff qdata_name atype { [mk_con_decl $4 $3 (VanillaCon [unbangedType $5]) $1] }
487                 | src_loc '=' ex_stuff qdata_name '{' qvar_name '::' atype '}'
488                                                         { [mk_con_decl $4 $3 (RecCon [([$6], unbangedType $8)]) $1] }
489
490 ex_stuff :: { ([HsTyVarBndr RdrName], RdrNameContext) }
491 ex_stuff        :                                       { ([],[]) }
492                 | '__forall' tv_bndrs opt_context '=>'  { ($2,$3) }
493
494 batypes         :: { [RdrNameBangType] }
495 batypes         :                                       { [] }
496                 |  batype batypes                       { $1 : $2 }
497
498 batype          :: { RdrNameBangType }
499 batype          :  tatype                               { unbangedType $1 }
500                 |  '!' tatype                           { BangType MarkedStrict    $2 }
501                 |  '!' '!' tatype                       { BangType MarkedUnboxed   $3 }
502
503 fields1         :: { [([RdrName], RdrNameBangType)] }
504 fields1         : field                                 { [$1] }
505                 | field ',' fields1                     { $1 : $3 }
506
507 field           :: { ([RdrName], RdrNameBangType) }
508 field           :  qvar_names1 '::' ttype               { ($1, unbangedType $3) }
509                 |  qvar_names1 '::' '!' ttype           { ($1, BangType MarkedStrict    $4) }
510                 |  qvar_names1 '::' '!' '!' ttype       { ($1, BangType MarkedUnboxed   $5) }
511
512 --------------------------------------------------------------------------
513
514 type            :: { RdrNameHsType }
515 type            : '__forall' tv_bndrs 
516                         opt_context '=>' type   { mkHsForAllTy (Just $2) $3 $5 }
517                 | btype '->' type               { HsFunTy $1 $3 }
518                 | btype                         { $1 }
519
520 opt_context     :: { RdrNameContext }
521 opt_context     :                                       { [] }
522                 | context                               { $1 }
523
524 context         :: { RdrNameContext }
525 context         : '(' context_list1 ')'                 { $2 }
526                 | '{' context_list1 '}'                 { $2 }  -- Backward compatibility
527
528 context_list1   :: { RdrNameContext }
529 context_list1   : class                                 { [$1] }
530                 | class ',' context_list1               { $1 : $3 }
531
532 class           :: { HsPred RdrName }
533 class           :  qcls_name atypes                     { (HsClassP $1 $2) }
534                 |  ipvar_name '::' type                 { (HsIParam $1 $3) }
535
536 types0          :: { [RdrNameHsType]                    {- Zero or more -}  }   
537 types0          :  {- empty -}                          { [ ] }
538                 |  type                                 { [ $1 ] }
539                 |  types2                               { $1 }
540
541 types2          :: { [RdrNameHsType]                    {- Two or more -}  }    
542 types2          :  type ',' type                        { [$1,$3] }
543                 |  type ',' types2                      { $1 : $3 }
544
545 btype           :: { RdrNameHsType }
546 btype           :  atype                                { $1 }
547                 |  btype atype                          { HsAppTy $1 $2 }
548                 |  '__u' atype atype                    { HsUsageTy $2 $3 }
549
550 atype           :: { RdrNameHsType }
551 atype           :  qtc_name                             { HsTyVar $1 }
552                 |  tv_name                              { HsTyVar $1 }
553                 |  '.'                                  { hsUsOnce }
554                 |  '!'                                  { hsUsMany }
555                 |  '(' ')'                              { HsTupleTy (mkHsTupCon tcName Boxed   []) [] }
556                 |  '(' types2 ')'                       { HsTupleTy (mkHsTupCon tcName Boxed   $2) $2 }
557                 |  '(#' types0 '#)'                     { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
558                 |  '[' type ']'                         { HsListTy  $2 }
559                 |  '{' qcls_name atypes '}'             { mkHsDictTy $2 $3 }
560                 |  '{' ipvar_name '::' type '}'         { mkHsIParamTy $2 $4 }
561                 |  '(' type ')'                         { $2 }
562
563 atypes          :: { [RdrNameHsType]    {-  Zero or more -} }
564 atypes          :                                       { [] }
565                 |  atype atypes                         { $1 : $2 }
566 --------------------------------------------------------------------------
567
568 -- versions of type/btype/atype that cant begin with '!' (or '.')
569 -- for use where the kind is definitely known NOT to be '$'
570
571 ttype           :: { RdrNameHsType }
572 ttype           : '__forall' tv_bndrs 
573                         opt_context '=>' type           { mkHsForAllTy (Just $2) $3 $5 }
574                 | tbtype '->' type                      { HsFunTy $1 $3 }
575                 | tbtype                                { $1 }
576
577 tbtype          :: { RdrNameHsType }
578 tbtype          :  tatype                               { $1 }
579                 |  tbtype atype                         { HsAppTy $1 $2 }
580                 |  '__u' atype atype                    { HsUsageTy $2 $3 }
581
582 tatype          :: { RdrNameHsType }
583 tatype          :  qtc_name                             { HsTyVar $1 }
584                 |  tv_name                              { HsTyVar $1 }
585                 |  '(' ')'                              { HsTupleTy (mkHsTupCon tcName Boxed   []) [] }
586                 |  '(' types2 ')'                       { HsTupleTy (mkHsTupCon tcName Boxed   $2) $2 }
587                 |  '(#' types0 '#)'                     { HsTupleTy (mkHsTupCon tcName Unboxed $2) $2 }
588                 |  '[' type ']'                         { HsListTy  $2 }
589                 |  '{' qcls_name atypes '}'             { mkHsDictTy $2 $3 }
590                 |  '{' ipvar_name '::' type '}'         { mkHsIParamTy $2 $4 }
591                 |  '(' type ')'                         { $2 }
592 ---------------------------------------------------------------------
593
594 package         :: { PackageName }
595                 :  STRING               { $1 }
596                 | {- empty -}           { opt_InPackage }
597                                 -- Useful for .hi-boot files,
598                                 -- which can omit the package Id
599                                 -- Module loops are always within a package
600
601 mod_name        :: { ModuleName }
602                 :  CONID                { mkSysModuleNameFS $1 }
603
604
605 ---------------------------------------------------
606 var_fs          :: { EncodedFS }
607                 : VARID                 { $1 }
608                 | 'as'                  { SLIT("as") }
609                 | 'qualified'           { SLIT("qualified") }
610                 | 'hiding'              { SLIT("hiding") }
611                 | 'forall'              { SLIT("forall") }
612                 | 'foreign'             { SLIT("foreign") }
613                 | 'export'              { SLIT("export") }
614                 | 'label'               { SLIT("label") }
615                 | 'dynamic'             { SLIT("dynamic") }
616                 | 'unsafe'              { SLIT("unsafe") }
617                 | 'with'                { SLIT("with") }
618                 | 'ccall'               { SLIT("ccall") }
619                 | 'stdcall'             { SLIT("stdcall") }
620
621 var_occ         :: { OccName }
622                 :  var_fs               { mkSysOccFS varName $1 }
623
624 var_name        :: { RdrName }
625 var_name        :  var_occ              { mkRdrUnqual $1 }
626
627 qvar_name       :: { RdrName }
628 qvar_name       :  var_name             { $1 }
629                 |  QVARID               { mkIfaceOrig varName $1 }
630
631 ipvar_name      :: { IPName RdrName }
632                 : IPDUPVARID            { Dupable   (mkRdrUnqual (mkSysOccFS varName $1)) }
633                 | IPSPLITVARID          { MustSplit (mkRdrUnqual (mkSysOccFS varName $1)) }
634
635 qvar_names1     :: { [RdrName] }
636 qvar_names1     : qvar_name             { [$1] }
637                 | qvar_name qvar_names1 { $1 : $2 }
638
639 var_names       :: { [RdrName] }
640 var_names       :                       { [] }
641                 | var_name var_names    { $1 : $2 }
642
643 var_names1      :: { [RdrName] }
644 var_names1      : var_name var_names    { $1 : $2 }
645
646 ---------------------------------------------------
647
648 data_occ        :: { OccName }
649                 :  CONID                { mkSysOccFS dataName $1 }
650
651 qdata_name      :: { RdrName }
652                 :  data_occ             { mkRdrUnqual $1 }
653                 |  QCONID               { mkIfaceOrig dataName $1 }
654                                 
655 var_or_data_name :: { RdrName }
656                   : qvar_name           { $1 }
657                   | qdata_name          { $1 }
658
659 ---------------------------------------------------
660 tc_occ          :: { OccName }
661                 :  CONID                { mkSysOccFS tcName $1 }
662
663 qtc_name        :: { RdrName }
664                 : tc_occ                { mkRdrUnqual $1 }
665                 | QCONID                { mkIfaceOrig tcName $1 }
666
667 ---------------------------------------------------
668 qcls_name       :: { RdrName }
669                 : CONID                 { mkRdrUnqual (mkSysOccFS clsName $1) }
670                 | QCONID                { mkIfaceOrig clsName $1 }
671
672 ---------------------------------------------------
673 tv_name         :: { RdrName }
674                 :  var_fs               { mkRdrUnqual (mkSysOccFS tvName $1) }
675
676 tv_bndr         :: { HsTyVarBndr RdrName }
677                 :  tv_name '::' akind   { IfaceTyVar $1 $3 }
678                 |  tv_name              { IfaceTyVar $1 liftedTypeKind }
679
680 tv_bndrs        :: { [HsTyVarBndr RdrName] }
681                 : tv_bndrs1             { $1 }
682                 | '[' tv_bndrs1 ']'     { $2 }  -- Backward compatibility
683
684 tv_bndrs1       :: { [HsTyVarBndr RdrName] }
685                 :                       { [] }
686                 | tv_bndr tv_bndrs1     { $1 : $2 }
687
688 ---------------------------------------------------
689 fds :: { [([RdrName], [RdrName])] }
690         : {- empty -}                   { [] }
691         | '|' fds1                      { reverse $2 }
692
693 fds1 :: { [([RdrName], [RdrName])] }
694         : fds1 ',' fd                   { $3 : $1 }
695         | fd                            { [$1] }
696
697 fd :: { ([RdrName], [RdrName]) }
698         : varids0 '->' varids0          { (reverse $1, reverse $3) }
699
700 varids0 :: { [RdrName] }
701         : {- empty -}                   { [] }
702         | varids0 tv_name               { $2 : $1 }
703
704 ---------------------------------------------------
705 kind            :: { Kind }
706                 : akind                 { $1 }
707                 | akind '->' kind       { mkArrowKind $1 $3 }
708
709 akind           :: { Kind }
710                 : VARSYM                { if $1 == SLIT("*") then
711                                                 liftedTypeKind
712                                           else if $1 == SLIT("?") then
713                                                 openTypeKind
714                                           else if $1 == SLIT("\36") then
715                                                 usageTypeKind  -- dollar
716                                           else panic "ParseInterface: akind"
717                                         }
718                 | '(' kind ')'  { $2 }
719
720 --------------------------------------------------------------------------
721
722 id_info         :: { [HsIdInfo RdrName] }
723                 : id_info_item                  { [$1] }
724                 | id_info_item id_info          { $1 : $2 }
725
726 id_info_item    :: { HsIdInfo RdrName }
727                 : '__A' INTEGER                 { HsArity (fromInteger $2) }
728                 | '__U' activation core_expr    { HsUnfold $2 $3 }
729                 | '__S'                         { HsStrictness $1 }
730                 | '__C'                         { HsNoCafRefs }
731                 | '__P' qvar_name INTEGER       { HsWorker $2 (fromInteger $3) }
732
733 -------------------------------------------------------
734 core_expr       :: { UfExpr RdrName }
735 core_expr       : '\\' core_bndrs '->' core_expr        { foldr UfLam $4 $2 }
736                 | 'case' core_expr 'of' var_name
737                   '{' core_alts '}'                     { UfCase $2 $4 $6 }
738
739                 | 'let' '{' core_val_bndr '=' core_expr
740                       '}' 'in' core_expr                { UfLet (UfNonRec $3 $5) $8 }
741                 | '__letrec' '{' rec_binds '}'          
742                   'in' core_expr                        { UfLet (UfRec $3) $6 }
743
744                 | '__litlit' STRING atype               { UfLitLit $2 $3 }
745
746                 | fexpr                                 { $1 }
747
748 fexpr   :: { UfExpr RdrName }
749 fexpr   : fexpr core_arg                                { UfApp $1 $2 }
750         | scc core_aexpr                                { UfNote (UfSCC $1) $2  }
751         | '__inline_me' core_aexpr                      { UfNote UfInlineMe $2 }
752         | '__inline_call' core_aexpr                    { UfNote UfInlineCall $2 }
753         | '__coerce' atype core_aexpr                   { UfNote (UfCoerce $2) $3 }
754         | core_aexpr                                    { $1 }
755
756 core_arg        :: { UfExpr RdrName }
757                 : '@' atype                                     { UfType $2 }
758                 | core_aexpr                                    { $1 }
759
760 core_args       :: { [UfExpr RdrName] }
761                 :                                               { [] }
762                 | core_arg core_args                            { $1 : $2 }
763
764 core_aexpr      :: { UfExpr RdrName }              -- Atomic expressions
765 core_aexpr      : qvar_name                                     { UfVar $1 }
766                 | qdata_name                                    { UfVar $1 }
767
768                 | core_lit               { UfLit $1 }
769                 | '(' core_expr ')'      { $2 }
770
771                 | '('  ')'               { UfTuple (mkHsTupCon dataName Boxed [])   [] }
772                 | '(' comma_exprs2 ')'   { UfTuple (mkHsTupCon dataName Boxed $2)   $2 }
773                 | '(#' comma_exprs0 '#)' { UfTuple (mkHsTupCon dataName Unboxed $2) $2 }
774
775                 | '{' '__ccall' ccall_string type '}'       
776                            { let
777                                  (is_dyn, is_casm, may_gc) = $2
778
779                                  target | is_dyn    = DynamicTarget
780                                         | is_casm   = CasmTarget $3
781                                         | otherwise = StaticTarget $3
782
783                                  ccall = CCallSpec target CCallConv may_gc
784                              in
785                              UfFCall (CCall ccall) $4
786                            }
787
788
789 comma_exprs0    :: { [UfExpr RdrName] } -- Zero or more
790 comma_exprs0    : {- empty -}                   { [ ] }
791                 | core_expr                     { [ $1 ] }
792                 | comma_exprs2                  { $1 }
793
794 comma_exprs2    :: { [UfExpr RdrName] } -- Two or more
795 comma_exprs2    : core_expr ',' core_expr                       { [$1,$3] }
796                 | core_expr ',' comma_exprs2                    { $1 : $3 }
797
798 rec_binds       :: { [(UfBinder RdrName, UfExpr RdrName)] }
799                 :                                               { [] }
800                 | core_val_bndr '=' core_expr ';' rec_binds     { ($1,$3) : $5 }
801
802 core_alts       :: { [UfAlt RdrName] }
803                 :                                               { [] }
804                 | core_alt ';' core_alts                        { $1 : $3 }
805
806 core_alt        :: { UfAlt RdrName }
807 core_alt        : core_pat '->' core_expr       { (fst $1, snd $1, $3) }
808
809 core_pat        :: { (UfConAlt RdrName, [RdrName]) }
810 core_pat        : core_lit                      { (UfLitAlt  $1, []) }
811                 | '__litlit' STRING atype       { (UfLitLitAlt $2 $3, []) }
812                 | qdata_name core_pat_names     { (UfDataAlt $1, $2) }
813                 | '('  ')'                      { (UfTupleAlt (mkHsTupCon dataName Boxed []),   []) }
814                 | '(' comma_var_names1 ')'      { (UfTupleAlt (mkHsTupCon dataName Boxed $2),   $2) }
815                 | '(#' comma_var_names1 '#)'    { (UfTupleAlt (mkHsTupCon dataName Unboxed $2), $2) }
816                 | '__DEFAULT'                   { (UfDefault, []) }
817                 | '(' core_pat ')'              { $2 }
818
819 core_pat_names :: { [RdrName] }
820 core_pat_names :                                { [] }
821                 | core_pat_name core_pat_names  { $1 : $2 }
822
823 -- Tyvar names and variable names live in different name spaces
824 -- so they need to be signalled separately.  But we don't record 
825 -- types or kinds in a pattern; we work that out from the type 
826 -- of the case scrutinee
827 core_pat_name   :: { RdrName }
828 core_pat_name   : var_name                      { $1 }
829                 | '@' tv_name                   { $2 }
830         
831 comma_var_names1 :: { [RdrName] }       -- One or more
832 comma_var_names1 : var_name                                     { [$1] }
833                  | var_name ',' comma_var_names1                { $1 : $3 }
834
835 core_lit        :: { Literal }
836 core_lit        : integer                       { mkMachInt $1 }
837                 | CHAR                          { MachChar $1 }
838                 | STRING                        { MachStr $1 }
839                 | rational                      { MachDouble $1 }
840                 | '__word' integer              { mkMachWord $2 }
841                 | '__word64' integer            { mkMachWord64 $2 }
842                 | '__int64' integer             { mkMachInt64 $2 }
843                 | '__float' rational            { MachFloat $2 }
844                 | '__addr' integer              { MachAddr $2 }
845                 | '__label' STRING              { MachLabel $2 }
846
847 integer         :: { Integer }
848                 : INTEGER                       { $1 }
849                 | '-' INTEGER                   { (-$2) }
850
851 rational        :: { Rational }
852                 : RATIONAL                      { $1 }
853                 | '-' RATIONAL                  { (-$2) }
854
855 core_bndr       :: { UfBinder RdrName }
856 core_bndr       : core_val_bndr                                 { $1 }
857                 | core_tv_bndr                                  { $1 }
858
859 core_bndrs      :: { [UfBinder RdrName] }
860 core_bndrs      :                                               { [] }
861                 | core_bndr core_bndrs                          { $1 : $2 }
862
863 core_val_bndr   :: { UfBinder RdrName }
864 core_val_bndr   : var_name '::' atype                           { UfValBinder $1 $3 }
865
866 core_tv_bndr    :: { UfBinder RdrName }
867 core_tv_bndr    :  '@' tv_name '::' akind               { UfTyBinder $2 $4 }
868                 |  '@' tv_name                          { UfTyBinder $2 liftedTypeKind }
869
870 ccall_string    :: { FAST_STRING }
871                 : STRING                                        { $1 }
872                 | CLITLIT                                       { $1 }
873                 | VARID                                         { $1 }
874                 | CONID                                         { $1 }
875
876 ------------------------------------------------------------------------
877 scc     :: { CostCentre }
878         :  '__sccC' '{' mod_name '}'                      { AllCafsCC $3 }
879         |  '__scc' '{' cc_name mod_name cc_dup cc_caf '}'
880                              { NormalCC { cc_name = $3, cc_mod = $4,
881                                           cc_is_dupd = $5, cc_is_caf = $6 } }
882
883 cc_name :: { EncodedFS }
884         : CONID                 { $1 }
885         | var_fs                { $1 }
886   
887 cc_dup  :: { IsDupdCC }
888 cc_dup  :                       { OriginalCC }
889         | '!'                   { DupdCC }
890
891 cc_caf  :: { IsCafCC }
892         :                       { NotCafCC }
893         | '__C'                 { CafCC }
894
895 -------------------------------------------------------------------
896
897 src_loc :: { SrcLoc }
898 src_loc :                               {% getSrcLocP }
899
900 -- Check the project version: this makes sure
901 -- that the project version (e.g. 407) in the interface
902 -- file is the same as that for the compiler that's reading it
903 checkVersion :: { () }
904            : {-empty-}                  {% checkVersion Nothing }
905            | INTEGER                    {% checkVersion (Just (fromInteger $1)) }
906
907 ------------------------------------------------------------------- 
908
909 --                      Haskell code 
910 {
911 happyError :: P a
912 happyError buf PState{ loc = loc } = PFailed (ifaceParseErr buf loc)
913
914 mk_con_decl name (ex_tvs, ex_ctxt) details loc = mkConDecl name ex_tvs ex_ctxt details loc
915 }