Giter VIP home page Giter VIP logo

chet's Introduction

Neslib - Base library used by other Neslib projects

Neslib is a (still small) library of Delphi utilities that is shared across some other Neslib projects.

License

Neslib is licensed under the Simplified BSD License.

See License.txt for details.

chet's People

Contributors

alexeydott avatar chiptamer avatar erikvanbilsen avatar jarroddavis68 avatar michalsznajder avatar neslib avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chet's Issues

Ignore List does not exclude function symbols

I added

if FSymbolsToIgnore.ContainsKey(ACursor.Spelling) then
  Exit;

to the top of

procedure THeaderTranslator.WriteFunction(const ACursor: TCursor);

Which now seems to properly ignore function symbols as well. Can you please verify?

Thanks

Post Processing does not work

Hi,
My output pas file contains line starting with (* SRCVAL ( papoSource , eSrcType , ii ) and ends with *)
I tried to use a few post processing functions:

  • RemoveLineRangeAll("(*", "*)")
  • RemoveAllLines(" (* SRCVAL", 1)

but without any effect. Any suggestions?

Compile Error

I am able to produce a .pas file, but when I compile i get the following errors;

[DCC Error] eServiceAPI.pas(15): E2029 $IFEND expected but $ENDIF found
[DCC Error] eServiceAPI.pas(765): E2003 Undeclared identifier: 'UTF8Char'

Ok, so....

how do I:

  1. create sdl3.pas
  2. create sdl3_image.pas, that depends on sdl3.h and will pull in ALL the declarations of sdl3.h, when it only needs to reference them to build the unit?
  3. I see a new feature, ignore a comma separated list of headers, but that does not seem to work, or maybe I'm just not setting it up correctly?

???

Type declarations

I noticed problem with autogenerated types.
Theu are generated with colon

CPLError: procedure(...) varargs; cdecl;
CPLErrorV: procedure(...); cdecl;
CPLEmergencyError: procedure(...); cdecl;
CPLErrorReset: procedure(); cdecl;

but should with equal sign:

CPLError = procedure(...) varargs; cdecl;
CPLErrorV = procedure(...); cdecl;
CPLEmergencyError = procedure(...); cdecl;
CPLErrorReset = procedure(); cdecl;

Error

D10.2.3

clang_gettoken could not be located in libclang.dll

what now?

Fail to translate wchar_t define

For example:

#define TET_WCHAR_SHORT_VERSIONSTRING	L"5"

translate to

const
  TET_WCHAR_SHORT_VERSIONSTRING = L"5";

It fail to compile with Delphi.

CreateDynamicImport(0) should not parse comments

Static (default) mode in Chet is more stable than dynamic.
Example:
In static mode Chet returns code with comments correctly moved from C header.
In my case this comment contains string:

/**
The outer loop to be set for the face. If the
function succeeds, this loop will be deallocated.
*/

After using CreateDynamicImport(0) Chet generates the following method, which is a bug:
succeeds := GetProcAddress(aDLLHandle, 'succeeds');

Translation Error

Parsed error

// Callbacks should be prepared to treat NULL strings as empty strings.
typedef int (CALLBACK *PFNCHECKINPUTA)(HWND hWnd,LPARAM lParamCheckInput,LPCSTR lpszOrigString,LPCSTR lpszString,LPSTR pszErrorBuf,int cchErrorMax);
typedef int (CALLBACK *PFNCHECKINPUTW)(HWND hWnd,LPARAM lParamCheckInput,LPCWSTR lpszOrigString,LPCWSTR lpszString,LPWSTR pszErrorBuf,int cchErrorMax);
typedef BOOL (CALLBACK *PFNOKINPUTA)(HWND hWnd,LPARAM lParamCheckInput,LPCSTR lpszOrigString,LPCSTR lpszString);
typedef BOOL (CALLBACK *PFNOKINPUTW)(HWND hWnd,LPARAM lParamCheckInput,LPCWSTR lpszOrigString,LPCWSTR lpszString);

Change to

typedef int (__stdcall *PFNCHECKINPUTA)(HWND hWnd,LPARAM lParamCheckInput,LPCSTR lpszOrigString,LPCSTR lpszString,LPSTR pszErrorBuf,int cchErrorMax);
typedef int (__stdcall *PFNCHECKINPUTW)(HWND hWnd,LPARAM lParamCheckInput,LPCWSTR lpszOrigString,LPCWSTR lpszString,LPWSTR pszErrorBuf,int cchErrorMax);
typedef BOOL (__stdcall *PFNOKINPUTA)(HWND hWnd,LPARAM lParamCheckInput,LPCSTR lpszOrigString,LPCSTR lpszString);
typedef BOOL (__stdcall *PFNOKINPUTW)(HWND hWnd,LPARAM lParamCheckInput,LPCWSTR lpszOrigString,LPCWSTR lpszString);

Parsed

  PFNCHECKINPUTA = function(hWnd: HWND; lParamCheckInput: LPARAM; lpszOrigString: LPCSTR; lpszString: LPCSTR; pszErrorBuf: LPSTR; cchErrorMax: Integer): Integer; cdecl;
  PFNCHECKINPUTW = function(hWnd: HWND; lParamCheckInput: LPARAM; lpszOrigString: LPCWSTR; lpszString: LPCWSTR; pszErrorBuf: LPWSTR; cchErrorMax: Integer): Integer; cdecl;
  PFNOKINPUTA = function(hWnd: HWND; lParamCheckInput: LPARAM; lpszOrigString: LPCSTR; lpszString: LPCSTR): LongBool; cdecl;
  PFNOKINPUTW = function(hWnd: HWND; lParamCheckInput: LPARAM; lpszOrigString: LPCWSTR; lpszString: LPCWSTR): LongBool; cdecl;

cdecl ought to be stdcall

Chet does not support tm time struct from time.h

My header contains:
#include <time.h>
then uses the tm (c time struct) in the following method:
RESULT MyFunc(struct tm* load_time);
The output Delphi function is:

function MyFunc(load_time: Ptm): Result; cdecl;
  external MY_DLL name _PU + 'MyFunc';

but Ptm (pointer to tm is not defined anywhere) and I get [dcc64 Error] bindings.pas(5446): E2003 Undeclared identifier: 'Ptm' error in RAD Studio.

My workaround is to create a Delphi record and pointer to it in a helper unit:

  tm = record
   tm_sec: Integer;         // seconds,  range 0 to 59
   tm_min: Integer;         // minutes, range 0 to 59
   tm_hour: Integer;        // hours, range 0 to 23
   tm_mday: Integer;        // day of the month, range 1 to 31
   tm_mon: Integer;         // month, range 0 to 11
   tm_year: Integer;        // The number of years since 1900
   tm_wday: Integer;        // day of the week, range 0 to 6
   tm_yday: Integer;        // day in the year, range 0 to 365
   tm_isdst: Integer;       // daylight saving time
  end;

  Ptm = ^tm;  

Shouldn't Chet do it automatically?

Chet does not preserve the constness of function / procedure parameters

First of all I need to say that Chet is excellent in most ways... by far the best C-header-to-Pascal translator available.

One problem I have found with it however (as this issue title says) is that it does not preserve the constness of function or procedure arguments. For example, I recently used it to do a translation of cimgui, which does work fine but for which functions that originally looked like this:

ImColor* ImColor_ImColorVec4(const ImVec4 col);

were translated to stuff like this:

function ImColor_ImColorVec4(col: ImVec4): PImColor;

In that particular case, ImVec4 is a 16-byte struct that certainly should be passed by reference, but that simply won't be no matter what by either Delphi or Free Pascal without the const specifier present.

Converting C structs issue

If I have a struct such as this:

typedef struct unz_file_info_s
{
    int version;              /* version made by                 2 bytes */
    int version_needed;       /* version needed to extract       2 bytes */
    int flag;                 /* general purpose bit flag        2 bytes */
    int compression_method;   /* compression method              2 bytes */
    int dosDate;              /* last mod file date in Dos fmt   4 bytes */
    int crc;                  /* crc-32                          4 bytes */
    int compressed_size;      /* compressed size                 4 bytes */
    int uncompressed_size;    /* uncompressed size               4 bytes */
    int size_filename;        /* filename length                 2 bytes */
    int size_file_extra;      /* extra field length              2 bytes */
    int size_file_comment;    /* file comment length             2 bytes */

    int disk_num_start;       /* disk number start               2 bytes */
    int internal_fa;          /* internal file attributes        2 bytes */
    int external_fa;          /* external file attributes        4 bytes */

    int tmu_date;
} unz_file_info;

when converted, it will create this and cut off the last two fields?? Do you limit the total number of fields or what is going on with this? How can I fix it?

type
  Punz_file_info_s = ^unz_file_info_s;

  unz_file_info_s = record
    version: Integer;
    version_needed: Integer;
    flag: Integer;
    compression_method: Integer;
    dosDate: Integer;
    crc: Integer;
    compressed_size: Integer;
    uncompressed_size: Integer;
    size_filename: Integer;
    size_file_extra: Integer;
    size_file_comment: Integer;
    disk_num_start: Integer;
    internal_fa: Integer;
  end;

  unz_file_info = unz_file_info_s;

web based translation

Perhaps a web based translation can be created, copy-paste a few headers and produce translation - it his feasible?

convert the `struct *` to `TArray<>`

A c header file:

typedef struct metadata {
   struct metadata_broker *brokers;
} metadata_t;

convert to pascal:

type
  metadata = record
    brokers: pmetadata_broker;
  end;

Is that possible to convert the struct * to TArray<> in pascal?

type
  metadata = record
    brokers: TArray<metadata_broker>;
  end;

Pulling in extra includes

How do you handle this scenario where you have maybe SDL_image (single header) which depends on SDL (multiple headers). When ran, it will pull in every single reference in SDL when only 2 or 3 items are referenced in SDL_image.

Anonymous Unions

PSDL_RWops::(unnamed at C:\Dev\Utils\Chet\projects\SDL\includes\SDL_rwops.h:109:13) = ^SDL_RWops::(unnamed at C:\Dev\Utils\Chet\projects\SDL\includes\SDL_rwops.h:109:13);

I'm getting a lot of these type of things now? Does not seem to handle anonymous unions any longer?

Generate pointer types for C unions

What changes need to be made so that PsfEvent is created for a union such as:

typedef union
{
    sfEventType             type;             ///< Type of the event
    sfSizeEvent             size;             ///< Size event parameters
    sfKeyEvent              key;              ///< Key event parameters
    sfTextEvent             text;             ///< Text event parameters
    sfMouseMoveEvent        mouseMove;        ///< Mouse move event parameters
    sfMouseButtonEvent      mouseButton;      ///< Mouse button event parameters
    sfMouseWheelEvent       mouseWheel;       ///< Mouse wheel event parameters (deprecated)
    sfMouseWheelScrollEvent mouseWheelScroll; ///< Mouse wheel event parameters
    sfJoystickMoveEvent     joystickMove;     ///< Joystick move event parameters
    sfJoystickButtonEvent   joystickButton;   ///< Joystick button event parameters
    sfJoystickConnectEvent  joystickConnect;  ///< Joystick (dis)connect event parameters
    sfTouchEvent            touch;            ///< Touch events parameters
    sfSensorEvent           sensor;           ///< Sensor event parameters
} sfEvent;

If it was a struct, the pointer type is created.

Add DelayLoading option for external procedure

Delphi allow declare external function as delay loading. It would be nice to have an option to specify delayed in external procedure declaration.

Example:

function GetDesktopWindow: HWND; stdcall; external user32 name 'GetDesktopWindow' delayed;
function GetFooBar: Integer; stdcall; external kernel32 name 'GetFooBar' delayed;
function GetFooBarBar: Integer; stdcall; external 'kernel33' name 'GetFooBarBar' delayed;

How to include struct tm from C standard library?

How to
#include <ctime>
to properly convert struct tm to Delphi?

Here is the structure definition:

struct tm {
   int tm_sec;         /* seconds,  range 0 to 59          */
   int tm_min;         /* minutes, range 0 to 59           */
   int tm_hour;        /* hours, range 0 to 23             */
   int tm_mday;        /* day of the month, range 1 to 31  */
   int tm_mon;         /* month, range 0 to 11             */
   int tm_year;        /* The number of years since 1900   */
   int tm_wday;        /* day of the week, range 0 to 6    */
   int tm_yday;        /* day in the year, range 0 to 365  */
   int tm_isdst;       /* daylight saving time             */	
};

https://en.cppreference.com/w/c/chrono/tm

Fatal error

Hi,
I get the following error:

fatal error: 'myAPI/common.h' file not found
Parsed header files with 1 error(s)

The structure of headers:

  • myAPI
    • Application
      • application.h
    • common.h
    • myAPI.h
    • ....

Parser is in Application/application.h and tries to resolve the following include:
#include <myAPI/common.h>

How configure Chet to know that it should looks for common.h in parent folder?

Post Processing Support

So, I have been working on adding a feature that can "clean up" the converted header that will compile. After working on this problem for a while, I discovered that, when you manually modify the header, you will be adding, removing, and changing lines. So, wrote some code that will allow you to do this easily and automate the process.

Next, I added a simple scripting interface over these four routines, and this forms the basis of this modification. I got it integrated tonight and it seems to be working. Yay! I'm gonna tweak it a bit more then figure out how to do a PR, LOL.

Chet1

Chet2

Chet3

Chet4

error: unknown type name 'bool'

How to configure Chet if header uses bool type, but it does not define #include <stdbool.h>
For the example code:

struct IsLicense {
  bool is_licensed;
  char error[10];
};

Chet returns the following error:
error: unknown type name 'bool'

CreateDynamicImport(0) does not insert var before function declarations

Below you can find a sample Chet result with CreateDynamicImport(0) directive:
Delphi can not compile it because of the lack of the var keyword before function declarations.

type
   MyEnum= (
    enum0= 0,
    enum1= 1,
    enum2= 2);
  PMyEnum = ^MyEnum;

  // more types...

  MyRecord= record
    a: Double;
    b: Double;
    c: Double;
  end;

// here should be var!

  MyFunc1: function(...): MyResult; cdecl;
  MyFunc2: function(...): MyResult; cdecl;
  // more functions...

I need to use PostProcess / InsertLine to insert var after the last type declaration.

Error converting XMLSec library

I'm using your excellent tool to convert the XMLSec library for Win64 use.

I have downloaded the source from https://www.zlatkovic.com/pub/libxml/64bit/zlib-1.2.8-win32-x86_64.7z, unpacked it and am using Chet to process the libxml2 directory.

I get an error

Parsing header files...
C:\Temp\xmlsec\libxml2\include\libxml2\libxml\c14n.h:20:10: fatal error: 'libxml/xmlversion.h' file not found
Parsed header files with 1 error(s)

It looks to be choking on the c14n.h file where line 20 has an include directive
#include <libxml/xmlversion.h>

I'm not sure why it has the path, as this IS the path of the file currently being processed. How can the path be ignored ?

Chet does not translate "postfix" comments in a desirable way

Oftentimes, C and C++ headers containing data type declarations (structs, enums, and so on) will have line-by-line comments that follow the field they're documenting, as opposed to preceding it. For example:

typedef struct S {
  int A; /** Integral value */
  char* C; /** String value */
  float Y; /** Floating-point value */
} S;

When passed that code, Chet currently produces the following:

  S = record
    A: Integer;
    (* Integral value *)
    C: PUTF8Char;
    (* String value *)
    Y: Single;
  end;

which of course when run through Pasdoc will have no comment associated with the A field at all, and comments that are actually intended for the previous field for C and Y.

I'm aware that this perhaps might be somewhat difficult to implement, but it would certainly be a welcome bit of added functionality if there is any way to pull it off.

Error Messages

Hi,

when I try to translate a project I got:

error: unknown type name 'WORD'
error: unknown type name 'BYTE'

I have all dependency files installed (like Visual Studio).
What I'm doing wrong?
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.