Skip to content

Commit

Permalink
XBGF transformations are grouped in the schema already
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@478 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Feb 19, 2009
1 parent 3b8912a commit 2704a8e
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 40 deletions.
102 changes: 83 additions & 19 deletions shared/xsd/xbgf.xsd
Expand Up @@ -30,16 +30,53 @@
</xsd:documentation>
</xsd:annotation>
<xsd:choice>
<!-- folding and unfolding -->
<xsd:element ref="xbgf:extract"/>
<xsd:group ref="xbgf:foldingtransformation"/>
<xsd:group ref="xbgf:refactoringtransformation"/>
<xsd:group ref="xbgf:increasingtransformation"/>
<xsd:group ref="xbgf:decreasingtransformation"/>
<xsd:group ref="xbgf:concreterevisingtransformation"/>
<xsd:group ref="xbgf:abstractrevisingtransformation"/>
<!-- labels, selectors and other decorative stuff -->
<xsd:element ref="xbgf:anonymize"/>
<xsd:element ref="xbgf:deanonymize"/>
<xsd:element ref="xbgf:designate"/>
<xsd:element ref="xbgf:unlabel"/>
<xsd:element ref="xbgf:reroot"/>
<!-- debug -->
<xsd:element ref="xbgf:dump"/>
<!-- unclear -->
<xsd:element ref="xbgf:rename"/>
<!-- deprecated -->
<xsd:element ref="xbgf:strip"/>
</xsd:choice>
</xsd:group>

<xsd:group name="foldingtransformation">
<xsd:annotation>
<xsd:documentation>
Here is a list of the XBGF transformations that perform
folding and unfolding activities.
</xsd:documentation>
</xsd:annotation>
<xsd:choice>
<xsd:element ref="xbgf:inline"/>
<xsd:element ref="xbgf:fold"/>
<xsd:element ref="xbgf:extract"/>
<xsd:element ref="xbgf:unfold"/>
<xsd:element ref="xbgf:fold"/>
<xsd:element ref="xbgf:abridge"/>
<xsd:element ref="xbgf:detour"/>
<xsd:element ref="xbgf:chain"/>
<xsd:element ref="xbgf:unchain"/>
<!-- other general refactorings -->
<xsd:element ref="xbgf:chain"/>
</xsd:choice>
</xsd:group>
<xsd:group name="refactoringtransformation">
<xsd:annotation>
<xsd:documentation>
Here is a list of the XBGF transformations that perform
other provably semantic-preserving refactorings
</xsd:documentation>
</xsd:annotation>
<xsd:choice>
<xsd:element ref="xbgf:massage"/>
<xsd:element ref="xbgf:factor"/>
<xsd:element ref="xbgf:distribute"/>
Expand All @@ -52,38 +89,65 @@
<xsd:element ref="xbgf:horizontal"/>
<xsd:element ref="xbgf:rassoc"/>
<xsd:element ref="xbgf:lassoc"/>
<!-- labels, selectors and other decorative stuff -->
<xsd:element ref="xbgf:anonymize"/>
<xsd:element ref="xbgf:deanonymize"/>
<xsd:element ref="xbgf:designate"/>
<xsd:element ref="xbgf:unlabel"/>
<xsd:element ref="xbgf:reroot"/>
<!-- semantics increasing (grammar lengthening) transformations -->
</xsd:choice>
</xsd:group>
<xsd:group name="increasingtransformation">
<xsd:annotation>
<xsd:documentation>
Here is a list of the XBGF transformations that
lenghten the grammar (increase semantics).
</xsd:documentation>
</xsd:annotation>
<xsd:choice>
<xsd:element ref="xbgf:add"/>
<xsd:element ref="xbgf:appear"/>
<xsd:element ref="xbgf:widen"/>
<xsd:element ref="xbgf:upgrade"/>
<xsd:element ref="xbgf:unite"/>
<!-- semantics decreasing (grammar shortening) transformations -->
</xsd:choice>
</xsd:group>
<xsd:group name="decreasingtransformation">
<xsd:annotation>
<xsd:documentation>
Here is a list of the XBGF transformations that
shorten the grammar (decrease semantics).
</xsd:documentation>
</xsd:annotation>
<xsd:choice>
<xsd:element ref="xbgf:remove"/>
<xsd:element ref="xbgf:disappear"/>
<xsd:element ref="xbgf:narrow"/>
<xsd:element ref="xbgf:downgrade"/>
<!-- transformations that only preserve abstract semantics -->
</xsd:choice>
</xsd:group>
<xsd:group name="concreterevisingtransformation">
<xsd:annotation>
<xsd:documentation>
Here is a list of the XBGF transformations that
preserve abstract semantics, but do not preserve
(break) concrete semantics.
</xsd:documentation>
</xsd:annotation>
<xsd:choice>
<xsd:element ref="xbgf:abstractize"/>
<xsd:element ref="xbgf:concretize"/>
<xsd:element ref="xbgf:permute"/>
<!-- semantics revising transformations -->
</xsd:choice>
</xsd:group>
<xsd:group name="abstractrevisingtransformation">
<xsd:annotation>
<xsd:documentation>
Here is a list of the XBGF transformations that
revise semantics, both abstract and concrete.
</xsd:documentation>
</xsd:annotation>
<xsd:choice>
<xsd:element ref="xbgf:define"/>
<xsd:element ref="xbgf:undefine"/>
<xsd:element ref="xbgf:redefine"/>
<xsd:element ref="xbgf:inject"/>
<xsd:element ref="xbgf:project"/>
<xsd:element ref="xbgf:replace"/>
<!-- the rest -->
<xsd:element ref="xbgf:dump"/>
<xsd:element ref="xbgf:rename"/>
<xsd:element ref="xbgf:strip"/>
</xsd:choice>
</xsd:group>

Expand Down
51 changes: 30 additions & 21 deletions topics/presentation/metrics/xbgf_detailed_overview.py
Expand Up @@ -28,15 +28,16 @@ def noi(filename):
return c

def report(keys,key,note):
print note,
s = note.replace('xbgf:','')
cx = 0
for x in keys:
cx += results[key][x]
if results[key][x]:
print '&',results[key][x],
s += '&'+`results[key][x]`
else:
print '& ---',
print '&'+`cx`+'\\\\'
s += '& ---'
if cx:
print s+'&'+`cx`+'\\\\'

if __name__ == "__main__":
if len(sys.argv) != 4:
Expand All @@ -45,9 +46,14 @@ def report(keys,key,note):
print ' xbgfover <xbgf.xsd> <lcf> <xbgfs-path>'
sys.exit(1)
xsd = ET.parse(sys.argv[1])
for x in xsd.findall('/*'):
if x.attrib.has_key('name'):
names.append(x.attrib['name'])
gn = 0
for x in xsd.findall('/xsd:group/xsd:choice'.replace('xsd:','{'+xsdns+'}')):
names.append([])
for y in x.findall('xsd:element'.replace('xsd:','{'+xsdns+'}')):
if y.attrib.has_key('ref'):
names[gn].append(y.attrib['ref'])
gn += 1
names.remove([])
lcf = ET.parse(sys.argv[2])
for x in lcf.findall('/target'):
name = x.findtext('name')
Expand All @@ -61,9 +67,10 @@ def report(keys,key,note):
results['NOI'] = {}
results['NOX'] = {}
for x in names:
results[x] = {}
for y in targets.keys():
results[x][y] = 0
for y in x:
results[y] = {}
for z in targets.keys():
results[y][z] = 0
for x in targets.keys():
results['LOC'][x] = 0
results['NOI'][x] = 0
Expand All @@ -74,24 +81,26 @@ def report(keys,key,note):
xbgf = ET.parse(path+y+'.xbgf')
results['NOX'][x] += len(xbgf.findall('/*'))
for z in names:
results[z][x] += len(xbgf.findall('/{'+xbgfns+'}'+z))
for x in names[:]:
used = False
for y in targets.keys():
if results[x][y]:
used = True
if not used:
print '%%',x,'not used in any XBGF script'
names.remove(x)
for q in z:
results[q][x] += len(xbgf.findall(q.replace('xbgf:','{'+xbgfns+'}')))
for x in names:
for y in x:
used = False
for z in targets.keys():
if results[y][z]:
used = True
if not used:
print '%%',y,'not used in any XBGF script'
sorted = targets.keys()[:]
sorted.sort()
print '\\begin{tabular}{l|'+('c|'*len(targets))+'|c}'
for x in sorted:
print '&\\textbf{'+x+'}',
print '&\\textbf{Total}\\\\\\hline'
for x in names:
report(sorted,x,'\\xbgfNumber{'+x+'}')
print '\\hline'
for y in x:
report(sorted,y,'\\xbgfNumber{'+y+'}')
print '\\hline'
print '\\end{tabular}'
sys.exit(0)

1 change: 1 addition & 0 deletions topics/transformation/xbgf/apps/xbgf/Makefile
Expand Up @@ -10,6 +10,7 @@ append.xbgf:
${tools}/appendxbgf append.xbgf \
../bgf/normalize.xbgf \
../bgf/rename.xbgf \
inline.xbgf \
rename.xbgf \
reroot.xbgf \
unchainF.xbgf \
Expand Down
13 changes: 13 additions & 0 deletions topics/transformation/xbgf/apps/xbgf/inline.xbgf
@@ -0,0 +1,13 @@
<xbgf:sequence
xmlns:bgf="http://planet-sl.org/bgf"
xmlns:xbgf="http://planet-sl.org/xbgf">
<xbgf:inline>foldingtransformation</xbgf:inline>
<xbgf:inline>refactoringtransformation</xbgf:inline>
<xbgf:inline>increasingtransformation</xbgf:inline>
<xbgf:inline>decreasingtransformation</xbgf:inline>
<xbgf:inline>concreterevisingtransformation</xbgf:inline>
<xbgf:inline>abstractrevisingtransformation</xbgf:inline>
<xbgf:distribute>
<nonterminal>transformation</nonterminal>
</xbgf:distribute>
</xbgf:sequence>

0 comments on commit 2704a8e

Please sign in to comment.