| 1 |
////////////////////////////////////////////////////////////////////////////// |
| 2 |
////////////////////////////////////////////////////////////////////////////// |
| 3 |
// |
| 4 |
// copyright : (C) 2014 Eran Ifrah |
| 5 |
// file name : pptable.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 PPTABLE_H |
| 27 |
#define PPTABLE_H |
| 28 |
|
| 29 |
#include <wx/arrstr.h> |
| 30 |
#include <map> |
| 31 |
#include <wx/ffile.h> |
| 32 |
#include <vector> |
| 33 |
#include <string> |
| 34 |
#include <list> |
| 35 |
#include <set> |
| 36 |
|
| 37 |
#ifndef WXDLLIMPEXP_CL |
| 38 |
|
| 39 |
#ifdef WXMAKINGDLL_CL |
| 40 |
#define WXDLLIMPEXP_CL __declspec(dllexport) |
| 41 |
#elif defined(WXUSINGDLL_CL) |
| 42 |
#define WXDLLIMPEXP_CL __declspec(dllimport) |
| 43 |
#else // not making nor using DLL |
| 44 |
#define WXDLLIMPEXP_CL |
| 45 |
#endif |
| 46 |
|
| 47 |
#endif |
| 48 |
|
| 49 |
struct WXDLLIMPEXP_CL CLReplacement { |
| 50 |
bool is_compound; |
| 51 |
bool is_ok; |
| 52 |
std::string full_pattern; |
| 53 |
std::string searchFor; |
| 54 |
std::string replaceWith; |
| 55 |
void construct(const std::string& pattern, const std::string& replacement); |
| 56 |
}; |
| 57 |
|
| 58 |
typedef std::list<CLReplacement> CLReplacementList; |
| 59 |
|
| 60 |
/** |
| 61 |
* @brief perform search and replace using CL pattern |
| 62 |
* an example: |
| 63 |
* pattern=wx_dynamic_cast(%0, %1) |
| 64 |
* replacement=dynamic_cast<%0>(%1) |
| 65 |
* in=wx_dynamic_cast(wxApp*, ptr)->OnInit(); |
| 66 |
* |
| 67 |
* the expected result is: |
| 68 |
* dynamic_cast<wxApp*>(ptr)->OnInit() |
| 69 |
* |
| 70 |
* It also supports simple search and replace |
| 71 |
*/ |
| 72 |
bool CLReplacePattern(const wxString& in, const wxString& pattern, const wxString& replacement, wxString& output); |
| 73 |
|
| 74 |
/** |
| 75 |
* @brief perform search and replace using CL pattern |
| 76 |
* an example: |
| 77 |
* pattern=wx_dynamic_cast(%0, %1) |
| 78 |
* replacement=dynamic_cast<%0>(%1) |
| 79 |
* in=wx_dynamic_cast(wxApp*, ptr)->OnInit(); |
| 80 |
* |
| 81 |
* the expected result is: |
| 82 |
* dynamic_cast<wxApp*>(ptr)->OnInit() |
| 83 |
* |
| 84 |
* It also supports simple search and replace |
| 85 |
*/ |
| 86 |
bool CLReplacePatternA(const std::string& in, const CLReplacement& repl, std::string& outStr); |
| 87 |
|
| 88 |
/** |
| 89 |
* |
| 90 |
*/ |
| 91 |
struct WXDLLIMPEXP_CL PPToken { |
| 92 |
enum { IsFunctionLike = 0x00000001, IsValid = 0x00000002, IsOverridable = 0x00000004 }; |
| 93 |
|
| 94 |
int line; // line where found |
| 95 |
wxString name; // preprocessor name |
| 96 |
wxString replacement; // un processed replacement |
| 97 |
wxArrayString args; // for function like macros, contains the argument's names |
| 98 |
size_t flags; // PP token flags |
| 99 |
wxString fileName; |
| 100 |
|
| 101 |
PPToken() |
| 102 |
: line(0) |
| 103 |
, flags(IsOverridable) |
| 104 |
{ |
| 105 |
} |
| 106 |
|
| 107 |
~PPToken() {} |
| 108 |
|
| 109 |
void expandOnce(const wxArrayString& initList); |
| 110 |
void processArgs(const wxString& argsList); |
| 111 |
wxString signature() const; |
| 112 |
void print(wxFFile& fp); |
| 113 |
static bool readInitList(const wxString& in, int from, wxString& initList, wxArrayString& initListArr); |
| 114 |
static bool |
| 115 |
readInitList(const std::string& in, size_t from, std::string& initList, std::vector<std::string>& initListArr); |
| 116 |
void squeeze(); |
| 117 |
wxString fullname() const; |
| 118 |
}; |
| 119 |
|
| 120 |
class WXDLLIMPEXP_CL PPTable |
| 121 |
{ |
| 122 |
std::map<wxString, PPToken> m_table; |
| 123 |
std::set<wxString> m_namesUsed; |
| 124 |
|
| 125 |
public: |
| 126 |
static PPTable* Instance(); |
| 127 |
static void Release(); |
| 128 |
|
| 129 |
private: |
| 130 |
PPTable(); |
| 131 |
~PPTable(); |
| 132 |
|
| 133 |
public: |
| 134 |
PPToken Token(const wxString& name); |
| 135 |
bool Contains(const wxString& name); |
| 136 |
void Add(const PPToken& token); |
| 137 |
void AddUsed(const wxString& name); |
| 138 |
void Print(wxFFile& fp); |
| 139 |
wxString Export(); |
| 140 |
void Clear(); |
| 141 |
void ClearNamesUsed(); |
| 142 |
void Squeeze(); |
| 143 |
|
| 144 |
const std::map<wxString, PPToken>& GetTable() const { return m_table; } |
| 145 |
|
| 146 |
const std::set<wxString>& GetNamesUsed() const { return m_namesUsed; } |
| 147 |
}; |
| 148 |
#endif // PPTABLE_H |