Skip to content

Commit

Permalink
Retire uint in favour of uint32.
Browse files Browse the repository at this point in the history
Change-Id: I236bab7d151600e63de444fda513512d3daa0247
Reviewed-on: https://code-review.googlesource.com/5506
Reviewed-by: Paul Wankadia <[email protected]>
  • Loading branch information
junyer committed Aug 4, 2016
1 parent 8ff7539 commit ead5eeb
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 35 deletions.
2 changes: 1 addition & 1 deletion re2/compile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ void Compiler::AddRuneRangeUTF8(Rune lo, Rune hi, bool foldcase) {

// Split range into sections that agree on leading bytes.
for (int i = 1; i < UTFmax; i++) {
uint m = (1<<(6*i)) - 1; // last i bytes of a UTF-8 sequence
uint32 m = (1<<(6*i)) - 1; // last i bytes of a UTF-8 sequence
if ((lo & ~m) != (hi & ~m)) {
if ((lo & m) != 0) {
AddRuneRangeUTF8(lo, lo|m, foldcase);
Expand Down
44 changes: 22 additions & 22 deletions re2/dfa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class DFA {

int* inst_; // Instruction pointers in the state.
int ninst_; // # of inst_ pointers.
uint flag_; // Empty string bitfield flags in effect on the way
uint32 flag_; // Empty string bitfield flags in effect on the way
// into this state, along with kFlagMatch if this
// is a matching state.
std::atomic<State*> next_[]; // Outgoing arrows from State,
Expand Down Expand Up @@ -189,11 +189,11 @@ class DFA {

// Looks up and returns the State corresponding to a Workq.
// L >= mutex_
State* WorkqToCachedState(Workq* q, uint flag);
State* WorkqToCachedState(Workq* q, uint32 flag);

// Looks up and returns a State matching the inst, ninst, and flag.
// L >= mutex_
State* CachedState(int* inst, int ninst, uint flag);
State* CachedState(int* inst, int ninst, uint32 flag);

// Clear the cache entirely.
// Must hold cache_mutex_.w or be in destructor.
Expand All @@ -212,17 +212,17 @@ class DFA {
// sets *ismatch to true.
// L >= mutex_
void RunWorkqOnByte(Workq* q, Workq* nq,
int c, uint flag, bool* ismatch,
int c, uint32 flag, bool* ismatch,
Prog::MatchKind kind);

// Runs a Workq on a set of empty-string flags, producing a new Workq in nq.
// L >= mutex_
void RunWorkqOnEmptyString(Workq* q, Workq* nq, uint flag);
void RunWorkqOnEmptyString(Workq* q, Workq* nq, uint32 flag);

// Adds the instruction id to the Workq, following empty arrows
// according to flag.
// L >= mutex_
void AddToQueue(Workq* q, int id, uint flag);
void AddToQueue(Workq* q, int id, uint32 flag);

// For debugging, returns a text representation of State.
static string DumpState(State* state);
Expand Down Expand Up @@ -275,7 +275,7 @@ class DFA {
// false on failure.
// cache_mutex_.r <= L < mutex_
bool AnalyzeSearch(SearchParams* params);
bool AnalyzeSearchHelper(SearchParams* params, StartInfo* info, uint flags);
bool AnalyzeSearchHelper(SearchParams* params, StartInfo* info, uint32 flags);

// The generic search loop, inlined to create specialized versions.
// cache_mutex_.r <= L < mutex_
Expand Down Expand Up @@ -587,7 +587,7 @@ string DFA::DumpState(State* state) {
// Looks in the State cache for a State matching q, flag.
// If one is found, returns it. If one is not found, allocates one,
// inserts it in the cache, and returns it.
DFA::State* DFA::WorkqToCachedState(Workq* q, uint flag) {
DFA::State* DFA::WorkqToCachedState(Workq* q, uint32 flag) {
if (DEBUG_MODE)
mutex_.AssertHeld();

Expand All @@ -597,9 +597,9 @@ DFA::State* DFA::WorkqToCachedState(Workq* q, uint flag) {
// RunWorkqOnEmptyString or RunWorkqOnByte.
int* inst = new int[q->size()];
int n = 0;
uint needflags = 0; // flags needed by kInstEmptyWidth instructions
uint32 needflags = 0; // flags needed by kInstEmptyWidth instructions
bool sawmatch = false; // whether queue contains guaranteed kInstMatch
bool sawmark = false; // whether queue contains a Mark
bool sawmark = false; // whether queue contains a Mark
if (DebugDFA)
fprintf(stderr, "WorkqToCachedState %s [%#x]", DumpWorkq(q).c_str(), flag);
for (Workq::iterator it = q->begin(); it != q->end(); ++it) {
Expand Down Expand Up @@ -706,7 +706,7 @@ DFA::State* DFA::WorkqToCachedState(Workq* q, uint flag) {
// Looks in the State cache for a State matching inst, ninst, flag.
// If one is found, returns it. If one is not found, allocates one,
// inserts it in the cache, and returns it.
DFA::State* DFA::CachedState(int* inst, int ninst, uint flag) {
DFA::State* DFA::CachedState(int* inst, int ninst, uint32 flag) {
if (DEBUG_MODE)
mutex_.AssertHeld();

Expand Down Expand Up @@ -784,7 +784,7 @@ void DFA::StateToWorkq(State* s, Workq* q) {
}

// Adds ip to the work queue, following empty arrows according to flag.
void DFA::AddToQueue(Workq* q, int id, uint flag) {
void DFA::AddToQueue(Workq* q, int id, uint32 flag) {

// Use astack_ to hold our stack of instructions yet to process.
// It was preallocated as follows:
Expand Down Expand Up @@ -884,7 +884,7 @@ void DFA::AddToQueue(Workq* q, int id, uint flag) {
// and then processing only $. Doing the two-step sequence won't match
// ^$^$^$ but processing ^ and $ simultaneously will (and is the behavior
// exhibited by existing implementations).
void DFA::RunWorkqOnEmptyString(Workq* oldq, Workq* newq, uint flag) {
void DFA::RunWorkqOnEmptyString(Workq* oldq, Workq* newq, uint32 flag) {
newq->clear();
for (Workq::iterator i = oldq->begin(); i != oldq->end(); ++i) {
if (oldq->is_mark(*i))
Expand All @@ -899,7 +899,7 @@ void DFA::RunWorkqOnEmptyString(Workq* oldq, Workq* newq, uint flag) {
// means to match c$. Sets the bool *ismatch to true if the end of the
// regular expression program has been reached (the regexp has matched).
void DFA::RunWorkqOnByte(Workq* oldq, Workq* newq,
int c, uint flag, bool* ismatch,
int c, uint32 flag, bool* ismatch,
Prog::MatchKind kind) {
if (DEBUG_MODE)
mutex_.AssertHeld();
Expand Down Expand Up @@ -993,10 +993,10 @@ DFA::State* DFA::RunStateOnByte(State* state, int c) {
// around this byte. Before the byte we have the flags recorded
// in the State structure itself. After the byte we have
// nothing yet (but that will change: read on).
uint needflag = state->flag_ >> kFlagNeedShift;
uint beforeflag = state->flag_ & kFlagEmptyMask;
uint oldbeforeflag = beforeflag;
uint afterflag = 0;
uint32 needflag = state->flag_ >> kFlagNeedShift;
uint32 beforeflag = state->flag_ & kFlagEmptyMask;
uint32 oldbeforeflag = beforeflag;
uint32 afterflag = 0;

if (c == '\n') {
// Insert implicit $ and ^ around \n
Expand Down Expand Up @@ -1043,7 +1043,7 @@ DFA::State* DFA::RunStateOnByte(State* state, int c) {
}

// Save afterflag along with ismatch and isword in new state.
uint flag = afterflag;
uint32 flag = afterflag;
if (ismatch)
flag |= kFlagMatch;
if (isword)
Expand Down Expand Up @@ -1194,7 +1194,7 @@ class DFA::StateSaver {
DFA* dfa_; // the DFA to use
int* inst_; // saved info from State
int ninst_;
uint flag_;
uint32 flag_;
bool is_special_; // whether original state was special
State* special_; // if is_special_, the original state

Expand Down Expand Up @@ -1612,7 +1612,7 @@ bool DFA::AnalyzeSearch(SearchParams* params) {

// Determine correct search type.
int start;
uint flags;
uint32 flags;
if (params->run_forward) {
if (text.begin() == context.begin()) {
start = kStartBeginText;
Expand Down Expand Up @@ -1671,7 +1671,7 @@ bool DFA::AnalyzeSearch(SearchParams* params) {

// Fills in info if needed. Returns true on success, false on failure.
bool DFA::AnalyzeSearchHelper(SearchParams* params, StartInfo* info,
uint flags) {
uint32 flags) {
// Quick check.
int fb = info->firstbyte.load(std::memory_order_acquire);
if (fb != kFbUnknown)
Expand Down
2 changes: 1 addition & 1 deletion re2/testing/tester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static string FormatMode(Regexp::ParseFlags flags) {
for (int i = 0; i < arraysize(parse_modes); i++)
if (parse_modes[i].parse_flags == flags)
return parse_modes[i].desc;
return StringPrintf("%#x", static_cast<uint>(flags));
return StringPrintf("%#x", static_cast<uint32>(flags));
}

// Constructs and saves all the matching engines that
Expand Down
10 changes: 5 additions & 5 deletions util/sparse_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,19 +311,19 @@ template<typename Value>
bool SparseArray<Value>::has_index(int i) const {
DCHECK_GE(i, 0);
DCHECK_LT(i, max_size_);
if (static_cast<uint>(i) >= static_cast<uint>(max_size_)) {
if (static_cast<uint32>(i) >= static_cast<uint32>(max_size_)) {
return false;
}
// Unsigned comparison avoids checking sparse_to_dense_[i] < 0.
return (uint)sparse_to_dense_[i] < (uint)size_ &&
dense_[sparse_to_dense_[i]].index_ == i;
return (uint32)sparse_to_dense_[i] < (uint32)size_ &&
dense_[sparse_to_dense_[i]].index_ == i;
}

// Set the value at index i to v.
template<typename Value>
typename SparseArray<Value>::iterator SparseArray<Value>::set(int i, Value v) {
DebugCheckInvariants();
if (static_cast<uint>(i) >= static_cast<uint>(max_size_)) {
if (static_cast<uint32>(i) >= static_cast<uint32>(max_size_)) {
// Semantically, end() would be better here, but we already know
// the user did something stupid, so begin() insulates them from
// dereferencing an invalid pointer.
Expand Down Expand Up @@ -387,7 +387,7 @@ template<typename Value>
typename SparseArray<Value>::iterator
SparseArray<Value>::set_new(int i, Value v) {
DebugCheckInvariants();
if (static_cast<uint>(i) >= static_cast<uint>(max_size_)) {
if (static_cast<uint32>(i) >= static_cast<uint32>(max_size_)) {
// Semantically, end() would be better here, but we already know
// the user did something stupid, so begin() insulates them from
// dereferencing an invalid pointer.
Expand Down
8 changes: 4 additions & 4 deletions util/sparse_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ class SparseSet {
bool contains(int i) const {
DCHECK_GE(i, 0);
DCHECK_LT(i, max_size_);
if (static_cast<uint>(i) >= static_cast<uint>(max_size_)) {
if (static_cast<uint32>(i) >= static_cast<uint32>(max_size_)) {
return false;
}
// Unsigned comparison avoids checking sparse_to_dense_[i] < 0.
return (uint)sparse_to_dense_[i] < (uint)size_ &&
dense_[sparse_to_dense_[i]] == i;
return (uint32)sparse_to_dense_[i] < (uint32)size_ &&
dense_[sparse_to_dense_[i]] == i;
}

// Adds i to the set.
Expand All @@ -146,7 +146,7 @@ class SparseSet {
// Set the value at the new index i to v.
// Fast but unsafe: only use if contains(i) is false.
void insert_new(int i) {
if (static_cast<uint>(i) >= static_cast<uint>(max_size_)) {
if (static_cast<uint32>(i) >= static_cast<uint32>(max_size_)) {
// Semantically, end() would be better here, but we already know
// the user did something stupid, so begin() insulates them from
// dereferencing an invalid pointer.
Expand Down
2 changes: 0 additions & 2 deletions util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ typedef uint32_t uint32;
typedef int64_t int64;
typedef uint64_t uint64;

typedef unsigned int uint;

// DISALLOW_COPY_AND_ASSIGN disallows the copy and operator= functions.
// It goes in the private: declarations in a class.
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
Expand Down

0 comments on commit ead5eeb

Please sign in to comment.