2012-12-04 17:13:33 +08:00
|
|
|
//===--- UnwrappedLineParser.h - Format C++ code ----------------*- C++ -*-===//
|
2012-12-04 02:12:45 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-12-04 02:12:45 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
2018-05-09 09:00:01 +08:00
|
|
|
/// This file contains the declaration of the UnwrappedLineParser,
|
2012-12-04 02:12:45 +08:00
|
|
|
/// which turns a stream of tokens into UnwrappedLines.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEPARSER_H
|
|
|
|
#define LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEPARSER_H
|
2012-12-04 02:12:45 +08:00
|
|
|
|
2014-01-07 19:51:46 +08:00
|
|
|
#include "FormatToken.h"
|
2012-12-04 02:12:45 +08:00
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
2012-12-07 02:03:27 +08:00
|
|
|
#include "clang/Format/Format.h"
|
2017-02-02 23:32:19 +08:00
|
|
|
#include "llvm/Support/Regex.h"
|
2013-01-16 17:10:19 +08:00
|
|
|
#include <list>
|
2014-10-30 06:49:58 +08:00
|
|
|
#include <stack>
|
2013-01-08 22:56:18 +08:00
|
|
|
|
2012-12-04 02:12:45 +08:00
|
|
|
namespace clang {
|
|
|
|
namespace format {
|
|
|
|
|
2013-09-05 17:29:45 +08:00
|
|
|
struct UnwrappedLineNode;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// An unwrapped line is a sequence of \c Token, that we would like to
|
2012-12-04 02:12:45 +08:00
|
|
|
/// put on a single line if there was no column limit.
|
|
|
|
///
|
|
|
|
/// This is used as a main interface between the \c UnwrappedLineParser and the
|
|
|
|
/// \c UnwrappedLineFormatter. The key property is that changing the formatting
|
|
|
|
/// within an unwrapped line does not affect any other unwrapped lines.
|
|
|
|
struct UnwrappedLine {
|
2013-09-06 02:28:53 +08:00
|
|
|
UnwrappedLine();
|
2012-12-04 02:12:45 +08:00
|
|
|
|
2013-01-16 18:41:46 +08:00
|
|
|
// FIXME: Don't use std::list here.
|
2018-05-09 09:00:01 +08:00
|
|
|
/// The \c Tokens comprising this \c UnwrappedLine.
|
2013-09-05 17:29:45 +08:00
|
|
|
std::list<UnwrappedLineNode> Tokens;
|
2012-12-04 02:12:45 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// The indent level of the \c UnwrappedLine.
|
2012-12-04 02:12:45 +08:00
|
|
|
unsigned Level;
|
2013-01-03 00:30:12 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Whether this \c UnwrappedLine is part of a preprocessor directive.
|
2013-01-03 00:30:12 +08:00
|
|
|
bool InPPDirective;
|
2013-01-23 17:32:48 +08:00
|
|
|
|
|
|
|
bool MustBeDeclaration;
|
2017-02-27 21:28:36 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// If this \c UnwrappedLine closes a block in a sequence of lines,
|
2017-02-27 21:28:36 +08:00
|
|
|
/// \c MatchingOpeningBlockLineIndex stores the index of the corresponding
|
|
|
|
/// opening line. Otherwise, \c MatchingOpeningBlockLineIndex must be
|
|
|
|
/// \c kInvalidIndex.
|
2018-04-23 17:34:26 +08:00
|
|
|
size_t MatchingOpeningBlockLineIndex = kInvalidIndex;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// If this \c UnwrappedLine opens a block, stores the index of the
|
2018-04-23 17:34:26 +08:00
|
|
|
/// line with the corresponding closing brace.
|
|
|
|
size_t MatchingClosingBlockLineIndex = kInvalidIndex;
|
2017-02-27 21:28:36 +08:00
|
|
|
|
|
|
|
static const size_t kInvalidIndex = -1;
|
2017-10-30 22:01:50 +08:00
|
|
|
|
|
|
|
unsigned FirstStartColumn = 0;
|
2012-12-04 02:12:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class UnwrappedLineConsumer {
|
|
|
|
public:
|
2015-10-20 21:23:58 +08:00
|
|
|
virtual ~UnwrappedLineConsumer() {}
|
2012-12-05 21:56:52 +08:00
|
|
|
virtual void consumeUnwrappedLine(const UnwrappedLine &Line) = 0;
|
2013-10-12 05:25:45 +08:00
|
|
|
virtual void finishRun() = 0;
|
2012-12-04 02:12:45 +08:00
|
|
|
};
|
|
|
|
|
2013-05-28 19:55:06 +08:00
|
|
|
class FormatTokenSource;
|
2012-12-08 00:15:44 +08:00
|
|
|
|
2012-12-04 02:12:45 +08:00
|
|
|
class UnwrappedLineParser {
|
|
|
|
public:
|
2014-11-04 20:41:02 +08:00
|
|
|
UnwrappedLineParser(const FormatStyle &Style,
|
|
|
|
const AdditionalKeywords &Keywords,
|
2019-03-01 17:09:54 +08:00
|
|
|
unsigned FirstStartColumn, ArrayRef<FormatToken *> Tokens,
|
2012-12-04 02:12:45 +08:00
|
|
|
UnwrappedLineConsumer &Callback);
|
|
|
|
|
2015-05-06 19:56:29 +08:00
|
|
|
void parse();
|
2012-12-04 02:12:45 +08:00
|
|
|
|
|
|
|
private:
|
2013-10-12 05:25:45 +08:00
|
|
|
void reset();
|
2013-04-12 22:13:36 +08:00
|
|
|
void parseFile();
|
|
|
|
void parseLevel(bool HasOpeningBrace);
|
2013-10-13 06:46:56 +08:00
|
|
|
void parseBlock(bool MustBeDeclaration, bool AddLevel = true,
|
|
|
|
bool MunchSemi = true);
|
2013-09-04 21:25:30 +08:00
|
|
|
void parseChildBlock();
|
2012-12-04 02:12:45 +08:00
|
|
|
void parsePPDirective();
|
2013-01-05 07:34:14 +08:00
|
|
|
void parsePPDefine();
|
2013-10-12 05:25:45 +08:00
|
|
|
void parsePPIf(bool IfDef);
|
2013-05-25 02:24:24 +08:00
|
|
|
void parsePPElIf();
|
|
|
|
void parsePPElse();
|
|
|
|
void parsePPEndIf();
|
2013-01-05 07:34:14 +08:00
|
|
|
void parsePPUnknown();
|
2016-03-15 03:21:36 +08:00
|
|
|
void readTokenWithJavaScriptASI();
|
2013-01-07 22:56:16 +08:00
|
|
|
void parseStructuralElement();
|
2015-05-18 22:49:19 +08:00
|
|
|
bool tryToParseBracedList();
|
2017-06-27 21:43:07 +08:00
|
|
|
bool parseBracedList(bool ContinueOnSemicolons = false,
|
|
|
|
tok::TokenKind ClosingBraceKind = tok::r_brace);
|
2012-12-04 02:12:45 +08:00
|
|
|
void parseParens();
|
2017-09-19 17:59:30 +08:00
|
|
|
void parseSquare(bool LambdaIntroducer = false);
|
2012-12-04 02:12:45 +08:00
|
|
|
void parseIfThenElse();
|
2014-05-08 19:58:24 +08:00
|
|
|
void parseTryCatch();
|
2012-12-05 23:06:06 +08:00
|
|
|
void parseForOrWhileLoop();
|
2012-12-04 02:12:45 +08:00
|
|
|
void parseDoWhile();
|
|
|
|
void parseLabel();
|
|
|
|
void parseCaseLabel();
|
|
|
|
void parseSwitch();
|
2012-12-07 02:03:27 +08:00
|
|
|
void parseNamespace();
|
2015-03-12 22:44:29 +08:00
|
|
|
void parseNew();
|
2012-12-04 02:12:45 +08:00
|
|
|
void parseAccessSpecifier();
|
2015-12-29 16:54:23 +08:00
|
|
|
bool parseEnum();
|
2014-11-13 23:56:28 +08:00
|
|
|
void parseJavaEnumBody();
|
2017-02-07 22:05:30 +08:00
|
|
|
// Parses a record (aka class) as a top level element. If ParseAsExpr is true,
|
|
|
|
// parses the record as a child block, i.e. if the class declaration is an
|
|
|
|
// expression.
|
|
|
|
void parseRecord(bool ParseAsExpr = false);
|
[clang-format/ObjC] Correctly parse Objective-C methods with 'class' in name
Summary:
Please take a close look at this CL. I haven't touched much of
`UnwrappedLineParser` before, so I may have gotten things wrong.
Previously, clang-format would incorrectly format the following:
```
@implementation Foo
- (Class)class {
}
- (void)foo {
}
@end
```
as:
```
@implementation Foo
- (Class)class {
}
- (void)foo {
}
@end
```
The problem is whenever `UnwrappedLineParser::parseStructuralElement()`
sees any of the keywords `class`, `struct`, or `enum`, it calls
`parseRecord()` to parse them as a C/C++ record.
This causes subsequent lines to be parsed incorrectly, which
causes them to be indented incorrectly.
In Objective-C/Objective-C++, these keywords are valid selector
components.
This diff fixes the issue by explicitly handling `+` and `-` lines
inside `@implementation` / `@interface` / `@protocol` blocks
and parsing them as Objective-C methods.
Test Plan: New tests added. Ran tests with:
make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests
Reviewers: jolesiak, klimek
Reviewed By: jolesiak, klimek
Subscribers: klimek, cfe-commits, Wizard
Differential Revision: https://reviews.llvm.org/D47095
llvm-svn: 333553
2018-05-30 23:21:38 +08:00
|
|
|
void parseObjCMethod();
|
2013-01-10 05:15:03 +08:00
|
|
|
void parseObjCProtocolList();
|
|
|
|
void parseObjCUntilAtEnd();
|
2013-01-10 07:25:37 +08:00
|
|
|
void parseObjCInterfaceOrImplementation();
|
2018-01-24 01:10:25 +08:00
|
|
|
bool parseObjCProtocol();
|
2015-02-20 00:14:18 +08:00
|
|
|
void parseJavaScriptEs6ImportExport();
|
clang-format: better handle statement macros
Summary:
Some macros are used in the body of function, and actually contain the trailing semicolon: they should thus be automatically followed by a new line, and not get merged with the next line. This is for example the case with Qt's Q_UNUSED macro:
void foo(int a, int b) {
Q_UNUSED(a)
return b;
}
This patch deals with these cases by introducing a new option to specify list of statement macros. This re-uses the system already in place for foreach macros, to ensure there is no impact on performance.
Reviewers: krasimir, djasper, klimek
Reviewed By: krasimir
Subscribers: acoomans, mgrang, alexfh, klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D33440
llvm-svn: 343602
2018-10-03 00:37:51 +08:00
|
|
|
void parseStatementMacro();
|
2013-12-23 15:29:06 +08:00
|
|
|
bool tryToParseLambda();
|
2013-09-03 23:10:01 +08:00
|
|
|
bool tryToParseLambdaIntroducer();
|
2014-05-08 17:25:39 +08:00
|
|
|
void tryToParseJSFunction();
|
2012-12-04 02:12:45 +08:00
|
|
|
void addUnwrappedLine();
|
|
|
|
bool eof() const;
|
2017-07-24 22:51:59 +08:00
|
|
|
// LevelDifference is the difference of levels after and before the current
|
|
|
|
// token. For example:
|
|
|
|
// - if the token is '{' and opens a block, LevelDifference is 1.
|
|
|
|
// - if the token is '}' and closes a block, LevelDifference is -1.
|
|
|
|
void nextToken(int LevelDifference = 0);
|
|
|
|
void readToken(int LevelDifference = 0);
|
2017-02-08 18:30:44 +08:00
|
|
|
|
|
|
|
// Decides which comment tokens should be added to the current line and which
|
|
|
|
// should be added as comments before the next token.
|
|
|
|
//
|
|
|
|
// Comments specifies the sequence of comment tokens to analyze. They get
|
|
|
|
// either pushed to the current line or added to the comments before the next
|
|
|
|
// token.
|
|
|
|
//
|
|
|
|
// NextTok specifies the next token. A null pointer NextTok is supported, and
|
2018-04-06 23:14:32 +08:00
|
|
|
// signifies either the absence of a next token, or that the next token
|
2017-02-08 18:30:44 +08:00
|
|
|
// shouldn't be taken into accunt for the analysis.
|
|
|
|
void distributeComments(const SmallVectorImpl<FormatToken *> &Comments,
|
|
|
|
const FormatToken *NextTok);
|
|
|
|
|
|
|
|
// Adds the comment preceding the next token to unwrapped lines.
|
2013-01-23 00:31:55 +08:00
|
|
|
void flushComments(bool NewlineBeforeNext);
|
2013-05-28 19:55:06 +08:00
|
|
|
void pushToken(FormatToken *Tok);
|
2015-05-18 22:49:19 +08:00
|
|
|
void calculateBraceTypes(bool ExpectClassBody = false);
|
2014-04-14 17:14:11 +08:00
|
|
|
|
|
|
|
// Marks a conditional compilation edge (for example, an '#if', '#ifdef',
|
|
|
|
// '#else' or merge conflict marker). If 'Unreachable' is true, assumes
|
|
|
|
// this branch either cannot be taken (for example '#if false'), or should
|
|
|
|
// not be taken in this round.
|
|
|
|
void conditionalCompilationCondition(bool Unreachable);
|
|
|
|
void conditionalCompilationStart(bool Unreachable);
|
|
|
|
void conditionalCompilationAlternative();
|
|
|
|
void conditionalCompilationEnd();
|
|
|
|
|
2014-05-09 21:11:16 +08:00
|
|
|
bool isOnNewLine(const FormatToken &FormatTok);
|
2013-05-23 17:41:43 +08:00
|
|
|
|
2017-07-28 15:56:14 +08:00
|
|
|
// Compute hash of the current preprocessor branch.
|
|
|
|
// This is used to identify the different branches, and thus track if block
|
|
|
|
// open and close in the same branch.
|
|
|
|
size_t computePPHash() const;
|
|
|
|
|
2013-01-06 06:14:16 +08:00
|
|
|
// FIXME: We are constantly running into bugs where Line.Level is incorrectly
|
|
|
|
// subtracted from beyond 0. Introduce a method to subtract from Line.Level
|
|
|
|
// and use that everywhere in the Parser.
|
2014-03-08 04:03:18 +08:00
|
|
|
std::unique_ptr<UnwrappedLine> Line;
|
2013-01-23 00:31:55 +08:00
|
|
|
|
|
|
|
// Comments are sorted into unwrapped lines by whether they are in the same
|
|
|
|
// line as the previous token, or not. If not, they belong to the next token.
|
|
|
|
// Since the next token might already be in a new unwrapped line, we need to
|
|
|
|
// store the comments belonging to that token.
|
2013-05-28 19:55:06 +08:00
|
|
|
SmallVector<FormatToken *, 1> CommentsBeforeNextToken;
|
|
|
|
FormatToken *FormatTok;
|
2013-01-09 23:25:02 +08:00
|
|
|
bool MustBreakBeforeNextToken;
|
2012-12-04 02:12:45 +08:00
|
|
|
|
2013-01-19 02:24:28 +08:00
|
|
|
// The parsed lines. Only added to through \c CurrentLines.
|
2013-09-05 17:29:45 +08:00
|
|
|
SmallVector<UnwrappedLine, 8> Lines;
|
2013-01-18 22:04:34 +08:00
|
|
|
|
|
|
|
// Preprocessor directives are parsed out-of-order from other unwrapped lines.
|
|
|
|
// Thus, we need to keep a list of preprocessor directives to be reported
|
2017-07-28 15:56:14 +08:00
|
|
|
// after an unwrapped line that has been started was finished.
|
2013-09-05 17:29:45 +08:00
|
|
|
SmallVector<UnwrappedLine, 4> PreprocessorDirectives;
|
2013-01-18 22:04:34 +08:00
|
|
|
|
|
|
|
// New unwrapped lines are added via CurrentLines.
|
|
|
|
// Usually points to \c &Lines. While parsing a preprocessor directive when
|
|
|
|
// there is an unfinished previous unwrapped line, will point to
|
|
|
|
// \c &PreprocessorDirectives.
|
2013-09-05 17:29:45 +08:00
|
|
|
SmallVectorImpl<UnwrappedLine> *CurrentLines;
|
2013-01-18 22:04:34 +08:00
|
|
|
|
2013-01-23 17:32:48 +08:00
|
|
|
// We store for each line whether it must be a declaration depending on
|
|
|
|
// whether we are in a compound statement or not.
|
|
|
|
std::vector<bool> DeclarationScopeStack;
|
|
|
|
|
2012-12-07 02:03:27 +08:00
|
|
|
const FormatStyle &Style;
|
2014-11-04 20:41:02 +08:00
|
|
|
const AdditionalKeywords &Keywords;
|
2017-02-07 22:05:30 +08:00
|
|
|
|
2017-02-02 23:32:19 +08:00
|
|
|
llvm::Regex CommentPragmasRegex;
|
2014-11-04 20:41:02 +08:00
|
|
|
|
2013-01-05 07:34:14 +08:00
|
|
|
FormatTokenSource *Tokens;
|
2012-12-04 02:12:45 +08:00
|
|
|
UnwrappedLineConsumer &Callback;
|
2013-01-10 19:52:21 +08:00
|
|
|
|
2013-05-23 17:41:43 +08:00
|
|
|
// FIXME: This is a temporary measure until we have reworked the ownership
|
|
|
|
// of the format tokens. The goal is to have the actual tokens created and
|
|
|
|
// owned outside of and handed into the UnwrappedLineParser.
|
2013-05-28 19:55:06 +08:00
|
|
|
ArrayRef<FormatToken *> AllTokens;
|
2013-05-23 17:41:43 +08:00
|
|
|
|
2013-05-25 02:24:24 +08:00
|
|
|
// Represents preprocessor branch type, so we can find matching
|
|
|
|
// #if/#else/#endif directives.
|
|
|
|
enum PPBranchKind {
|
2013-07-08 22:34:09 +08:00
|
|
|
PP_Conditional, // Any #if, #ifdef, #ifndef, #elif, block outside #if 0
|
|
|
|
PP_Unreachable // #if 0 or a conditional preprocessor block inside #if 0
|
2013-05-25 02:24:24 +08:00
|
|
|
};
|
|
|
|
|
2017-07-28 15:56:14 +08:00
|
|
|
struct PPBranch {
|
|
|
|
PPBranch(PPBranchKind Kind, size_t Line) : Kind(Kind), Line(Line) {}
|
|
|
|
PPBranchKind Kind;
|
|
|
|
size_t Line;
|
|
|
|
};
|
|
|
|
|
2013-05-25 02:24:24 +08:00
|
|
|
// Keeps a stack of currently active preprocessor branching directives.
|
2017-07-28 15:56:14 +08:00
|
|
|
SmallVector<PPBranch, 16> PPStack;
|
2013-05-25 02:24:24 +08:00
|
|
|
|
2013-10-12 05:25:45 +08:00
|
|
|
// The \c UnwrappedLineParser re-parses the code for each combination
|
|
|
|
// of preprocessor branches that can be taken.
|
|
|
|
// To that end, we take the same branch (#if, #else, or one of the #elif
|
|
|
|
// branches) for each nesting level of preprocessor branches.
|
|
|
|
// \c PPBranchLevel stores the current nesting level of preprocessor
|
|
|
|
// branches during one pass over the code.
|
|
|
|
int PPBranchLevel;
|
|
|
|
|
|
|
|
// Contains the current branch (#if, #else or one of the #elif branches)
|
|
|
|
// for each nesting level.
|
|
|
|
SmallVector<int, 8> PPLevelBranchIndex;
|
|
|
|
|
|
|
|
// Contains the maximum number of branches at each nesting level.
|
|
|
|
SmallVector<int, 8> PPLevelBranchCount;
|
|
|
|
|
|
|
|
// Contains the number of branches per nesting level we are currently
|
|
|
|
// in while parsing a preprocessor branch sequence.
|
|
|
|
// This is used to update PPLevelBranchCount at the end of a branch
|
|
|
|
// sequence.
|
|
|
|
std::stack<int> PPChainBranchIndex;
|
|
|
|
|
2018-02-05 23:59:00 +08:00
|
|
|
// Include guard search state. Used to fixup preprocessor indent levels
|
|
|
|
// so that include guards do not participate in indentation.
|
|
|
|
enum IncludeGuardState {
|
|
|
|
IG_Inited, // Search started, looking for #ifndef.
|
|
|
|
IG_IfNdefed, // #ifndef found, IncludeGuardToken points to condition.
|
|
|
|
IG_Defined, // Matching #define found, checking other requirements.
|
|
|
|
IG_Found, // All requirements met, need to fix indents.
|
|
|
|
IG_Rejected, // Search failed or never started.
|
|
|
|
};
|
|
|
|
|
|
|
|
// Current state of include guard search.
|
|
|
|
IncludeGuardState IncludeGuard;
|
|
|
|
|
|
|
|
// Points to the #ifndef condition for a potential include guard. Null unless
|
|
|
|
// IncludeGuardState == IG_IfNdefed.
|
|
|
|
FormatToken *IncludeGuardToken;
|
|
|
|
|
2017-10-30 22:01:50 +08:00
|
|
|
// Contains the first start column where the source begins. This is zero for
|
|
|
|
// normal source code and may be nonzero when formatting a code fragment that
|
|
|
|
// does not start at the beginning of the file.
|
|
|
|
unsigned FirstStartColumn;
|
clang-format: Add preprocessor directive indentation
Summary:
This is an implementation for [bug 17362](https://bugs.llvm.org/attachment.cgi?bugid=17362) which adds support for indenting preprocessor statements inside if/ifdef/endif. This takes previous work from fmauch (https://github.com/fmauch/clang/tree/preprocessor_indent) and makes it into a full feature.
The context of this patch is that I'm a VMware intern, and I implemented this because VMware needs the feature. As such, some decisions were made based on what VMware wants, and I would appreciate suggestions on expanding this if necessary to use-cases other people may want.
This adds a new enum config option, `IndentPPDirectives`. Values are:
* `PPDIS_None` (in config: `None`):
```
#if FOO
#if BAR
#include <foo>
#endif
#endif
```
* `PPDIS_AfterHash` (in config: `AfterHash`):
```
#if FOO
# if BAR
# include <foo>
# endif
#endif
```
This is meant to work whether spaces or tabs are used for indentation. Preprocessor indentation is independent of indentation for non-preprocessor lines.
Preprocessor indentation also attempts to ignore include guards with the checks:
1. Include guards cover the entire file
2. Include guards don't have `#else`
3. Include guards begin with
```
#ifndef <var>
#define <var>
```
This patch allows `UnwrappedLineParser::PPBranchLevel` to be decremented to -1 (the initial value is -1) so the variable can be used for indent tracking.
Defects:
* This patch does not handle the case where there's code between the `#ifndef` and `#define` but all other conditions hold. This is because when the #define line is parsed, `UnwrappedLineParser::Lines` doesn't hold the previous code line yet, so we can't detect it. This is out of the scope of this patch.
* This patch does not handle cases where legitimate lines may be outside an include guard. Examples are `#pragma once` and `#pragma GCC diagnostic`, or anything else that does not change the meaning of the file if it's included multiple times.
* This does not detect when there is a single non-preprocessor line in front of an include-guard-like structure where other conditions hold because `ScopedLineState` hides the line.
* Preprocessor indentation throws off `TokenAnnotator::setCommentLineLevels` so the indentation of comments immediately before indented preprocessor lines is toggled on each run. Fixing this issue appears to be a major change and too much complexity for this patch.
Contributed by @euhlmann!
Reviewers: djasper, klimek, krasimir
Reviewed By: djasper, krasimir
Subscribers: krasimir, mzeren-vmw, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D35955
llvm-svn: 312125
2017-08-30 22:34:57 +08:00
|
|
|
|
2013-01-10 19:52:21 +08:00
|
|
|
friend class ScopedLineState;
|
2013-12-12 17:49:52 +08:00
|
|
|
friend class CompoundStatementIndenter;
|
2012-12-04 02:12:45 +08:00
|
|
|
};
|
|
|
|
|
2013-09-05 17:29:45 +08:00
|
|
|
struct UnwrappedLineNode {
|
2014-05-09 16:15:10 +08:00
|
|
|
UnwrappedLineNode() : Tok(nullptr) {}
|
2013-09-05 17:29:45 +08:00
|
|
|
UnwrappedLineNode(FormatToken *Tok) : Tok(Tok) {}
|
|
|
|
|
|
|
|
FormatToken *Tok;
|
|
|
|
SmallVector<UnwrappedLine, 0> Children;
|
|
|
|
};
|
|
|
|
|
2017-09-20 17:51:03 +08:00
|
|
|
inline UnwrappedLine::UnwrappedLine()
|
|
|
|
: Level(0), InPPDirective(false), MustBeDeclaration(false),
|
|
|
|
MatchingOpeningBlockLineIndex(kInvalidIndex) {}
|
2013-09-06 02:28:53 +08:00
|
|
|
|
2013-01-07 21:26:07 +08:00
|
|
|
} // end namespace format
|
|
|
|
} // end namespace clang
|
2012-12-04 02:12:45 +08:00
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#endif
|