PointerAssociated

Whether a pointer is associated, or associated with a particular target.

Declaration

Syntax

PointerAssociated(expr ptr, expr? tgt, ttype type, expr? value)

Arguments

Argument

Description

ptr

the pointer to test.

tgt

the target to compare against, or nil to test only whether the pointer is associated.

type

the logical type of the result.

value

the compile time value of the expression, when the frontend could fold it; nil otherwise.

Return values

The value of the expression.

Description

associated(p) and associated(p, t). With a target the test is whether the pointer refers to that particular object, which is not the same question as whether it refers to anything.

Examples

(PointerAssociated
  :ptr (Var
    :v (SymbolRef 1 "p")
  )
  :tgt (Var
    :v (SymbolRef 1 "target")
  )
  :type (Logical
    :kind 4
  )
  :value nil
)

It comes from this complete ASR text document:

(TranslationUnit
  :symtab (SymbolTable
    :id 0
    :symbols {
      "main" (Program
        :symtab (SymbolTable
          :id 1
          :symbols {
            "b" (Variable
              :parent_symtab 1
              :name "b"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Logical
                :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 []
            )
            "c" (Variable
              :parent_symtab 1
              :name "c"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (CPtr)
              :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 []
            )
            "n" (Variable
              :parent_symtab 1
              :name "n"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Integer
                :kind 8
              )
              :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 []
            )
            "p" (Variable
              :parent_symtab 1
              :name "p"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Pointer
                :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 []
            )
            "target" (Variable
              :parent_symtab 1
              :name "target"
              :dependencies []
              :intent :Local
              :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 true
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
          }
        )
        :name "main"
        :dependencies []
        :body [
          (Assignment
            :target (Var
              :v (SymbolRef 1 "c")
            )
            :value (CLoc
              :arg (Var
                :v (SymbolRef 1 "target")
              )
              :type (CPtr)
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "c")
            )
            :value (PointerToCPtr
              :arg (Var
                :v (SymbolRef 1 "p")
              )
              :type (CPtr)
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Associate
            :target (Var
              :v (SymbolRef 1 "p")
            )
            :value (GetPointer
              :arg (Var
                :v (SymbolRef 1 "target")
              )
              :type (Pointer
                :type (Integer
                  :kind 4
                )
              )
              :value nil
            )
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "b")
            )
            :value (CPtrCompare
              :left (Var
                :v (SymbolRef 1 "c")
              )
              :op :Eq
              :right (Var
                :v (SymbolRef 1 "c")
              )
              :type (Logical
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "b")
            )
            :value (PointerAssociated
              :ptr (Var
                :v (SymbolRef 1 "p")
              )
              :tgt (Var
                :v (SymbolRef 1 "target")
              )
              :type (Logical
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "n")
            )
            :value (SizeOfType
              :arg (Integer
                :kind 4
              )
              :type (Integer
                :kind 8
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
        ]
      )
    }
  )
  :items []
)

See Also

Nullify, PointerNullConstant, GetPointer