ffi-clang

FORK: Ruby FFI bindings for my custom patched clang 8.0.
git clone https://git.neptards.moe/neptards/ffi-clang.git
Log | Files | Refs | README

file.rb (1894B)


      1 # Copyright, 2014, by Masahiro Sano.
      2 # 
      3 # Permission is hereby granted, free of charge, to any person obtaining a copy
      4 # of this software and associated documentation files (the "Software"), to deal
      5 # in the Software without restriction, including without limitation the rights
      6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      7 # copies of the Software, and to permit persons to whom the Software is
      8 # furnished to do so, subject to the following conditions:
      9 # 
     10 # The above copyright notice and this permission notice shall be included in
     11 # all copies or substantial portions of the Software.
     12 # 
     13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     19 # THE SOFTWARE.
     20 
     21 require_relative 'lib/file'
     22 
     23 module FFI
     24 	module Clang
     25 		class File < Pointer
     26 			attr_reader :translation_unit
     27 
     28 			def initialize(pointer, translation_unit)
     29 				super pointer
     30 				@translation_unit = translation_unit
     31 
     32 				pointer = MemoryPointer.new(Lib::CXFileUniqueID)
     33 				Lib.get_file_unique_id(self, pointer)
     34 				@unique_id = Lib::CXFileUniqueID.new(pointer)
     35 			end
     36 
     37 			def to_s
     38 				name
     39 			end
     40 
     41 			def name
     42 				Lib.extract_string Lib.get_file_name(self)
     43 			end
     44 
     45 			def time
     46 				Time.at(Lib.get_file_time(self))
     47 			end
     48 
     49 			def include_guarded?
     50 				Lib.is_file_multiple_include_guarded(@translation_unit, self) != 0
     51 			end
     52 
     53 			def device
     54 				@unique_id[:device]
     55 			end
     56 
     57 			def inode
     58 				@unique_id[:inode]
     59 			end
     60 
     61 			def modification
     62 				Time.at(@unique_id[:modification])
     63 			end
     64 		end
     65 	end
     66 end