wiki:SemanticQuery/ExpressionEntity

Version 4 (modified by manualwiki, 12 years ago) (diff)

--

Expression entity

Expressions are the basic syntactic elements of Erlang, and they are represented by expression entities. This is the only syntactic entity in the query language, it is mainly useful to express relations that cannot be calculated by selectors of other entities. Patterns and guards are also represented as expressions, however, there are syntactic units which are not expressions and cannot be handled in this query language, like clauses and module attributes.

Initial selector

  • @expr a query can be started from the currently selected expression using this selector.

Selectors

The following selectors work on expression entities.

Note that an expression is always treated as a single unit with its subexpressions, even in case expressions with more clauses, like if or case.

In parentheses you find the type of the result elements.

  • fundef (function): returns the function entity which contains the expression.
  • funs (function): returns every function entity referred directly in the expression.
  • vars (variable): returns every variable entity referred in the expression.
  • records (record): returns every record entity referred in the expression.
  • macros (macro): returns every macro entity referred in the expression.
  • sub (expression): returns the set of expressions that are nested in the expression in any depth. This is mainly useful together with the type property.
  • top (expression): returns the expression's top-level expression.
  • file (file): returns the file entity where the expression is located.
  • origin (expression): returns the origin of the expression's value determined by data-flow analysis.
  • reach (expression): returns the places where the expression's value is copied, determined by data-flow analysis.

Properties

These properties are defined for expression entities.

Note that some of them depends on the context of the expression, which makes possible selecting tail calls or indexing function arguments.

  • type (atom): returns the type of the expression. The type can be one of the following:
    • application: func(Arg1, ...)
    • implicit_fun: fun func/1
    • parenthesis: (Expr)
    • tuple: \{A, B, C\
    • binary: <<3.14/float>>
    • binary_field: 3.14/float in the previous binary
    • record_access: Rec#name.fld
    • record_expr: #name{fld=Val}
    • record_update: Rec#name{fld=Val}
    • record_index: #name.fld
    • match_expr: Pattern = Expr
    • send_expr: Pid ! Expr
    • 'bnot': bnot Expr (there are other prefix operators like this)
    • '+': A + B (there are other infix operators like this)
    • cons: [1, 2, 3 | Tail]
    • list: 1, 2, 3 in the previous list
    • nil: []
    • atom, char, float, integer, string: constants
    • variable: Var
    • catch_expr: catch Expr
    • list_comp: [A || A <- L, A > 0]
    • list_gen: A <- L in the previous list comprehension
    • filter: A > 0 in the previous list comprehension
    • bin_comp: {<< <<C/utf8>> || <<C:16>> <= Str >>}
    • binary_gen: <<C:16>> <= Str in the previous binary comprehension
    • block_expr: begin ... end
    • if_expr: if ... end
    • fun_expr: fun () -> ... end
    • receive_expr: receive ... end
    • case_expr: case Expr of ... end
    • try_expr: try ... end
  • value: returns the value of the expression. It is either the value of a constant expression or an operator of an operator-based expression.
  • class (atom): returns the class of the expression: it can be either expr (stands for single expressions), pattern, or guard.
  • last (bool): returns true if the expression is the last expression of the clause.
  • index (int): returns the index of the expression in the containing expression list.
  • tailcall (bool): returns true if the expression is a tail call. Tail call expressions are function applications, which are the last expressions of their containing clause.
  • macro_value (string): returns the value of the macro contained by the expression.