FlatSignature.jrag 3.73 KB
Newer Older
1
2
import java.util.*;

3
aspect NoIntentionForTypeOrSampledefs {
4
5
6
7
8
9
    inh boolean TypeInstance.addIntentions();
    eq Decl.getTypeInstance().addIntentions() = false;
    eq StructType.getField(int i).addIntentions() = true;
}

aspect FlatSignature {
10
11
12
13
14

  public SignatureList Decl.flatSignature(int version) {
    SignatureList result = getSignature().getFlatSignatureList();
    return result;
  }
15

16
  public void ASTNode.flatSignature(SignatureList list) {
17
18
    throw new Error(this.getClass().getName() +
                    ".flatSignature(SignatureList list)" +
19
20
21
22
                    " not declared");
  }

  public void TypeDecl.flatSignature(SignatureList list) {
23
    getTypeInstance().flatSignature(list);
24
25
26
  }

  public void SampleDecl.flatSignature(SignatureList list) {
27
    getTypeInstance().flatSignature(list);
28
29
  }

30
31
32
//  public void SampleRefType.flatSignature(SignatureList list) {
//    list.addInt(LABCOMM_SAMPLE_REF, "sample");
//  }
Anders Blomdell's avatar
Anders Blomdell committed
33

34
  public void TypeInstance.flatSignature(SignatureList list) {
35
36
    if(addIntentions()) {
      debugAnnotations(this.getName()+".TypeInstance.flatSignature");
37
      list.addIntentions(intentions(), "intentions: "+getIntentionString());
38
39
    }
    getDataType().flatSignature(list);
40
41
  }

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  public void VoidType.flatSignature(SignatureList list) {
    list.addInt(LABCOMM_STRUCT, "void");
    list.addInt(0, null);
  }

  public void PrimType.flatSignature(SignatureList list) {
    list.addInt(getToken(), null);
  }

  public void UserType.flatSignature(SignatureList list) {
    lookupType(getName()).flatSignature(list);
  }

  public void ArrayType.flatSignature(SignatureList list) {
    list.addInt(LABCOMM_ARRAY, signatureComment());
    list.indent();
    list.addInt(getNumExp(), null);
    for (int i = 0 ; i < getNumExp() ; i++) {
      getExp(i).flatSignature(list);
    }
62
    getDataType().flatSignature(list);
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    list.unindent();
    list.add(null, "}");
  }

  public void StructType.flatSignature(SignatureList list) {
    list.addInt(LABCOMM_STRUCT, "struct { " + getNumField() + " fields");
    list.indent();
    list.addInt(getNumField(), null);
    for (int i = 0 ; i < getNumField() ; i++) {
      getField(i).flatSignature(list);
    }
    list.unindent();
    list.add(null, "}");
  }

  public void Field.flatSignature(SignatureList list) {
79
    debugAnnotations(this.getName()+".Field.flatSignature");
80
    list.addIntentions(intentions(), "Field: "+getIntentionString());
81
//    list.addString(getName(), signatureComment());
82
    getDataType().flatSignature(list);
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  }

  public void IntegerLiteral.flatSignature(SignatureList list) {
    list.addInt(Integer.parseInt(getValue()), null);
  }

  public void VariableSize.flatSignature(SignatureList list) {
    list.addInt(0, null);
  }

  public String ArrayType.signatureComment() {
    StringBuffer result = new StringBuffer("array [");
    for (int i = 0 ; i < getNumExp() ; i++) {
      if (i > 0) {
97
  result.append(", ");
98
99
100
101
102
103
104
105
      }
      result.append(getExp(i).signatureComment());
    }
    result.append("]");
    return result.toString();
  }

  public String ASTNode.signatureComment() {
106
107
    throw new Error(this.getClass().getName() +
                    ".signatureComment()" +
108
109
110
111
                    " not declared");
  }

  public String Field.signatureComment() {
112
    return getDataType().signatureComment() + " '" + getName() +"'";
113
114
  }

115
116
117
//  public String SampleRefType.signatureComment() {
//    return "sample";
//  }
Anders Blomdell's avatar
Anders Blomdell committed
118

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
  public String PrimType.signatureComment() {
    return getName();
  }

  public String UserType.signatureComment() {
    return getName();
  }

  public String StructType.signatureComment() {
    return "struct";
  }

  public String IntegerLiteral.signatureComment() {
    return getValue();
  }

  public String VariableSize.signatureComment() {
    return "_";
  }

}