ArrayTypeRewrite.jrag 1.04 KB
Newer Older
Anders Nilsson's avatar
Anders Nilsson committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
aspect ArrayRewrite {

  syn boolean Dim.isVariable() {
    for (int i = 0 ; i < getNumExp() ; i++) {
      if (getExp(i) instanceof VariableSize) {
	return true;
      }	
    }
    return false;
  }

  rewrite ParseArrayType {
    when (! getDim(0).isVariable()) 
    to FixedArrayType  { 
      if (getNumDim() == 1) {
        return new FixedArrayType(getType(), 
				  getDim(0).getExpList());
      } else {
        List l = new List();
        for (int i = 1 ; i < getNumDim() ; i++) {
	  l.add(getDim(i));
        }
        return new FixedArrayType(new ParseArrayType(getType(), l), 
				  getDim(0).getExpList());
      }
    }
    when (getDim(0).isVariable()) 
    to VariableArrayType  { 
      if (getNumDim() == 1) {
        return new VariableArrayType(getType(), 
				     getDim(0).getExpList());
      } else {
        List l = new List();
        for (int i = 1 ; i < getNumDim() ; i++) {
	  l.add(getDim(i));
        }
        return new VariableArrayType(new ParseArrayType(getType(), l), 
				     getDim(0).getExpList());
      }
    }
  }

}