File: asciidoc.tmpl

package info (click to toggle)
android-platform-frameworks-native 1%3A7.0.0%2Br33-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 15,036 kB
  • sloc: cpp: 126,962; xml: 48,615; ansic: 18,880; java: 4,991; python: 1,324; sh: 187; asm: 105; perl: 74; makefile: 28
file content (151 lines) | stat: -rw-r--r-- 5,155 bytes parent folder | download | duplicates (5)
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
{{Include "vulkan_common.tmpl"}}
{{if not (Global "AsciiDocPath")}}{{Global "AsciiDocPath" "../../doc/specs/vulkan/"}}{{end}}
{{$ | Macro "AsciiDoc.Main"}}


{{/*
-------------------------------------------------------------------------------
  AsciiDoc generation main entry point.
-------------------------------------------------------------------------------
*/}}
{{define "AsciiDoc.Main"}}
  {{$docPath := Global "AsciiDocPath"}}

  {{/* Generate AsciiDoc files for API enums and bitfields (flags). */}}
  {{range $e := $.Enums}}
    {{if not $e.IsBitfield}}
      {{$filename := print $docPath "enums/" (Macro "EnumName" $e) ".txt"}}
      {{Macro "AsciiDoc.Write" "Code" (Macro "AsciiDoc.Enum" $e) "File" $filename}}
    {{else}}
      {{$filename := print $docPath "flags/" (Macro "EnumName" $e) ".txt"}}
      {{Macro "AsciiDoc.Write" "Code" (Macro "AsciiDoc.Flag" $e) "File" $filename}}
    {{end}}
  {{end}}

  {{/* Generate AsciiDoc files for API commands (protos). */}}
  {{range $f := (AllCommands $)}}
    {{if not (GetAnnotation $f "pfn")}}
      {{$filename := print $docPath "protos/" $f.Name ".txt"}}
      {{Macro "AsciiDoc.Write" "Code" (Macro "AsciiDoc.Proto" $f) "File" $filename}}
    {{end}}
  {{end}}

  {{/* Generate AsciiDoc files for API structs. */}}
  {{range $c := $.Classes}}
    {{if not (GetAnnotation $c "internal")}}
      {{$filename := print $docPath "structs/" $c.Name ".txt"}}
      {{Macro "AsciiDoc.Write" "Code" (Macro "AsciiDoc.Struct" $c) "File" $filename}}
    {{end}}
  {{end}}
{{end}}


{{/*
-------------------------------------------------------------------------------
  Emits the AsciiDoc contents for the specified API enum.
-------------------------------------------------------------------------------
*/}}
{{define "AsciiDoc.Enum"}}
  {{AssertType $ "Enum"}}

  {{Macro "Docs" $.Docs}}
  typedef enum {
    {{range $i, $e := $.Entries}}
      {{Macro "EnumEntry" $e}} = {{AsSigned $e.Value}}, {{Macro "Docs" $e.Docs}}
    {{end}}
  ΒΆ
    {{$name := Macro "EnumName" $ | TrimRight "ABCDEFGHIJKLMNOQRSTUVWXYZ" | SplitPascalCase | Upper | JoinWith "_"}}
    {{$first := Macro "EnumFirstEntry" $}}
    {{$last  := Macro "EnumLastEntry" $}}
    {{$name}}_BEGIN_RANGE = {{$first}},
    {{$name}}_END_RANGE = {{$last}},
    {{$name}}_NUM = ({{$last}} - {{$first}} + 1),
    {{$name}}_MAX_ENUM = 0x7FFFFFFF
  } {{Macro "EnumName" $}};
{{end}}


{{/*
-------------------------------------------------------------------------------
  Emits the AsciiDoc contents for the specified API bitfield.
-------------------------------------------------------------------------------
*/}}
{{define "AsciiDoc.Flag"}}
  {{AssertType $ "Enum"}}

  {{Macro "Docs" $.Docs}}
  typedef VkFlags {{Macro "EnumName" $}};
  {{if $.Entries}}
  typedef enum {
  {{range $e := $.Entries}}
    {{Macro "BitfieldEntryName" $e}} = {{printf "%#.8x" $e.Value}}, {{Macro "Docs" $e.Docs}}
  {{end}}
  } {{Macro "EnumName" $ | TrimRight "s"}}Bits;
  {{end}}
{{end}}



{{/*
-------------------------------------------------------------------------------
  Emits the AsciiDoc contents for the specified API class.
-------------------------------------------------------------------------------
*/}}
{{define "AsciiDoc.Struct"}}
  {{AssertType $ "Class"}}

  {{Macro "Docs" $.Docs}}
  typedef {{if GetAnnotation $ "union"}}union{{else}}struct{{end}} {
    {{range $f := $.Fields}}
      {{Node "Type" $f}} {{$f.Name}}{{Macro "ArrayPostfix" (TypeOf $f)}}; {{Macro "Docs" $f.Docs}}
    {{end}}
  } {{Macro "StructName" $}};
{{end}}


{{/*
-------------------------------------------------------------------------------
  Emits the AsciiDoc contents for the specified API function.
-------------------------------------------------------------------------------
*/}}
{{define "AsciiDoc.Proto"}}
  {{AssertType $ "Function"}}

  {{Macro "Docs" $.Docs}}
  {{Node "Type" $.Return}} VKAPI {{Macro "FunctionName" $}}({{Macro "Parameters" $}});
{{end}}


{{/*
-------------------------------------------------------------------------------
  Wraps the specified Code in AsciiDoc source tags then writes to the specified File.
-------------------------------------------------------------------------------
*/}}
{{define "AsciiDoc.Write"}}
  {{AssertType $.Code "string"}}
  {{AssertType $.File "string"}}

  {{$code := $.Code | Format (Global "clang-format")}}
  {{JoinWith "\n" (Macro "AsciiDoc.Header") $code (Macro "AsciiDoc.Footer") ""| Write $.File}}
{{end}}


{{/*
-------------------------------------------------------------------------------
  Emits an AsciiDoc source header.
-------------------------------------------------------------------------------
*/}}
{{define "AsciiDoc.Header"}}
[source,{basebackend@docbook:c++:cpp}]
------------------------------------------------------------------------------
{{end}}


{{/*
-------------------------------------------------------------------------------
  Emits an AsciiDoc source footer.
-------------------------------------------------------------------------------
*/}}
{{define "AsciiDoc.Footer"}}
------------------------------------------------------------------------------
{{end}}