Skip to content

Remove clang-pseudo #109154

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

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion clang-tools-extra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ add_subdirectory(clang-move)
add_subdirectory(clang-query)
add_subdirectory(include-cleaner)
add_subdirectory(pp-trace)
add_subdirectory(pseudo)
add_subdirectory(tool-template)

option(CLANG_TOOLS_EXTRA_INCLUDE_DOCS "Generate build targets for the Clang Extra Tools docs."
Expand Down
1 change: 0 additions & 1 deletion clang-tools-extra/clangd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ target_link_libraries(clangDaemon
${LLVM_PTHREAD_LIB}

clangIncludeCleaner
clangPseudo
clangTidy
clangTidyUtils

Expand Down
32 changes: 16 additions & 16 deletions clang-tools-extra/clangd/SemanticSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#include "Protocol.h"
#include "Selection.h"
#include "SourceCode.h"
#include "clang-pseudo/Bracket.h"
#include "clang-pseudo/DirectiveTree.h"
#include "clang-pseudo/Token.h"
#include "clang/AST/DeclBase.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
Expand All @@ -25,6 +22,9 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Error.h"
#include "support/Bracket.h"
#include "support/DirectiveTree.h"
#include "support/Token.h"
#include <optional>
#include <queue>
#include <vector>
Expand Down Expand Up @@ -181,16 +181,16 @@ llvm::Expected<std::vector<FoldingRange>> getFoldingRanges(ParsedAST &AST) {
// Related issue: https://github.com/clangd/clangd/issues/310
llvm::Expected<std::vector<FoldingRange>>
getFoldingRanges(const std::string &Code, bool LineFoldingOnly) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we revert 70914aa instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have strong opinions one way or the other, but I figure the current approach retains the previous functionality and so is probably a reasonable way forward.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep it in this patch to avoid changing the current behavior of clangd.

auto OrigStream = pseudo::lex(Code, clang::pseudo::genericLangOpts());
auto OrigStream = lex(Code, genericLangOpts());

auto DirectiveStructure = pseudo::DirectiveTree::parse(OrigStream);
pseudo::chooseConditionalBranches(DirectiveStructure, OrigStream);
auto DirectiveStructure = DirectiveTree::parse(OrigStream);
chooseConditionalBranches(DirectiveStructure, OrigStream);

// FIXME: Provide ranges in the disabled-PP regions as well.
auto Preprocessed = DirectiveStructure.stripDirectives(OrigStream);

auto ParseableStream = cook(Preprocessed, clang::pseudo::genericLangOpts());
pseudo::pairBrackets(ParseableStream);
auto ParseableStream = cook(Preprocessed, genericLangOpts());
pairBrackets(ParseableStream);

std::vector<FoldingRange> Result;
auto AddFoldingRange = [&](Position Start, Position End,
Expand All @@ -205,19 +205,19 @@ getFoldingRanges(const std::string &Code, bool LineFoldingOnly) {
FR.kind = Kind.str();
Result.push_back(FR);
};
auto OriginalToken = [&](const pseudo::Token &T) {
auto OriginalToken = [&](const Token &T) {
return OrigStream.tokens()[T.OriginalIndex];
};
auto StartOffset = [&](const pseudo::Token &T) {
auto StartOffset = [&](const Token &T) {
return OriginalToken(T).text().data() - Code.data();
};
auto StartPosition = [&](const pseudo::Token &T) {
auto StartPosition = [&](const Token &T) {
return offsetToPosition(Code, StartOffset(T));
};
auto EndOffset = [&](const pseudo::Token &T) {
auto EndOffset = [&](const Token &T) {
return StartOffset(T) + OriginalToken(T).Length;
};
auto EndPosition = [&](const pseudo::Token &T) {
auto EndPosition = [&](const Token &T) {
return offsetToPosition(Code, EndOffset(T));
};
auto Tokens = ParseableStream.tokens();
Expand All @@ -235,7 +235,7 @@ getFoldingRanges(const std::string &Code, bool LineFoldingOnly) {
}
}
}
auto IsBlockComment = [&](const pseudo::Token &T) {
auto IsBlockComment = [&](const Token &T) {
assert(T.Kind == tok::comment);
return OriginalToken(T).Length >= 2 &&
Code.substr(StartOffset(T), 2) == "/*";
Expand All @@ -246,10 +246,10 @@ getFoldingRanges(const std::string &Code, bool LineFoldingOnly) {
T++;
continue;
}
pseudo::Token *FirstComment = T;
Token *FirstComment = T;
// Show starting sentinals (// and /*) of the comment.
Position Start = offsetToPosition(Code, 2 + StartOffset(*FirstComment));
pseudo::Token *LastComment = T;
Token *LastComment = T;
Position End = EndPosition(*T);
while (T != Tokens.end() && T->Kind == tok::comment &&
StartPosition(*T).line <= End.line + 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
//
//===----------------------------------------------------------------------===//

#include "clang-pseudo/Bracket.h"
#include "Bracket.h"

namespace clang {
namespace pseudo {
namespace clangd {
namespace {

struct Bracket {
Expand All @@ -83,7 +83,7 @@ struct Bracket {
// Find brackets in the stream and convert to Bracket struct.
std::vector<Bracket> findBrackets(const TokenStream &Stream) {
std::vector<Bracket> Brackets;
auto Add = [&](const pseudo::Token &Tok, Bracket::BracketKind K,
auto Add = [&](const Token &Tok, Bracket::BracketKind K,
Bracket::Direction D) {
Brackets.push_back(
{K, D, Tok.Line, Tok.Indent, Stream.index(Tok), Bracket::None});
Expand Down Expand Up @@ -151,5 +151,5 @@ void pairBrackets(TokenStream &Stream) {
applyPairings(Brackets, Stream);
}

} // namespace pseudo
} // namespace clangd
} // namespace clang
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
//
//===----------------------------------------------------------------------===//

#ifndef CLANG_PSEUDO_BRACKET_H
#define CLANG_PSEUDO_BRACKET_H
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_BRACKET_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_BRACKET_H

#include "clang-pseudo/Token.h"
#include "Token.h"

namespace clang {
namespace pseudo {
namespace clangd {

/// Identifies bracket token in the stream which should be paired.
/// Sets Token::Pair accordingly.
void pairBrackets(TokenStream &);

} // namespace pseudo
} // namespace clangd
} // namespace clang

#endif
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_BRACKET_H
4 changes: 4 additions & 0 deletions clang-tools-extra/clangd/support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB OR NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
endif()

add_clang_library(clangdSupport
Bracket.cpp
Cancellation.cpp
Context.cpp
DirectiveTree.cpp
FileCache.cpp
Lex.cpp
Logger.cpp
Markup.cpp
MemoryTree.cpp
Expand All @@ -27,6 +30,7 @@ add_clang_library(clangdSupport
ThreadCrashReporter.cpp
Threading.cpp
ThreadsafeFS.cpp
Token.cpp
Trace.cpp

LINK_LIBS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
//
//===----------------------------------------------------------------------===//

#include "clang-pseudo/DirectiveTree.h"
#include "DirectiveTree.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/TokenKinds.h"
#include "llvm/Support/FormatVariadic.h"
#include <optional>
#include <variant>

namespace clang {
namespace pseudo {
namespace clangd {
namespace {

class DirectiveParser {
Expand Down Expand Up @@ -353,5 +353,5 @@ TokenStream DirectiveTree::stripDirectives(const TokenStream &In) const {
return Out;
}

} // namespace pseudo
} // namespace clangd
} // namespace clang
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
//
//===----------------------------------------------------------------------===//

#ifndef CLANG_PSEUDO_DIRECTIVETREE_H
#define CLANG_PSEUDO_DIRECTIVETREE_H
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_DIRECTIVETREE_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_DIRECTIVETREE_H

#include "clang-pseudo/Token.h"
#include "Token.h"
#include "clang/Basic/TokenKinds.h"
#include <optional>
#include <variant>
#include <vector>

namespace clang {
namespace pseudo {
namespace clangd {

/// Describes the structure of a source file, as seen by the preprocessor.
///
Expand Down Expand Up @@ -124,7 +124,7 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &,
/// The choices are stored in Conditional::Taken nodes.
void chooseConditionalBranches(DirectiveTree &, const TokenStream &Code);

} // namespace pseudo
} // namespace clangd
} // namespace clang

#endif // CLANG_PSEUDO_DIRECTIVETREE_H
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_DIRECTIVETREE_H
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
//
//===----------------------------------------------------------------------===//

#include "clang-pseudo/Token.h"
#include "Token.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/TokenKinds.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/LiteralSupport.h"

namespace clang {
namespace pseudo {
namespace clangd {

TokenStream lex(const std::string &Code, const clang::LangOptions &LangOpts) {
clang::SourceLocation Start;
Expand Down Expand Up @@ -135,5 +135,5 @@ TokenStream cook(const TokenStream &Code, const LangOptions &LangOpts) {
return Result;
}

} // namespace pseudo
} // namespace clangd
} // namespace clang
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
//
//===----------------------------------------------------------------------===//

#include "clang-pseudo/Token.h"
#include "Token.h"
#include "clang/Basic/LangOptions.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/FormatVariadic.h"

namespace clang {
namespace pseudo {
namespace clangd {

llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Token &T) {
OS << llvm::formatv("{0} {1}:{2} ", clang::tok::getTokenName(T.Kind), T.Line,
Expand Down Expand Up @@ -126,5 +126,5 @@ TokenStream stripComments(const TokenStream &Input) {
return Out;
}

} // namespace pseudo
} // namespace clangd
} // namespace clang
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef CLANG_PSEUDO_TOKEN_H
#define CLANG_PSEUDO_TOKEN_H
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOKEN_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOKEN_H

#include "clang/Basic/LLVM.h"
#include "clang/Basic/LangStandard.h"
Expand All @@ -41,7 +41,7 @@

namespace clang {
class LangOptions;
namespace pseudo {
namespace clangd {

/// A single C++ or preprocessor token.
///
Expand Down Expand Up @@ -249,7 +249,7 @@ TokenStream cook(const TokenStream &, const clang::LangOptions &);
/// Drops comment tokens.
TokenStream stripComments(const TokenStream &);

} // namespace pseudo
} // namespace clangd
} // namespace clang

#endif // CLANG_PSEUDO_TOKEN_H
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOKEN_H
5 changes: 5 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ infrastructure are described first, followed by tool-specific sections.
Major New Features
------------------

- The ``clang-pseudo`` tool is incomplete and does not have active maintainers,
so it has been removed. See
`the RFC <https://discourse.llvm.org/t/removing-pseudo-parser/71131/>`_ for
more details.

...

Improvements to clangd
Expand Down
12 changes: 0 additions & 12 deletions clang-tools-extra/pseudo/CMakeLists.txt

This file was deleted.

Loading
Loading