[llvm-dev] RFC: changing variable naming rules in LLVM codebase
David Greene via llvm-dev
llvm-dev at lists.llvm.org
Fri Jul 12 09:04:14 PDT 2019
Rui Ueyama via llvm-dev <llvm-dev at lists.llvm.org> writes:
> - LLVM's `/*foo=*/`-style comment to annotate function arguments need
> to be handled automatically to make the tool scalable. So is the
> doxygen @parameter.
This is a bit of a side note, but in my own work I've more recently
tried to move from this style:
foo.h
int foo(int a, bool doSomething);
foo.cpp
x = foo(a, /*doSomething=*/true);
y = foo(a, /*doSomething=*/false);
to something like:
foo.h
inline constexpr DoDoSomething = true;
inline constexpr DontDoSomething = false;
int foo(int a, bool doSomething);
foo.cpp
x = foo(a, DoDoSomething);
y = foo(a, DontDoSomething);
One doesn't need the inline variable (and thus not C++17) if one uses
macros or enums or something else less elegant.
This kind of thing is slightly more cumbersome to do if the parameter
takes a wide range of values, but the most common place I see the former
style is for Boolean arguments. Nevertheless, the wide-ranging case can
be handled:
bar.h
inline int Threshold(int x) { return x; }
int bar(int a, int threshold);
bar.cpp
x = bar(a, Threshold(1000));
y = bar(a, Threshold(100));
With either technique the "named values" could be wrapped in their own
namespaces to avoid collisions.
I wonder if there is any appetite for doing something similar in LLVM.
-David
More information about the llvm-dev
mailing list