}
};
-/// \brief The state of the coverage mapping builder.
-struct SourceMappingState {
- Counter CurrentRegionCount;
- const Stmt *CurrentSourceGroup;
- const Stmt *CurrentUnreachableRegionInitiator;
-
- SourceMappingState(Counter CurrentRegionCount, const Stmt *CurrentSourceGroup,
- const Stmt *CurrentUnreachableRegionInitiator)
- : CurrentRegionCount(CurrentRegionCount),
- CurrentSourceGroup(CurrentSourceGroup),
- CurrentUnreachableRegionInitiator(CurrentUnreachableRegionInitiator) {}
-};
-
/// \brief Provides the common functionality for the different
/// coverage mapping region builders.
class CoverageMappingBuilder {
Flags);
}
- void mapSourceCodeRange(const SourceMappingState &State,
- SourceLocation LocStart, SourceLocation LocEnd,
- unsigned Flags = 0) {
- mapSourceCodeRange(LocStart, LocEnd, State.CurrentRegionCount,
- State.CurrentUnreachableRegionInitiator,
- State.CurrentSourceGroup, Flags);
- }
-
/// \brief Generate the coverage counter mapping regions from collected
/// source regions.
void emitSourceRegions() {
Writer.write(OS);
}
- /// \brief Return the current source mapping state.
- SourceMappingState getCurrentState() const {
- return SourceMappingState(CurrentRegionCount, CurrentSourceGroup,
- CurrentUnreachableRegionInitiator);
- }
-
/// \brief Associate the source code range with the current region count.
void mapSourceCodeRange(SourceLocation LocStart, SourceLocation LocEnd,
unsigned Flags = 0) {
SourceMappingRegion::IgnoreIfNotExtended);
}
- void mapToken(const SourceMappingState &State, SourceLocation LocStart) {
- CoverageMappingBuilder::mapSourceCodeRange(
- State, LocStart, LocStart, SourceMappingRegion::IgnoreIfNotExtended);
- }
-
void VisitStmt(const Stmt *S) {
mapSourceCodeRange(S->getLocStart());
for (Stmt::const_child_range I = S->children(); I; ++I) {
}
void VisitCompoundStmt(const CompoundStmt *S) {
- SourceMappingState State = getCurrentState();
mapSourceCodeRange(S->getLBracLoc());
+ mapSourceCodeRange(S->getRBracLoc());
for (Stmt::const_child_range I = S->children(); I; ++I) {
if (*I)
this->Visit(*I);
}
- CoverageMappingBuilder::mapSourceCodeRange(State, S->getRBracLoc(),
- S->getRBracLoc());
}
void VisitReturnStmt(const ReturnStmt *S) {
void VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
Visit(E->getCond());
mapToken(E->getQuestionLoc());
- auto State = getCurrentState();
+ mapToken(E->getColonLoc());
// Counter tracks the "true" part of a conditional operator. The
// count in the "false" part will be calculated from this counter.
Visit(E->getTrueExpr());
Cnt.adjustForControlFlow();
- mapToken(State, E->getColonLoc());
-
Cnt.beginElseRegion();
Visit(E->getFalseExpr());
Cnt.adjustForControlFlow();