Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:59

0001 //===- CXXFieldCollector.h - Utility class for C++ class semantic analysis ===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 //  This file provides CXXFieldCollector that is used during parsing & semantic
0010 //  analysis of C++ classes.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_CLANG_SEMA_CXXFIELDCOLLECTOR_H
0015 #define LLVM_CLANG_SEMA_CXXFIELDCOLLECTOR_H
0016 
0017 #include "clang/Basic/LLVM.h"
0018 #include "llvm/ADT/SmallVector.h"
0019 
0020 namespace clang {
0021   class FieldDecl;
0022 
0023 /// CXXFieldCollector - Used to keep track of CXXFieldDecls during parsing of
0024 /// C++ classes.
0025 class CXXFieldCollector {
0026   /// Fields - Contains all FieldDecls collected during parsing of a C++
0027   /// class. When a nested class is entered, its fields are appended to the
0028   /// fields of its parent class, when it is exited its fields are removed.
0029   SmallVector<FieldDecl*, 32> Fields;
0030 
0031   /// FieldCount - Each entry represents the number of fields collected during
0032   /// the parsing of a C++ class. When a nested class is entered, a new field
0033   /// count is pushed, when it is exited, the field count is popped.
0034   SmallVector<size_t, 4> FieldCount;
0035 
0036   // Example:
0037   //
0038   // class C {
0039   //   int x,y;
0040   //   class NC {
0041   //     int q;
0042   //     // At this point, Fields contains [x,y,q] decls and FieldCount contains
0043   //     // [2,1].
0044   //   };
0045   //   int z;
0046   //   // At this point, Fields contains [x,y,z] decls and FieldCount contains
0047   //   // [3].
0048   // };
0049 
0050 public:
0051   /// StartClass - Called by Sema::ActOnStartCXXClassDef.
0052   void StartClass() { FieldCount.push_back(0); }
0053 
0054   /// Add - Called by Sema::ActOnCXXMemberDeclarator.
0055   void Add(FieldDecl *D) {
0056     Fields.push_back(D);
0057     ++FieldCount.back();
0058   }
0059 
0060   /// getCurNumField - The number of fields added to the currently parsed class.
0061   size_t getCurNumFields() const {
0062     assert(!FieldCount.empty() && "no currently-parsed class");
0063     return FieldCount.back();
0064   }
0065 
0066   /// getCurFields - Pointer to array of fields added to the currently parsed
0067   /// class.
0068   FieldDecl **getCurFields() { return &*(Fields.end() - getCurNumFields()); }
0069 
0070   /// FinishClass - Called by Sema::ActOnFinishCXXClassDef.
0071   void FinishClass() {
0072     Fields.resize(Fields.size() - getCurNumFields());
0073     FieldCount.pop_back();
0074   }
0075 };
0076 
0077 } // end namespace clang
0078 
0079 #endif