1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # `compounddef` element reading.
16 module doxml
::compounddef
20 import more_collections
22 # Processes the content of a `compounddef` element.
23 class CompoundDefListener
24 super EntityDefListener
26 # The defined compound.
27 var compound
: Compound is writable, noinit
29 private var memberdef
: MemberDefListener is noinit
30 private var param_listener
: TypeParamListener is noinit
32 # Default attributes for members in the current section.
33 private var member_defaults
: MemberDefaults is noinit
35 # For each section kind, default attributes for member in that section.
36 private var section_kinds
: DefaultMap[String, MemberDefaults] is noinit
39 # Attributes of the current `<basecompoundref>` element.
41 private var refid
= ""
48 var defaults
= new MemberDefaults("public", false, false)
50 memberdef
= new MemberDefListener(reader
, self)
51 param_listener
= new TypeParamListener(reader
, self)
53 member_defaults
= defaults
54 section_kinds
= new DefaultMap[String, MemberDefaults](defaults
)
57 section_kinds
["public-type"] = defaults
58 section_kinds
["public-func"] = defaults
59 section_kinds
["public-attrib"] = defaults
60 section_kinds
["public-slot"] = defaults
62 defaults
= new MemberDefaults("public", true, false)
63 section_kinds
["public-static-func"] = defaults
64 section_kinds
["public-static-attrib"] = defaults
65 # Not scoped => public static
66 section_kinds
["signal"] = defaults
67 section_kinds
["dcop-func"] = defaults
68 section_kinds
["property"] = defaults
69 section_kinds
["event"] = defaults
70 section_kinds
["define"] = defaults
71 section_kinds
["typedef"] = defaults
72 section_kinds
["enum"] = defaults
73 section_kinds
["func"] = defaults
74 section_kinds
["var"] = defaults
77 defaults
= new MemberDefaults("protected", false, false)
78 section_kinds
["protected-type"] = defaults
79 section_kinds
["protected-func"] = defaults
80 section_kinds
["protected-attrib"] = defaults
81 section_kinds
["protected-slot"] = defaults
83 defaults
= new MemberDefaults("protected", true, false)
84 section_kinds
["protected-static-func"] = defaults
85 section_kinds
["protected-static-attrib"] = defaults
88 defaults
= new MemberDefaults("package", false, false)
89 section_kinds
["package-type"] = defaults
90 section_kinds
["package-func"] = defaults
91 section_kinds
["package-attrib"] = defaults
93 defaults
= new MemberDefaults("package", true, false)
94 section_kinds
["package-static-func"] = defaults
95 section_kinds
["package-static-attrib"] = defaults
98 defaults
= new MemberDefaults("private", false, false)
99 section_kinds
["private-type"] = defaults
100 section_kinds
["private-func"] = defaults
101 section_kinds
["private-attrib"] = defaults
102 section_kinds
["private-slot"] = defaults
104 defaults
= new MemberDefaults("private", true, false)
105 section_kinds
["private-static-func"] = defaults
106 section_kinds
["private-static-attrib"] = defaults
109 # TODO Do something these sections.
110 defaults
= new MemberDefaults("public", true, true)
111 section_kinds
["related"] = defaults
112 section_kinds
["user-defined"] = defaults
113 # TODO Determine what `friend` and `prototype` mean.
116 redef fun entity
: Entity do return compound
118 redef fun start_dox_element
(local_name
: String, atts
: Attributes) do
119 if "compoundname" == local_name
then
120 text
.listen_until
(dox_uri
, local_name
)
121 else if ["innerclass", "innernamespace", "basecompoundref"].has
(local_name
) then
122 prot
= get_optional
(atts
, "prot", "")
123 text
.listen_until
(dox_uri
, local_name
)
124 if "basecompoundref" == local_name
then
125 refid
= get_optional
(atts
, "refid", "")
126 virt
= get_optional
(atts
, "virt", "")
128 refid
= get_required
(atts
, "refid")
130 else if "memberdef" == local_name
then
132 else if "sectiondef" == local_name
then
133 member_defaults
= section_kinds
[get_required
(atts
, "kind")]
134 if member_defaults
.is_special
then
137 else if "param" == local_name
then
138 param_listener
.listen_until
(dox_uri
, local_name
)
139 else if "templateparamlist" != local_name
then
144 redef fun end_dox_element
(local_name
: String) do
145 if "compoundname" == local_name
then
146 compound
.doxyname
= text
.to_s
147 else if "innerclass" == local_name
then
148 compound
.doxygen_declare_class
(refid
, text
.to_s
, prot
)
149 else if "innernamespace" == local_name
then
150 compound
.declare_namespace
(refid
, text
.to_s
)
151 else if "memberdef" == local_name
then
152 if not (memberdef
.member
isa UnknownMember) then
153 compound
.declare_member
(memberdef
.member
)
155 else if "basecompoundref" == local_name
then
156 compound
.declare_super
(refid
, text
.to_s
, prot
, virt
)
157 else if "param" == local_name
and compound
isa ClassCompound then
158 compound
.as(ClassCompound).add_type_parameter
(param_listener
.parameter
)
164 private fun read_member
(atts
: Attributes) do
165 var kind
= get_required
(atts
, "kind")
168 memberdef
.member
.model_id
= get_required
(atts
, "id")
169 memberdef
.member
.visibility
= get_optional
(atts
, "prot",
170 member_defaults
.visibility
)
173 private fun create_member
(kind
: String) do
174 if kind
== "variable" then
175 memberdef
.member
= new Attribute(compound
.graph
)
176 else if kind
== "function" then
177 memberdef
.member
= new Method(compound
.graph
)
179 memberdef
.member
= new UnknownMember(compound
.graph
)
180 noop
.listen_until
(dox_uri
, "memberdef")
183 memberdef
.listen_until
(dox_uri
, "memberdef")
187 # Default attributes for members in the current section.
188 private class MemberDefaults
189 var visibility
: String