Class: Clang::Rbind::Cursor

Inherits:
FFI::Struct
  • Object
show all
Defined in:
lib/rbind/clang/clang.rb,
lib/rbind/clang/clang_types.rb

Overview

A cursor representing some element in the abstract syntax tree for a translation unit.

The cursor abstraction unifies the different kinds of entities in a program–declaration, statements, expressions, references to declarations, etc.–under a single “cursor” abstraction with a common set of operations. Common operation for a cursor include: getting the physical location in a source file where the cursor points, getting the name associated with a cursor, and retrieving cursors for any child nodes of a particular cursor.

Cursors can be produced in two specific ways. clang_getTranslationUnitCursor() produces a cursor for a translation unit, from which one can use clang_visitChildren() to explore the rest of the translation unit. clang_getCursor() maps from a physical source location to the entity that resides at that location, allowing one to map from the source code into the AST.

Fields:

:kind

(Symbol from enum_cursor_kind)

:xdata

(Integer)

:data

(Array<FFI::Pointer(*Void)>)

Instance Method Summary collapse

Instance Method Details

#columnObject



118
119
120
# File 'lib/rbind/clang/clang_types.rb', line 118

def column
    location[2]
end

#complete?Boolean

Returns:



213
214
215
# File 'lib/rbind/clang/clang_types.rb', line 213

def complete?
    !incomplete?
end

#cxx_access_specifierObject



134
135
136
# File 'lib/rbind/clang/clang_types.rb', line 134

def cxx_access_specifier
    Rbind::get_cxx_access_specifier self
end

#definitionObject



221
222
223
# File 'lib/rbind/clang/clang_types.rb', line 221

def definition
    Rbind::get_cursor_definition self
end

#display_nameObject



185
186
187
# File 'lib/rbind/clang/clang_types.rb', line 185

def display_name
    Rbind::get_cursor_display_name(self).to_s
end

#expressionObject



160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/rbind/clang/clang_types.rb', line 160

def expression
    num = FFI::MemoryPointer.new(:uint,1)
    tokens = FFI::MemoryPointer.new(:pointer,1)
    tu = translation_unit
    Rbind::tokenize(tu,extent,tokens,num)
    ptr = FFI::Pointer.new(Token,tokens.read_pointer)
    result = 0.upto(num.read_uint-1).map do |i|
        Rbind::get_token_spelling(tu,ptr[i])
    end
    Rbind::dispose_tokens(tu,ptr,num.get_uint(0))
    result
end

#extentObject



138
139
140
# File 'lib/rbind/clang/clang_types.rb', line 138

def extent
    Rbind::get_cursor_extent self
end

#file_nameObject



110
111
112
# File 'lib/rbind/clang/clang_types.rb', line 110

def file_name
    location[0]
end

#incomplete?Boolean

Returns:



217
218
219
# File 'lib/rbind/clang/clang_types.rb', line 217

def incomplete?
    definition.null?
end

#kindObject



189
190
191
# File 'lib/rbind/clang/clang_types.rb', line 189

def kind
    Rbind::get_cursor_kind(self)
end

#kind_spellingObject



177
178
179
# File 'lib/rbind/clang/clang_types.rb', line 177

def kind_spelling
    Rbind::get_cursor_kind_spelling(self).to_s
end

#lineObject



114
115
116
# File 'lib/rbind/clang/clang_types.rb', line 114

def line
    location[1]
end

#locationObject



92
93
94
95
96
97
98
99
100
# File 'lib/rbind/clang/clang_types.rb', line 92

def location
    line = FFI::MemoryPointer.new(:uint,1)
    col = FFI::MemoryPointer.new(:uint,1)
    location = Rbind::get_cursor_location(self)
    fstr = String.new
    Rbind::get_presumed_location(location,fstr,line,col)
    result = [fstr.to_s,line.get_uint(0),col.get_uint(0)]
    result
end

#location_intObject



102
103
104
# File 'lib/rbind/clang/clang_types.rb', line 102

def location_int
    Rbind::get_cursor_location(self)[:int_data]
end

#namespaceObject



146
147
148
149
150
151
152
153
154
# File 'lib/rbind/clang/clang_types.rb', line 146

def namespace
    namespace = []
    cursor = semantic_parent
    while !cursor.translation_unit?
        namespace << cursor.spelling
        cursor = cursor.semantic_parent
    end
    namespace.reverse.join("::")
end

#null?Boolean

Returns:



88
89
90
# File 'lib/rbind/clang/clang_types.rb', line 88

def null?
    1 == Rbind::cursor_is_null(self)
end

#private?Boolean

Returns:



122
123
124
# File 'lib/rbind/clang/clang_types.rb', line 122

def private?
    cxx_access_specifier == :x_private
end

#protected?Boolean

Returns:



130
131
132
# File 'lib/rbind/clang/clang_types.rb', line 130

def protected?
    cxx_access_specifier == :x_protected
end

#public?Boolean

Returns:



126
127
128
# File 'lib/rbind/clang/clang_types.rb', line 126

def public?
    cxx_access_specifier == :x_public
end

#referencedObject



106
107
108
# File 'lib/rbind/clang/clang_types.rb', line 106

def referenced
    Rbind::get_cursor_referenced self
end

#result_typeObject



173
174
175
# File 'lib/rbind/clang/clang_types.rb', line 173

def result_type
    Rbind::get_cursor_result_type self
end

#semantic_parentObject



142
143
144
# File 'lib/rbind/clang/clang_types.rb', line 142

def semantic_parent
    Rbind::get_cursor_semantic_parent self
end

#specialized_templateObject



205
206
207
# File 'lib/rbind/clang/clang_types.rb', line 205

def specialized_template
    Rbind::get_specialized_cursor_template self
end

#spellingObject



181
182
183
# File 'lib/rbind/clang/clang_types.rb', line 181

def spelling
    Rbind::get_cursor_spelling(self).to_s
end

#static?Boolean

Returns:



225
226
227
# File 'lib/rbind/clang/clang_types.rb', line 225

def static?
    1 == Rbind::cxx_method_is_static(self)
end

#template_kindObject



209
210
211
# File 'lib/rbind/clang/clang_types.rb', line 209

def template_kind
    Rbind::get_template_cursor_kind self
end

#translation_unitObject



193
194
195
# File 'lib/rbind/clang/clang_types.rb', line 193

def translation_unit
    Rbind::cursor_get_translation_unit(self)
end

#translation_unit?Boolean

Returns:



156
157
158
# File 'lib/rbind/clang/clang_types.rb', line 156

def translation_unit?
    kind == :translation_unit
end

#typeObject



197
198
199
# File 'lib/rbind/clang/clang_types.rb', line 197

def type
    Rbind::get_cursor_type self
end

#virtual?Boolean

Returns:



229
230
231
# File 'lib/rbind/clang/clang_types.rb', line 229

def virtual?
    1 == Rbind::cxx_method_is_virtual(self)
end

#virtul_base?Boolean

Returns:



201
202
203
# File 'lib/rbind/clang/clang_types.rb', line 201

def virtul_base?
    1 == Rbind::is_virtual_base(self)
end

#visit_children(recurse = false, *reg_filters, &block) ⇒ Object



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/rbind/clang/clang_types.rb', line 233

def visit_children(recurse=false,*reg_filters,&block)
    if reg_filters.empty?
        reg_filters << Regexp.new("#{File.dirname(translation_unit.spelling)}")
    end
    p = proc do |cur,parent,data|
      #  puts "#{cur.kind} #{cur.spelling} #{cur.template_kind} #{cur.specialized_template.kind} #{cur.location}"
        if(reg_filters.find{|reg| cur.file_name =~ reg})
            block.call(cur,parent)
            if recurse
                :recurse
            else
                :continue
            end
        else
            :continue
        end
    end
    Rbind::visit_children(self,p,FFI::Pointer.new(0))
end