Reflection¶
Usage
use Reflection;
or
import Reflection;
Support for reflecting about properties of a Chapel program’s code.
Functions for reflecting about language elements, such as fields, functions, and methods.
Note
There are several ways in which this module could be improved:
the methods here might be better as type methods, so you could use R.numFields() instead of numFields(R).
getField
does not yet return a mutable value.
Note
For reflecting about aspects of the compilation process, see
ChplConfig
.
- proc numFields(type t) param: int¶
Return the number of fields in a class or record as a param. The count of fields includes types and param fields.
- proc getFieldName(type t, param idx: int) param: string¶
Get the name of the field at idx in a class or record. Causes a compilation error if idx is not in 0..<numFields(t).
- Arguments
t – a class or record type
idx – which field to get the name of
- Returns
the name of the field, as a param string
- proc getFieldName(type t, param i: int) param: string
Get the name of the field at i in a class or record. Causes a compilation error if i is not in 0..<numFields(t).
- Arguments
t – a class or record type
i – which field to get the name of
- Returns
the name of the field, as a param string
Warning
Formal ‘i’ is deprecated, please use ‘idx’ instead
- proc getField(const ref obj: ?t, param idx: int) param¶
Get the field at idx in a class or record. When the field at idx is a param, this overload will be chosen to return a param. Causes a compilation error if idx is not in 0..<numFields(t).
- Arguments
obj – a class or record
idx – which field to get
- Returns
the param that field represents
- proc getField(const ref x: ?t, param i: int) param
Get the ith field in a class or record. When the ith field is a param, this overload will be chosen to return a param. Causes a compilation error if i is not in 0..<numFields(t).
- Arguments
x – a class or record
i – which field to get
- Returns
the param that field represents
Warning
The formals ‘x’ and ‘i’ are deprecated, please use ‘obj’ and ‘idx’ instead
- proc getField(const ref obj: ?t, param idx: int) type
Get the field at idx in a class or record. When the field at idx is a type variable, this overload will be chosen to return a type. Causes a compilation error if idx is not in 0..<numFields(t).
- Arguments
obj – a class or record
idx – which field to get
- Returns
the type that field represents
- proc getField(const ref x: ?t, param i: int) type
Get the ith field in a class or record. When the ith field is a type variable, this overload will be chosen to return a type. Causes a compilation error if i is not in 0..<numFields(t).
- Arguments
x – a class or record
i – which field to get
- Returns
the type that field represents
Warning
The formals ‘x’ and ‘i’ are deprecated, please use ‘obj’ and ‘idx’ instead
- proc getField(const ref obj: ?t, param idx: int) const ref
Get the field at idx in a class or record. Causes a compilation error if idx is not in 0..<numFields(t).
- Arguments
obj – a class or record
idx – which field to get
- Returns
an rvalue referring to that field.
- proc getField(const ref x: ?t, param i: int) const ref
Get the ith field in a class or record. Causes a compilation error if i is not in 0..<numFields(t).
- Arguments
x – a class or record
i – which field to get
- Returns
an rvalue referring to that field.
Warning
The formals ‘x’ and ‘i’ are deprecated, please use ‘obj’ and ‘idx’ instead
- proc getField(const ref obj: ?t, param name: string) param
Get a field in a class or record by name. When the named field is a param, this overload will be chosen to return a param. Will generate a compilation error if a field named name is not found.
- Arguments
obj – a class or record
name – the name of a field
- Returns
the param that field represents
- proc getField(const ref x: ?t, param s: string) param
Get a field in a class or record by name. When the named field is a param, this overload will be chosen to return a param. Will generate a compilation error if a field with that name is not found.
- Arguments
x – a class or record
s – the name of a field
- Returns
the param that field represents
Warning
The formals ‘x’ and ‘s’ are deprecated, please use ‘obj’ and ‘name’ instead
- proc getField(const ref obj: ?t, param name: string) type
Get a field in a class or record by name. When the named field is a type variable, this overload will be chosen to return a type. Will generate a compilation error if a field named name is not found.
- Arguments
obj – a class or record
name – the name of a field
- Returns
the type that field represents
- proc getField(const ref x: ?t, param s: string) type
Get a field in a class or record by name. When the named field is a type variable, this overload will be chosen to return a type. Will generate a compilation error if a field with that name is not found.
- Arguments
x – a class or record
s – the name of a field
- Returns
the type that field represents
Warning
The formals ‘x’ and ‘s’ are deprecated, please use ‘obj’ and ‘name’ instead
- proc getField(const ref obj: ?t, param name: string) const ref
Get a field in a class or record by name. Will generate a compilation error if a field named name is not found.
- Arguments
obj – a class or record
name – the name of a field
- Returns
an rvalue referring to that field.
- proc getField(const ref x: ?t, param s: string) const ref
Get a field in a class or record by name. Will generate a compilation error if a field with that name is not found.
- Arguments
x – a class or record
s – the name of a field
- Returns
an rvalue referring to that field.
Warning
The formals ‘x’ and ‘s’ are deprecated, please use ‘obj’ and ‘name’ instead
- proc getFieldRef(ref x: ?t, param i: int) ref¶
Get a mutable ref to the ith field in a class or record. Causes a compilation error if i is not in 0..<numFields(t) or if the argument is not mutable.
- Arguments
x – a class or record
i – which field to get
- Returns
an rvalue referring to that field.
- proc getFieldRef(ref x: ?t, param s: string) ref
Get a mutable ref to a field in a class or record by name. Will generate a compilation error if a field with that name is not found or if the class or record is not mutable.
- Arguments
x – a class or record
s – the name of a field
- Returns
an rvalue referring to that field.
- proc getFieldIndex(type t, param name: string) param: int¶
Get the index of a field named name in a class or record type t, or
-1
if the field name is not found.- Arguments
t – a class or record type
name – the name of a field
- Returns
an index usable in
getField
, or-1
if the field was not found.
- proc getFieldIndex(type t, param s: string) param: int
Get a field index in a class or record, or
-1
if the field is not found.- Arguments
t – a class or record type
s – the name of a field
- Returns
an index usable in
getField
, or-1
if the field was not found.
Warning
The formal ‘s’ is deprecated, please use ‘name’ instead
- proc hasField(type t, param name: string) param: bool¶
Returns
true
if a class or record has a field named name, orfalse
otherwise.- Arguments
t – a class or record type
name – the name of a field
- Returns
true
if the field is present.
- proc hasField(type t, param s: string) param: bool
Returns
true
if a class or record has a field named s, orfalse
otherwise.- Arguments
t – a class or record type
s – the name of a field
- Returns
true
if the field is present.
Warning
The formal ‘s’ is deprecated, please use ‘name’ instead
- proc isFieldBound(type t, param idx: int) param: bool¶
Returns
true
if the field at idx has been instantiated in a given class or record type t.- Arguments
t – a class or record type
idx – which field to query
- Returns
true
if the field is instantiated
- proc isFieldBound(type t, param i: int) param: bool
Returns
true
if the given class or record’s ith field has been instantiated.- Arguments
t – a class or record type
i – which field to query
- Returns
true
if the field is instantiated
Warning
The formal ‘i’ is deprecated, please use ‘idx’ instead
- proc isFieldBound(type t, param name: string) param: bool
Returns
true
if the field named name has been instantiated in a given class or record type t.- Arguments
t – a class or record type
name – the name of a field
- Returns
true
if the field is instantiated
- proc isFieldBound(type t, param s: string) param: bool
Returns
true
if the given class or record’s field named s has been instantiated.- Arguments
t – a class or record type
s – the name of a field
- Returns
true
if the field is instantiated
Warning
The formal ‘s’ is deprecated, please use ‘name’ instead
- proc canResolve(param fname: string) param: bool¶
Returns
true
if a function named fname taking no arguments could be called in the current scope.
- proc canResolve(param fname: string, args ...) param: bool
Returns
true
if a function named fname taking the arguments in args could be called in the current scope.
- proc canResolveMethod(obj, param fname: string) param: bool¶
Returns
true
if a method named fname taking no arguments could be called on obj in the current scope.
- proc canResolveMethod(obj, param fname: string, args ...) param: bool
Returns
true
if a method named fname taking the arguments in args could be called on obj in the current scope.
- proc canResolveTypeMethod(type t, param fname: string) param: bool¶
Returns
true
if a type method named fname taking no arguments could be called on type t in the current scope.
- proc canResolveTypeMethod(type t, param fname: string, args ...) param: bool
Returns
true
if a type method named fname taking the arguments in args could be called on type t in the current scope.
- proc getLineNumber() param: int¶
Returns the line number of the call to this function.
- proc getFileName() param: string¶
Returns the file name this function was called from.
- proc getRoutineName() param: string¶
Returns the name of the function this function was called from.
- proc getModuleName() param: string¶
Returns the name of the module this function was called from.