{"id":18397298,"url":"https://github.com/php-ffi/preprocessor","last_synced_at":"2025-08-20T19:11:14.532Z","repository":{"id":56982114,"uuid":"376651458","full_name":"php-ffi/preprocessor","owner":"php-ffi","description":"Simple C Preprocessor","archived":false,"fork":false,"pushed_at":"2025-01-23T20:38:57.000Z","size":172,"stargazers_count":23,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-14T15:15:44.905Z","etag":null,"topics":["c","compiler","php","preprocessor"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/php-ffi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-13T22:25:10.000Z","updated_at":"2025-06-09T19:09:31.000Z","dependencies_parsed_at":"2024-06-21T15:21:49.555Z","dependency_job_id":"c99332f2-b9e9-4b47-949f-9fed44f0fd22","html_url":"https://github.com/php-ffi/preprocessor","commit_stats":{"total_commits":22,"total_committers":2,"mean_commits":11.0,"dds":"0.045454545454545414","last_synced_commit":"ad3391b48dd648220b04b6126f7886f027b63be0"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/php-ffi/preprocessor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-ffi%2Fpreprocessor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-ffi%2Fpreprocessor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-ffi%2Fpreprocessor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-ffi%2Fpreprocessor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-ffi","download_url":"https://codeload.github.com/php-ffi/preprocessor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-ffi%2Fpreprocessor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271369934,"owners_count":24747802,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-20T02:00:09.606Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","compiler","php","preprocessor"],"created_at":"2024-11-06T02:16:39.002Z","updated_at":"2025-08-20T19:11:13.893Z","avatar_url":"https://github.com/php-ffi.png","language":"PHP","readme":"# Simple C-lang Preprocessor\n\nThis implementation of a preprocessor based in part on\n[ISO/IEC 9899:TC2](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf).\n\n## Requirements\n\n- PHP \u003e= 7.4\n\n## Installation\n\nLibrary is available as composer repository and can be installed using the \nfollowing command in a root of your project.\n\n```sh\n$ composer require ffi/preprocessor\n```\n\n## Usage\n\n```php\nuse FFI\\Preprocessor\\Preprocessor;\n\n$pre = new Preprocessor();\n\necho $pre-\u003eprocess('\n    #define VK_DEFINE_HANDLE(object) typedef struct object##_T* object;\n\n    #if !defined(VK_DEFINE_NON_DISPATCHABLE_HANDLE)\n        #if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) \u0026\u0026 !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)\n            #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object;\n        #else\n            #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;\n        #endif\n    #endif\n\n    VK_DEFINE_HANDLE(VkInstance)\n    VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSemaphore)\n');\n\n//\n// Expected Output:\n//\n//  typedef struct VkInstance_T* VkInstance;\n//  typedef uint64_t VkSemaphore;\n//\n```\n\n## Directives\n\n### Supported Directives\n\n- [x] `#include \"file.h\"` local-first include\n- [x] `#include \u003cfile.h\u003e` global-first include\n- [x] `#define name` defining directives\n    - [x] `#define name value` object-like macro\n    - [x] `#define name(arg) value` function-like macro\n    - [x] `#define name(arg) xxx##arg` concatenation\n    - [x] `#define name(arg) #arg` stringizing\n- [x] `#undef name` removing directives\n- [x] `#ifdef name` \"if directive defined\" condition\n- [x] `#ifndef name` \"if directive not defined\" condition\n- [x] `#if EXPRESSION` if condition\n- [x] `#elif EXPRESSION` else if condition\n- [x] `#else` else condition\n- [x] `#endif` completion of a condition\n- [x] `#error message` error message directive\n- [x] `#warning message` warning message directive\n- [ ] `#line 66 \"filename\"` line and file override\n- [ ] `#pragma XXX` compiler control\n    - [ ] `#pragma once`\n- [ ] `#assert XXX` compiler assertion\n    - [ ] `#unassert XXX` compiler assertion\n- [ ] `#ident XXX`\n    - [ ] `#sccs XXX`\n\n### Expression Grammar\n\n#### Comparison Operators\n\n- [x] `A \u003e B` greater than\n- [x] `A \u003c B` less than\n- [x] `A == B` equal\n- [x] `A != B` not equal\n- [x] `A \u003e= B` greater than or equal\n- [x] `A \u003c= B` less than or equal\n\n#### Logical Operators\n\n- [x] `! A` logical NOT\n- [x] `A \u0026\u0026 B` conjunction\n- [x] `A || B` disjunction\n- [x] `(...)` grouping\n\n#### Arithmetic Operators\n\n- [x] `A + B` math addition\n- [x] `A - B` math subtraction\n- [x] `A * B` math multiplication\n- [x] `A / B` math division\n- [x] `A % B` modulo\n- [ ] `A++` increment\n    - [x] `++A` prefix form\n- [ ] `A--` decrement\n    - [x] `--A` prefix form\n- [x] `+A` unary plus\n- [x] `-A` unary minus\n- [ ] `\u0026A` unary addr\n- [ ] `*A` unary pointer\n\n#### Bitwise Operators\n\n- [x] `~A` bitwise NOT\n- [x] `A \u0026 B` bitwise AND\n- [x] `A | B` bitwise OR\n- [x] `A ^ B` bitwise XOR\n- [x] `A \u003c\u003c B` bitwise left shift\n- [x] `A \u003e\u003e B` bitwise right shift\n\n#### Other Operators\n\n- [x] `defined(X)` defined macro\n- [ ] `A ? B : C` ternary\n- [ ] `sizeof VALUE` sizeof\n    - [ ] `sizeof(TYPE)` sizeof type\n\n### Literals\n\n- [x] `true`, `false` boolean\n- [x] `42` decimal integer literal\n    - [x] `42u`, `42U` unsigned int\n    - [x] `42l`, `42L` long int\n    - [x] `42ul`, `42UL` unsigned long int\n    - [x] `42ll`, `42LL` long long int\n    - [x] `42ull`, `42ULL` unsigned long long int\n- [x] `042` octal integer literal\n- [x] `0x42` hexadecimal integer literal\n- [x] `0b42` binary integer literal\n- [x] `\"string\"` string (char array)\n    - [x] `L\"string\"` string (wide char array)\n    - [x] `\"\\•\"` escape sequences in strings\n    - [ ] `\"\\•••\"` arbitrary octal value in strings\n    - [ ] `\"\\X••\"` arbitrary hexadecimal value in strings\n- [ ] `'x'` char literal\n    - [ ] `'\\•'` escape sequences\n    - [ ] `'\\•••'` arbitrary octal value\n    - [ ] `'\\X••'` arbitrary hexadecimal value\n    - [ ] `L'x'` wide character literal\n- [ ] `42.0` double\n    - [ ] `42f`, `42F` float\n    - [ ] `42l`, `42L` long double\n    - [ ] `42E` exponential form\n    - [ ] `0.42e23` exponential form\n- [ ] `NULL` null macro\n\n### Type Casting\n\n- [x] `(char)42`\n- [x] `(short)42`\n- [x] `(int)42`\n- [x] `(long)42`\n- [x] `(float)42`\n- [x] `(double)42`\n- [x] `(bool)42` (Out of ISO/IEC 9899:TC2 specification)\n- [x] `(string)42` (Out of ISO/IEC 9899:TC2 specification)\n- [ ] `(void)42`\n- [ ] `(long type)42` Casting to a long type (`long int`, `long double`, etc)\n- [ ] `(const type)42` Casting to a constant type (`const char`, etc)\n- [ ] `(unsigned type)42` Casting to unsigned type (`unsigned int`, `unsigned long`, etc)\n- [ ] `(signed type)42` Casting to signed type (`signed int`, `signed long`, etc)\n- [ ] Pointers (`void *`, etc)\n- [ ] References (`unsigned int`, `unsigned long`, etc)\n\n### Object Like Directive\n\n```php\nuse FFI\\Preprocessor\\Preprocessor;\nuse FFI\\Preprocessor\\Directive\\ObjectLikeDirective;\n\n$pre = new Preprocessor();\n\n// #define A\n$pre-\u003edefine('A');\n\n// #define B 42\n$pre-\u003edefine('B', '42');\n\n// #define С 42\n$pre-\u003edefine('С', new ObjectLikeDirective('42'));\n```\n\n## Function Like Directive\n\n```php\nuse FFI\\Preprocessor\\Preprocessor;\nuse FFI\\Preprocessor\\Directive\\FunctionLikeDirective;\n\n$pre = new Preprocessor();\n\n// #define C(object) object##_T* object;\n$pre-\u003edefine('C', function (string $arg) {\n    return \"${arg}_T* ${arg};\";\n});\n\n// #define D(object) object##_T* object;\n$pre-\u003edefine('D', new FunctionLikeDirective(['object'], 'object##_T* object'));\n```\n\n## Include Directories\n\n```php\nuse FFI\\Preprocessor\\Preprocessor;\n\n$pre = new Preprocessor();\n\n$pre-\u003einclude('/path/to/directory');\n$pre-\u003eexclude('some');\n```\n\n## Message Handling\n\n```php\nuse FFI\\Preprocessor\\Preprocessor;\n\n$logger = new Psr3LoggerImplementation();\n\n$pre = new Preprocessor($logger);\n\n$pre-\u003eprocess('\n    #error Error message\n    // Will be sent to the logger:\n    //  - LoggerInterface::error(\"Error message\")\n    \n    #warning Warning message\n    // Will be sent to the logger: \n    //  - LoggerInterface::warning(\"Warning message\")\n');\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-ffi%2Fpreprocessor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-ffi%2Fpreprocessor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-ffi%2Fpreprocessor/lists"}