class AdLint::Exam::CBuiltin::W0432
Private Instance Methods
do_execute(phase_ctxt)
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 9086 def do_execute(phase_ctxt) while tok = next_token case tok.type when "{" on_left_brace(tok) when "}" on_right_brace(tok) when "(" on_left_paren(tok) when ")" on_right_paren(tok) end case tok.type when :IF, :FOR, :WHILE if last_line_no < tok.location.line_no on_beginning_of_line(tok) end skip_controlling_part unless tok = peek_token and tok.type == "{" process_simple_substatement end when :ELSE if last_line_no < tok.location.line_no on_beginning_of_line(tok) end unless tok = peek_token and tok.type == :IF || tok.type == "{" process_simple_substatement end when :DO if last_line_no < tok.location.line_no on_beginning_of_line(tok) end unless tok = peek_token and tok.type == "{" process_simple_substatement end else if last_line_no < tok.location.line_no on_beginning_of_line(tok) end end end end
do_prepare(phase_ctxt)
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 9070 def do_prepare(phase_ctxt) fpath = phase_ctxt[:sources].first.fpath @tokens = phase_ctxt[:cc1_tokens].select { |tok| tok.location.fpath == fpath } @index = 0 @indent_level = 0 @indent_width = indent_width @paren_depth = 0 @lst_token = nil end
expected_indent_width(tok, delta_level = 0)
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 9272 def expected_indent_width(tok, delta_level = 0) if @indent_width == 0 && @indent_level > 0 @indent_width = (tok.location.appearance_column_no - 1) / @indent_level end if @indent_width > 0 @indent_width * @indent_level + @indent_width * delta_level + 1 else tok.location.appearance_column_no end end
last_line_no()
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 9082 def last_line_no @lst_token ? @lst_token.location.line_no : 0 end
monitor()
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 9284 def monitor @phase_ctxt.monitor end
next_token()
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 9194 def next_token return nil unless tok = peek_token @index += 1 case tok.type when :CASE while tok = peek_token @index += 1 break if tok.type == ":" end when :IDENTIFIER, :DEFAULT if nxt_tok = @tokens[@index] and nxt_tok.type == ":" tok = peek_token @index += 1 end end tok end
on_beginning_of_line(tok)
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 9247 def on_beginning_of_line(tok) return if @paren_depth > 0 || @lst_token.replaced? case tok.type when "{" if @indent_level == 0 expected_column_no = expected_indent_width(tok) else expected_column_no = expected_indent_width(tok, -1) end when "}" if indent_style == INDENT_STYLE_GNU && @indent_level > 0 expected_column_no = expected_indent_width(tok, +1) else expected_column_no = expected_indent_width(tok) end else expected_column_no = expected_indent_width(tok) end unless tok.location.appearance_column_no == expected_column_no W(tok.location) if tok.analysis_target?(traits) end end
on_left_brace(tok)
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 9222 def on_left_brace(tok) if indent_style == INDENT_STYLE_GNU && @indent_level > 0 @indent_level += 2 else @indent_level += 1 end end
on_left_paren(tok)
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 9239 def on_left_paren(tok) @paren_depth += 1 end
on_right_brace(tok)
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 9230 def on_right_brace(tok) if indent_style == INDENT_STYLE_GNU @indent_level -= 2 @indent_level = 0 if @indent_level < 0 else @indent_level -= 1 end end
on_right_paren(tok)
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 9243 def on_right_paren(tok) @paren_depth -= 1 end
peek_token()
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 9214 def peek_token if tok = @tokens[@index] @lst_token = @tokens[[0, @index - 1].max] checkpoint(tok.location) end tok end
process_simple_substatement()
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 9143 def process_simple_substatement @indent_level += 1 while tok = next_token case tok.type when "{" on_left_brace(tok) when "}" on_right_brace(tok) when "(" on_left_paren(tok) when ")" on_right_paren(tok) end case tok.type when :IF, :FOR, :WHILE if last_line_no < tok.location.line_no on_beginning_of_line(tok) end skip_controlling_part unless tok = peek_token and tok.type == "{" process_simple_substatement break end when :ELSE if last_line_no < tok.location.line_no on_beginning_of_line(tok) end unless tok = peek_token and tok.type == :IF || tok.type == "{" process_simple_substatement break end when :DO if last_line_no < tok.location.line_no on_beginning_of_line(tok) end unless tok = peek_token and tok.type == "{" process_simple_substatement process_simple_substatement break end else if last_line_no < tok.location.line_no on_beginning_of_line(tok) end break if tok.type == ";" end end @indent_level -= 1 end
skip_controlling_part()
click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 9130 def skip_controlling_part paren_depth = 0 while tok = next_token case tok.type when "(" paren_depth += 1 when ")" paren_depth -= 1 break if paren_depth == 0 end end end