Class: CodeParser
Constant Summary collapse
'--c-kinds=f --fortran-kinds=fsip --php-kinds=f --perl-kinds=f'
- @@workDir =
ENV['HOME'] + '/.codegraph'
- @@filesDBfile =
@@workDir+'/filesDB.json'
- @@filesDB =
File.exist?(@@filesDBfile) ? JSON.parse(File.open(@@filesDBfile).read) : Hash.new
- @@filesCk =
@@filesDB.hash
- @@lock =
Mutex.new
Instance Attribute Summary collapse
-
#exclude ⇒ Object
Returns the value of attribute exclude.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#funx ⇒ Object
readonly
Returns the value of attribute funx.
Class Method Summary collapse
- .filesCk ⇒ Object
-
.filesDB ⇒ Object
come class methods.
Instance Method Summary collapse
-
#initialize(debug = false, dir = "#{ENV['HOME']}/.codegraph") ⇒ CodeParser
constructor
.
- #read(*filelist) ⇒ Object
Constructor Details
#initialize(debug = false, dir = "#{ENV['HOME']}/.codegraph") ⇒ CodeParser
35 36 37 38 39 40 41 |
# File 'lib/codegraph.rb', line 35 def initialize(debug=false,dir="#{ENV['HOME']}/.codegraph") @dir = dir @debug = debug @funx = {} @files = {} @exclude = [] end |
Instance Attribute Details
#exclude ⇒ Object
Returns the value of attribute exclude.
17 18 19 |
# File 'lib/codegraph.rb', line 17 def exclude @exclude end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
16 17 18 |
# File 'lib/codegraph.rb', line 16 def files @files end |
#funx ⇒ Object (readonly)
Returns the value of attribute funx.
16 17 18 |
# File 'lib/codegraph.rb', line 16 def funx @funx end |
Class Method Details
.filesCk ⇒ Object
30 31 32 |
# File 'lib/codegraph.rb', line 30 def CodeParser.filesCk @@filesCk end |
.filesDB ⇒ Object
come class methods
27 28 29 |
# File 'lib/codegraph.rb', line 27 def CodeParser.filesDB @@filesDB end |
Instance Method Details
#read(*filelist) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/codegraph.rb', line 43 def read(*filelist) jobqueue = JobQueue.new filelist.each {|file| jobqueue.push { unless File.exist?(file) warn "Cannot find file #{file}" return else puts "Processing #{file} ..." if @debug end checksum = hexencode(file) if @@filesDB.has_key?(checksum) and @@filesDB.has_key?(file) code,funxLocations = @@filesDB[checksum] @files[file] = @@filesDB[file] else basefile = File.basename(file) tempfile = "_" + basefile case File.extname(file) when '.c','.h' cppCommand = "cpp -w -fpreprocessed -E -fdirectives-only #{file} -o #{@dir}/#{tempfile} 2>/dev/null" cppCommand = "cpp -fpreprocessed #{file} -o #{@dir}/#{tempfile} 2>/dev/null" grep = "grep -v -e '^$' #{@dir}/#{tempfile} | grep -v -e '^#' | perl -pi -e " +'\'s/".[^"]*"//g\'' +" > #{@dir}/#{basefile}" when '.f','.f77','.f90','.f95' cppCommand = "cp #{file} #{@dir}/#{tempfile}" grep = "grep -v -e '^$' #{@dir}/#{tempfile} | grep -v -e '^ *!' > #{@dir}/#{basefile}" else cppCommand = "cp #{file} #{@dir}/#{tempfile}" grep = "grep -v -e '^$' #{@dir}/#{tempfile} | grep -v -e '^#' > #{@dir}/#{basefile}" end = "ctags -x #{@@ctagsOpts} #{@dir}/#{basefile} | sort -n -k 3" command = [cppCommand,grep].join(";") puts if @debug puts command if @debug system(command) code = open(@dir+'/'+ File.basename(file)).readlines funxLocations = IO.popen().readlines.map {|l| l.split[0,4]} @@lock.synchronize { @@filesDB[checksum] = [code,funxLocations] @@filesDB[file] = funxLocations.map {|v| v[0]} @files[file] = @@filesDB[file] } # cleanup FileUtils.rm("#{@dir}/#{tempfile}") unless @debug FileUtils.rm("#{@dir}/#{basefile}") unless @debug end funxLocations.each_with_index {|ary,i| name, kind, line, file = ary next if @exclude.include?(name) puts name if @debug line = line.to_i startLineIndex = line - 1 endLineIndex = (i+1 < funxLocations.size) ? funxLocations[i+1][2].to_i - 2 : -1 body = code[startLineIndex..endLineIndex].join @@lock.synchronize { @funx.store(name,body) } } } } jobqueue.run updateFilesDB end |