summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/UnwrappedLineParser.h
diff options
context:
space:
mode:
authorFrancois Ferrand <thetypz@gmail.com>2017-07-28 07:56:14 +0000
committerFrancois Ferrand <thetypz@gmail.com>2017-07-28 07:56:14 +0000
commita98a95cca735b95cca5c904fa5ca875d916effc1 (patch)
tree0f392d9d1dd382895dd7ed0e6a236a8329a0bba8 /clang/lib/Format/UnwrappedLineParser.h
parent25271b91b237cde8f897b230aa366d38dd701f6c (diff)
downloadbcm5719-llvm-a98a95cca735b95cca5c904fa5ca875d916effc1.tar.gz
bcm5719-llvm-a98a95cca735b95cca5c904fa5ca875d916effc1.zip
clang-format: fix block OpeningLineIndex around preprocessor
Summary: The current code would return an incorrect value when a preprocessor directive is present immediately after the opening brace: this causes the nanespace end comment fixer to break in some places, for exemple it would not add the comment in this case: namespace a { #define FOO } Fixing the computation is simple enough, but it was breaking a feature, as it would cause comments to be added also when the namespace declaration was dependant on conditional compilation. To fix this, a hash of the current preprocessor stack/branches is computed at the beginning of parseBlock(), so that we explicitely do not store the OpeningLineIndex when the beginning and end of the block are not in the same preprocessor conditions. Tthe hash is computed based on the line, but this could propbably be improved by using the actual condition, so that clang-format would be able to match multiple identical #ifdef blocks. Reviewers: krasimir, djasper Reviewed By: krasimir Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D35483 llvm-svn: 309369
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.h')
-rw-r--r--clang/lib/Format/UnwrappedLineParser.h15
1 files changed, 13 insertions, 2 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.h b/clang/lib/Format/UnwrappedLineParser.h
index 5e1eef76619..47e41b3bb29 100644
--- a/clang/lib/Format/UnwrappedLineParser.h
+++ b/clang/lib/Format/UnwrappedLineParser.h
@@ -160,6 +160,11 @@ private:
bool isOnNewLine(const FormatToken &FormatTok);
+ // 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;
+
// 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.
@@ -178,7 +183,7 @@ private:
// Preprocessor directives are parsed out-of-order from other unwrapped lines.
// Thus, we need to keep a list of preprocessor directives to be reported
- // after an unwarpped line that has been started was finished.
+ // after an unwrapped line that has been started was finished.
SmallVector<UnwrappedLine, 4> PreprocessorDirectives;
// New unwrapped lines are added via CurrentLines.
@@ -211,8 +216,14 @@ private:
PP_Unreachable // #if 0 or a conditional preprocessor block inside #if 0
};
+ struct PPBranch {
+ PPBranch(PPBranchKind Kind, size_t Line) : Kind(Kind), Line(Line) {}
+ PPBranchKind Kind;
+ size_t Line;
+ };
+
// Keeps a stack of currently active preprocessor branching directives.
- SmallVector<PPBranchKind, 16> PPStack;
+ SmallVector<PPBranch, 16> PPStack;
// The \c UnwrappedLineParser re-parses the code for each combination
// of preprocessor branches that can be taken.
OpenPOWER on IntegriCloud