[cfe-commits] r91719 - in /cfe/trunk: include/clang/AST/CharUnits.h lib/AST/CMakeLists.txt lib/AST/CharUnits.cpp

Ken Dyck ken.dyck at onsemi.com
Fri Dec 18 13:51:04 PST 2009


Author: kjdyck
Date: Fri Dec 18 15:51:03 2009
New Revision: 91719

URL: http://llvm.org/viewvc/llvm-project?rev=91719&view=rev
Log:
Add and tidy doxygen comments and move implementation of toString() to newly
created CharUnits.cpp.

Added:
    cfe/trunk/lib/AST/CharUnits.cpp
Modified:
    cfe/trunk/include/clang/AST/CharUnits.h
    cfe/trunk/lib/AST/CMakeLists.txt

Modified: cfe/trunk/include/clang/AST/CharUnits.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CharUnits.h?rev=91719&r1=91718&r2=91719&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/CharUnits.h (original)
+++ cfe/trunk/include/clang/AST/CharUnits.h Fri Dec 18 15:51:03 2009
@@ -14,13 +14,28 @@
 #ifndef LLVM_CLANG_AST_CHARUNITS_H
 #define LLVM_CLANG_AST_CHARUNITS_H
 
-#include "llvm/ADT/StringExtras.h"
 #include "llvm/System/DataTypes.h"
 
 #include <string>
 
 namespace clang {
-  // An opaque type for sizes expressed in character units 
+  
+  /// CharUnits - This is an opaque type for sizes expressed in character units.
+  /// Instances of this type represent a quantity as a multiple of the size 
+  /// of the standard C type, char, on the target architecture. As an opaque
+  /// type, CharUnits protects you from accidentally combining operations on
+  /// quantities in bit units and character units. 
+  ///
+  /// It should be noted that characters and bytes are distinct concepts. Bytes
+  /// refer to addressable units of data storage on the target machine, and
+  /// characters are members of a set of elements used for the organization,
+  /// control, or representation of data. According to C99, bytes are allowed
+  /// to exceed characters in size, although currently, clang only supports
+  /// architectures where the two are the same size.
+  /// 
+  /// For portability, never assume that a target character is 8 bits wide. Use 
+  /// CharUnit values whereever you calculate sizes, offsets, or alignments
+  /// in character units.
   class CharUnits {
     public:
       typedef int64_t RawType;
@@ -32,15 +47,15 @@
 
     public:
 
-      /// A default constructor
+      /// CharUnits - A default constructor.
       CharUnits() : Quantity(0) {}
 
-      /// Zero - Construct a CharUnits quantity of zero
+      /// Zero - Construct a CharUnits quantity of zero.
       static CharUnits Zero() {
         return CharUnits(0);
       }
 
-      /// One - Construct a CharUnits quantity of one
+      /// One - Construct a CharUnits quantity of one.
       static CharUnits One() {
         return CharUnits(1);
       }
@@ -50,7 +65,7 @@
         return CharUnits(Quantity); 
       }
 
-      // compound assignment
+      // Compound assignment.
       CharUnits& operator+= (const CharUnits &Other) {
         Quantity += Other.Quantity;
         return *this;
@@ -60,7 +75,7 @@
         return *this;
       }
        
-      // comparison operators
+      // Comparison operators.
       bool operator== (const CharUnits &Other) const {
         return Quantity == Other.Quantity;
       }
@@ -68,7 +83,7 @@
         return Quantity != Other.Quantity;
       }
 
-      // relational operators
+      // Relational operators.
       bool operator<  (const CharUnits &Other) const { 
         return Quantity <  Other.Quantity; 
       }
@@ -82,7 +97,7 @@
         return Quantity >= Other.Quantity; 
       }
 
-      // other predicates
+      // Other predicates.
       
       /// isZero - Test whether the quantity equals zero.
       bool isZero() const     { return Quantity == 0; }
@@ -96,7 +111,7 @@
       /// isNegative - Test whether the quantity is less than zero.
       bool isNegative() const { return Quantity  < 0; }
 
-      // arithmetic operators
+      // Arithmetic operators.
       CharUnits operator* (RawType N) const {
         return CharUnits(Quantity * N);
       }
@@ -119,12 +134,10 @@
         return CharUnits(Quantity - Other.Quantity);
       }
       
-      // conversions
+      // Conversions.
 
       /// toString - Convert to a string.
-      std::string toString() const {
-        return llvm::itostr(Quantity);
-      }
+      std::string toString() const;
 
       /// getRaw - Get the raw integer representation of this quantity.
       RawType getRaw() const { return Quantity; }

Modified: cfe/trunk/lib/AST/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CMakeLists.txt?rev=91719&r1=91718&r2=91719&view=diff

==============================================================================
--- cfe/trunk/lib/AST/CMakeLists.txt (original)
+++ cfe/trunk/lib/AST/CMakeLists.txt Fri Dec 18 15:51:03 2009
@@ -5,6 +5,7 @@
   ASTConsumer.cpp
   ASTContext.cpp
   CXXInheritance.cpp
+  CharUnits.cpp
   Decl.cpp
   DeclBase.cpp
   DeclCXX.cpp

Added: cfe/trunk/lib/AST/CharUnits.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CharUnits.cpp?rev=91719&view=auto

==============================================================================
--- cfe/trunk/lib/AST/CharUnits.cpp (added)
+++ cfe/trunk/lib/AST/CharUnits.cpp Fri Dec 18 15:51:03 2009
@@ -0,0 +1,24 @@
+//===--- CharUnits.cpp - Character units for sizes and offsets ------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file implements the CharUnits class.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/AST/CharUnits.h"
+
+#include "llvm/ADT/StringExtras.h"
+
+#include <string>
+
+using namespace clang;
+
+std::string CharUnits::toString() const {
+  return llvm::itostr(Quantity);
+}





More information about the cfe-commits mailing list