Tidy up more integral types.

For #65.

Change-Id: Ifabf53a3105eedccf0d84ce89be53c8cbc99d65f
Reviewed-on: https://code-review.googlesource.com/3811
Reviewed-by: Paul Wankadia <junyer@google.com>
diff --git a/re2/bitstate.cc b/re2/bitstate.cc
index 8ced6ea..5740daa 100644
--- a/re2/bitstate.cc
+++ b/re2/bitstate.cc
@@ -94,7 +94,7 @@
 // If so, remember that it was visited so that the next time,
 // we don't repeat the visit.
 bool BitState::ShouldVisit(int id, const char* p) {
-  uint n = id * (text_.size() + 1) + (p - text_.begin());
+  size_t n = id * (text_.size() + 1) + (p - text_.begin());
   if (visited_[n/VisitedBits] & (1 << (n & (VisitedBits-1))))
     return false;
   visited_[n/VisitedBits] |= 1 << (n & (VisitedBits-1));
@@ -272,7 +272,8 @@
         if (submatch_[0].data() == NULL ||
             (longest_ && p > submatch_[0].end())) {
           for (int i = 0; i < nsubmatch_; i++)
-            submatch_[i] = StringPiece(cap_[2*i], cap_[2*i+1] - cap_[2*i]);
+            submatch_[i].set(cap_[2*i],
+                             static_cast<int>(cap_[2*i+1] - cap_[2*i]));
         }
 
         // If going for first match, we're done.
diff --git a/re2/dfa.cc b/re2/dfa.cc
index b102175..7801e07 100644
--- a/re2/dfa.cc
+++ b/re2/dfa.cc
@@ -1901,9 +1901,9 @@
   // as the beginning.
   if (match0) {
     if (reversed_)
-      *match0 = StringPiece(ep, text.end() - ep);
+      match0->set(ep, static_cast<int>(text.end() - ep));
     else
-      *match0 = StringPiece(text.begin(), ep - text.begin());
+      match0->set(text.begin(), static_cast<int>(ep - text.begin()));
   }
   return true;
 }
@@ -1939,7 +1939,7 @@
     }
   }
 
-  return q.size();
+  return static_cast<int>(q.size());
 }
 
 // Build out all states in DFA for kind.  Returns number of states.
diff --git a/re2/filtered_re2.cc b/re2/filtered_re2.cc
index 1ca46d4..5dd65d5 100644
--- a/re2/filtered_re2.cc
+++ b/re2/filtered_re2.cc
@@ -33,7 +33,7 @@
     }
     delete re;
   } else {
-    *id = re2_vec_.size();
+    *id = static_cast<int>(re2_vec_.size());
     re2_vec_.push_back(re);
   }
 
diff --git a/re2/filtered_re2.h b/re2/filtered_re2.h
index 0f161e2..f4b2be4 100644
--- a/re2/filtered_re2.h
+++ b/re2/filtered_re2.h
@@ -76,7 +76,7 @@
                      vector<int>* potential_regexps) const;
 
   // The number of regexps added.
-  int NumRegexps() const { return re2_vec_.size(); }
+  int NumRegexps() const { return static_cast<int>(re2_vec_.size()); }
 
  private:
 
diff --git a/re2/nfa.cc b/re2/nfa.cc
index 3ca275e..bc8996c 100644
--- a/re2/nfa.cc
+++ b/re2/nfa.cc
@@ -608,7 +608,8 @@
 
   if (matched_) {
     for (int i = 0; i < nsubmatch; i++)
-      submatch[i].set(match_[2*i], match_[2*i+1] - match_[2*i]);
+      submatch[i].set(match_[2*i],
+                      static_cast<int>(match_[2*i+1] - match_[2*i]));
     if (Debug)
       fprintf(stderr, "match (%d,%d)\n",
               static_cast<int>(match_[0] - btext_),
diff --git a/re2/onepass.cc b/re2/onepass.cc
index 2404617..73acdc8 100644
--- a/re2/onepass.cc
+++ b/re2/onepass.cc
@@ -331,7 +331,8 @@
   if (!matched)
     return false;
   for (int i = 0; i < nmatch; i++)
-    match[i].set(matchcap[2*i], matchcap[2*i+1] - matchcap[2*i]);
+    match[i].set(matchcap[2*i],
+                 static_cast<int>(matchcap[2*i+1] - matchcap[2*i]));
   return true;
 }
 
diff --git a/re2/prog.h b/re2/prog.h
index 3e6be8f..8c5b2c4 100644
--- a/re2/prog.h
+++ b/re2/prog.h
@@ -96,7 +96,7 @@
     void InitFail();
 
     // Getters
-    int id(Prog* p) { return this - p->inst_; }
+    int id(Prog* p) { return static_cast<int>(this - p->inst_); }
     InstOp opcode() { return static_cast<InstOp>(out_opcode_&7); }
     int out()     { return out_opcode_>>3; }
     int out1()    { DCHECK(opcode() == kInstAlt || opcode() == kInstAltMatch); return out1_; }
diff --git a/re2/regexp.cc b/re2/regexp.cc
index d3aa1f0..7bb8390 100644
--- a/re2/regexp.cc
+++ b/re2/regexp.cc
@@ -453,10 +453,11 @@
         continue;
     }
 
-    int n = stk.size();
+    size_t n = stk.size();
     if (n == 0)
       break;
 
+    DCHECK_GE(n, 2);
     a = stk[n-2];
     b = stk[n-1];
     stk.resize(n-2);
diff --git a/re2/set.cc b/re2/set.cc
index 5363ef7..a1a84ba 100644
--- a/re2/set.cc
+++ b/re2/set.cc
@@ -45,7 +45,7 @@
   }
 
   // Concatenate with match index and push on vector.
-  int n = re_.size();
+  int n = static_cast<int>(re_.size());
   re2::Regexp* m = re2::Regexp::HaveMatch(n, pf);
   if (re->op() == kRegexpConcat) {
     int nsub = re->nsub();
@@ -76,7 +76,7 @@
   Regexp::ParseFlags pf = static_cast<Regexp::ParseFlags>(
     options_.ParseFlags());
   re2::Regexp* re = re2::Regexp::Alternate(const_cast<re2::Regexp**>(re_.data()),
-                                           re_.size(), pf);
+                                           static_cast<int>(re_.size()), pf);
   re_.clear();
   re2::Regexp* sre = re->Simplify();
   re->Decref();
diff --git a/re2/testing/backtrack.cc b/re2/testing/backtrack.cc
index b2dd6db..a872840 100644
--- a/re2/testing/backtrack.cc
+++ b/re2/testing/backtrack.cc
@@ -72,7 +72,7 @@
   // Search state
   const char* cap_[64];     // capture registers
   uint32 *visited_;         // bitmap: (Inst*, char*) pairs already backtracked
-  int nvisited_;            //   # of words in bitmap
+  size_t nvisited_;         //   # of words in bitmap
 };
 
 Backtracker::Backtracker(Prog* prog)
@@ -150,7 +150,7 @@
   // either it didn't match or it did but we're hoping for a better match.
   // Either way, don't go down that road again.
   CHECK(p <= text_.end());
-  int n = id*(text_.size()+1) + (p - text_.begin());
+  size_t n = id*(text_.size()+1) + (p - text_.begin());
   CHECK_LT(n/32, nvisited_);
   if (visited_[n/32] & (1 << (n&31)))
     return false;
@@ -212,7 +212,8 @@
       if (submatch_[0].data() == NULL ||           // First match so far ...
           (longest_ && p > submatch_[0].end())) {  // ... or better match
         for (int i = 0; i < nsubmatch_; i++)
-          submatch_[i] = StringPiece(cap_[2*i], cap_[2*i+1] - cap_[2*i]);
+          submatch_[i].set(cap_[2*i],
+                           static_cast<int>(cap_[2*i+1] - cap_[2*i]));
       }
       return true;