Class: LazyPP::Unit
Instance Attribute Summary collapse
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#cpp ⇒ Object
Returns the value of attribute cpp.
-
#file ⇒ Object
Returns the value of attribute file.
-
#program ⇒ Object
Returns the value of attribute program.
-
#raw_tree ⇒ Object
Returns the value of attribute raw_tree.
-
#time ⇒ Object
Returns the value of attribute time.
-
#tree ⇒ Object
Returns the value of attribute tree.
Instance Method Summary collapse
- #basename ⇒ Object
- #build? ⇒ Boolean
- #debugger_required! ⇒ Object
- #debugger_required? ⇒ Boolean
- #gen_header ⇒ Object
- #gen_header=(val) ⇒ Object
-
#initialize(prog, file, opts = {}) ⇒ Unit
constructor
A new instance of Unit.
- #outname ⇒ Object
- #read ⇒ Object
- #scan ⇒ Object
- #to_cpp(*args) ⇒ Object
- #to_hpp(*args) ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(prog, file, opts = {}) ⇒ Unit
Returns a new instance of Unit.
6 7 8 9 10 |
# File 'lib/readable-cpp/program.rb', line 6 def initialize prog, file, opts={} super prog, file, nil, nil, nil, nil @read,@scanned = false,false @opts={gen_header: false, build: true}.merge opts end |
Instance Attribute Details
#contents ⇒ Object
Returns the value of attribute contents
4 5 6 |
# File 'lib/readable-cpp/program.rb', line 4 def contents @contents end |
#cpp ⇒ Object
Returns the value of attribute cpp.
5 6 7 |
# File 'lib/readable-cpp/program.rb', line 5 def cpp @cpp end |
#file ⇒ Object
Returns the value of attribute file
4 5 6 |
# File 'lib/readable-cpp/program.rb', line 4 def file @file end |
#program ⇒ Object
Returns the value of attribute program
4 5 6 |
# File 'lib/readable-cpp/program.rb', line 4 def program @program end |
#raw_tree ⇒ Object
Returns the value of attribute raw_tree
4 5 6 |
# File 'lib/readable-cpp/program.rb', line 4 def raw_tree @raw_tree end |
#time ⇒ Object
Returns the value of attribute time
4 5 6 |
# File 'lib/readable-cpp/program.rb', line 4 def time @time end |
#tree ⇒ Object
Returns the value of attribute tree
4 5 6 |
# File 'lib/readable-cpp/program.rb', line 4 def tree @tree end |
Instance Method Details
#basename ⇒ Object
41 42 43 |
# File 'lib/readable-cpp/program.rb', line 41 def basename File.basename(file, '.lpp') end |
#build? ⇒ Boolean
19 |
# File 'lib/readable-cpp/program.rb', line 19 def build?; @opts[:build] end |
#debugger_required! ⇒ Object
13 14 15 |
# File 'lib/readable-cpp/program.rb', line 13 def debugger_required! @opts[:debugger_required?] = true end |
#debugger_required? ⇒ Boolean
16 17 18 |
# File 'lib/readable-cpp/program.rb', line 16 def debugger_required? @opts[:debugger_required?] end |
#gen_header ⇒ Object
11 |
# File 'lib/readable-cpp/program.rb', line 11 def gen_header; @opts[:gen_header] end |
#gen_header=(val) ⇒ Object
12 |
# File 'lib/readable-cpp/program.rb', line 12 def gen_header= val; @opts[:gen_header]= val end |
#outname ⇒ Object
32 33 34 |
# File 'lib/readable-cpp/program.rb', line 32 def outname basename + '.cpp' end |
#read ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/readable-cpp/program.rb', line 20 def read return if @read warn "reading "+file #self.contents = File.read(file) self.contents = ERB.new(File.read(file)).result(binding) t = program.parse_str(self.contents) self.tree, self.raw_tree = t self.time = Time.now @read = true self.tree end |
#scan ⇒ Object
35 36 37 38 39 40 |
# File 'lib/readable-cpp/program.rb', line 35 def scan return if @scanned warn "scanning "+file tree && tree.scan(program) @scanned = true end |
#to_cpp(*args) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/readable-cpp/program.rb', line 63 def to_cpp(*args) @cpp ||= ( if gen_header ##filter out top-level declarations so they only appear in the header tree.to_cpp(*args) { |n| !(n.is_a?(VarDeclInitializer) || n.is_a?(VarDeclSimple)) } else tree.to_cpp(*args) end ) end |
#to_hpp(*args) ⇒ Object
72 |
# File 'lib/readable-cpp/program.rb', line 72 def to_hpp(*args); @hpp ||= tree.to_hpp(*args) end |
#write ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/readable-cpp/program.rb', line 44 def write if gen_header warn "writing "+(n= basename+'.hpp') open(n, 'w+') do |f| f.puts "#pragma once" # f.puts "#ifndef __HEADER_#{basename}" # f.puts "#define __HEADER_#{basename}" f.puts to_hpp(RenderState.new(program: program, gen_header: gen_header)) # f.puts "#endif" end end warn 'writing '+outname open(outname, 'w+') do |f| if gen_header f.puts "#include \"#{basename+'.hpp'}\"" end f.puts to_cpp(RenderState.new(program: program, gen_header: gen_header)) end end |