/
AClassHeaderDeclIR.vm
118 lines (98 loc) · 2.59 KB
/
AClassHeaderDeclIR.vm
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
// The template for class header
#set( $cname = $node.getName())
#set( $cstructname = $String.format("%sCLASS",$cname))
#set( $cdefname = $String.format("CLASSES_%s_H_", $cname ) )
#ifndef $cdefname
\#define $cdefname
\#define VDM_CG
\#include "Vdm.h"
#foreach( $super in $node.getFlattenedSupers() )
\#include "$String.format("%s.h",$super.getName().toString())"
#end
//include types used in the class
#foreach( $typeName in $node.getIncludes() )
\#include "$String.format("%s.h",$typeName)"
#end
#[[
/* -------------------------------
*
* Quotes
*
--------------------------------- */
]]#
#foreach( $val in $node.getQuotes() )
#set($qn = $String.format("QUOTE_%S",$val.getName()))
#ifndef $qn
\#define $qn $val.getId()
#endif /* $qn */
#end
#[[
/* -------------------------------
*
* values / global const
*
--------------------------------- */
]]#
#foreach( $val in $node.getValues() )
extern TVP $val.getName();
#end
#[[
/* -------------------------------
*
* The class
*
--------------------------------- */
]]#
//class id
\#define $String.format("CLASS_ID_%s_ID %d",$cname, $CFormat.getClassId($cname))
\#define $String.format("%s struct %s*",$cstructname,$cname)
// The vtable ids
#foreach( $entry in $node.getVtable().getTable() )
\#define $String.format("CLASS_%s_%s %d",$cname,$entry.getKey(), $node.getVtable().getTable().indexOf($entry))
#end
struct $cname
{
#foreach( $super in $node.getFlattenedSupers() )
$CFormat.format($super.getState())
#end
$CFormat.format($node.getState())
};
#[[
/* -------------------------------
*
* Constructors
*
--------------------------------- */
]]#
#foreach( $method in $node.getOriginalDef().getMethods() )
#if($method.getIsConstructor())
$CFormat.formatSource($method)
$CFormat.format($method.getMethodType().getResult()) $method.getName()($CFormat.format($method.getFormalParams()).replace("this","this_"));
#end
#end
#[[
/* -------------------------------
*
* public access functions
*
--------------------------------- */
]]#
#foreach( $method in $node.getOriginalDef().getMethods() )
#if($CFormat.isPublic($method) && !$method.getIsConstructor())
$CFormat.format($method.getMethodType().getResult()) $method.getName()($CFormat.format($method.getFormalParams()).replace("this","this_"));
#end
#end
#[[
/* -------------------------------
*
* Internal
*
--------------------------------- */
]]#
void ${cname}_free_fields(${cstructname});
$cstructname ${cname}_Constructor(${cstructname});
#if(!$CFormat.isNull($node.getArrDMinit()))
$CFormat.format($node.getArrDMinit())
#end
##$CFormat.format($node.getArrDMinit())
#endif /* $cdefname */