Module: Dub::MemberExtraction

Included in:
Klass, Namespace
Defined in:
lib/dub/member_extraction.rb,
lib/dub/klass.rb

Overview

This module is used by Namespace and Klass to extract member functions

Instance Method Summary collapse

Instance Method Details

#get_member(name, source = @members_hash) ⇒ Object

Lazy construction of members


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
# File 'lib/dub/member_extraction.rb', line 61

def get_member(name, source = @members_hash)
  if member_or_group = source[name]
    if member_or_group.kind_of?(Array)
      if member_or_group.first.kind_of?(Hpricot::Elem)
        list = []
        member_or_group.each do |m|
          list << make_member(name, m)
        end
        list.compact!
        if list == []
          member_or_group = nil
        elsif list.size == 1
          member_or_group = list.first
        else
          member_or_group = Dub::FunctionGroup.new(self)
          # set overloaded_index
          list.each_with_index do |m, i|
            m.overloaded_index = i + 1
            member_or_group << m
          end
        end
      end
    elsif member_or_group.kind_of?(Hpricot::Elem)
      source[name] = member_or_group = make_member(name, member_or_group)
    end
  end
  member_or_group
end

#ignore_member?(member) ⇒ Boolean

Returns:

  • (Boolean)

106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/dub/member_extraction.rb', line 106

def ignore_member?(member)
  return false if member.kind_of?(Klass)

  if !member.public? ||
     member.name =~ /^~/           || # do not build constructor
     member.name =~ /^operator/    || # no conversion operators
     member.has_complex_arguments? || # no complex arguments or return values
     member.has_array_arguments? ||
     member.vararg? ||
     member.original_signature =~ /void\s+\*/ # used to detect return value and parameters
    true # ignore
  elsif return_value = member.return_value
    if return_value.create_type == 'const char *'
      return false # do not ignore
    end
    return_value.type =~ />$/    || # no complex return types
    (return_value.is_native? && member.return_value.is_pointer?)
  else
    false # ok, do not ignore
  end
end

#insert_member(member, name, destination) ⇒ Object


30
31
32
33
34
35
36
37
38
# File 'lib/dub/member_extraction.rb', line 30

def insert_member(member, name, destination)
  if destination[name].kind_of?(Array)
    destination[name] << member
  elsif first_member = destination[name]
    destination[name] = [first_member, member]
  else
    destination[name] = member
  end
end

#make_member(name, member) ⇒ Object


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/dub/member_extraction.rb', line 90

def make_member(name, member)
  member = case member[:kind]
  when 'function', 'slot'
    Dub.logger.info "Building #{members_prefix}::#{name}"
    Function.new(self, name, member, members_prefix)
  when 'class'
    Dub.logger.info "Building #{members_prefix}::#{name}"
    Klass.new(self, name, member, members_prefix)
  else
    # not supported: ignore
    return nil
  end

  ignore_member?(member) ? nil : member
end

#member(name) ⇒ Object


40
41
42
# File 'lib/dub/member_extraction.rb', line 40

def member(name)
  get_member(name.to_s, @members_hash)
end

#members(ignore_list = []) ⇒ Object


44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dub/member_extraction.rb', line 44

def members(ignore_list = [])
  @members ||= begin
    list = []
    @members_hash.each do |name, member|
      next if ignore_list.include?(name)
      list << get_member(name)
    end
    list.compact!
    list.sort
  end
end

#members_prefixObject


11
12
13
# File 'lib/dub/member_extraction.rb', line 11

def members_prefix
  @name
end

#parse_membersObject


15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dub/member_extraction.rb', line 15

def parse_members
  @members_hash   = {}
  @t_members_hash = {}
  # TODO: template functions
  (@xml/'memberdef').each do |member|
    Dub.logger.info "Parsing #{(member/'name').innerHTML}"
    name = (member/"name").innerHTML
    if (member/'templateparamlist').first
      insert_member(member, name, @t_members_hash)
    else
      insert_member(member, name, @members_hash)
    end
  end
end

#template_method(name) ⇒ Object


56
57
58
# File 'lib/dub/member_extraction.rb', line 56

def template_method(name)
  get_member(name.to_s, @t_members_hash)
end