Class: Idl::BitfieldFieldDefinitionAst

Inherits:
AstNode
  • Object
show all
Defined in:
lib/idl/ast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, interval, name, msb, lsb) ⇒ BitfieldFieldDefinitionAst

Returns a new instance of BitfieldFieldDefinitionAst.



1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
# File 'lib/idl/ast.rb', line 1168

def initialize(input, interval, name, msb, lsb)
  if lsb.nil?
    super(input, interval, [msb])
  else
    super(input, interval, [msb, lsb])
  end

  @name = name
  @lsb = lsb
  @msb = msb
end

Instance Attribute Details

#nameString (readonly)

Returns The field name.

Returns:

  • (String)

    The field name



1166
1167
1168
# File 'lib/idl/ast.rb', line 1166

def name
  @name
end

Instance Method Details

#range(symtab) ⇒ Object

Returns Range The field’s location in the bitfield.

Returns:

  • Range The field’s location in the bitfield



1203
1204
1205
1206
1207
1208
1209
# File 'lib/idl/ast.rb', line 1203

def range(symtab)
  if @lsb.nil?
    @msb.value(symtab)..@msb.value(symtab)
  else
    @lsb.value(symtab)..@msb.value(symtab)
  end
end

#to_idlObject



1211
1212
1213
1214
1215
1216
1217
# File 'lib/idl/ast.rb', line 1211

def to_idl
  if @lsb.nil?
    "#{@name} #{@msb.to_idl}"
  else
    "#{@name} #{@msb.to_idl}-#{@lsb.to_idl}"
  end
end

#type_check(symtab) ⇒ void

This method returns an undefined value.

type check this node and all children

Calls to #type and/or #value may depend on type_check being called first with the same symtab. If not, those functions may raise an AstNode::InternalError

Parameters:

Raises:



1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
# File 'lib/idl/ast.rb', line 1181

def type_check(symtab)
  @msb.type_check(symtab)

  value_result = value_try do
    @msb.value(symtab)
  end
  value_else(value_result) do
    @msb.type_error "Bitfield position must be compile-time-known"
  end

  return if @lsb.nil?

  @lsb.type_check(symtab)
  value_result = value_try do
    @lsb.value(symtab)
  end
  value_else(value_result) do
    @lsb.type_error "Bitfield position must be compile-time-known"
  end
end