Skip to content
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

Introduce base type for generated structs #92

Merged
merged 3 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion projects/jdwp/defs/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class IdType(Enum):
OBJECT_ID = "objectID"
THREAD_ID = "threadID"
THREAD_GROUP_ID = "threadGroupID"
STRING_ID = "stringId"
STRING_ID = "stringID"
CLASS_LOADER_ID = "classLoaderID"
CLASS_OBJECT_ID = "classObjectID"
ARRAY_ID = "arrayID"
Expand Down
4 changes: 2 additions & 2 deletions projects/jdwp/runtime/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ python_library(
name = "runtime",
srcs = [
":type-aliases",
"async_streams.py",
"jdwpstruct.py",
],
visibility = ["PUBLIC", ],


deps = [],
)
58 changes: 29 additions & 29 deletions projects/jdwp/runtime/async_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import abc
import typing

from projects.jdwp.defs.schema import IdType
from projects.jdwp.runtime.type_aliases import *


class JDWPInputStreamBase(abc.ABC):
Expand All @@ -22,59 +22,59 @@ async def read_string(self) -> str:

# Methods for IdType
@abc.abstractmethod
async def read_object_id(self) -> IdType.OBJECT_ID:
async def read_object_id(self) -> ObjectIDType:
pass

@abc.abstractmethod
async def read_thread_id(self) -> IdType.THREAD_ID:
async def read_thread_id(self) -> ThreadIDType:
pass

@abc.abstractmethod
async def read_thread_group_id(self) -> IdType.THREAD_GROUP_ID:
async def read_thread_group_id(self) -> ThreadGroupIDType:
pass

@abc.abstractmethod
async def read_string_id(self) -> IdType.STRING_ID:
async def read_string_id(self) -> StringIDType:
pass

@abc.abstractmethod
async def read_class_loader_id(self) -> IdType.CLASS_LOADER_ID:
async def read_class_loader_id(self) -> ClassLoaderIDType:
pass

@abc.abstractmethod
async def read_class_object_id(self) -> IdType.CLASS_OBJECT_ID:
async def read_class_object_id(self) -> ClassObjectIDType:
pass

@abc.abstractmethod
async def read_array_id(self) -> IdType.ARRAY_ID:
async def read_array_id(self) -> ArrayIDType:
pass

@abc.abstractmethod
async def read_reference_type_id(self) -> IdType.REFERENCE_TYPE_ID:
async def read_reference_type_id(self) -> ReferenceTypeIDType:
pass

@abc.abstractmethod
async def read_class_id(self) -> IdType.CLASS_ID:
async def read_class_id(self) -> ClassIDType:
pass

@abc.abstractmethod
async def read_interface_id(self) -> IdType.INTERFACE_ID:
async def read_interface_id(self) -> InterfaceIDType:
pass

@abc.abstractmethod
async def read_array_type_id(self) -> IdType.ARRAY_TYPE_ID:
async def read_array_type_id(self) -> ArrayTypeIDType:
pass

@abc.abstractmethod
async def read_method_id(self) -> IdType.METHOD_ID:
async def read_method_id(self) -> MethodIDType:
pass

@abc.abstractmethod
async def read_field_id(self) -> IdType.FIELD_ID:
async def read_field_id(self) -> FieldIDType:
pass

@abc.abstractmethod
async def read_frame_id(self) -> IdType.FRAME_ID:
async def read_frame_id(self) -> FrameIDType:
pass

# Methods for IntegralType
Expand Down Expand Up @@ -109,59 +109,59 @@ def write_string(self, value: str) -> None:

# Methods for IdType
@abc.abstractmethod
def write_object_id(self, value: IdType.OBJECT_ID) -> None:
def write_object_id(self, value: ObjectIDType) -> None:
pass

@abc.abstractmethod
def write_thread_id(self, value: IdType.THREAD_ID) -> None:
def write_thread_id(self, value: ThreadIDType) -> None:
pass

@abc.abstractmethod
def write_thread_group_id(self, value: IdType.THREAD_GROUP_ID) -> None:
def write_thread_group_id(self, value: ThreadGroupIDType) -> None:
pass

@abc.abstractmethod
def write_string_id(self, value: IdType.STRING_ID) -> None:
def write_string_id(self, value: StringIDType) -> None:
pass

@abc.abstractmethod
def write_class_loader_id(self, value: IdType.CLASS_LOADER_ID) -> None:
def write_class_loader_id(self, value: ClassLoaderIDType) -> None:
pass

@abc.abstractmethod
def write_class_object_id(self, value: IdType.CLASS_OBJECT_ID) -> None:
def write_class_object_id(self, value: ClassObjectIDType) -> None:
pass

@abc.abstractmethod
def write_array_id(self, value: IdType.ARRAY_ID) -> None:
def write_array_id(self, value: ArrayIDType) -> None:
pass

@abc.abstractmethod
def write_reference_type_id(self, value: IdType.REFERENCE_TYPE_ID) -> None:
def write_reference_type_id(self, value: ReferenceTypeIDType) -> None:
pass

@abc.abstractmethod
def write_class_id(self, value: IdType.CLASS_ID) -> None:
def write_class_id(self, value: ClassIDType) -> None:
pass

@abc.abstractmethod
def write_interface_id(self, value: IdType.INTERFACE_ID) -> None:
def write_interface_id(self, value: InterfaceIDType) -> None:
pass

@abc.abstractmethod
def write_array_type_id(self, value: IdType.ARRAY_TYPE_ID) -> None:
def write_array_type_id(self, value: ArrayTypeIDType) -> None:
pass

@abc.abstractmethod
def write_method_id(self, value: IdType.METHOD_ID) -> None:
def write_method_id(self, value: MethodIDType) -> None:
pass

@abc.abstractmethod
def write_field_id(self, value: IdType.FIELD_ID) -> None:
def write_field_id(self, value: FieldIDType) -> None:
pass

@abc.abstractmethod
def write_frame_id(self, value: IdType.FRAME_ID) -> None:
def write_frame_id(self, value: FrameIDType) -> None:
pass

# Methods for IntegralType
Expand Down
20 changes: 20 additions & 0 deletions projects/jdwp/runtime/jdwpstruct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.

from __future__ import annotations

import abc
from projects.jdwp.runtime.async_streams import (
JDWPInputStreamBase,
JDWPOutputStreamBase,
)


class JDWPStruct(abc.ABC):
@abc.abstractmethod
async def serialize(self, output: JDWPOutputStreamBase):
pass

@staticmethod
@abc.abstractmethod
async def parse(input: JDWPInputStreamBase) -> JDWPStruct:
pass
3 changes: 1 addition & 2 deletions projects/jdwp/tests/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ python_test(
deps = [
"//projects/jdwp/defs:defs",
"//projects/jdwp/codegen:codegen",


"//projects/jdwp/runtime:runtime",
],
srcs = glob(["**/*.py"]),
)
8 changes: 8 additions & 0 deletions projects/jdwp/tests/runtime/jdwpstruct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.

import unittest


class JDWPStructTest(unittest.TestCase):
def test_jdwpstruct_can_be_imported(self):
from projects.jdwp.runtime.jdwpstruct import JDWPStruct