template<typename From> struct simplify_type<const From> {
typedef const From SimpleType;
static SimpleType &getSimplifiedValue(const From &Val) {
- return simplify_type<From>::getSimplifiedValue((From&)Val);
+ return simplify_type<From>::getSimplifiedValue(static_cast<From&>(Val));
}
};
template<class To, class FromTy> struct cast_convert_val<To,FromTy,FromTy> {
// This _is_ a simple type, just cast it.
static typename cast_retty<To, FromTy>::ret_type doit(const FromTy &Val) {
- return (typename cast_retty<To, FromTy>::ret_type)Val;
+ return reinterpret_cast<typename cast_retty<To, FromTy>::ret_type>(
+ const_cast<FromTy&>(Val));
}
};
inline enum NumOccurrences getNumOccurrencesFlag() const {
int NO = Flags & OccurrencesMask;
- return NO ? (enum NumOccurrences)NO : getNumOccurrencesFlagDefault();
+ return NO ? static_cast<enum NumOccurrences>(NO)
+ : getNumOccurrencesFlagDefault();
}
inline enum ValueExpected getValueExpectedFlag() const {
int VE = Flags & ValueMask;
- return VE ? (enum ValueExpected)VE : getValueExpectedFlagDefault();
+ return VE ? static_cast<enum ValueExpected>(VE)
+ : getValueExpectedFlagDefault();
}
inline enum OptionHidden getOptionHiddenFlag() const {
int OH = Flags & HiddenMask;
- return OH ? (enum OptionHidden)OH : getOptionHiddenFlagDefault();
+ return OH ? static_cast<enum OptionHidden>(OH)
+ : getOptionHiddenFlagDefault();
}
inline enum FormattingFlags getFormattingFlag() const {
int OH = Flags & FormattingMask;
- return OH ? (enum FormattingFlags)OH : getFormattingFlagDefault();
+ return OH ? static_cast<enum FormattingFlags>(OH)
+ : getFormattingFlagDefault();
}
inline unsigned getMiscFlags() const {
return Flags & MiscMask;
// Process the varargs portion of the values...
while (const char *EnumName = va_arg(ValueArgs, const char *)) {
- DataType EnumVal = (DataType)va_arg(ValueArgs, int);
+ DataType EnumVal = static_cast<DataType>(va_arg(ValueArgs, int));
const char *EnumDesc = va_arg(ValueArgs, const char *);
Values.push_back(std::make_pair(EnumName, // Add value to value map
std::make_pair(EnumVal, EnumDesc)));
template <class DT>
void addLiteralOption(const char *Name, const DT &V, const char *HelpStr) {
assert(findOption(Name) == Values.size() && "Option already exists!");
- Values.push_back(std::make_pair(Name, std::make_pair((DataType)V,HelpStr)));
+ Values.push_back(std::make_pair(Name,
+ std::make_pair(static_cast<DataType>(V),HelpStr)));
}
// removeLiteralOption - Remove the specified option.
void writeNode(NodeType *Node) {
std::string NodeAttributes = DOTTraits::getNodeAttributes(Node);
- O << "\tNode" << (void*)Node << " [shape=record,";
+ O << "\tNode" << reinterpret_cast<const void*>(Node) << " [shape=record,";
if (!NodeAttributes.empty()) O << NodeAttributes << ",";
O << "label=\"{"
<< DOT::EscapeString(DOTTraits::getNodeLabel(Node, G));
// Figure out which edge this targets...
unsigned Offset = std::distance(GTraits::child_begin(TargetNode),
TargetIt);
- DestPort = (int)Offset;
+ DestPort = static_cast<int>(Offset);
}
- emitEdge((void *)Node, edgeidx, (void*)TargetNode, DestPort,
+ emitEdge(reinterpret_cast<const void*>(Node), edgeidx,
+ reinterpret_cast<const void*>(TargetNode), DestPort,
DOTTraits::getEdgeAttributes(Node, EI));
}
}
O << "\tNode" << SrcNodeID;
if (SrcNodePort >= 0)
O << ":g" << SrcNodePort;
- O << " -> Node" << (void*)DestNodeID;
+ O << " -> Node" << reinterpret_cast<const void*>(DestNodeID);
if (DestNodePort >= 0)
O << ":g" << DestNodePort;
// Provide a hash function for arbitrary pointers...
template <class T> struct hash<T *> {
- inline size_t operator()(const T *Val) const { return (size_t)Val; }
+ inline size_t operator()(const T *Val) const {
+ return reinterpret_cast<size_t>(Val);
+ }
};
} // End namespace std
size_type max_size() const { return ~0 / sizeof(T); }
static pointer allocate(size_t n, void* hint = 0) {
- return (pointer)malloc(n*sizeof(T));
+ return static_cast<pointer>(malloc(n*sizeof(T)));
}
static void deallocate(pointer p, size_t n) {
- free((void*)p);
+ free(static_cast<void*>(p));
}
void construct(pointer p, const T &val) {
- new((void*)p) T(val);
+ new(static_cast<void*>(p)) T(val);
}
void destroy(pointer p) {
p->~T();
inline bool isPowerOf2(int64_t C, unsigned &getPow) {
if (C < 0) C = -C;
if (C > 0 && C == (C & ~(C - 1))) {
- getPow = log2((uint64_t)C);
+ getPow = log2(static_cast<uint64_t>(C));
return true;
}
static inline std::string itostr(int64_t X) {
if (X < 0)
- return utostr((uint64_t)-X, true);
+ return utostr(static_cast<uint64_t>(-X), true);
else
- return utostr((uint64_t)X);
+ return utostr(static_cast<uint64_t>(X));
}
static inline std::string utostr(unsigned long X, bool isNeg = false) {
- return utostr((unsigned long long)X, isNeg);
+ return utostr(static_cast<unsigned long long>(X), isNeg);
}
static inline std::string utostr(unsigned X, bool isNeg = false) {
static inline std::string itostr(int X) {
if (X < 0)
- return utostr((unsigned)-X, true);
+ return utostr(static_cast<unsigned>(-X), true);
else
- return utostr((unsigned)X);
+ return utostr(static_cast<unsigned>(X));
}
static inline std::string ftostr(double V) {
// Provide a hash function for arbitrary pointers...
template <class T> struct hash<T *> {
- inline size_t operator()(const T *Val) const { return (size_t)Val; }
+ inline size_t operator()(const T *Val) const {
+ return reinterpret_cast<size_t>(Val);
+ }
};
} // End namespace std
static inline std::string itostr(int64_t X) {
if (X < 0)
- return utostr((uint64_t)-X, true);
+ return utostr(static_cast<uint64_t>(-X), true);
else
- return utostr((uint64_t)X);
+ return utostr(static_cast<uint64_t>(X));
}
static inline std::string utostr(unsigned long X, bool isNeg = false) {
- return utostr((unsigned long long)X, isNeg);
+ return utostr(static_cast<unsigned long long>(X), isNeg);
}
static inline std::string utostr(unsigned X, bool isNeg = false) {
static inline std::string itostr(int X) {
if (X < 0)
- return utostr((unsigned)-X, true);
+ return utostr(static_cast<unsigned>(-X), true);
else
- return utostr((unsigned)X);
+ return utostr(static_cast<unsigned>(X));
}
static inline std::string ftostr(double V) {
case Type::LongTyID: return castToLong(V);
case Type::FloatTyID: return castToFloat(V);
case Type::DoubleTyID: return castToDouble(V);
- case Type::PointerTyID:return castToPointer(V, (PointerType*)Ty);
+ case Type::PointerTyID:
+ return castToPointer(V, reinterpret_cast<const PointerType*>(Ty));
default: return 0;
}
}
static inline ConstRules *get(const Constant &V1, const Constant &V2) {
if (isa<ConstantExpr>(V1) || isa<ConstantExpr>(V2))
return getConstantExprRules();
- return (ConstRules*)V1.getType()->getOrCreateAnnotation(AID);
+ return static_cast<ConstRules*>(V1.getType()->getOrCreateAnnotation(AID));
}
private:
static ConstRules *getConstantExprRules();
/// which reduces the amount of casting needed in parts of the compiler.
///
inline const ArrayType *getType() const {
- return (ArrayType*)Value::getType();
+ return reinterpret_cast<const ArrayType*>(Value::getType());
}
/// getAsString - If the sub-element type of this array is either sbyte or
/// getType() specialization - Reduce amount of casting...
inline const StructType *getType() const {
- return (StructType*)Value::getType();
+ return reinterpret_cast<const StructType*>(Value::getType());
}
/// getValues - Return a vector of the component constants that make up this
class ConstantPointer : public Constant {
ConstantPointer(const ConstantPointer &); // DO NOT IMPLEMENT
protected:
- inline ConstantPointer(const PointerType *T) : Constant((const Type*)T) {}
+ inline ConstantPointer(const PointerType *T)
+ : Constant(reinterpret_cast<const Type*>(T)) { }
public:
inline const PointerType *getType() const {
- return (PointerType*)Value::getType();
+ return reinterpret_cast<const PointerType*>(Value::getType());
}
/// isNullValue - Return true if this is the value that would be returned by
/// getType - Global values are always pointers.
inline const PointerType *getType() const {
- return (const PointerType*)User::getType();
+ return reinterpret_cast<const PointerType*>(User::getType());
}
bool hasExternalLinkage() const { return Linkage == ExternalLinkage; }
///
inline Constant *getInitializer() const {
assert(hasInitializer() && "GV doesn't have initializer!");
- return (Constant*)Operands[0].get();
+ return reinterpret_cast<Constant*>(Operands[0].get());
}
inline Constant *getInitializer() {
assert(hasInitializer() && "GV doesn't have initializer!");
- return (Constant*)Operands[0].get();
+ return reinterpret_cast<Constant*>(Operands[0].get());
}
inline void setInitializer(Constant *CPV) {
if (CPV == 0) {
if (hasInitializer()) Operands.pop_back();
} else {
if (!hasInitializer()) Operands.push_back(Use(0, this));
- Operands[0] = (Value*)CPV;
+ Operands[0] = reinterpret_cast<Value*>(CPV);
}
}
virtual void setSuccessor(unsigned idx, BasicBlock *B) = 0;
inline BasicBlock *getSuccessor(unsigned idx) {
- return (BasicBlock*)((const TerminatorInst *)this)->getSuccessor(idx);
+ const TerminatorInst *TI = this;
+ return const_cast<BasicBlock*>(TI->getSuccessor(idx));
}
// Methods for support type inquiry through isa, cast, and dyn_cast:
static Value* getNotArgument( BinaryOperator* Bop);
BinaryOps getOpcode() const {
- return (BinaryOps)Instruction::getOpcode();
+ return static_cast<BinaryOps>(Instruction::getOpcode());
}
virtual Instruction *clone() const {
RegisterOpt(const char *PassArg, const char *Name, FunctionPass *(*ctor)(),
bool CFGOnly = false) {
registerPass(new PassInfo(Name, PassArg, typeid(PassName),
- PassInfo::Optimization, (Pass*(*)())ctor));
+ PassInfo::Optimization,
+ static_cast<Pass*(*)()>(ctor)));
if (CFGOnly) setOnlyUsesCFG();
}
bool CFGOnly = false) {
registerPass(new PassInfo(Name, PassArg, typeid(PassName),
PassInfo::Optimization, 0,
- (Pass*(*)(TargetMachine&))targetctor));
+ static_cast<Pass*(*)(TargetMachine&)>(targetctor)));
if (CFGOnly) setOnlyUsesCFG();
}
};
template<typename From> struct simplify_type<const From> {
typedef const From SimpleType;
static SimpleType &getSimplifiedValue(const From &Val) {
- return simplify_type<From>::getSimplifiedValue((From&)Val);
+ return simplify_type<From>::getSimplifiedValue(static_cast<From&>(Val));
}
};
template<class To, class FromTy> struct cast_convert_val<To,FromTy,FromTy> {
// This _is_ a simple type, just cast it.
static typename cast_retty<To, FromTy>::ret_type doit(const FromTy &Val) {
- return (typename cast_retty<To, FromTy>::ret_type)Val;
+ return reinterpret_cast<typename cast_retty<To, FromTy>::ret_type>(
+ const_cast<FromTy&>(Val));
}
};
inline enum NumOccurrences getNumOccurrencesFlag() const {
int NO = Flags & OccurrencesMask;
- return NO ? (enum NumOccurrences)NO : getNumOccurrencesFlagDefault();
+ return NO ? static_cast<enum NumOccurrences>(NO)
+ : getNumOccurrencesFlagDefault();
}
inline enum ValueExpected getValueExpectedFlag() const {
int VE = Flags & ValueMask;
- return VE ? (enum ValueExpected)VE : getValueExpectedFlagDefault();
+ return VE ? static_cast<enum ValueExpected>(VE)
+ : getValueExpectedFlagDefault();
}
inline enum OptionHidden getOptionHiddenFlag() const {
int OH = Flags & HiddenMask;
- return OH ? (enum OptionHidden)OH : getOptionHiddenFlagDefault();
+ return OH ? static_cast<enum OptionHidden>(OH)
+ : getOptionHiddenFlagDefault();
}
inline enum FormattingFlags getFormattingFlag() const {
int OH = Flags & FormattingMask;
- return OH ? (enum FormattingFlags)OH : getFormattingFlagDefault();
+ return OH ? static_cast<enum FormattingFlags>(OH)
+ : getFormattingFlagDefault();
}
inline unsigned getMiscFlags() const {
return Flags & MiscMask;
// Process the varargs portion of the values...
while (const char *EnumName = va_arg(ValueArgs, const char *)) {
- DataType EnumVal = (DataType)va_arg(ValueArgs, int);
+ DataType EnumVal = static_cast<DataType>(va_arg(ValueArgs, int));
const char *EnumDesc = va_arg(ValueArgs, const char *);
Values.push_back(std::make_pair(EnumName, // Add value to value map
std::make_pair(EnumVal, EnumDesc)));
template <class DT>
void addLiteralOption(const char *Name, const DT &V, const char *HelpStr) {
assert(findOption(Name) == Values.size() && "Option already exists!");
- Values.push_back(std::make_pair(Name, std::make_pair((DataType)V,HelpStr)));
+ Values.push_back(std::make_pair(Name,
+ std::make_pair(static_cast<DataType>(V),HelpStr)));
}
// removeLiteralOption - Remove the specified option.
void writeNode(NodeType *Node) {
std::string NodeAttributes = DOTTraits::getNodeAttributes(Node);
- O << "\tNode" << (void*)Node << " [shape=record,";
+ O << "\tNode" << reinterpret_cast<const void*>(Node) << " [shape=record,";
if (!NodeAttributes.empty()) O << NodeAttributes << ",";
O << "label=\"{"
<< DOT::EscapeString(DOTTraits::getNodeLabel(Node, G));
// Figure out which edge this targets...
unsigned Offset = std::distance(GTraits::child_begin(TargetNode),
TargetIt);
- DestPort = (int)Offset;
+ DestPort = static_cast<int>(Offset);
}
- emitEdge((void *)Node, edgeidx, (void*)TargetNode, DestPort,
+ emitEdge(reinterpret_cast<const void*>(Node), edgeidx,
+ reinterpret_cast<const void*>(TargetNode), DestPort,
DOTTraits::getEdgeAttributes(Node, EI));
}
}
O << "\tNode" << SrcNodeID;
if (SrcNodePort >= 0)
O << ":g" << SrcNodePort;
- O << " -> Node" << (void*)DestNodeID;
+ O << " -> Node" << reinterpret_cast<const void*>(DestNodeID);
if (DestNodePort >= 0)
O << ":g" << DestNodePort;
size_type max_size() const { return ~0 / sizeof(T); }
static pointer allocate(size_t n, void* hint = 0) {
- return (pointer)malloc(n*sizeof(T));
+ return static_cast<pointer>(malloc(n*sizeof(T)));
}
static void deallocate(pointer p, size_t n) {
- free((void*)p);
+ free(static_cast<void*>(p));
}
void construct(pointer p, const T &val) {
- new((void*)p) T(val);
+ new(static_cast<void*>(p)) T(val);
}
void destroy(pointer p) {
p->~T();
inline bool isPowerOf2(int64_t C, unsigned &getPow) {
if (C < 0) C = -C;
if (C > 0 && C == (C & ~(C - 1))) {
- getPow = log2((uint64_t)C);
+ getPow = log2(static_cast<uint64_t>(C));
return true;
}
template<> struct simplify_type<Use> {
typedef Value* SimpleType;
static SimpleType getSimplifiedValue(const Use &Val) {
- return (SimpleType)Val.get();
+ return static_cast<SimpleType>(Val.get());
}
};
template<> struct simplify_type<const Use> {
typedef Value* SimpleType;
static SimpleType getSimplifiedValue(const Use &Val) {
- return (SimpleType)Val.get();
+ return static_cast<SimpleType>(Val.get());
}
};
typedef Value* SimpleType;
static SimpleType getSimplifiedValue(const User::op_iterator &Val) {
- return (SimpleType)Val->get();
+ return static_cast<SimpleType>(Val->get());
}
};
template<> struct simplify_type<const User::op_iterator>
typedef Value* SimpleType;
static SimpleType getSimplifiedValue(const User::const_op_iterator &Val) {
- return (SimpleType)Val->get();
+ return static_cast<SimpleType>(Val->get());
}
};
template<> struct simplify_type<const User::const_op_iterator>
// getType - Overload to return most specific pointer type...
inline const PointerType *getType() const {
- return (const PointerType*)Instruction::getType();
+ return reinterpret_cast<const PointerType*>(Instruction::getType());
}
// getAllocatedType - Return the type that is being allocated by the
class GetElementPtrInst : public Instruction {
GetElementPtrInst(const GetElementPtrInst &EPI)
- : Instruction((Type*)EPI.getType(), GetElementPtr) {
+ : Instruction(reinterpret_cast<const Type*>(EPI.getType()), GetElementPtr) {
Operands.reserve(EPI.Operands.size());
for (unsigned i = 0, E = EPI.Operands.size(); i != E; ++i)
Operands.push_back(Use(EPI.Operands[i], this));
// getType - Overload to return most specific pointer type...
inline const PointerType *getType() const {
- return (PointerType*)Instruction::getType();
+ return reinterpret_cast<const PointerType*>(Instruction::getType());
}
/// getIndexedType - Returns the type of the element that would be loaded with
Operands.push_back(Use(SA, this));
}
- OtherOps getOpcode() const { return (OtherOps)Instruction::getOpcode(); }
+ OtherOps getOpcode() const {
+ return static_cast<OtherOps>(Instruction::getOpcode());
+ }
virtual Instruction *clone() const { return new ShiftInst(*this); }
/// getIncomingBlock - Return incoming basic block #x
BasicBlock *getIncomingBlock(unsigned i) const {
assert(i*2+1 < Operands.size() && "Invalid value number!");
- return (BasicBlock*)Operands[i*2+1].get();
+ return reinterpret_cast<BasicBlock*>(Operands[i*2+1].get());
}
void setIncomingBlock(unsigned i, BasicBlock *BB) {
assert(i*2+1 < Operands.size() && "Invalid value number!");
- Operands[i*2+1] = (Value*)BB;
+ Operands[i*2+1] = reinterpret_cast<Value*>(BB);
}
unsigned getOperandNumForIncomingBlock(unsigned i) {
return i*2+1;
assert(getType() == D->getType() &&
"All operands to PHI node must be the same type as the PHI node!");
Operands.push_back(Use(D, this));
- Operands.push_back(Use((Value*)BB, this));
+ Operands.push_back(Use(reinterpret_cast<Value*>(BB), this));
}
/// removeIncomingValue - Remove an incoming value. This is useful if a
inline bool isConditional() const { return Operands.size() == 3; }
inline Value *getCondition() const {
- return isUnconditional() ? 0 : (Value*)Operands[2].get();
+ return isUnconditional() ? 0 : reinterpret_cast<Value*>(Operands[2].get());
}
void setCondition(Value *V) {
//
void setUnconditionalDest(BasicBlock *Dest) {
if (isConditional()) Operands.erase(Operands.begin()+1, Operands.end());
- Operands[0] = (Value*)Dest;
+ Operands[0] = reinterpret_cast<Value*>(Dest);
}
virtual const BasicBlock *getSuccessor(unsigned i) const {
cast<BasicBlock>(Operands[1].get());
}
inline BasicBlock *getSuccessor(unsigned idx) {
- return (BasicBlock*)((const BranchInst *)this)->getSuccessor(idx);
+ const BranchInst *BI = this;
+ return const_cast<BasicBlock*>(BI->getSuccessor(idx));
}
virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
- Operands[idx] = (Value*)NewSucc;
+ Operands[idx] = reinterpret_cast<Value*>(NewSucc);
}
virtual unsigned getNumSuccessors() const { return 1+isConditional(); }
virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
- Operands[idx*2+1] = (Value*)NewSucc;
+ Operands[idx*2+1] = reinterpret_cast<Value*>(NewSucc);
}
// getSuccessorValue - Return the value associated with the specified
}
inline void setNormalDest(BasicBlock *B){
- Operands[1] = (Value*)B;
+ Operands[1] = reinterpret_cast<Value*>(B);
}
inline void setExceptionalDest(BasicBlock *B){
- Operands[2] = (Value*)B;
+ Operands[2] = reinterpret_cast<Value*>(B);
}
virtual const BasicBlock *getSuccessor(unsigned i) const {
virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
assert(idx < 2 && "Successor # out of range for invoke!");
- Operands[idx+1] = (Value*)NewSucc;
+ Operands[idx+1] = reinterpret_cast<Value*>(NewSucc);
}
virtual unsigned getNumSuccessors() const { return 2; }
case Type::LongTyID: return castToLong(V);
case Type::FloatTyID: return castToFloat(V);
case Type::DoubleTyID: return castToDouble(V);
- case Type::PointerTyID:return castToPointer(V, (PointerType*)Ty);
+ case Type::PointerTyID:
+ return castToPointer(V, reinterpret_cast<const PointerType*>(Ty));
default: return 0;
}
}
static inline ConstRules *get(const Constant &V1, const Constant &V2) {
if (isa<ConstantExpr>(V1) || isa<ConstantExpr>(V2))
return getConstantExprRules();
- return (ConstRules*)V1.getType()->getOrCreateAnnotation(AID);
+ return static_cast<ConstRules*>(V1.getType()->getOrCreateAnnotation(AID));
}
private:
static ConstRules *getConstantExprRules();
case Type::LongTyID: return castToLong(V);
case Type::FloatTyID: return castToFloat(V);
case Type::DoubleTyID: return castToDouble(V);
- case Type::PointerTyID:return castToPointer(V, (PointerType*)Ty);
+ case Type::PointerTyID:
+ return castToPointer(V, reinterpret_cast<const PointerType*>(Ty));
default: return 0;
}
}
static inline ConstRules *get(const Constant &V1, const Constant &V2) {
if (isa<ConstantExpr>(V1) || isa<ConstantExpr>(V2))
return getConstantExprRules();
- return (ConstRules*)V1.getType()->getOrCreateAnnotation(AID);
+ return static_cast<ConstRules*>(V1.getType()->getOrCreateAnnotation(AID));
}
private:
static ConstRules *getConstantExprRules();