class AdLint::Exam::CBuiltin::W0704

Public Class Methods

new(phase_ctxt) click to toggle source
Calls superclass method AdLint::Examination::new
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 16250
def initialize(phase_ctxt)
  super
  interp = phase_ctxt[:cc1_interpreter]
  interp.on_variable_defined           += T(:define_variable)
  interp.on_explicit_function_declared += T(:declare_function)
  interp.on_variable_declared          += T(:declare_variable)
  interp.on_enum_declared              += T(:declare_enum)
  interp.on_typedef_declared           += T(:declare_typedef)
  interp.on_explicit_function_defined  += T(:define_function)
  interp.on_parameter_defined          += T(:define_parameter)
  interp.on_block_started              += T(:enter_scope)
  interp.on_block_ended                += T(:leave_scope)
  @vdcls = [[]]
  @vdefs = [[]]
  @fdcls = [[]]
  @fdefs = [[]]
  @tdefs = [[]]
  @enums = [[]]
end

Private Instance Methods

declare_enum(enum_dcl) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 16331
def declare_enum(enum_dcl)
  enum_dcl.enumerators.each do |enum|
    enum_name = enum.identifier

    pair_names = wider_identifiers_of_enum_declaration.select { |id|
      id.value == enum_name.value
    }

    unless pair_names.empty?
      W(enum.location, enum_name.value,
        *pair_names.map { |pair| C(:C0001, pair.location, pair.value) })
    end

    @enums.last.push(enum_name)
  end
end
declare_function(fun_dcl, *) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 16291
def declare_function(fun_dcl, *)
  dcl_name = fun_dcl.identifier

  pair_names = wider_identifiers_of_function_declaration.select { |id|
    id.value == dcl_name.value
  }

  unless pair_names.empty?
    W(fun_dcl.location, dcl_name.value,
      *pair_names.map { |pair| C(:C0001, pair.location, pair.value) })
  end

  @fdcls.last.push(dcl_name)
end
declare_typedef(typedef_dcl) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 16353
def declare_typedef(typedef_dcl)
  dcl_name = typedef_dcl.identifier

  pair_names = wider_identifiers_of_typedef_declaration.select { |id|
    id.value == dcl_name.value
  }

  unless pair_names.empty?
    W(typedef_dcl.location, dcl_name.value,
      *pair_names.map { |pair| C(:C0001, pair.location, pair.value) })
  end

  @enums.last.push(dcl_name)
end
declare_variable(var_dcl, *) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 16311
def declare_variable(var_dcl, *)
  dcl_name = var_dcl.identifier

  pair_names = wider_identifiers_of_variable_declaration.select { |id|
    id.value == dcl_name.value
  }

  unless pair_names.empty?
    W(var_dcl.location, dcl_name.value,
      *pair_names.map { |pair| C(:C0001, pair.location, pair.value) })
  end

  @vdcls.last.push(dcl_name)
end
define_function(fun_def, *) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 16373
def define_function(fun_def, *)
  dcl_name = fun_def.identifier

  pair_names = wider_identifiers_of_function_definition.select { |id|
    id.value == dcl_name.value
  }

  unless pair_names.empty?
    W(fun_def.location, dcl_name.value,
      *pair_names.map { |pair| C(:C0001, pair.location, pair.value) })
  end

  @fdefs.last.push(dcl_name)
end
define_parameter(param_def, *) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 16393
def define_parameter(param_def, *)
  dcl_name = param_def.identifier

  pair_names = wider_identifiers_of_parameter_definition.select { |id|
    id.value == dcl_name.value
  }

  unless pair_names.empty?
    W(param_def.location, dcl_name.value,
      *pair_names.map { |pair| C(:C0001, pair.location, pair.value) })
  end

  @vdefs.last.push(dcl_name)
end
define_variable(var_def, *) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 16271
def define_variable(var_def, *)
  dcl_name = var_def.identifier

  pair_names = wider_identifiers_of_variable_definition.select { |id|
    id.value == dcl_name.value
  }

  unless pair_names.empty?
    W(var_def.location, dcl_name.value,
      *pair_names.map { |pair| C(:C0001, pair.location, pair.value) })
  end

  @vdefs.last.push(dcl_name)
end
enter_scope(*) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 16413
def enter_scope(*)
  @vdcls.push([])
  @vdefs.push([])
  @fdcls.push([])
  @fdefs.push([])
  @tdefs.push([])
  @enums.push([])
end
leave_scope(*) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 16422
def leave_scope(*)
  @vdcls.pop
  @vdefs.pop
  @fdcls.pop
  @fdefs.pop
  @tdefs.pop
  @enums.pop
end
wider_identifiers_of_enum_declaration() click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 16348
def wider_identifiers_of_enum_declaration
  (@vdcls[0..-2] + @vdefs[0..-2] + @fdcls[0..-2] + @fdefs[0..-2] +
   @tdefs[0..-2] + @enums[0..-2]).flatten
end
wider_identifiers_of_function_declaration() click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 16306
def wider_identifiers_of_function_declaration
  (@vdcls[0..-2] + @vdefs[0..-2] + @fdcls[0..-2] + @fdefs[0..-2] +
   @tdefs[0..-2] + @enums[0..-2]).flatten
end
wider_identifiers_of_function_definition() click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 16388
def wider_identifiers_of_function_definition
  (@vdcls[0..-2] + @vdefs[0..-2] + @fdefs[0..-2] + @tdefs[0..-2] +
   @enums[0..-2]).flatten
end
wider_identifiers_of_parameter_definition() click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 16408
def wider_identifiers_of_parameter_definition
  (@vdcls[0..-2] + @vdefs[0..-2] + @fdcls[0..-2] + @fdefs[0..-2] +
   @tdefs[0..-2] + @enums[0..-2]).flatten
end
wider_identifiers_of_typedef_declaration() click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 16368
def wider_identifiers_of_typedef_declaration
  (@vdcls[0..-2] + @vdefs[0..-2] + @fdcls[0..-2] + @fdefs[0..-2] +
   @tdefs[0..-2] + @enums[0..-2]).flatten
end
wider_identifiers_of_variable_declaration() click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 16326
def wider_identifiers_of_variable_declaration
  (@vdefs[0..-2] + @fdcls[0..-2] + @fdefs[0..-2] + @tdefs[0..-2] +
   @enums[0..-2]).flatten
end
wider_identifiers_of_variable_definition() click to toggle source
# File lib/adlint/exam/c_builtin/cc1_check.rb, line 16286
def wider_identifiers_of_variable_definition
  (@vdcls[0..-2] + @vdefs[0..-2] + @fdcls[0..-2] + @fdefs[0..-2] +
   @tdefs[0..-2] + @enums[0..-2]).flatten
end