Class: AdLint::Cc1::Branch
- Inherits:
-
Object
- Object
- AdLint::Cc1::Branch
show all
- Includes:
- BranchOptions
- Defined in:
- lib/adlint/cc1/branch.rb
Constant Summary
AdLint::Cc1::BranchOptions::COMPLEMENTAL, AdLint::Cc1::BranchOptions::FINAL, AdLint::Cc1::BranchOptions::FIRST, AdLint::Cc1::BranchOptions::IMPLICIT_COND, AdLint::Cc1::BranchOptions::NARROWING, AdLint::Cc1::BranchOptions::SMOTHER_BREAK, AdLint::Cc1::BranchOptions::WIDENING
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(branch_group, *opts) ⇒ Branch
Returns a new instance of Branch.
41
42
43
44
45
46
|
# File 'lib/adlint/cc1/branch.rb', line 41
def initialize(branch_group, *opts)
@group = branch_group
@options = opts
@break_event = nil
@ctrlexpr = nil
end
|
Instance Attribute Details
#break_event ⇒ Object
Returns the value of attribute break_event.
49
50
51
|
# File 'lib/adlint/cc1/branch.rb', line 49
def break_event
@break_event
end
|
Returns the value of attribute ctrlexpr.
50
51
52
|
# File 'lib/adlint/cc1/branch.rb', line 50
def ctrlexpr
@ctrlexpr
end
|
Returns the value of attribute group.
48
49
50
|
# File 'lib/adlint/cc1/branch.rb', line 48
def group
@group
end
|
Instance Method Details
#add_options(*new_opts) ⇒ Object
56
57
58
59
|
# File 'lib/adlint/cc1/branch.rb', line 56
def add_options(*new_opts)
@options = (@options + new_opts).uniq
@group.add_options(*new_opts)
end
|
#break_with_break? ⇒ Boolean
141
142
143
|
# File 'lib/adlint/cc1/branch.rb', line 141
def break_with_break?
@break_event && @break_event.break?
end
|
#break_with_continue? ⇒ Boolean
145
146
147
|
# File 'lib/adlint/cc1/branch.rb', line 145
def break_with_continue?
@break_event && @break_event.continue?
end
|
#break_with_return? ⇒ Boolean
149
150
151
|
# File 'lib/adlint/cc1/branch.rb', line 149
def break_with_return?
@break_event && @break_event.return?
end
|
#complemental? ⇒ Boolean
85
86
87
|
# File 'lib/adlint/cc1/branch.rb', line 85
def complemental?
@options.include?(COMPLEMENTAL)
end
|
#execute(interp, expr = nil, &block) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/adlint/cc1/branch.rb', line 89
def execute(interp, expr = nil, &block)
env.enter_versioning_group if first?
env.begin_versioning
@ctrlexpr = ControllingExpression.new(interp, self, expr)
if ensure_condition(@ctrlexpr)
@break_event = BreakEvent.catch { yield(self) }
else
unless final? && @group.branches.size == 1
@break_event = BreakEvent.of_return
end
end
ensure
if @ctrlexpr.complexly_compounded? && !complemental?
if @group.in_iteration? && !smother_break?
env.end_versioning(break_with_return? || break_with_break?, true)
else
env.end_versioning(break_with_return?, true)
end
else
if @group.in_iteration? && !smother_break?
env.end_versioning(break_with_return? || break_with_break?, false)
else
env.end_versioning(break_with_return?, false)
end
end
if final?
env.leave_versioning_group(!@group.complete?)
if @group.complete?
rethrow_break_event
end
end
end
|
#final? ⇒ Boolean
73
74
75
|
# File 'lib/adlint/cc1/branch.rb', line 73
def final?
@options.include?(FINAL)
end
|
#first? ⇒ Boolean
69
70
71
|
# File 'lib/adlint/cc1/branch.rb', line 69
def first?
@options.include?(FIRST)
end
|
#implicit_condition? ⇒ Boolean
81
82
83
|
# File 'lib/adlint/cc1/branch.rb', line 81
def implicit_condition?
@options.include?(IMPLICIT_COND)
end
|
#narrowing? ⇒ Boolean
61
62
63
|
# File 'lib/adlint/cc1/branch.rb', line 61
def narrowing?
@options.include?(NARROWING)
end
|
#restart_versioning(&block) ⇒ Object
131
132
133
134
135
136
137
138
139
|
# File 'lib/adlint/cc1/branch.rb', line 131
def restart_versioning(&block)
@ctrlexpr.save_affected_variables
env.end_versioning(false)
env.leave_versioning_group(true)
env.enter_versioning_group
env.begin_versioning
yield
@ctrlexpr.restore_affected_variables
end
|
#smother_break? ⇒ Boolean
77
78
79
|
# File 'lib/adlint/cc1/branch.rb', line 77
def smother_break?
@options.include?(SMOTHER_BREAK)
end
|
52
53
54
|
# File 'lib/adlint/cc1/branch.rb', line 52
def trunk
@group.trunk
end
|
#widening? ⇒ Boolean
65
66
67
|
# File 'lib/adlint/cc1/branch.rb', line 65
def widening?
@options.include?(WIDENING)
end
|