Class: AdLint::Cc1::Branch

Inherits:
Object
  • Object
show all
Includes:
BranchOptions
Defined in:
lib/adlint/cc1/branch.rb

Constant Summary

Constants included from BranchOptions

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_eventObject (readonly)

Returns the value of attribute break_event.



49
50
51
# File 'lib/adlint/cc1/branch.rb', line 49

def break_event
  @break_event
end

#ctrlexprObject (readonly)

Returns the value of attribute ctrlexpr.



50
51
52
# File 'lib/adlint/cc1/branch.rb', line 50

def ctrlexpr
  @ctrlexpr
end

#groupObject (readonly)

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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


149
150
151
# File 'lib/adlint/cc1/branch.rb', line 149

def break_with_return?
  @break_event && @break_event.return?
end

#complemental?Boolean

Returns:

  • (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?
    # NOTE: Give up value domain thinning of the controlling variables,
    #       because the controlling expression is too complex to manage
    #       value domains correctly.
    # TODO: Study about introducing inter-value-constraints to correctly
    #       manage value domains of controlling variables related with each
    #       other.
    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

Returns:

  • (Boolean)


73
74
75
# File 'lib/adlint/cc1/branch.rb', line 73

def final?
  @options.include?(FINAL)
end

#first?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/adlint/cc1/branch.rb', line 69

def first?
  @options.include?(FIRST)
end

#implicit_condition?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/adlint/cc1/branch.rb', line 81

def implicit_condition?
  @options.include?(IMPLICIT_COND)
end

#narrowing?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


77
78
79
# File 'lib/adlint/cc1/branch.rb', line 77

def smother_break?
  @options.include?(SMOTHER_BREAK)
end

#trunkObject



52
53
54
# File 'lib/adlint/cc1/branch.rb', line 52

def trunk
  @group.trunk
end

#widening?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/adlint/cc1/branch.rb', line 65

def widening?
  @options.include?(WIDENING)
end