[feaLib] Implement explicit lookup references as calls

Before this change, the compiler had (essentially) implemented lookup
references by inlining the statements of the invoked lookup into the
current feature block. After this change, the lookup gets compiled
separately, and any call sites make explicit calls.
This commit is contained in:
Sascha Brawer 2016-01-07 08:57:34 +01:00
parent 7eee900ea3
commit e2405c9aef
3 changed files with 16 additions and 55 deletions

View File

@ -289,8 +289,7 @@ class LookupReferenceStatement(Statement):
self.location, self.lookup = (location, lookup)
def build(self, builder):
for s in self.lookup.statements:
s.build(builder)
builder.add_lookup_call(self.lookup.name)
class MarkBasePosStatement(Statement):

View File

@ -58,6 +58,11 @@ class Builder(object):
self.lookups_.append(result)
return result
def add_lookup_to_feature_(self, lookup, feature_name):
for script, lang in self.language_systems:
key = (script, lang, feature_name)
self.features_.setdefault(key, []).append(lookup)
def get_lookup_(self, location, builder_class):
if (self.cur_lookup_ and
type(self.cur_lookup_) == builder_class and
@ -79,9 +84,8 @@ class Builder(object):
if self.cur_feature_name_:
# We are starting a lookup rule inside a feature. This includes
# lookup rules inside named lookups inside features.
for script, lang in self.language_systems:
key = (script, lang, self.cur_feature_name_)
self.features_.setdefault(key, []).append(self.cur_lookup_)
self.add_lookup_to_feature_(self.cur_lookup_,
self.cur_feature_name_)
return self.cur_lookup_
def makeGDEF(self):
@ -285,6 +289,12 @@ class Builder(object):
self.cur_lookup_name_ = None
self.cur_lookup_ = None
def add_lookup_call(self, lookup_name):
assert lookup_name in self.named_lookups_, lookup_name
self.cur_lookup_ = None
lookup = self.named_lookups_[lookup_name]
self.add_lookup_to_feature_(lookup, self.cur_feature_name_)
def set_language(self, location, language, include_default, required):
assert(len(language) == 4)
if self.cur_lookup_name_:

View File

@ -23,12 +23,12 @@
<FeatureTag value="test"/>
<Feature>
<!-- LookupCount=1 -->
<LookupListIndex index="0" value="2"/>
<LookupListIndex index="0" value="1"/>
</Feature>
</FeatureRecord>
</FeatureList>
<LookupList>
<!-- LookupCount=3 -->
<!-- LookupCount=2 -->
<Lookup index="0">
<!-- LookupType=2 -->
<LookupFlag value="0"/>
@ -85,54 +85,6 @@
</SubstLookupRecord>
</ChainContextSubst>
</Lookup>
<Lookup index="2">
<!-- LookupType=6 -->
<LookupFlag value="0"/>
<!-- SubTableCount=1 -->
<ChainContextSubst index="0" Format="3">
<!-- BacktrackGlyphCount=3 -->
<BacktrackCoverage index="0">
<Glyph value="E"/>
</BacktrackCoverage>
<BacktrackCoverage index="1">
<Glyph value="D"/>
<Glyph value="d"/>
</BacktrackCoverage>
<BacktrackCoverage index="2">
<Glyph value="A"/>
<Glyph value="B"/>
<Glyph value="C"/>
<Glyph value="a"/>
<Glyph value="b"/>
<Glyph value="c"/>
</BacktrackCoverage>
<!-- InputGlyphCount=1 -->
<InputCoverage index="0">
<Glyph value="c_t"/>
</InputCoverage>
<!-- LookAheadGlyphCount=3 -->
<LookAheadCoverage index="0">
<Glyph value="V"/>
</LookAheadCoverage>
<LookAheadCoverage index="1">
<Glyph value="W"/>
<Glyph value="w"/>
</LookAheadCoverage>
<LookAheadCoverage index="2">
<Glyph value="X"/>
<Glyph value="Y"/>
<Glyph value="Z"/>
<Glyph value="x"/>
<Glyph value="y"/>
<Glyph value="z"/>
</LookAheadCoverage>
<!-- SubstCount=1 -->
<SubstLookupRecord index="0">
<SequenceIndex value="0"/>
<LookupListIndex value="0"/>
</SubstLookupRecord>
</ChainContextSubst>
</Lookup>
</LookupList>
</GSUB>