Skip to content

Commit

Permalink
Merge pull request #172 from AsherGlick/remove_doc_type_to_cpp_type
Browse files Browse the repository at this point in the history
Removing doc_type_to_cpp_type variable as it was duplicated
  • Loading branch information
AsherGlick authored Oct 9, 2023
2 parents 1aaae11 + bbd1c60 commit ab1c739
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions xml_converter/generators/code_generator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from jsonschema import validate # type:ignore
from jsonschema.exceptions import ValidationError # type:ignore
import frontmatter # type:ignore
from typing import Any, Dict, List, Tuple, Set, Optional, Final
from typing import Any, Dict, List, Tuple, Set, Optional, Final, TypedDict
import os
import markdown
from dataclasses import dataclass, field
Expand Down Expand Up @@ -104,17 +104,20 @@ class FieldRow:
description: str


# TODO: Eventually replace all references to `doc_type_to_cpp_type` with
# references to `documentation_type_data` because they contain the same data
doc_type_to_cpp_type: Dict[str, str] = {
"Fixed32": "int",
"Int32": "int",
"Boolean": "bool",
"Float32": "float",
"String": "std::string",
}
################################################################################
# DocumentationTypeData
#
# A type definition to indicate what information should be included in the
# documentation_type_data variable.
################################################################################
class DocumentationTypeData(TypedDict):
class_name: str
cpp_type: str


documentation_type_data = {
# A map between the documentation types, and useful class name info related to
# that type.
documentation_type_data: Dict[str, DocumentationTypeData] = {
"Fixed32": {
"class_name": "int",
"cpp_type": "int",
Expand Down Expand Up @@ -391,7 +394,7 @@ def generate_cpp_variable_data(
component_attribute_variable = AttributeVariable(
attribute_name=attribute_name + "." + component_name,
attribute_type="CompoundValue",
cpp_type=doc_type_to_cpp_type[component['type']],
cpp_type=documentation_type_data[component['type']]["cpp_type"],
class_name=component_class_name,
xml_fields=component_xml_fields,
default_xml_field=component_default_xml_field,
Expand Down Expand Up @@ -490,7 +493,7 @@ def write_attribute(self, output_directory: str) -> None:
elif metadata[filepath]['type'] == "CompoundValue":
for component in metadata[filepath]['components']:
xml_fields = []
if component['type'] not in doc_type_to_cpp_type:
if component['type'] not in documentation_type_data:
raise ValueError("Unexpected type for component. Look at markdown file {attribute_name}".format(
attribute_name=attribute_name
))
Expand All @@ -502,7 +505,7 @@ def write_attribute(self, output_directory: str) -> None:
attribute_variable = AttributeVariable(
attribute_name=component_attribute_name,
attribute_type=metadata[filepath]['type'],
cpp_type=doc_type_to_cpp_type[component['type']],
cpp_type=documentation_type_data[component['type']]["cpp_type"],
class_name=attribute_name,
xml_fields=xml_fields,
protobuf_field=component["protobuf_field"],
Expand Down

0 comments on commit ab1c739

Please sign in to comment.