Chapter 17. Queries

Table of Contents

17.1. Query Variables
17.2. Invocation of Queries
17.3. Compound Predicates
17.3.1. Places
17.3.2. Connected Predicates
17.3.3. Connecting Primary Predicates
17.4. Simple Predicates
17.4.1. Predicate Arguments
17.4.2. Label Arguments
17.4.3. Name Predicates
17.4.4. Parametrized Predicates
17.4.5. Type Predicates
17.4.6. Wrapped Type Predicates
17.4.7. Expression Predicates
17.4.8. Method Predicates
17.4.9. Class Predicates
17.4.10. Root Predicate
17.5. Path Predicates
17.5.1. Name Path Predicates
17.5.2. Parametrized Path Predicates
17.5.3. Method Path Predicates
17.5.4. Expression Edge Predicates
17.5.5. Standard Edge Predicates
17.5.6. Constant Edge Predicates
17.6. Control Flow Predicates
17.6.1. First Element Predicate
17.6.2. Transitive Closures
17.6.3. Minimal Elements Predicate

Queries are used in rules and query expressions (Section 16.4, “Query Expressions”) to specify a pattern. At run-time, occurences of this pattern in the current relational data source (to be more precise, in its extent, Section 3.2, “Run-Time Model”) are searched. The query syntax provides versatile means for specifying patterns, including a rich set of built-in predicates, user-defined predicates, and transitive closures.

A query consists of a set of predicates and query variables. The sequential evaluation of a query binds values to query variables in order to fulfil the conditions imposed by the predicates. If a complete binding has been found which matches all predicates, this match is yielded as one of the results of the query. The current binding of query variables is part of the query state.

In the sequel, the predicates of the XL programming language are described. Each predicate is specified by the following properties:

17.1. Query Variables

Query variables are a special kind of local variables. They are implicitly final in the sense of the Java programming language. It is illegal to assign values to query variables, even in their declaration. Instead of this, values are bound to query variables as part of the sequential evaluation of a query; this evaluation is performed by the run-time system of the XL programming language.

Query variables are declared explicitly by compound predicates and some other predicates, or implicitly by a compiler for the XL programming language where this is needed. The identifiers of the latter have to be generated such that they are distinct from any other identifier.

An explicitly declared query variable v is a label for a place (Section 17.3.1, “Places”). If the place is a node place and a wrapper is needed for the type of v (Section 3.1, “Compile-Time Model”) in order to represent its values as nodes, v is wrapped by another query variable which is called the v's wrapper variable (Section 17.3.1, “Places”). The identifier of the wrapper variable is the identifier of v with the single character $ prepended.

Query variables are represented by instances of VMXState.Local, i.e., their values are stored on the stack of the extended state of the virtual machine (Chapter 4, Extended State of the Virtual Machine). Otherwise, the run-time system of the XL programming language would not be able to bind values to these variables.