/
DocBookGenerator.scala
519 lines (505 loc) · 27.3 KB
/
DocBookGenerator.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
package org.bynar
import scala.xml.Elem
import org.bynar.versailles.Statement
import org.bynar.versailles.Variable
import org.bynar.versailles.Let
import org.bynar.versailles.VariableIdentity
import org.bynar.versailles.Def
import org.bynar.versailles.StringLiteral
import org.bynar.versailles.Application
import org.bynar.versailles.Block
import org.bynar.versailles.Irreversible
import scala.xml.Node
import scala.xml.XML
import org.bynar.versailles.Sequence
import org.bynar.versailles.Expression
import org.bynar.versailles.NumberLiteral
import org.bynar.versailles.Plus
import org.bynar.versailles.AnnotationKey
import org.bynar.versailles.Term
import org.bynar.versailles.Lambda
import org.bynar.versailles.Undefined
import org.bynar.versailles.OrElse
import org.bynar.versailles.Member
import org.bynar.versailles.BooleanLiteral
import org.bynar.versailles.InfiniteIndex
import org.bynar.versailles.IndexComposition
import scala.xml.Text
import org.bynar.versailles.OrElseValue
import org.bynar.versailles.RangeIndex
import org.bynar.versailles.Module
import org.bynar.versailles.Tuple
import org.bynar.versailles.Length
import org.bynar.versailles.SingletonIndex
import org.bynar.versailles.ZeroaryExpression
class DocBookGenerator(root1: Statement,
val offsetSizeColumnsIfPossible: Boolean = true,
val shortTables: Boolean = false) extends {
val simp = new Simplifier()
val pp = new TextPrettyPrinter()
} with org.bynar.versailles.DocBookGenerator(simp.simplifyStatement(root1, defaultContext, true)._1) {
import org.bynar.versailles.DocBookGenerator._
import org.bynar.versailles.TermImplicits._
import TermImplicits._
override def annotatePathInfo(item: Term, path: Seq[Symbol] = Seq()) {
item match {
case item: BitRecordComponent =>
item.putAnnotation(pathInfo, path)
annotatePathInfo(item.`type`, path :+ item.name)
case item: BitRegisterComponent =>
item.putAnnotation(pathInfo, path)
annotatePathInfo(item.`type`, path :+ item.name)
case item: BitUnionVariant =>
item.putAnnotation(pathInfo, path)
annotatePathInfo(item.`type`, path :+ item.name)
case item: EnumValue =>
item.putAnnotation(pathInfo, path)
annotatePathInfo(item.value, path :+ item.name)
case _ => super.annotatePathInfo(item, path)
}
}
def term2Xml(term: Term): Seq[Node] =
XML.loadString("<root>" + pp.prettyPrint(term) + "</root>").child
def briefFromXml(nodes: Seq[Node]): Seq[Node] = {
def briefHelper(nodes: Seq[Node]): Seq[Node] =
nodes.flatMap{
case n: Elem if n.attribute("role").map{ _.map{ _.text }.mkString("") }.getOrElse("") == "brief" =>
Seq(n)
case n: Elem =>
val children = briefHelper(n.child)
if (children.size > 0)
Seq(n.copy(child = children))
else
Seq()
case _ => Seq()
}
val result = briefHelper(nodes)
if (result.isEmpty)
nodes
else
result
}
override def generateMainDefinitions(item: Statement): Seq[Node] =
item match {
case d@Def(id, t: BitTypeExpression) =>
generateMainTypeDefinition(d)
case d@Def(id, Module(b)) =>
val path = d.identity.annotation(pathInfo).get :+ VariableIdentity.getName(d.identity)
val title = d.identity.annotation(titleInfo).getOrElse(niceTitle(path(path.size - 1)))
val descr = d.identity.annotation(descriptionInfo).map{ d =>
XML.loadString("<root>" + pp.prettyPrint(simp.simplify(
Block(root, Application(d, StringLiteral("it"))),
false, defaultContext
)._1) + "</root>").child }.getOrElse(Seq())
Seq(<section xml:id={ path.map{ _.name }.mkString(".") }>
<title>{ title }</title>
{ descr }
{ generateMainDefinitions(b) }
</section>)
case d@Def(id, v) =>
val path = d.identity.annotation(pathInfo).get :+ VariableIdentity.getName(d.identity)
val title = d.identity.annotation(titleInfo).getOrElse(niceTitle(path(path.size - 1)))
val descr = d.identity.annotation(descriptionInfo).map{ d =>
XML.loadString("<root>" + pp.prettyPrint(simp.simplify(
Block(root, Application(d, StringLiteral("it"))),
false, defaultContext
)._1) + "</root>").child }.getOrElse(Seq())
def functionDescr(t: Expression): (Seq[Seq[Node]], Seq[Node]) =
t match {
case t: Lambda =>
val (args, body) = functionDescr(t.body)
t.pattern match {
case Tuple(patterns@_*) =>
(patterns.map(p => <listitem><para>{ term2Xml(p) }</para></listitem>) ++ args, body)
case pattern =>
(<listitem><para>{ term2Xml(pattern) }</para></listitem> ++ args, body)
}
case t: BitTypeExpression => (Seq(), generateMainTypeDescription(t, title, path))
case t => (Seq(), <literallayout>{ term2Xml(simp.simplify(Block(root, t), true, defaultContext)._1) }</literallayout>)
}
val (args, body) = functionDescr(v)
Seq(<section xml:id={ path.map{ _.name }.mkString(".") }>
<title>{ title }</title>
{ descr }
{ if (args.nonEmpty) <para>Parameters:<orderedlist>{ args }</orderedlist></para> }
{ body }
</section>)
case _ => super.generateMainDefinitions(item)
}
def generateMainTypeDefinition(d: Def): Seq[Node] = {
val path = d.identity.annotation(pathInfo).get :+ VariableIdentity.getName(d.identity)
val title = d.identity.annotation(titleInfo).getOrElse(niceTitle(path(path.size - 1)))
val descr = d.identity.annotation(descriptionInfo).map{ d =>
XML.loadString("<root>" + pp.prettyPrint(simp.simplify(
Block(root, Application(d, StringLiteral("it"))),
false, defaultContext
)._1) + "</root>").child }.getOrElse(Seq())
Seq(<section xml:id={ path.map{ _.name }.mkString(".") }>
<title>{ title }</title>
{ descr }
{ generateMainTypeDescription(d.value.asInstanceOf[BitTypeExpression], title, path) }
</section>)
}
def generateTypeDescription(t: Expression): Seq[Node] = {
def isName(t: Expression): Boolean =
t match {
case Variable(_, false) => true
case Application(Member(_), t2) => isName(t2)
case _ => false
}
t match {
case BitFieldType(_) => Seq()
case t: BitRecordType =>
if (t.components.isEmpty)
<para>An empty data structure.</para>
else
Seq()
case t: BitRegisterType =>
if (t.components.isEmpty)
<para>An empty data structure.</para>
else
Seq()
case t: BitUnionType =>
if (t.variants.isEmpty)
<para>An impossible data structure.</para>
else
Seq()
case BitArrayType(ct, u) =>
<para>Elements are parsed until {
val it = VariableIdentity.setName(new VariableIdentity, 'it)
term2Xml(simp.simplify(Block(root, Application(u, Variable(it, false))), true, defaultContext)._1)
}.</para>
case WhereType(t, w) =>
generateTypeDescription(t) ++ whereTypeDescription(w)
case ConvertedType(t, c) =>
generateTypeDescription(t) ++ convertedTypeDescription(c)
case WrittenType(t, w) =>
generateTypeDescription(t) ++ writtenTypeDescription(w)
case InterpretedBitType(t, i) =>
generateTypeDescription(t) ++ interpretedTypeDescription(i)
case _ if isName(t) =>
<para>A { term2Xml(t) }.</para>
case Application(MemberContextedType(_), t) =>
generateTypeDescription(t)
case t@Application(_, _) =>
<para>A { term2Xml(t) }.</para>
case _ => throw new Exception
}
}
def generateMainTypeDescription(t: Expression, title: String, path: Seq[Symbol]): Seq[Node] = {
def generateBitWidthDescription(bw: Expression): Seq[Node] = {
val it = VariableIdentity.setName(new VariableIdentity, 'it)
<para>Bit width: { term2Xml(simp.simplify(Block(root, Application(bw, Variable(it, false))), true, defaultContext)._1) }</para>
}
def generateTableDescription(entries: Seq[TableEntry]): Seq[Node] = {
def isSimpleOrElseRange(e: Expression): Boolean =
e match {
case OrElseValue(a, b) => isSimpleOrElseRange(a) && isSimpleOrElseRange(b)
case Application(Application(RangeIndex(), _: ZeroaryExpression), _: ZeroaryExpression) => true
case Application(SingletonIndex(), _: ZeroaryExpression) => true
case Block(Let(BooleanLiteral(true), _), a) => isSimpleOrElseRange(a)
case _ => false
}
def firstIndex(e: Expression): Expression =
e match {
case e@OrElseValue(a, b) => e.copy(firstIndex(a), firstIndex(b))
case Application(Application(RangeIndex(), i), _) => i
case e: Block => e.copy(scope = firstIndex(e.scope))
}
def indexSize(e: Expression): Expression =
simp.simplify(Length()(e), true, Map())._1
def removeIfs1(expr: Expression): Seq[Expression] =
expr match {
case OrElseValue(a, b) =>
removeIfs1(a) ++ removeIfs1(b)
case Block(Let(BooleanLiteral(true), _), x) =>
removeIfs1(x)
case expr => Seq(expr)
}
def findLiterals(e: Expression): BigDecimal =
e match {
case NumberLiteral(v) => v
case Block(_, e) => findLiterals(e)
case Application(Application(RangeIndex(), a), b) => findLiterals(a)
case Application(Application(Plus(), a), b) => findLiterals(a)
case _ => 0
}
def removeIfs(e: Expression): Seq[Expression] =
removeIfs1(e).distinct
def generateTableRows(entries: Seq[TableEntry])(rowGen: TableEntry => Seq[Node]): Seq[Node] =
for (e <- entries;
val row = if (!shortTables || e.children.isEmpty || e.shortDoc.nonEmpty) rowGen(e) else Seq();
rows <- row ++ generateTableRows(e.children)(rowGen))
yield rows
if (offsetSizeColumnsIfPossible && entries.forall{ e => isSimpleOrElseRange(e.bitPosition) })
<table pgwide="1" xml:id={ path.map{ _.name }.mkString(".") + "-structure" }>
<title>Structure of a { title }</title>
<tgroup cols="4" colsep="1" rowsep="1">
<colspec colwidth="0.75*"/>
<colspec colwidth="0.75*"/>
<colspec colwidth="2*"/>
<colspec colwidth="3*"/>
<thead><row><entry>Offset</entry><entry>Size</entry><entry>Name</entry><entry>Description</entry></row></thead>
<tbody>{ generateTableRows(entries){ e =>
<row>
<entry xml:id={ if (!shortTables) (path ++ e.path).map{ _.name }.mkString(".") else null }
xreflabel={ if (!shortTables) e.title else null }>{ term2Xml(removeIfs(firstIndex(e.bitPosition)).sortBy(findLiterals _).reduce{ OrElseValue(_, _) }) }</entry>
<entry>{ term2Xml(removeIfs(indexSize(e.bitPosition)).sortBy(findLiterals _).reduce{ OrElseValue(_, _) }) }</entry>
<entry>{ if (shortTables)
<link linkend={ (path ++ e.path).map{ _.name }.mkString(".") }>{ pp.pathAsXml(e.path) }</link>
else
pp.pathAsXml(e.path) }</entry>
<entry>{ if (shortTables) e.shortDoc else e.doc }</entry>
</row>}
}</tbody>
</tgroup>
</table>
else
<table pgwide="1" xml:id={ path.map{ _.name }.mkString(".") + "-structure" }>
<title>Structure of a { title }</title>
<tgroup cols="3" colsep="1" rowsep="1">
<colspec colwidth="1.5*"/>
<colspec colwidth="2*"/>
<colspec colwidth="3*"/>
<thead><row><entry>Bit Position</entry><entry>Name</entry><entry>Description</entry></row></thead>
<tbody>{ generateTableRows(entries){ e =>
<row>
<entry xml:id={ if (!shortTables) (path ++ e.path).map{ _.name }.mkString(".") else null }
xreflabel={ if (!shortTables) e.title else null }>{ term2Xml(removeIfs(e.bitPosition).sortBy(findLiterals _).reduce{ OrElseValue(_, _) }) }</entry>
<entry>{ if (shortTables)
<link linkend={ (path ++ e.path).map{ _.name }.mkString(".") }>{ pp.pathAsXml(e.path) }</link>
else
pp.pathAsXml(e.path) }</entry>
<entry>{ if (shortTables) e.shortDoc else e.doc }</entry>
</row>}
}</tbody>
</tgroup>
</table>
}
def generateComponentDescription(entries: Seq[TableEntry]): Seq[Node] =
for (TableEntry(bp, p, t, sd, d, ch) <- entries;
rows <- <simplesect xml:id={ (path ++ p).map{ _.name }.mkString(".") }>
<title>{ t }</title>
<segmentedlist>
<segtitle>Name</segtitle><segtitle>Bit position</segtitle><segtitle>Bit width</segtitle>
<seglistitem><seg>{ pp.pathAsXml(p) }</seg><seg>{ term2Xml(bp) }</seg><seg>{ term2Xml(simp.simplify(Length()(bp), true, Map())._1) }</seg></seglistitem>
</segmentedlist>
{ d }
</simplesect> +: generateComponentDescription(ch))
yield rows
t match {
case BitRecordType(b) =>
val (entries, bw) = generateTableEntries(t, Lambda(Irreversible(), Undefined(), Application(InfiniteIndex(), NumberLiteral(0))), Seq())
if (entries.isEmpty)
<para>A <firstterm><type>{ title }</type></firstterm><indexterm><primary>{ title }</primary></indexterm> is an empty data structure.</para> ++
generateBitWidthDescription(bw)
else
<para>A <firstterm><type>{ title }</type></firstterm><indexterm><primary>{ title }</primary></indexterm>
is a data structure with the bit format in <xref linkend={ path.map{ _.name }.mkString(".") + "-structure" } xrefstyle="select:label"/>.</para> ++
generateBitWidthDescription(bw) ++
generateTableDescription(entries) ++
(if (shortTables) generateComponentDescription(entries) else Seq())
case BitRegisterType(bw, b) =>
val (entries, _) = generateTableEntries(t, Lambda(Irreversible(), Undefined(), rangeIndex(NumberLiteral(0), bw)), Seq())
if (entries.isEmpty)
<para>A <firstterm><type>{ title }</type></firstterm><indexterm><primary>{ title }</primary></indexterm> is an empty data structure.</para> ++
generateBitWidthDescription(Lambda(Irreversible(), Variable(new VariableIdentity(), true), bw))
else
<para>A <firstterm><type>{ title }</type></firstterm><indexterm><primary>{ title }</primary></indexterm>
is a data structure with the bit format in <xref linkend={ path.map{ _.name }.mkString(".") + "-structure" } xrefstyle="select:label"/>.</para> ++
generateBitWidthDescription(Lambda(Irreversible(), Variable(new VariableIdentity(), true), bw)) ++
generateTableDescription(entries) ++
(if (shortTables) generateComponentDescription(entries) else Seq())
case BitUnionType(b) =>
val (entries, bw) = generateTableEntries(t, Lambda(Irreversible(), Undefined(), Application(InfiniteIndex(), NumberLiteral(0))), Seq())
if (entries.isEmpty)
<para>A <firstterm><type>{ title }</type></firstterm><indexterm><primary>{ title }</primary></indexterm> is an impossible data structure.</para> ++
generateBitWidthDescription(bw)
else
<para>A <firstterm><type>{ title }</type></firstterm><indexterm><primary>{ title }</primary></indexterm>
is a data structure with the bit format in <xref linkend={ path.map{ _.name }.mkString(".") + "-structure" } xrefstyle="select:label"/>.</para> ++
generateBitWidthDescription(bw) ++
generateTableDescription(entries) ++
(if (shortTables) generateComponentDescription(entries) else Seq())
case BitFieldType(bw) =>
<para>A <firstterm><type>{ title }</type></firstterm><indexterm><primary>{ title }</primary></indexterm> is a bit field of {
val it = VariableIdentity.setName(new VariableIdentity, 'it)
term2Xml(simp.simplify(Block(root, Application(bw, Variable(it, false))), true, defaultContext)._1)
} bits.</para>
case WrittenType(t2, w) =>
generateMainTypeDescription(t2, title, path) ++ writtenTypeDescription(w)
case ConvertedType(t2, c) =>
generateMainTypeDescription(t2, title, path) ++ convertedTypeDescription(c)
case WhereType(t2, w) =>
generateMainTypeDescription(t2, title, path) ++ whereTypeDescription(w)
case InterpretedBitType(t2, i) =>
generateMainTypeDescription(t2, title, path) ++ interpretedTypeDescription(i)
case Variable(id, _) =>
<para>A <firstterm><type>{ title }</type></firstterm><indexterm><primary>{ title }</primary></indexterm> is an alias for { term2Xml(t) }.</para>
case _ => Seq()
}
}
def bitRange(bitWidth: Expression): Expression = {
val x = VariableIdentity.setName(new VariableIdentity, 'it)
Lambda(Irreversible(), Variable(x, true),
rangeIndex(0, bitWidth(Variable(x, false))))
}
def bitPermutationText(bitPermutation: Expression, bitPositions: Expression): Expression = {
simp.simplify(Block(root, {
val it = VariableIdentity.setName(new VariableIdentity, 'it)
Application(Application(IndexComposition(), Application(bitPositions, Variable(it, false))),
Application(bitPermutation, Variable(it, false)))
}), true, defaultContext)._1
}
case class TableEntry(val bitPosition: Expression,
val path: Seq[Symbol],
val title: String,
val shortDoc: Seq[Node],
val doc: Seq[Node],
val children: Seq[TableEntry])
def generateTableEntries(`type`: Expression,
bitPermutation: Expression,
tablePath: Seq[Symbol]): (Seq[TableEntry], Expression) =
`type` match {
case BitFieldType(bw) =>
(Seq(), bw)
case t: BitRecordType =>
t.foldComponents(Seq[TableEntry](), Lambda(Irreversible(), Undefined(), NumberLiteral(0))){
case (c, (rows, ofs)) =>
val bp = {
val x = VariableIdentity.setName(new VariableIdentity, '_)
Lambda(Irreversible(), Variable(x, true),
Application(Application(IndexComposition(), Application(InfiniteIndex(), Application(ofs, Variable(x, false)))),
Application(bitPermutation, Variable(x, false))))
}
val (rows2, bw) = generateTableEntries(c.`type`, bp, tablePath :+ c.name)
val t = c.annotation(titleInfo).getOrElse(niceTitle(c.name))
val dd = term2Xml(c.annotation(descriptionInfo).getOrElse(StringLiteral("")))
val d = dd ++ generateTypeDescription(c.`type`)
val row3 = TableEntry(bitPermutationText(bp, bitRange(bw)),
tablePath :+ c.name,
t,
briefFromXml(dd),
d,
rows2)
(rows :+ row3, {
val x = VariableIdentity.setName(new VariableIdentity, '_)
Lambda(Irreversible(), Variable(x, true), Application(Application(Plus(), Application(ofs, Variable(x, false))), Application(bw, Variable(x, false))))
})
}
case t: BitRegisterType =>
val bp = {
val x = VariableIdentity.setName(new VariableIdentity, '_)
Lambda(Irreversible(), Variable(x, true),
bitPermutation(Variable(x, false)) o rangeIndex(NumberLiteral(0), t.bitWidth))
}
(t.foldComponents(Seq[TableEntry]()){
case (c, rows) =>
val (rows2, _) = generateTableEntries(c.`type`, {
val x = VariableIdentity.setName(new VariableIdentity, '_)
Lambda(Irreversible(), Variable(x, true),
Application(Application(IndexComposition(), c.position), Application(bp, Variable(x, false))))
}, tablePath :+ c.name)
val t = c.annotation(titleInfo).getOrElse(niceTitle(c.name))
val dd = term2Xml(c.annotation(descriptionInfo).getOrElse(StringLiteral("")))
val d = dd ++ generateTypeDescription(c.`type`)
val row3 = TableEntry(bitPermutationText(bp, Lambda(Irreversible(), Undefined(), c.position)),
tablePath :+ c.name,
t,
briefFromXml(dd),
d,
rows2)
rows :+ row3
}, Lambda(Irreversible(), Undefined(), t.bitWidth))
case t: BitUnionType =>
t.foldVariants(Seq[TableEntry](), (Lambda(Irreversible(), Undefined(), Undefined()): Expression)){
case (v, (rows, bw)) =>
val (rows2, bw2) = generateTableEntries(v.`type`, bitPermutation, tablePath :+ v.name)
val t = v.annotation(titleInfo).getOrElse(niceTitle(v.name))
val dd = term2Xml(v.annotation(descriptionInfo).getOrElse(StringLiteral("")))
val d = dd ++ generateTypeDescription(v.`type`)
val row3 = TableEntry(bitPermutationText(bitPermutation, bitRange(bw2)),
tablePath :+ v.name,
t,
briefFromXml(dd),
d,
rows2)
(rows :+ row3, Application(Application(OrElse(), bw), bw2))
}
case BitArrayType(et, u) =>
(Seq(), Lambda(Irreversible(), Undefined(), StringLiteral("∞")))
case WrittenType(t, _) =>
generateTableEntries(t, bitPermutation, tablePath)
case ConvertedType(t, _) =>
generateTableEntries(t, bitPermutation, tablePath)
case WhereType(t, w) =>
val x = VariableIdentity.setName(new VariableIdentity, '_)
val (rows, bw) = generateTableEntries(t, bitPermutation /*Lambda(Irreversible(), Variable(x, true),
Block(Let(BooleanLiteral(true), Application(w, Variable(x, false))),
Application(bitPermutation, Variable(x, false))))*/, tablePath)
(rows, {
val x = VariableIdentity.setName(new VariableIdentity, '_)
Lambda(Irreversible(), Variable(x, true),
Block(Let(BooleanLiteral(true), Application(w, Variable(x, false))), Application(bw, Variable(x, false))))
})
// val x = VariableIdentity.setName(new VariableIdentity, '_)
// generateTableEntries(t,
// Lambda(Irreversible(), Variable(x, true),
// Block(Let(BooleanLiteral(true), Application(w, Variable(x, false))),
// Application(bitPermutation, Variable(x, false)))),
// tablePath)
case InterpretedBitType(t, _) =>
generateTableEntries(t, bitPermutation, tablePath)
case Application(MemberContextedType(p), t) =>
val (rows, bw) = generateTableEntries(t, {
val it = VariableIdentity.setName(new VariableIdentity, 'it)
Lambda(Irreversible(), Variable(it, true), Application(bitPermutation,
((Variable(it, false): Expression) /: p){ case (b, n) => Application(Member(n), b) }))
}, tablePath)
(rows, {
val it = VariableIdentity.setName(new VariableIdentity, 'it)
Lambda(Irreversible(), Variable(it, true), Application(bw,
((Variable(it, false): Expression) /: p){ case (b, n) => Application(Member(n), b) }))
})
case _ =>
(Seq(), Application(BitWidth(), `type`))
}
def whereTypeDescription(where: Expression): Seq[Node] =
<para>Only if { term2Xml(simp.simplify(Block(root, Application(where, Variable(VariableIdentity.setName(new VariableIdentity, 'it), false))), true, defaultContext)._1) }.</para>
def convertedTypeDescription(converted: Expression): Seq[Node] =
<para>Converted via { term2Xml(simp.simplify(Block(root, Application(converted, Variable(VariableIdentity.setName(new VariableIdentity, 'it), false))), true, defaultContext)._1) }.</para>
def writtenTypeDescription(written: Expression): Seq[Node] =
<para>Written as { term2Xml(simp.simplify(Block(root, Application(written, Variable(VariableIdentity.setName(new VariableIdentity, 'x), false))), true, defaultContext)._1) }.</para>
def interpretedTypeDescription(interpretation: BitTypeInterpretation): Seq[Node] =
interpretation match {
case i: EnumInterpretation =>
<para>May contain one of the following values:
<variablelist spacing="compact">
{ i.foldValues(Seq[Node]()){
case (v, ns) =>
ns :+
<varlistentry xml:id={ v.annotation(pathInfo).map{ p => (p :+ v.name).map{ _.name }.mkString(".") }.orNull }
xreflabel={ v.name.name }>
<term>{ v.name.name } = { term2Xml(v.value) }</term>
{ v.annotation(descriptionInfo) match {
case Some(d) => <listitem>{ term2Xml(d) }</listitem>
case None => <listitem><para/></listitem>
}}
</varlistentry>
}
}
</variablelist>
</para>
case i: UnitInterpretation =>
<para>Values are in {i.unit}.</para>
case i: FixedInterpretation =>
<para>Must contain the value {
val it = VariableIdentity.setName(new VariableIdentity, 'it)
term2Xml(simp.simplify(Block(root, Application(i.fixedValue, Variable(it, false))), true, defaultContext)._1)
}.</para>
case i: ContainingInterpretation =>
<para>Values are of the following structure.
{ generateTypeDescription(i.containedType) }
</para>
}
}