Class: Idl::DollarFunctionCallSyntaxNode

Inherits:
SyntaxNode show all
Defined in:
lib/idlc/ast.rb

Overview

Generic syntax node for $name(arg, ...) — dispatches to the correct typed AstNode in to_ast.

Instance Method Summary collapse

Methods inherited from Treetop::Runtime::SyntaxNode

#set_input_file, #set_input_file_unless_already_set, #space?

Instance Method Details

#to_astObject



5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
# File 'lib/idlc/ast.rb', line 5793

def to_ast
  dollar_name = "$#{send(:name).text_value}"
  arg_nodes = dollar_arg_list_elements
  enum_type_name_validation = {
    0 => {
      classes: [IdAst, UserTypeNameAst],
      description: "an identifier or user type name"
    }
  }

  case dollar_name
  when "$width"             then builtin_call_ast(dollar_name, arg_nodes, 1, WidthRevealAst)
  when "$signed"            then builtin_call_ast(dollar_name, arg_nodes, 1, SignCastAst)
  when "$bits"              then builtin_call_ast(dollar_name, arg_nodes, 1, BitsCastAst)
  when "$enum_size"         then builtin_call_ast(dollar_name, arg_nodes, 1, EnumSizeAst, enum_type_name_validation)
  when "$enum_element_size" then builtin_call_ast(dollar_name, arg_nodes, 1, EnumElementSizeAst, enum_type_name_validation)
  when "$enum_to_a"         then builtin_call_ast(dollar_name, arg_nodes, 1, EnumArrayCastAst, enum_type_name_validation)
  when "$enum"              then builtin_call_ast(dollar_name, arg_nodes, 2, EnumCastAst, enum_type_name_validation)
  when "$array_size"        then builtin_call_ast(dollar_name, arg_nodes, 1, ArraySizeAst)
  when "$array_includes?"   then builtin_call_ast(dollar_name, arg_nodes, 2, ArrayIncludesAst)
  else
    ParseTimeDetectedTypeError.new(input, interval, "#{dollar_name} is not a builtin function")
  end
end