 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
77.3% |
34 / 44 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
86.4% |
38 / 44 |
| |
|
Line Coverage: |
95.2% |
40 / 42 |
| |
 |
|
 |
1 : //===--- ParentMap.cpp - Mappings from Stmts to their Parents ---*- C++ -*-===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 : //
10 : // This file defines the ParentMap class.
11 : //
12 : //===----------------------------------------------------------------------===//
13 :
14 : #include "clang/AST/ParentMap.h"
15 : #include "clang/AST/Decl.h"
16 : #include "clang/AST/Expr.h"
17 : #include "llvm/ADT/DenseMap.h"
18 :
19 : using namespace clang;
20 :
21 : typedef llvm::DenseMap<Stmt*, Stmt*> MapTy;
22 :
23 12465: static void BuildParentMap(MapTy& M, Stmt* S) {
12033: branch 4 taken
12465: branch 5 taken
24 24498: for (Stmt::child_iterator I=S->child_begin(), E=S->child_end(); I!=E; ++I)
11699: branch 1 taken
334: branch 2 taken
25 12033: if (*I) {
26 11699: M[*I] = S;
27 11699: BuildParentMap(M, *I);
28 : }
29 12465: }
30 :
31 766: ParentMap::ParentMap(Stmt* S) : Impl(0) {
766: branch 0 taken
0: branch 1 not taken
0: branch 2 not taken
0: branch 3 not taken
32 766: if (S) {
33 766: MapTy *M = new MapTy();
34 766: BuildParentMap(*M, S);
35 766: Impl = M;
36 : }
37 766: }
38 :
39 766: ParentMap::~ParentMap() {
766: branch 0 taken
0: branch 1 not taken
766: branch 4 taken
766: branch 5 taken
40 766: delete (MapTy*) Impl;
41 766: }
42 :
43 14037: Stmt* ParentMap::getParent(Stmt* S) const {
44 14037: MapTy* M = (MapTy*) Impl;
45 14037: MapTy::iterator I = M->find(S);
2652: branch 3 taken
11385: branch 4 taken
46 14037: return I == M->end() ? 0 : I->second;
47 : }
48 :
49 4294: Stmt *ParentMap::getParentIgnoreParens(Stmt *S) const {
4259: branch 1 taken
35: branch 2 taken
52: branch 4 taken
4207: branch 5 taken
52: branch 6 taken
4242: branch 7 taken
50 4294: do { S = getParent(S); } while (S && isa<ParenExpr>(S));
51 4242: return S;
52 : }
53 :
54 2683: bool ParentMap::isConsumedExpr(Expr* E) const {
55 2683: Stmt *P = getParent(E);
56 2683: Stmt *DirectChild = E;
57 :
58 : // Ignore parents that are parentheses or casts.
3000: branch 0 taken
0: branch 1 not taken
2904: branch 3 taken
96: branch 4 taken
221: branch 6 taken
2683: branch 7 taken
317: branch 8 taken
2683: branch 9 taken
59 5683: while (P && (isa<ParenExpr>(P) || isa<CastExpr>(P))) {
60 317: DirectChild = P;
61 317: P = getParent(P);
62 : }
63 :
0: branch 0 not taken
2683: branch 1 taken
64 2683: if (!P)
65 0: return false;
66 :
1195: branch 1 taken
888: branch 2 taken
208: branch 3 taken
12: branch 4 taken
5: branch 5 taken
5: branch 6 taken
192: branch 7 taken
0: branch 8 not taken
2: branch 9 taken
176: branch 10 taken
67 2683: switch (P->getStmtClass()) {
68 : default:
69 1195: return isa<Expr>(P);
70 : case Stmt::DeclStmtClass:
71 888: return true;
72 : case Stmt::BinaryOperatorClass: {
73 208: BinaryOperator *BE = cast<BinaryOperator>(P);
74 : // If it is a comma, only the right side is consumed.
75 : // If it isn't a comma, both sides are consumed.
0: branch 1 not taken
208: branch 2 taken
0: branch 4 not taken
0: branch 5 not taken
76 208: return BE->getOpcode()!=BinaryOperator::Comma ||DirectChild==BE->getRHS();
77 : }
78 : case Stmt::ForStmtClass:
79 12: return DirectChild == cast<ForStmt>(P)->getCond();
80 : case Stmt::WhileStmtClass:
81 5: return DirectChild == cast<WhileStmt>(P)->getCond();
82 : case Stmt::DoStmtClass:
83 5: return DirectChild == cast<DoStmt>(P)->getCond();
84 : case Stmt::IfStmtClass:
85 192: return DirectChild == cast<IfStmt>(P)->getCond();
86 : case Stmt::IndirectGotoStmtClass:
87 0: return DirectChild == cast<IndirectGotoStmt>(P)->getTarget();
88 : case Stmt::SwitchStmtClass:
89 2: return DirectChild == cast<SwitchStmt>(P)->getCond();
90 : case Stmt::ReturnStmtClass:
91 176: return true;
92 : }
93 : }
94 :
Generated: 2010-02-10 01:31 by zcov