-
Notifications
You must be signed in to change notification settings - Fork 12
support natspec preconditions #1070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
c5b618c
1d8a941
6db5081
df0454c
b857852
88a95ea
89fbff0
c102905
382d2a5
c5bc915
0916be6
0ef6edb
66afe8d
2276824
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,12 +19,16 @@ dependencies = [ | |
name = "Runtime Verification, Inc." | ||
email = "[email protected]" | ||
|
||
[tool.hatch.build.targets.wheel] | ||
packages = ["src/kontrol", "src/natspec"] | ||
|
||
[project.scripts] | ||
kontrol = "kontrol.__main__:main" | ||
kontrol-kdist = "pyk.kdist.__main__:main" | ||
|
||
[project.entry-points.kdist] | ||
kontrol = "kontrol.kdist.plugin" | ||
natspec = "natspec.kdist.plugin" | ||
|
||
[dependency-groups] | ||
dev = [ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you consider the following alternatives:
With both approaches, you can avoid the burden of kompiling and distributing the parser. With (1), you get support for all the remaining features ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't aware of |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
Solidity Natspec Grammar | ||
------------------------ | ||
|
||
|
||
TODO: | ||
---- | ||
1. add support for bitwise operators | ||
|
||
```k | ||
module NATSPEC-SYNTAX | ||
imports INT-SYNTAX | ||
imports BOOL-SYNTAX | ||
imports ID-SYNTAX | ||
|
||
// Literals | ||
syntax HexLiteral ::= r"0x[0-9a-fA-F]+" [token, symbol(SolidityHexLiteral)] | ||
// --------------------------------------------------------------------------- | ||
|
||
syntax Access ::= Id | ||
| Access "[" Exp "]" [symbol(SolidityIndexAccess)] | ||
| Access "." Id [symbol(SolidityFieldAccess)] | ||
// ------------------------------------------------------------------ | ||
|
||
syntax Exp ::= Int | Bool | HexLiteral | Access | ||
| "(" Exp ")" [bracket] | ||
// Unary operators (high precedence) | ||
> "!" Exp [symbol(SolidityNegation)] | ||
// Power (right associative) | ||
> right: | ||
Exp "**" Exp [symbol(SolidityPower)] | ||
// Multiplicative | ||
> left: | ||
Exp "*" Exp [symbol(SolidityMultiplication)] | ||
| Exp "/" Exp [symbol(SolidityDivision)] | ||
| Exp "%" Exp [symbol(SolidityModulo)] | ||
// Additive | ||
> left: | ||
Exp "+" Exp [symbol(SolidityAddition)] | ||
| Exp "-" Exp [symbol(SoliditySubtraction)] | ||
// Relational | ||
> non-assoc: | ||
Exp "<" Exp [symbol(SolidityLT)] | ||
| Exp ">" Exp [symbol(SolidityGT)] | ||
| Exp "<=" Exp [symbol(SolidityLE)] | ||
| Exp ">=" Exp [symbol(SolidityGE)] | ||
// Equality | ||
> non-assoc: | ||
Exp "==" Exp [symbol(SolidityEq)] | ||
| Exp "!=" Exp [symbol(SolidityNeq)] | ||
// Logical AND | ||
> left: | ||
Exp "&&" Exp [symbol(SolidityConjunction)] | ||
// Logical OR | ||
> left: | ||
Exp "||" Exp [symbol(SolidityDisjunction)] | ||
endmodule | ||
|
||
module NATSPEC | ||
endmodule | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from __future__ import annotations | ||
|
||
import shutil | ||
from typing import TYPE_CHECKING | ||
|
||
from pyk.kbuild.utils import k_version | ||
from pyk.kdist.api import Target | ||
from pyk.ktool.kompile import PykBackend, kompile | ||
|
||
if TYPE_CHECKING: | ||
from collections.abc import Callable, Mapping | ||
from typing import Any, Final | ||
from pathlib import Path | ||
|
||
from .utils import KSRC_DIR | ||
|
||
|
||
class SourceTarget(Target): | ||
|
||
def build(self, output_dir: Path, deps: dict[str, Path], args: dict[str, Any], verbose: bool) -> None: | ||
shutil.copy(KSRC_DIR / 'natspec-grammar.md', output_dir / 'natspec-grammar.md') | ||
|
||
def source(self) -> tuple[Path, ...]: | ||
return (KSRC_DIR,) | ||
|
||
|
||
class KompileTarget(Target): | ||
_kompile_args: Callable[[Path], Mapping[str, Any]] | ||
|
||
def __init__(self, kompile_args: Callable[[Path], Mapping[str, Any]]): | ||
self._kompile_args = kompile_args | ||
|
||
def build(self, output_dir: Path, deps: dict[str, Path], args: dict[str, Any], verbose: bool) -> None: | ||
kompile_args = self._kompile_args(deps['natspec.source']) | ||
kompile(output_dir=output_dir, verbose=verbose, **kompile_args) | ||
|
||
def context(self) -> dict[str, str]: | ||
return {'k-version': k_version().text} | ||
|
||
def deps(self) -> tuple[str]: | ||
return ('natspec.source',) | ||
|
||
|
||
__TARGETS__: Final = { | ||
'source': SourceTarget(), | ||
'llvm': KompileTarget( | ||
lambda src_dir: { | ||
'backend': PykBackend.LLVM, | ||
'main_file': src_dir / 'natspec-grammar.md', | ||
'main_module': 'NATSPEC', | ||
'syntax_module': 'NATSPEC-SYNTAX', | ||
'md_selector': 'k', | ||
'warnings_to_errors': True, | ||
'gen_glr_bison_parser': True, | ||
'opt_level': 3, | ||
'ccopts': ['-g'], | ||
}, | ||
), | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing import Final | ||
|
||
|
||
KSRC_DIR: Final = Path(__file__).parent.resolve(strict=True) |
Uh oh!
There was an error while loading. Please reload this page.