Class: Ibex::IR::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/ir/grammar_ir.rb,
sig/ibex/ir/grammar_ir.rbs

Overview

Opaque Ruby semantic action metadata.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, location:, named_refs: [], context_length: 0, composition: nil) ⇒ Action

Returns a new instance of Action.

RBS:

  • (code: String, location: location, ?named_refs: Array[named_ref], ?context_length: Integer, ?composition: action_composition?) -> void

Parameters:

  • code: (String)
  • location: (location)
  • named_refs: (Array[named_ref]) (defaults to: [])
  • context_length: (Integer) (defaults to: 0)
  • composition: (action_composition, nil) (defaults to: nil)


76
77
78
79
80
81
82
83
# File 'lib/ibex/ir/grammar_ir.rb', line 76

def initialize(code:, location:, named_refs: [], context_length: 0, composition: nil)
  @code = code.freeze
  @location = IR.deep_freeze(location)
  @named_refs = IR.deep_freeze(named_refs)
  @context_length = context_length
  @composition = IR.deep_freeze(composition)
  freeze
end

Instance Attribute Details

#codeString (readonly)

Signature:

  • String

Returns:

  • (String)


68
69
70
# File 'lib/ibex/ir/grammar_ir.rb', line 68

def code
  @code
end

#compositionaction_composition? (readonly)

Signature:

  • action_composition?

Returns:

  • (action_composition, nil)


72
73
74
# File 'lib/ibex/ir/grammar_ir.rb', line 72

def composition
  @composition
end

#context_lengthInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


71
72
73
# File 'lib/ibex/ir/grammar_ir.rb', line 71

def context_length
  @context_length
end

#locationlocation (readonly)

Signature:

  • location

Returns:



69
70
71
# File 'lib/ibex/ir/grammar_ir.rb', line 69

def location
  @location
end

#named_refsArray[named_ref] (readonly)

Signature:

  • Array[named_ref]

Returns:

  • (Array[named_ref])


70
71
72
# File 'lib/ibex/ir/grammar_ir.rb', line 70

def named_refs
  @named_refs
end

Instance Method Details

#to_h(schema_version: SCHEMA_VERSION) ⇒ Hash[Symbol, untyped]

RBS:

  • (?schema_version: Integer) -> Hash[Symbol, untyped]

Parameters:

  • schema_version: (Integer) (defaults to: SCHEMA_VERSION)

Returns:

  • (Hash[Symbol, untyped])


86
87
88
89
90
91
# File 'lib/ibex/ir/grammar_ir.rb', line 86

def to_h(schema_version: SCHEMA_VERSION)
  value = { code: @code, loc: @location, named_refs: @named_refs,
            context_length: @context_length } #: Hash[Symbol, untyped]
  value[:composition] = @composition if schema_version >= 2
  value
end