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

Improve type safety #8

Open
vgvassilev opened this issue Mar 14, 2023 · 0 comments
Open

Improve type safety #8

vgvassilev opened this issue Mar 14, 2023 · 0 comments
Labels
good first issue Good for newcomers

Comments

@vgvassilev
Copy link

I don't think so. :) And there seems to be a real benefit there to prevent crashes.

struct ScopeCursor {
    void* fDecl;
};

Certain operations that can be performed on Decls and other on Types. We have interface GetScopeFromType and GetTypeFromScope if we need to convert but I'd prefer to have these explicit. This is more aligned to the underlying compiler API. I'd be happy if we had a special opaque entity for both. Eg:

    typedef ScopeCursor* CppScope_t;

    struct TypeCursor {
        void* fType;
        operator CppScope_t() { return GetScopeFromType(*this); }
    };

    typedef TypeCursor* CppType_t;

Here the compiler could enforce some checks if we try to call an interface with the unexpected parameter. We should look into better ways to strong typing as used here:
https://github.com/llvm/llvm-project/blob/4875e0670926b0a40ce0dd2c3d490b1866889f54/clang/include/clang-c/Index.h#L2243-L2247

Where the cursor can be classified to point to particular data type via an enum. Perhaps we could implement the former suggestion and extend it with the latter.

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

No branches or pull requests

1 participant