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_POINTER_TYPE_HPP 00035 #define CFRONT_POINTER_TYPE_HPP 00036 00037 namespace cfront { 00038 00042 class PointerType : public Type { 00043 public: 00044 PointerType(const Type* baseType, QualFlags qualFlags) 00045 : baseType_(baseType), qualFlags_(qualFlags) {} 00046 PointerType(const PointerType& other) 00047 : Type(other), baseType_(other.baseType_), 00048 qualFlags_(other.qualFlags_) {} 00049 00050 virtual ~PointerType() {} 00051 00052 virtual PointerType* clone() const 00053 { 00054 return new PointerType(*this); 00055 } 00056 00057 virtual bool isCompatibleType(const Type* other) const 00058 { 00059 const PointerType* po = dynamic_cast<const PointerType*>(other); 00060 if (po == NULL) return false; 00061 return baseType_->isCompatibleType(po->baseType_); 00062 } 00063 00064 virtual bool isScalarType() const 00065 { 00066 return true; 00067 } 00068 00069 virtual size_t getSize(const TargetInfo& targetInfo) const 00070 { 00071 return targetInfo.getSize(TargetInfo::POINTER); 00072 } 00073 00074 virtual size_t getAlign(const TargetInfo& targetInfo) const 00075 { 00076 return targetInfo.getAlign(TargetInfo::POINTER); 00077 } 00078 00079 const Type* getBaseType() const 00080 { 00081 return baseType_; 00082 } 00083 00084 QualFlags getQualFlags() const 00085 { 00086 return qualFlags_; 00087 } 00088 00089 void setBaseType(const Type* t) 00090 { 00091 baseType_ = t; 00092 } 00093 00094 void setQualFlags(QualFlags qf) 00095 { 00096 qualFlags_ = qf; 00097 } 00098 00099 #ifdef PARSER_DEBUG 00100 virtual std::string toString() const 00101 { 00102 std::stringstream ss; 00103 ss << "* " << toStringQualFlags(qualFlags_) << baseType_->toString(); 00104 return ss.str(); 00105 } 00106 #endif 00107 00108 protected: 00109 const Type* baseType_; 00110 QualFlags qualFlags_; 00111 }; 00112 00113 } // namespace cfront 00114 00115 #endif 00116 00117 00118 /* 00119 * Local Variables: 00120 * mode: C++ 00121 * c-basic-offset: 4 00122 * indent-tabs-mode: nil 00123 * End: 00124 */