clang API Documentation
00001 //===- CXXFieldCollector.h - Utility class for C++ class semantic analysis ===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file provides CXXFieldCollector that is used during parsing & semantic 00011 // analysis of C++ classes. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_CLANG_SEMA_CXXFIELDCOLLECTOR_H 00016 #define LLVM_CLANG_SEMA_CXXFIELDCOLLECTOR_H 00017 00018 #include "llvm/ADT/SmallVector.h" 00019 00020 namespace clang { 00021 class FieldDecl; 00022 00023 /// CXXFieldCollector - Used to keep track of CXXFieldDecls during parsing of 00024 /// C++ classes. 00025 class CXXFieldCollector { 00026 /// Fields - Contains all FieldDecls collected during parsing of a C++ 00027 /// class. When a nested class is entered, its fields are appended to the 00028 /// fields of its parent class, when it is exited its fields are removed. 00029 SmallVector<FieldDecl*, 32> Fields; 00030 00031 /// FieldCount - Each entry represents the number of fields collected during 00032 /// the parsing of a C++ class. When a nested class is entered, a new field 00033 /// count is pushed, when it is exited, the field count is popped. 00034 SmallVector<size_t, 4> FieldCount; 00035 00036 // Example: 00037 // 00038 // class C { 00039 // int x,y; 00040 // class NC { 00041 // int q; 00042 // // At this point, Fields contains [x,y,q] decls and FieldCount contains 00043 // // [2,1]. 00044 // }; 00045 // int z; 00046 // // At this point, Fields contains [x,y,z] decls and FieldCount contains 00047 // // [3]. 00048 // }; 00049 00050 public: 00051 /// StartClass - Called by Sema::ActOnStartCXXClassDef. 00052 void StartClass() { FieldCount.push_back(0); } 00053 00054 /// Add - Called by Sema::ActOnCXXMemberDeclarator. 00055 void Add(FieldDecl *D) { 00056 Fields.push_back(D); 00057 ++FieldCount.back(); 00058 } 00059 00060 /// getCurNumField - The number of fields added to the currently parsed class. 00061 size_t getCurNumFields() const { 00062 assert(!FieldCount.empty() && "no currently-parsed class"); 00063 return FieldCount.back(); 00064 } 00065 00066 /// getCurFields - Pointer to array of fields added to the currently parsed 00067 /// class. 00068 FieldDecl **getCurFields() { return &*(Fields.end() - getCurNumFields()); } 00069 00070 /// FinishClass - Called by Sema::ActOnFinishCXXClassDef. 00071 void FinishClass() { 00072 Fields.resize(Fields.size() - getCurNumFields()); 00073 FieldCount.pop_back(); 00074 } 00075 }; 00076 00077 } // end namespace clang 00078 00079 #endif