Skip to content

Commit 61c83e9

Browse files
committed
Revert "[clang-format][NFC] Make LangOpts global in namespace Format"
This reverts commit 32e65b0. It seems to break some PowerPC bots. See #81390 (comment).
1 parent 70ebc78 commit 61c83e9

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

clang/lib/Format/FormatTokenLexer.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
#include "FormatTokenLexer.h"
16-
#include "TokenAnalyzer.h"
16+
#include "FormatToken.h"
17+
#include "clang/Basic/SourceLocation.h"
18+
#include "clang/Basic/SourceManager.h"
19+
#include "clang/Format/Format.h"
20+
#include "llvm/Support/Regex.h"
1721

1822
namespace clang {
1923
namespace format {
@@ -24,12 +28,12 @@ FormatTokenLexer::FormatTokenLexer(
2428
llvm::SpecificBumpPtrAllocator<FormatToken> &Allocator,
2529
IdentifierTable &IdentTable)
2630
: FormatTok(nullptr), IsFirstToken(true), StateStack({LexerState::NORMAL}),
27-
Column(Column), TrailingWhitespace(0), SourceMgr(SourceMgr), ID(ID),
31+
Column(Column), TrailingWhitespace(0),
32+
LangOpts(getFormattingLangOpts(Style)), SourceMgr(SourceMgr), ID(ID),
2833
Style(Style), IdentTable(IdentTable), Keywords(IdentTable),
2934
Encoding(Encoding), Allocator(Allocator), FirstInLineIndex(0),
3035
FormattingDisabled(false), MacroBlockBeginRegex(Style.MacroBlockBegin),
3136
MacroBlockEndRegex(Style.MacroBlockEnd) {
32-
assert(LangOpts.CPlusPlus);
3337
Lex.reset(new Lexer(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts));
3438
Lex->SetKeepWhitespaceMode(true);
3539

@@ -1438,7 +1442,7 @@ void FormatTokenLexer::readRawToken(FormatToken &Tok) {
14381442

14391443
void FormatTokenLexer::resetLexer(unsigned Offset) {
14401444
StringRef Buffer = SourceMgr.getBufferData(ID);
1441-
assert(LangOpts.CPlusPlus);
1445+
LangOpts = getFormattingLangOpts(Style);
14421446
Lex.reset(new Lexer(SourceMgr.getLocForStartOfFile(ID), LangOpts,
14431447
Buffer.begin(), Buffer.begin() + Offset, Buffer.end()));
14441448
Lex->SetKeepWhitespaceMode(true);

clang/lib/Format/FormatTokenLexer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@
1717

1818
#include "Encoding.h"
1919
#include "FormatToken.h"
20+
#include "clang/Basic/LangOptions.h"
21+
#include "clang/Basic/SourceLocation.h"
22+
#include "clang/Basic/SourceManager.h"
23+
#include "clang/Format/Format.h"
2024
#include "llvm/ADT/MapVector.h"
2125
#include "llvm/ADT/SmallPtrSet.h"
2226
#include "llvm/ADT/StringSet.h"
27+
#include "llvm/Support/Regex.h"
2328

2429
#include <stack>
2530

@@ -115,6 +120,7 @@ class FormatTokenLexer {
115120
unsigned Column;
116121
unsigned TrailingWhitespace;
117122
std::unique_ptr<Lexer> Lex;
123+
LangOptions LangOpts;
118124
const SourceManager &SourceMgr;
119125
FileID ID;
120126
const FormatStyle &Style;

clang/lib/Format/IntegerLiteralSeparatorFixer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ IntegerLiteralSeparatorFixer::process(const Environment &Env,
7979
AffectedRangeManager AffectedRangeMgr(SourceMgr, Env.getCharRanges());
8080

8181
const auto ID = Env.getFileID();
82-
assert(LangOpts.CPlusPlus);
82+
const auto LangOpts = getFormattingLangOpts(Style);
8383
Lexer Lex(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts);
8484
Lex.SetCommentRetentionState(true);
8585

clang/lib/Format/TokenAnalyzer.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
namespace clang {
3636
namespace format {
3737

38-
LangOptions LangOpts;
39-
4038
// FIXME: Instead of printing the diagnostic we should store it and have a
4139
// better way to return errors through the format APIs.
4240
class FatalDiagnosticConsumer : public DiagnosticConsumer {
@@ -101,11 +99,9 @@ TokenAnalyzer::TokenAnalyzer(const Environment &Env, const FormatStyle &Style)
10199

102100
std::pair<tooling::Replacements, unsigned>
103101
TokenAnalyzer::process(bool SkipAnnotation) {
104-
LangOpts = getFormattingLangOpts(Style);
105-
106102
tooling::Replacements Result;
107103
llvm::SpecificBumpPtrAllocator<FormatToken> Allocator;
108-
IdentifierTable IdentTable(LangOpts);
104+
IdentifierTable IdentTable(getFormattingLangOpts(Style));
109105
FormatTokenLexer Lex(Env.getSourceManager(), Env.getFileID(),
110106
Env.getFirstStartColumn(), Style, Encoding, Allocator,
111107
IdentTable);

clang/lib/Format/TokenAnalyzer.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
namespace clang {
3535
namespace format {
3636

37-
extern LangOptions LangOpts;
38-
3937
class Environment {
4038
public:
4139
// This sets up an virtual file system with file \p FileName containing the

0 commit comments

Comments
 (0)