[PATCH] D83592: [Parser] Add comment to skipped regions
Zequan Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 13 11:52:22 PDT 2020
zequanwu updated this revision to Diff 277518.
zequanwu marked an inline comment as done.
zequanwu added a comment.
Herald added subscribers: kbarton, nemanjai.
Classfiying comments as `SkippedRegion`, https://github.com/llvm/llvm-project/blob/master/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L217
This will result overlapping `SkippedRegion` for comments and macro. Maybe, we shuold merge the overlapped `SkippedRegion` at the end.
Example:
File 0, 1:12 -> 6:2 = #0
Skipped,File 0, 2:3 -> 4:9 = 0
Skipped,File 0, 2:15 -> 2:25 = 0
1| 1|int main() {
2| | #ifdef TEST // comment
3| | int x = 1;
4| | #endif
5| 1| return 0;
6| 1|}
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D83592/new/
https://reviews.llvm.org/D83592
Files:
clang/include/clang/Lex/PPCallbacks.h
clang/lib/CodeGen/CoverageMappingGen.cpp
clang/lib/CodeGen/CoverageMappingGen.h
clang/lib/Parse/Parser.cpp
Index: clang/lib/Parse/Parser.cpp
===================================================================
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -34,6 +34,7 @@
explicit ActionCommentHandler(Sema &S) : S(S) { }
bool HandleComment(Preprocessor &PP, SourceRange Comment) override {
+ PP.getPPCallbacks()->CommentSkipped(Comment);
S.ActOnComment(Comment);
return false;
}
Index: clang/lib/CodeGen/CoverageMappingGen.h
===================================================================
--- clang/lib/CodeGen/CoverageMappingGen.h
+++ clang/lib/CodeGen/CoverageMappingGen.h
@@ -38,6 +38,8 @@
ArrayRef<SourceRange> getSkippedRanges() const { return SkippedRanges; }
void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) override;
+
+ void CommentSkipped(SourceRange Range) override;
};
namespace CodeGen {
Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===================================================================
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -39,6 +39,10 @@
SkippedRanges.push_back(Range);
}
+void CoverageSourceInfo::CommentSkipped(SourceRange Range) {
+ SkippedRanges.push_back(Range);
+}
+
namespace {
/// A region of source code that can be mapped to a counter.
Index: clang/include/clang/Lex/PPCallbacks.h
===================================================================
--- clang/include/clang/Lex/PPCallbacks.h
+++ clang/include/clang/Lex/PPCallbacks.h
@@ -319,6 +319,10 @@
virtual void SourceRangeSkipped(SourceRange Range, SourceLocation EndifLoc) {
}
+ /// Hood called when the source range is comment, which should be skipped.
+ /// \param Range The SourceRange that is comment.
+ virtual void CommentSkipped(SourceRange Range) {}
+
enum ConditionValueKind {
CVK_NotEvaluated, CVK_False, CVK_True
};
@@ -565,6 +569,11 @@
Second->SourceRangeSkipped(Range, EndifLoc);
}
+ void CommentSkipped(SourceRange Range) override {
+ First->CommentSkipped(Range);
+ Second->CommentSkipped(Range);
+ }
+
/// Hook called whenever an \#if is seen.
void If(SourceLocation Loc, SourceRange ConditionRange,
ConditionValueKind ConditionValue) override {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83592.277518.patch
Type: text/x-patch
Size: 2256 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200713/4c7e8c98/attachment.bin>
More information about the cfe-commits
mailing list