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_TYPE_HPP 00035 #define CFRONT_TYPE_HPP 00036 00037 #ifdef PARSER_DEBUG 00038 #include <string> 00039 #include <sstream> 00040 #endif 00041 00042 #include "TargetInfo.hpp" 00043 #include "Extension.hpp" 00044 #include <antlr/AST.hpp> 00045 #include <list> 00046 00047 namespace cfront { 00048 00050 typedef unsigned int QualFlags; 00051 static const unsigned int Const = 01U; 00052 static const unsigned int Volatile = 02U; 00053 static const unsigned int Restrict = 04U; 00054 static const unsigned int Static = 010U; 00055 00056 typedef long long int ConstantValue; 00057 static const ConstantValue ConstantUnspecified = -1; 00058 00062 class Type { 00063 public: 00064 00069 class Definition { 00070 public: 00071 virtual ~Definition() {} 00072 }; 00073 00077 typedef std::list<Extension*> Extensions; 00078 00079 Type() {} 00080 00081 protected: 00085 Type(const Type& other) 00086 { 00087 this->extensions_.resize(other.extensions_.size()); 00088 std::copy(other.extensions_.begin(), other.extensions_.end(), 00089 this->extensions_.begin()); 00090 } 00091 00092 public: 00093 00097 virtual Type* clone() const = 0; 00098 00099 virtual ~Type() {} 00100 00101 // type predicates 00102 00106 virtual bool isCompatibleType(const Type* other) const = 0; 00107 00108 virtual bool isScalarType() const 00109 { 00110 return false; 00111 } 00112 00113 virtual bool isArithmeticType() const 00114 { 00115 return false; 00116 } 00117 00118 virtual bool isIntegerType() const 00119 { 00120 return false; 00121 } 00122 00126 virtual bool isVoidType() const 00127 { 00128 return false; 00129 } 00130 00131 const Extensions& getExtensions() const 00132 { 00133 return extensions_; 00134 } 00135 00136 void addExtension(Extension* e) 00137 { 00138 extensions_.push_back(e); 00139 } 00140 00141 virtual size_t getSize(const TargetInfo& targetInfo) const = 0; 00142 00143 virtual size_t getAlign(const TargetInfo& targetInfo) const = 0; 00144 00145 00146 #ifdef PARSER_DEBUG 00147 virtual std::string toString() const 00148 { 00149 return "<AbstractType>"; 00150 } 00151 00152 std::string toStringQualFlags(QualFlags qf) const 00153 { 00154 std::stringstream ss; 00155 if (qf & Const) { 00156 ss << "Const "; 00157 } 00158 if (qf & Volatile) { 00159 ss << "Volatile "; 00160 } 00161 if (qf & Restrict) { 00162 ss << "Restrict "; 00163 } 00164 return ss.str(); 00165 } 00166 #endif 00167 00168 protected: 00169 Extensions extensions_; 00170 }; 00171 00172 } // namespace cfront 00173 00174 #endif 00175 00176 00177 /* 00178 * Local Variables: 00179 * mode: C++ 00180 * c-basic-offset: 4 00181 * indent-tabs-mode: nil 00182 * End: 00183 */