Class: Clang::Rbind::Cursor
- Inherits:
-
FFI::Struct
- Object
- FFI::Struct
- Clang::Rbind::Cursor
- 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
- #column ⇒ Object
- #complete? ⇒ Boolean
- #cxx_access_specifier ⇒ Object
- #definition ⇒ Object
- #display_name ⇒ Object
- #expression ⇒ Object
- #extent ⇒ Object
- #file_name ⇒ Object
- #incomplete? ⇒ Boolean
- #kind ⇒ Object
- #kind_spelling ⇒ Object
- #line ⇒ Object
- #location ⇒ Object
- #location_int ⇒ Object
- #namespace ⇒ Object
- #null? ⇒ Boolean
- #private? ⇒ Boolean
- #protected? ⇒ Boolean
- #public? ⇒ Boolean
- #referenced ⇒ Object
- #result_type ⇒ Object
- #semantic_parent ⇒ Object
- #specialized_template ⇒ Object
- #spelling ⇒ Object
- #static? ⇒ Boolean
- #template_kind ⇒ Object
- #translation_unit ⇒ Object
- #translation_unit? ⇒ Boolean
- #type ⇒ Object
- #virtual? ⇒ Boolean
- #virtul_base? ⇒ Boolean
- #visit_children(recurse = false, *reg_filters, &block) ⇒ Object
Instance Method Details
#column ⇒ Object
118 119 120 |
# File 'lib/rbind/clang/clang_types.rb', line 118 def column location[2] end |
#complete? ⇒ Boolean
213 214 215 |
# File 'lib/rbind/clang/clang_types.rb', line 213 def complete? !incomplete? end |
#cxx_access_specifier ⇒ Object
134 135 136 |
# File 'lib/rbind/clang/clang_types.rb', line 134 def cxx_access_specifier Rbind::get_cxx_access_specifier self end |
#definition ⇒ Object
221 222 223 |
# File 'lib/rbind/clang/clang_types.rb', line 221 def definition Rbind::get_cursor_definition self end |
#display_name ⇒ Object
185 186 187 |
# File 'lib/rbind/clang/clang_types.rb', line 185 def display_name Rbind::get_cursor_display_name(self).to_s end |
#expression ⇒ Object
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 |
#extent ⇒ Object
138 139 140 |
# File 'lib/rbind/clang/clang_types.rb', line 138 def extent Rbind::get_cursor_extent self end |
#file_name ⇒ Object
110 111 112 |
# File 'lib/rbind/clang/clang_types.rb', line 110 def file_name location[0] end |
#incomplete? ⇒ Boolean
217 218 219 |
# File 'lib/rbind/clang/clang_types.rb', line 217 def incomplete? definition.null? end |
#kind ⇒ Object
189 190 191 |
# File 'lib/rbind/clang/clang_types.rb', line 189 def kind Rbind::get_cursor_kind(self) end |
#kind_spelling ⇒ Object
177 178 179 |
# File 'lib/rbind/clang/clang_types.rb', line 177 def kind_spelling Rbind::get_cursor_kind_spelling(self).to_s end |
#line ⇒ Object
114 115 116 |
# File 'lib/rbind/clang/clang_types.rb', line 114 def line location[1] end |
#location ⇒ Object
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_int ⇒ Object
102 103 104 |
# File 'lib/rbind/clang/clang_types.rb', line 102 def location_int Rbind::get_cursor_location(self)[:int_data] end |
#namespace ⇒ Object
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
88 89 90 |
# File 'lib/rbind/clang/clang_types.rb', line 88 def null? 1 == Rbind::cursor_is_null(self) end |
#private? ⇒ Boolean
122 123 124 |
# File 'lib/rbind/clang/clang_types.rb', line 122 def private? cxx_access_specifier == :x_private end |
#protected? ⇒ Boolean
130 131 132 |
# File 'lib/rbind/clang/clang_types.rb', line 130 def protected? cxx_access_specifier == :x_protected end |
#public? ⇒ Boolean
126 127 128 |
# File 'lib/rbind/clang/clang_types.rb', line 126 def public? cxx_access_specifier == :x_public end |
#referenced ⇒ Object
106 107 108 |
# File 'lib/rbind/clang/clang_types.rb', line 106 def referenced Rbind::get_cursor_referenced self end |
#result_type ⇒ Object
173 174 175 |
# File 'lib/rbind/clang/clang_types.rb', line 173 def result_type Rbind::get_cursor_result_type self end |
#semantic_parent ⇒ Object
142 143 144 |
# File 'lib/rbind/clang/clang_types.rb', line 142 def semantic_parent Rbind::get_cursor_semantic_parent self end |
#specialized_template ⇒ Object
205 206 207 |
# File 'lib/rbind/clang/clang_types.rb', line 205 def specialized_template Rbind::get_specialized_cursor_template self end |
#spelling ⇒ Object
181 182 183 |
# File 'lib/rbind/clang/clang_types.rb', line 181 def spelling Rbind::get_cursor_spelling(self).to_s end |
#static? ⇒ Boolean
225 226 227 |
# File 'lib/rbind/clang/clang_types.rb', line 225 def static? 1 == Rbind::cxx_method_is_static(self) end |
#template_kind ⇒ Object
209 210 211 |
# File 'lib/rbind/clang/clang_types.rb', line 209 def template_kind Rbind::get_template_cursor_kind self end |
#translation_unit ⇒ Object
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
156 157 158 |
# File 'lib/rbind/clang/clang_types.rb', line 156 def translation_unit? kind == :translation_unit end |
#type ⇒ Object
197 198 199 |
# File 'lib/rbind/clang/clang_types.rb', line 197 def type Rbind::get_cursor_type self end |
#virtual? ⇒ Boolean
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
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 |