substr renamed to str_ref in line with its type byte_str_ref_t

This commit is contained in:
Michiharu Ariza 2018-12-20 14:54:33 -08:00
parent e3de0c8420
commit abebca2690
9 changed files with 73 additions and 73 deletions

View File

@ -522,18 +522,18 @@ struct ArgStack : Stack<ARG, 513>
return (unsigned)i; return (unsigned)i;
} }
void push_longint_from_substr (byte_str_ref_t& substr) void push_longint_from_substr (byte_str_ref_t& str_ref)
{ {
push_int ((substr[0] << 24) | (substr[1] << 16) | (substr[2] << 8) | (substr[3])); push_int ((str_ref[0] << 24) | (str_ref[1] << 16) | (str_ref[2] << 8) | (str_ref[3]));
substr.inc (4); str_ref.inc (4);
} }
bool push_fixed_from_substr (byte_str_ref_t& substr) bool push_fixed_from_substr (byte_str_ref_t& str_ref)
{ {
if (unlikely (!substr.avail (4))) if (unlikely (!str_ref.avail (4)))
return false; return false;
push_fixed ((int32_t)*(const HBUINT32*)&substr[0]); push_fixed ((int32_t)*(const HBUINT32*)&str_ref[0]);
substr.inc (4); str_ref.inc (4);
return true; return true;
} }
@ -581,20 +581,20 @@ struct ParsedValues
} }
void fini () { values.fini_deep (); } void fini () { values.fini_deep (); }
void add_op (OpCode op, const byte_str_ref_t& substr = byte_str_ref_t ()) void add_op (OpCode op, const byte_str_ref_t& str_ref = byte_str_ref_t ())
{ {
VAL *val = values.push (); VAL *val = values.push ();
val->op = op; val->op = op;
val->str = substr.str.sub_str (opStart, substr.offset - opStart); val->str = str_ref.str.sub_str (opStart, str_ref.offset - opStart);
opStart = substr.offset; opStart = str_ref.offset;
} }
void add_op (OpCode op, const byte_str_ref_t& substr, const VAL &v) void add_op (OpCode op, const byte_str_ref_t& str_ref, const VAL &v)
{ {
VAL *val = values.push (v); VAL *val = values.push (v);
val->op = op; val->op = op;
val->str = substr.sub_str ( opStart, substr.offset - opStart); val->str = str_ref.sub_str ( opStart, str_ref.offset - opStart);
opStart = substr.offset; opStart = str_ref.offset;
} }
bool has_op (OpCode op) const bool has_op (OpCode op) const
@ -617,30 +617,30 @@ struct InterpEnv
{ {
void init (const byte_str_t &str_) void init (const byte_str_t &str_)
{ {
substr.reset (str_); str_ref.reset (str_);
argStack.init (); argStack.init ();
error = false; error = false;
} }
void fini () { argStack.fini (); } void fini () { argStack.fini (); }
bool in_error () const bool in_error () const
{ return error || substr.in_error () || argStack.in_error (); } { return error || str_ref.in_error () || argStack.in_error (); }
void set_error () { error = true; } void set_error () { error = true; }
OpCode fetch_op () OpCode fetch_op ()
{ {
OpCode op = OpCode_Invalid; OpCode op = OpCode_Invalid;
if (unlikely (!substr.avail ())) if (unlikely (!str_ref.avail ()))
return OpCode_Invalid; return OpCode_Invalid;
op = (OpCode)(unsigned char)substr[0]; op = (OpCode)(unsigned char)str_ref[0];
if (op == OpCode_escape) { if (op == OpCode_escape) {
if (unlikely (!substr.avail ())) if (unlikely (!str_ref.avail ()))
return OpCode_Invalid; return OpCode_Invalid;
op = Make_OpCode_ESC(substr[1]); op = Make_OpCode_ESC(str_ref[1]);
substr.inc (); str_ref.inc ();
} }
substr.inc (); str_ref.inc ();
return op; return op;
} }
@ -664,7 +664,7 @@ struct InterpEnv
pop_n_args (argStack.get_count ()); pop_n_args (argStack.get_count ());
} }
byte_str_ref_t substr; byte_str_ref_t str_ref;
ArgStack<ARG> argStack; ArgStack<ARG> argStack;
protected: protected:
bool error; bool error;
@ -679,20 +679,20 @@ struct OpSet
{ {
switch (op) { switch (op) {
case OpCode_shortint: case OpCode_shortint:
env.argStack.push_int ((int16_t)((env.substr[0] << 8) | env.substr[1])); env.argStack.push_int ((int16_t)((env.str_ref[0] << 8) | env.str_ref[1]));
env.substr.inc (2); env.str_ref.inc (2);
break; break;
case OpCode_TwoBytePosInt0: case OpCode_TwoBytePosInt1: case OpCode_TwoBytePosInt0: case OpCode_TwoBytePosInt1:
case OpCode_TwoBytePosInt2: case OpCode_TwoBytePosInt3: case OpCode_TwoBytePosInt2: case OpCode_TwoBytePosInt3:
env.argStack.push_int ((int16_t)((op - OpCode_TwoBytePosInt0) * 256 + env.substr[0] + 108)); env.argStack.push_int ((int16_t)((op - OpCode_TwoBytePosInt0) * 256 + env.str_ref[0] + 108));
env.substr.inc (); env.str_ref.inc ();
break; break;
case OpCode_TwoByteNegInt0: case OpCode_TwoByteNegInt1: case OpCode_TwoByteNegInt0: case OpCode_TwoByteNegInt1:
case OpCode_TwoByteNegInt2: case OpCode_TwoByteNegInt3: case OpCode_TwoByteNegInt2: case OpCode_TwoByteNegInt3:
env.argStack.push_int ((int16_t)(-(op - OpCode_TwoByteNegInt0) * 256 - env.substr[0] - 108)); env.argStack.push_int ((int16_t)(-(op - OpCode_TwoByteNegInt0) * 256 - env.str_ref[0] - 108));
env.substr.inc (); env.str_ref.inc ();
break; break;
default: default:

View File

@ -43,14 +43,14 @@ struct CallContext
{ {
void init (const byte_str_ref_t substr_=byte_str_ref_t (), CSType type_=CSType_CharString, unsigned int subr_num_=0) void init (const byte_str_ref_t substr_=byte_str_ref_t (), CSType type_=CSType_CharString, unsigned int subr_num_=0)
{ {
substr = substr_; str_ref = substr_;
type = type_; type = type_;
subr_num = subr_num_; subr_num = subr_num_;
} }
void fini () {} void fini () {}
byte_str_ref_t substr; byte_str_ref_t str_ref;
CSType type; CSType type;
unsigned int subr_num; unsigned int subr_num;
}; };
@ -167,19 +167,19 @@ struct CSInterpEnv : InterpEnv<ARG>
SUPER::set_error (); SUPER::set_error ();
return; return;
} }
context.substr = SUPER::substr; context.str_ref = SUPER::str_ref;
callStack.push (context); callStack.push (context);
context.init ( biasedSubrs[subr_num], type, subr_num); context.init ( biasedSubrs[subr_num], type, subr_num);
SUPER::substr = context.substr; SUPER::str_ref = context.str_ref;
} }
void returnFromSubr () void returnFromSubr ()
{ {
if (unlikely (SUPER::substr.in_error ())) if (unlikely (SUPER::str_ref.in_error ()))
SUPER::set_error (); SUPER::set_error ();
context = callStack.pop (); context = callStack.pop ();
SUPER::substr = context.substr; SUPER::str_ref = context.str_ref;
} }
void determine_hintmask_size () void determine_hintmask_size ()
@ -262,7 +262,7 @@ struct CSOpSet : OpSet<ARG>
break; break;
case OpCode_fixedcs: case OpCode_fixedcs:
env.argStack.push_fixed_from_substr (env.substr); env.argStack.push_fixed_from_substr (env.str_ref);
break; break;
case OpCode_callsubr: case OpCode_callsubr:
@ -385,10 +385,10 @@ struct CSOpSet : OpSet<ARG>
static void process_hintmask (OpCode op, ENV &env, PARAM& param) static void process_hintmask (OpCode op, ENV &env, PARAM& param)
{ {
env.determine_hintmask_size (); env.determine_hintmask_size ();
if (likely (env.substr.avail (env.hintmask_size))) if (likely (env.str_ref.avail (env.hintmask_size)))
{ {
OPSET::flush_hintmask (op, env, param); OPSET::flush_hintmask (op, env, param);
env.substr.inc (env.hintmask_size); env.str_ref.inc (env.hintmask_size);
} }
} }

View File

@ -81,11 +81,11 @@ struct DictOpSet : OpSet<Number>
{ {
switch (op) { switch (op) {
case OpCode_longintdict: /* 5-byte integer */ case OpCode_longintdict: /* 5-byte integer */
env.argStack.push_longint_from_substr (env.substr); env.argStack.push_longint_from_substr (env.str_ref);
break; break;
case OpCode_BCD: /* real number */ case OpCode_BCD: /* real number */
env.argStack.push_real (parse_bcd (env.substr)); env.argStack.push_real (parse_bcd (env.str_ref));
break; break;
default: default:
@ -94,7 +94,7 @@ struct DictOpSet : OpSet<Number>
} }
} }
static double parse_bcd (byte_str_ref_t& substr) static double parse_bcd (byte_str_ref_t& str_ref)
{ {
bool neg = false; bool neg = false;
double int_part = 0; double int_part = 0;
@ -115,13 +115,13 @@ struct DictOpSet : OpSet<Number>
char d; char d;
if ((i & 1) == 0) if ((i & 1) == 0)
{ {
if (!substr.avail ()) if (!str_ref.avail ())
{ {
substr.set_error (); str_ref.set_error ();
return 0.0; return 0.0;
} }
byte = substr[0]; byte = str_ref[0];
substr.inc (); str_ref.inc ();
d = byte >> 4; d = byte >> 4;
} }
else else
@ -130,7 +130,7 @@ struct DictOpSet : OpSet<Number>
switch (d) switch (d)
{ {
case RESERVED: case RESERVED:
substr.set_error (); str_ref.set_error ();
return value; return value;
case END: case END:
@ -162,7 +162,7 @@ struct DictOpSet : OpSet<Number>
case NEG: case NEG:
if (i != 0) if (i != 0)
{ {
substr.set_error (); str_ref.set_error ();
return 0.0; return 0.0;
} }
neg = true; neg = true;
@ -171,7 +171,7 @@ struct DictOpSet : OpSet<Number>
case DECIMAL: case DECIMAL:
if (part != INT_PART) if (part != INT_PART)
{ {
substr.set_error (); str_ref.set_error ();
return value; return value;
} }
part = FRAC_PART; part = FRAC_PART;
@ -184,7 +184,7 @@ struct DictOpSet : OpSet<Number>
case EXP_POS: case EXP_POS:
if (part == EXP_PART) if (part == EXP_PART)
{ {
substr.set_error (); str_ref.set_error ();
return value; return value;
} }
part = EXP_PART; part = EXP_PART;
@ -275,7 +275,7 @@ struct DictInterpreter : Interpreter<ENV>
bool interpret (PARAM& param) bool interpret (PARAM& param)
{ {
param.init (); param.init ();
while (SUPER::env.substr.avail ()) while (SUPER::env.str_ref.avail ())
{ {
OPSET::process_op (SUPER::env.fetch_op (), SUPER::env, param); OPSET::process_op (SUPER::env.fetch_op (), SUPER::env, param);
if (unlikely (SUPER::env.in_error ())) if (unlikely (SUPER::env.in_error ()))

View File

@ -102,7 +102,7 @@ struct CFF2CSInterpEnv : CSInterpEnv<BlendArg, CFF2Subrs>
OpCode fetch_op () OpCode fetch_op ()
{ {
if (this->substr.avail ()) if (this->str_ref.avail ())
return SUPER::fetch_op (); return SUPER::fetch_op ();
/* make up return or endchar op */ /* make up return or endchar op */

View File

@ -794,7 +794,7 @@ struct CFF1TopDictOpSet : TopDictOpSet<CFF1TopDictVal>
break; break;
default: default:
env.last_offset = env.substr.offset; env.last_offset = env.str_ref.offset;
TopDictOpSet<CFF1TopDictVal>::process_op (op, env, dictval); TopDictOpSet<CFF1TopDictVal>::process_op (op, env, dictval);
/* Record this operand below if stack is empty, otherwise done */ /* Record this operand below if stack is empty, otherwise done */
if (!env.argStack.is_empty ()) return; if (!env.argStack.is_empty ()) return;
@ -803,7 +803,7 @@ struct CFF1TopDictOpSet : TopDictOpSet<CFF1TopDictVal>
if (unlikely (env.in_error ())) return; if (unlikely (env.in_error ())) return;
dictval.add_op (op, env.substr, val); dictval.add_op (op, env.str_ref, val);
} }
}; };
@ -848,7 +848,7 @@ struct CFF1FontDictOpSet : DictOpSet
if (unlikely (env.in_error ())) return; if (unlikely (env.in_error ())) return;
dictval.add_op (op, env.substr); dictval.add_op (op, env.str_ref);
} }
}; };
@ -924,7 +924,7 @@ struct CFF1PrivateDictOpSet : DictOpSet
if (unlikely (env.in_error ())) return; if (unlikely (env.in_error ())) return;
dictval.add_op (op, env.substr, val); dictval.add_op (op, env.str_ref, val);
} }
}; };
@ -966,7 +966,7 @@ struct CFF1PrivateDictOpSet_Subset : DictOpSet
if (unlikely (env.in_error ())) return; if (unlikely (env.in_error ())) return;
dictval.add_op (op, env.substr); dictval.add_op (op, env.str_ref);
} }
}; };

View File

@ -179,7 +179,7 @@ struct CFF2TopDictOpSet : TopDictOpSet<>
{ {
DictVal val; DictVal val;
val.init (); val.init ();
dictval.add_op (op, env.substr); dictval.add_op (op, env.str_ref);
env.clear_args (); env.clear_args ();
} }
break; break;
@ -201,7 +201,7 @@ struct CFF2TopDictOpSet : TopDictOpSet<>
if (unlikely (env.in_error ())) return; if (unlikely (env.in_error ())) return;
dictval.add_op (op, env.substr); dictval.add_op (op, env.str_ref);
} }
typedef TopDictOpSet<> SUPER; typedef TopDictOpSet<> SUPER;
@ -238,7 +238,7 @@ struct CFF2FontDictOpSet : DictOpSet
if (unlikely (env.in_error ())) return; if (unlikely (env.in_error ())) return;
dictval.add_op (op, env.substr); dictval.add_op (op, env.str_ref);
} }
private: private:
@ -348,7 +348,7 @@ struct CFF2PrivateDictOpSet : DictOpSet
if (unlikely (env.in_error ())) return; if (unlikely (env.in_error ())) return;
dictval.add_op (op, env.substr, val); dictval.add_op (op, env.str_ref, val);
} }
}; };
@ -390,7 +390,7 @@ struct CFF2PrivateDictOpSet_Subset : DictOpSet
if (unlikely (env.in_error ())) return; if (unlikely (env.in_error ())) return;
dictval.add_op (op, env.substr); dictval.add_op (op, env.str_ref);
} }
private: private:

View File

@ -403,13 +403,13 @@ struct ParsedCStr : ParsedValues<ParsedCSOp>
has_prefix_ = false; has_prefix_ = false;
} }
void add_op (OpCode op, const byte_str_ref_t& substr) void add_op (OpCode op, const byte_str_ref_t& str_ref)
{ {
if (!is_parsed ()) if (!is_parsed ())
SUPER::add_op (op, substr); SUPER::add_op (op, str_ref);
} }
void add_call_op (OpCode op, const byte_str_ref_t& substr, unsigned int subr_num) void add_call_op (OpCode op, const byte_str_ref_t& str_ref, unsigned int subr_num)
{ {
if (!is_parsed ()) if (!is_parsed ())
{ {
@ -419,7 +419,7 @@ struct ParsedCStr : ParsedValues<ParsedCSOp>
ParsedCSOp val; ParsedCSOp val;
val.init (subr_num); val.init (subr_num);
SUPER::add_op (op, substr, val); SUPER::add_op (op, str_ref, val);
} }
} }

View File

@ -315,7 +315,7 @@ struct CFF1CSOpSet_Flatten : CFF1CSOpSet<CFF1CSOpSet_Flatten, FlattenParam>
{ {
StrEncoder encoder (param.flatStr); StrEncoder encoder (param.flatStr);
for (unsigned int i = 0; i < env.hintmask_size; i++) for (unsigned int i = 0; i < env.hintmask_size; i++)
encoder.encode_byte (env.substr[i]); encoder.encode_byte (env.str_ref[i]);
} }
} }
@ -349,14 +349,14 @@ struct CFF1CSOpSet_SubrSubset : CFF1CSOpSet<CFF1CSOpSet_SubrSubset, SubrSubsetPa
switch (op) { switch (op) {
case OpCode_return: case OpCode_return:
param.current_parsed_str->add_op (op, env.substr); param.current_parsed_str->add_op (op, env.str_ref);
param.current_parsed_str->set_parsed (); param.current_parsed_str->set_parsed ();
env.returnFromSubr (); env.returnFromSubr ();
param.set_current_str (env, false); param.set_current_str (env, false);
break; break;
case OpCode_endchar: case OpCode_endchar:
param.current_parsed_str->add_op (op, env.substr); param.current_parsed_str->add_op (op, env.str_ref);
param.current_parsed_str->set_parsed (); param.current_parsed_str->set_parsed ();
SUPER::process_op (op, env, param); SUPER::process_op (op, env, param);
break; break;
@ -371,7 +371,7 @@ struct CFF1CSOpSet_SubrSubset : CFF1CSOpSet<CFF1CSOpSet_SubrSubset, SubrSubsetPa
default: default:
SUPER::process_op (op, env, param); SUPER::process_op (op, env, param);
param.current_parsed_str->add_op (op, env.substr); param.current_parsed_str->add_op (op, env.str_ref);
break; break;
} }
} }
@ -381,9 +381,9 @@ struct CFF1CSOpSet_SubrSubset : CFF1CSOpSet<CFF1CSOpSet_SubrSubset, SubrSubsetPa
CFF1CSInterpEnv &env, SubrSubsetParam& param, CFF1CSInterpEnv &env, SubrSubsetParam& param,
CFF1BiasedSubrs& subrs, hb_set_t *closure) CFF1BiasedSubrs& subrs, hb_set_t *closure)
{ {
byte_str_ref_t substr = env.substr; byte_str_ref_t str_ref = env.str_ref;
env.callSubr (subrs, type); env.callSubr (subrs, type);
param.current_parsed_str->add_call_op (op, substr, env.context.subr_num); param.current_parsed_str->add_call_op (op, str_ref, env.context.subr_num);
hb_set_add (closure, env.context.subr_num); hb_set_add (closure, env.context.subr_num);
param.set_current_str (env, true); param.set_current_str (env, true);
} }

View File

@ -202,7 +202,7 @@ struct CFF2CSOpSet_SubrSubset : CFF2CSOpSet<CFF2CSOpSet_SubrSubset, SubrSubsetPa
default: default:
SUPER::process_op (op, env, param); SUPER::process_op (op, env, param);
param.current_parsed_str->add_op (op, env.substr); param.current_parsed_str->add_op (op, env.str_ref);
break; break;
} }
} }
@ -212,9 +212,9 @@ struct CFF2CSOpSet_SubrSubset : CFF2CSOpSet<CFF2CSOpSet_SubrSubset, SubrSubsetPa
CFF2CSInterpEnv &env, SubrSubsetParam& param, CFF2CSInterpEnv &env, SubrSubsetParam& param,
CFF2BiasedSubrs& subrs, hb_set_t *closure) CFF2BiasedSubrs& subrs, hb_set_t *closure)
{ {
byte_str_ref_t substr = env.substr; byte_str_ref_t str_ref = env.str_ref;
env.callSubr (subrs, type); env.callSubr (subrs, type);
param.current_parsed_str->add_call_op (op, substr, env.context.subr_num); param.current_parsed_str->add_call_op (op, str_ref, env.context.subr_num);
hb_set_add (closure, env.context.subr_num); hb_set_add (closure, env.context.subr_num);
param.set_current_str (env, true); param.set_current_str (env, true);
} }