Debian Codegraph @

CodeLite/CxxPreProcessorScanner.h

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // Copyright : (C) 2015 Eran Ifrah
5 // File name : CxxPreProcessorScanner.h
6 //
7 // -------------------------------------------------------------------------
8 // A
9 // _____ _ _ _ _
10 // / __ \ | | | | (_) |
11 // | / \/ ___ __| | ___| | _| |_ ___
12 // | | / _ \ / _ |/ _ \ | | | __/ _ )
13 // | \__/\ (_) | (_| | __/ |___| | || __/
14 // \____/\___/ \__,_|\___\_____/_|\__\___|
15 //
16 // F i l e
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25
26 #ifndef CXXPREPROCESSORSCANNER_H
27 #define CXXPREPROCESSORSCANNER_H
28
29 #include "CxxLexerAPI.h"
30 #include "codelite_exports.h"
31 #include <list>
32 #include <unordered_set>
33 #include <wx/sharedptr.h>
34 #include <wx/string.h>
35
36 class CxxPreProcessor;
37 class WXDLLIMPEXP_CL CxxPreProcessorScanner
38 {
39 protected:
40 Scanner_t m_scanner;
41 wxFileName m_filename;
42 size_t m_options;
43 std::unordered_set<wxString>& m_visitedFiles;
44
45 public:
46 typedef wxSharedPtr<CxxPreProcessorScanner> Ptr_t;
47
48 private:
49 /**
50 * @brief run the scanner until we reach the closing #endif
51 * directive
52 * Note that this function consumes the 'endif' directive
53 */
54 bool ConsumeBlock();
55 /**
56 * @brief run the scanner until it reaches the next pre processor branch
57 * or until it finds the closing #endif directive
58 * Note that this function also consumes the directive 'endif'
59 * but will _not_ consume the elif/else directives
60 */
61 bool ConsumeCurrentBranch();
62 /**
63 * @brief read the next token that matches 'type'
64 * If we reached the end of the 'PreProcessor' state and there is no match
65 * throw an exception
66 */
67 void ReadUntilMatch(int type, CxxLexerToken& token);
68
69 void GetRestOfPPLine(wxString& rest, bool collectNumberOnly = false);
70 bool CheckIfDefined(const CxxPreProcessorToken::Map_t& table);
71 bool CheckIf(const CxxPreProcessorToken::Map_t& table);
72 bool IsTokenExists(const CxxPreProcessorToken::Map_t& table, const CxxLexerToken& token);
73
74 public:
75 CxxPreProcessorScanner(const wxFileName& file, size_t options, std::unordered_set<wxString>& visitedFiles);
76
77 /**
78 * @brief return true if we got a valid scanner
79 */
80 bool IsNull() const
81 {
82 return m_scanner == NULL;
83 ;
84 }
85
86 virtual ~CxxPreProcessorScanner();
87
88 /**
89 * @brief the main parsing function
90 * @param ppTable
91 */
92 void Parse(CxxPreProcessor* pp);
93 };
94
95 #endif // CXXPREPROCESSORSCANNER_H