// 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));
// 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
#include "Support/GraphTraits.h"
class DerivedType;
-class MethodType;
+class FunctionType;
class ArrayType;
class PointerType;
class StructType;
// 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:
// TargetData subsystem to do this.
//
bool isSized() const {
- return ID != TypeTyID && ID != MethodTyID && ID != OpaqueTyID;
+ return ID != TypeTyID && ID != FunctionTyID && ID != OpaqueTyID;
}
//===--------------------------------------------------------------------===//
// 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...
} 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...
// 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...
} 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...
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())
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);
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
// 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 {
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() {
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
// 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...
} 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...
// 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());
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())
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;
}
//===----------------------------------------------------------------------===//
-// 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)
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;
};
// Define the actual map itself now...
-static TypeMap<MethodValType, MethodType> MethodTypes;
-
-// 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);
+static TypeMap<FunctionValType, FunctionType> FunctionTypes;
+
+// 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;
// 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
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 {