mirror of https://github.com/ecmwf/eccodes.git
Added conversion_pack
This commit is contained in:
parent
62587e1f81
commit
b46ba3e014
|
@ -382,6 +382,12 @@ class AstParser:
|
|||
|
||||
def parse_CXX_UNARY_EXPR(self, node):
|
||||
keyword = node.spelling
|
||||
if not keyword:
|
||||
# Some unary expressions (e.g. sizeof) give an empty keyword, but we can extract it
|
||||
# from the first token
|
||||
tokens = [token.spelling for token in node.get_tokens()]
|
||||
keyword = tokens[0]
|
||||
|
||||
children = list(node.get_children())
|
||||
assert len(children) == 1, f"Expected exactly one child for unary expression"
|
||||
expression = children[0]
|
||||
|
|
|
@ -5,7 +5,8 @@ import code_object.declaration_specifier as declaration_specifier
|
|||
import code_object_converter.code_interface_converter as code_interface_converter
|
||||
import code_object_converter.conversion_funcs as conversion_funcs
|
||||
import utils.standard_transforms as standard_transforms
|
||||
from code_object_converter.supporting.conversion_data_helper import *
|
||||
from code_object_converter.conversion_pack.conversion_data_helper import *
|
||||
from code_object_converter.conversion_pack.conversion_pack import ConversionPack
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
|
||||
class ArgConverter(code_interface_converter.CodeInterfaceConverter):
|
||||
|
@ -13,8 +14,9 @@ class ArgConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, arg.Arg), f"Expected arg.Arg, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
self._conversion_data = conversion_data
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
self._conversion_pack = conversion_pack
|
||||
assert isinstance(self._conversion_pack, ConversionPack), f"self._conversion_pack=[{type(self._conversion_pack).__name__}]"
|
||||
|
||||
debug.line("create_cpp_code_object", f"ArgConverter [IN] self._ccode_object=[{debug.as_debug_string(self._ccode_object)}] is_func_arg=[{self._ccode_object.is_func_arg}]")
|
||||
|
||||
|
@ -32,7 +34,7 @@ class ArgConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
debug.line("convert_funcsig_arg", f"--[1]-- carg=[{debug.as_debug_string(carg)}]")
|
||||
|
||||
# 1. Check for existing arg mappings
|
||||
cpp_arg = self._conversion_data.funcsig_cpparg_for_carg(carg)
|
||||
cpp_arg = self._conversion_pack.conversion_data.funcsig_cpparg_for_carg(carg)
|
||||
if cpp_arg:
|
||||
return cpp_arg
|
||||
|
||||
|
@ -46,7 +48,7 @@ class ArgConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
|
||||
if cpp_decl_spec == NONE_VALUE:
|
||||
cpp_arg = NONE_VALUE
|
||||
self._conversion_data.add_funcbody_arg_mapping(carg, cpp_arg)
|
||||
self._conversion_pack.conversion_data.add_funcbody_arg_mapping(carg, cpp_arg)
|
||||
debug.line("convert_funcsig_arg", f"Arg conversion funcbody arg mapping: [{debug.as_debug_string(carg)}] -> [{debug.as_debug_string(cpp_arg)}]")
|
||||
else:
|
||||
if match_type != DeclSpecMatchType.FULL:
|
||||
|
@ -61,7 +63,7 @@ class ArgConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
debug.line("convert_funcsig_arg", f"--[4]-- cpp_decl_spec=[{debug.as_debug_string(cpp_decl_spec)}] cpp_arg=[{debug.as_debug_string(cpp_arg)}]")
|
||||
|
||||
if not match_type == DeclSpecMatchType.FULL:
|
||||
self._conversion_data.add_funcsig_type_mapping(carg.decl_spec, cpp_decl_spec)
|
||||
self._conversion_pack.conversion_data.add_funcsig_type_mapping(carg.decl_spec, cpp_decl_spec)
|
||||
debug.line("convert_funcsig_arg", f"Arg conversion funcsig type mapping: carg.decl_spec=[{debug.as_debug_string(carg.decl_spec)}] cpp_decl_spec=[{debug.as_debug_string(cpp_decl_spec)}]")
|
||||
|
||||
return cpp_arg
|
||||
|
@ -69,10 +71,10 @@ class ArgConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
def convert_funcsig_decl_spec(self, test_decl_spec):
|
||||
assert test_decl_spec
|
||||
|
||||
cpp_decl_spec, match_type = self._conversion_data.closest_funcsig_cppdecl_spec_for_cdecl_spec(test_decl_spec)
|
||||
cpp_decl_spec, match_type = self._conversion_pack.conversion_data.closest_funcsig_cppdecl_spec_for_cdecl_spec(test_decl_spec)
|
||||
|
||||
if match_type == DeclSpecMatchType.NONE:
|
||||
cpp_decl_spec = conversion_funcs.convert_ccode_object(test_decl_spec, self._conversion_data)
|
||||
cpp_decl_spec = conversion_funcs.convert_ccode_object(test_decl_spec, self._conversion_pack)
|
||||
|
||||
return cpp_decl_spec, match_type
|
||||
|
||||
|
@ -84,7 +86,7 @@ class ArgConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
|
||||
cpp_arg = arg.Arg(new_decl_spec, cpp_name, cpp_is_func_arg)
|
||||
|
||||
self._conversion_data.add_funcsig_arg_mapping(carg, cpp_arg)
|
||||
self._conversion_pack.conversion_data.add_funcsig_arg_mapping(carg, cpp_arg)
|
||||
debug.line("create_funcsig_cpparg", f"Arg conversion arg mapping: [{debug.as_debug_string(carg)}] -> [{debug.as_debug_string(cpp_arg)}]")
|
||||
|
||||
return cpp_arg
|
||||
|
@ -94,7 +96,7 @@ class ArgConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
debug.line("convert_funcbody_arg", f"==[1]== carg=[{debug.as_debug_string(carg)}]")
|
||||
|
||||
# 1. Check for existing arg mappings
|
||||
cpp_arg = self._conversion_data.funcbody_cpparg_for_carg(carg)
|
||||
cpp_arg = self._conversion_pack.conversion_data.funcbody_cpparg_for_carg(carg)
|
||||
if cpp_arg:
|
||||
return cpp_arg
|
||||
|
||||
|
@ -118,7 +120,7 @@ class ArgConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
debug.line("convert_funcbody_arg", f"==[4]== cpp_decl_spec=[{debug.as_debug_string(cpp_decl_spec)}] cpp_arg=[{debug.as_debug_string(cpp_arg)}]")
|
||||
|
||||
if not match_type == DeclSpecMatchType.FULL:
|
||||
self._conversion_data.add_funcbody_type_mapping(carg.decl_spec, cpp_decl_spec)
|
||||
self._conversion_pack.conversion_data.add_funcbody_type_mapping(carg.decl_spec, cpp_decl_spec)
|
||||
debug.line("convert_funcbody_arg", f"Arg conversion type mapping: carg.decl_spec=[{debug.as_debug_string(carg.decl_spec)}] cpp_decl_spec=[{debug.as_debug_string(cpp_decl_spec)}]")
|
||||
|
||||
return cpp_arg
|
||||
|
@ -128,13 +130,13 @@ class ArgConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
|
||||
debug.line("convert_funcbody_decl_spec", f"[1] test_decl_spec=[{debug.as_debug_string(test_decl_spec)}]")
|
||||
|
||||
cpp_decl_spec, match_type = self._conversion_data.closest_funcbody_cppdecl_spec_for_cdecl_spec(test_decl_spec)
|
||||
cpp_decl_spec, match_type = self._conversion_pack.conversion_data.closest_funcbody_cppdecl_spec_for_cdecl_spec(test_decl_spec)
|
||||
|
||||
debug.line("convert_funcbody_decl_spec", f"[2.1] test_decl_spec=[{debug.as_debug_string(test_decl_spec)}]")
|
||||
debug.line("convert_funcbody_decl_spec", f"[2.2] cpp_decl_spec=[{debug.as_debug_string(cpp_decl_spec)}] match_type=[{match_type}]")
|
||||
|
||||
if match_type == DeclSpecMatchType.NONE:
|
||||
cpp_decl_spec = conversion_funcs.convert_ccode_object(test_decl_spec, self._conversion_data)
|
||||
cpp_decl_spec = conversion_funcs.convert_ccode_object(test_decl_spec, self._conversion_pack)
|
||||
|
||||
return cpp_decl_spec, match_type
|
||||
|
||||
|
@ -146,7 +148,7 @@ class ArgConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
|
||||
cpp_arg = arg.Arg(new_decl_spec, cpp_name, cpp_is_func_arg)
|
||||
|
||||
self._conversion_data.add_funcbody_arg_mapping(carg, cpp_arg)
|
||||
self._conversion_pack.conversion_data.add_funcbody_arg_mapping(carg, cpp_arg)
|
||||
debug.line("create_funcbody_cpparg", f"Arg conversion arg mapping: [{debug.as_debug_string(carg)}] -> [{debug.as_debug_string(cpp_arg)}]")
|
||||
|
||||
return cpp_arg
|
||||
|
|
|
@ -129,7 +129,7 @@ class ArgConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
# Returns the equivalent C++ arg (name and type), which could be None
|
||||
# Note there are some differences in what is produced if the arg is a function arg...
|
||||
#
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
#def to_cpp_arg(self, transforms):
|
||||
|
||||
# For now, just change the name
|
||||
|
|
|
@ -9,8 +9,8 @@ class ArrayAccessConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, array_access.ArrayAccess), f"Expected ArrayAccess, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
cpp_name = conversion_funcs.convert_ccode_object(self._ccode_object.name, conversion_data)
|
||||
cpp_index = conversion_funcs.convert_ccode_object(self._ccode_object.index, conversion_data)
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cpp_name = conversion_funcs.convert_ccode_object(self._ccode_object.name, conversion_pack)
|
||||
cpp_index = conversion_funcs.convert_ccode_object(self._ccode_object.index, conversion_pack)
|
||||
|
||||
return array_access.ArrayAccess(cpp_name, cpp_index)
|
||||
|
|
|
@ -12,29 +12,13 @@ class BinaryOperationConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, binary_operation.BinaryOperation), f"Expected BinaryOperation, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
self._conversion_data = conversion_data
|
||||
cpp_left_operand = conversion_funcs.convert_ccode_object(self._ccode_object.left_operand, conversion_data)
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
self._conversion_data = conversion_pack.conversion_data
|
||||
cpp_left_operand = conversion_funcs.convert_ccode_object(self._ccode_object.left_operand, conversion_pack)
|
||||
cpp_binary_op = self._ccode_object.binary_op
|
||||
cpp_right_operand = conversion_funcs.convert_ccode_object(self._ccode_object.right_operand, conversion_data)
|
||||
cpp_right_operand = conversion_funcs.convert_ccode_object(self._ccode_object.right_operand, conversion_pack)
|
||||
|
||||
|
||||
# TODO ********************
|
||||
|
||||
'''if isinstance(cpp_right_operand, literal.Literal):
|
||||
cpptype = self.get_type(cpp_left_operand)
|
||||
if cpptype:
|
||||
assert False
|
||||
'''
|
||||
cppbinary_operation = binary_operation.BinaryOperation(cpp_left_operand, cpp_binary_op, cpp_right_operand)
|
||||
|
||||
return binary_operation.BinaryOperation(cpp_left_operand, cpp_binary_op, cpp_right_operand)
|
||||
|
||||
def get_type(self, operand):
|
||||
debug.line("get_type", f"operand=[{operand}] as_string=[{debug.as_debug_string(operand)}]")
|
||||
if isinstance(operand, arg.Arg):
|
||||
return operand.decl_spec.type
|
||||
if isinstance(operand, struct_member_access.StructMemberAccess):
|
||||
cppmember = self._conversion_data.cppdata_member_for_cdata_member_name(operand.name)
|
||||
return conversion_pack.conversion_validation.validate_binary_operation(self._ccode_object, cppbinary_operation)
|
||||
|
||||
return cppmember.decl_spec.type
|
||||
return None
|
||||
|
|
|
@ -17,12 +17,12 @@ class CodeInterfaceConverter:
|
|||
# prone to this!)
|
||||
#
|
||||
# The real work is done in create_cpp_code_object() !!!
|
||||
def to_cpp_code_object(self, conversion_data):
|
||||
cpp_code_object = self.create_cpp_code_object(conversion_data)
|
||||
def to_cpp_code_object(self, conversion_pack):
|
||||
cpp_code_object = self.create_cpp_code_object(conversion_pack)
|
||||
return copy.deepcopy(cpp_code_object)
|
||||
|
||||
# Actual implementation of to_cpp_code_object()
|
||||
# It must be overridden - this version just returns the passed in ccode_object!
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
debug.line("create_cpp_code_object", f"Base version - just returning the C code object")
|
||||
return self._ccode_object
|
||||
|
|
|
@ -13,11 +13,11 @@ class CodeObjectsConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
def code_objects_class(self):
|
||||
return code_objects.CodeObjects
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cpp_code_objects = self.code_objects_class()
|
||||
|
||||
for entry in self._ccode_object.code_objects:
|
||||
converted_object = conversion_funcs.convert_ccode_object(entry, conversion_data)
|
||||
converted_object = conversion_funcs.convert_ccode_object(entry, conversion_pack)
|
||||
cpp_code_objects.add_code_object(converted_object)
|
||||
|
||||
return cpp_code_objects
|
||||
|
|
|
@ -9,9 +9,9 @@ class ConditionalOperationConverter(code_interface_converter.CodeInterfaceConver
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, conditional_operation.ConditionalOperation), f"Expected ConditionalOperation, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
cpp_bool_expression = conversion_funcs.convert_ccode_object(self._ccode_object.bool_expression, conversion_data)
|
||||
cpp_true_expression = conversion_funcs.convert_ccode_object(self._ccode_object.true_expression, conversion_data)
|
||||
cpp_false_expression = conversion_funcs.convert_ccode_object(self._ccode_object.false_expression, conversion_data)
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cpp_bool_expression = conversion_funcs.convert_ccode_object(self._ccode_object.bool_expression, conversion_pack)
|
||||
cpp_true_expression = conversion_funcs.convert_ccode_object(self._ccode_object.true_expression, conversion_pack)
|
||||
cpp_false_expression = conversion_funcs.convert_ccode_object(self._ccode_object.false_expression, conversion_pack)
|
||||
|
||||
return conditional_operation.ConditionalOperation(cpp_bool_expression, cpp_true_expression, cpp_false_expression)
|
||||
|
|
|
@ -9,8 +9,8 @@ class ConstructorFunctionConverter(member_function_converter.MemberFunctionConve
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, constructor_function.ConstructorFunction), f"Expected ConstructorFunction, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
cpp_funcsig = conversion_funcs.convert_ccode_object(self._ccode_object.funcsig, conversion_data)
|
||||
cpp_body = conversion_funcs.convert_ccode_object(self._ccode_object.body, conversion_data)
|
||||
return constructor_function.ConstructorFunction(cpp_funcsig, cpp_body, conversion_data.info.class_name, conversion_data.info.super_class_name)
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cpp_funcsig = conversion_funcs.convert_ccode_object(self._ccode_object.funcsig, conversion_pack)
|
||||
cpp_body = conversion_funcs.convert_ccode_object(self._ccode_object.body, conversion_pack)
|
||||
return constructor_function.ConstructorFunction(cpp_funcsig, cpp_body, conversion_pack.conversion_data.info.class_name, conversion_pack.conversion_data.info.super_class_name)
|
||||
|
|
@ -106,7 +106,7 @@ CodeInterfaceConverterClasses = {
|
|||
}
|
||||
|
||||
# Convert a code_object into a C++ code_object
|
||||
def convert_ccode_object(ccode_object, conversion_data):
|
||||
def convert_ccode_object(ccode_object, conversion_pack):
|
||||
debug.line("convert_ccode_object", f"[IN] [{type(ccode_object).__name__}] {debug.as_debug_string(ccode_object)}")
|
||||
|
||||
if ccode_object is None:
|
||||
|
@ -116,7 +116,7 @@ def convert_ccode_object(ccode_object, conversion_data):
|
|||
else:
|
||||
converter_class = CodeInterfaceConverterClasses.get(type(ccode_object), code_interface_converter.CodeInterfaceConverter)
|
||||
converter = converter_class(ccode_object)
|
||||
cpp_obj = converter.to_cpp_code_object(conversion_data)
|
||||
cpp_obj = converter.to_cpp_code_object(conversion_pack)
|
||||
|
||||
debug.line("convert_ccode_object", f"[OUT][{type(cpp_obj).__name__}] {debug.as_debug_string(cpp_obj)}")
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
|
||||
import utils.debug as debug
|
||||
import cpp_code.code_info as code_info
|
||||
import code_object_converter.supporting.code_mappings as code_mappings
|
||||
import code_object_converter.supporting.funcsig_mapping as funcsig_mapping
|
||||
import code_object_converter.supporting.funcsig_pointer_mapping as funcsig_pointer_mapping
|
||||
import code_object_converter.conversion_pack.code_mappings as code_mappings
|
||||
import code_object_converter.conversion_pack.funcsig_mapping as funcsig_mapping
|
||||
import code_object_converter.conversion_pack.funcsig_pointer_mapping as funcsig_pointer_mapping
|
||||
from code_object.arg import Arg
|
||||
from code_object.data_member import DataMember
|
||||
from code_object.declaration_specifier import DeclSpec
|
||||
from code_object_converter.supporting.conversion_data_helper import *
|
||||
from code_object_converter.conversion_validation import ConversionValidation
|
||||
from code_object_converter.conversion_pack.conversion_data_helper import *
|
||||
from code_object_converter.conversion_pack.conversion_validation import ConversionValidation
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
from copy import deepcopy
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
import utils.debug as debug
|
||||
from enum import Enum, auto
|
||||
|
||||
import code_object_converter.supporting.conversion_data as conversion_data
|
||||
import code_object_converter.conversion_pack.conversion_data as conversion_data
|
||||
import code_object.declaration_specifier as declaration_specifier
|
||||
|
||||
# Functions and data to help the conversion data object
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
import utils.debug as debug
|
||||
|
||||
# Holds the conversion data, conversion validation and any other useful conversion objects
|
||||
|
||||
class ConversionPack:
|
||||
def __init__(self, conversion_data, conversion_validation) -> None:
|
||||
self._conversion_data = conversion_data
|
||||
self._conversion_validation = conversion_validation
|
||||
|
||||
@property
|
||||
def conversion_data(self):
|
||||
return self._conversion_data
|
||||
|
||||
@property
|
||||
def conversion_validation(self):
|
||||
return self._conversion_validation
|
|
@ -1,11 +1,13 @@
|
|||
|
||||
import utils.debug as debug
|
||||
import code_object.unary_operation as unary_operation
|
||||
|
||||
# Provides functions to perform extra validation as part of a conversion operation
|
||||
#
|
||||
# Holds a reference to the conversion_data (part of the containing conversion_pack class)
|
||||
# This is the interface, override as required...
|
||||
class ConversionValidation:
|
||||
def __init__(self, conversion_data):
|
||||
self._conversion_data = conversion_data
|
||||
|
||||
# ---------- CodeObject Validation : Begin -----------------------------------------------------
|
||||
# Perform full validation of converted C++ function call
|
||||
|
@ -15,6 +17,9 @@ class ConversionValidation:
|
|||
|
||||
def validate_variable_declaration(self, cvariable_declaration, cppvariable_declaration):
|
||||
return cppvariable_declaration
|
||||
|
||||
def validate_binary_operation(self, cbinary_operation, cppbinary_operation):
|
||||
return cppbinary_operation
|
||||
# ---------- CodeObject Validation : End -----------------------------------------------------
|
||||
|
||||
|
|
@ -6,7 +6,7 @@ import code_object.declaration_specifier as declaration_specifier
|
|||
import code_object_converter.code_interface_converter as code_interface_converter
|
||||
import code_object_converter.conversion_funcs as conversion_funcs
|
||||
import utils.standard_transforms as standard_transforms
|
||||
from code_object_converter.supporting.conversion_data_helper import *
|
||||
from code_object_converter.conversion_pack.conversion_data_helper import *
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
|
||||
class DataMemberConverter(arg_converter.ArgConverter):
|
||||
|
@ -14,7 +14,7 @@ class DataMemberConverter(arg_converter.ArgConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, data_member.DataMember), f"Expected DataMember, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
cpparg = super().create_cpp_code_object(conversion_data)
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cpparg = super().create_cpp_code_object(conversion_pack)
|
||||
|
||||
return data_member.DataMember(cpparg.decl_spec, cpparg.name, self._ccode_object.mutable)
|
||||
|
|
|
@ -9,13 +9,13 @@ class DeclSpecConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, declaration_specifier.DeclSpec), f"Expected DeclSpec, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cdecl_spec = self._ccode_object
|
||||
|
||||
debug.line("create_cpp_code_object", f"DeclSpecConverter [IN] [{cdecl_spec.as_string()}] [{cdecl_spec}]")
|
||||
|
||||
|
||||
cpp_decl_spec, _ = conversion_data.closest_funcbody_cppdecl_spec_for_cdecl_spec(cdecl_spec)
|
||||
cpp_decl_spec, _ = conversion_pack.conversion_data.closest_funcbody_cppdecl_spec_for_cdecl_spec(cdecl_spec)
|
||||
|
||||
if not cpp_decl_spec:
|
||||
cpp_decl_spec = declaration_specifier.DeclSpec(storage_class=cdecl_spec.storage_class,
|
||||
|
@ -23,7 +23,7 @@ class DeclSpecConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
type=cdecl_spec.type,
|
||||
pointer=cdecl_spec.pointer)
|
||||
|
||||
conversion_data.add_funcbody_type_mapping(cdecl_spec, cpp_decl_spec)
|
||||
conversion_pack.conversion_data.add_funcbody_type_mapping(cdecl_spec, cpp_decl_spec)
|
||||
debug.line("create_cpp_code_object", f"DeclSpecConverter [OUT] DeclSpec conversion: [{cdecl_spec.as_string()}] [{cdecl_spec}] -> [{cpp_decl_spec.as_string()}]")
|
||||
|
||||
return cpp_decl_spec
|
||||
|
|
|
@ -9,9 +9,9 @@ class DestructorFunctionConverter(member_function_converter.MemberFunctionConver
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, destructor_function.DestructorFunction), f"Expected DestructorFunction, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
cpp_funcsig = conversion_funcs.convert_ccode_object(self._ccode_object.funcsig, conversion_data)
|
||||
cpp_body = conversion_funcs.convert_ccode_object(self._ccode_object.body, conversion_data)
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cpp_funcsig = conversion_funcs.convert_ccode_object(self._ccode_object.funcsig, conversion_pack)
|
||||
cpp_body = conversion_funcs.convert_ccode_object(self._ccode_object.body, conversion_pack)
|
||||
|
||||
return destructor_function.DestructorFunction(cpp_funcsig, cpp_body)
|
||||
|
|
@ -9,11 +9,11 @@ class ForStatementConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, for_statement.ForStatement), f"Expected ForStatement, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
cpp_init_statement = conversion_funcs.convert_ccode_object(self._ccode_object.init_statement, conversion_data)
|
||||
cpp_condition = conversion_funcs.convert_ccode_object(self._ccode_object.condition, conversion_data)
|
||||
cpp_iteration_expression = conversion_funcs.convert_ccode_object(self._ccode_object.iteration_expression, conversion_data)
|
||||
cpp_statement = conversion_funcs.convert_ccode_object(self._ccode_object.statement, conversion_data)
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cpp_init_statement = conversion_funcs.convert_ccode_object(self._ccode_object.init_statement, conversion_pack)
|
||||
cpp_condition = conversion_funcs.convert_ccode_object(self._ccode_object.condition, conversion_pack)
|
||||
cpp_iteration_expression = conversion_funcs.convert_ccode_object(self._ccode_object.iteration_expression, conversion_pack)
|
||||
cpp_statement = conversion_funcs.convert_ccode_object(self._ccode_object.statement, conversion_pack)
|
||||
|
||||
return for_statement.ForStatement(cpp_init_statement, cpp_condition, cpp_iteration_expression, cpp_statement)
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
import utils.debug as debug
|
||||
import code_object.funcsig as funcsig
|
||||
import code_object_converter.code_interface_converter as code_interface_converter
|
||||
import code_object_converter.supporting.funcsig_mapping as funcsig_mapping
|
||||
import code_object_converter.conversion_pack.funcsig_mapping as funcsig_mapping
|
||||
import code_object_converter.conversion_funcs as conversion_funcs
|
||||
import code_object.arg as arg
|
||||
import code_object.declaration_specifier as declaration_specifier
|
||||
|
@ -13,11 +13,11 @@ class FuncSigConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, funcsig.FuncSig), f"Expected FuncSig, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
self._conversion_data = conversion_data
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
self._conversion_pack = conversion_pack
|
||||
|
||||
# If we have a mapping already stored, just use that!
|
||||
cppfuncsig = self._conversion_data.cppfuncsig_for_cfuncsig(self._ccode_object)
|
||||
cppfuncsig = self._conversion_pack.conversion_data.cppfuncsig_for_cfuncsig(self._ccode_object)
|
||||
if not cppfuncsig:
|
||||
cppfunc_arg = self.to_cpp_func_arg()
|
||||
cpp_args = self.to_cpp_args()
|
||||
|
@ -30,7 +30,7 @@ class FuncSigConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
|
||||
# Add this to the conversion data mappings
|
||||
mapping = funcsig_mapping.FuncSigMapping(self._ccode_object, cppfuncsig)
|
||||
self._conversion_data.add_funcsig_mapping(mapping)
|
||||
self._conversion_pack.conversion_data.add_funcsig_mapping(mapping)
|
||||
|
||||
# Update the settings that we don't need (want?) to store in the map
|
||||
cppfuncsig.is_declaration = self._ccode_object.is_declaration
|
||||
|
@ -45,7 +45,7 @@ class FuncSigConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
# Converts the name and return type internal representation to C++
|
||||
def to_cpp_func_arg(self):
|
||||
cfunc_arg = self._ccode_object.func_arg
|
||||
cppfunc_arg = conversion_funcs.convert_ccode_object(cfunc_arg, self._conversion_data)
|
||||
cppfunc_arg = conversion_funcs.convert_ccode_object(cfunc_arg, self._conversion_pack)
|
||||
|
||||
if cppfunc_arg.decl_spec.type == "int":
|
||||
# We'll assume int means GribStatus
|
||||
|
@ -61,7 +61,7 @@ class FuncSigConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
def to_cpp_args(self):
|
||||
cppargs = []
|
||||
for entry in self._ccode_object.args:
|
||||
cpparg = conversion_funcs.convert_ccode_object(entry, self._conversion_data)
|
||||
cpparg = conversion_funcs.convert_ccode_object(entry, self._conversion_pack)
|
||||
cppargs.append(cpparg)
|
||||
|
||||
return cppargs
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
import code_object.funcsig_pointer as funcsig_pointer
|
||||
import code_object_converter.funcsig_converter as funcsig_converter
|
||||
import code_object_converter.supporting.funcsig_pointer_mapping as funcsig_pointer_mapping
|
||||
import code_object_converter.conversion_pack.funcsig_pointer_mapping as funcsig_pointer_mapping
|
||||
import code_object.declaration_specifier as declaration_specifier
|
||||
import utils.debug as debug
|
||||
|
||||
|
@ -14,11 +14,11 @@ class FuncSigPointerConverter(funcsig_converter.FuncSigConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, funcsig_pointer.FuncSigPointer), f"Expected FuncSigPointer, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
self._conversion_data = conversion_data
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
self._conversion_pack = conversion_pack
|
||||
|
||||
# If we have a mapping already stored, just use that!
|
||||
cppfuncsig_pointer = self._conversion_data.cppfuncsig_pointer_for_cfuncsig_pointer(self._ccode_object)
|
||||
cppfuncsig_pointer = self._conversion_pack.conversion_data.cppfuncsig_pointer_for_cfuncsig_pointer(self._ccode_object)
|
||||
if not cppfuncsig_pointer:
|
||||
cppfunc_arg = self.to_cpp_func_arg()
|
||||
cpp_args = self.to_cpp_args()
|
||||
|
@ -31,12 +31,12 @@ class FuncSigPointerConverter(funcsig_converter.FuncSigConverter):
|
|||
|
||||
# Add this to the conversion data mappings
|
||||
mapping = funcsig_pointer_mapping.FuncSigPointerMapping(self._ccode_object, cppfuncsig_pointer)
|
||||
self._conversion_data.add_funcsig_pointer_mapping(mapping)
|
||||
self._conversion_pack.conversion_data.add_funcsig_pointer_mapping(mapping)
|
||||
|
||||
# We've also created a new type, so need to add this (to the funcbody map) too!
|
||||
cdecl_spec = declaration_specifier.DeclSpec(type=self._ccode_object.func_arg.name, pointer=self._ccode_object.func_arg.decl_spec.pointer)
|
||||
cppdecl_spec = declaration_specifier.DeclSpec(type=cppfunc_arg.name, pointer=cppfunc_arg.decl_spec.pointer)
|
||||
self._conversion_data.add_funcbody_type_mapping(cdecl_spec, cppdecl_spec)
|
||||
self._conversion_pack.conversion_data.add_funcbody_type_mapping(cdecl_spec, cppdecl_spec)
|
||||
debug.line("create_cpp_code_object", f"FuncSigPointer conversion: [{cdecl_spec.as_string()}] -> [{cppdecl_spec.as_string()}]")
|
||||
|
||||
|
||||
|
|
|
@ -11,18 +11,18 @@ class FunctionCallConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, function_call.FunctionCall), f"Expected FunctionCall, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cfunction_call = self._ccode_object
|
||||
cppfunction_call = None
|
||||
|
||||
# 1. Check if there is a function mapping defined
|
||||
mapping = conversion_data.funcsig_mapping_for_cfuncname(cfunction_call.name)
|
||||
mapping = conversion_pack.conversion_data.funcsig_mapping_for_cfuncname(cfunction_call.name)
|
||||
if mapping:
|
||||
debug.line("create_cpp_code_object", f"FunctionCallConverter [1]")
|
||||
cpp_args = []
|
||||
for i, arg_entry in enumerate(mapping.cppfuncsig.args):
|
||||
if arg_entry != NONE_VALUE:
|
||||
cpp_arg_entry = conversion_funcs.convert_ccode_object(cfunction_call.args[i], conversion_data)
|
||||
cpp_arg_entry = conversion_funcs.convert_ccode_object(cfunction_call.args[i], conversion_pack)
|
||||
assert cpp_arg_entry != NONE_VALUE, f"Expected cpp_arg_entry for carg=[{debug.as_debug_string(cfunction_call.args[i])}], got NoneValue!"
|
||||
cpp_args.append(cpp_arg_entry)
|
||||
|
||||
|
@ -30,10 +30,10 @@ class FunctionCallConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
else:
|
||||
debug.line("create_cpp_code_object", f"FunctionCallConverter [2]")
|
||||
# 2. Perform a manual conversion
|
||||
cpp_name = conversion_funcs.convert_ccode_object(cfunction_call.name, conversion_data)
|
||||
cpp_name = conversion_funcs.convert_ccode_object(cfunction_call.name, conversion_pack)
|
||||
cpp_args = []
|
||||
for arg_entry in self._ccode_object.args:
|
||||
cpp_arg_entry = conversion_funcs.convert_ccode_object(arg_entry, conversion_data)
|
||||
cpp_arg_entry = conversion_funcs.convert_ccode_object(arg_entry, conversion_pack)
|
||||
|
||||
if cpp_arg_entry != NONE_VALUE:
|
||||
cpp_args.append(cpp_arg_entry)
|
||||
|
@ -41,4 +41,4 @@ class FunctionCallConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
cppfunction_call = function_call.FunctionCall(cpp_name, cpp_args)
|
||||
|
||||
# 3. Apply validation (and special handling)
|
||||
return conversion_data.conversion_validation.validate_function_call(cfunction_call, cppfunction_call, mapping)
|
||||
return conversion_pack.conversion_validation.validate_function_call(cfunction_call, cppfunction_call, mapping)
|
||||
|
|
|
@ -9,9 +9,9 @@ class FunctionConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, function.Function), f"Expected Function, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
cpp_funcsig = conversion_funcs.convert_ccode_object(self._ccode_object.funcsig, conversion_data)
|
||||
cpp_body = conversion_funcs.convert_ccode_object(self._ccode_object.body, conversion_data)
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cpp_funcsig = conversion_funcs.convert_ccode_object(self._ccode_object.funcsig, conversion_pack)
|
||||
cpp_body = conversion_funcs.convert_ccode_object(self._ccode_object.body, conversion_pack)
|
||||
|
||||
return function.Function(cpp_funcsig, cpp_body)
|
||||
|
|
@ -11,16 +11,16 @@ class GlobalFunctionConverter(function_converter.FunctionConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, global_function.GlobalFunction), f"Expected GlobalFunction, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
self._conversion_data = conversion_data
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
self._conversion_pack = conversion_pack
|
||||
cpp_body = code_objects.CodeObjects()
|
||||
|
||||
for entry in self._ccode_object.body.code_objects:
|
||||
if isinstance(entry, funcsig.FuncSig) and conversion_data.is_member_function(entry.name):
|
||||
if isinstance(entry, funcsig.FuncSig) and self._conversion_pack.conversion_data.is_member_function(entry.name):
|
||||
debug.line("create_cpp_code_object", f"Ignoring member function name=[{entry.name}]")
|
||||
continue
|
||||
|
||||
cpp_code_obj = conversion_funcs.convert_ccode_object(entry, conversion_data)
|
||||
cpp_code_obj = conversion_funcs.convert_ccode_object(entry, self._conversion_pack)
|
||||
cpp_body.add_code_object(cpp_code_obj)
|
||||
|
||||
return global_function.GlobalFunction(cpp_body)
|
||||
|
|
|
@ -9,8 +9,8 @@ class IfStatementConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, if_statement.IfStatement), f"Expected IfStatement, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
cpp_expression = conversion_funcs.convert_ccode_object(self._ccode_object.expression, conversion_data)
|
||||
cpp_action = conversion_funcs.convert_ccode_object(self._ccode_object.action, conversion_data)
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cpp_expression = conversion_funcs.convert_ccode_object(self._ccode_object.expression, conversion_pack)
|
||||
cpp_action = conversion_funcs.convert_ccode_object(self._ccode_object.action, conversion_pack)
|
||||
|
||||
return if_statement.IfStatement(cpp_expression, cpp_action)
|
||||
|
|
|
@ -9,12 +9,12 @@ class InitListConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, init_list.InitList), f"Expected InitList, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
cpp_decl_spec = conversion_funcs.convert_ccode_object(self._ccode_object.decl_spec, conversion_data)
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cpp_decl_spec = conversion_funcs.convert_ccode_object(self._ccode_object.decl_spec, conversion_pack)
|
||||
cpp_init_list = init_list.InitList(cpp_decl_spec)
|
||||
|
||||
for entry in self._ccode_object.entries:
|
||||
cpp_entry = conversion_funcs.convert_ccode_object(entry, conversion_data)
|
||||
cpp_entry = conversion_funcs.convert_ccode_object(entry, conversion_pack)
|
||||
cpp_init_list.add_entry(cpp_entry)
|
||||
|
||||
return cpp_init_list
|
||||
|
|
|
@ -9,10 +9,10 @@ class LiteralConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, literal.Literal), f"Expected Literal, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
|
||||
# 1. Check for a literal mapping
|
||||
cppliteral = conversion_data.cppstring_literal_for_cstring(self._ccode_object.value)
|
||||
cppliteral = conversion_pack.conversion_data.cppstring_literal_for_cstring(self._ccode_object.value)
|
||||
if cppliteral:
|
||||
return literal.Literal(cppliteral)
|
||||
|
||||
|
|
|
@ -9,6 +9,6 @@ class MacroDefinitionConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, macro_definition.MacroDefinition), f"Expected MacroDefinition, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
# For now, just return a copy...
|
||||
return macro_definition.MacroDefinition(self._ccode_object.as_lines())
|
||||
|
|
|
@ -9,6 +9,6 @@ class MacroInstantiationConverter(code_interface_converter.CodeInterfaceConverte
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, macro_instantation.MacroInstantation), f"Expected MacroInstantation, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
# For now, just return a copy...
|
||||
return macro_instantation.MacroInstantation(self._ccode_object.as_lines())
|
||||
|
|
|
@ -9,9 +9,9 @@ class MemberFunctionConverter(function_converter.FunctionConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, member_function.MemberFunction), f"Expected MemberFunction, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
cpp_funcsig = conversion_funcs.convert_ccode_object(self._ccode_object.funcsig, conversion_data)
|
||||
cpp_body = conversion_funcs.convert_ccode_object(self._ccode_object.body, conversion_data)
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cpp_funcsig = conversion_funcs.convert_ccode_object(self._ccode_object.funcsig, conversion_pack)
|
||||
cpp_body = conversion_funcs.convert_ccode_object(self._ccode_object.body, conversion_pack)
|
||||
|
||||
return member_function.MemberFunction(cpp_funcsig, cpp_body)
|
||||
|
|
@ -9,6 +9,6 @@ class OperationConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, operation.Operation), f"Expected Operation, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
# By default we just return a copy of the value
|
||||
return operation.Operation(self._ccode_object.value)
|
||||
|
|
|
@ -9,7 +9,7 @@ class ParenExpressionConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, paren_expression.ParenExpression), f"Expected ParenExpression, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
cpp_expression = conversion_funcs.convert_ccode_object(self._ccode_object.expression, conversion_data)
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cpp_expression = conversion_funcs.convert_ccode_object(self._ccode_object.expression, conversion_pack)
|
||||
|
||||
return paren_expression.ParenExpression(cpp_expression)
|
||||
|
|
|
@ -9,7 +9,7 @@ class ReturnStatementConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, return_statement.ReturnStatement), f"Expected ReturnStatement, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
cpp_expression = conversion_funcs.convert_ccode_object(self._ccode_object.expression, conversion_data)
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cpp_expression = conversion_funcs.convert_ccode_object(self._ccode_object.expression, conversion_pack)
|
||||
|
||||
return return_statement.ReturnStatement(cpp_expression)
|
||||
|
|
|
@ -10,20 +10,20 @@ class StructArgConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, struct_arg.StructArg), f"Expected StructArg, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
# Note: The struct name actually defines a type...
|
||||
cpp_decl_spec, _ = conversion_data.closest_funcbody_cppdecl_spec_for_ctype(self._ccode_object.name)
|
||||
cpp_decl_spec, _ = conversion_pack.conversion_data.closest_funcbody_cppdecl_spec_for_ctype(self._ccode_object.name)
|
||||
|
||||
if not cpp_decl_spec:
|
||||
cpp_name = conversion_funcs.convert_ccode_object(self._ccode_object.name, conversion_data)
|
||||
cpp_name = conversion_funcs.convert_ccode_object(self._ccode_object.name, conversion_pack)
|
||||
cdecl_spec = declaration_specifier.DeclSpec(type=self._ccode_object.name, pointer="")
|
||||
cpp_decl_spec = declaration_specifier.DeclSpec(type=cpp_name, pointer="")
|
||||
conversion_data.add_funcbody_type_mapping(cdecl_spec, cpp_decl_spec)
|
||||
conversion_pack.conversion_data.add_funcbody_type_mapping(cdecl_spec, cpp_decl_spec)
|
||||
debug.line("create_cpp_code_object", f"StructArg type mapping: [{cdecl_spec.as_string()}] -> [{cpp_decl_spec.as_string()}]")
|
||||
|
||||
cpp_members=[]
|
||||
for member in self._ccode_object.members:
|
||||
cpp_member = conversion_funcs.convert_ccode_object(member, conversion_data)
|
||||
cpp_member = conversion_funcs.convert_ccode_object(member, conversion_pack)
|
||||
cpp_members.append(cpp_member)
|
||||
|
||||
return struct_arg.StructArg(cpp_decl_spec.type, cpp_members)
|
||||
|
|
|
@ -9,23 +9,23 @@ class StructMemberAccessConverter(code_interface_converter.CodeInterfaceConverte
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, struct_member_access.StructMemberAccess), f"Expected StructMemberAccess, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
debug.line("create_cpp_code_object",f" StructMemberAccessConverter [IN] self._ccode_object=[{debug.as_debug_string(self._ccode_object)}]")
|
||||
|
||||
# Check if this is a pointer to a class instance
|
||||
if conversion_data.conversion_validation.is_pointer_to_class_instance(self._ccode_object.name):
|
||||
if conversion_pack.conversion_validation.is_pointer_to_class_instance(self._ccode_object.name):
|
||||
cstruct_member_access = self._ccode_object.member
|
||||
cpp_access = ""
|
||||
cpp_data_member = conversion_data.cppdata_member_for_cdata_member_name(cstruct_member_access.name)
|
||||
cpp_data_member = conversion_pack.conversion_data.cppdata_member_for_cdata_member_name(cstruct_member_access.name)
|
||||
assert cpp_data_member
|
||||
cpp_name = cpp_data_member.name
|
||||
cpp_index = conversion_funcs.convert_ccode_object(cstruct_member_access.index, conversion_data)
|
||||
cpp_member = conversion_funcs.convert_ccode_object(cstruct_member_access.member, conversion_data)
|
||||
cpp_index = conversion_funcs.convert_ccode_object(cstruct_member_access.index, conversion_pack)
|
||||
cpp_member = conversion_funcs.convert_ccode_object(cstruct_member_access.member, conversion_pack)
|
||||
else:
|
||||
cstruct_member_access = self._ccode_object
|
||||
cpp_access = conversion_funcs.convert_ccode_object(cstruct_member_access.access, conversion_data)
|
||||
cpp_name = conversion_funcs.convert_ccode_object(cstruct_member_access.name, conversion_data)
|
||||
cpp_index = conversion_funcs.convert_ccode_object(cstruct_member_access.index, conversion_data)
|
||||
cpp_member = conversion_funcs.convert_ccode_object(cstruct_member_access.member, conversion_data)
|
||||
cpp_access = conversion_funcs.convert_ccode_object(cstruct_member_access.access, conversion_pack)
|
||||
cpp_name = conversion_funcs.convert_ccode_object(cstruct_member_access.name, conversion_pack)
|
||||
cpp_index = conversion_funcs.convert_ccode_object(cstruct_member_access.index, conversion_pack)
|
||||
cpp_member = conversion_funcs.convert_ccode_object(cstruct_member_access.member, conversion_pack)
|
||||
|
||||
return struct_member_access.StructMemberAccess(cpp_access, cpp_name, cpp_index, cpp_member)
|
||||
|
|
|
@ -9,8 +9,8 @@ class UnaryExpressionConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, unary_expression.UnaryExpression), f"Expected UnaryExpression, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
cpp_keyword = conversion_funcs.convert_ccode_object(self._ccode_object.keyword, conversion_data)
|
||||
cpp_expression = conversion_funcs.convert_ccode_object(self._ccode_object.expression, conversion_data)
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cpp_keyword = conversion_funcs.convert_ccode_object(self._ccode_object.keyword, conversion_pack)
|
||||
cpp_expression = conversion_funcs.convert_ccode_object(self._ccode_object.expression, conversion_pack)
|
||||
|
||||
return unary_expression.UnaryExpression(cpp_keyword, cpp_expression)
|
||||
|
|
|
@ -9,8 +9,8 @@ class UnaryOperationConverter(code_interface_converter.CodeInterfaceConverter):
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, unary_operation.UnaryOperation), f"Expected UnaryOperation, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
cpp_unary_op = conversion_funcs.convert_ccode_object(self._ccode_object.unary_op, conversion_data)
|
||||
cpp_operand = conversion_funcs.convert_ccode_object(self._ccode_object.operand, conversion_data)
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cpp_unary_op = conversion_funcs.convert_ccode_object(self._ccode_object.unary_op, conversion_pack)
|
||||
cpp_operand = conversion_funcs.convert_ccode_object(self._ccode_object.operand, conversion_pack)
|
||||
|
||||
return unary_operation.UnaryOperation(cpp_unary_op, cpp_operand)
|
||||
|
|
|
@ -11,22 +11,22 @@ class ValueDeclarationReferenceConverter(code_interface_converter.CodeInterfaceC
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, value_declaration_reference.ValueDeclarationReference), f"Expected ValueDeclarationReference, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cdecl_ref_expr_value = self._ccode_object.as_string()
|
||||
|
||||
# 1. Check if it is a function name
|
||||
cppfuncsig = conversion_data.cppfuncsig_for_cfuncname(cdecl_ref_expr_value)
|
||||
cppfuncsig = conversion_pack.conversion_data.cppfuncsig_for_cfuncname(cdecl_ref_expr_value)
|
||||
if cppfuncsig:
|
||||
return value_declaration_reference.ValueDeclarationReference(cppfuncsig.name)
|
||||
|
||||
# 2. Check if it is an arg
|
||||
cpparg = conversion_data.funcbody_cpparg_for_carg_name(cdecl_ref_expr_value)
|
||||
cpparg = conversion_pack.conversion_data.funcbody_cpparg_for_carg_name(cdecl_ref_expr_value)
|
||||
if cpparg == NONE_VALUE:
|
||||
return NONE_VALUE
|
||||
elif cpparg:
|
||||
return value_declaration_reference.ValueDeclarationReference(cpparg.name)
|
||||
|
||||
# 3. Perform a default conversion
|
||||
cdecl_ref_expr_value = conversion_funcs.convert_ccode_object(cdecl_ref_expr_value, conversion_data)
|
||||
cdecl_ref_expr_value = conversion_funcs.convert_ccode_object(cdecl_ref_expr_value, conversion_pack)
|
||||
|
||||
return value_declaration_reference.ValueDeclarationReference(cdecl_ref_expr_value)
|
||||
|
|
|
@ -11,17 +11,17 @@ class VariableDeclarationConverter(code_interface_converter.CodeInterfaceConvert
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, variable_declaration.VariableDeclaration), f"Expected VariableDeclaration, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
|
||||
cpp_variable = conversion_funcs.convert_ccode_object(self._ccode_object.variable, conversion_data)
|
||||
cpp_variable = conversion_funcs.convert_ccode_object(self._ccode_object.variable, conversion_pack)
|
||||
|
||||
if cpp_variable == NONE_VALUE:
|
||||
return conversion_funcs.as_commented_out_code(self._ccode_object, f"Removed invalid variable")
|
||||
|
||||
cpp_value = conversion_funcs.convert_ccode_object(self._ccode_object.value, conversion_data)
|
||||
cpp_value = conversion_funcs.convert_ccode_object(self._ccode_object.value, conversion_pack)
|
||||
|
||||
cpp_variable_declaration = variable_declaration.VariableDeclaration(cpp_variable, cpp_value)
|
||||
cpp_variable_declaration = conversion_data.conversion_validation.validate_variable_declaration(self._ccode_object, cpp_variable_declaration)
|
||||
cpp_variable_declaration = conversion_pack.conversion_validation.validate_variable_declaration(self._ccode_object, cpp_variable_declaration)
|
||||
|
||||
return cpp_variable_declaration
|
||||
|
|
@ -9,9 +9,9 @@ class VirtualMemberFunctionConverter(member_function_converter.MemberFunctionCon
|
|||
super().__init__(ccode_object)
|
||||
assert isinstance(ccode_object, virtual_member_function.VirtualMemberFunction), f"Expected MemberFunction, got type=[{type(ccode_object)}]"
|
||||
|
||||
def create_cpp_code_object(self, conversion_data):
|
||||
cpp_funcsig = conversion_funcs.convert_ccode_object(self._ccode_object.funcsig, conversion_data)
|
||||
cpp_body = conversion_funcs.convert_ccode_object(self._ccode_object.body, conversion_data)
|
||||
def create_cpp_code_object(self, conversion_pack):
|
||||
cpp_funcsig = conversion_funcs.convert_ccode_object(self._ccode_object.funcsig, conversion_pack)
|
||||
cpp_body = conversion_funcs.convert_ccode_object(self._ccode_object.body, conversion_pack)
|
||||
|
||||
return virtual_member_function.VirtualMemberFunction(cpp_funcsig, cpp_body)
|
||||
|
|
@ -3,10 +3,11 @@ import utils.debug as debug
|
|||
import cpp_code.cppcode as cppcode
|
||||
import cpp_code.code_info as code_info
|
||||
import cpp_code.code_elements as code_elements
|
||||
import code_object_converter.supporting.conversion_data as conversion_data
|
||||
import code_object_converter.conversion_pack.conversion_data as conversion_data
|
||||
import code_object_converter.conversion_pack.conversion_pack as conversion_pack
|
||||
import code_object_converter.conversion_funcs as conversion_funcs
|
||||
import code_object.data_member as data_member
|
||||
from default.default_conversion_validation import DefaultConversionValidation
|
||||
from default.default_conversion_pack.default_conversion_validation import DefaultConversionValidation
|
||||
import code_object.member_function as member_function
|
||||
|
||||
# Convert a CCode object into a CppCode object, using the cconverter and derived classes as helpers
|
||||
|
@ -16,13 +17,13 @@ class DefaultCCodeConverter:
|
|||
self._ccode = ccode_instance
|
||||
|
||||
def convert(self):
|
||||
self.setup_conversion_objects()
|
||||
self.setup_conversion_pack()
|
||||
self.add_includes()
|
||||
self.convert_global_function()
|
||||
self.convert_data_members()
|
||||
|
||||
# Now set the conversion data state to local for the rest of the conversion
|
||||
self._conversion_data.set_local_state()
|
||||
self._conversion_pack.conversion_data.set_local_state()
|
||||
|
||||
self.convert_functions()
|
||||
self.convert_constructor_function()
|
||||
|
@ -34,20 +35,28 @@ class DefaultCCodeConverter:
|
|||
|
||||
# ============================== Setup functions: start ==============================
|
||||
|
||||
def setup_conversion_objects(self):
|
||||
def setup_conversion_pack(self):
|
||||
self._code_info = self.create_code_info()
|
||||
self._code_elements = code_elements.CodeElements()
|
||||
self._conversion_data = conversion_data.ConversionData(self._code_info)
|
||||
self.initialise_conversion_data()
|
||||
conv_data = self.create_conversion_data()
|
||||
conv_validation = self.create_conversion_validation(conv_data)
|
||||
self._conversion_pack = conversion_pack.ConversionPack(conv_data, conv_validation)
|
||||
self.initialise_conversion_pack()
|
||||
|
||||
def create_code_info(self):
|
||||
cpp_filename = self._ccode.cfilename
|
||||
cpp_class_name = self._ccode.class_name
|
||||
return code_info.CodeInfo(cpp_filename, cpp_class_name)
|
||||
|
||||
def create_conversion_data(self):
|
||||
return conversion_data.ConversionData(self._code_info)
|
||||
|
||||
def create_conversion_validation(self, conv_data):
|
||||
return DefaultConversionValidation(conv_data)
|
||||
|
||||
# Override to set required initial state
|
||||
def initialise_conversion_data(self):
|
||||
self._conversion_data.conversion_validation = DefaultConversionValidation()
|
||||
def initialise_conversion_pack(self):
|
||||
pass
|
||||
|
||||
# ============================== Setup functions: end ==============================
|
||||
|
||||
|
@ -59,13 +68,13 @@ class DefaultCCodeConverter:
|
|||
pass
|
||||
|
||||
def convert_global_function(self):
|
||||
self._code_elements.global_function = conversion_funcs.convert_ccode_object(self._ccode.global_function, self._conversion_data)
|
||||
self._code_elements.global_function = conversion_funcs.convert_ccode_object(self._ccode.global_function, self._conversion_pack)
|
||||
debug.line("convert_global_function", f"Converted C++ code [as_lines]...")
|
||||
debug.line("convert_global_function", self._code_elements.global_function.as_lines())
|
||||
|
||||
def convert_data_members(self):
|
||||
for cmember in self._ccode.data_members:
|
||||
cppmember = conversion_funcs.convert_ccode_object(cmember, self._conversion_data)
|
||||
cppmember = conversion_funcs.convert_ccode_object(cmember, self._conversion_pack)
|
||||
cppmember = data_member.DataMember(cppmember.decl_spec, cppmember.name + "_")
|
||||
|
||||
# FOR NOW - MAKE ALL MEMBERS NON-CONST
|
||||
|
@ -74,7 +83,7 @@ class DefaultCCodeConverter:
|
|||
debug.line("convert_data_members", f"*** SETTING DATA MEMBER TO NON-CONST *** cppmember=[{debug.as_debug_string(cppmember)}]")
|
||||
|
||||
self._code_elements.add_data_member(cppmember)
|
||||
self._conversion_data.add_data_member_mapping(cmember, cppmember)
|
||||
self._conversion_pack.conversion_data.add_data_member_mapping(cmember, cppmember)
|
||||
debug.line("convert_data_members", f"cmember=[{debug.as_debug_string(cmember)}] cppmember=[{debug.as_debug_string(cppmember)}]")
|
||||
|
||||
|
||||
|
@ -84,16 +93,16 @@ class DefaultCCodeConverter:
|
|||
|
||||
# Helper to ensure the function is converted correctly, including resetting the local conversion data!
|
||||
def to_cpp_function(self, func):
|
||||
self._conversion_data.reset_local_state()
|
||||
cpp_func = conversion_funcs.convert_ccode_object(func, self._conversion_data)
|
||||
self._conversion_pack.conversion_data.reset_local_state()
|
||||
cpp_func = conversion_funcs.convert_ccode_object(func, self._conversion_pack)
|
||||
if isinstance(cpp_func, member_function.MemberFunction):
|
||||
cpp_func.class_name = self._conversion_data.info.class_name
|
||||
cpp_func.class_name = self._conversion_pack.conversion_data.info.class_name
|
||||
cpp_func.set_is_const(self.is_const_member_function(func.funcsig.name))
|
||||
return cpp_func
|
||||
|
||||
def convert_functions(self):
|
||||
for func in self._ccode.functions:
|
||||
self._conversion_data.reset_local_state()
|
||||
self._conversion_pack.conversion_data.reset_local_state()
|
||||
cppfunc = self.to_cpp_function(func)
|
||||
self._code_elements.add_function(cppfunc)
|
||||
self.dump_function("convert_functions", cppfunc)
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
|
||||
import utils.debug as debug
|
||||
import code_object_converter.conversion_validation as conversion_validation
|
||||
import code_object_converter.conversion_pack.conversion_validation as conversion_validation
|
||||
import code_object.unary_operation as unary_operation
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
import code_object.function_call as function_call
|
||||
import code_object.literal as literal
|
||||
import re
|
||||
|
||||
# Pass this to the conversion_data object to be accessed by the conversion routines
|
||||
class DefaultConversionValidation(conversion_validation.ConversionValidation):
|
||||
|
@ -31,7 +33,32 @@ class DefaultConversionValidation(conversion_validation.ConversionValidation):
|
|||
|
||||
# Just return the passed in value!
|
||||
return calling_arg_value
|
||||
|
||||
|
||||
def validate_binary_operation(self, cbinary_operation, cppbinary_operation):
|
||||
# Check for the sizeof(x)/sizeof(*x) idiom (in the C code), and if x is a container in C++, replace with x.size()
|
||||
# Note we also check for sizeof(x)/sizeof(x[0])
|
||||
cvalue = cbinary_operation.as_string()
|
||||
m = re.search(rf"sizeof\(([^\)])\)/sizeof\((\*\1\)|(\1\[0\]\)))", cvalue)
|
||||
if m:
|
||||
cvariable = m.group(1)
|
||||
cpparg = self._conversion_data.funcbody_cpparg_for_carg_name(cvariable)
|
||||
if cpparg and self.is_cpp_container_type(cpparg.decl_spec):
|
||||
return literal.Literal(f"{cpparg.name}.size()")
|
||||
|
||||
return cppbinary_operation
|
||||
|
||||
# Returns True is the name is a pointer to a class instance
|
||||
def is_pointer_to_class_instance(self, arg_name):
|
||||
return arg_name in ["self", "this"]
|
||||
return arg_name in ["self", "this"]
|
||||
|
||||
def is_cpp_container_type(self, cppdecl_spec):
|
||||
for type in [
|
||||
"std::string",
|
||||
"std::array",
|
||||
"std::vector",
|
||||
"std::map",
|
||||
]:
|
||||
if type in cppdecl_spec.type:
|
||||
return True
|
||||
|
||||
return False
|
|
@ -13,7 +13,7 @@ import grib_accessor.supporting.type_mappings as type_mappings
|
|||
from code_object.declaration_specifier import DeclSpec
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
import grib_accessor.supporting.funcsig_mappings.all_funcsig_mappings as all_funcsig_mappings
|
||||
from grib_accessor.grib_accessor_conversion_validation import GribAccessorConversionValidation
|
||||
from grib_accessor.grib_accessor_conversion_pack.grib_accessor_conversion_validation import GribAccessorConversionValidation
|
||||
import grib_accessor.supporting.grib_literal_mapping as grib_literal_mapping
|
||||
import grib_accessor.supporting.grib_literal_mapping as grib_literal_mapping
|
||||
import grib_accessor.supporting.arg_mappings as arg_mappings
|
||||
|
@ -54,47 +54,48 @@ class GribAccessorCCodeConverter(default_ccode_converter.DefaultCCodeConverter):
|
|||
|
||||
return info
|
||||
|
||||
def initialise_conversion_data(self):
|
||||
self._conversion_data.conversion_validation = GribAccessorConversionValidation()
|
||||
def create_conversion_validation(self, conv_data):
|
||||
return GribAccessorConversionValidation(conv_data)
|
||||
|
||||
def initialise_conversion_pack(self):
|
||||
for mapping in grib_accessor_member_funcsig_mapping:
|
||||
self._conversion_data.add_member_funcsig_mapping(mapping)
|
||||
self._conversion_pack.conversion_data.add_member_funcsig_mapping(mapping)
|
||||
|
||||
for mapping in grib_accessor_virtual_member_funcsig_mapping:
|
||||
self._conversion_data.add_virtual_member_funcsig_mapping(mapping)
|
||||
self._conversion_pack.conversion_data.add_virtual_member_funcsig_mapping(mapping)
|
||||
|
||||
all_funcsig_mappings.add_all_funcsig_mappings_to_conversion_data(self._conversion_data)
|
||||
all_funcsig_mappings.add_all_funcsig_mappings_to_conversion_data(self._conversion_pack.conversion_data)
|
||||
|
||||
arg_mappings.add_arg_mappings_to_conversion_data(self._conversion_data)
|
||||
arg_mappings.add_arg_mappings_to_conversion_data(self._conversion_pack.conversion_data)
|
||||
|
||||
type_mappings.add_type_mappings_to_conversion_data(self._conversion_data)
|
||||
type_mappings.add_type_mappings_to_conversion_data(self._conversion_pack.conversion_data)
|
||||
|
||||
grib_literal_mapping.add_grib_literal_mappings_to_conversion_data(self._conversion_data)
|
||||
grib_literal_mapping.add_grib_literal_mappings_to_conversion_data(self._conversion_pack.conversion_data)
|
||||
|
||||
data_member_mappings.add_data_member_mappings_to_conversion_data(self._conversion_data)
|
||||
data_member_mappings.add_data_member_mappings_to_conversion_data(self._conversion_pack.conversion_data)
|
||||
|
||||
# Add C class name pointer as "do not convert" (e.g. grib_accessor_class_proj_string* -> NoneDeclSpec)
|
||||
debug.line("initialise_conversion_data", f"Adding funcbody mapping for Accessor name=[{self._ccode.accessor_name}]")
|
||||
self._conversion_data.add_funcbody_type_mapping(DeclSpec.from_decl_specifier_seq(self._ccode.accessor_name+"*"), NONE_VALUE)
|
||||
self._conversion_pack.conversion_data.add_funcbody_type_mapping(DeclSpec.from_decl_specifier_seq(self._ccode.accessor_name+"*"), NONE_VALUE)
|
||||
|
||||
def set_function_specific_conversion_data(self, function_name):
|
||||
pass
|
||||
|
||||
def add_includes(self):
|
||||
# Header includes
|
||||
if self._conversion_data.info.super_class_name == "AccessorData":
|
||||
self._conversion_data.info.header_includes.append("/".join(["AccessorData", self._conversion_data.info.super_class_name + ".h"]))
|
||||
if self._conversion_pack.conversion_data.info.super_class_name == "AccessorData":
|
||||
self._conversion_pack.conversion_data.info.header_includes.append("/".join(["AccessorData", self._conversion_pack.conversion_data.info.super_class_name + ".h"]))
|
||||
else:
|
||||
self._conversion_data.info.header_includes.append(f"{self._conversion_data.info.super_class_name}.h")
|
||||
self._conversion_pack.conversion_data.info.header_includes.append(f"{self._conversion_pack.conversion_data.info.super_class_name}.h")
|
||||
|
||||
for inc in includes.grib_accessor_header_includes:
|
||||
self._conversion_data.info.header_includes.append(inc)
|
||||
self._conversion_pack.conversion_data.info.header_includes.append(inc)
|
||||
|
||||
# Source includes
|
||||
self._conversion_data.info.source_includes.append(f"\"{self._conversion_data.info.class_name}.h\"")
|
||||
self._conversion_pack.conversion_data.info.source_includes.append(f"\"{self._conversion_pack.conversion_data.info.class_name}.h\"")
|
||||
|
||||
for inc in includes.grib_accessor_source_includes:
|
||||
self._conversion_data.info.source_includes.append(inc)
|
||||
self._conversion_pack.conversion_data.info.source_includes.append(inc)
|
||||
|
||||
|
||||
# TODO: Class-specific includes
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
|
||||
import utils.debug as debug
|
||||
import default.default_conversion_validation as default_conversion_validation
|
||||
import default.default_conversion_pack.default_conversion_validation as default_conversion_validation
|
||||
import code_object.literal as literal
|
||||
import code_object.variable_declaration as variable_declaration
|
||||
import code_object.function_call as function_call
|
||||
from grib_accessor.conversion_validation.grib_accessor_special_function_call_conversion import apply_special_function_call_conversions
|
||||
import code_object.binary_operation as binary_operation
|
||||
from grib_accessor.grib_accessor_conversion_pack.grib_accessor_special_function_call_conversion import apply_special_function_call_conversions
|
||||
|
||||
# Pass this to the conversion_data object to be accessed by the conversion routines
|
||||
class GribAccessorConversionValidation(default_conversion_validation.DefaultConversionValidation):
|
||||
|
@ -31,8 +31,25 @@ class GribAccessorConversionValidation(default_conversion_validation.DefaultConv
|
|||
return updated_cpp_variable_declaration
|
||||
|
||||
return super().validate_variable_declaration(cvariable_declaration, cppvariable_declaration)
|
||||
|
||||
|
||||
def validate_binary_operation(self, cbinary_operation, cppbinary_operation):
|
||||
if cppbinary_operation.left_operand.as_string() == "flags_":
|
||||
if cppbinary_operation.right_operand.as_string().startswith("GribAccessorFlag"):
|
||||
updated_right_operand = literal.Literal(f"toInt({cppbinary_operation.right_operand.as_string()})")
|
||||
return binary_operation.BinaryOperation(cppbinary_operation.left_operand, cppbinary_operation.binary_op, updated_right_operand)
|
||||
|
||||
return super().validate_binary_operation(cbinary_operation, cppbinary_operation)
|
||||
|
||||
def is_pointer_to_class_instance(self, arg_name):
|
||||
if arg_name in ["a"]:
|
||||
return True
|
||||
return super().is_pointer_to_class_instance(arg_name)
|
||||
return super().is_pointer_to_class_instance(arg_name)
|
||||
|
||||
def is_cpp_container_type(self, cppdecl_spec):
|
||||
for type in [
|
||||
"AccessorDataBuffer",
|
||||
]:
|
||||
if type in cppdecl_spec.type:
|
||||
return True
|
||||
|
||||
return super().is_cpp_container_type(cppdecl_spec)
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
from code_object.arg import Arg
|
||||
from code_object.declaration_specifier import DeclSpec
|
||||
import code_object_converter.supporting.conversion_data as conversion_data
|
||||
import code_object_converter.conversion_pack.conversion_data as conversion_data
|
||||
|
||||
# These will be used if no other supplied...
|
||||
common_funcbody_arg_mappings = {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
from code_object.data_member import DataMember
|
||||
from code_object.declaration_specifier import DeclSpec
|
||||
import code_object_converter.supporting.conversion_data as conversion_data
|
||||
import code_object_converter.conversion_pack.conversion_data as conversion_data
|
||||
|
||||
# Define base class member mapping
|
||||
grib_accessor_base_data_members_map = {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
|
||||
grib_bits_funcsig_mappings = [
|
||||
FuncSigMapping( FuncSig("void", "grib_set_bit_on", [Arg("unsigned char*", "p"), Arg("long*", "bitp")]),
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
|
||||
# Conversions for common Grib functions
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
|
||||
grib_query_funcsig_mappings = [
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
|
||||
grib_scaling_funcsig_mappings = [
|
||||
FuncSigMapping( FuncSig("T", "codes_power<T>", [Arg("long", "s"), Arg("long", "n")]),
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
|
||||
grib_value_funcsig_mappings = [
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
|
||||
string_util_funcsig_mappings = [
|
||||
FuncSigMapping( FuncSig("int", "string_to_long", [Arg("const char*", "input"), Arg("long*", "output"), Arg("int", "strict")]),
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
|
||||
grib_accessor_class_stub_funcsig_mappings = [
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
|
||||
grib_accessor_stub_funcsig_mappings = [
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
|
||||
grib_bits_any_endian_stub_funcsig_mappings = [
|
||||
FuncSigMapping( FuncSig("unsigned long", "grib_decode_unsigned_long", [Arg("const unsigned char*", "p"), Arg("long*", "p"), Arg("long", "nbits")]),
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
|
||||
grib_buffer_stub_funcsig_mappings = [
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
|
||||
grib_context_stub_funcsig_mappings = [
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
|
||||
grib_date_stub_funcsig_mappings = [
|
||||
FuncSigMapping( FuncSig("long", "grib_date_to_julian", [Arg("long", "ddate")]),
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
|
||||
grib_errors_stub_funcsig_mappings = [
|
||||
FuncSigMapping( FuncSig("const char*", "grib_get_error_message", [Arg("int", "code")]),
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
|
||||
# Conversions for common Grib functions
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
|
||||
grib_ieeefloat_stub_funcsig_mappings = [
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
|
||||
grib_optimize_decimal_factor_stub_funcsig_mappings = [
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
|
||||
grib_parse_utils_stub_funcsig_mappings = [
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
|
||||
grib_scaling_stub_funcsig_mappings = [
|
||||
FuncSigMapping( FuncSig("long", "grib_get_binary_scale_fact", [Arg("double", "max"), Arg("double", "min"), Arg("long", "bpval"), Arg("int*", "error")]),
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
|
||||
grib_util_stub_funcsig_mappings = [
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
from code_object.code_interface import NONE_VALUE
|
||||
|
||||
grib_value_stub_funcsig_mappings = [
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
|
||||
grib_accessor_header_includes = [
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
|
||||
# NOTE: The C FuncSig variable names may be different so should only be used as a guide (some are missing)
|
||||
grib_accessor_member_funcsig_mapping = [
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
from code_object.arg import Arg
|
||||
from code_object.declaration_specifier import DeclSpec
|
||||
import code_object_converter.supporting.conversion_data as conversion_data
|
||||
import code_object_converter.conversion_pack.conversion_data as conversion_data
|
||||
|
||||
common_grib_type_mappings = {
|
||||
"grib_accessor*" : "AccessorPtr",
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
from code_object_converter.supporting.funcsig_mapping import FuncSigMapping
|
||||
from code_object_converter.conversion_pack.funcsig_mapping import FuncSigMapping
|
||||
from code_object.funcsig import FuncSig
|
||||
from code_object.arg import Arg
|
||||
from code_object_converter.supporting.arg_indexes import ArgIndexes
|
||||
from code_object_converter.conversion_pack.arg_indexes import ArgIndexes
|
||||
|
||||
# NOTE: The C FuncSig variable names may be different so should only be used as a guide (some are missing)
|
||||
grib_accessor_virtual_member_funcsig_mapping = [
|
||||
|
|
Loading…
Reference in New Issue