Reflection¶
Usage
use Reflection;
Functions for finding out about fields, functions, and methods.
Note
There are several ways in which this module could be improved upon:
- 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.
-
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 i: int) param: string¶ Get the name of the ith field in a class or record. Causes a compilation error if i is not in 1..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
-
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 1..numFields(t).
Arguments: - x -- a class or record
- i -- which field to get
Returns: the param 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 1..numFields(t).
Arguments: - x -- a class or record
- i -- which field to get
Returns: the type that field represents
-
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 1..numFields(t).
Arguments: - x -- a class or record
- i -- which field to get
Returns: an rvalue referring to that field.
-
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
-
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
-
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.
-
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 1..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 s: string) param: int¶ Get a field index in a class or record, or 0 if the field is not found.
Arguments: - t -- a class or record type
- s -- the name of a field
Returns: an index i usable in getField, or 0 if the field was not found.
-
proc
hasField
(type t, param s: string) param: bool¶ Returns true if a class or record has a field named s, or false otherwise.
Arguments: - t -- a class or record type
- s -- the name of a field
Returns: true if the field is present.
-
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.