updated parse for function declaration
This commit is contained in:
@@ -155,6 +155,7 @@ class VariableDeclaration:
|
|||||||
@dataclass
|
@dataclass
|
||||||
class Function:
|
class Function:
|
||||||
declaration: "FunctionDeclaration"
|
declaration: "FunctionDeclaration"
|
||||||
|
block: Block
|
||||||
type: TypeUsage
|
type: TypeUsage
|
||||||
|
|
||||||
|
|
||||||
@@ -202,10 +203,13 @@ class FunctionDeclartation:
|
|||||||
type: TypeUsage
|
type: TypeUsage
|
||||||
|
|
||||||
|
|
||||||
|
TraitItem = Union[FunctionDeclaration, Function]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TraitTypeDeclaration:
|
class TraitTypeDeclaration:
|
||||||
struct: str
|
struct: str
|
||||||
functions: List[Function]
|
items: List[TraitItem]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -464,18 +468,39 @@ class TreeToBoring(Transformer):
|
|||||||
(identifier, type_usage) = identifier
|
(identifier, type_usage) = identifier
|
||||||
return VariableDeclaration(name=identifier, type=type_usage)
|
return VariableDeclaration(name=identifier, type=type_usage)
|
||||||
|
|
||||||
def function_without_return(self, function) -> Function:
|
def function_declaration_without_return(self, fdwr) -> FunctionDeclaration:
|
||||||
|
return FunctionDeclaration(
|
||||||
|
name=function[0],
|
||||||
|
arguments=function[1:],
|
||||||
|
return_type=DataTypeUsage(name=UNIT_TYPE),
|
||||||
|
type=FunctionTypeUsage(
|
||||||
|
arguments=[arg.type for arg in function[1:]],
|
||||||
|
return_type=DataTypeUsage(name=UNIT_TYPE),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
def function_declaration_with_return(self, fdwr) -> FunctionDeclaration:
|
||||||
return Function(
|
return Function(
|
||||||
name=function[0],
|
name=function[0],
|
||||||
arguments=function[1:-1],
|
arguments=function[1:-1],
|
||||||
return_type=DataTypeUsage(name=UNIT_TYPE),
|
return_type=function[-1],
|
||||||
block=function[-1],
|
|
||||||
type=FunctionTypeUsage(
|
type=FunctionTypeUsage(
|
||||||
arguments=[arg.type for arg in function[1:-1]],
|
arguments=[arg.type for arg in function[1:-1]], return_type=function[-1]
|
||||||
return_type=DataTypeUsage(name=UNIT_TYPE),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def function_declaration(self, fd) -> FunctionDeclaration:
|
||||||
|
(fd,) = fd
|
||||||
|
assert isinstance(fd, FunctionDeclaration)
|
||||||
|
return fd
|
||||||
|
|
||||||
|
def function(self, function) -> Function:
|
||||||
|
return Function(
|
||||||
|
declaration=function[0],
|
||||||
|
block=function[1],
|
||||||
|
type=UnknownTypeUsage(),
|
||||||
|
)
|
||||||
|
|
||||||
def function_with_return(self, function) -> Function:
|
def function_with_return(self, function) -> Function:
|
||||||
return Function(
|
return Function(
|
||||||
name=function[0],
|
name=function[0],
|
||||||
|
|||||||
Reference in New Issue
Block a user