| 1 |
////////////////////////////////////////////////////////////////////////////// |
| 2 |
////////////////////////////////////////////////////////////////////////////// |
| 3 |
// |
| 4 |
// Copyright : (C) 2015 Eran Ifrah |
| 5 |
// File name : CxxPreProcessor.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 CXXPREPROCESSOR_H |
| 27 |
#define CXXPREPROCESSOR_H |
| 28 |
|
| 29 |
#include "CxxLexerAPI.h" |
| 30 |
#include "CxxPreProcessorScanner.h" |
| 31 |
#include "codelite_exports.h" |
| 32 |
#include <set> |
| 33 |
#include <wx/filename.h> |
| 34 |
|
| 35 |
class WXDLLIMPEXP_CL CxxPreProcessor |
| 36 |
{ |
| 37 |
CxxPreProcessorToken::Map_t m_tokens; |
| 38 |
wxArrayString m_includePaths; |
| 39 |
std::set<wxString> m_noSuchFiles; |
| 40 |
std::unordered_map<wxString, wxString> m_fileMapping; |
| 41 |
size_t m_options; |
| 42 |
int m_maxDepth; |
| 43 |
int m_currentDepth; |
| 44 |
|
| 45 |
public: |
| 46 |
CxxPreProcessor(); |
| 47 |
CxxPreProcessor(const wxArrayString& search_paths, int maxDepth) |
| 48 |
: m_includePaths(search_paths) |
| 49 |
, m_options(0) |
| 50 |
, m_maxDepth(maxDepth) |
| 51 |
, m_currentDepth(0) |
| 52 |
{ |
| 53 |
} |
| 54 |
virtual ~CxxPreProcessor(); |
| 55 |
|
| 56 |
void SetMaxDepth(int maxDepth) { this->m_maxDepth = maxDepth; } |
| 57 |
int GetMaxDepth() const { return m_maxDepth; } |
| 58 |
void SetCurrentDepth(int currentDepth) { this->m_currentDepth = currentDepth; } |
| 59 |
void SetFileMapping(const std::unordered_map<wxString, wxString>& fileMapping) |
| 60 |
{ |
| 61 |
this->m_fileMapping = fileMapping; |
| 62 |
} |
| 63 |
int GetCurrentDepth() const { return m_currentDepth; } |
| 64 |
const std::unordered_map<wxString, wxString>& GetFileMapping() const { return m_fileMapping; } |
| 65 |
void SetIncludePaths(const wxArrayString& includePaths); |
| 66 |
const wxArrayString& GetIncludePaths() const { return m_includePaths; } |
| 67 |
|
| 68 |
void SetOptions(size_t options) { this->m_options = options; } |
| 69 |
size_t GetOptions() const { return m_options; } |
| 70 |
/** |
| 71 |
* @brief return a command that generates a single file with all defines in it |
| 72 |
*/ |
| 73 |
wxString GetGxxCommand(const wxString& gxx, const wxString& filename) const; |
| 74 |
CxxPreProcessorToken::Map_t& GetTokens() { return m_tokens; } |
| 75 |
|
| 76 |
const CxxPreProcessorToken::Map_t& GetTokens() const { return m_tokens; } |
| 77 |
void SetTokens(const CxxPreProcessorToken::Map_t& tokens) { m_tokens = tokens; } |
| 78 |
|
| 79 |
/** |
| 80 |
* @brief add search path to the PreProcessor |
| 81 |
*/ |
| 82 |
void AddIncludePath(const wxString& path); |
| 83 |
|
| 84 |
/** |
| 85 |
* @brief add definition in the form of A[=B] (=B is optional) |
| 86 |
*/ |
| 87 |
void AddDefinition(const wxString& def); |
| 88 |
/** |
| 89 |
* @brief resolve an include statement and return the full path for it |
| 90 |
* @param currentFile the current file being processed. ( we use it's path to resolve relative include |
| 91 |
* statements) |
| 92 |
* @param includeStatement the include statement found by the scanner |
| 93 |
* @param outFile [output] |
| 94 |
*/ |
| 95 |
bool ExpandInclude(const wxFileName& currentFile, const wxString& includeStatement, wxFileName& outFile); |
| 96 |
/** |
| 97 |
* @brief the main entry function |
| 98 |
* @param filename |
| 99 |
*/ |
| 100 |
void Parse(const wxFileName& filename, size_t options); |
| 101 |
|
| 102 |
/** |
| 103 |
* @brief return the definitions collected as an array |
| 104 |
* @return |
| 105 |
*/ |
| 106 |
wxArrayString GetDefinitions() const; |
| 107 |
|
| 108 |
/** |
| 109 |
* @brief return true if we can open another include file or not (depends on the max depts set |
| 110 |
* and the current depth) |
| 111 |
* @return |
| 112 |
*/ |
| 113 |
bool CanGoDeeper() const; |
| 114 |
|
| 115 |
/** |
| 116 |
* @brief increase the current include depth |
| 117 |
*/ |
| 118 |
void IncDepth(); |
| 119 |
|
| 120 |
/** |
| 121 |
* @brief decrease the current include depth |
| 122 |
*/ |
| 123 |
void DecDepth(); |
| 124 |
}; |
| 125 |
|
| 126 |
#endif // CXXPREPROCESSOR_H |