 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
0.0% |
0 / 0 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
0.0% |
0 / 0 |
| |
|
Line Coverage: |
100.0% |
41 / 41 |
| |
 |
|
 |
1 : //===--- CharUnits.h - Character units for sizes and offsets ----*- C++ -*-===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 : //
10 : // This file defines the CharUnits class
11 : //
12 : //===----------------------------------------------------------------------===//
13 :
14 : #ifndef LLVM_CLANG_AST_CHARUNITS_H
15 : #define LLVM_CLANG_AST_CHARUNITS_H
16 :
17 : #include "llvm/System/DataTypes.h"
18 :
19 : namespace clang {
20 :
21 : /// CharUnits - This is an opaque type for sizes expressed in character units.
22 : /// Instances of this type represent a quantity as a multiple of the size
23 : /// of the standard C type, char, on the target architecture. As an opaque
24 : /// type, CharUnits protects you from accidentally combining operations on
25 : /// quantities in bit units and character units.
26 : ///
27 : /// It should be noted that characters and bytes are distinct concepts. Bytes
28 : /// refer to addressable units of data storage on the target machine, and
29 : /// characters are members of a set of elements used for the organization,
30 : /// control, or representation of data. According to C99, bytes are allowed
31 : /// to exceed characters in size, although currently, clang only supports
32 : /// architectures where the two are the same size.
33 : ///
34 : /// For portability, never assume that a target character is 8 bits wide. Use
35 : /// CharUnit values whereever you calculate sizes, offsets, or alignments
36 : /// in character units.
37 : class CharUnits {
38 : public:
39 : typedef int64_t QuantityType;
40 :
41 : private:
42 : QuantityType Quantity;
43 :
44 16763: explicit CharUnits(QuantityType C) : Quantity(C) {}
45 :
46 : public:
47 :
48 : /// CharUnits - A default constructor.
49 10567: CharUnits() : Quantity(0) {}
50 :
51 : /// Zero - Construct a CharUnits quantity of zero.
52 5092: static CharUnits Zero() {
53 5092: return CharUnits(0);
54 : }
55 :
56 : /// One - Construct a CharUnits quantity of one.
57 28: static CharUnits One() {
58 28: return CharUnits(1);
59 : }
60 :
61 : /// fromQuantity - Construct a CharUnits quantity from a raw integer type.
62 9289: static CharUnits fromQuantity(QuantityType Quantity) {
63 9289: return CharUnits(Quantity);
64 : }
65 :
66 : // Compound assignment.
67 1445: CharUnits& operator+= (const CharUnits &Other) {
68 1445: Quantity += Other.Quantity;
69 1445: return *this;
70 : }
71 32: CharUnits& operator-= (const CharUnits &Other) {
72 32: Quantity -= Other.Quantity;
73 32: return *this;
74 : }
75 :
76 : // Comparison operators.
77 4: bool operator== (const CharUnits &Other) const {
78 4: return Quantity == Other.Quantity;
79 : }
80 1: bool operator!= (const CharUnits &Other) const {
81 1: return Quantity != Other.Quantity;
82 : }
83 :
84 : // Relational operators.
85 233: bool operator< (const CharUnits &Other) const {
86 233: return Quantity < Other.Quantity;
87 : }
88 28: bool operator<= (const CharUnits &Other) const {
89 28: return Quantity <= Other.Quantity;
90 : }
91 47: bool operator> (const CharUnits &Other) const {
92 47: return Quantity > Other.Quantity;
93 : }
94 : bool operator>= (const CharUnits &Other) const {
95 : return Quantity >= Other.Quantity;
96 : }
97 :
98 : // Other predicates.
99 :
100 : /// isZero - Test whether the quantity equals zero.
101 234: bool isZero() const { return Quantity == 0; }
102 :
103 : /// isOne - Test whether the quantity equals one.
104 23: bool isOne() const { return Quantity == 1; }
105 :
106 : /// isPositive - Test whether the quantity is greater than zero.
107 647: bool isPositive() const { return Quantity > 0; }
108 :
109 : /// isNegative - Test whether the quantity is less than zero.
110 31: bool isNegative() const { return Quantity < 0; }
111 :
112 : // Arithmetic operators.
113 1906: CharUnits operator* (QuantityType N) const {
114 1906: return CharUnits(Quantity * N);
115 : }
116 : CharUnits operator/ (QuantityType N) const {
117 : return CharUnits(Quantity / N);
118 : }
119 19: QuantityType operator/ (const CharUnits &Other) const {
120 19: return Quantity / Other.Quantity;
121 : }
122 : CharUnits operator% (QuantityType N) const {
123 : return CharUnits(Quantity % N);
124 : }
125 16: QuantityType operator% (const CharUnits &Other) const {
126 16: return Quantity % Other.Quantity;
127 : }
128 357: CharUnits operator+ (const CharUnits &Other) const {
129 357: return CharUnits(Quantity + Other.Quantity);
130 : }
131 91: CharUnits operator- (const CharUnits &Other) const {
132 91: return CharUnits(Quantity - Other.Quantity);
133 : }
134 :
135 : // Conversions.
136 :
137 : /// getQuantity - Get the raw integer representation of this quantity.
138 10624: QuantityType getQuantity() const { return Quantity; }
139 :
140 :
141 : }; // class CharUnit
142 : } // namespace clang
143 :
144 : inline clang::CharUnits operator* (clang::CharUnits::QuantityType Scale,
145 1906: const clang::CharUnits &CU) {
146 1906: return CU * Scale;
147 : }
148 :
149 : #endif // LLVM_CLANG_AST_CHARUNITS_H
Generated: 2010-02-10 01:31 by zcov