ffi/preprocessor
Composer 安装命令:
composer require ffi/preprocessor
包简介
Simple C Preprocessor
README 文档
README
This implementation of a preprocessor based in part on ISO/IEC 9899:TC2.
Requirements
- PHP >= 7.4
Installation
Library is available as composer repository and can be installed using the following command in a root of your project.
$ composer require ffi/preprocessor
Usage
use FFI\Preprocessor\Preprocessor; $pre = new Preprocessor(); echo $pre->process(' #define VK_DEFINE_HANDLE(object) typedef struct object##_T* object; #if !defined(VK_DEFINE_NON_DISPATCHABLE_HANDLE) #if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__) #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object; #else #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object; #endif #endif VK_DEFINE_HANDLE(VkInstance) VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSemaphore) '); // // Expected Output: // // typedef struct VkInstance_T* VkInstance; // typedef uint64_t VkSemaphore; //
Directives
Supported Directives
-
#include "file.h"local-first include -
#include <file.h>global-first include -
#define namedefining directives-
#define name valueobject-like macro -
#define name(arg) valuefunction-like macro -
#define name(arg) xxx##argconcatenation -
#define name(arg) #argstringizing
-
-
#undef nameremoving directives -
#ifdef name"if directive defined" condition -
#ifndef name"if directive not defined" condition -
#if EXPRESSIONif condition -
#elif EXPRESSIONelse if condition -
#elseelse condition -
#endifcompletion of a condition -
#error messageerror message directive -
#warning messagewarning message directive -
#line 66 "filename"line and file override -
#pragma XXXcompiler control-
#pragma once
-
-
#assert XXXcompiler assertion-
#unassert XXXcompiler assertion
-
-
#ident XXX-
#sccs XXX
-
Expression Grammar
Comparison Operators
-
A > Bgreater than -
A < Bless than -
A == Bequal -
A != Bnot equal -
A >= Bgreater than or equal -
A <= Bless than or equal
Logical Operators
-
! Alogical NOT -
A && Bconjunction -
A || Bdisjunction -
(...)grouping
Arithmetic Operators
-
A + Bmath addition -
A - Bmath subtraction -
A * Bmath multiplication -
A / Bmath division -
A % Bmodulo -
A++increment-
++Aprefix form
-
-
A--decrement-
--Aprefix form
-
-
+Aunary plus -
-Aunary minus -
&Aunary addr -
*Aunary pointer
Bitwise Operators
-
~Abitwise NOT -
A & Bbitwise AND -
A | Bbitwise OR -
A ^ Bbitwise XOR -
A << Bbitwise left shift -
A >> Bbitwise right shift
Other Operators
-
defined(X)defined macro -
A ? B : Cternary -
sizeof VALUEsizeof-
sizeof(TYPE)sizeof type
-
Literals
-
true,falseboolean -
42decimal integer literal-
42u,42Uunsigned int -
42l,42Llong int -
42ul,42ULunsigned long int -
42ll,42LLlong long int -
42ull,42ULLunsigned long long int
-
-
042octal integer literal -
0x42hexadecimal integer literal -
0b42binary integer literal -
"string"string (char array)-
L"string"string (wide char array) -
"\•"escape sequences in strings -
"\•••"arbitrary octal value in strings -
"\X••"arbitrary hexadecimal value in strings
-
-
'x'char literal-
'\•'escape sequences -
'\•••'arbitrary octal value -
'\X••'arbitrary hexadecimal value -
L'x'wide character literal
-
-
42.0double-
42f,42Ffloat -
42l,42Llong double -
42Eexponential form -
0.42e23exponential form
-
-
NULLnull macro
Type Casting
-
(char)42 -
(short)42 -
(int)42 -
(long)42 -
(float)42 -
(double)42 -
(bool)42(Out of ISO/IEC 9899:TC2 specification) -
(string)42(Out of ISO/IEC 9899:TC2 specification) -
(void)42 -
(long type)42Casting to a long type (long int,long double, etc) -
(const type)42Casting to a constant type (const char, etc) -
(unsigned type)42Casting to unsigned type (unsigned int,unsigned long, etc) -
(signed type)42Casting to signed type (signed int,signed long, etc) - Pointers (
void *, etc) - References (
unsigned int,unsigned long, etc)
Object Like Directive
use FFI\Preprocessor\Preprocessor; use FFI\Preprocessor\Directive\ObjectLikeDirective; $pre = new Preprocessor(); // #define A $pre->define('A'); // #define B 42 $pre->define('B', '42'); // #define С 42 $pre->define('С', new ObjectLikeDirective('42'));
Function Like Directive
use FFI\Preprocessor\Preprocessor; use FFI\Preprocessor\Directive\FunctionLikeDirective; $pre = new Preprocessor(); // #define C(object) object##_T* object; $pre->define('C', function (string $arg) { return "${arg}_T* ${arg};"; }); // #define D(object) object##_T* object; $pre->define('D', new FunctionLikeDirective(['object'], 'object##_T* object'));
Include Directories
use FFI\Preprocessor\Preprocessor; $pre = new Preprocessor(); $pre->include('/path/to/directory'); $pre->exclude('some');
Message Handling
use FFI\Preprocessor\Preprocessor; $logger = new Psr3LoggerImplementation(); $pre = new Preprocessor($logger); $pre->process(' #error Error message // Will be sent to the logger: // - LoggerInterface::error("Error message") #warning Warning message // Will be sent to the logger: // - LoggerInterface::warning("Warning message") ');
ffi/preprocessor 适用场景与选型建议
ffi/preprocessor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 37.05k 次下载、GitHub Stars 达 26, 最近一次更新时间为 2021 年 06 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「parser」 「headers」 「preprocessor」 「compiler」 「c」 「ffi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ffi/preprocessor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ffi/preprocessor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ffi/preprocessor 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
Permissions-Policy (Feature-Policy) header builder and middleware for Laravel
PHP polyfill for the Apache Functions. The aim is to provides functions as the PHP way in order to get them available even if PHP is not running as an Apache module.
An MT940 bank statement parser for PHP
Helper bundle, configure the request headers from a given base URL.
Provides an scss preprocessor to Magento 2
统计信息
- 总下载量: 37.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 26
- 点击次数: 7
- 依赖项目数: 13
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-06-13