Menu

[r2000]: / trunk / Src / Compilers.UGlobals.pas  Maximize  Restore  History

Download this file

321 lines (295 with data), 11.3 kB

  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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
{
* Compilers.UGlobals.pas
*
* Declares various types that describe the compiler and compilation results and
* defines interfaces to compiler objects.
*
* $Rev$
* $Date$
*
* ***** BEGIN LICENSE BLOCK *****
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The Original Code is Compilers.UGlobals.pas, formerly IntfCompilers.pas
*
* The Initial Developer of the Original Code is Peter Johnson
* (http://www.delphidabbler.com/).
*
* Portions created by the Initial Developer are Copyright (C) 2005-2011 Peter
* Johnson. All Rights Reserved.
*
* Contributor(s)
* NONE
*
* ***** END LICENSE BLOCK *****
}
unit Compilers.UGlobals;
interface
uses
// Delphi
Generics.Collections, Classes, Graphics;
type
{
TCompilerID:
Enumeration that identifies all compilers supported by the program.
}
TCompilerID = (
ciD2, ciD3, ciD4, ciD5, ciD6, ciD7, // Delphi 2-7
ciD2005w32, ciD2006w32, // Delphi 2005/6 Win32 personality
ciD2007, // Delphi 2007 for Win32
ciD2009w32, // Delphi 2009 Win32 personality
ciD2010, // Delphi 2010
ciDXE, // Delphi XE
ciDXE2, // Delphi XE2
ciFPC // Free Pascal
);
const
// Sets grouping compiler ids into compiler types
cClassicDelphiCompilers = // Classic Borland / Inprise Delphi
[ciD2, ciD3, ciD4, ciD5, ciD6, ciD7];
cBDSCompilers = // BDS based compilers
[ciD2005w32, ciD2006w32, ciD2007, ciD2009w32, ciD2010, ciDXE, ciDXE2];
cFreePascalCompilers = // Free Pascal
[ciFPC];
type
{
TCompileResult:
Enumeration of possible results of a compilation.
}
TCompileResult = (
crSuccess, // successful compilation without warnings
crWarning, // successful compilation with warnings
crError, // compilation failed
crQuery // compilation result not known
);
{
TCompileResults:
Defines array of TCompileResult values with an entry for each supported
compiler.
}
TCompileResults = array[TCompilerID] of TCompileResult;
{
TCompLogPrefixID:
Enumeration of different prefixes compiler logs can recognise in a log file.
The values are used to map onto the prefix text used by for a specific
compiler.
}
TCompLogPrefixID = (
cpFatal, // identifies fatal error messages in log file
cpError, // identifies error messages in log file
cpWarning // identifies warnings in log file
);
{
TCompLogPrefixes
Defines array used to record prefix text used to detect error and warning
lines in compiler log files.
}
TCompLogPrefixes = array[TCompLogPrefixID] of string;
{
TCompLogFilter:
Enumeration of various filter types that can be applied to compiler output
logs.
}
TCompLogFilter = (
cfAll, // no filtering: use all of log
cfWarnings, // filter out anything that is not a warning message
cfErrors // filter out anything that is not an error message
);
type
/// <summary>
/// Interface to list of directories to be searched by a compiler when
/// looking for files.
/// </summary>
ISearchDirs = interface(IInterface)
['{77CAFAC1-9B0F-4244-9FFF-A9FB4EBDEE8B}']
/// <summary>Creates and returns enumerator for directories list.</summary>
function GetEnumerator: TEnumerator<string>;
/// <summary>Adds a new search directory to list.</summary>
procedure Add(const DirName: string);
/// <summary>Clears list.</summary>
procedure Clear;
/// <summary>Checks if list is empty.</summary>
function IsEmpty: Boolean;
/// <summary>Returns an array containing the names of all directories in
/// the list.</summary>
function ToStrings: TArray<string>;
end;
{
ICompiler:
Interface that must be supported by any object that represents a compiler.
Exposes methods used to get information about the compiler, to execute the
compiler and to process the compiler's log file.
}
ICompiler = interface(IInterface)
['{8D473D8A-3341-401C-B054-17E9334DF6A6}']
function GetName: string;
{Provides the human readable name of the compiler.
@return Compiler name.
}
function GetID: TCompilerID;
{Provides the unique id of the compiler.
@return Compiler Id code.
}
function GetIDString: string;
{Provides a non-localisable string that identifies the compiler.
@return Compiler Id string.
}
function GetGlyph: TBitmap;
{Returns reference to any 18x18 bitmap associated with the compiler.
@return Reference to bitmap or nil if there is no associated bitmap.
}
function IsAvailable: Boolean;
{Tells whether the compiler is installed on this computer and made
available to CodeSnip.
@return True if compiler is available to CodeSnip.
}
function GetExecFile: string;
{Gets full path to compiler's executable file.
@return Required path.
}
procedure SetExecFile(const Value: string);
{Stores full path to compiler's executable file.
@param Value [in] Path to compiler.
}
function GetDefaultSwitches: string;
{Returns default command line switches for compiler.
@return Switches separated by commas.
}
function GetSwitches: string;
{Returns user-defined swtches to be used by compiler.
@return Required switches separated by commas.
}
procedure SetSwitches(const Switches: string);
{Sets user defined switches.
@param Switches [in] Required switches separated by commas.
}
function GetSearchDirs: ISearchDirs;
{Returns copy of list of search directories used by compiler.
@return Required list of directories.
}
procedure SetSearchDirs(Dirs: ISearchDirs);
{Stores a copy of given list of search directories.
@param Dirs [in] List of search directories.
}
function GetLogFilePrefixes: TCompLogPrefixes;
{Returns prefixes used in interpreting error, fatal error and warning
conditions in log files.
@return Array of prefix strings.
}
procedure SetLogFilePrefixes(const Prefixes: TCompLogPrefixes);
{Records prefixes used in interpreting error, fatal error and warning
conditions in log files.
@param Prefixes [in] Array of required prefix strings.
}
function Compile(const Path, Project: string): TCompileResult;
{Compiles a project and returns result of compilation. Records result of
compilation and compiler's output log.
@param Path [in] Path where the project is found.
@param Project [in] Name of project (source) file.
@return Result of compilation i.e. success, warnings or error.
@except Exception raised if we can't execute the compiler.
}
procedure DeleteObjFiles(const Path, Project: string);
{Delete binary intermdiates files created during a compilation. Does
nothing if there has been no compilation.
@param Path [in] Path where project file is found.
@param Project [in] Name of project (source file)
}
procedure Log(const Filter: TCompLogFilter; const Lines: TStrings);
overload;
{Copies filtered compiler log to a string list.
@param Filter [in] Indicates how log to be filtered i.e. return all log,
return warnings only or return errors only.
@param Lines [in] List of string in filtered log (cleared if no
entries).
}
function Log(const Filter: TCompLogFilter): string;
overload;
{Returns compiler log as a CRLF delimited string using a filter.
@param Filter [in] Indicates how log to be filtered i.e. return all log,
return warnings only or return errors only.
@return Text of log, with lines separated by CRLF.
}
function HasErrorsOrWarnings: Boolean;
{Checks if last compile result was an error or a warning.
@return True if there are errors or warning, False otherwise.
}
function GetLastCompileResult: TCompileResult;
{Informs of result of last compilation by this compiler.
@return Result of last compilation or crQuery of compiler not available.
}
end;
{
ICompilers:
Interface implemented by an object that maintans a list of all compilers
supported by the program.
}
ICompilers = interface(IInterface)
['{39083768-2479-4F39-8473-0BDA381E1E81}']
function GetCompiler(CompID: TCompilerID): ICompiler;
{Read accessor for Compilers property. Returns requested compiler object.
@param CompID [in] Id of required compiler.
@return Requested compiler object.
}
function GetCount: Integer;
{Read access method for Count property.
@return Number of compilers in list.
}
function GetAvailableCount: Integer;
{Read access method for AvailableCount property
@return Number of installed compilers available to program.
}
function GetEnumerator: TEnumerator<ICompiler>;
{Gets an enumerator that enumerates all compilers in this object.
@return Required enumerator.
}
property Compilers[Ver: TCompilerID]: ICompiler
read GetCompiler; default;
{List of all compilers supported by the program, indexed by compiler id}
property Count: Integer
read GetCount;
{Number of compilers in list}
property AvailableCount: Integer
read GetAvailableCount;
{Number of compilers installed on this computer and made available to
program}
end;
{
IPersistCompilers:
Iterface supported by objects that can save and load an ICompilers object to
and from persistent storage, e.g. the program's ini file.
}
IPersistCompilers = interface(IInterface)
['{76A78863-5B95-4ECA-9295-75A98994EFA5}']
procedure Save(const Compilers: ICompilers);
{Save a list of compilers to storage.
@param Compilers [in] List of compilers to save.
}
procedure Load(const Compilers: ICompilers);
{Load a list of compilers from persistent storage.
@param Compilers [in] List of compilers to load.
}
end;
{
ICompilerAutoDetect:
Interface supported by compiler objects that can detect their executable
file path as registered on the host computer.
}
ICompilerAutoDetect = interface(IInterface)
['{62FE97CE-4616-406B-A9C2-D4B3BC751936}']
function DetectExeFile: Boolean;
{Detects and records path to command line compiler if present.
@return True if compiler path found, false otherwise.
}
end;
implementation
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.