00001 /* 00002 Copyright (c) 2009, National Institute of Advanced Industrial Science 00003 and Technology. All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without 00006 modification, are permitted provided that the following conditions are 00007 met: 00008 00009 * Redistributions of source code must retain the above copyright 00010 notice, this list of conditions and the following disclaimer. 00011 00012 * Redistributions in binary form must reproduce the above copyright 00013 notice, this list of conditions and the following disclaimer in 00014 the documentation and/or other materials provided with the 00015 distribution. 00016 00017 * Neither the name of Fixstars Corporation nor the names of its 00018 contributors may be used to endorse or promote products derived 00019 from this software without specific prior written permission. 00020 00021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00024 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00025 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00026 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00027 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00028 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00029 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00030 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00031 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 */ 00033 00034 #ifndef CFRONT_TYPEDEF_TYPE_HPP 00035 #define CFRONT_TYPEDEF_TYPE_HPP 00036 00037 namespace cfront { 00038 00039 00040 class TypeDefinition : public Type::Definition { 00041 public: 00042 TypeDefinition(const Type* baseType, const std::string& name) 00043 : baseType_(baseType), name_(name) {} 00044 00045 const Type* getBaseType() const 00046 { 00047 return baseType_; 00048 } 00049 00050 const std::string& getName() const 00051 { 00052 return name_; 00053 } 00054 00055 private: 00056 const Type* baseType_; 00057 00058 std::string name_; 00059 }; 00060 00061 00065 class TypedefType : public Type { 00066 public: 00067 TypedefType(TypeDefinition* def, QualFlags qf = 0) 00068 : def_(def), qualFlags_(qf) {} 00069 TypedefType(const TypedefType& other) 00070 : Type(other), def_(other.def_), qualFlags_(other.qualFlags_) {} 00071 00072 virtual ~TypedefType() {} 00073 00074 virtual TypedefType* clone() const 00075 { 00076 return new TypedefType(*this); 00077 } 00078 00079 virtual bool isCompatibleType(const Type* other) const 00080 { 00081 const TypedefType* to = dynamic_cast<const TypedefType*>(other); 00082 if (to == NULL) return false; 00083 /* FIXME: QualFlags */ 00084 return getBaseType()->isCompatibleType(to->getBaseType()); 00085 } 00086 00087 virtual bool isScalarType() const 00088 { 00089 return getBaseType()->isScalarType(); 00090 } 00091 00092 virtual bool isArithmeticType() const 00093 { 00094 return getBaseType()->isArithmeticType(); 00095 } 00096 00097 virtual bool isIntegerType() const 00098 { 00099 return getBaseType()->isIntegerType(); 00100 } 00101 00102 virtual bool isVoidType() const 00103 { 00104 return getBaseType()->isVoidType(); 00105 } 00106 00107 virtual size_t getSize(const TargetInfo& targetInfo) const 00108 { 00109 return getBaseType()->getSize(targetInfo); 00110 } 00111 00112 virtual size_t getAlign(const TargetInfo& targetInfo) const 00113 { 00114 return getBaseType()->getAlign(targetInfo); 00115 } 00116 00117 const Type* getBaseType() const 00118 { 00119 return def_->getBaseType(); 00120 } 00121 00122 TypeDefinition* getDefinition() const 00123 { 00124 return def_; 00125 } 00126 00127 QualFlags getQualFlags() const 00128 { 00129 return qualFlags_; 00130 } 00131 00132 void setQualFlags(QualFlags qf) 00133 { 00134 qualFlags_ = qf; 00135 } 00136 00137 #ifdef PARSER_DEBUG 00138 virtual std::string toString() const 00139 { 00140 std::stringstream ss; 00141 ss << "(typedef) " << toStringQualFlags(qualFlags_) << 00142 getBaseType()->toString(); 00143 return ss.str(); 00144 } 00145 #endif 00146 00147 protected: 00148 TypeDefinition* def_; 00149 QualFlags qualFlags_; 00150 }; 00151 00152 } // namespace cfront 00153 00154 #endif 00155 00156 00157 /* 00158 * Local Variables: 00159 * mode: C++ 00160 * c-basic-offset: 4 00161 * indent-tabs-mode: nil 00162 * End: 00163 */