Skip to content

Commit 86d97a7

Browse files
committedFeb 22, 2022
Initial commit
0 parents  commit 86d97a7

22 files changed

+515
-0
lines changed
 

‎.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

‎.gitattributes

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
* text=auto
2+
3+
/.github export-ignore
4+
/tests export-ignore
5+
6+
.editorconfig export-ignore
7+
.gitattributes export-ignore
8+
.gitignore export-ignore
9+
.styleci.yml export-ignore
10+
.travis.yml export-ignore
11+
12+
monorepo-builder.php export-ignore
13+
phpunit.xml export-ignore

‎.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.idea/
2+
vendor/
3+
4+
# Local testing
5+
include/
6+
test.php
7+
8+
composer.lock
9+
.phpunit.result.cache

‎composer.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "ffi/preprocessor-contracts",
3+
"type": "library",
4+
"description": "C preprocessor interfaces / compatibility library",
5+
"license": "MIT",
6+
"keywords": ["ffi", "parser", "compiler", "c", "headers", "preprocessor", "contracts"],
7+
"support": {
8+
"source": "https://github.com/php-ffi/preprocessor-contracts",
9+
"issues": "https://github.com/php-ffi/preprocessor-contracts/issues",
10+
"docs": "https://github.com/php-ffi/preprocessor-contracts/blob/master/README.md"
11+
},
12+
"authors": [
13+
{
14+
"name": "Nesmeyanov Kirill",
15+
"email": "nesk@xakep.ru",
16+
"homepage": "https://serafimarts.ru",
17+
"role": "maintainer"
18+
}
19+
],
20+
"require": {
21+
"php": ">=7.4",
22+
"phplrt/source-contracts": "^3.1"
23+
},
24+
"autoload": {
25+
"psr-4": {
26+
"FFI\\Contracts\\Preprocessor\\": "src"
27+
}
28+
},
29+
"require-dev": {
30+
"vimeo/psalm": "^4.21"
31+
},
32+
"config": {
33+
"sort-packages": true,
34+
"allow-plugins": {
35+
"composer/package-versions-deprecated": true
36+
}
37+
},
38+
"scripts": {
39+
"psalm": "psalm --no-cache"
40+
},
41+
"extra": {
42+
"branch-alias": {
43+
"dev-master": "1.0.x-dev"
44+
}
45+
},
46+
"minimum-stability": "dev",
47+
"prefer-stable": true
48+
}

‎psalm.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="1"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns="https://getpsalm.org/schema/config"
6+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
7+
>
8+
<projectFiles>
9+
<directory name="src" />
10+
<ignoreFiles>
11+
<directory name="vendor" />
12+
</ignoreFiles>
13+
</projectFiles>
14+
</psalm>

‎src/Directive/DirectiveInterface.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/**
4+
* This file is part of FFI package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace FFI\Contracts\Preprocessor\Directive;
13+
14+
/**
15+
* @mixin callable
16+
*/
17+
interface DirectiveInterface
18+
{
19+
/**
20+
* @var string
21+
*/
22+
public const DEFAULT_VALUE = '';
23+
24+
/**
25+
* @return string
26+
*/
27+
public function __invoke(): string;
28+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/**
4+
* This file is part of FFI package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace FFI\Contracts\Preprocessor\Directive;
13+
14+
use FFI\Contracts\Preprocessor\Exception\DirectiveExecutionExceptionInterface;
15+
16+
interface FunctionLikeDirectiveInterface extends DirectiveInterface
17+
{
18+
/**
19+
* @param string ...$args
20+
* @return string
21+
* @throws DirectiveExecutionExceptionInterface
22+
*/
23+
public function __invoke(string ...$args): string;
24+
25+
/**
26+
* @return positive-int|0
27+
*/
28+
public function getMaxArgumentsCount(): int;
29+
30+
/**
31+
* @return positive-int|0
32+
*/
33+
public function getMinArgumentsCount(): int;
34+
}

‎src/Directive/RegistrarInterface.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/**
4+
* This file is part of FFI package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace FFI\Contracts\Preprocessor\Directive;
13+
14+
use FFI\Contracts\Preprocessor\Exception\DirectiveDefinitionExceptionInterface;
15+
16+
interface RegistrarInterface
17+
{
18+
/**
19+
* @param non-empty-string $directive
20+
* @param mixed $value
21+
* @throws DirectiveDefinitionExceptionInterface
22+
*/
23+
public function define(string $directive, $value = DirectiveInterface::DEFAULT_VALUE): void;
24+
25+
/**
26+
* @param non-empty-string $directive
27+
* @return bool
28+
*/
29+
public function undef(string $directive): bool;
30+
}

‎src/Directive/RepositoryInterface.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/**
4+
* This file is part of FFI package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace FFI\Contracts\Preprocessor\Directive;
13+
14+
/**
15+
* @template-extends \Traversable<array-key, DirectiveInterface>
16+
*/
17+
interface RepositoryInterface extends \Countable, \Traversable
18+
{
19+
/**
20+
* @param non-empty-string $directive
21+
* @return bool
22+
*/
23+
public function defined(string $directive): bool;
24+
25+
/**
26+
* @param non-empty-string $directive
27+
* @return DirectiveInterface|null
28+
*/
29+
public function find(string $directive): ?DirectiveInterface;
30+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/**
4+
* This file is part of FFI package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace FFI\Contracts\Preprocessor\Exception;
13+
14+
interface DirectiveDefinitionExceptionInterface extends DirectiveExceptionInterface
15+
{
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/**
4+
* This file is part of FFI package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace FFI\Contracts\Preprocessor\Exception;
13+
14+
interface DirectiveExceptionInterface extends PreprocessorExceptionInterface
15+
{
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/**
4+
* This file is part of FFI package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace FFI\Contracts\Preprocessor\Exception;
13+
14+
interface DirectiveExecutionExceptionInterface extends DirectiveExceptionInterface
15+
{
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/**
4+
* This file is part of FFI package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace FFI\Contracts\Preprocessor\Exception;
13+
14+
interface PreprocessorExceptionInterface extends \Throwable
15+
{
16+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/**
4+
* This file is part of FFI package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace FFI\Contracts\Preprocessor\Io\Directory;
13+
14+
interface RegistrarInterface
15+
{
16+
/**
17+
* @psalm-taint-sink file $directory
18+
* @param non-empty-string $directory
19+
*/
20+
public function include(string $directory): void;
21+
22+
/**
23+
* @psalm-taint-sink file $directory
24+
* @param non-empty-string $directory
25+
*/
26+
public function exclude(string $directory): void;
27+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/**
4+
* This file is part of FFI package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace FFI\Contracts\Preprocessor\Io\Directory;
13+
14+
/**
15+
* @template-extends \Traversable<array-key, non-empty-string>
16+
*/
17+
interface RepositoryInterface extends \Countable, \Traversable
18+
{
19+
}

‎src/Io/Source/RegistrarInterface.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/**
4+
* This file is part of FFI package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace FFI\Contracts\Preprocessor\Io\Source;
13+
14+
use FFI\Contracts\Preprocessor\PreprocessorInterface;
15+
16+
/**
17+
* @psalm-import-type SourceEntry from PreprocessorInterface
18+
*/
19+
interface RegistrarInterface
20+
{
21+
/**
22+
* @psalm-taint-sink file $file
23+
* @param non-empty-string $file
24+
* @param SourceEntry $source
25+
* @param bool $overwrite
26+
* @return bool
27+
*/
28+
public function add(string $file, $source, bool $overwrite = false): bool;
29+
30+
/**
31+
* @psalm-taint-sink file $file
32+
* @param non-empty-string $file
33+
* @return bool
34+
*/
35+
public function remove(string $file): bool;
36+
}

‎src/Io/Source/RepositoryInterface.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/**
4+
* This file is part of FFI package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace FFI\Contracts\Preprocessor\Io\Source;
13+
14+
use Phplrt\Contracts\Source\ReadableInterface;
15+
16+
/**
17+
* @template-extends \Traversable<non-empty-string, ReadableInterface>
18+
*/
19+
interface RepositoryInterface extends \Countable, \Traversable
20+
{
21+
}

‎src/PreprocessorInterface.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/**
4+
* This file is part of FFI package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace FFI\Contracts\Preprocessor;
13+
14+
use FFI\Contracts\Preprocessor\Directive\RegistrarInterface as DirectiveRegistrarInterface;
15+
use FFI\Contracts\Preprocessor\Exception\PreprocessorExceptionInterface;
16+
use FFI\Contracts\Preprocessor\Io\Directory\RegistrarInterface as DirectoryRegistrarInterface;
17+
use FFI\Contracts\Preprocessor\Io\Source\RegistrarInterface as SourceRegistrarInterface;
18+
use FFI\Contracts\Preprocessor\ProvidesDirectoriesInterface as DirectoriesProviderInterface;
19+
use FFI\Contracts\Preprocessor\ProvidesDirectivesInterface as DirectivesProviderInterface;
20+
use FFI\Contracts\Preprocessor\ProvidesSourcesInterface as SourcesProviderInterface;
21+
use Phplrt\Contracts\Source\ReadableInterface;
22+
23+
/**
24+
* @psalm-type SourceEntry = string|resource|ReadableInterface|\SplFileInfo
25+
*/
26+
interface PreprocessorInterface extends
27+
SourceRegistrarInterface,
28+
SourcesProviderInterface,
29+
DirectiveRegistrarInterface,
30+
DirectivesProviderInterface,
31+
DirectoryRegistrarInterface,
32+
DirectoriesProviderInterface
33+
{
34+
/**
35+
* @param SourceEntry $source
36+
* @return ResultInterface
37+
* @throws PreprocessorExceptionInterface
38+
*/
39+
public function process($source): ResultInterface;
40+
}

‎src/ProvidesDirectivesInterface.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/**
4+
* This file is part of FFI package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace FFI\Contracts\Preprocessor;
13+
14+
use FFI\Contracts\Preprocessor\Directive\RepositoryInterface;
15+
16+
interface ProvidesDirectivesInterface
17+
{
18+
/**
19+
* @return RepositoryInterface
20+
*/
21+
public function getDirectives(): RepositoryInterface;
22+
}

‎src/ProvidesDirectoriesInterface.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/**
4+
* This file is part of FFI package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace FFI\Contracts\Preprocessor;
13+
14+
use FFI\Contracts\Preprocessor\Io\Directory\RepositoryInterface;
15+
16+
interface ProvidesDirectoriesInterface
17+
{
18+
/**
19+
* @return RepositoryInterface
20+
*/
21+
public function getDirectories(): RepositoryInterface;
22+
}

‎src/ProvidesSourcesInterface.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/**
4+
* This file is part of FFI package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace FFI\Contracts\Preprocessor;
13+
14+
use FFI\Contracts\Preprocessor\Io\Source\RepositoryInterface;
15+
16+
interface ProvidesSourcesInterface
17+
{
18+
/**
19+
* @return RepositoryInterface
20+
*/
21+
public function getSources(): RepositoryInterface;
22+
}

‎src/ResultInterface.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* This file is part of FFI package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace FFI\Contracts\Preprocessor;
13+
14+
use FFI\Contracts\Preprocessor\ProvidesDirectoriesInterface as DirectoriesProviderInterface;
15+
use FFI\Contracts\Preprocessor\ProvidesDirectivesInterface as DirectivesProviderInterface;
16+
use FFI\Contracts\Preprocessor\ProvidesSourcesInterface as SourcesProviderInterface;
17+
18+
interface ResultInterface extends
19+
\Stringable,
20+
SourcesProviderInterface,
21+
DirectivesProviderInterface,
22+
DirectoriesProviderInterface
23+
{
24+
}

0 commit comments

Comments
 (0)
Please sign in to comment.