Class: StatementGroup
- Defined in:
- lib/core/statement/StatementGroup.rb
Direct Known Subclasses
Constant Summary collapse
- @@scope_id =
The scope id is used to determine what variables are available with the nested statement
0
Instance Attribute Summary collapse
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#scope_id ⇒ Object
Returns the value of attribute scope_id.
-
#statement_level ⇒ Object
Returns the value of attribute statement_level.
Instance Method Summary collapse
- #array_push ⇒ Object
- #cauldron_method_calls ⇒ Object
- #copy ⇒ Object
- #describe(tab = 0) ⇒ Object
-
#find_all_required_runtime_methods ⇒ Object
Returns an array of all the runtime method instances that are required for this statement group.
-
#find_container_at_level(statement_level) ⇒ Object
Returns a statement container (either a runtime method or a nested statement) thats scope is the statement level specified.
-
#find_overriding_statements(overriding_statements = []) ⇒ Object
Returns an array of overriding statements that reside inside this statement group.
-
#find_statement(id) ⇒ Object
Returns the statement thats id matches that supplied.
-
#identify_overriding_statements(already_declared = []) ⇒ Object
Identify any of the contained statements that override an existing variable.
-
#initialize(*statements) ⇒ StatementGroup
constructor
A new instance of StatementGroup.
- #push(*entries) ⇒ Object
-
#remove_simple ⇒ Object
Removes any statements that simple re-declare an existing statement e.g var_a = var_b.
-
#statement_id ⇒ Object
TODO This method name doesn’t suit what it returns.
- #write(tab = 0) ⇒ Object
Methods inherited from Array
#contains?, #select_all, #to_declaration, #to_intrinsic, #to_literal, #to_var
Constructor Details
#initialize(*statements) ⇒ StatementGroup
Returns a new instance of StatementGroup.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/core/statement/StatementGroup.rb', line 10 def initialize(*statements) super() statements.each {|x| self.push(x)} # Update the scope id for the nested statement @scope_id = @@scope_id @@scope_id += 1 @scope = [@scope_id] end |
Instance Attribute Details
#scope ⇒ Object
Returns the value of attribute scope.
2 3 4 |
# File 'lib/core/statement/StatementGroup.rb', line 2 def scope @scope end |
#scope_id ⇒ Object
Returns the value of attribute scope_id.
2 3 4 |
# File 'lib/core/statement/StatementGroup.rb', line 2 def scope_id @scope_id end |
#statement_level ⇒ Object
Returns the value of attribute statement_level.
2 3 4 |
# File 'lib/core/statement/StatementGroup.rb', line 2 def statement_level @statement_level end |
Instance Method Details
#array_push ⇒ Object
8 |
# File 'lib/core/statement/StatementGroup.rb', line 8 alias :array_push :push |
#cauldron_method_calls ⇒ Object
22 23 24 |
# File 'lib/core/statement/StatementGroup.rb', line 22 def cauldron_method_calls return ['.statement_id'] end |
#copy ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/core/statement/StatementGroup.rb', line 123 def copy result = self.class.new(*self.collect {|x| x.copy }) result.scope_id = scope_id result.scope = scope result.statement_level = statement_level return result end |
#describe(tab = 0) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/core/statement/StatementGroup.rb', line 32 def describe(tab=0) line = '' #self.each {|x| line += x.describe(tab)+"\n" } self.each do |x| line += x.describe(tab)+"\n" end return line end |
#find_all_required_runtime_methods ⇒ Object
Returns an array of all the runtime method instances that are required for this statement group. This is essentially the runtime methods referenced in DefCalls.
115 116 117 118 119 120 121 |
# File 'lib/core/statement/StatementGroup.rb', line 115 def find_all_required_runtime_methods results = [] self.each do |x| results += x.find_all_required_runtime_methods end return results end |
#find_container_at_level(statement_level) ⇒ Object
Returns a statement container (either a runtime method or a nested statement) thats scope is the statement level specified. This means that any statements with the statement level specified should reside directly in the statement container.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/core/statement/StatementGroup.rb', line 78 def find_container_at_level(statement_level) return self if scope_id == statement_level self.each do |x| if x.kind_of?(StatementGroup) begin return x.find_container_at_level(statement_level) rescue FailedToFindStatementContainerError => e next end #result = x.find_container_at_level(statement_level) #return result unless result.nil? end end raise FailedToFindStatementContainerError.new('Failed to find containing statement with id '+statement_level.to_s) #return nil #raise StandardEror.new('There is no container at level '+) end |
#find_overriding_statements(overriding_statements = []) ⇒ Object
Returns an array of overriding statements that reside inside this statement group. A overriding statement is a statement that re-declares or modifies a previously declared variable.
150 151 152 153 154 155 |
# File 'lib/core/statement/StatementGroup.rb', line 150 def find_overriding_statements(overriding_statements=[]) self.each do |x| x.find_overriding_statements(overriding_statements) end return overriding_statements end |
#find_statement(id) ⇒ Object
Returns the statement thats id matches that supplied.
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/core/statement/StatementGroup.rb', line 100 def find_statement(id) self.each do |x| begin return x.find_statement(id) rescue FailedToFindStatementError => e next end end raise FailedToFindStatementError.new('Couldn\'t find statement with id '+id.to_s) end |
#identify_overriding_statements(already_declared = []) ⇒ Object
Identify any of the contained statements that override an existing variable.
137 138 139 140 141 |
# File 'lib/core/statement/StatementGroup.rb', line 137 def identify_overriding_statements(already_declared=[]) self.each do |x| x.identify_overriding_statements(already_declared) end end |
#push(*entries) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/core/statement/StatementGroup.rb', line 52 def push(*entries) self.entries.each do |x| x.scope = [@scope_id] end #super.array_push(*entries) entries.each do |y| # TODO Oddly super.array_push seems to add it twice - might investigate #super.array_push(y) array_push(y) end end |
#remove_simple ⇒ Object
Removes any statements that simple re-declare an existing statement e.g var_a = var_b.
44 45 46 47 48 49 50 |
# File 'lib/core/statement/StatementGroup.rb', line 44 def remove_simple results = StatementGroup.new self.each do |x| results.push x unless x.is_simple? end return results end |
#statement_id ⇒ Object
TODO This method name doesn’t suit what it returns
66 67 68 |
# File 'lib/core/statement/StatementGroup.rb', line 66 def statement_id return @scope_id end |
#write(tab = 0) ⇒ Object
26 27 28 29 30 |
# File 'lib/core/statement/StatementGroup.rb', line 26 def write(tab=0) line = '' self.each {|x| line += x.write(tab)+"\n" } return line end |