[PATCH] D25153: preprocessor supports `-dI` flag

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 5 15:53:38 PDT 2016


majnemer added inline comments.


> PrintPreprocessedOutput.cpp:331-349
> +  const size_t N = Path.size();
> +  size_t I = 0;
> +  while (I < N) {
> +    if (Path[I] == '\\' || Path[I] == '\"') {
> +      // Have to escape backslashes or double-quotes.
> +      // Send out backslash to escape the next char.
> +      Buffer.push_back('\\');

I think this loop would be easier to understand like so:

  while (!Path.empty()) {
    if (Path.consume_front("\\")) {
      Buffer.push_back("\\\\");
    } else if (Path.consume_front("\"")) {
      Buffer.push_back("\\\"");
    } else if (Path.consume_front("*/")) {
      Buffer.push_back("*\\/");
    } else {
      Buffer.push_back(Path.front());
      Path = Path.drop_front();
    }
  }

The big takeaway is that we now avoid messy `I + 1 < N` type checks.

https://reviews.llvm.org/D25153





More information about the cfe-commits mailing list