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)
{
}
protected:
- double value;
+ double value;
};
/* byte string */
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);
}
: 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_)); }
/* 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 ()
{
}
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 */
{ 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)))
/* stack */
template <typename ELEM, int LIMIT>
-struct stack_t
+struct cff_stack_t
{
void init ()
{
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)
{
else
set_error ();
}
-
ELEM &push ()
{
if (likely (count < elements.length))
return Crap(ELEM);
}
}
-
void pop (unsigned int n)
{
if (likely (count >= n))
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 ()
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;
/* 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)
{
i = 0;
S::set_error ();
}
- return (unsigned)i;
+ return (unsigned) i;
}
void push_longint_from_substr (byte_str_ref_t& str_ref)
}
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 */
}
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;
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;
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;
};
template <typename ENV>
-struct interpreter_t {
-
+struct interpreter_t
+{
~interpreter_t() { fini (); }
void fini () { env.fini (); }