Coverage Report

Created: 2019-07-24 05:18

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