Class: Rucc::Lexer::Preprocessor

Inherits:
Object
  • Object
show all
Includes:
Constructor, Pragma, SpecialMacro
Defined in:
lib/rucc/lexer/preprocessor.rb,
lib/rucc/lexer/preprocessor/pragma.rb,
lib/rucc/lexer/preprocessor/cond_incl.rb,
lib/rucc/lexer/preprocessor/constructor.rb,
lib/rucc/lexer/preprocessor/special_macro.rb

Defined Under Namespace

Modules: CondInclCtx, Constructor, Pragma, SpecialMacro Classes: CondIncl

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Constructor

#copy_token, #define_obj_macro, #make_cond_incl, #make_func_macro, #make_macro_token, #make_obj_macro, #make_special_macro

Constructor Details

#initialize(impl) ⇒ Preprocessor

Returns a new instance of Preprocessor.

Parameters:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rucc/lexer/preprocessor.rb', line 17

def initialize(impl)
  @impl = impl
  @std_include_path = []

  # preprocessor context
  @cond_incl_stack = []
  @macros = {}
  @once = {}
  @include_guard = {}

  # warning context
  # TODO(south37) Impl warnf
  @enable_warning = true

  # Used for __DATE__ and __TIME__
  @now = Time.now

  define_special_macros!
end

Instance Attribute Details

#expr_reader=(value) ⇒ Object (writeonly)

Return parsed node, only used for read_constexpr



38
39
40
# File 'lib/rucc/lexer/preprocessor.rb', line 38

def expr_reader=(value)
  @expr_reader = value
end

Instance Method Details

#append_include_path(path) ⇒ Object

Parameters:

  • path (String)


67
68
69
# File 'lib/rucc/lexer/preprocessor.rb', line 67

def append_include_path(path)
  @std_include_path << path
end

#peek_tokenToken

Returns:



60
61
62
63
64
# File 'lib/rucc/lexer/preprocessor.rb', line 60

def peek_token
  r = read_token
  unget_token(r)
  r
end

#read_tokenToken

Returns:



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rucc/lexer/preprocessor.rb', line 41

def read_token
  while true
    tok = read_expand
    if tok.bol && Token.is_keyword?(tok, '#') && (tok.hideset.size == 0)
      read_directive(tok)
      next
    end
    Util.assert!{ !T::CPP_TOKENS.include?(tok.kind) }
    return maybe_convert_keyword(tok)
  end
  raise "Must not reach here!"
end

#unget_token(tok) ⇒ Object

Parameters:



55
56
57
# File 'lib/rucc/lexer/preprocessor.rb', line 55

def unget_token(tok)
  @impl.unget_token(tok)
end