ACT Library
|
Dense arrays, sparse arrays, and array dereferences. More...
#include <act_array.h>
Classes | |
struct | _act_array_expr_pair |
A range specifier that can include parameters/etc. This is used during parsing, prior to expansion. More... | |
struct | _act_array_exprex_pair |
A range specifier post expansion where all parameters/etc. are substituted, resulting in a constant range. More... | |
struct | _act_array_internal |
Used to hold the result of an expanded array range reference. More... | |
struct | range |
Public Member Functions | |
int | isSparse () |
int | isDeref () |
void | mkArray () |
int | nDims () |
int | effDims () |
void | Concat (Array *a) |
void | preConcat (Array *a) |
int | isEqual (Array *a, int strict) |
int | isDimCompatible (Array *a) |
void | Merge (Array *a) |
Array (Expr *e, Expr *f=NULL) | |
Array (int lo, int hi) | |
Array (int idx) | |
~Array () | |
void | Print (FILE *fp, int style=0) |
void | sPrint (char *buf, int sz, int style=0) |
int | sPrintOne (char *buf, int sz, int style=0) |
void | PrintOne (FILE *fp, int style=0) |
Array * | Next () |
Array * | Clone () |
returns a deep copy of the entire array | |
Array * | CloneOne () |
only return a deep copy of the current dense range | |
Array * | Reduce () |
int | isExpanded () |
int | size () |
int | range_size (int d) |
void | update_range (int d, int lo, int hi) |
int | isrange (int d) |
Expr * | lo (int d) |
Expr * | hi (int d) |
Array * | Expand (ActNamespace *ns, Scope *s, int is_ref=0) |
Array * | ExpandRef (ActNamespace *ns, Scope *s) |
Array * | ExpandRefCHP (ActNamespace *ns, Scope *s) |
int | Validate (Array *a) |
int | isDynamicDeref () |
Expr * | getDeref (int idx) |
int | Offset (Array *a) |
int | Offset (int *a) |
Array * | unOffset (int offset) |
Arraystep * | stepper (Array *sub=NULL) |
Private Member Functions | |
Array () | |
int | in_range (Array *a) |
offset within a range, -1 if missing | |
int | in_range (int *a) |
offset within a range, -1 if missing | |
void | dumprange (struct range *r) |
void | _merge_range (int idx, Array *prev, struct range *m) |
int | overlapping (struct range *a, struct range *b) |
Private Attributes | |
int | dims |
struct Array::range * | r |
unsigned int | range_sz |
Array * | next |
unsigned int | deref:1 |
unsigned int | expanded:1 |
Friends | |
class | Arraystep |
Dense arrays, sparse arrays, and array dereferences.
Used to represent a set of dense ranges/derefs If a sub-range specifier is not used, then the "deref" field is set to 1—it means the user wrote [x] rather than [x..y] for every dimension of the array.
This class is also used to represent a sparse array. In this case, the array is represented as a list of dense sub-arrays. The next field is used to build the linked list of dense components of the sparse array.
This class is also used to represent a "de-reference" as part of an identifier. De-references are either constant values, or may contain a variable (e.g. a de-reference within a CHP body). De-references with variables are called "dynamic", because their value cannot be determined statically.
The elements within an array are also numbered sequentially. This provides a linear addressing mechanism for the array elements, making it simple to write loops that iterate over the array. The numbers are from 0 to size()-1. This numbering can be used once the array is expanded for arrays that are not de-references.
Create a new one-dimensional dense unexpanded array.
e | is an integer expression corresponding to the size of the array |
f | is an integer expression. If f is not NULL, then the array range is e..f; otherwise it is 0..(e-1). |
Array::Array | ( | int | lo, |
int | hi | ||
) |
Create a new one-dimensional dense expanded array.
lo | is the low end of the range |
hi | is the high end of the range |
Array::Array | ( | int | idx | ) |
Create a de-reference corresponding to the specified index
idx | is the index of the de-reference |
Array::~Array | ( | ) |
|
private |
for deep copy only
Used to merge a range into the current array. This is the ordered merge algorithm used to have a canonical representation of a sparse array as a collection of dense blocks.
idx | is the dimension to be merged |
prev | is the previous (if any) pointer for the array |
m | is the new range to be merged in |
Array * Array::Clone | ( | ) |
returns a deep copy of the entire array
Array * Array::CloneOne | ( | ) |
only return a deep copy of the current dense range
void Array::Concat | ( | Array * | a | ) |
Append array dimensions from the argument into the current array. The current array must be dense.
a | contains the arguments to be merged, which must be a dense array |
Updates the current array with the additional dimensions from parameter a
|
private |
used for debugging
int Array::effDims | ( | ) |
Array * Array::Expand | ( | ActNamespace * | ns, |
Scope * | s, | ||
int | is_ref = 0 |
||
) |
Return expanded array.
ns | is the namespace |
s | is the scope for evaluation |
is_ref | 1 if it is on the rhs of an ID, 0 if it is for a type. |
|
inline |
Array * Array::ExpandRefCHP | ( | ActNamespace * | ns, |
Scope * | s | ||
) |
Expr * Array::getDeref | ( | int | idx | ) |
Must be called on an expanded array that is in fact an array dereference.
idx | is the dimension of the array of interest |
|
inline |
Returns the hi expression for dimension d This only works for unexpanded arrays.
d | is the dimension of interest |
|
private |
offset within a range, -1 if missing
|
private |
offset within a range, -1 if missing
|
inline |
int Array::isDimCompatible | ( | Array * | a | ) |
Check if two arrays have compatible parameters (matching dimensions)
int Array::isDynamicDeref | ( | ) |
Checks to see if this array includes a dynamic de-reference
int Array::isEqual | ( | Array * | a, |
int | strict | ||
) |
Check if two array derefs are identical. If the arrays are not expanded, then the syntax of the expressions are checked in a strict manner. If the arrays are expanded, then the values are checked.
a | is the other array for comparison |
strict | is 1 if the low and high indices must match; 0 means the sizes must match. |
|
inline |
returns 1 if this is an expanded array, 0 otherwise
|
inline |
|
inline |
|
inline |
Returns the lo expression for dimension d This only works for unexpanded arrays.
d | is the dimension of interest |
void Array::Merge | ( | Array * | a | ) |
Merge a second array into this one. Used to construct sparse array types. Both must be expanded.
a | is the other array that has to be combined with the current one. |
|
inline |
Force this to be an array, not a deref. Used to override type specifier for compact foo f[n] which is shorthand for foo[0..n-1]
|
inline |
|
inline |
int Array::Offset | ( | Array * | a | ) |
Given an array deference or subrange, returns the offset for the first element of the sub-range/dereference in the standard linear numbering of the elements of the array
a | is the de-reference/sub-range specifier to look for |
int Array::Offset | ( | int * | a | ) |
Same as the other Offset() function, except the de-reference corresponds to a set of constant indices.
a | is the de-reference index |
Checks if two ranges have a non-empty intersection
a | is one of the two ranges |
b | is one of the two ranges |
void Array::preConcat | ( | Array * | a | ) |
Same as Concat(), except append dimensions starting from position 0, rather than adding to the dimensions at the end
a | contains the argument to be merged into the current array |
void Array::Print | ( | FILE * | fp, |
int | style = 0 |
||
) |
Print the array out to the specified file. Arrays can be printed in two styles: [num][num] (style=0), or [num,num] (style=1).
fp | is the output file |
style | is the printing style |
void Array::PrintOne | ( | FILE * | fp, |
int | style = 0 |
||
) |
This is similar to sPrintOne(), except it prints the output to a file.
fp | is the output file |
style | is the printing style |
int Array::range_size | ( | int | d | ) |
returns size of a particular dimension. Only works for expanded arrays.
Array * Array::Reduce | ( | ) |
return a deep copy, but elide dimensions that are derefs
int Array::size | ( | ) |
returns total number of elements. Only works for expanded arrays
void Array::sPrint | ( | char * | buf, |
int | sz, | ||
int | style = 0 |
||
) |
Similar to Print(), but writes the output to a buffer.
buf | is the output buffer |
sz | is the size of the output buffer |
style | is the printing style |
int Array::sPrintOne | ( | char * | buf, |
int | sz, | ||
int | style = 0 |
||
) |
This prints out the first dense component of a sparse array.
buf | is the output buffer |
sz | is the size of the output buffer |
style | is the printing style |
Stepper/iterator functionality. This returns an array "stepper" that allows you to step through the elements of the array. If a sub-range specifier is included, then the stepper only steps through the subrange within the array.
sub | is the sub-range specifier, NULL if not needed |
Array * Array::unOffset | ( | int | offset | ) |
Convert a linear offset into an array into the corresponding array de-reference
offset | is the offset for the element of interest |
void Array::update_range | ( | int | d, |
int | lo, | ||
int | hi | ||
) |
Set the range for dimension d to lo .. hi. Only works for expanded arrays.
d | is the dimension of the range to be updated |
lo | is the new low range |
hi | is the new high range |
int Array::Validate | ( | Array * | a | ) |
Validate that the array indices specified in the argument are valid indicies for the array. This must be called on an expanded array.
a | is the Array that contains the indices of interest |
|
friend |
|
private |
1 if this is a dereference, 0 otherwise
|
private |
number of dimensions
|
private |
1 if this is expanded, 0 otherwise
|
private |
for sparse arrays, used to link together dense blocks for each component of the sparse array.
|
private |
range for each dimension
|
private |
cache: size of the range; only for expanded arrays