1 //
2 // Copyright (c) 2006, Brian Frank and Andy Frank
3 // Licensed under the Academic Free License version 3.0
4 //
5 // History:
6 // 15 Sep 05 Brian Frank Creation
7 // 20 Aug 06 Brian Frank Ported from Java to Fan
8 //
9
10 **
11 ** AttrAsm provides support for assembling the attributes
12 ** table for types and slots.
13 **
14 class AttrAsm : CompilerSupport
15 {
16
17 //////////////////////////////////////////////////////////////////////////
18 // Construction
19 //////////////////////////////////////////////////////////////////////////
20
21 new make(Compiler compiler, FPod fpod)
22 : super(compiler)
23 {
24 this.fpod = fpod;
25 this.attrs = FAttr[,]
26 }
27
28 //////////////////////////////////////////////////////////////////////////
29 // Named Adds
30 //////////////////////////////////////////////////////////////////////////
31
32 Void sourceFile(Str source)
33 {
34 if (source == null) return
35 utf(FConst.SourceFileAttr, source)
36 }
37
38 Void lineNumber(Int line)
39 {
40 if (line == null || line == 0) return
41 u2(FConst.LineNumberAttr, line)
42 }
43
44 Void facets(Str:FacetDef facets)
45 {
46 if (facets == null || facets.isEmpty) return
47
48 buf := Buf.make
49 buf.writeI2(facets.size)
50 facets.each |FacetDef f|
51 {
52 buf.writeI2(fpod.addName(f.name))
53 try
54 {
55 buf.writeUtf(f.value.serialize)
56 }
57 catch (CompilerErr e)
58 {
59 err("Facet value is not serializable: '$f.name' ($e.message)", f.value.location)
60 }
61 }
62 add(FConst.FacetsAttr, buf)
63 }
64
65 //////////////////////////////////////////////////////////////////////////
66 // Generic Adds
67 //////////////////////////////////////////////////////////////////////////
68
69 Void utf(Str name, Str data)
70 {
71 buf := Buf.make
72 buf.writeUtf(data)
73 add(name, buf)
74 }
75
76 Void u2(Str name, Int data)
77 {
78 buf := Buf.make
79 buf.writeI2(data)
80 add(name, buf)
81 }
82
83 Void add(Str name, Buf data)
84 {
85 a := FAttr.make
86 a.name = fpod.addName(name)
87 a.data = data
88 attrs.add(a)
89 }
90
91 //////////////////////////////////////////////////////////////////////////
92 // Fields
93 //////////////////////////////////////////////////////////////////////////
94
95 FPod fpod
96 FAttr[] attrs
97
98 }
2 // Copyright (c) 2006, Brian Frank and Andy Frank
3 // Licensed under the Academic Free License version 3.0
4 //
5 // History:
6 // 15 Sep 05 Brian Frank Creation
7 // 20 Aug 06 Brian Frank Ported from Java to Fan
8 //
9
10 **
11 ** AttrAsm provides support for assembling the attributes
12 ** table for types and slots.
13 **
14 class AttrAsm : CompilerSupport
15 {
16
17 //////////////////////////////////////////////////////////////////////////
18 // Construction
19 //////////////////////////////////////////////////////////////////////////
20
21 new make(Compiler compiler, FPod fpod)
22 : super(compiler)
23 {
24 this.fpod = fpod;
25 this.attrs = FAttr[,]
26 }
27
28 //////////////////////////////////////////////////////////////////////////
29 // Named Adds
30 //////////////////////////////////////////////////////////////////////////
31
32 Void sourceFile(Str source)
33 {
34 if (source == null) return
35 utf(FConst.SourceFileAttr, source)
36 }
37
38 Void lineNumber(Int line)
39 {
40 if (line == null || line == 0) return
41 u2(FConst.LineNumberAttr, line)
42 }
43
44 Void facets(Str:FacetDef facets)
45 {
46 if (facets == null || facets.isEmpty) return
47
48 buf := Buf.make
49 buf.writeI2(facets.size)
50 facets.each |FacetDef f|
51 {
52 buf.writeI2(fpod.addName(f.name))
53 try
54 {
55 buf.writeUtf(f.value.serialize)
56 }
57 catch (CompilerErr e)
58 {
59 err("Facet value is not serializable: '$f.name' ($e.message)", f.value.location)
60 }
61 }
62 add(FConst.FacetsAttr, buf)
63 }
64
65 //////////////////////////////////////////////////////////////////////////
66 // Generic Adds
67 //////////////////////////////////////////////////////////////////////////
68
69 Void utf(Str name, Str data)
70 {
71 buf := Buf.make
72 buf.writeUtf(data)
73 add(name, buf)
74 }
75
76 Void u2(Str name, Int data)
77 {
78 buf := Buf.make
79 buf.writeI2(data)
80 add(name, buf)
81 }
82
83 Void add(Str name, Buf data)
84 {
85 a := FAttr.make
86 a.name = fpod.addName(name)
87 a.data = data
88 attrs.add(a)
89 }
90
91 //////////////////////////////////////////////////////////////////////////
92 // Fields
93 //////////////////////////////////////////////////////////////////////////
94
95 FPod fpod
96 FAttr[] attrs
97
98 }