s/Method/Function

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2034 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2002-03-29 03:44:36 +00:00
parent 6056c49ca0
commit 6bfd6a578a
9 changed files with 61 additions and 58 deletions

View File

@ -138,7 +138,7 @@ public:
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const FunctionType *T) { return true; }
static inline bool classof(const Type *T) {
return T->getPrimitiveID() == MethodTyID;
return T->getPrimitiveID() == FunctionTyID;
}
static inline bool classof(const Value *V) {
return isa<Type>(V) && classof(cast<const Type>(V));

View File

@ -47,11 +47,11 @@ HANDLE_PRIM_TYPE(Label , 8)
// Type Name: This is the symbolic name of the type, without the trailing Ty.
// Class Name: This is the subclass that implements the derived type.
//
HANDLE_DERV_TYPE(Method , MethodType)
HANDLE_DERV_TYPE(Array , ArrayType)
HANDLE_DERV_TYPE(Pointer, PointerType)
HANDLE_DERV_TYPE(Struct , StructType)
HANDLE_DERV_TYPE(Opaque , OpaqueType)
HANDLE_DERV_TYPE(Function, FunctionType)
HANDLE_DERV_TYPE(Array , ArrayType)
HANDLE_DERV_TYPE(Pointer , PointerType)
HANDLE_DERV_TYPE(Struct , StructType)
HANDLE_DERV_TYPE(Opaque , OpaqueType)
// Kill the macros on exit...
#undef HANDLE_PRIM_TYPE

View File

@ -30,7 +30,7 @@
#include "Support/GraphTraits.h"
class DerivedType;
class MethodType;
class FunctionType;
class ArrayType;
class PointerType;
class StructType;
@ -58,14 +58,14 @@ public:
// Derived types... see DerivedTypes.h file...
// Make sure FirstDerivedTyID stays up to date!!!
MethodTyID , StructTyID, // Methods... Structs...
FunctionTyID , StructTyID, // Functions... Structs...
ArrayTyID , PointerTyID, // Array... pointer...
OpaqueTyID, // Opaque type instances...
//PackedTyID , // SIMD 'packed' format... TODO
//...
NumPrimitiveIDs, // Must remain as last defined ID
FirstDerivedTyID = MethodTyID,
FirstDerivedTyID = FunctionTyID,
};
private:
@ -151,7 +151,7 @@ public:
// TargetData subsystem to do this.
//
bool isSized() const {
return ID != TypeTyID && ID != MethodTyID && ID != OpaqueTyID;
return ID != TypeTyID && ID != FunctionTyID && ID != OpaqueTyID;
}
//===--------------------------------------------------------------------===//

View File

@ -263,7 +263,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// Check to make sure the method is not defined in both modules...
if (!SM->isExternal() && !DM->isExternal())
return Error(Err, "Function '" +
SM->getMethodType()->getDescription() + "':\"" +
SM->getFunctionType()->getDescription() + "':\"" +
SM->getName() + "\" - Function is already defined!");
// Otherwise, just remember this mapping...
@ -271,7 +271,8 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
} else {
// Function does not already exist, simply insert an external method
// signature identical to SM into the dest module...
Function *DM = new Function(SM->getMethodType(), SM->hasInternalLinkage(),
Function *DM = new Function(SM->getFunctionType(),
SM->hasInternalLinkage(),
SM->getName());
// Add the method signature to the dest module...

View File

@ -263,7 +263,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// Check to make sure the method is not defined in both modules...
if (!SM->isExternal() && !DM->isExternal())
return Error(Err, "Function '" +
SM->getMethodType()->getDescription() + "':\"" +
SM->getFunctionType()->getDescription() + "':\"" +
SM->getName() + "\" - Function is already defined!");
// Otherwise, just remember this mapping...
@ -271,7 +271,8 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
} else {
// Function does not already exist, simply insert an external method
// signature identical to SM into the dest module...
Function *DM = new Function(SM->getMethodType(), SM->hasInternalLinkage(),
Function *DM = new Function(SM->getFunctionType(),
SM->hasInternalLinkage(),
SM->getName());
// Add the method signature to the dest module...

View File

@ -147,10 +147,10 @@ static string calcTypeName(const Type *Ty, vector<const Type *> &TypeStack,
string Result;
switch (Ty->getPrimitiveID()) {
case Type::MethodTyID: {
const MethodType *MTy = cast<const MethodType>(Ty);
case Type::FunctionTyID: {
const FunctionType *MTy = cast<const FunctionType>(Ty);
Result = calcTypeName(MTy->getReturnType(), TypeStack, TypeNames) + " (";
for (MethodType::ParamTypes::const_iterator
for (FunctionType::ParamTypes::const_iterator
I = MTy->getParamTypes().begin(),
E = MTy->getParamTypes().end(); I != E; ++I) {
if (I != MTy->getParamTypes().begin())
@ -395,15 +395,15 @@ void AssemblyWriter::printFunction(const Function *M) {
Table.incorporateMethod(M);
// Loop over the arguments, printing them...
const MethodType *MT = cast<const MethodType>(M->getMethodType());
const FunctionType *MT = M->getFunctionType();
if (!M->isExternal()) {
for_each(M->getArgumentList().begin(), M->getArgumentList().end(),
bind_obj(this, &AssemblyWriter::printFunctionArgument));
} else {
// Loop over the arguments, printing them...
const MethodType *MT = cast<const MethodType>(M->getMethodType());
for (MethodType::ParamTypes::const_iterator I = MT->getParamTypes().begin(),
const FunctionType *MT = M->getFunctionType();
for (FunctionType::ParamTypes::const_iterator I = MT->getParamTypes().begin(),
E = MT->getParamTypes().end(); I != E; ++I) {
if (I != MT->getParamTypes().begin()) Out << ", ";
printType(*I);
@ -538,7 +538,7 @@ void AssemblyWriter::printInstruction(const Instruction *I) {
Out << " void";
} else if (isa<CallInst>(I)) {
const PointerType *PTy = dyn_cast<PointerType>(Operand->getType());
const MethodType *MTy = PTy ?dyn_cast<MethodType>(PTy->getElementType()):0;
const FunctionType*MTy = PTy ? dyn_cast<FunctionType>(PTy->getElementType()):0;
const Type *RetTy = MTy ? MTy->getReturnType() : 0;
// If possible, print out the short form of the call instruction, but we can
@ -546,7 +546,7 @@ void AssemblyWriter::printInstruction(const Instruction *I) {
// and if the value returned is not a pointer to a method.
//
if (RetTy && !MTy->isVarArg() &&
(!isa<PointerType>(RetTy)||!isa<MethodType>(cast<PointerType>(RetTy)))){
(!isa<PointerType>(RetTy)||!isa<FunctionType>(cast<PointerType>(RetTy)))){
Out << " "; printType(RetTy);
writeOperand(Operand, false);
} else {

View File

@ -25,11 +25,10 @@
template class ValueHolder<FunctionArgument, Function, Function>;
template class ValueHolder<BasicBlock , Function, Function>;
Function::Function(const MethodType *Ty, bool isInternal,
Function::Function(const FunctionType *Ty, bool isInternal,
const std::string &name)
: GlobalValue(PointerType::get(Ty), Value::FunctionVal, isInternal, name),
SymTabValue(this), BasicBlocks(this), ArgumentList(this, this) {
assert(::isa<MethodType>(Ty) && "Function signature must be of method type!");
}
Function::~Function() {
@ -62,12 +61,12 @@ void Function::setParent(Module *parent) {
setParentSymTab(Parent ? Parent->getSymbolTableSure() : 0);
}
const MethodType *Function::getMethodType() const {
return cast<MethodType>(cast<PointerType>(getType())->getElementType());
const FunctionType *Function::getFunctionType() const {
return cast<FunctionType>(getType()->getElementType());
}
const Type *Function::getReturnType() const {
return getMethodType()->getReturnType();
return getFunctionType()->getReturnType();
}
// dropAllReferences() - This function causes all the subinstructions to "let

View File

@ -263,7 +263,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// Check to make sure the method is not defined in both modules...
if (!SM->isExternal() && !DM->isExternal())
return Error(Err, "Function '" +
SM->getMethodType()->getDescription() + "':\"" +
SM->getFunctionType()->getDescription() + "':\"" +
SM->getName() + "\" - Function is already defined!");
// Otherwise, just remember this mapping...
@ -271,7 +271,8 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
} else {
// Function does not already exist, simply insert an external method
// signature identical to SM into the dest module...
Function *DM = new Function(SM->getMethodType(), SM->hasInternalLinkage(),
Function *DM = new Function(SM->getFunctionType(),
SM->hasInternalLinkage(),
SM->getName());
// Add the method signature to the dest module...

View File

@ -194,8 +194,9 @@ Type *Type::VoidTy = new Type("void" , VoidTyID),
// Derived Type Constructors
//===----------------------------------------------------------------------===//
MethodType::MethodType(const Type *Result, const vector<const Type*> &Params,
bool IsVarArgs) : DerivedType(MethodTyID),
FunctionType::FunctionType(const Type *Result,
const vector<const Type*> &Params,
bool IsVarArgs) : DerivedType(FunctionTyID),
ResultType(PATypeHandle<Type>(Result, this)),
isVarArgs(IsVarArgs) {
ParamTys.reserve(Params.size());
@ -271,11 +272,11 @@ static string getTypeProps(const Type *Ty, vector<const Type *> &TypeStack,
TypeStack.push_back(Ty); // Add us to the stack..
switch (Ty->getPrimitiveID()) {
case Type::MethodTyID: {
const MethodType *MTy = cast<const MethodType>(Ty);
case Type::FunctionTyID: {
const FunctionType *MTy = cast<const FunctionType>(Ty);
Result = getTypeProps(MTy->getReturnType(), TypeStack,
isAbstract, isRecursive)+" (";
for (MethodType::ParamTypes::const_iterator
for (FunctionType::ParamTypes::const_iterator
I = MTy->getParamTypes().begin(),
E = MTy->getParamTypes().end(); I != E; ++I) {
if (I != MTy->getParamTypes().begin())
@ -381,8 +382,8 @@ static bool TypesEqual(const Type *Ty, const Type *Ty2,
if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
if (ATy->getNumElements() != cast<const ArrayType>(Ty2)->getNumElements())
return false;
} else if (const MethodType *MTy = dyn_cast<MethodType>(Ty)) {
if (MTy->isVarArg() != cast<const MethodType>(Ty2)->isVarArg())
} else if (const FunctionType *MTy = dyn_cast<FunctionType>(Ty)) {
if (MTy->isVarArg() != cast<const FunctionType>(Ty2)->isVarArg())
return false;
}
@ -522,29 +523,29 @@ protected:
//===----------------------------------------------------------------------===//
// Method Type Factory and Value Class...
// Function Type Factory and Value Class...
//
// MethodValType - Define a class to hold the key that goes into the TypeMap
// FunctionValType - Define a class to hold the key that goes into the TypeMap
//
class MethodValType : public ValTypeBase<MethodValType, MethodType> {
class FunctionValType : public ValTypeBase<FunctionValType, FunctionType> {
PATypeHandle<Type> RetTy;
vector<PATypeHandle<Type> > ArgTypes;
bool isVarArg;
public:
MethodValType(const Type *ret, const vector<const Type*> &args,
bool IVA, TypeMap<MethodValType, MethodType> &Tab)
: ValTypeBase<MethodValType, MethodType>(Tab), RetTy(ret, this),
FunctionValType(const Type *ret, const vector<const Type*> &args,
bool IVA, TypeMap<FunctionValType, FunctionType> &Tab)
: ValTypeBase<FunctionValType, FunctionType>(Tab), RetTy(ret, this),
isVarArg(IVA) {
for (unsigned i = 0; i < args.size(); ++i)
ArgTypes.push_back(PATypeHandle<Type>(args[i], this));
}
// We *MUST* have an explicit copy ctor so that the TypeHandles think that
// this MethodValType owns them, not the old one!
// this FunctionValType owns them, not the old one!
//
MethodValType(const MethodValType &MVT)
: ValTypeBase<MethodValType, MethodType>(MVT), RetTy(MVT.RetTy, this),
FunctionValType(const FunctionValType &MVT)
: ValTypeBase<FunctionValType, FunctionType>(MVT), RetTy(MVT.RetTy, this),
isVarArg(MVT.isVarArg) {
ArgTypes.reserve(MVT.ArgTypes.size());
for (unsigned i = 0; i < MVT.ArgTypes.size(); ++i)
@ -565,7 +566,7 @@ public:
if (ArgTypes[i] == Ty) ArgTypes[i].removeUserFromConcrete();
}
inline bool operator<(const MethodValType &MTV) const {
inline bool operator<(const FunctionValType &MTV) const {
if (RetTy.get() < MTV.RetTy.get()) return true;
if (RetTy.get() > MTV.RetTy.get()) return false;
@ -575,17 +576,17 @@ public:
};
// Define the actual map itself now...
static TypeMap<MethodValType, MethodType> MethodTypes;
static TypeMap<FunctionValType, FunctionType> FunctionTypes;
// MethodType::get - The factory function for the MethodType class...
MethodType *MethodType::get(const Type *ReturnType,
const vector<const Type*> &Params,
bool isVarArg) {
MethodValType VT(ReturnType, Params, isVarArg, MethodTypes);
MethodType *MT = MethodTypes.get(VT);
// FunctionType::get - The factory function for the FunctionType class...
FunctionType *FunctionType::get(const Type *ReturnType,
const vector<const Type*> &Params,
bool isVarArg) {
FunctionValType VT(ReturnType, Params, isVarArg, FunctionTypes);
FunctionType *MT = FunctionTypes.get(VT);
if (MT) return MT;
MethodTypes.add(VT, MT = new MethodType(ReturnType, Params, isVarArg));
FunctionTypes.add(VT, MT = new FunctionType(ReturnType, Params, isVarArg));
#ifdef DEBUG_MERGE_TYPES
cerr << "Derived new type: " << MT << endl;
@ -910,10 +911,10 @@ void DerivedType::typeIsRefined() {
// concrete - this could potentially change us from an abstract type to a
// concrete type.
//
void MethodType::refineAbstractType(const DerivedType *OldType,
const Type *NewType) {
void FunctionType::refineAbstractType(const DerivedType *OldType,
const Type *NewType) {
#ifdef DEBUG_MERGE_TYPES
cerr << "MethodTy::refineAbstractTy(" << (void*)OldType << "["
cerr << "FunctionTy::refineAbstractTy(" << (void*)OldType << "["
<< OldType->getDescription() << "], " << (void*)NewType << " ["
<< NewType->getDescription() << "])\n";
#endif
@ -931,7 +932,7 @@ void MethodType::refineAbstractType(const DerivedType *OldType,
if (ParamTys[i] == OldType) ParamTys[i] = NewType;
}
const MethodType *MT = MethodTypes.containsEquivalent(this);
const FunctionType *MT = FunctionTypes.containsEquivalent(this);
if (MT && MT != this) {
refineAbstractTypeTo(MT); // Different type altogether...
} else {