Imported Upstream version 2.6.4
[platform/upstream/harfbuzz.git] / src / hb-cff-interp-common.hh
index 72e9e06..780f618 100644 (file)
@@ -220,32 +220,22 @@ struct number_t
   void init () { set_real (0.0); }
   void fini () {}
 
-  void set_int (int v)       { value = (double) v; }
-  int to_int () const        { return (int) value; }
+  void set_int (int v)       { value = v; }
+  int to_int () const        { return value; }
 
   void set_fixed (int32_t v) { value = v / 65536.0; }
-  int32_t to_fixed () const  { return (int32_t) (value * 65536.0); }
+  int32_t to_fixed () const  { return value * 65536.0; }
 
-  void set_real (double v)      { value = v; }
+  void set_real (double v)   { value = v; }
   double to_real () const    { return value; }
 
-  int ceil () const          { return (int) ::ceil (value); }
-  int floor () const         { return (int) ::floor (value); }
-
   bool in_int_range () const
   { return ((double) (int16_t) to_int () == value); }
 
-  bool operator > (const number_t &n) const
-  { return value > n.to_real (); }
-
-  bool operator < (const number_t &n) const
-  { return n > *this; }
-
-  bool operator >= (const number_t &n) const
-  { return !(*this < n); }
-
-  bool operator <= (const number_t &n) const
-  { return !(*this > n); }
+  bool operator >  (const number_t &n) const { return value > n.to_real (); }
+  bool operator <  (const number_t &n) const { return n > *this; }
+  bool operator >= (const number_t &n) const { return !(*this < n); }
+  bool operator <= (const number_t &n) const { return !(*this > n); }
 
   const number_t &operator += (const number_t &n)
   {
@@ -255,7 +245,7 @@ struct number_t
   }
 
   protected:
-  double  value;
+  double value;
 };
 
 /* byte string */
@@ -272,11 +262,11 @@ struct UnsizedByteStr : UnsizedArrayOf <HBUINT8>
 
     HBUINT8 *p = c->allocate_size<HBUINT8> (1);
     if (unlikely (p == nullptr)) return_trace (false);
-    p->set (intOp);
+    *p = intOp;
 
     INTTYPE *ip = c->allocate_size<INTTYPE> (INTTYPE::static_size);
     if (unlikely (ip == nullptr)) return_trace (false);
-    ip->set ((unsigned int)value);
+    *ip = (unsigned int) value;
 
     return_trace (true);
   }
@@ -308,7 +298,7 @@ struct byte_str_t : hb_ubytes_t
     : hb_ubytes_t (s, l) {}
   byte_str_t (const hb_ubytes_t &ub)   /* conversion from hb_ubytes_t */
     : hb_ubytes_t (ub) {}
-  
+
   /* sub-string */
   byte_str_t sub_str (unsigned int offset, unsigned int len_) const
   { return byte_str_t (hb_ubytes_t::sub_array (offset, len_)); }
@@ -320,8 +310,7 @@ struct byte_str_t : hb_ubytes_t
 /* A byte string associated with the current offset and an error condition */
 struct byte_str_ref_t
 {
-  byte_str_ref_t ()
-  { init (); }
+  byte_str_ref_t () { init (); }
 
   void init ()
   {
@@ -343,13 +332,12 @@ struct byte_str_ref_t
   }
 
   const unsigned char& operator [] (int i) {
-    if (unlikely ((unsigned int)(offset + i) >= str.length))
+    if (unlikely ((unsigned int) (offset + i) >= str.length))
     {
       set_error ();
-      return Null(unsigned char);
+      return Null (unsigned char);
     }
-    else
-      return str[offset + i];
+    return str[offset + i];
   }
 
   /* Conversion to byte_str_t */
@@ -359,9 +347,7 @@ struct byte_str_ref_t
   { return str.sub_str (offset_, len_); }
 
   bool avail (unsigned int count=1) const
-  {
-    return (!in_error () && str.check_limit (offset, count));
-  }
+  { return (!in_error () && str.check_limit (offset, count)); }
   void inc (unsigned int count=1)
   {
     if (likely (!in_error () && (offset <= str.length) && (offset + count <= str.length)))
@@ -389,7 +375,7 @@ typedef hb_vector_t<byte_str_t> byte_str_array_t;
 
 /* stack */
 template <typename ELEM, int LIMIT>
-struct stack_t
+struct cff_stack_t
 {
   void init ()
   {
@@ -400,11 +386,7 @@ struct stack_t
     for (unsigned int i = 0; i < elements.length; i++)
       elements[i].init ();
   }
-
-  void fini ()
-  {
-    elements.fini_deep ();
-  }
+  void fini () { elements.fini_deep (); }
 
   ELEM& operator [] (unsigned int i)
   {
@@ -419,7 +401,6 @@ struct stack_t
     else
       set_error ();
   }
-
   ELEM &push ()
   {
     if (likely (count < elements.length))
@@ -441,7 +422,6 @@ struct stack_t
       return Crap(ELEM);
     }
   }
-
   void pop (unsigned int n)
   {
     if (likely (count >= n))
@@ -452,13 +432,12 @@ struct stack_t
 
   const ELEM& peek ()
   {
-    if (likely (count > 0))
-      return elements[count-1];
-    else
+    if (unlikely (count < 0))
     {
       set_error ();
       return Null(ELEM);
     }
+    return elements[count - 1];
   }
 
   void unpop ()
@@ -475,7 +454,7 @@ struct stack_t
   void set_error ()      { error = true; }
 
   unsigned int get_count () const { return count; }
-  bool is_empty () const { return count == 0; }
+  bool is_empty () const          { return !count; }
 
   static constexpr unsigned kSizeLimit = LIMIT;
 
@@ -487,7 +466,7 @@ struct stack_t
 
 /* argument stack */
 template <typename ARG=number_t>
-struct arg_stack_t : stack_t<ARG, 513>
+struct arg_stack_t : cff_stack_t<ARG, 513>
 {
   void push_int (int v)
   {
@@ -519,7 +498,7 @@ struct arg_stack_t : stack_t<ARG, 513>
       i = 0;
       S::set_error ();
     }
-    return (unsigned)i;
+    return (unsigned) i;
   }
 
   void push_longint_from_substr (byte_str_ref_t& str_ref)
@@ -538,12 +517,10 @@ struct arg_stack_t : stack_t<ARG, 513>
   }
 
   hb_array_t<const ARG> get_subarray (unsigned int start) const
-  {
-    return S::elements.sub_array (start);
-  }
+  { return S::elements.sub_array (start); }
 
   private:
-  typedef stack_t<ARG, 513> S;
+  typedef cff_stack_t<ARG, 513> S;
 };
 
 /* an operator prefixed by its operands in a byte string */
@@ -605,7 +582,7 @@ struct parsed_values_t
   }
 
   unsigned get_count () const { return values.length; }
-  const VAL &get_value (unsigned int i) const { return values[i]; }
+  const VAL &get_value (unsigned int i)   const { return values[i]; }
   const VAL &operator [] (unsigned int i) const { return get_value (i); }
 
   unsigned int       opStart;
@@ -644,30 +621,19 @@ struct interp_env_t
     return op;
   }
 
-  const ARG& eval_arg (unsigned int i)
-  {
-    return argStack[i];
-  }
-
-  ARG& pop_arg ()
-  {
-    return argStack.pop ();
-  }
+  const ARG& eval_arg (unsigned int i) { return argStack[i]; }
 
-  void pop_n_args (unsigned int n)
-  {
-    argStack.pop (n);
-  }
+  ARG& pop_arg () { return argStack.pop (); }
+  void pop_n_args (unsigned int n) { argStack.pop (n); }
 
-  void clear_args ()
-  {
-    pop_n_args (argStack.get_count ());
-  }
+  void clear_args () { pop_n_args (argStack.get_count ()); }
 
-  byte_str_ref_t    str_ref;
-  arg_stack_t<ARG> argStack;
+  byte_str_ref_t
+               str_ref;
+  arg_stack_t<ARG>
+               argStack;
   protected:
-  bool   error;
+  bool         error;
 };
 
 typedef interp_env_t<> num_interp_env_t;
@@ -691,7 +657,7 @@ struct opset_t
 
       case OpCode_TwoByteNegInt0: case OpCode_TwoByteNegInt1:
       case OpCode_TwoByteNegInt2: case OpCode_TwoByteNegInt3:
-       env.argStack.push_int ((int16_t)(-(op - OpCode_TwoByteNegInt0) * 256 - env.str_ref[0] - 108));
+       env.argStack.push_int ((-(int16_t)(op - OpCode_TwoByteNegInt0) * 256 - env.str_ref[0] - 108));
        env.str_ref.inc ();
        break;
 
@@ -711,8 +677,8 @@ struct opset_t
 };
 
 template <typename ENV>
-struct interpreter_t {
-
+struct interpreter_t
+{
   ~interpreter_t() { fini (); }
 
   void fini () { env.fini (); }