00001 /******************************************************************************* 00002 00003 Copyright (C) 2007 by Brendon Costa 00004 00005 This library is free software; you can redistribute it and/or modify 00006 it under the terms of the "LGPL Like" License defined in the file COPYING 00007 that should have been distributed along with this source. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 You should have received a copy of the "LGPL Like" License 00014 along with this library; see the file COPYING. if not, it can be 00015 obtained from the EDoc++ website: 00016 http://edoc.sourceforge.net/license.html 00017 00018 *******************************************************************************/ 00019 #ifndef EDOC_TYPE_H 00020 #define EDOC_TYPE_H 00021 00022 #include "EDoc/StringIdentifiedObject.h" 00023 #include "EDoc/Location.h" 00024 00025 #include <string> 00026 #include <vector> 00027 #include <sstream> 00028 #include <list> 00029 #include <list> 00030 00031 namespace EDoc 00032 { 00033 class PersistenceIFace; 00034 class IndexedDictionary; 00035 class Dictionary; 00036 class Function; 00037 class PStack; 00038 class File; 00039 class TranslationUnit; 00040 00041 //=========================================================================== 00042 /** \brief Represents a type in C/C++ code that has been encounterd 00043 * during compilation. 00044 * 00045 * 00046 */ 00047 class Type : public StringIdentifiedObject 00048 { 00049 public: 00050 00051 //------------------------------------------------------------------------ 00052 /** \brief See StringIdentifiedObject::(Dictionary& dict_in, 00053 * std::string key_name_in, bool populated_in=false) 00054 */ 00055 Type(Dictionary& dict_in, std::string key_name_in); 00056 00057 //------------------------------------------------------------------------ 00058 /** \brief See StringIdentifiedObject(Dictionary& dict_in, 00059 * int32_t index_in, bool populated_in=false) 00060 */ 00061 Type(Dictionary& dict_in, int32_t index_in); 00062 00063 //------------------------------------------------------------------------ 00064 /** \brief Copies data from another object into this one. 00065 * 00066 * This can be used across different dictionaries and will only copy 00067 * object data but not identification information used in the 00068 * StringIdentifiedObject such as the key name. 00069 */ 00070 Type& operator=(const Type& right); 00071 00072 //------------------------------------------------------------------------ 00073 /** \brief See StringIdentifiedObject::Read() 00074 */ 00075 void Read(PersistenceIFace& file, IndexedDictionary& idict); 00076 00077 //------------------------------------------------------------------------ 00078 /** \brief See StringIdentifiedObject::Write() 00079 */ 00080 void Write(PersistenceIFace& file) const; 00081 00082 //------------------------------------------------------------------------ 00083 /** \brief See StringIdentifiedObject::Merge() 00084 */ 00085 virtual void Merge(const StringIdentifiedObject& right); 00086 00087 //------------------------------------------------------------------------ 00088 /** \brief DictionarySpecific::ReplaceReferences() 00089 */ 00090 virtual size_t ReplaceReferences(PStack& stack, 00091 void* remove, void* replace); 00092 00093 //------------------------------------------------------------------------ 00094 /** \brief See DictionarySpecific::Print() 00095 */ 00096 virtual std::ostream& Print(std::ostream& out, 00097 std::string prefix="") const; 00098 00099 //------------------------------------------------------------------------ 00100 /** \brief See DictionarySpecific::Validate() 00101 */ 00102 virtual void Validate(PStack& stack, const Dictionary& dict_in) const; 00103 00104 //------------------------------------------------------------------------ 00105 /** \brief Returns true if the two types are the same. 00106 * 00107 * Works across dictionaries. 00108 */ 00109 bool operator==(const Type& right) const; 00110 00111 //------------------------------------------------------------------------ 00112 /** \brief See operator==() 00113 */ 00114 bool operator!=(const Type& right) const 00115 { 00116 return !(*this == right); 00117 } 00118 00119 //------------------------------------------------------------------------ 00120 /** \brief See StringIdentifiedObject::GetRecordType() 00121 */ 00122 virtual uint8_t GetRecordType() const; 00123 00124 00125 00126 00127 00128 00129 00130 00131 00132 00133 //------------------------------------------------------------------------ 00134 /** \brief Returns the root name of this type. 00135 */ 00136 inline std::string GetNormalisedName() const 00137 { 00138 return root_type->name; 00139 } 00140 00141 //------------------------------------------------------------------------ 00142 /** \brief Returns the name of this type as declared by the user in the 00143 * source code. 00144 */ 00145 inline std::string GetDeclaredName() const 00146 { 00147 return name; 00148 } 00149 00150 //------------------------------------------------------------------------ 00151 /** \brief Will return one of GetKeyName() or GetDeclaredName() 00152 * depending upon how much information is available in the object (I.e. if 00153 * it has been populated yet). 00154 */ 00155 inline std::string GetBestName() const 00156 { 00157 return (IsPopulated() ? name : GetKeyName()); 00158 } 00159 00160 00161 00162 00163 //------------------------------------------------------------------------ 00164 /** \brief True if an exception of this type is thrown and it can be 00165 * caught by the type passed into right. 00166 */ 00167 bool IsCaughtBy(const Type& right) const; 00168 00169 //------------------------------------------------------------------------ 00170 /** \brief See FunctionType::IsEquivilant() 00171 */ 00172 bool IsEquivilant(const Type& right) const; 00173 00174 //------------------------------------------------------------------------ 00175 00176 00177 00178 //------------------------------------------------------------------------ 00179 // Public Primary Data values. 00180 //------------------------------------------------------------------------ 00181 00182 //------------------------------------------------------------------------ 00183 /** \brief Name of the type as declared by the user. 00184 */ 00185 std::string name; 00186 00187 //------------------------------------------------------------------------ 00188 /** \brief True if this type has external linkage identification or false 00189 * if defined privatly to the translation unit. 00190 */ 00191 bool external_linkage; 00192 00193 //------------------------------------------------------------------------ 00194 /** \brief A reference to the translation unit this type belongs to. 00195 * 00196 * This may change in the future, or not... It is NON-NULL if the type has 00197 * external linkage. Possible remove the boolean value and just have the 00198 * pointer. If NULL then is external if not null then internal. 00199 */ 00200 TranslationUnit* translation_unit; 00201 00202 //------------------------------------------------------------------------ 00203 /** \brief If this type is thrown what is a base type that will be used in 00204 * all exception calculations. 00205 * 00206 * This is usually the base type (followed back typedefs) stripped of top 00207 * level const/volatile qualifiers. 00208 */ 00209 Type* throw_type; 00210 00211 //------------------------------------------------------------------------ 00212 /** \brief This is usually the base type (followed back typedefs) with 00213 * equivilant const/volatile qualifiers. 00214 */ 00215 Type* root_type; 00216 00217 //------------------------------------------------------------------------ 00218 /** \brief A list of other types that are considered identical to this 00219 * one. 00220 * 00221 * Determined by typedefs etc. 00222 */ 00223 std::vector<Type*> identical; 00224 00225 //------------------------------------------------------------------------ 00226 /** \brief A list of other types that can be used to catch this type. 00227 */ 00228 std::vector<Type*> catchable; 00229 00230 //------------------------------------------------------------------------ 00231 /** \brief The source Location where this type was defined. 00232 */ 00233 Location loc; 00234 00235 //------------------------------------------------------------------------ 00236 /** \brief A list of source files that this type is used in. 00237 */ 00238 std::list<File*> referenced_in_files; 00239 00240 //------------------------------------------------------------------------ 00241 /** \brief Returns the name of the type with translation unit info 00242 * appended if it is provate to the translation unit. 00243 */ 00244 std::string GetNameInternal() const; 00245 00246 //------------------------------------------------------------------------ 00247 /** \brief True if this type is visible to the user for exceptions or 00248 * false if any exceptions of this type will never be shown to the user. 00249 * 00250 * This is used for suppressions. 00251 */ 00252 bool visible; 00253 00254 //------------------------------------------------------------------------ 00255 00256 }; 00257 //=========================================================================== 00258 typedef std::vector<EDoc::Type*> TypePVec; 00259 00260 } 00261 00262 #endif // EDOC_TYPE_H