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

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 3 22:23:24 PDT 2016


majnemer added inline comments.


> PrintPreprocessedOutput.cpp:321
> + */
> +std::string sanitizePath(const StringRef& path) {
> +  std::string str(path.size() * 2, '\0');

Don't pass `StringRef` by const reference, just pass it by value.

> PrintPreprocessedOutput.cpp:321-325
> +std::string sanitizePath(const StringRef& path) {
> +  std::string str(path.size() * 2, '\0');
> +  size_t len = 0;
> +  for (size_t i = 0; i < path.size(); i++) {
> +    const char c = path[i];

Variables should start with uppercase characters.

> PrintPreprocessedOutput.cpp:344
> + */
> +bool tryGetTokenText(std::string* text, const Token &tok) {
> +  if (tok.getKind() == clang::tok::identifier) {

This could be a StringRef instead of a std::string.

> PrintPreprocessedOutput.cpp:346
> +  if (tok.getKind() == clang::tok::identifier) {
> +    const auto* idInfo = tok.getIdentifierInfo();
> +    if (idInfo && idInfo->getNameStart() != nullptr) {

Pointers lean right.

> PrintPreprocessedOutput.cpp:348
> +    if (idInfo && idInfo->getNameStart() != nullptr) {
> +      *text = std::string(idInfo->getNameStart(), idInfo->getLength());
> +      return true;

Why not just use `getName` ?

https://reviews.llvm.org/D25153





More information about the cfe-commits mailing list