xref: /aosp_15_r20/external/llvm/docs/TableGen/LangRef.rst (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker===========================
2*9880d681SAndroid Build Coastguard WorkerTableGen Language Reference
3*9880d681SAndroid Build Coastguard Worker===========================
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Worker.. contents::
6*9880d681SAndroid Build Coastguard Worker   :local:
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard Worker.. warning::
9*9880d681SAndroid Build Coastguard Worker   This document is extremely rough. If you find something lacking, please
10*9880d681SAndroid Build Coastguard Worker   fix it, file a documentation bug, or ask about it on llvm-dev.
11*9880d681SAndroid Build Coastguard Worker
12*9880d681SAndroid Build Coastguard WorkerIntroduction
13*9880d681SAndroid Build Coastguard Worker============
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard WorkerThis document is meant to be a normative spec about the TableGen language
16*9880d681SAndroid Build Coastguard Workerin and of itself (i.e. how to understand a given construct in terms of how
17*9880d681SAndroid Build Coastguard Workerit affects the final set of records represented by the TableGen file). If
18*9880d681SAndroid Build Coastguard Workeryou are unsure if this document is really what you are looking for, please
19*9880d681SAndroid Build Coastguard Workerread the :doc:`introduction to TableGen <index>` first.
20*9880d681SAndroid Build Coastguard Worker
21*9880d681SAndroid Build Coastguard WorkerNotation
22*9880d681SAndroid Build Coastguard Worker========
23*9880d681SAndroid Build Coastguard Worker
24*9880d681SAndroid Build Coastguard WorkerThe lexical and syntax notation used here is intended to imitate
25*9880d681SAndroid Build Coastguard Worker`Python's`_. In particular, for lexical definitions, the productions
26*9880d681SAndroid Build Coastguard Workeroperate at the character level and there is no implied whitespace between
27*9880d681SAndroid Build Coastguard Workerelements. The syntax definitions operate at the token level, so there is
28*9880d681SAndroid Build Coastguard Workerimplied whitespace between tokens.
29*9880d681SAndroid Build Coastguard Worker
30*9880d681SAndroid Build Coastguard Worker.. _`Python's`: http://docs.python.org/py3k/reference/introduction.html#notation
31*9880d681SAndroid Build Coastguard Worker
32*9880d681SAndroid Build Coastguard WorkerLexical Analysis
33*9880d681SAndroid Build Coastguard Worker================
34*9880d681SAndroid Build Coastguard Worker
35*9880d681SAndroid Build Coastguard WorkerTableGen supports BCPL (``// ...``) and nestable C-style (``/* ... */``)
36*9880d681SAndroid Build Coastguard Workercomments.
37*9880d681SAndroid Build Coastguard Worker
38*9880d681SAndroid Build Coastguard WorkerThe following is a listing of the basic punctuation tokens::
39*9880d681SAndroid Build Coastguard Worker
40*9880d681SAndroid Build Coastguard Worker   - + [ ] { } ( ) < > : ; .  = ? #
41*9880d681SAndroid Build Coastguard Worker
42*9880d681SAndroid Build Coastguard WorkerNumeric literals take one of the following forms:
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Worker.. TableGen actually will lex some pretty strange sequences an interpret
45*9880d681SAndroid Build Coastguard Worker   them as numbers. What is shown here is an attempt to approximate what it
46*9880d681SAndroid Build Coastguard Worker   "should" accept.
47*9880d681SAndroid Build Coastguard Worker
48*9880d681SAndroid Build Coastguard Worker.. productionlist::
49*9880d681SAndroid Build Coastguard Worker   TokInteger: `DecimalInteger` | `HexInteger` | `BinInteger`
50*9880d681SAndroid Build Coastguard Worker   DecimalInteger: ["+" | "-"] ("0"..."9")+
51*9880d681SAndroid Build Coastguard Worker   HexInteger: "0x" ("0"..."9" | "a"..."f" | "A"..."F")+
52*9880d681SAndroid Build Coastguard Worker   BinInteger: "0b" ("0" | "1")+
53*9880d681SAndroid Build Coastguard Worker
54*9880d681SAndroid Build Coastguard WorkerOne aspect to note is that the :token:`DecimalInteger` token *includes* the
55*9880d681SAndroid Build Coastguard Worker``+`` or ``-``, as opposed to having ``+`` and ``-`` be unary operators as
56*9880d681SAndroid Build Coastguard Workermost languages do.
57*9880d681SAndroid Build Coastguard Worker
58*9880d681SAndroid Build Coastguard WorkerAlso note that :token:`BinInteger` creates a value of type ``bits<n>``
59*9880d681SAndroid Build Coastguard Worker(where ``n`` is the number of bits).  This will implicitly convert to
60*9880d681SAndroid Build Coastguard Workerintegers when needed.
61*9880d681SAndroid Build Coastguard Worker
62*9880d681SAndroid Build Coastguard WorkerTableGen has identifier-like tokens:
63*9880d681SAndroid Build Coastguard Worker
64*9880d681SAndroid Build Coastguard Worker.. productionlist::
65*9880d681SAndroid Build Coastguard Worker   ualpha: "a"..."z" | "A"..."Z" | "_"
66*9880d681SAndroid Build Coastguard Worker   TokIdentifier: ("0"..."9")* `ualpha` (`ualpha` | "0"..."9")*
67*9880d681SAndroid Build Coastguard Worker   TokVarName: "$" `ualpha` (`ualpha` |  "0"..."9")*
68*9880d681SAndroid Build Coastguard Worker
69*9880d681SAndroid Build Coastguard WorkerNote that unlike most languages, TableGen allows :token:`TokIdentifier` to
70*9880d681SAndroid Build Coastguard Workerbegin with a number. In case of ambiguity, a token will be interpreted as a
71*9880d681SAndroid Build Coastguard Workernumeric literal rather than an identifier.
72*9880d681SAndroid Build Coastguard Worker
73*9880d681SAndroid Build Coastguard WorkerTableGen also has two string-like literals:
74*9880d681SAndroid Build Coastguard Worker
75*9880d681SAndroid Build Coastguard Worker.. productionlist::
76*9880d681SAndroid Build Coastguard Worker   TokString: '"' <non-'"' characters and C-like escapes> '"'
77*9880d681SAndroid Build Coastguard Worker   TokCodeFragment: "[{" <shortest text not containing "}]"> "}]"
78*9880d681SAndroid Build Coastguard Worker
79*9880d681SAndroid Build Coastguard Worker:token:`TokCodeFragment` is essentially a multiline string literal
80*9880d681SAndroid Build Coastguard Workerdelimited by ``[{`` and ``}]``.
81*9880d681SAndroid Build Coastguard Worker
82*9880d681SAndroid Build Coastguard Worker.. note::
83*9880d681SAndroid Build Coastguard Worker   The current implementation accepts the following C-like escapes::
84*9880d681SAndroid Build Coastguard Worker
85*9880d681SAndroid Build Coastguard Worker      \\ \' \" \t \n
86*9880d681SAndroid Build Coastguard Worker
87*9880d681SAndroid Build Coastguard WorkerTableGen also has the following keywords::
88*9880d681SAndroid Build Coastguard Worker
89*9880d681SAndroid Build Coastguard Worker   bit   bits      class   code         dag
90*9880d681SAndroid Build Coastguard Worker   def   foreach   defm    field        in
91*9880d681SAndroid Build Coastguard Worker   int   let       list    multiclass   string
92*9880d681SAndroid Build Coastguard Worker
93*9880d681SAndroid Build Coastguard WorkerTableGen also has "bang operators" which have a
94*9880d681SAndroid Build Coastguard Workerwide variety of meanings:
95*9880d681SAndroid Build Coastguard Worker
96*9880d681SAndroid Build Coastguard Worker.. productionlist::
97*9880d681SAndroid Build Coastguard Worker   BangOperator: one of
98*9880d681SAndroid Build Coastguard Worker               :!eq     !if      !head    !tail      !con
99*9880d681SAndroid Build Coastguard Worker               :!add    !shl     !sra     !srl       !and
100*9880d681SAndroid Build Coastguard Worker               :!cast   !empty   !subst   !foreach   !listconcat   !strconcat
101*9880d681SAndroid Build Coastguard Worker
102*9880d681SAndroid Build Coastguard WorkerSyntax
103*9880d681SAndroid Build Coastguard Worker======
104*9880d681SAndroid Build Coastguard Worker
105*9880d681SAndroid Build Coastguard WorkerTableGen has an ``include`` mechanism. It does not play a role in the
106*9880d681SAndroid Build Coastguard Workersyntax per se, since it is lexically replaced with the contents of the
107*9880d681SAndroid Build Coastguard Workerincluded file.
108*9880d681SAndroid Build Coastguard Worker
109*9880d681SAndroid Build Coastguard Worker.. productionlist::
110*9880d681SAndroid Build Coastguard Worker   IncludeDirective: "include" `TokString`
111*9880d681SAndroid Build Coastguard Worker
112*9880d681SAndroid Build Coastguard WorkerTableGen's top-level production consists of "objects".
113*9880d681SAndroid Build Coastguard Worker
114*9880d681SAndroid Build Coastguard Worker.. productionlist::
115*9880d681SAndroid Build Coastguard Worker   TableGenFile: `Object`*
116*9880d681SAndroid Build Coastguard Worker   Object: `Class` | `Def` | `Defm` | `Let` | `MultiClass` | `Foreach`
117*9880d681SAndroid Build Coastguard Worker
118*9880d681SAndroid Build Coastguard Worker``class``\es
119*9880d681SAndroid Build Coastguard Worker------------
120*9880d681SAndroid Build Coastguard Worker
121*9880d681SAndroid Build Coastguard Worker.. productionlist::
122*9880d681SAndroid Build Coastguard Worker   Class: "class" `TokIdentifier` [`TemplateArgList`] `ObjectBody`
123*9880d681SAndroid Build Coastguard Worker
124*9880d681SAndroid Build Coastguard WorkerA ``class`` declaration creates a record which other records can inherit
125*9880d681SAndroid Build Coastguard Workerfrom. A class can be parametrized by a list of "template arguments", whose
126*9880d681SAndroid Build Coastguard Workervalues can be used in the class body.
127*9880d681SAndroid Build Coastguard Worker
128*9880d681SAndroid Build Coastguard WorkerA given class can only be defined once. A ``class`` declaration is
129*9880d681SAndroid Build Coastguard Workerconsidered to define the class if any of the following is true:
130*9880d681SAndroid Build Coastguard Worker
131*9880d681SAndroid Build Coastguard Worker.. break ObjectBody into its consituents so that they are present here?
132*9880d681SAndroid Build Coastguard Worker
133*9880d681SAndroid Build Coastguard Worker#. The :token:`TemplateArgList` is present.
134*9880d681SAndroid Build Coastguard Worker#. The :token:`Body` in the :token:`ObjectBody` is present and is not empty.
135*9880d681SAndroid Build Coastguard Worker#. The :token:`BaseClassList` in the :token:`ObjectBody` is present.
136*9880d681SAndroid Build Coastguard Worker
137*9880d681SAndroid Build Coastguard WorkerYou can declare an empty class by giving and empty :token:`TemplateArgList`
138*9880d681SAndroid Build Coastguard Workerand an empty :token:`ObjectBody`. This can serve as a restricted form of
139*9880d681SAndroid Build Coastguard Workerforward declaration: note that records deriving from the forward-declared
140*9880d681SAndroid Build Coastguard Workerclass will inherit no fields from it since the record expansion is done
141*9880d681SAndroid Build Coastguard Workerwhen the record is parsed.
142*9880d681SAndroid Build Coastguard Worker
143*9880d681SAndroid Build Coastguard Worker.. productionlist::
144*9880d681SAndroid Build Coastguard Worker   TemplateArgList: "<" `Declaration` ("," `Declaration`)* ">"
145*9880d681SAndroid Build Coastguard Worker
146*9880d681SAndroid Build Coastguard WorkerDeclarations
147*9880d681SAndroid Build Coastguard Worker------------
148*9880d681SAndroid Build Coastguard Worker
149*9880d681SAndroid Build Coastguard Worker.. Omitting mention of arcane "field" prefix to discourage its use.
150*9880d681SAndroid Build Coastguard Worker
151*9880d681SAndroid Build Coastguard WorkerThe declaration syntax is pretty much what you would expect as a C++
152*9880d681SAndroid Build Coastguard Workerprogrammer.
153*9880d681SAndroid Build Coastguard Worker
154*9880d681SAndroid Build Coastguard Worker.. productionlist::
155*9880d681SAndroid Build Coastguard Worker   Declaration: `Type` `TokIdentifier` ["=" `Value`]
156*9880d681SAndroid Build Coastguard Worker
157*9880d681SAndroid Build Coastguard WorkerIt assigns the value to the identifier.
158*9880d681SAndroid Build Coastguard Worker
159*9880d681SAndroid Build Coastguard WorkerTypes
160*9880d681SAndroid Build Coastguard Worker-----
161*9880d681SAndroid Build Coastguard Worker
162*9880d681SAndroid Build Coastguard Worker.. productionlist::
163*9880d681SAndroid Build Coastguard Worker   Type: "string" | "code" | "bit" | "int" | "dag"
164*9880d681SAndroid Build Coastguard Worker       :| "bits" "<" `TokInteger` ">"
165*9880d681SAndroid Build Coastguard Worker       :| "list" "<" `Type` ">"
166*9880d681SAndroid Build Coastguard Worker       :| `ClassID`
167*9880d681SAndroid Build Coastguard Worker   ClassID: `TokIdentifier`
168*9880d681SAndroid Build Coastguard Worker
169*9880d681SAndroid Build Coastguard WorkerBoth ``string`` and ``code`` correspond to the string type; the difference
170*9880d681SAndroid Build Coastguard Workeris purely to indicate programmer intention.
171*9880d681SAndroid Build Coastguard Worker
172*9880d681SAndroid Build Coastguard WorkerThe :token:`ClassID` must identify a class that has been previously
173*9880d681SAndroid Build Coastguard Workerdeclared or defined.
174*9880d681SAndroid Build Coastguard Worker
175*9880d681SAndroid Build Coastguard WorkerValues
176*9880d681SAndroid Build Coastguard Worker------
177*9880d681SAndroid Build Coastguard Worker
178*9880d681SAndroid Build Coastguard Worker.. productionlist::
179*9880d681SAndroid Build Coastguard Worker   Value: `SimpleValue` `ValueSuffix`*
180*9880d681SAndroid Build Coastguard Worker   ValueSuffix: "{" `RangeList` "}"
181*9880d681SAndroid Build Coastguard Worker              :| "[" `RangeList` "]"
182*9880d681SAndroid Build Coastguard Worker              :| "." `TokIdentifier`
183*9880d681SAndroid Build Coastguard Worker   RangeList: `RangePiece` ("," `RangePiece`)*
184*9880d681SAndroid Build Coastguard Worker   RangePiece: `TokInteger`
185*9880d681SAndroid Build Coastguard Worker             :| `TokInteger` "-" `TokInteger`
186*9880d681SAndroid Build Coastguard Worker             :| `TokInteger` `TokInteger`
187*9880d681SAndroid Build Coastguard Worker
188*9880d681SAndroid Build Coastguard WorkerThe peculiar last form of :token:`RangePiece` is due to the fact that the
189*9880d681SAndroid Build Coastguard Worker"``-``" is included in the :token:`TokInteger`, hence ``1-5`` gets lexed as
190*9880d681SAndroid Build Coastguard Workertwo consecutive :token:`TokInteger`'s, with values ``1`` and ``-5``,
191*9880d681SAndroid Build Coastguard Workerinstead of "1", "-", and "5".
192*9880d681SAndroid Build Coastguard WorkerThe :token:`RangeList` can be thought of as specifying "list slice" in some
193*9880d681SAndroid Build Coastguard Workercontexts.
194*9880d681SAndroid Build Coastguard Worker
195*9880d681SAndroid Build Coastguard Worker
196*9880d681SAndroid Build Coastguard Worker:token:`SimpleValue` has a number of forms:
197*9880d681SAndroid Build Coastguard Worker
198*9880d681SAndroid Build Coastguard Worker
199*9880d681SAndroid Build Coastguard Worker.. productionlist::
200*9880d681SAndroid Build Coastguard Worker   SimpleValue: `TokIdentifier`
201*9880d681SAndroid Build Coastguard Worker
202*9880d681SAndroid Build Coastguard WorkerThe value will be the variable referenced by the identifier. It can be one
203*9880d681SAndroid Build Coastguard Workerof:
204*9880d681SAndroid Build Coastguard Worker
205*9880d681SAndroid Build Coastguard Worker.. The code for this is exceptionally abstruse. These examples are a
206*9880d681SAndroid Build Coastguard Worker   best-effort attempt.
207*9880d681SAndroid Build Coastguard Worker
208*9880d681SAndroid Build Coastguard Worker* name of a ``def``, such as the use of ``Bar`` in::
209*9880d681SAndroid Build Coastguard Worker
210*9880d681SAndroid Build Coastguard Worker     def Bar : SomeClass {
211*9880d681SAndroid Build Coastguard Worker       int X = 5;
212*9880d681SAndroid Build Coastguard Worker     }
213*9880d681SAndroid Build Coastguard Worker
214*9880d681SAndroid Build Coastguard Worker     def Foo {
215*9880d681SAndroid Build Coastguard Worker       SomeClass Baz = Bar;
216*9880d681SAndroid Build Coastguard Worker     }
217*9880d681SAndroid Build Coastguard Worker
218*9880d681SAndroid Build Coastguard Worker* value local to a ``def``, such as the use of ``Bar`` in::
219*9880d681SAndroid Build Coastguard Worker
220*9880d681SAndroid Build Coastguard Worker     def Foo {
221*9880d681SAndroid Build Coastguard Worker       int Bar = 5;
222*9880d681SAndroid Build Coastguard Worker       int Baz = Bar;
223*9880d681SAndroid Build Coastguard Worker     }
224*9880d681SAndroid Build Coastguard Worker
225*9880d681SAndroid Build Coastguard Worker* a template arg of a ``class``, such as the use of ``Bar`` in::
226*9880d681SAndroid Build Coastguard Worker
227*9880d681SAndroid Build Coastguard Worker     class Foo<int Bar> {
228*9880d681SAndroid Build Coastguard Worker       int Baz = Bar;
229*9880d681SAndroid Build Coastguard Worker     }
230*9880d681SAndroid Build Coastguard Worker
231*9880d681SAndroid Build Coastguard Worker* value local to a ``multiclass``, such as the use of ``Bar`` in::
232*9880d681SAndroid Build Coastguard Worker
233*9880d681SAndroid Build Coastguard Worker     multiclass Foo {
234*9880d681SAndroid Build Coastguard Worker       int Bar = 5;
235*9880d681SAndroid Build Coastguard Worker       int Baz = Bar;
236*9880d681SAndroid Build Coastguard Worker     }
237*9880d681SAndroid Build Coastguard Worker
238*9880d681SAndroid Build Coastguard Worker* a template arg to a ``multiclass``, such as the use of ``Bar`` in::
239*9880d681SAndroid Build Coastguard Worker
240*9880d681SAndroid Build Coastguard Worker     multiclass Foo<int Bar> {
241*9880d681SAndroid Build Coastguard Worker       int Baz = Bar;
242*9880d681SAndroid Build Coastguard Worker     }
243*9880d681SAndroid Build Coastguard Worker
244*9880d681SAndroid Build Coastguard Worker.. productionlist::
245*9880d681SAndroid Build Coastguard Worker   SimpleValue: `TokInteger`
246*9880d681SAndroid Build Coastguard Worker
247*9880d681SAndroid Build Coastguard WorkerThis represents the numeric value of the integer.
248*9880d681SAndroid Build Coastguard Worker
249*9880d681SAndroid Build Coastguard Worker.. productionlist::
250*9880d681SAndroid Build Coastguard Worker   SimpleValue: `TokString`+
251*9880d681SAndroid Build Coastguard Worker
252*9880d681SAndroid Build Coastguard WorkerMultiple adjacent string literals are concatenated like in C/C++. The value
253*9880d681SAndroid Build Coastguard Workeris the concatenation of the strings.
254*9880d681SAndroid Build Coastguard Worker
255*9880d681SAndroid Build Coastguard Worker.. productionlist::
256*9880d681SAndroid Build Coastguard Worker   SimpleValue: `TokCodeFragment`
257*9880d681SAndroid Build Coastguard Worker
258*9880d681SAndroid Build Coastguard WorkerThe value is the string value of the code fragment.
259*9880d681SAndroid Build Coastguard Worker
260*9880d681SAndroid Build Coastguard Worker.. productionlist::
261*9880d681SAndroid Build Coastguard Worker   SimpleValue: "?"
262*9880d681SAndroid Build Coastguard Worker
263*9880d681SAndroid Build Coastguard Worker``?`` represents an "unset" initializer.
264*9880d681SAndroid Build Coastguard Worker
265*9880d681SAndroid Build Coastguard Worker.. productionlist::
266*9880d681SAndroid Build Coastguard Worker   SimpleValue: "{" `ValueList` "}"
267*9880d681SAndroid Build Coastguard Worker   ValueList: [`ValueListNE`]
268*9880d681SAndroid Build Coastguard Worker   ValueListNE: `Value` ("," `Value`)*
269*9880d681SAndroid Build Coastguard Worker
270*9880d681SAndroid Build Coastguard WorkerThis represents a sequence of bits, as would be used to initialize a
271*9880d681SAndroid Build Coastguard Worker``bits<n>`` field (where ``n`` is the number of bits).
272*9880d681SAndroid Build Coastguard Worker
273*9880d681SAndroid Build Coastguard Worker.. productionlist::
274*9880d681SAndroid Build Coastguard Worker   SimpleValue: `ClassID` "<" `ValueListNE` ">"
275*9880d681SAndroid Build Coastguard Worker
276*9880d681SAndroid Build Coastguard WorkerThis generates a new anonymous record definition (as would be created by an
277*9880d681SAndroid Build Coastguard Workerunnamed ``def`` inheriting from the given class with the given template
278*9880d681SAndroid Build Coastguard Workerarguments) and the value is the value of that record definition.
279*9880d681SAndroid Build Coastguard Worker
280*9880d681SAndroid Build Coastguard Worker.. productionlist::
281*9880d681SAndroid Build Coastguard Worker   SimpleValue: "[" `ValueList` "]" ["<" `Type` ">"]
282*9880d681SAndroid Build Coastguard Worker
283*9880d681SAndroid Build Coastguard WorkerA list initializer. The optional :token:`Type` can be used to indicate a
284*9880d681SAndroid Build Coastguard Workerspecific element type, otherwise the element type will be deduced from the
285*9880d681SAndroid Build Coastguard Workergiven values.
286*9880d681SAndroid Build Coastguard Worker
287*9880d681SAndroid Build Coastguard Worker.. The initial `DagArg` of the dag must start with an identifier or
288*9880d681SAndroid Build Coastguard Worker   !cast, but this is more of an implementation detail and so for now just
289*9880d681SAndroid Build Coastguard Worker   leave it out.
290*9880d681SAndroid Build Coastguard Worker
291*9880d681SAndroid Build Coastguard Worker.. productionlist::
292*9880d681SAndroid Build Coastguard Worker   SimpleValue: "(" `DagArg` `DagArgList` ")"
293*9880d681SAndroid Build Coastguard Worker   DagArgList: `DagArg` ("," `DagArg`)*
294*9880d681SAndroid Build Coastguard Worker   DagArg: `Value` [":" `TokVarName`] | `TokVarName`
295*9880d681SAndroid Build Coastguard Worker
296*9880d681SAndroid Build Coastguard WorkerThe initial :token:`DagArg` is called the "operator" of the dag.
297*9880d681SAndroid Build Coastguard Worker
298*9880d681SAndroid Build Coastguard Worker.. productionlist::
299*9880d681SAndroid Build Coastguard Worker   SimpleValue: `BangOperator` ["<" `Type` ">"] "(" `ValueListNE` ")"
300*9880d681SAndroid Build Coastguard Worker
301*9880d681SAndroid Build Coastguard WorkerBodies
302*9880d681SAndroid Build Coastguard Worker------
303*9880d681SAndroid Build Coastguard Worker
304*9880d681SAndroid Build Coastguard Worker.. productionlist::
305*9880d681SAndroid Build Coastguard Worker   ObjectBody: `BaseClassList` `Body`
306*9880d681SAndroid Build Coastguard Worker   BaseClassList: [":" `BaseClassListNE`]
307*9880d681SAndroid Build Coastguard Worker   BaseClassListNE: `SubClassRef` ("," `SubClassRef`)*
308*9880d681SAndroid Build Coastguard Worker   SubClassRef: (`ClassID` | `MultiClassID`) ["<" `ValueList` ">"]
309*9880d681SAndroid Build Coastguard Worker   DefmID: `TokIdentifier`
310*9880d681SAndroid Build Coastguard Worker
311*9880d681SAndroid Build Coastguard WorkerThe version with the :token:`MultiClassID` is only valid in the
312*9880d681SAndroid Build Coastguard Worker:token:`BaseClassList` of a ``defm``.
313*9880d681SAndroid Build Coastguard WorkerThe :token:`MultiClassID` should be the name of a ``multiclass``.
314*9880d681SAndroid Build Coastguard Worker
315*9880d681SAndroid Build Coastguard Worker.. put this somewhere else
316*9880d681SAndroid Build Coastguard Worker
317*9880d681SAndroid Build Coastguard WorkerIt is after parsing the base class list that the "let stack" is applied.
318*9880d681SAndroid Build Coastguard Worker
319*9880d681SAndroid Build Coastguard Worker.. productionlist::
320*9880d681SAndroid Build Coastguard Worker   Body: ";" | "{" BodyList "}"
321*9880d681SAndroid Build Coastguard Worker   BodyList: BodyItem*
322*9880d681SAndroid Build Coastguard Worker   BodyItem: `Declaration` ";"
323*9880d681SAndroid Build Coastguard Worker           :| "let" `TokIdentifier` [`RangeList`] "=" `Value` ";"
324*9880d681SAndroid Build Coastguard Worker
325*9880d681SAndroid Build Coastguard WorkerThe ``let`` form allows overriding the value of an inherited field.
326*9880d681SAndroid Build Coastguard Worker
327*9880d681SAndroid Build Coastguard Worker``def``
328*9880d681SAndroid Build Coastguard Worker-------
329*9880d681SAndroid Build Coastguard Worker
330*9880d681SAndroid Build Coastguard Worker.. TODO::
331*9880d681SAndroid Build Coastguard Worker   There can be pastes in the names here, like ``#NAME#``. Look into that
332*9880d681SAndroid Build Coastguard Worker   and document it (it boils down to ParseIDValue with IDParseMode ==
333*9880d681SAndroid Build Coastguard Worker   ParseNameMode). ParseObjectName calls into the general ParseValue, with
334*9880d681SAndroid Build Coastguard Worker   the only different from "arbitrary expression parsing" being IDParseMode
335*9880d681SAndroid Build Coastguard Worker   == Mode.
336*9880d681SAndroid Build Coastguard Worker
337*9880d681SAndroid Build Coastguard Worker.. productionlist::
338*9880d681SAndroid Build Coastguard Worker   Def: "def" `TokIdentifier` `ObjectBody`
339*9880d681SAndroid Build Coastguard Worker
340*9880d681SAndroid Build Coastguard WorkerDefines a record whose name is given by the :token:`TokIdentifier`. The
341*9880d681SAndroid Build Coastguard Workerfields of the record are inherited from the base classes and defined in the
342*9880d681SAndroid Build Coastguard Workerbody.
343*9880d681SAndroid Build Coastguard Worker
344*9880d681SAndroid Build Coastguard WorkerSpecial handling occurs if this ``def`` appears inside a ``multiclass`` or
345*9880d681SAndroid Build Coastguard Workera ``foreach``.
346*9880d681SAndroid Build Coastguard Worker
347*9880d681SAndroid Build Coastguard Worker``defm``
348*9880d681SAndroid Build Coastguard Worker--------
349*9880d681SAndroid Build Coastguard Worker
350*9880d681SAndroid Build Coastguard Worker.. productionlist::
351*9880d681SAndroid Build Coastguard Worker   Defm: "defm" `TokIdentifier` ":" `BaseClassListNE` ";"
352*9880d681SAndroid Build Coastguard Worker
353*9880d681SAndroid Build Coastguard WorkerNote that in the :token:`BaseClassList`, all of the ``multiclass``'s must
354*9880d681SAndroid Build Coastguard Workerprecede any ``class``'s that appear.
355*9880d681SAndroid Build Coastguard Worker
356*9880d681SAndroid Build Coastguard Worker``foreach``
357*9880d681SAndroid Build Coastguard Worker-----------
358*9880d681SAndroid Build Coastguard Worker
359*9880d681SAndroid Build Coastguard Worker.. productionlist::
360*9880d681SAndroid Build Coastguard Worker   Foreach: "foreach" `Declaration` "in" "{" `Object`* "}"
361*9880d681SAndroid Build Coastguard Worker          :| "foreach" `Declaration` "in" `Object`
362*9880d681SAndroid Build Coastguard Worker
363*9880d681SAndroid Build Coastguard WorkerThe value assigned to the variable in the declaration is iterated over and
364*9880d681SAndroid Build Coastguard Workerthe object or object list is reevaluated with the variable set at each
365*9880d681SAndroid Build Coastguard Workeriterated value.
366*9880d681SAndroid Build Coastguard Worker
367*9880d681SAndroid Build Coastguard WorkerTop-Level ``let``
368*9880d681SAndroid Build Coastguard Worker-----------------
369*9880d681SAndroid Build Coastguard Worker
370*9880d681SAndroid Build Coastguard Worker.. productionlist::
371*9880d681SAndroid Build Coastguard Worker   Let:  "let" `LetList` "in" "{" `Object`* "}"
372*9880d681SAndroid Build Coastguard Worker      :| "let" `LetList` "in" `Object`
373*9880d681SAndroid Build Coastguard Worker   LetList: `LetItem` ("," `LetItem`)*
374*9880d681SAndroid Build Coastguard Worker   LetItem: `TokIdentifier` [`RangeList`] "=" `Value`
375*9880d681SAndroid Build Coastguard Worker
376*9880d681SAndroid Build Coastguard WorkerThis is effectively equivalent to ``let`` inside the body of a record
377*9880d681SAndroid Build Coastguard Workerexcept that it applies to multiple records at a time. The bindings are
378*9880d681SAndroid Build Coastguard Workerapplied at the end of parsing the base classes of a record.
379*9880d681SAndroid Build Coastguard Worker
380*9880d681SAndroid Build Coastguard Worker``multiclass``
381*9880d681SAndroid Build Coastguard Worker--------------
382*9880d681SAndroid Build Coastguard Worker
383*9880d681SAndroid Build Coastguard Worker.. productionlist::
384*9880d681SAndroid Build Coastguard Worker   MultiClass: "multiclass" `TokIdentifier` [`TemplateArgList`]
385*9880d681SAndroid Build Coastguard Worker             : [":" `BaseMultiClassList`] "{" `MultiClassObject`+ "}"
386*9880d681SAndroid Build Coastguard Worker   BaseMultiClassList: `MultiClassID` ("," `MultiClassID`)*
387*9880d681SAndroid Build Coastguard Worker   MultiClassID: `TokIdentifier`
388*9880d681SAndroid Build Coastguard Worker   MultiClassObject: `Def` | `Defm` | `Let` | `Foreach`
389