1 //===- CXXFieldCollector.h - Utility class for C++ class semantic analysis ===//
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
7 //===----------------------------------------------------------------------===//
9 // This file provides CXXFieldCollector that is used during parsing & semantic
10 // analysis of C++ classes.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_SEMA_CXXFIELDCOLLECTOR_H
15 #define LLVM_CLANG_SEMA_CXXFIELDCOLLECTOR_H
17 #include "clang/Basic/LLVM.h"
18 #include "llvm/ADT/SmallVector.h"
23 /// CXXFieldCollector - Used to keep track of CXXFieldDecls during parsing of
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;
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;
42 // // At this point, Fields contains [x,y,q] decls and FieldCount contains
46 // // At this point, Fields contains [x,y,z] decls and FieldCount contains
51 /// StartClass - Called by Sema::ActOnStartCXXClassDef.
52 void StartClass() { FieldCount.push_back(0); }
54 /// Add - Called by Sema::ActOnCXXMemberDeclarator.
55 void Add(FieldDecl *D) {
60 /// getCurNumField - The number of fields added to the currently parsed class.
61 size_t getCurNumFields() const {
62 assert(!FieldCount.empty() && "no currently-parsed class");
63 return FieldCount.back();
66 /// getCurFields - Pointer to array of fields added to the currently parsed
68 FieldDecl **getCurFields() { return &*(Fields.end() - getCurNumFields()); }
70 /// FinishClass - Called by Sema::ActOnFinishCXXClassDef.
72 Fields.resize(Fields.size() - getCurNumFields());
73 FieldCount.pop_back();
77 } // end namespace clang