Coverage Report

Created: 2018-11-16 02:38

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Sema/CXXFieldCollector.h
Line
Count
Source
1
//===- CXXFieldCollector.h - Utility class for C++ class semantic analysis ===//
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 provides CXXFieldCollector that is used during parsing & semantic
11
//  analysis of C++ classes.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_CLANG_SEMA_CXXFIELDCOLLECTOR_H
16
#define LLVM_CLANG_SEMA_CXXFIELDCOLLECTOR_H
17
18
#include "clang/Basic/LLVM.h"
19
#include "llvm/ADT/SmallVector.h"
20
21
namespace clang {
22
  class FieldDecl;
23
24
/// CXXFieldCollector - Used to keep track of CXXFieldDecls during parsing of
25
/// C++ classes.
26
class CXXFieldCollector {
27
  /// Fields - Contains all FieldDecls collected during parsing of a C++
28
  /// class. When a nested class is entered, its fields are appended to the
29
  /// fields of its parent class, when it is exited its fields are removed.
30
  SmallVector<FieldDecl*, 32> Fields;
31
32
  /// FieldCount - Each entry represents the number of fields collected during
33
  /// the parsing of a C++ class. When a nested class is entered, a new field
34
  /// count is pushed, when it is exited, the field count is popped.
35
  SmallVector<size_t, 4> FieldCount;
36
37
  // Example:
38
  //
39
  // class C {
40
  //   int x,y;
41
  //   class NC {
42
  //     int q;
43
  //     // At this point, Fields contains [x,y,q] decls and FieldCount contains
44
  //     // [2,1].
45
  //   };
46
  //   int z;
47
  //   // At this point, Fields contains [x,y,z] decls and FieldCount contains
48
  //   // [3].
49
  // };
50
51
public:
52
  /// StartClass - Called by Sema::ActOnStartCXXClassDef.
53
797k
  void StartClass() { FieldCount.push_back(0); }
54
55
  /// Add - Called by Sema::ActOnCXXMemberDeclarator.
56
1.43M
  void Add(FieldDecl *D) {
57
1.43M
    Fields.push_back(D);
58
1.43M
    ++FieldCount.back();
59
1.43M
  }
60
61
  /// getCurNumField - The number of fields added to the currently parsed class.
62
2.39M
  size_t getCurNumFields() const {
63
2.39M
    assert(!FieldCount.empty() && "no currently-parsed class");
64
2.39M
    return FieldCount.back();
65
2.39M
  }
66
67
  /// getCurFields - Pointer to array of fields added to the currently parsed
68
  /// class.
69
797k
  FieldDecl **getCurFields() { return &*(Fields.end() - getCurNumFields()); }
70
71
  /// FinishClass - Called by Sema::ActOnFinishCXXClassDef.
72
797k
  void FinishClass() {
73
797k
    Fields.resize(Fields.size() - getCurNumFields());
74
797k
    FieldCount.pop_back();
75
797k
  }
76
};
77
78
} // end namespace clang
79
80
#endif