[llvm-commits] CVS: llvm/include/Support/Casting.h CommandLine.h GraphWriter.h HashExtras.h MallocAllocator.h MathExtras.h StringExtras.h

Chris Lattner lattner at cs.uiuc.edu
Sun Nov 16 14:22:18 PST 2003


Changes in directory llvm/include/Support:

Casting.h updated: 1.11 -> 1.12
CommandLine.h updated: 1.28 -> 1.29
GraphWriter.h updated: 1.17 -> 1.18
HashExtras.h updated: 1.9 -> 1.10
MallocAllocator.h updated: 1.6 -> 1.7
MathExtras.h updated: 1.9 -> 1.10
StringExtras.h updated: 1.10 -> 1.11

---
Log message:

Fixes for PR114: Thanks to Reid Spencer!


---
Diffs of the changes:  (+31 -22)

Index: llvm/include/Support/Casting.h
diff -u llvm/include/Support/Casting.h:1.11 llvm/include/Support/Casting.h:1.12
--- llvm/include/Support/Casting.h:1.11	Tue Nov 11 16:41:29 2003
+++ llvm/include/Support/Casting.h	Sun Nov 16 14:21:13 2003
@@ -37,7 +37,7 @@
 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 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));
   }
 };
 


Index: llvm/include/Support/CommandLine.h
diff -u llvm/include/Support/CommandLine.h:1.28 llvm/include/Support/CommandLine.h:1.29
--- llvm/include/Support/CommandLine.h:1.28	Tue Nov 11 16:41:29 2003
+++ llvm/include/Support/CommandLine.h	Sun Nov 16 14:21:13 2003
@@ -148,19 +148,23 @@
 
   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 @@
 
     // 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 @@
   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.


Index: llvm/include/Support/GraphWriter.h
diff -u llvm/include/Support/GraphWriter.h:1.17 llvm/include/Support/GraphWriter.h:1.18
--- llvm/include/Support/GraphWriter.h:1.17	Tue Nov 11 16:41:29 2003
+++ llvm/include/Support/GraphWriter.h	Sun Nov 16 14:21:13 2003
@@ -100,7 +100,7 @@
   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 @@
         // 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 @@
     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;    
 


Index: llvm/include/Support/HashExtras.h
diff -u llvm/include/Support/HashExtras.h:1.9 llvm/include/Support/HashExtras.h:1.10
--- llvm/include/Support/HashExtras.h:1.9	Mon Oct 20 14:46:57 2003
+++ llvm/include/Support/HashExtras.h	Sun Nov 16 14:21:13 2003
@@ -31,7 +31,9 @@
 
 // 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


Index: llvm/include/Support/MallocAllocator.h
diff -u llvm/include/Support/MallocAllocator.h:1.6 llvm/include/Support/MallocAllocator.h:1.7
--- llvm/include/Support/MallocAllocator.h:1.6	Wed Nov 12 16:45:14 2003
+++ llvm/include/Support/MallocAllocator.h	Sun Nov 16 14:21:13 2003
@@ -47,15 +47,15 @@
   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();


Index: llvm/include/Support/MathExtras.h
diff -u llvm/include/Support/MathExtras.h:1.9 llvm/include/Support/MathExtras.h:1.10
--- llvm/include/Support/MathExtras.h:1.9	Tue Nov 11 16:41:29 2003
+++ llvm/include/Support/MathExtras.h	Sun Nov 16 14:21:13 2003
@@ -28,7 +28,7 @@
 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;
   }
 


Index: llvm/include/Support/StringExtras.h
diff -u llvm/include/Support/StringExtras.h:1.10 llvm/include/Support/StringExtras.h:1.11
--- llvm/include/Support/StringExtras.h:1.10	Tue Nov 11 16:41:29 2003
+++ llvm/include/Support/StringExtras.h	Sun Nov 16 14:21:13 2003
@@ -57,14 +57,14 @@
 
 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 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) {





More information about the llvm-commits mailing list