# `compounddef` element reading.
module doxml::compounddef
-import entitydef
+import memberdef
+import doxyname
+import more_collections
# Processes the content of a `compounddef` element.
class CompoundDefListener
super EntityDefListener
+ # The defined compound.
var compound: Compound is writable, noinit
+ private var memberdef: MemberDefListener is noinit
+ private var param_listener: TypeParamListener is noinit
+
+ # Default attributes for members in the current section.
+ private var member_defaults: MemberDefaults is noinit
+
+ # For each section kind, default attributes for member in that section.
+ private var section_kinds: DefaultMap[String, MemberDefaults] is noinit
+
# Attributes of the current `<basecompoundref>` element.
init do
super
+ var defaults = new MemberDefaults("public", false, false)
+
+ memberdef = new MemberDefListener(reader, self)
+ param_listener = new TypeParamListener(reader, self)
+
+ member_defaults = defaults
+ section_kinds = new DefaultMap[String, MemberDefaults](defaults)
+
+ # public
+ section_kinds["public-type"] = defaults
+ section_kinds["public-func"] = defaults
+ section_kinds["public-attrib"] = defaults
+ section_kinds["public-slot"] = defaults
+ # public static
+ defaults = new MemberDefaults("public", true, false)
+ section_kinds["public-static-func"] = defaults
+ section_kinds["public-static-attrib"] = defaults
+ # Not scoped => public static
+ section_kinds["signal"] = defaults
+ section_kinds["dcop-func"] = defaults
+ section_kinds["property"] = defaults
+ section_kinds["event"] = defaults
+ section_kinds["define"] = defaults
+ section_kinds["typedef"] = defaults
+ section_kinds["enum"] = defaults
+ section_kinds["func"] = defaults
+ section_kinds["var"] = defaults
+
+ # protected
+ defaults = new MemberDefaults("protected", false, false)
+ section_kinds["protected-type"] = defaults
+ section_kinds["protected-func"] = defaults
+ section_kinds["protected-attrib"] = defaults
+ section_kinds["protected-slot"] = defaults
+ # protected static
+ defaults = new MemberDefaults("protected", true, false)
+ section_kinds["protected-static-func"] = defaults
+ section_kinds["protected-static-attrib"] = defaults
+
+ # package
+ defaults = new MemberDefaults("package", false, false)
+ section_kinds["package-type"] = defaults
+ section_kinds["package-func"] = defaults
+ section_kinds["package-attrib"] = defaults
+ # package static
+ defaults = new MemberDefaults("package", true, false)
+ section_kinds["package-static-func"] = defaults
+ section_kinds["package-static-attrib"] = defaults
+
+ # private
+ defaults = new MemberDefaults("private", false, false)
+ section_kinds["private-type"] = defaults
+ section_kinds["private-func"] = defaults
+ section_kinds["private-attrib"] = defaults
+ section_kinds["private-slot"] = defaults
+ # private static
+ defaults = new MemberDefaults("private", true, false)
+ section_kinds["private-static-func"] = defaults
+ section_kinds["private-static-attrib"] = defaults
+
+ # Special sections.
+ # TODO Do something these sections.
+ defaults = new MemberDefaults("public", true, true)
+ section_kinds["related"] = defaults
+ section_kinds["user-defined"] = defaults
+ # TODO Determine what `friend` and `prototype` mean.
end
redef fun entity: Entity do return compound
redef fun start_dox_element(local_name: String, atts: Attributes) do
- if ["compoundname", "innerclass", "innernamespace"].has(local_name) then
+ if "compoundname" == local_name then
text.listen_until(dox_uri, local_name)
- if ["innerclass", "innernamespace"].has(local_name) then
- refid = get_required(atts, "refid")
- end
- else if "basecompoundref" == local_name then
- refid = get_optional(atts, "refid", "")
+ else if ["innerclass", "innernamespace", "basecompoundref"].has(local_name) then
prot = get_optional(atts, "prot", "")
- virt = get_optional(atts, "virt", "")
text.listen_until(dox_uri, local_name)
- else
+ if "basecompoundref" == local_name then
+ refid = get_optional(atts, "refid", "")
+ virt = get_optional(atts, "virt", "")
+ else
+ refid = get_required(atts, "refid")
+ end
+ else if "memberdef" == local_name then
+ read_member(atts)
+ else if "sectiondef" == local_name then
+ member_defaults = section_kinds[get_required(atts, "kind")]
+ if member_defaults.is_special then
+ super # TODO
+ end
+ else if "param" == local_name then
+ param_listener.listen_until(dox_uri, local_name)
+ else if "templateparamlist" != local_name then
super
end
end
redef fun end_dox_element(local_name: String) do
- if local_name == "compounddef" then
- compound.put_in_graph
- else if local_name == "compoundname" then
- compound.full_name = text.to_s
- else if local_name == "innerclass" then
- compound.declare_class(refid, text.to_s)
- else if local_name == "innernamespace" then
+ if "compoundname" == local_name then
+ compound.doxyname = text.to_s
+ else if "innerclass" == local_name then
+ compound.doxygen_declare_class(refid, text.to_s, prot)
+ else if "innernamespace" == local_name then
compound.declare_namespace(refid, text.to_s)
- else if local_name == "basecompoundref" then
+ else if "memberdef" == local_name then
+ if not (memberdef.member isa UnknownMember) then
+ compound.declare_member(memberdef.member)
+ end
+ else if "basecompoundref" == local_name then
compound.declare_super(refid, text.to_s, prot, virt)
+ else if "param" == local_name and compound isa ClassCompound then
+ compound.as(ClassCompound).add_type_parameter(param_listener.parameter)
else
super
end
end
+
+ private fun read_member(atts: Attributes) do
+ var kind = get_required(atts, "kind")
+
+ create_member(kind)
+ memberdef.member.model_id = get_required(atts, "id")
+ memberdef.member.visibility = get_optional(atts, "prot",
+ member_defaults.visibility)
+ end
+
+ private fun create_member(kind: String) do
+ if kind == "variable" then
+ memberdef.member = new Attribute(compound.graph)
+ else if kind == "function" then
+ memberdef.member = new Method(compound.graph)
+ else
+ memberdef.member = new UnknownMember(compound.graph)
+ noop.listen_until(dox_uri, "memberdef")
+ return
+ end
+ memberdef.listen_until(dox_uri, "memberdef")
+ end
+end
+
+# Default attributes for members in the current section.
+private class MemberDefaults
+ var visibility: String
+ var is_static: Bool
+ var is_special: Bool
end