Module: EasySwig::Query

Included in:
GeneratorUtil
Defined in:
lib/util/query.rb

Instance Method Summary collapse

Instance Method Details

#anonymous_enum?(enum) ⇒ Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/util/query.rb', line 131

def anonymous_enum?(enum)
  enum.basename =~ /_Enum\d*$/
end

#get_reference_type(type, klass) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/util/query.rb', line 4

def get_reference_type(type, klass)
if is_primitive?(type.name)
		return :ptr
	elsif type.name.end_with?('&')
		return :ref
	elsif type.name == 'std::string'
		return :str
	else
		looked_up = klass.lookup_node(type)
		return nil if looked_up.nil?
		if type.name.end_with?('*')
			if is_primitive?(looked_up.name)
				return :prim_ptr
			end
			return :ptr
		end
		if looked_up.class == Doxyparser::Enum
			return :ptr
		else
			return :val
		end
	end  
end

#is_operator?(name) ⇒ Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/util/query.rb', line 113

def is_operator?(name)
	name =~ /operator\W+/
end

#is_template?(typename) ⇒ Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/util/query.rb', line 109

def is_template?(typename)
	Doxyparser::Type.template?(typename)
end

#is_template_param?(typename, klass) ⇒ Boolean

Returns:

  • (Boolean)


102
103
104
105
106
107
# File 'lib/util/query.rb', line 102

def is_template_param?(typename, klass)
	class_template_params = klass.template_params.map{|tp| tp.declname}
	return if nested_typenames_for(typename).any?{ |t| 
		class_template_params.include?(t) 
	}
end

#lookup_typename(type, klass) ⇒ Object

Type should not have * & const



28
29
30
31
32
33
34
35
# File 'lib/util/query.rb', line 28

def lookup_typename(type, klass) # Type should not have * & const
	escaped_typename = escape_template(type.escaped_name)
  return type.escaped_name if escaped_typename.include?('::') || is_primitive?(escaped_typename)
  return type.escaped_name.gsub(escaped_typename, 'std::' + escaped_typename) if is_std?(escaped_typename)      
  lookedup = klass.lookup_node(type)
  return nil if lookedup.nil?
			lookedup.name
end

#method_has_blacklisted_types?(method) ⇒ Boolean

Returns:

  • (Boolean)


117
118
119
120
121
# File 'lib/util/query.rb', line 117

def method_has_blacklisted_types?(method)
  return true if type_is_blacklisted?(method)
  return true if method.params.any?{ |p| type_is_blacklisted?(p) }
  return false
end

#name_for_friend(typename, num_args = 0) ⇒ Object



96
97
98
99
100
# File 'lib/util/query.rb', line 96

def name_for_friend(typename, num_args = 0)
  return '_friend_' + typename if num_args == 0
  result = name_for_operator(typename, num_args)
  return result.nil? ? '_friend_' + typename : result
end

#name_for_operator(typename, num_args) ⇒ Object



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
# File 'lib/util/query.rb', line 55

def name_for_operator(typename, num_args)
  ret = case typename
    when 'operator+'
      return num_args == 2 ? '__add__' : '__pos__'
    when 'operator-'
      return num_args == 2 ? '__sub__' : '__neg__'
    when 'operator*'
      return '__mul__'
    when 'operator/'
      return '__div__'
    when 'operator%'
      return '__mod__'
    when 'operator<<'
      return '__lshift__'
    when 'operator>>'
      return '__rshift__'
    when 'operator&'
      return '__and__'
    when 'operator||'
      return '__or__'
    when 'operator^'
      return '__xor__'
    when 'operator~'
      return '__invert__'
    when 'operator<'
      return '__lt__'
    when 'operator<='
      return '__le__'
    when 'operator>'
      return '__gt__'
    when 'operator>='
      return '__ge__'
    when 'operator=='
      return '__eq__'
    when 'operator()'
      return '__call__'
  else
  return nil
  end
end

#name_for_template(template_name) ⇒ Object



49
50
51
52
53
# File 'lib/util/query.rb', line 49

def name_for_template(template_name)
		nested_typenames_for(template_name).map{ |typename|
			 del_prefix_class(typename.split(' ').join('')).capitalize 
		}.join('')
end

#nested_typenames_for(typename) ⇒ Object



37
38
39
# File 'lib/util/query.rb', line 37

def nested_typenames_for(typename) 
	Doxyparser::Type.nested_typenames(typename)
end

#no_public_constructors?(klass) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/util/query.rb', line 41

def no_public_constructors?(klass)
	klass.constructors(:public).empty? && !klass.constructors(:all).empty?
end

#no_public_destructors?(klass) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/util/query.rb', line 45

def no_public_destructors?(klass)
	klass.destructors(:public).empty? && !klass.destructors(:all).empty?
end

#type_is_blacklisted?(p) ⇒ Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/util/query.rb', line 123

def type_is_blacklisted?(p)
  return p.type.nested_typenames.any?{ |t| typename_is_blacklisted?(t)}
end

#typename_is_blacklisted?(typename) ⇒ Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/util/query.rb', line 127

def typename_is_blacklisted?(typename)
  return typename == 'multimap' || typename == 'std::multimap'
end