Class: Idl::ReturnStatementAst

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

Overview

represents a function return statement

for example:

return 5;
return X[rs1] + 1;

Instance Method Summary collapse

Constructor Details

#initialize(input, interval, return_expression) ⇒ ReturnStatementAst

Returns a new instance of ReturnStatementAst.



3928
3929
3930
# File 'lib/idl/ast.rb', line 3928

def initialize(input, interval, return_expression)
  super(input, interval, [return_expression])
end

Instance Method Details

#enclosing_functionObject



3957
3958
3959
# File 'lib/idl/ast.rb', line 3957

def enclosing_function
  return_expression.enclosing_function
end

#expected_return_type(symtab) ⇒ Type

Returns The expected return type (as defined by the encolsing function).

Returns:

  • (Type)

    The expected return type (as defined by the encolsing function)



3943
3944
3945
# File 'lib/idl/ast.rb', line 3943

def expected_return_type(symtab)
  return_expression.expected_return_type(symtab)
end

#return_expressionObject



3924
3925
3926
# File 'lib/idl/ast.rb', line 3924

def return_expression
  @children[0]
end

#return_type(symtab) ⇒ Type

Returns The actual return type.

Returns:

  • (Type)

    The actual return type



3938
3939
3940
# File 'lib/idl/ast.rb', line 3938

def return_type(symtab)
  return_expression.retrun_type(symtab)
end

#return_types(symtab) ⇒ Array<Type>

Returns List of actual return types.

Returns:

  • (Array<Type>)

    List of actual return types



3933
3934
3935
# File 'lib/idl/ast.rb', line 3933

def return_types(symtab)
  return_expression.return_types(symtab)
end

#return_value(symtab) ⇒ Integer, ...

Evaluate the compile-time return value of this node, or, if the node does not return (e.g., because it is an IfAst but there is no return on the taken path), execute the node and update the symtab

Parameters:

  • symtab (SymbolTable)

    The symbol table for the context

Returns:

  • (Integer)

    The return value, if it is integral

  • (Boolean)

    The return value, if it is boolean

  • (nil)

    if the return value is not compile-time-known

Raises:

  • ValueError if, during evaluation, a node without a compile-time value is found



3962
3963
3964
# File 'lib/idl/ast.rb', line 3962

def return_value(symtab)
  return_expression.return_value(symtab)
end

#return_value_nodesArray<AstNode>

Returns List of return value nodes.

Returns:

  • (Array<AstNode>)

    List of return value nodes



3953
3954
3955
# File 'lib/idl/ast.rb', line 3953

def return_value_nodes
  return_expression.return_value_nodes
end

#return_values(symtab) ⇒ Array<Integer>, Array<Boolean>

Evaluate all possible compile-time return values of this node, or, if the node does not return (e.g., because it is an IfAst but there is no return on a possible path), execute the node and update the symtab

Parameters:

  • symtab (SymbolTable)

    The symbol table for the context

Returns:

  • (Array<Integer>)

    The possible return values. Will be an empty array if there are no return values

  • (Array<Boolean>)

    The possible return values. Will be an empty array if there are no return values

Raises:

  • ValueError if, during evaluation, a node without a compile-time value is found



3967
3968
3969
# File 'lib/idl/ast.rb', line 3967

def return_values(symtab)
  return_expression.return_values(symtab)
end

#to_idlObject



3971
# File 'lib/idl/ast.rb', line 3971

def to_idl = "#{return_expression.to_idl};"

#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:



3948
3949
3950
# File 'lib/idl/ast.rb', line 3948

def type_check(symtab)
  return_expression.type_check(symtab)
end