[cfe-commits] r58892 - in /cfe/trunk/lib/CodeGen: CGDebugInfo.cpp CGDebugInfo.h
Daniel Dunbar
daniel at zuster.org
Fri Nov 7 22:12:46 PST 2008
Author: ddunbar
Date: Sat Nov 8 00:12:46 2008
New Revision: 58892
URL: http://llvm.org/viewvc/llvm-project?rev=58892&view=rev
Log:
Avoid redundant cast<>s / simplify type dispatch.
Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=58892&r1=58891&r2=58892&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Sat Nov 8 00:12:46 2008
@@ -214,14 +214,10 @@
/// getOrCreateBuiltinType - Get the Basic type from the cache or create a new
/// one if necessary.
llvm::TypeDesc *
-CGDebugInfo::getOrCreateBuiltinType(QualType type, llvm::CompileUnitDesc *Unit)
-{
- assert (type->getTypeClass() == Type::Builtin);
-
- const BuiltinType *BT = type->getAsBuiltinType();
-
+CGDebugInfo::getOrCreateBuiltinType(const BuiltinType *type,
+ llvm::CompileUnitDesc *Unit) {
unsigned Encoding = 0;
- switch (BT->getKind())
+ switch (type->getKind())
{
case BuiltinType::Void:
return NULL;
@@ -261,7 +257,7 @@
llvm::BasicTypeDesc *BTy = new llvm::BasicTypeDesc();
// Get the name and location early to assist debugging.
- const char *TyName = BT->getName();
+ const char *TyName = type->getName();
// Bit size, align and offset of the type.
uint64_t Size = M->getContext().getTypeSize(type);
@@ -282,15 +278,14 @@
}
llvm::TypeDesc *
-CGDebugInfo::getOrCreatePointerType(QualType type, llvm::CompileUnitDesc *Unit)
-{
+CGDebugInfo::getOrCreatePointerType(const PointerType *type,
+ llvm::CompileUnitDesc *Unit) {
// type*
llvm::DerivedTypeDesc *DTy =
new llvm::DerivedTypeDesc(llvm::dwarf::DW_TAG_pointer_type);
// Handle the derived type.
- const PointerType *PTRT = type->getAsPointerType();
- llvm::TypeDesc *FromTy = getOrCreateType(PTRT->getPointeeType(), Unit);
+ llvm::TypeDesc *FromTy = getOrCreateType(type->getPointeeType(), Unit);
// Get the name and location early to assist debugging.
SourceManager &SM = M->getContext().getSourceManager();
@@ -315,16 +310,15 @@
}
llvm::TypeDesc *
-CGDebugInfo::getOrCreateTypedefType(QualType type, llvm::CompileUnitDesc *Unit)
-{
+CGDebugInfo::getOrCreateTypedefType(const TypedefType *TDT,
+ llvm::CompileUnitDesc *Unit) {
// typedefs are derived from some other type.
llvm::DerivedTypeDesc *DTy =
new llvm::DerivedTypeDesc(llvm::dwarf::DW_TAG_typedef);
// Handle derived type.
- const TypedefType *TDT = type->getAsTypedefType();
llvm::TypeDesc *FromTy = getOrCreateType(TDT->LookThroughTypedefs(),
- Unit);
+ Unit);
// Get the name and location early to assist debugging.
const char *TyName = TDT->getDecl()->getName();
@@ -375,7 +369,7 @@
}
/// getOrCreateRecordType - get structure or union type.
-void CGDebugInfo::getOrCreateRecordType(QualType type,
+void CGDebugInfo::getOrCreateRecordType(const RecordType *type,
llvm::CompileUnitDesc *Unit,
llvm::TypeDesc *&Slot)
{
@@ -391,7 +385,7 @@
else
return;
- RecordDecl *RecDecl = type->getAsRecordType()->getDecl();
+ RecordDecl *RecDecl = type->getDecl();
// We can not get the type for forward declarations.
// FIXME: What *should* we be doing here?
if (!RecDecl->getDefinition(M->getContext()))
@@ -429,15 +423,12 @@
/// getOrCreateEnumType - get Enum type.
llvm::TypeDesc *
-CGDebugInfo::getOrCreateEnumType(QualType type, llvm::CompileUnitDesc *Unit)
-{
+CGDebugInfo::getOrCreateEnumType(const EnumType *type,
+ llvm::CompileUnitDesc *Unit) {
llvm::CompositeTypeDesc *EnumTy
= new llvm::CompositeTypeDesc(llvm::dwarf::DW_TAG_enumeration_type);
- EnumType *EType = dyn_cast<EnumType>(type);
- if (!EType) return(NULL);
-
- EnumDecl *EDecl = EType->getDecl();
+ EnumDecl *EDecl = type->getDecl();
SourceManager &SM = M->getContext().getSourceManager();
uint64_t Line = SM.getLogicalLineNumber(EDecl->getLocation());
@@ -481,8 +472,8 @@
/// getOrCreateArrayType - get or create array types.
llvm::TypeDesc *
-CGDebugInfo::getOrCreateArrayType(QualType type, llvm::CompileUnitDesc *Unit)
-{
+CGDebugInfo::getOrCreateArrayType(QualType type,
+ llvm::CompileUnitDesc *Unit) {
llvm::CompositeTypeDesc *ArrayTy
= new llvm::CompositeTypeDesc(llvm::dwarf::DW_TAG_array_type);
@@ -527,21 +518,19 @@
/// getOrCreateTaggedType - get or create structure/union/Enum type.
-void CGDebugInfo::getOrCreateTaggedType(QualType type,
+void CGDebugInfo::getOrCreateTagType(const TagType *type,
llvm::CompileUnitDesc *Unit,
- llvm::TypeDesc *&Slot)
-{
- if (type->isStructureType() || type->isUnionType())
- getOrCreateRecordType(type, Unit, Slot);
- else if (type->isEnumeralType())
- Slot = getOrCreateEnumType(type, Unit);
+ llvm::TypeDesc *&Slot) {
+ if (const RecordType *RT = dyn_cast<RecordType>(type))
+ getOrCreateRecordType(RT, Unit, Slot);
+ else if (const EnumType *ET = dyn_cast<EnumType>(type))
+ Slot = getOrCreateEnumType(ET, Unit);
}
/// getOrCreateType - Get the type from the cache or create a new
/// one if necessary.
llvm::TypeDesc *
-CGDebugInfo::getOrCreateType(QualType type, llvm::CompileUnitDesc *Unit)
-{
+CGDebugInfo::getOrCreateType(QualType type, llvm::CompileUnitDesc *Unit) {
if (type.isNull())
return NULL;
@@ -571,7 +560,7 @@
return NULL;
case Type::TypeName:
- Slot = getOrCreateTypedefType(type, Unit);
+ Slot = getOrCreateTypedefType(cast<TypedefType>(type), Unit);
break;
case Type::FunctionProto:
@@ -580,15 +569,15 @@
break;
case Type::Builtin:
- Slot = getOrCreateBuiltinType(type, Unit);
+ Slot = getOrCreateBuiltinType(cast<BuiltinType>(type), Unit);
break;
case Type::Pointer:
- Slot = getOrCreatePointerType(type, Unit);
+ Slot = getOrCreatePointerType(cast<PointerType>(type), Unit);
break;
case Type::Tagged:
- getOrCreateTaggedType(type, Unit, Slot);
+ getOrCreateTagType(cast<TagType>(type), Unit, Slot);
break;
case Type::ConstantArray:
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=58892&r1=58891&r2=58892&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Sat Nov 8 00:12:46 2008
@@ -79,20 +79,20 @@
/// Helper functions for getOrCreateType.
llvm::TypeDesc *getOrCreateCVRType(QualType type,
llvm::CompileUnitDesc *unit);
- llvm::TypeDesc *getOrCreateBuiltinType(QualType type,
+ llvm::TypeDesc *getOrCreateBuiltinType(const BuiltinType *type,
llvm::CompileUnitDesc *unit);
- llvm::TypeDesc *getOrCreateTypedefType(QualType type,
+ llvm::TypeDesc *getOrCreateTypedefType(const TypedefType *type,
llvm::CompileUnitDesc *unit);
- llvm::TypeDesc *getOrCreatePointerType(QualType type,
+ llvm::TypeDesc *getOrCreatePointerType(const PointerType *type,
llvm::CompileUnitDesc *unit);
llvm::TypeDesc *getOrCreateFunctionType(QualType type,
llvm::CompileUnitDesc *unit);
- void getOrCreateRecordType(QualType type,
+ void getOrCreateRecordType(const RecordType *type,
llvm::CompileUnitDesc *unit,
llvm::TypeDesc *&Slot);
- llvm::TypeDesc *getOrCreateEnumType(QualType type,
+ llvm::TypeDesc *getOrCreateEnumType(const EnumType *type,
llvm::CompileUnitDesc *unit);
- void getOrCreateTaggedType(QualType type,
+ void getOrCreateTagType(const TagType *type,
llvm::CompileUnitDesc *unit,
llvm::TypeDesc *&Slot);
llvm::TypeDesc *getOrCreateArrayType(QualType type,
More information about the cfe-commits
mailing list