~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/plugins/codecompletion/parser/parser.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
 
3
 * http://www.gnu.org/licenses/gpl-3.0.html
 
4
 */
 
5
 
 
6
#ifndef PARSER_H
 
7
#define PARSER_H
 
8
 
 
9
#include <wx/string.h>
 
10
#include <wx/treectrl.h>
 
11
#include <wx/event.h>
 
12
#include <wx/timer.h>
 
13
#include <wx/file.h>
 
14
#include <wx/filefn.h> // wxPathList
 
15
#include "parserthread.h"
 
16
#include <cbthreadpool.h>
 
17
#include <sdk_events.h>
 
18
 
 
19
#ifndef STANDALONE
 
20
    #include <wx/imaglist.h>
 
21
#endif // STANDALONE
 
22
 
 
23
#define PARSER_IMG_NONE                -2
 
24
#define PARSER_IMG_CLASS_FOLDER        0
 
25
#define PARSER_IMG_CLASS            1
 
26
#define PARSER_IMG_CTOR_PRIVATE        2
 
27
#define PARSER_IMG_CTOR_PROTECTED    3
 
28
#define PARSER_IMG_CTOR_PUBLIC        4
 
29
#define PARSER_IMG_DTOR_PRIVATE        5
 
30
#define PARSER_IMG_DTOR_PROTECTED    6
 
31
#define PARSER_IMG_DTOR_PUBLIC        7
 
32
#define PARSER_IMG_FUNC_PRIVATE        8
 
33
#define PARSER_IMG_FUNC_PROTECTED    9
 
34
#define PARSER_IMG_FUNC_PUBLIC        10
 
35
#define PARSER_IMG_VAR_PRIVATE        11
 
36
#define PARSER_IMG_VAR_PROTECTED    12
 
37
#define PARSER_IMG_VAR_PUBLIC        13
 
38
#define PARSER_IMG_PREPROCESSOR        14
 
39
#define PARSER_IMG_ENUM                15
 
40
#define PARSER_IMG_ENUMERATOR        16
 
41
#define PARSER_IMG_NAMESPACE         17
 
42
#define PARSER_IMG_TYPEDEF         18
 
43
#define PARSER_IMG_SYMBOLS_FOLDER    19
 
44
#define PARSER_IMG_ENUMS_FOLDER        20
 
45
#define PARSER_IMG_PREPROC_FOLDER    21
 
46
#define PARSER_IMG_OTHERS_FOLDER    22
 
47
#define PARSER_IMG_TYPEDEF_FOLDER    23
 
48
 
 
49
#define PARSER_IMG_MIN PARSER_IMG_CLASS_FOLDER
 
50
#define PARSER_IMG_MAX PARSER_IMG_OTHERS_FOLDER
 
51
 
 
52
extern int PARSER_END;
 
53
class ClassTreeData : public BlockAllocated<ClassTreeData, 500>, public wxTreeItemData
 
54
{
 
55
    public:
 
56
        ClassTreeData(Token* token){ m_Token = token; }
 
57
        Token* GetToken(){ return m_Token; }
 
58
        void SetToken(Token* token){ m_Token = token; }
 
59
    private:
 
60
        Token* m_Token;
 
61
};
 
62
 
 
63
struct ParserOptions
 
64
{
 
65
    bool followLocalIncludes;
 
66
    bool followGlobalIncludes;
 
67
    bool caseSensitive;
 
68
    bool wantPreprocessor;
 
69
    bool useSmartSense;
 
70
};
 
71
 
 
72
enum BrowserDisplayFilter
 
73
{
 
74
    bdfFile = 0,
 
75
    bdfProject,
 
76
    bdfWorkspace,
 
77
};
 
78
 
 
79
struct BrowserOptions
 
80
{
 
81
    bool showInheritance; // default: false
 
82
    bool expandNS; // default: false (auto-expand namespaces)
 
83
    BrowserDisplayFilter displayFilter; // default: bdfWorkspace
 
84
};
 
85
 
 
86
class ClassBrowser;
 
87
class ClassBrowserBuilderThread;
 
88
 
 
89
class Parser : public wxEvtHandler
 
90
{
 
91
    public:
 
92
        friend class ClassBrowser;
 
93
        friend class ParserThread;
 
94
        Parser(wxEvtHandler* parent);
 
95
        ~Parser();
 
96
 
 
97
        void BatchParse(const wxArrayString& filenames);
 
98
        bool Parse(const wxString& filename, bool isLocal = true, LoaderBase* loader = 0);
 
99
        bool Parse(const wxString& bufferOrFilename, bool isLocal, ParserThreadOptions& opts);
 
100
        bool ParseBuffer(const wxString& buffer, bool isLocal = true, bool bufferSkipBlocks = false, bool isTemp = false);
 
101
        bool ParseBufferForFunctions(const wxString& buffer);
 
102
        bool ParseBufferForUsingNamespace(const wxString& buffer, wxArrayString& result);
 
103
        bool Reparse(const wxString& filename, bool isLocal = true);
 
104
        bool ReparseModifiedFiles();
 
105
        bool RemoveFile(const wxString& filename);
 
106
        void Clear();
 
107
        void ReadOptions();
 
108
        void WriteOptions();
 
109
        bool ReadFromCache(wxInputStream* f);
 
110
        bool WriteToCache(wxOutputStream* f);
 
111
        bool CacheNeedsUpdate();
 
112
 
 
113
        void StartStopWatch();
 
114
        void EndStopWatch();
 
115
        long EllapsedTime();
 
116
        long LastParseTime();
 
117
 
 
118
#ifndef STANDALONE
 
119
        int GetTokenKindImage(Token* token);
 
120
        void SetTokenKindImage(int kind, const wxBitmap& bitmap, const wxBitmap& mask = wxNullBitmap);
 
121
        void SetTokenKindImage(int kind, const wxBitmap& bitmap, const wxColour& maskColour);
 
122
        void SetTokenKindImage(int kind, const wxIcon& icon);
 
123
        wxImageList* GetImageList(){ return m_pImageList; }
 
124
#endif // STANDALONE
 
125
        Token* FindTokenByName(const wxString& name, bool globalsOnly = true, short int kindMask = 0xFFFF) const;
 
126
        Token* FindChildTokenByName(Token* parent, const wxString& name, bool useInheritance = false, short int kindMask = 0xFFFF) const;
 
127
        size_t FindMatches(const wxString& s,TokenList& result,bool caseSensitive = true,bool is_prefix = true);
 
128
 
 
129
        ParserOptions& Options(){ return m_Options; }
 
130
        BrowserOptions& ClassBrowserOptions(){ return m_BrowserOptions; }
 
131
 
 
132
        void ClearIncludeDirs(){ m_IncludeDirs.Clear(); }
 
133
        void AddIncludeDir(const wxString& dir);
 
134
        const wxArrayString& GetIncludeDirs() const { return m_IncludeDirs; }
 
135
        wxString GetFullFileName(const wxString& src,const wxString& tgt, bool isGlobal);
 
136
        wxString FindFirstFileInIncludeDirs(const wxString& file);
 
137
        wxArrayString FindFileInIncludeDirs(const wxString& file,bool firstonly = false);
 
138
 
 
139
        TokensTree* GetTokens(){ return m_pTokens; }
 
140
        TokensTree* GetTempTokens() { return m_pTempTokens; }
 
141
        unsigned int GetFilesCount();
 
142
 
 
143
        bool Done();
 
144
        void LinkInheritance(bool tempsOnly = false);
 
145
        void MarkFileTokensAsLocal(const wxString& filename, bool local, void* userData = 0);
 
146
 
 
147
        unsigned int GetMaxThreads()const { return m_Pool.GetConcurrentThreads(); }
 
148
        void SetMaxThreads(unsigned int max){ m_Pool.SetConcurrentThreads(max); }
 
149
 
 
150
        void TerminateAllThreads();
 
151
    protected:
 
152
        void OnParseFile(const wxString& filename,int flags);
 
153
        void OnAllThreadsDone(CodeBlocksEvent& event);
 
154
        void OnTimer(wxTimerEvent& event);
 
155
        void OnBatchTimer(wxTimerEvent& event);
 
156
    private:
 
157
        void ConnectEvents();
 
158
        void DisconnectEvents();
 
159
 
 
160
        ParserOptions m_Options;
 
161
        BrowserOptions m_BrowserOptions;
 
162
        SearchTree<wxString> m_GlobalIncludes;
 
163
        wxArrayString m_IncludeDirs;
 
164
        wxEvtHandler* m_pParent;
 
165
        wxTreeItemId m_RootNode;
 
166
#ifndef STANDALONE
 
167
        wxImageList* m_pImageList;
 
168
    protected:
 
169
        // the following three members are used to detect changes between
 
170
        // in-mem data and cache
 
171
        bool m_UsingCache; // true if loaded from cache
 
172
 
 
173
        cbThreadPool m_Pool;
 
174
        TokensTree* m_pTokens;
 
175
        TokensTree* m_pTempTokens;
 
176
        set<wxString, less<wxString> > m_LocalFiles;
 
177
        bool m_NeedsReparse;
 
178
        bool m_IsBatch;
 
179
        ClassBrowser* m_pClassBrowser; // Which class browser are we updating?
 
180
        int m_TreeBuildingStatus; // 0 = Done; 1 = Needs update; 2 = Updating.
 
181
        size_t m_TreeBuildingTokenIdx; // Bookmark for the tree-building process
 
182
    private:
 
183
        wxTimer m_timer,m_batchtimer;
 
184
        wxStopWatch m_StopWatch;
 
185
        bool m_StopWatchRunning;
 
186
        long m_LastStopWatchTime;
 
187
        bool m_IgnoreThreadEvents;
 
188
        bool m_ShuttingDown;
 
189
 
 
190
        ClassBrowserBuilderThread* m_pClassBrowserBuilderThread;
 
191
 
 
192
#endif // STANDALONE
 
193
 
 
194
        DECLARE_EVENT_TABLE()
 
195
};
 
196
 
 
197
#endif // PARSER_H