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

[IDEA] const-qualify tool #22

Open
SamuelMarks opened this issue Oct 9, 2021 · 2 comments
Open

[IDEA] const-qualify tool #22

SamuelMarks opened this issue Oct 9, 2021 · 2 comments

Comments

@SamuelMarks
Copy link
Contributor

SamuelMarks commented Oct 9, 2021

I want to work on a const qualify tool… concentrating on C with C++ as an afterthought (so don't want to get caught up on the constexpr, const ref, and const method conditions).

Whenever I go to a new codebase I'm [usually] annoyed at the lack of care taken to differentiate changing (var) names and unchanging (val/binding-only) names. Probably all those functional languages rubbing off on me!

I'd expect this to aid in compiler optimisations also…

So what I'm thinking is to use libclang and/or libtooling to modify code automatically from:

int f(int n) {
    int a = 5, b = 6, c;
    puts("nop");
    c = b;
    return n;
}

To:

const int f(const int n) {
    const int a = 5, b = 6;
    int c;
    puts("nop");
    c = b;
    return n;
}

…and get it to work nicely on enums, structs, objects (instantiations of classes and structs), functions, globals, and { scoped bodies (e.g., function bodies).

On the surface I'm not thinking this would be particularly difficult… at least for the majority of cases.

What do you think? - I don't have much experience here so happy to write it myself but could use some oversight 😅
(happy to release under CC0 to be compliant with your philosophy)

Thanks for your consideration

EDIT: Oh and I was watching this CppCon talk from a guy who made some progress in this direction: https://www.youtube.com/watch?v=tUBUqJSGr54

@banach-space
Copy link
Owner

Probably all those functional languages rubbing off on me!

haha, I knew!

On the surface I'm not thinking this would be particularly difficult… at least for the majority of cases.

The devil with these things is often in the details. Once you start testing the corner cases :) But if you ignore C++ ... it sounds doable!

EDIT: Oh and I was watching this CppCon talk from a guy who made some progress in this direction: https://www.youtube.com/watch?v=tUBUqJSGr54

Yeah, you could try re-implementing it? It would be a great example for clang-tutor.

@SamuelMarks
Copy link
Contributor Author

Sure happy to give it a go. I'm using CC0 to be compliant with your project, even though (Apache-2.0 OR MIT) is my goto.

Yeah C++ is full of weird edge cases and extended syntax and semantics that I'd like to ignore. Not to say this tool shouldn't run on C++ codebases, but just that if I could ignore its fancier features and do the bare minimum to get it working on C++ then I'd be happy.

Will go over that video with a fine-toothed comb, maybe even contacting the speaker, and port it to LLVM 13 in a monorepo… focussing on just the features I care about (but maybe doing his const ref stuff if he just shares the code along).

I think I'll do #23 first since that's heavy on my mind and will allow me to give a large LoC PR to a few open-source projects I have my eye on.

Watch this space!

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