Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically Detect Template Types #191

Open
TheTripleV opened this issue Jan 1, 2023 · 4 comments
Open

Automatically Detect Template Types #191

TheTripleV opened this issue Jan 1, 2023 · 4 comments

Comments

@TheTripleV
Copy link
Member

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.

@TheTripleV
Copy link
Member Author

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.

@TheTripleV
Copy link
Member Author

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.

@TheTripleV
Copy link
Member Author

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:])

@virtuald
Copy link
Member

You probably should now be able to do this pretty easily with the data from cxxheaderparser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants