class AdLint::Exam::CBuiltin::LiteralExtraction

Public Class Methods

new(phase_ctxt) click to toggle source
Calls superclass method AdLint::Examination::new
# File lib/adlint/exam/c_builtin/cc1_code.rb, line 419
def initialize(phase_ctxt)
  super
  trav = phase_ctxt[:cc1_ast_traversal]
  trav.enter_constant_specifier       += T(:extract_constant)
  trav.enter_string_literal_specifier += T(:extract_string_literal)
end

Private Instance Methods

do_execute(*) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_code.rb, line 428
def do_execute(*) end
do_prepare(*) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_code.rb, line 427
def do_prepare(*) end
extract_constant(const_spec) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_code.rb, line 430
def extract_constant(const_spec)
  LIT(const_spec.location, type_of(const_spec),
      const_spec.prefix, const_spec.suffix, const_spec.constant.value)
end
extract_string_literal(str_lit_spec) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_code.rb, line 435
def extract_string_literal(str_lit_spec)
  LIT(str_lit_spec.location, type_of(str_lit_spec),
      str_lit_spec.prefix, nil, str_lit_spec.literal.value)
end
type_of(const_or_str_lit_spec) click to toggle source
# File lib/adlint/exam/c_builtin/cc1_code.rb, line 440
def type_of(const_or_str_lit_spec)
  case const_or_str_lit_spec
  when Cc1::ConstantSpecifier
    case const_or_str_lit_spec.constant.value
    when /\A0x[0-9a-f]+[UL]*\z/i
      "HN"
    when /\A0b[01]+[UL]*\z/i
      "BN"
    when /\A0[0-9]+[UL]*\z/i
      "ON"
    when /\A[0-9]+[UL]*\z/i
      "DN"
    when /\A(?:[0-9]*\.[0-9]*E[+-]?[0-9]+|[0-9]+\.?E[+-]?[0-9]+)[FL]*\z/i,
         /\A(?:[0-9]*\.[0-9]+|[0-9]+\.)[FL]*\z/i
      "FN"
    when /\A'.*'\z/i
      "CN"
    when /\AL'.*'\z/i
      "CW"
    else
      "NA"
    end
  when Cc1::StringLiteralSpecifier
    case const_or_str_lit_spec.literal.value
    when /\A".*"\z/i
      "SN"
    when /\AL".*"\z/i
      "SW"
    else
      "NA"
    end
  else
    raise TypeError
  end
end