next up previous
Next: Location shifting Up: Operators Previous: Operator new

Restricted type conversion

When an array has position information in its dimensions, Location references, instead of int values are used as indexes. Given a global index we can get a location reference by | operation from the range. Sometimes it is also convenient that given a location reference, we can get the order of the Location in a range. So a type conversion is defined from Location to int inside at and over constructs.

  on(q)
    over(Location i= x|0:3) {
      b[i]=(int)i;
    }

will assign the location id to each array element. It is equevalent to,

  on(q)
    over(Location i= x|0:3) {
      b[i]=x.id(i);
    }

Whenever necessary, this conversion can be an implicit one.

We call it as a restricted coversion, because it works only with at and over constructs. For example,

  on(q)
    over(Location i= x|0:3) {
      Location j=i;
      b[i]=j;          //error;
      
      Range y=x;   
      Location k=y|i;  //correct;
      b[i]=k;          //error;
    }



Guansong Zhang
Thu Nov 13 17:36:47 EST 1997