Expr

Evaluates an expression and discards its value.

Declaration

Syntax

Expr(expr expression)

Arguments

Argument

Description

expression

the expression to evaluate.

Return values

None.

Description

Fortran has no expression statement: a function whose result is not wanted is called with call only if it is a subroutine. Expr exists for LPython, where f(x) is a statement, and for compiler-generated code that needs an expression evaluated for its effect.

Examples

(Expr
  :expression (FunctionCall
    :name (SymbolRef 1 "next")
    :original_name nil
    :args [
      (call_arg
        :value (Var
          :v (SymbolRef 2 "a")
        )
      )
    ]
    :type (Integer
      :kind 4
    )
    :value nil
    :dt nil
  )
)

It comes from this complete ASR text document:

(TranslationUnit
  :symtab (SymbolTable
    :id 0
    :symbols {
      "m" (Module
        :symtab (SymbolTable
          :id 1
          :symbols {
            "next" (Function
              :symtab (SymbolTable
                :id 2
                :symbols {
                  "a" (Variable
                    :parent_symtab 2
                    :name "a"
                    :dependencies []
                    :intent :In
                    :symbolic_value nil
                    :value nil
                    :storage :Default
                    :type (Integer
                      :kind 4
                    )
                    :type_declaration nil
                    :abi :Source
                    :access :Public
                    :presence :Required
                    :value_attr false
                    :target_attr false
                    :contiguous_attr false
                    :bindc_name nil
                    :is_volatile false
                    :is_protected false
                    :pass_attr :NotMethod
                    :self_argument nil
                    :codims []
                  )
                  "b" (Variable
                    :parent_symtab 2
                    :name "b"
                    :dependencies []
                    :intent :ReturnVar
                    :symbolic_value nil
                    :value nil
                    :storage :Default
                    :type (Integer
                      :kind 4
                    )
                    :type_declaration nil
                    :abi :Source
                    :access :Public
                    :presence :Required
                    :value_attr false
                    :target_attr false
                    :contiguous_attr false
                    :bindc_name nil
                    :is_volatile false
                    :is_protected false
                    :pass_attr :NotMethod
                    :self_argument nil
                    :codims []
                  )
                }
              )
              :name "next"
              :function_signature (FunctionType
                :arg_types [
                  (Integer
                    :kind 4
                  )
                ]
                :return_var_type (Integer
                  :kind 4
                )
                :abi :Source
                :deftype :Implementation
                :bindc_name nil
                :elemental false
                :pure false
                :module false
                :inline false
                :static false
                :restrictions []
                :is_restriction false
              )
              :dependencies [
                "next"
              ]
              :args [
                (Var
                  :v (SymbolRef 2 "a")
                )
              ]
              :body [
                (Assignment
                  :target (Var
                    :v (SymbolRef 2 "b")
                  )
                  :value (IntegerBinOp
                    :left (Var
                      :v (SymbolRef 2 "a")
                    )
                    :op :Add
                    :right (IntegerConstant
                      :n 1
                      :type (Integer
                        :kind 4
                      )
                      :intboz_type :Decimal
                    )
                    :type (Integer
                      :kind 4
                    )
                    :value nil
                  )
                  :overloaded nil
                  :realloc_lhs false
                  :move_allocation false
                )
                (Expr
                  :expression (FunctionCall
                    :name (SymbolRef 1 "next")
                    :original_name nil
                    :args [
                      (call_arg
                        :value (Var
                          :v (SymbolRef 2 "a")
                        )
                      )
                    ]
                    :type (Integer
                      :kind 4
                    )
                    :value nil
                    :dt nil
                  )
                )
              ]
              :return_var (Var
                :v (SymbolRef 2 "b")
              )
              :access :Public
              :deterministic false
              :side_effect_free false
              :module_file nil
            )
          }
        )
        :name "m"
        :parent_module nil
        :dependencies []
        :loaded_from_mod false
        :intrinsic false
        :has_submodules false
      )
      "main" (Program
        :symtab (SymbolTable
          :id 3
          :symbols {}
        )
        :name "main"
        :dependencies []
        :body []
      )
    }
  )
  :items []
)

See Also

Assignment, SubroutineCall, FunctionCall