Class: AdLint::Cpp::PreprocessedSource

Inherits:
Object
  • Object
show all
Extended by:
Pluggable
Includes:
InlineAssemblyDefinition
Defined in:
lib/adlint/cpp/source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Pluggable

def_plugin

Methods included from InlineAssemblyDefinition

#create_cxx_asm_definition, #create_extended_asm_definitions, #create_inline_assembly_substitutions

Constructor Details

#initialize(root_fpath) ⇒ PreprocessedSource

Returns a new instance of PreprocessedSource.



42
43
44
45
# File 'lib/adlint/cpp/source.rb', line 42

def initialize(root_fpath)
  @root_fpath = root_fpath
  @tokens = []
end

Instance Attribute Details

#root_fpathObject (readonly)

Returns the value of attribute root_fpath.



52
53
54
# File 'lib/adlint/cpp/source.rb', line 52

def root_fpath
  @root_fpath
end

Instance Method Details

#add_token(tok) ⇒ Object



54
55
56
# File 'lib/adlint/cpp/source.rb', line 54

def add_token(tok)
  @tokens.push(tok)
end

#pp_tokensObject



58
59
60
# File 'lib/adlint/cpp/source.rb', line 58

def pp_tokens
  @tokens.select { |tok| tok.type == :PP_TOKEN }
end

#substitute_code_blocks(traits) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/adlint/cpp/source.rb', line 62

def substitute_code_blocks(traits)
  traits.of_compiler.extension_substitutions.each do |ptn, repl|
    @tokens = create_extension_substitution(ptn, repl).execute(@tokens)
  end

  traits.of_compiler.arbitrary_substitutions.each do |ptn, repl|
    @tokens = create_arbitrary_substitution(ptn, repl).execute(@tokens)
  end

  create_inline_assembly_substitutions(self).each do |sub|
    @tokens = sub.execute(@tokens)
  end

  self
end

#to_sObject



78
79
80
81
82
83
84
85
86
87
# File 'lib/adlint/cpp/source.rb', line 78

def to_s
  @lst_fpath     = nil
  @lst_line_no   = 0
  @lst_column_no = 1
  @lst_token     = nil
  @io = StringIO.new
  @io.set_encoding(Encoding.default_external)
  @tokens.each { |tok| print(tok) }
  @io.string
end