summaryrefslogtreecommitdiffstats
path: root/languages/cpp/simpletypenamespace.h
blob: b465cfb62974901961a360209f7cd717e645afce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/***************************************************************************
   copyright            : (C) 2006 by David Nolden
   email                : [email protected]
***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#ifndef SIMPLETYPENAMESPACE_H
#define SIMPLETYPENAMESPACE_H

#include<hashedstring.h>
#include "simpletype.h"
#include "includefiles.h"
#include <set>
#include <ext/hash_map>
#include <list>

class SimpleTypeNamespace : public SimpleTypeImpl {
  public:

    struct Import {
      Import( const TypeDesc& _import, const TypePointer& persp ) : import( _import ), perspective( persp ) {}

      Import( const IncludeFiles& _files, const TypeDesc& _import, const TypePointer& persp ) : files( _files ), import( _import ), perspective( persp ) {}

      ///Does not respect the include-file-list, only the import-name is compared
      bool operator < ( const Import& rhs ) const {
        return import.name() < rhs.import.name();
      }

      ///Does not respect the include-file-list, only the import-name is compared
      bool operator == ( const Import& rhs ) const {
        return import.name() == rhs.import.name();
      }

      IncludeFiles files;
      TypeDesc import;
      TypePointer perspective; //From where the import should be searched
      /*
      bool operator < ( const Alias& rhs ) const {
        if( alias < rhs.alias ) return true;
        return false;
      }

      bool operator == ( const Alias& rhs ) const {
        return alias == rhs.alias && files == rhs.files;
      }*/

    };

    //First.first is the desc(including include-file-information for searching), first.second is the set of include-files that activate this import, second is the perspective in which to search
  typedef std::pair<std::pair<TypeDesc, IncludeFiles>, TypePointer> SlaveDesc;
    typedef std::list<SlaveDesc> SlaveList;
    //Maps IDs to slaves
    typedef std::map<size_t, SlaveDesc> SlaveMap;

    typedef std::multiset<Import> ImportList;

    SimpleTypeNamespace( const TQStringList& fakeScope, const TQStringList& realScope );

    SimpleTypeNamespace( const TQStringList& fakeScope );

    SimpleTypeNamespace( SimpleTypeNamespace* ns );

    bool isANamespace( SimpleTypeImpl* t ) {
      return dynamic_cast<SimpleTypeNamespace*>( t ) != 0;
    }

    virtual TypePointer clone();

    ///Returns a list of all slave-namespaces that have an effect with the given set of include-files. Some of the returned type-descs may be unresolved, in case they could not be resolved.
    SlaveList getSlaves( const IncludeFiles& includeFiles );

    /**empty name means an import.
     * @param files Set of files that must be included for this alias-map to be active. If the set is empty, the alias will be used globally.
     * @param alias The type to import. May contain the include-file-set to search with.
     * @param perspective The point from which to search for the item on demand
     */
    void addAliasMap( const TypeDesc& name, const TypeDesc& alias , const IncludeFiles& files = IncludeFiles(), bool recurse = true, bool symmetric = false, const TypePointer& perspective = TypePointer() );

    /**Takes a map of multiple aliases in form "A=B;C=D;....;" similar to the C++ "namespace A=B;" statement
     * @param files Set of files that must be included for this alias-map to be active. If the set is empty, the alias will be used globally.
     */
    void addAliases( TQString map, const IncludeFiles& files = IncludeFiles() );

  private:
    SlaveMap m_activeSlaves;
    size_t m_currentSlaveId;
    HashedStringSetGroup m_activeSlaveGroups;
    typedef TQMap<TQString, ImportList> AliasMap;
    AliasMap m_aliases;

    //Inserts all aliases necessary fo handling a request using the given IncludeFiles
    std::set<size_t> updateAliases( const IncludeFiles& files/*, bool isRecursion = false */);

//     LocateResult locateSlave( const SlaveList::const_iterator& it, const IncludeFiles& includeFiles );

    void addImport( const TypeDesc& import, const IncludeFiles& files = IncludeFiles(), TypePointer perspective = TypePointer() );

    friend class NamespaceBuildInfo;

  struct NamespaceBuildInfo : public TypeBuildInfo {
      TQStringList m_fakeScope;
      ImportList m_imports;
      TypePointer m_built;


      NamespaceBuildInfo( TQStringList fakeScope, const ImportList& imports ) {
        m_fakeScope = fakeScope;
        m_imports = imports;
      }

      virtual TypePointer build();
    };

    explicit SimpleTypeNamespace( const SimpleTypeNamespace& rhs ) {}

  protected:

    //void updateAliases( const HashedStringSet& files );

    SimpleTypeImpl::MemberInfo findMember( TypeDesc name, MemberInfo::MemberType type, std::set<HashedString>& ignore );

    virtual void breakReferences();

    virtual bool hasNode() const;

    virtual bool isNamespace() const {
      return true;
    }

    virtual void invalidatePrimaryCache( bool onlyNegative = false );
  
    virtual MemberInfo findMember( TypeDesc name, MemberInfo::MemberType type =  MemberInfo::AllTypes );

    virtual TQValueList<TypePointer> getMemberClasses( const TypeDesc& name ) ;

  private:
    struct HashedStringHasher {
      size_t operator () ( const HashedStringSet& s ) const {
        return s.hash();
      }
    };
    //Maps from HashedStringSet to the count of slaves when the item was cached, and the SlaveList
//     typedef __gnu_cxx::hash_map<HashedStringSet, std::pair<size_t, SlaveList>, HashedStringHasher> SlavesCache;
  //SlavesCache m_slavesCache;
    TQValueList<TypePointer> getMemberClasses( const TypeDesc& name, std::set<HashedString>& ignore ) ;

    MemberInfo setupMemberInfo( const TQStringList& subName, const ImportList& imports );

    //TypePointer locateNamespace( const TypeDesc& alias );

    //void recurseAliasMap() ;
};


#endif
// kate: indent-mode csands; tab-width 4;