aboutsummaryrefslogtreecommitdiffstats
path: root/include/Support
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-11-16 20:21:15 +0000
committerChris Lattner <sabre@nondot.org>2003-11-16 20:21:15 +0000
commit8b70b78ba489b090d9866e6a4084ab1e8613b527 (patch)
treec3e137b779b119b92587950176b457381132b18f /include/Support
parentf3b2410bc4c098c0f27f689c797a539d6ef8a09e (diff)
downloadexternal_llvm-8b70b78ba489b090d9866e6a4084ab1e8613b527.zip
external_llvm-8b70b78ba489b090d9866e6a4084ab1e8613b527.tar.gz
external_llvm-8b70b78ba489b090d9866e6a4084ab1e8613b527.tar.bz2
Fixes for PR114: Thanks to Reid Spencer!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10029 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/Support')
-rw-r--r--include/Support/Casting.h5
-rw-r--r--include/Support/CommandLine.h17
-rw-r--r--include/Support/GraphWriter.h9
-rw-r--r--include/Support/HashExtras.h4
-rw-r--r--include/Support/MallocAllocator.h6
-rw-r--r--include/Support/MathExtras.h2
-rw-r--r--include/Support/StringExtras.h10
7 files changed, 31 insertions, 22 deletions
diff --git a/include/Support/Casting.h b/include/Support/Casting.h
index 4b070c1..abc80aa 100644
--- a/include/Support/Casting.h
+++ b/include/Support/Casting.h
@@ -37,7 +37,7 @@ template<typename From> struct simplify_type {
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));
}
};
@@ -178,7 +178,8 @@ template<class To, class From, class SimpleFrom> struct cast_convert_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));
}
};
diff --git a/include/Support/CommandLine.h b/include/Support/CommandLine.h
index df40d80..0a3cb6f 100644
--- a/include/Support/CommandLine.h
+++ b/include/Support/CommandLine.h
@@ -148,19 +148,23 @@ public:
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;
@@ -307,7 +311,7 @@ public:
// 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)));
@@ -452,7 +456,8 @@ public:
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.
diff --git a/include/Support/GraphWriter.h b/include/Support/GraphWriter.h
index 7e5aa80..0eace78 100644
--- a/include/Support/GraphWriter.h
+++ b/include/Support/GraphWriter.h
@@ -100,7 +100,7 @@ public:
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));
@@ -137,10 +137,11 @@ public:
// 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));
}
}
@@ -178,7 +179,7 @@ public:
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;
diff --git a/include/Support/HashExtras.h b/include/Support/HashExtras.h
index 871080c..67f65b5 100644
--- a/include/Support/HashExtras.h
+++ b/include/Support/HashExtras.h
@@ -31,7 +31,9 @@ template <> struct hash<std::string> {
// 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
diff --git a/include/Support/MallocAllocator.h b/include/Support/MallocAllocator.h
index 022953d..3e3da41 100644
--- a/include/Support/MallocAllocator.h
+++ b/include/Support/MallocAllocator.h
@@ -47,15 +47,15 @@ struct MallocAllocator {
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();
diff --git a/include/Support/MathExtras.h b/include/Support/MathExtras.h
index 74958fb..125aff3 100644
--- a/include/Support/MathExtras.h
+++ b/include/Support/MathExtras.h
@@ -28,7 +28,7 @@ inline unsigned log2(uint64_t C) {
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;
}
diff --git a/include/Support/StringExtras.h b/include/Support/StringExtras.h
index 2ebac81..08e5eb7 100644
--- a/include/Support/StringExtras.h
+++ b/include/Support/StringExtras.h
@@ -57,14 +57,14 @@ static inline std::string utostr(unsigned long long X, bool isNeg = false) {
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) {
@@ -86,9 +86,9 @@ 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) {