class ADSL::Parser::ASTBlock
Public Instance Methods
optimize(last_stmt = false)
click to toggle source
Calls superclass method
ADSL::Parser::ASTNode#optimize
# File lib/adsl/parser/ast_nodes.rb, line 659 def optimize(last_stmt = false) until_no_change super() do |block| next block if block.statements.empty? statements = block.statements.map(&:optimize).map{ |stmt| stmt.is_a?(ASTBlock) ? stmt.statements : [stmt] }.flatten(1).reject{ |stmt| stmt.is_a?(ASTDummyStmt) } if last_stmt if statements.last.is_a?(ASTAssignment) if statements.last.objset.objset_has_side_effects? statements[-1] = ASTObjsetStmt.new(:objset => statements.last.objset) else statements.pop end elsif statements.last.is_a?(ASTEither) statements.last.blocks.map!{ |b| b.optimize true } statements[-1] = statements.last.optimize elsif statements.last.is_a?(ASTBlock) last = statements.pop.optimize true statements += last.statements end end ASTBlock.new(:statements => statements) end end
to_adsl()
click to toggle source
# File lib/adsl/parser/ast_nodes.rb, line 689 def to_adsl @statements.map(&:to_adsl).join end
typecheck_and_resolve(context, open_subcontext=true)
click to toggle source
# File lib/adsl/parser/ast_nodes.rb, line 645 def typecheck_and_resolve(context, open_subcontext=true) context.push_frame if open_subcontext stmts = [] @statements.each do |node| main_stmt = node.typecheck_and_resolve context stmts += context.pre_stmts stmts << main_stmt unless main_stmt.nil? context.pre_stmts = [] end return ADSL::DS::DSBlock.new :statements => stmts.flatten ensure context.pop_frame if open_subcontext end