[tools] Allow struct types in definitions
Allow struct type names in definitions, which result in struct buffer pointers in generated code.
This commit is contained in:
@@ -24,10 +24,12 @@ method: description? "method" name options? ("{" param* "}")?
|
|||||||
|
|
||||||
param: "param" name type options? description?
|
param: "param" name type options? description?
|
||||||
|
|
||||||
?type: PRIMITIVE | object_name
|
?type: PRIMITIVE | object_name | struct_name
|
||||||
|
|
||||||
object_name: "ref" name
|
object_name: "ref" name
|
||||||
|
|
||||||
|
struct_name: "struct" name
|
||||||
|
|
||||||
id: NUMBER
|
id: NUMBER
|
||||||
name: IDENTIFIER
|
name: IDENTIFIER
|
||||||
options: "[" ( OPTION | IDENTIFIER )+ "]"
|
options: "[" ( OPTION | IDENTIFIER )+ "]"
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -126,6 +126,11 @@ class DefTransformer(Transformer):
|
|||||||
from .types import ObjectRef
|
from .types import ObjectRef
|
||||||
return ObjectRef(n, self.filename)
|
return ObjectRef(n, self.filename)
|
||||||
|
|
||||||
|
@v_args(inline=True)
|
||||||
|
def struct_name(self, n):
|
||||||
|
from .types import Struct
|
||||||
|
return Struct(n)
|
||||||
|
|
||||||
def PRIMITIVE(self, s):
|
def PRIMITIVE(self, s):
|
||||||
from .types import get_primitive
|
from .types import get_primitive
|
||||||
return get_primitive(s)
|
return get_primitive(s)
|
||||||
|
|||||||
@@ -24,3 +24,4 @@ from .function import Function, Method, Param
|
|||||||
from .type import Type
|
from .type import Type
|
||||||
from .primitive import get_primitive
|
from .primitive import get_primitive
|
||||||
from .objref import ObjectRef
|
from .objref import ObjectRef
|
||||||
|
from .struct import Struct
|
||||||
|
|||||||
17
scripts/definitions/types/struct.py
Normal file
17
scripts/definitions/types/struct.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
from .type import Type
|
||||||
|
|
||||||
|
class Struct(Type):
|
||||||
|
def __repr__(self):
|
||||||
|
return f'Struct({self.name})'
|
||||||
|
|
||||||
|
def c_names(self, options):
|
||||||
|
one = f"struct j6_{self.name} *"
|
||||||
|
two = "size_t"
|
||||||
|
|
||||||
|
out = bool({"out", "inout"}.intersection(options))
|
||||||
|
if out:
|
||||||
|
two += " *"
|
||||||
|
return ((one, ""), (two, "_size"))
|
||||||
|
|
||||||
|
def cxx_names(self, options):
|
||||||
|
return self.c_names(options)
|
||||||
4
scripts/generate_parser.sh
Executable file
4
scripts/generate_parser.sh
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
python3 -m lark.tools.standalone assets/grammars/definitions.g > scripts/definitions/parser.py
|
||||||
|
python3 scripts/test_parse_definitions.py
|
||||||
10
scripts/test_parse_definitions.py
Normal file
10
scripts/test_parse_definitions.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
from definitions.context import Context
|
||||||
|
|
||||||
|
root = Path(sys.argv[0]).parent.parent
|
||||||
|
defs_path = (root / "definitions").resolve()
|
||||||
|
print(f"Definitions: {defs_path}")
|
||||||
|
ctx = Context(str(defs_path))
|
||||||
|
ctx.parse("syscalls.def")
|
||||||
|
|
||||||
Reference in New Issue
Block a user