00001 package edu.ksu.cis.bandera.bir;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 import ca.mcgill.sable.util.*;
00036
00037 import java.io.*;
00038 import java.util.*;
00039
00040
00041
00042
00043
00044 public class Record extends Type implements BirConstants {
00045
00046 Vector fields;
00047 boolean isMonitor = false;
00048
00049 public Record() {
00050 this.fields = new Vector(10);
00051 this.extent = 0;
00052 }
00053 public Field addField(String name, Type fieldType) {
00054 Field field = new Field(name, fieldType, this);
00055 fields.addElement(field);
00056 return field;
00057 }
00058 public void apply(TypeSwitch sw, Object o)
00059 {
00060 sw.caseRecord(this, o);
00061 }
00062 public Expr defaultVal() { return null; }
00063
00064
00065
00066
00067 public boolean equals(Object o) {
00068 if (o instanceof Record) {
00069 Vector o_fields = ((Record)o).fields;
00070 if (o_fields.size() != fields.size())
00071 return false;
00072 for (int i = 0; i < fields.size(); i++)
00073 if (! fields.elementAt(i).equals(o_fields.elementAt(i)))
00074 return false;
00075 return true;
00076 }
00077 return false;
00078 }
00079 public int getExtent() {
00080 if (extent == 0)
00081 for (int i = 0; i < fields.size(); i++) {
00082 Field field = (Field)fields.elementAt(i);
00083 field.setOffset(extent);
00084 extent += field.getType().getExtent();
00085 }
00086 return extent;
00087 }
00088 public Field getField(String name) {
00089 for (int i = 0; i < fields.size(); i++) {
00090 Field field = (Field)fields.elementAt(i);
00091 if (field.getName().equals(name))
00092 return field;
00093 }
00094 return null;
00095 }
00096 public Vector getFields() { return fields; }
00097 public boolean isKind(int kind) {
00098 return (kind & RECORD) != 0;
00099 }
00100
00101 public String toString() {
00102 String result = "";
00103 for (int i = 0; i < fields.size(); i++)
00104 result += ((Field)fields.elementAt(i)).toString();
00105 return "record { " + result + "}";
00106 }
00107 }