include/EDoc/FunctionType.h

Go to the documentation of this file.
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_FUNCTIONTYPE_H
00020 #define EDOC_FUNCTIONTYPE_H
00021 
00022 #include "EDoc/StringIdentifiedObject.h"
00023 #include <vector>
00024 #include <sstream>
00025 
00026 namespace EDoc
00027 {
00028    class Type;
00029    class Function;
00030    
00031    //===========================================================================
00032    /** \brief Represents a C/C++ function pointer type.
00033     *
00034     * This stores information about the individual elements of a function
00035     * pointer or a member function pointer in C++. This information is stored
00036     * seperatly in order to be able to match function pointers that can be
00037     * called across C/C++ with types that may have different names due to
00038     * typedefs etc.
00039     *
00040     * It is primarily used for storing the type of a Function object and for
00041     * being stored in a CodeBlock::function_pointers list as a list of calls to
00042     * function pointers. The most important call is the IsEquivilant() function.
00043     */
00044    class FunctionType : public StringIdentifiedObject
00045    {
00046    public:
00047 
00048       //------------------------------------------------------------------------
00049       /** \brief See StringIdentifiedObject::(Dictionary& dict_in, 
00050        * std::string key_name_in, bool populated_in=false)
00051        */
00052       FunctionType(Dictionary& dict_in, std::string key_name_in);
00053 
00054       //------------------------------------------------------------------------
00055       /** \brief See StringIdentifiedObject(Dictionary& dict_in, 
00056        * int32_t index_in, bool populated_in=false)
00057        */
00058       FunctionType(Dictionary& dict_in, int32_t index_in);
00059 
00060       //------------------------------------------------------------------------
00061       /** \brief Copies data from another object into this one.
00062        *
00063        * This can be used across different dictionaries and will only copy
00064        * object data but not identification information used in the
00065        * StringIdentifiedObject such as the key name.
00066        */
00067       FunctionType& operator=(const FunctionType& right);
00068 
00069       //------------------------------------------------------------------------
00070       /** \brief See StringIdentifiedObject::Read()
00071        */
00072       void Read(PersistenceIFace& file, IndexedDictionary& idict);
00073 
00074       //------------------------------------------------------------------------
00075       /** \brief See StringIdentifiedObject::Write()
00076        */
00077       void Write(PersistenceIFace& file) const;
00078 
00079       //------------------------------------------------------------------------
00080       /** \brief See StringIdentifiedObject::Merge()
00081        */
00082       virtual void Merge(const StringIdentifiedObject& right);
00083 
00084       //------------------------------------------------------------------------
00085       /** \brief DictionarySpecific::ReplaceReferences()
00086        */
00087       virtual size_t ReplaceReferences(PStack& stack, 
00088          void* remove, void* replace);
00089 
00090       //------------------------------------------------------------------------
00091       /** \brief See DictionarySpecific::Print()
00092        */
00093       virtual std::ostream& Print(std::ostream& out, 
00094          std::string prefix="") const;
00095 
00096       //------------------------------------------------------------------------
00097       /** \brief See DictionarySpecific::Validate()
00098        */
00099       virtual void Validate(PStack& stack, const Dictionary& dict_in) const;
00100 
00101       //------------------------------------------------------------------------
00102       /** \brief Returns true if the two types are the same.
00103        *
00104        * Works across dictionaries.
00105        */
00106       bool operator==(const FunctionType& right) const;
00107 
00108       //------------------------------------------------------------------------
00109       /** \brief See StringIdentifiedObject::GetRecordType()
00110        */
00111       virtual uint8_t GetRecordType() const;
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126       //------------------------------------------------------------------------
00127       /** \brief Returns a string representation of this function pointer type
00128        * using the names for the types as the user may have defined them.
00129        */
00130       inline std::string GetDeclaredName() const
00131       {
00132          return GetNameInternal(false);
00133       }
00134 
00135       //------------------------------------------------------------------------
00136       /** \brief Returns a string representation of this function pointer type
00137        * using the names for the types in a normalized format.
00138        */
00139       inline std::string GetNormalisedName() const
00140       {
00141          return GetNameInternal(true);
00142       }
00143       
00144 
00145 
00146       //------------------------------------------------------------------------
00147       /** \brief See Function::GetSpecString()
00148        */
00149       std::string GetSpecString() const;
00150 
00151 
00152       //------------------------------------------------------------------------
00153       /** \brief Returns true if the function type on the right is equivilant
00154        * to the function type on the left.
00155        *
00156        * Note: This is not exact. It will return true in some cases where they
00157        * are NOT equivilant. This is due to C type equivilance tests that
00158        * differ from C++ ones. This needs to be worked on in the future, however
00159        * it will match as best it can from the data it has available.
00160        *
00161        * Types that trace to a root type with external linkage can be accuratly
00162        * tested for equivilance, however types whose root_type does NOT have
00163        * external linkage can not be tested for equality currently. So we 
00164        * just assume they are equal.
00165        */
00166       bool IsEquivilant(const FunctionType& right) const;
00167 
00168       //------------------------------------------------------------------------
00169       /** \brief A representative name for the function type.
00170        */
00171       std::string full_name;
00172 
00173       //------------------------------------------------------------------------
00174       /** \brief The type instance that represents the functions return type.
00175        */
00176       Type* return_type;
00177       
00178       //------------------------------------------------------------------------
00179       /** \brief The type instance that represents the class this function
00180        * belongs to if it is a pointer to a C++ class member.
00181        */
00182       Type* method_context;
00183 
00184       //------------------------------------------------------------------------
00185       /** \brief The type instances for all the parameters that make up the
00186        * functions aregument list.
00187        */
00188       std::vector<Type*> parameters;
00189       
00190       //------------------------------------------------------------------------
00191       /** \brief True if method_context is not null and this member is defined
00192        * const.
00193        */
00194       bool is_const;
00195       
00196       //------------------------------------------------------------------------
00197       /** \brief See Function::has_exception_spec
00198        */
00199       bool has_exception_spec;
00200 
00201       //------------------------------------------------------------------------
00202       /** \brief See Function::exception_spec
00203        */
00204       std::vector<Type*> exception_spec;
00205 
00206 
00207       //------------------------------------------------------------------------
00208       /** \brief Returns the name of this function type in one of two formats.
00209        *
00210        * \param canonical If true returns the canonical form of the function
00211        * name otherwise returns the declared form of the function pointer types
00212        * name.
00213        */
00214       std::string GetNameInternal(bool canonical) const;
00215 
00216 
00217 
00218       //------------------------------------------------------------------------
00219       // Public Temporary Data values.
00220       //------------------------------------------------------------------------
00221       // @@@Brendon These really should not be here!
00222       /** \brief Stores a list of other function types that are considered
00223        * equivilant to this one.
00224        *
00225        * This value is set by Dictionary::UpdateFunctionAddressLists() and is
00226        * used in expanding the callgraph for function pointer calls. Its value
00227        * is considered temporary and should not be used elsewhere.
00228        */
00229       std::vector<FunctionType*> equivilant;
00230       
00231       //------------------------------------------------------------------------
00232       /** \brief USED ONLY FROM Dictionary::CalculatePropogatingExceptions()
00233        *
00234        * This is only used as a "cache" and contains a list of all functions
00235        * that match this type whose addresses have been taken.
00236        */
00237       std::vector<Function*> addressed_functions;
00238 
00239 
00240       //------------------------------------------------------------------------
00241 
00242 
00243    };
00244    //===========================================================================
00245 }
00246 
00247 #endif // EDOC_FUNCTIONTYPE_H

Generated on Tue Jan 20 18:26:07 2009 for EDoc-0.2.1 by  doxygen 1.5.1