Parser automatically parses missing super classes

This commit is contained in:
kevstone 2023-11-14 09:38:38 +00:00
parent 9c81f5e407
commit 7775c203b9
10 changed files with 135 additions and 4 deletions

View File

@ -35,8 +35,8 @@ grib_accessor_class_count_total.cc
grib_accessor_class_data_apply_bitmap.cc
#grib_accessor_class_data_apply_boustrophedonic.cc
grib_accessor_class_data_apply_boustrophedonic_bitmap.cc
grib_accessor_class_data_ccsds_packing.cc
grib_accessor_class_data_complex_packing.cc
#grib_accessor_class_data_ccsds_packing.cc
#grib_accessor_class_data_complex_packing.cc
grib_accessor_class_data_dummy_field.cc
grib_accessor_class_data_g1complex_packing.cc
grib_accessor_class_data_g1second_order_constant_width_packing.cc

View File

@ -2,9 +2,11 @@ from accessor_specific.default import AccessorSpecific
from converter_collection import Converter
import private_method_funcsig_conv
import static_func_funcsig_conv
from funcsig import FuncSig
from arg_indexes import ArgIndexes
from arg import Arg
import arg
from funcsig_mapping import FuncSigMapping
class DataComplexPackingDataFuncSigConverter(private_method_funcsig_conv.PrivateMethodFuncSigConverter):
@ -19,10 +21,27 @@ class DataComplexPackingDataFuncSigConverter(private_method_funcsig_conv.Private
super().__init__(cfuncsig)
self._conversions.extend(self.func_conversions)
class DataComplexPackingDataStaticFunctionSigConverter(static_func_funcsig_conv.StaticFunctionFuncSigConverter):
func_conversions = [
FuncSigMapping(FuncSig("double", "calculate_pfactor", [Arg("const grib_context*", "a"), Arg("const double*", "spectralField"), Arg("long", "fieldTruncation"), Arg("long", "subsetTruncation")]),
FuncSig("double", "calculatePfactor", [None, Arg("std::vector<double>", "spectralField"), Arg("long", "fieldTruncation"), Arg("long", "subsetTruncation")])),
]
def __init__(self, cfuncsig):
super().__init__(cfuncsig)
self._conversions.extend(self.func_conversions)
class DataComplexPackingDataAccessorSpecific(AccessorSpecific):
def __init__(self) -> None:
super().__init__()
self._custom_arg_transforms = {
arg.Arg("unsigned char*","buf") : arg.Arg("AccessorDataPointer","buf"),
arg.Arg("unsigned char*","hres") : arg.Arg("AccessorDataPointer","hres"),
arg.Arg("unsigned char*","lres") : arg.Arg("AccessorDataPointer","lres"),
}
def update_converters(self, converters):
converters[Converter.PRIVATE_METHOD_FUNCSIG] = DataComplexPackingDataFuncSigConverter
converters[Converter.STATIC_FUNC_FUNCSIG] = DataComplexPackingDataStaticFunctionSigConverter
return converters

View File

@ -289,6 +289,28 @@ def convert_grib_accessors():
if gribAccessorInst is not None:
grib_accessors[gribAccessorInst._name] = gribAccessorInst
# Parse any super classes not listed
LOG.info("Looking for missing super classes...")
grib_accessor_supers = {}
for name, gribAccessor in grib_accessors.items():
gribAccessorInst = gribAccessor
super_name = gribAccessorInst._super
while super_name != "grib_accessor_class_gen":
if super_name in grib_accessors.keys() or super_name in grib_accessor_supers.keys():
break
else:
LOG.info("Found super class %s of class %s", super_name, gribAccessorInst._name)
gribAccessorInst = parse_file(super_name+".cc")
if gribAccessorInst is not None:
grib_accessor_supers[gribAccessorInst._name] = gribAccessorInst
super_name = gribAccessorInst._super
LOG.info("Number of missing super classes parsed: %d", len(grib_accessor_supers))
grib_accessors.update(grib_accessor_supers)
for gribAccessorInst in grib_accessors.values():
converter = GribAccessorConverter(gribAccessorInst)
accessorDataImpl = converter.to_accessor_data(grib_accessors)
@ -296,7 +318,7 @@ def convert_grib_accessors():
write_header_file(accessorDataImpl)
write_source_file(accessorDataImpl)
write_makefile(accessor_name_list)
write_makefile(sorted(accessor_name_list))
def main():
convert_grib_accessors()

View File

@ -1357,7 +1357,7 @@ class FunctionConverter:
# Split comma-separated variable definitions into separate lines
# We then call ourself recursively for each split line
m = re.match(r"^(\s*[\w\*]+\s*)\s\*?\w+\s*[^,\(\{]*,", line)
m = re.match(r"^(\s*[\w]+\s*)[\s\*]+\w+\s*[^,\(\{]*,", line)
if m:
debug.line("update_cpp_body", f"--------------------------------------------------------------------------------")
debug.line("update_cpp_body", f"comma-separated vars [before]: {line}")

View File

@ -9,6 +9,7 @@ import funcsig_conversions.grib_stub_funcsig_conversions.grib_expression_stub_fu
import funcsig_conversions.grib_stub_funcsig_conversions.grib_parse_utils_stub_funcsig_conv as grib_parse_utils_stub_funcsig_conv
import funcsig_conversions.grib_stub_funcsig_conversions.grib_context_stub_funcsig_conv as grib_context_stub_funcsig_conv
import funcsig_conversions.grib_stub_funcsig_conversions.grib_value_stub_funcsig_conv as grib_value_stub_funcsig_conv
import funcsig_conversions.grib_stub_funcsig_conversions.grib_ieeefloat_stub_funcsig_conv as grib_ieeefloat_stub_funcsig_conv
grib_stub_funcsig_conversions = [
grib_accessor_class_stub_funcsig_conv.grib_accessor_class_stub_funcsig_conversions,
@ -21,6 +22,7 @@ grib_stub_funcsig_conversions = [
grib_parse_utils_stub_funcsig_conv.grib_parse_utils_stub_funcsig_conversions,
grib_context_stub_funcsig_conv.grib_context_stub_funcsig_conversions,
grib_value_stub_funcsig_conv.grib_value_stub_funcsig_conversions,
grib_ieeefloat_stub_funcsig_conv.grib_ieeefloat_stub_funcsig_conversions,
]
# Return a list of all the funcsig conversions

View File

@ -0,0 +1,20 @@
from funcsig import FuncSig
from arg_indexes import ArgIndexes
from arg import Arg
from funcsig_mapping import FuncSigMapping
grib_ieeefloat_stub_funcsig_conversions = [
FuncSigMapping( FuncSig("int", "grib_ieee_decode_array<T>", [Arg("grib_context*", "c"), Arg("unsigned char*", "buf"), Arg("size_t", "nvals"), Arg("int", "bytes"), Arg("T*", "val")]),
FuncSig("GribStatus", "gribIeeeDecodeArray", [None, Arg("AccessorDataPointer", "buf"), Arg("size_t", "nvals"), Arg("int", "bytes"), Arg("std::vector<T>", "val")])),
FuncSigMapping( FuncSig("int", "grib_ieee_encode_array", [Arg("grib_context*", "c"), Arg("double*", "val"), Arg("size_t", "nvals"), Arg("int", "bytes"), Arg("unsigned char*", "buf")]),
FuncSig("GribStatus", "gribGetDoubleElement", [None, Arg("std::vector<double>&", "val"), Arg("size_t", "nvals"), Arg("int", "bytes"), Arg("AccessorDataPointer", "buf")])),
FuncSigMapping( FuncSig("unsigned long", "grib_ieee_to_long", [Arg("double", "x")]),
FuncSig("unsigned long", "gribIeeeToLong", [Arg("double", "x")])),
FuncSigMapping( FuncSig("unsigned long", "grib_ieee64_to_long", [Arg("double", "x")]),
FuncSig("unsigned long", "gribIeee64ToLong", [Arg("double", "x")])),
]

View File

@ -86,6 +86,8 @@ set(accessor_grib_stub_src_files
${accessor_grib_stub_dir}/GribDateStub.h
${accessor_grib_stub_dir}/GribExpressionStub.cc
${accessor_grib_stub_dir}/GribExpressionStub.h
${accessor_grib_stub_dir}/GribIeeefloatStub.cc
${accessor_grib_stub_dir}/GribIeeefloatStub.h
${accessor_grib_stub_dir}/GribUtilStub.cc
${accessor_grib_stub_dir}/GribUtilStub.h
${accessor_grib_stub_dir}/GribParseUtilsStub.cc

View File

@ -0,0 +1,40 @@
#include "GribIeeefloatStub.h"
#include <cassert>
namespace eccodes::accessor {
template <>
GribStatus gribIeeeDecodeArray<float>(AccessorDataPointer buf, size_t nvals, int bytes, std::vector<float> val)
{
assert(false);
return GribStatus::NOT_IMPLEMENTED;
}
template <>
GribStatus gribIeeeDecodeArray<double>(AccessorDataPointer buf, size_t nvals, int bytes, std::vector<double> val)
{
assert(false);
return GribStatus::NOT_IMPLEMENTED;
}
GribStatus gribIeeeEncodeArray(std::vector<double>& val, size_t nvals, int bytes, AccessorDataPointer buf)
{
assert(false);
return GribStatus::NOT_IMPLEMENTED;
}
unsigned long gribIeeeToLong(double x)
{
assert(false);
return 0;
}
unsigned long gribIeee64ToLong(double x)
{
assert(false);
return 0;
}
}

View File

@ -0,0 +1,25 @@
#pragma once
// Utils to help convert the accessor C code to C++
#include "AccessorDefs.h"
#include "AccessorBuffer.h"
#include "GribCpp/GribStatus.h"
#include <string>
#include <vector>
namespace eccodes::accessor
{
//template <typename T> int grib_ieee_decode_array(grib_context* c, unsigned char* buf, size_t nvals, int bytes, T* val);
template <typename T>
GribStatus gribIeeeDecodeArray(AccessorDataPointer buf, size_t nvals, int bytes, std::vector<T> val);
//int grib_ieee_encode_array(grib_context* c, double* val, size_t nvals, int bytes, unsigned char* buf);
GribStatus gribIeeeEncodeArray(std::vector<double>& val, size_t nvals, int bytes, AccessorDataPointer buf);
//unsigned long grib_ieee_to_long(double x);
unsigned long gribIeeeToLong(double x);
//unsigned long grib_ieee64_to_long(double x);
unsigned long gribIeee64ToLong(double x);
}

View File

@ -11,6 +11,7 @@
#include "GribContextStub.h"
#include "GribDateStub.h"
#include "GribExpressionStub.h"
#include "GribIeeefloatStub.h"
#include "GribUtilStub.h"
#include "GribParseUtilsStub.h"
#include "GribValueStub.h"