00001
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 #ifndef CFRONT_ARRAY_TYPE_HPP
00035 #define CFRONT_ARRAY_TYPE_HPP
00036
00037 namespace cfront {
00038
00042 class ArrayType : public Type {
00043 public:
00044
00048 enum LengthSpec {
00049 NOT_SPECIFIED,
00050 FIXED,
00051 VARIABLE,
00052 VARIABLE_NOT_SPECIFIED,
00054 INCOMPLETE
00055 };
00056
00057 ArrayType(const Type* baseType, QualFlags qualFlags, LengthSpec lengthSpec)
00058 : baseType_(baseType), lengthValue_(ConstantUnspecified),
00059 qualFlags_(qualFlags), lengthSpec_(lengthSpec) {}
00060 ArrayType(const Type* baseType, ConstantValue& lengthValue,
00061 QualFlags qualFlags)
00062 : baseType_(baseType), lengthValue_(lengthValue),
00063 qualFlags_(qualFlags), lengthSpec_(FIXED) {}
00064 ArrayType(const ArrayType& other)
00065 : Type(other), baseType_(other.baseType_),
00066 lengthValue_(other.lengthValue_), qualFlags_(other.qualFlags_),
00067 lengthSpec_(lengthSpec_) {}
00068
00069 virtual ~ArrayType() {}
00070
00071 virtual ArrayType* clone() const
00072 {
00073 return new ArrayType(*this);
00074 }
00075
00076 virtual bool isCompatibleType(const Type* other) const
00077 {
00078 const ArrayType* po = dynamic_cast<const ArrayType*>(other);
00079 if (po == NULL) return false;
00080 return baseType_->isCompatibleType(po->baseType_);
00081 }
00082
00083 virtual size_t getSize(const TargetInfo& targetInfo) const
00084 {
00085
00086 return getBaseType()->getSize(targetInfo) * getLengthValue();
00087 }
00088
00089 virtual size_t getAlign(const TargetInfo& targetInfo) const
00090 {
00091 return getBaseType()->getAlign(targetInfo);
00092 }
00093
00094 const Type* getBaseType() const
00095 {
00096 return baseType_;
00097 }
00098
00099 const ConstantValue& getLengthValue() const
00100 {
00101 return lengthValue_;
00102 }
00103
00104 QualFlags getQualFlags() const
00105 {
00106 return qualFlags_;
00107 }
00108
00109 LengthSpec getLengthSpec() const
00110 {
00111 return lengthSpec_;
00112 }
00113
00114 void setBaseType(const Type* t)
00115 {
00116 baseType_ = t;
00117 }
00118
00119 void setLengthValue(const ConstantValue lengthValue)
00120 {
00121 lengthValue_ = lengthValue;
00122 }
00123
00124 #ifdef PARSER_DEBUG
00125 virtual std::string toString() const
00126 {
00127 std::stringstream ss;
00128 ss << "ArrayType[ " << lengthValue_ << ":" << baseType_->toString() <<
00129 " (" << toStringQualFlags(qualFlags_) << ")]";
00130 return ss.str();
00131 }
00132 #endif
00133
00134 protected:
00135 const Type* baseType_;
00136 ConstantValue lengthValue_;
00137 QualFlags qualFlags_;
00138 LengthSpec lengthSpec_;
00139 };
00140
00141 }
00142
00143 #endif
00144
00145
00146
00147
00148
00149
00150
00151
00152