Added support for static_cast and reinterpret_cast

This commit is contained in:
kevstone 2024-02-15 15:23:33 +00:00
parent c147a05199
commit 6cd14eb5ae
2 changed files with 42 additions and 20 deletions

View File

@ -15,13 +15,13 @@ grib_accessor_class_double.cc
grib_accessor_class_long.cc
grib_accessor_class_proj_string.cc
grib_accessor_class_blob.cc
#grib_accessor_class_bufr_data_array.cc
# [SLOW] grib_accessor_class_bufr_data_array.cc
grib_accessor_class_bufr_data_element.cc
grib_accessor_class_bufr_elements_table.cc
#grib_accessor_class_bufr_extract_area_subsets.cc
#grib_accessor_class_bufr_extract_datetime_subsets.cc
#grib_accessor_class_bufr_extract_subsets.cc
#grib_accessor_class_bufr_simple_thinning.cc
grib_accessor_class_bufr_extract_area_subsets.cc
grib_accessor_class_bufr_extract_datetime_subsets.cc
grib_accessor_class_bufr_extract_subsets.cc
grib_accessor_class_bufr_simple_thinning.cc
grib_accessor_class_change_alternative_row_scanning.cc
grib_accessor_class_change_scanning_direction.cc
grib_accessor_class_codetable_title.cc
@ -33,7 +33,7 @@ grib_accessor_class_data_apply_boustrophedonic_bitmap.cc
grib_accessor_class_data_secondary_bitmap.cc
grib_accessor_class_data_shsimple_packing.cc
grib_accessor_class_dictionary.cc
#grib_accessor_class_g1_half_byte_codeflag.cc
grib_accessor_class_g1_half_byte_codeflag.cc
grib_accessor_class_g2_mars_labeling.cc
grib_accessor_class_g2step_range.cc
grib_accessor_class_gaussian_grid_name.cc
@ -44,7 +44,7 @@ grib_accessor_class_headers_only.cc
grib_accessor_class_ifs_param.cc
grib_accessor_class_iterator.cc
grib_accessor_class_label.cc
#grib_accessor_class_md5.cc
grib_accessor_class_md5.cc
grib_accessor_class_message_copy.cc
grib_accessor_class_nearest.cc
grib_accessor_class_non_alpha.cc
@ -79,20 +79,19 @@ grib_accessor_class_bit.cc
grib_accessor_class_bitmap.cc
grib_accessor_class_bits_per_value.cc
grib_accessor_class_budgdate.cc
#grib_accessor_class_bufr_group.cc
#grib_accessor_class_bufr_string_values.cc
#grib_accessor_class_bufr_string_values.cc
grib_accessor_class_bufr_group.cc
grib_accessor_class_bufr_string_values.cc
grib_accessor_class_bufrdc_expanded_descriptors.cc
#grib_accessor_class_check_internal_version.cc
#grib_accessor_class_closest_date.cc
#grib_accessor_class_constant.cc
grib_accessor_class_check_internal_version.cc
grib_accessor_class_closest_date.cc
grib_accessor_class_constant.cc
grib_accessor_class_count_file.cc
grib_accessor_class_count_missing.cc
grib_accessor_class_count_total.cc
#grib_accessor_class_data_ccsds_packing.cc
grib_accessor_class_data_ccsds_packing.cc
grib_accessor_class_data_g1secondary_bitmap.cc
grib_accessor_class_data_g1shsimple_packing.cc
#grib_accessor_class_data_g22order_packing.cc
# [SLOW] grib_accessor_class_data_g22order_packing.cc
grib_accessor_class_data_g2secondary_bitmap.cc
grib_accessor_class_data_g2shsimple_packing.cc
#grib_accessor_class_data_png_packing.cc

View File

@ -294,7 +294,7 @@ class AstParser:
debug.line("parse_LABEL_STMT", f"label_stmt=[{debug.as_debug_string(label_stmt)}]")
#ast_utils.dump_node(node)
#assert False
return label_stmt
def parse_RETURN_STMT(self, node):
@ -823,10 +823,6 @@ class AstParser:
def parse_CSTYLE_CAST_EXPR(self, node):
debug.line("parse_CSTYLE_CAST_EXPR", f"Node dump:")
ast_utils.dump_node(node)
tokens = [token.spelling for token in node.get_tokens()]
assert tokens[0] == "("
@ -847,6 +843,31 @@ class AstParser:
debug.line("parse_CSTYLE_CAST_EXPR", f"Created ccast_expression = [{debug.as_debug_string(ccast_expression)}]")
return ccast_expression
def parse_CXX_CAST_EXPR(self, node):
children = list(node.get_children())
child_count = len(children)
assert child_count >= 1, f"Expected at least one child for reinterpret_cast, got [{child_count}]"
if node.kind == clang.cindex.CursorKind.CXX_REINTERPRET_CAST_EXPR:
cxx_cast_type = "reinterpret"
elif node.kind == clang.cindex.CursorKind.CXX_STATIC_CAST_EXPR:
cxx_cast_type = "static"
else:
assert False, f"Unrecognized C++ cast type: kind=[{node.kind}]"
# Extract the cast value by finding the first '<' and '>' [note this will throw if not found!]
tokens = [token.spelling for token in node.get_tokens()]
cast_start_index = tokens.index("<") + 1
cast_end_index = tokens.index(">")
cxx_cast_value = literal.Literal(f"{' '.join([t for t in tokens[cast_start_index:cast_end_index]])}")
cxx_expression = self.parse_ast_node(children[-1])
cxx_cast_expression = cast_expression.CastExpression(cxx_cast_type, cxx_cast_value, cxx_expression)
debug.line("parse_CXX_REINTERPRET_CAST_EXPR", f"Created cxx_cast_expression = [{debug.as_debug_string(cxx_cast_expression)}]")
return cxx_cast_expression
def parse_ARRAY_SUBSCRIPT_EXPR(self, node):
# We expect two children: the variable name and the index
children = list(node.get_children())
@ -881,6 +902,8 @@ class AstParser:
clang.cindex.CursorKind.CALL_EXPR: parse_CALL_EXPR,
clang.cindex.CursorKind.ARRAY_SUBSCRIPT_EXPR: parse_ARRAY_SUBSCRIPT_EXPR,
clang.cindex.CursorKind.CSTYLE_CAST_EXPR: parse_CSTYLE_CAST_EXPR,
clang.cindex.CursorKind.CXX_REINTERPRET_CAST_EXPR: parse_CXX_CAST_EXPR,
clang.cindex.CursorKind.CXX_STATIC_CAST_EXPR: parse_CXX_CAST_EXPR,
clang.cindex.CursorKind.COMPOUND_LITERAL_EXPR: parse_node_not_implemented,
clang.cindex.CursorKind.INIT_LIST_EXPR: parse_INIT_LIST_EXPR,
clang.cindex.CursorKind.INTEGER_LITERAL: parse_INTEGER_LITERAL,