-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit separates types representing ids of internal vm objects from opaque types that map to types that are provided by the language or the debugger runtime. While doing so I noticed that command sets cannot be imported due to runtime errors. I would have expected pyre would have caught those errors, but apparently not. While there I fixed issues and added a test case preventing this from happening again.
- Loading branch information
Showing
11 changed files
with
146 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,16 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
||
from projects.jdwp.defs.schema import PrimitiveType | ||
import typing | ||
from projects.jdwp.defs.schema import IdType | ||
from projects.jdwp.codegen.types import python_type_for | ||
|
||
|
||
def get_python_type(jdwp_type: PrimitiveType) -> str: | ||
"""Map JDWP type to Python type.""" | ||
mapping = { | ||
PrimitiveType.STRING: "str", | ||
PrimitiveType.BOOLEAN: "bool", | ||
} | ||
return mapping.get(jdwp_type, "int") | ||
|
||
|
||
def get_type_alias_definition(jdwp_type: PrimitiveType) -> str: | ||
"""Return the type alias definition for a given JDWP type.""" | ||
python_type = get_python_type(jdwp_type) | ||
new_type_name = f"{jdwp_type.name.capitalize()}Type" | ||
return f"{new_type_name} = typing.NewType('{new_type_name}', {python_type})" | ||
def get_type_alias_definition(jdwp_type: IdType) -> str: | ||
"""Return the type alias definition for a given IdType.""" | ||
python_type = python_type_for(jdwp_type) | ||
return f"{python_type} = typing.NewType('{python_type}', int)" | ||
|
||
|
||
def generate_new_types(): | ||
for jdwp_type in PrimitiveType: | ||
type_alias_definition = get_type_alias_definition(jdwp_type) | ||
for id_type in IdType: | ||
type_alias_definition = get_type_alias_definition(id_type) | ||
print(type_alias_definition) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
||
from projects.jdwp.defs.schema import OpaqueType, IdType, IntegralType, Type | ||
import typing | ||
|
||
|
||
__OPAQUE_TYPE_MAPPING = { | ||
OpaqueType.BOOLEAN: "bool", | ||
OpaqueType.LOCATION: "typing.Any", | ||
OpaqueType.STRING: "str", | ||
} | ||
|
||
|
||
def python_type_for(jdwp_type: Type) -> str: | ||
match jdwp_type: | ||
case OpaqueType(): | ||
return __OPAQUE_TYPE_MAPPING[jdwp_type] | ||
case IdType(): | ||
return jdwp_type.value[0].upper() + jdwp_type.value[1:] + "Type" | ||
case IntegralType(): | ||
return "int" | ||
case _: | ||
raise Exception("not implemented") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
||
import unittest | ||
from projects.jdwp.defs.schema import IdType | ||
from projects.jdwp.codegen.new_type_generator import get_type_alias_definition | ||
|
||
|
||
class TestTypeAliasDefinition(unittest.TestCase): | ||
def test_specific_type_alias_definitions(self): | ||
expected_object_id_type_definition = ( | ||
"ObjectIDType = typing.NewType('ObjectIDType', int)" | ||
) | ||
self.assertEqual( | ||
get_type_alias_definition(IdType.OBJECT_ID), | ||
expected_object_id_type_definition, | ||
) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.