From d3b9065ec7052ec4741783d2fb4130d13c766933 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 15 Mar 2008 05:43:15 +0000 Subject: [PATCH] various minor cleanups. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48389 91177308-0d34-0410-b5e6-96231b3b80d8 --- AST/Decl.cpp | 175 +++++++++++++++++++-------------------------------- 1 file changed, 63 insertions(+), 112 deletions(-) diff --git a/AST/Decl.cpp b/AST/Decl.cpp index 05cd49021b..32ca4198f5 100644 --- a/AST/Decl.cpp +++ b/AST/Decl.cpp @@ -16,9 +16,12 @@ #include "clang/AST/Attr.h" #include "clang/Basic/IdentifierTable.h" #include "llvm/ADT/DenseMap.h" - using namespace clang; +//===----------------------------------------------------------------------===// +// Statistics +//===----------------------------------------------------------------------===// + // temporary statistics gathering static unsigned nFuncs = 0; static unsigned nBlockVars = 0; @@ -54,42 +57,28 @@ static DeclAttrMapTy *DeclAttrs = 0; const char *Decl::getDeclKindName() const { switch (DeclKind) { default: assert(0 && "Unknown decl kind!"); - case Typedef: - return "Typedef"; - case Function: - return "Function"; - case BlockVar: - return "BlockVar"; - case FileVar: - return "FileVar"; - case ParmVar: - return "ParmVar"; - case EnumConstant: - return "EnumConstant"; - case ObjCInterface: - return "ObjCInterface"; - case ObjCClass: - return "ObjCClass"; - case ObjCMethod: - return "ObjCMethod"; - case ObjCProtocol: - return "ObjCProtocol"; - case ObjCForwardProtocol: - return "ObjCForwardProtocol"; - case Struct: - return "Struct"; - case Union: - return "Union"; - case Class: - return "Class"; - case Enum: - return "Enum"; + case Typedef: return "Typedef"; + case Function: return "Function"; + case BlockVar: return "BlockVar"; + case FileVar: return "FileVar"; + case ParmVar: return "ParmVar"; + case EnumConstant: return "EnumConstant"; + case ObjCInterface: return "ObjCInterface"; + case ObjCClass: return "ObjCClass"; + case ObjCMethod: return "ObjCMethod"; + case ObjCProtocol: return "ObjCProtocol"; + case ObjCForwardProtocol: return "ObjCForwardProtocol"; + case Struct: return "Struct"; + case Union: return "Union"; + case Class: return "Class"; + case Enum: return "Enum"; } } -bool Decl::CollectingStats(bool enable) { - if (enable) StatSwitch = true; - return StatSwitch; +bool Decl::CollectingStats(bool Enable) { + if (Enable) + StatSwitch = true; + return StatSwitch; } void Decl::PrintStats() { @@ -184,79 +173,37 @@ void Decl::PrintStats() { } -void Decl::addDeclKind(const Kind k) { +void Decl::addDeclKind(Kind k) { switch (k) { - case Typedef: - nTypedef++; - break; - case Function: - nFuncs++; - break; - case BlockVar: - nBlockVars++; - break; - case FileVar: - nFileVars++; - break; - case ParmVar: - nParmVars++; - break; - case EnumConstant: - nEnumConst++; - break; - case Field: - nFieldDecls++; - break; - case Struct: - case Union: - case Class: - nSUC++; - break; - case Enum: - nEnumDecls++; - break; - case ObjCInterface: - nInterfaceDecls++; - break; - case ObjCClass: - nClassDecls++; - break; - case ObjCMethod: - nMethodDecls++; - break; - case ObjCProtocol: - nProtocolDecls++; - break; - case ObjCForwardProtocol: - nForwardProtocolDecls++; - break; - case ObjCCategory: - nCategoryDecls++; - break; - case ObjCIvar: - nIvarDecls++; - break; - case ObjCImplementation: - nObjCImplementationDecls++; - break; - case ObjCCategoryImpl: - nObjCCategoryImpl++; - break; - case CompatibleAlias: - nObjCCompatibleAlias++; - break; - case PropertyDecl: - nObjCPropertyDecl++; - break; - case LinkageSpec: - nLinkageSpecDecl++; - break; - case FileScopeAsm: - nFileScopeAsmDecl++; - break; + case Typedef: nTypedef++; break; + case Function: nFuncs++; break; + case BlockVar: nBlockVars++; break; + case FileVar: nFileVars++; break; + case ParmVar: nParmVars++; break; + case EnumConstant: nEnumConst++; break; + case Field: nFieldDecls++; break; + case Struct: case Union: case Class: nSUC++; break; + case Enum: nEnumDecls++; break; + case ObjCInterface: nInterfaceDecls++; break; + case ObjCClass: nClassDecls++; break; + case ObjCMethod: nMethodDecls++; break; + case ObjCProtocol: nProtocolDecls++; break; + case ObjCForwardProtocol: nForwardProtocolDecls++; break; + case ObjCCategory: nCategoryDecls++; break; + case ObjCIvar: nIvarDecls++; break; + case ObjCImplementation: nObjCImplementationDecls++; break; + case ObjCCategoryImpl: nObjCCategoryImpl++; break; + case CompatibleAlias: nObjCCompatibleAlias++; break; + case PropertyDecl: nObjCPropertyDecl++; break; + case LinkageSpec: nLinkageSpecDecl++; break; + case FileScopeAsm: nFileScopeAsmDecl++; break; } } +//===----------------------------------------------------------------------===// +// Decl Implementation +//===----------------------------------------------------------------------===// + // Out-of-line virtual method providing a home for Decl. Decl::~Decl() { if (!HasAttrs) @@ -273,21 +220,19 @@ Decl::~Decl() { } } -void Decl::addAttr(Attr *newattr) -{ +void Decl::addAttr(Attr *NewAttr) { if (!DeclAttrs) - DeclAttrs = new llvm::DenseMap; + DeclAttrs = new llvm::DenseMap(); - Attr *&attr = (*DeclAttrs)[this]; + Attr *&ExistingAttr = (*DeclAttrs)[this]; - newattr->setNext(attr); - attr = newattr; + NewAttr->setNext(ExistingAttr); + ExistingAttr = NewAttr; HasAttrs = true; } -const Attr *Decl::getAttrs() const -{ +const Attr *Decl::getAttrs() const { if (!HasAttrs) return 0; @@ -305,7 +250,8 @@ FunctionDecl::~FunctionDecl() { } unsigned FunctionDecl::getNumParams() const { - if (isa(getCanonicalType())) return 0; + if (isa(getCanonicalType())) + return 0; return cast(getCanonicalType())->getNumArgs(); } @@ -346,6 +292,11 @@ FieldDecl* RecordDecl::getMember(IdentifierInfo *name) { return 0; } + +//===----------------------------------------------------------------------===// +// Objective-C Decl Implementation +//===----------------------------------------------------------------------===// + void ObjCMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo, unsigned NumParams) { assert(ParamInfo == 0 && "Already has param info!"); -- 2.40.0