robotpy-build
robotpy-build copied to clipboard
Automatically Detect Template Types
When headers are scanned, the types used in a template should be cached. This can be used automatically fill in the template_params in create-gen.
For example (ctre pro),
CoreTalonFX.hpp
has a function StatusSignalValue<units::angle::turn_t> &GetPosition();
From this, we know that StatusSignalValue
needs a units::angle::turn_t
template param.
Then, SignalStatusValue.hpp
has a function SignalMeasurement<T> GetDataCopy() const {...}
From this, we can propogate all of SignalStatusValue
's template_params including units::angle::turn_t
to SignalMeasurement
.
This would require all headers to be scanned before yaml files are written.
Also, it would be nice to be able to scan additional headers to look for template usages. For example, in the case of WPILib, I could pass in the path to all wpilib examples and tests. These headers could be scanned purely to look for template params.
Took a stab at this. The biggest issue is getting the correct qualname for each type and I don't think that info is available.
For the future:
def extract_templated_types(atype: str):
match = re.fullmatch(r"(.*?)<(.*)>", atype)
if match:
template_type = match.group(1)
template_params = match.group(2)
yield (template_type.strip(), template_params.strip())
start = 0
in_angle_brackets = False
for i, c in enumerate(template_params):
if c == '<':
in_angle_brackets = True
elif c == '>':
in_angle_brackets = False
elif c == ',' and not in_angle_brackets:
yield from extract_templated_types(template_params[start:i])
start = i + 1
yield from extract_templated_types(template_params[start:])
You probably should now be able to do this pretty easily with the data from cxxheaderparser.