Chet is a
.h-to-.pas translator powered by libclang for Delphi.
No longer like one more header translators, Chet makes utilize of the Clang compiler to parse header files, leading to more good translations that require fewer handbook adjustments.
Some vital aspects are:
- Translates C data forms reminiscent of structs, union, enums, typedefs, procedural forms and opaque forms.
- Translates C capabilities to Delphi procedures or capabilities.
- Tries to translate
#make cleardeclarations to constants where imaginable.
- Generates a single
.pasfile for a total directory of
.hfiles. This reduces factors consequently of dependencies between header files.
- Generates output for loads of platforms (Winsows, macOS, Linux, iOS and Android) if desired.
- You more than seemingly can furthermore customize the Clang parsing process by supplying give an explanation for line arguments to the compiler.
- You more than seemingly can furthermore customize the output of some conversion operations.
- Retains any Doxygen style documentation comments if desired, or converts them to XmlDoc comments or PasDoc comments.
- Affords a GUI for configuring the conversion process, and lets you save the conversion settings to a
.chetventure file for reuse.
- Chet handiest works with C header files, no longer with C++ header files.
- All non-inlined capabilities within the header files are translated and assumed to be on hand within the static or dynamic library for the venture. This would now not would possibly well furthermore smooth be the case. (Inlined capabilities are by no technique translated since they’re by no technique on hand within the library.)
- Since Clang is pale to parse the header files, this system that Clangs preprocessor is speed as smartly to select up conditional parsing (guided by
#ifdefdirectives). Here’s every felony and inappropriate. It’s felony attributable to it improves conversion accuracy. But it no doubt can even be inappropriate attributable to it makes utilize of the machine that Chet runs on to resolve some conditional paths. As an instance, attributable to Chet runs on Dwelling windows, this may well possibly well parse code in
#ifdef _WIN32sections however skip any code in sections for other platforms.
Since Chet makes utilize of an valid compiler, it’s seemingly you’ll well must have a (minimal) C construct environment installed, as smartly as LLVM with Clang. Clang needs to be ready to search out the machine headers for the come environment. These will generally be on hand whenever you happen to would possibly well furthermore have some model of Visible Studio with Visible C++ installed. The free (neighborhood) edition of Visible Studio suffices.
You more than seemingly can furthermore speed Chet first to examine for any errors linked to missing dependencies. Whereas you pick up any dependency errors when running the translator, then it’s seemingly you’ll well presumably download the dependencies here:
- LLVM with Clang (Clang for Dwelling windows (64-bit) is urged).
- Visible Studio IDE (the free Neighborhood edition suffices; make sure to set up C++ enhance).
You more than seemingly can furthermore utilize the pre-compiled 64-bit Dwelling windows Chet utility within the
Whereas you prefer to must compile Chet yourself, then you furthermore want libclang for Delphi and make obvious the Delphi IDE can get it (the Chet venture will get it robotically if the
Neslib.Clang directory is at the identical stage as the
Particular person Files
Chet is soft straightforward. In quite loads of circumstances, you handiest must provide a directory with header files, the name of the output
.pas file and catch “Lag Header Translator (F9)”.
For more adjust over the conversion process, it’s seemingly you’ll well presumably specify various options, described beneath.
Any configuration options you plight can even be saved to a
.chet configuration file (which is a clear-cut ini-file). This permits you to load the settings later to rerun the conversion (as an instance, when original versions of the header files were released). You more than seemingly can furthermore load and save these configuration options the utilize of the
To reduction pre-configure some settings for a original session, catch
File | New Venture... (Ctrl+N). You enter the name of the venture and Chet will pre-configure some settings per the name you enter (even supposing it’s seemingly you’ll well presumably consistently adjust those settings later).
Lag menu good as the one possibility
Lag Header Translator, which it’s seemingly you’ll well presumably furthermore activate with
The venture page contains the ideal configuration options:
- Directory with C Header files: specify the directory with the offer
.hfiles here. The directory would possibly well furthermore be relative to the directory containing the
.chetventure file. Click on the
...button to browse for a directory. It’s urged that you just originate no longer utilize the directory with the everyday C offer code. As an different, reproduction the header files to a separate directory good for conversion purposes. This makes it more uncomplicated to delete header files you originate no longer are searching for to become, or to make edits to header files for conversion purposes.
- Encompass subdirectories: take a look at this box if the header files are spread across loads of directories. In that case, Chet will search all subdirectories of the given directory as smartly.
- Purpose Pascal file: specify the name of the
.pasfile that will be generated. I single blended Pascal file will be generated for all parsed header files. The name would possibly well furthermore be relative to the directory containing the
.chetventure file. Click on the
...button to originate a save dialog.
- Comma-separated checklist of unit to “utilize”: if the header files rely on declarations in a single more Delphi objects (reminiscent of
Dwelling windows.Winapi), then it’s seemingly you’ll well presumably checklist those objects here. The want be added to the makes utilize of clause of the generated Pascal file.
On this page you specify what platforms you prefer to must target, and the device you prefer to must configure them.
- Library constant: specify the name of the constant to make utilize of for the library name. As an instance, whenever you happen to would possibly well furthermore have a library known as “mylib.dll”, then the name of this constant would be
LIB_MYLIB, so the following declaration will be generated:
const LIB_MYLIB = 'mylib.dll'.
Subsequent are checkboxes for all platforms you prefer to must target (32-bit Dwelling windows, 64-bit Dwelling windows, 32-bit macOS, 64-bit Linux, iOS and Android). For every platform that you just take a look at, you prefer to enter the following options:
- Library name: the name of the dynamic or static library for the platform.
- Prefix (_PU): the characteristic name prefix to make utilize of for the platform. This would possibly well well furthermore generally be left empty. But, counting on how the library is built, all characteristic names would possibly well furthermore be prefixed (generally with an underscore
Parse Choices Page
Here it’s seemingly you’ll well presumably customize the Clang parsing process.
- Ignore parse errors: take a look at this box to ignore any parsing errors and spend a witness at to translate the header files anyway. Point out that this may well possibly well lead to unsuitable output, so that you just on the total would possibly well furthermore smooth leave this options unchecked. You more than seemingly can furthermore get this possibility vital as a non permanent possibility to examine for parsing errors. In general, Clang will quit parsing after it encounters the major lethal error. By checking this box, this may well possibly well give an explanation for all parsing errors (as a lot as a limit), so that it’s seemingly you’ll well presumably address those and then uncheck this box but again.
- Repeat line arguments to pass to Clang: specify any give an explanation for line arguments to pass to the Clang compiler here. There may well be often no want for this, however some C projects would possibly well furthermore require some give an explanation for line arguments for parsing to prevail. The most typical give an explanation for line arguments it’s seemingly you’ll well presumably furthermore have are at the side of preprocessor defines (
-D) and embody search paths (
-I). There are separate buttons to make it more uncomplicated so as to add these. Refer to the Clang documentation for data about on hand give an explanation for line arguments.
Here’s where you customize the generated output.
- Calling convention: specify the calling convention to make utilize of for all translated capabilities. You more than seemingly can furthermore spend between
stdcall. In nearly all circumstances, it’s seemingly you’ll well presumably furthermore smooth utilize the default
cdeclcalling convention. Exercise
stdcallhandiest for 32-bit Dwelling windows DLL’s which you perceive are compiled with the stdcall calling convention. These are generally handiest Dwelling windows machine DLL’s. Most 3rd birthday celebration DLL’s utilize cdecl.
- Observation handling: here you specify the ideal device to take care of documentation comments (undercover agent furthermore remarks beneath):
- Serve comments as-is (default): originate no longer convert the comments, however retain them in their normal (Doxygen) style.
- Put off away comments: all comments will be removed.
- Convert comments to XmlDoc style (experimental): converts Doxygen-style comments to XmlDoc style comments (the default documentation style for Delphi). This characteristic is smooth beneath constructing and belief to be experimental.
- Convert comments to PasDoc style (experimental): converts Doxygen-style comments to PasDoc style comments. This characteristic is smooth beneath constructing and belief to be experimental.
- Convert “char” to: the C
charkind is ambiguous, it’ll also be pale as an 8-bit integer or a personality in a textual express string. The typed versions
unsigned charare consistently converted to
Byterespectively. But when no signed-ness is specified, it’s seemingly you’ll well presumably furthermore have the following options:
- UTF8Char (default): convert
charto a unsuitable-platform
- Shortint: convert
charto an 8-bit signed
- Byte: convert
charto an 8-bit unsigned
- UTF8Char (default): convert
- Reserved phrase handling: header files would possibly well furthermore utilize identifiers which war with reserved words in Delphi (reminiscent of
design). Here you specify the device you prefer to must become these identifiers:
- Add leading ‘&’ (default): prefix the identifier with an ampersand.
- Add leading ‘_’: prefix the identifier with an underscore.
- Add trailing ‘_’: add an underscore to the discontinue of the identifier.
- Treat directives as reserved words: whether to address Delphi directives as reserved words as smartly (checked by default). Technically, you are allowed to make utilize of many directives (reminiscent of
public) as identifiers in Delphi, however it no doubt appears to be like uncommon and Delphi’s syntax highlighter treats them in a completely different device. So you consistently are searching for to address these as reserved words as smartly.
- Enum handling: it’s seemingly you’ll well presumably furthermore have the chance of converting C enums in two ways:
- Convert to enumerated kind (default): convert to a Delphi enumerated kind.
- Convert to integer kind and constants: convert the kind name itself to an integer (as in
kind MyEnum = Integer;) and produce constants for every possibility within the enumeration. This would possibly well well furthermore be more relevant for some libraries.
- Unconvertible declarations: no subject ideal efforts, Chet would possibly well furthermore no longer be ready to become all declarations (especially
#make clear‘s, undercover agent remarks beneath). Here you specify the ideal device to take care of these:
- Write TODO merchandise (default): writes a
TODOcomment to the Delphi offer code, as smartly as a commented-out model of the everyday declaration. Take note that it’s seemingly you’ll well presumably see an inventory of all TODO’s within the Delphi IDE by deciding on
Undercover agent | Machine Dwelling windows | To-End Checklist.
- Observation out normal declaration: writes a commented-out model of the everyday declaration to the Delphi offer code.
- Ignore declaration: ignores the declaration and would now not write the relaxation to the Delphi offer code.
- Write TODO merchandise (default): writes a
Point out that handiest Doxygen style documentation comments are parsed by Clang. These are comments that follow any of these format conventions:
/// Observation (with 3 slashes)
/Observation (with two stars) */
/*! Observation (with exclamation point) */
///< Observation (applies to previous declaration)
/< Observation (applies to previous declaration) */
/*!< Observation (applies to previous declaration) */
Chet tries to become
#make clear declarations to constants if imaginable. This handiest works if:
- The make clear is no longer characteristic-take care of. That is, macros take care of
#make clear ABS(x) (x < 0) ? -x : xcan't be translated.
- The make clear makes utilize of an expression that handiest makes utilize of other defines and literals. As an instance:
#make clear FOO 3<
will be converted to
const FOO = 3 shl BAR.
Here it's seemingly you'll well presumably specify an inventory of symbols to ignore. These symbols is no longer going to be translated.
The most typical utilize is to ignore
#make clear's that generate conversion errors, or capabilities you originate no longer want. You more than seemingly can furthermore furthermore spend to ignore some forms, however that will lead to compilation errors later attributable to anticipated forms are missing.
Point out that symbols are case-sensitive.
The closing page good has a single button "Lag Header Translator" (which it's seemingly you'll well presumably furthermore activate with
F9). It exhibits the progress of the interpretation process, as smartly as any errors that took place while parsing the header files.
You more than seemingly can furthermore utilize these errors to repair the header files, add missing header files, or configure that parsing process by at the side of give an explanation for line arguments (as an instance, by at the side of embody search paths).
Chet is licensed beneath the Simplified BSD License. Look License.txt for particulars.