File: compiler.h

package info (click to toggle)
codelite 17.0.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 136,244 kB
  • sloc: cpp: 491,547; ansic: 280,393; php: 10,259; sh: 8,930; lisp: 7,664; vhdl: 6,518; python: 6,020; lex: 4,920; yacc: 3,123; perl: 2,385; javascript: 1,715; cs: 1,193; xml: 1,110; makefile: 804; cobol: 741; sql: 709; ruby: 620; f90: 566; ada: 534; asm: 464; fortran: 350; objc: 289; tcl: 258; java: 157; erlang: 61; pascal: 51; ml: 49; awk: 44; haskell: 36
file content (272 lines) | stat: -rw-r--r-- 10,489 bytes parent folder | download | duplicates (2)
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2008 by Eran Ifrah
// file name            : compiler.h
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    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 COMPILER_H
#define COMPILER_H

#include "GCCMetadata.hpp"
#include "asyncprocess.h"
#include "codelite_exports.h"
#include "configuration_object.h"
#include "smart_ptr.h"

#include <list>
#include <map>
#include <memory>
#include <vector>
#include <wx/arrstr.h>
#include <wx/clntdata.h>
#include <wx/regex.h>
#include <wx/string.h>

/**
 * \ingroup LiteEditor
 * This class represents a compiler entry in the configuration file
 *
 * \version 1.0
 * first version
 *
 * \date 05-25-2007
 *
 * \author Eran
 */
class WXDLLIMPEXP_SDK Compiler : public ConfObject
{
public:
    enum eSeverity { kSevError, kSevWarning, kSevNote };

    enum CmpFileKind { CmpFileKindSource, CmpFileKindResource };

    struct CmpFileTypeInfo {
        wxString extension;
        wxString compilation_line;
        CmpFileKind kind;
    };

    struct CmpCmdLineOption {
        wxString name;
        wxString help;
    };
    typedef std::map<wxString, CmpCmdLineOption> CmpCmdLineOptions;

    struct CmpInfoPattern {
        wxString pattern;
        wxString lineNumberIndex;
        wxString fileNameIndex;
        wxString columnIndex;
        std::shared_ptr<wxRegEx> re;
    };

    /// If a file matches a regular expression, this structure
    /// will hold the information about it
    struct PatternMatch : public wxClientData {
        wxString file_path;
        Compiler::eSeverity sev = kSevError;
        int line_number = wxNOT_FOUND;
        int column = wxNOT_FOUND;
    };

    struct LinkLine {
        wxString lineFromFile;
        wxString line;
    };

    enum eRegexType { kRegexVC = 0, kRegexGNU };
    typedef std::list<CmpInfoPattern> CmpListInfoPattern;

private:
    void AddPattern(int type, const wxString& pattern, int fileNameIndex, int lineNumberIndex,
                    int colIndex = wxNOT_FOUND);
    void AddDefaultGnuCompilerOptions();
    void AddDefaultGnuLinkerOptions();
    void AddDefaultGnuCompilerLinkerOptions();

protected:
    wxString m_name;
    std::map<wxString, wxString> m_switches;
    std::map<wxString, Compiler::CmpFileTypeInfo> m_fileTypes;
    CmpCmdLineOptions m_compilerOptions;
    CmpCmdLineOptions m_linkerOptions;
    wxString m_objectSuffix;
    wxString m_dependSuffix;
    wxString m_preprocessSuffix;
    CmpListInfoPattern m_errorPatterns;
    CmpListInfoPattern m_warningPatterns;
    std::map<wxString, wxString> m_tools;
    wxString m_globalIncludePath;
    wxString m_globalLibPath;
    wxString m_pathVariable;
    bool m_generateDependeciesFile;
    bool m_readObjectFilesFromList;
    bool m_objectNameIdenticalToFileName;
    wxString m_compilerFamily;
    bool m_isDefault;
    wxString m_installationPath;
    wxArrayString m_compilerBuiltinDefinitions;
    std::map<wxString, LinkLine> m_linkerLines;

private:
    wxString GetGCCVersion() const;
    wxString GetIncludePath(const wxString& pathSuffix) const;
    wxArrayString POSIXGetIncludePaths() const;
    bool IsMatchesPattern(CmpInfoPattern& pattern, eSeverity severity, const wxString& line,
                          PatternMatch* match_result) const;

public:
    typedef std::map<wxString, wxString>::const_iterator ConstIterator;

    Compiler(wxXmlNode* node, Compiler::eRegexType regexType = Compiler::kRegexGNU);
    virtual ~Compiler();

    /**
     * @brief attempt to parse line and provide details about the parsed data
     */
    bool Matches(const wxString& line, PatternMatch* match_result);

    /**
     * @brief return { "PATH", "/compiler/bin:$PATH"} pair
     */
    void CreatePathEnv(clEnvList_t* env_list);

    /**
     * @brief check if this compiler is a 64 bit compiler
     */
    bool Is64BitCompiler();

    /**
     * @brief return the compiler default include paths
     */
    wxArrayString GetDefaultIncludePaths();

    /**
     * @brief return true if this compiler is compatible with GNU compilers
     */
    bool IsGnuCompatibleCompiler() const;

    wxXmlNode* ToXml() const;
    void SetTool(const wxString& toolname, const wxString& cmd);
    void SetSwitch(const wxString& switchName, const wxString& switchValue);

    void SetInstallationPath(const wxString& installationPath) { this->m_installationPath = installationPath; }
    const wxString& GetInstallationPath() const { return m_installationPath; }
    void SetCompilerFamily(const wxString& compilerFamily) { this->m_compilerFamily = compilerFamily; }
    void SetIsDefault(bool isDefault) { this->m_isDefault = isDefault; }
    const wxString& GetCompilerFamily() const { return m_compilerFamily; }
    bool IsDefault() const { return m_isDefault; }
    // iteration over switches
    Compiler::ConstIterator SwitchesBegin() const { return m_switches.begin(); }
    Compiler::ConstIterator SwitchesEnd() const { return m_switches.end(); }

    void AddCompilerOption(const wxString& name, const wxString& desc);
    void AddLinkerOption(const wxString& name, const wxString& desc);
    void AddCompilerLinkerOption(const wxString& name, const wxString& desc);

    wxString GetLinkLine(const wxString& type, bool inputFromFile) const;
    void SetLinkLine(const wxString& type, const wxString& line, bool inputFromFile);

    /**
     * @brief return list of builtin macros for this compiler instance
     * @return
     */
    const wxArrayString& GetBuiltinMacros();

    //---------------------------------------------------
    // setters/getters
    //---------------------------------------------------
    wxString GetTool(const wxString& name) const;
    wxString GetSwitch(const wxString& name) const;

    const wxString& GetObjectSuffix() const { return m_objectSuffix; }
    void SetObjectSuffix(const wxString& suffix) { m_objectSuffix = suffix; }
    const wxString& GetDependSuffix() const { return m_dependSuffix; }
    void SetDependSuffix(const wxString& suffix) { m_dependSuffix = suffix; }
    const wxString& GetPreprocessSuffix() const { return m_preprocessSuffix; }
    void SetPreprocessSuffix(const wxString& suffix) { m_preprocessSuffix = suffix; }

    void SetName(const wxString& name) { m_name = name; }
    const wxString& GetName() const { return m_name; }
    const CmpListInfoPattern& GetErrPatterns() const { return m_errorPatterns; }
    const CmpListInfoPattern& GetWarnPatterns() const { return m_warningPatterns; }

    void SetErrPatterns(const CmpListInfoPattern& p) { m_errorPatterns = p; }
    void SetWarnPatterns(const CmpListInfoPattern& p) { m_warningPatterns = p; }

    void SetGlobalIncludePath(const wxString& globalIncludePath) { this->m_globalIncludePath = globalIncludePath; }
    void SetGlobalLibPath(const wxString& globalLibPath) { this->m_globalLibPath = globalLibPath; }
    const wxString& GetGlobalIncludePath() const { return m_globalIncludePath; }
    const wxString& GetGlobalLibPath() const { return m_globalLibPath; }

    void SetPathVariable(const wxString& pathVariable) { this->m_pathVariable = pathVariable; }
    const wxString& GetPathVariable() const { return m_pathVariable; }

    void SetFileTypes(const std::map<wxString, Compiler::CmpFileTypeInfo>& fileTypes)
    {
        m_fileTypes.clear();
        this->m_fileTypes = fileTypes;
    }

    const std::map<wxString, Compiler::CmpFileTypeInfo>& GetFileTypes() const { return m_fileTypes; }
    const std::map<wxString, LinkLine>& GetLinkerLines() const { return m_linkerLines; }
    void SetLinkerLines(const std::map<wxString, LinkLine>& lines) { m_linkerLines = lines; }

    const CmpCmdLineOptions& GetCompilerOptions() const { return m_compilerOptions; }

    void SetCompilerOptions(const CmpCmdLineOptions& cmpOptions) { m_compilerOptions = cmpOptions; }

    const CmpCmdLineOptions& GetLinkerOptions() const { return m_linkerOptions; }

    void SetLinkerOptions(const CmpCmdLineOptions& cmpOptions) { m_linkerOptions = cmpOptions; }

    void SetGenerateDependeciesFile(bool generateDependeciesFile)
    {
        this->m_generateDependeciesFile = generateDependeciesFile;
    }
    bool GetGenerateDependeciesFile() const { return IsGnuCompatibleCompiler() && m_generateDependeciesFile; }
    void SetReadObjectFilesFromList(bool readObjectFilesFromList)
    {
        this->m_readObjectFilesFromList = readObjectFilesFromList;
    }
    bool GetReadObjectFilesFromList() const { return m_readObjectFilesFromList; }
    void AddCmpFileType(const wxString& extension, CmpFileKind type, const wxString& compile_line);
    bool GetCmpFileType(const wxString& extension, Compiler::CmpFileTypeInfo& ft);
    void SetObjectNameIdenticalToFileName(bool objectNameIdenticalToFileName)
    {
        this->m_objectNameIdenticalToFileName = objectNameIdenticalToFileName;
    }
    bool GetObjectNameIdenticalToFileName() const { return m_objectNameIdenticalToFileName; }
    /**
     * @brief return the compiler metadata info
     */
    GCCMetadata GetMetadata() const;

    /**
     * @brief does this compiler support metadata object?
     */
    bool HasMetadata() const;
};

typedef SmartPtr<Compiler> CompilerPtr;
typedef std::vector<CompilerPtr> CompilerPtrVec_t;

#endif // COMPILER_H