Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@611 ab42f6e0-554d-0410-b580-99e487e6eeb2
- Loading branch information
1 parent
4ce8738
commit cf17e9b
Showing
9 changed files
with
253 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,17 @@ | ||
#!/usr/bin/python | ||
import os | ||
import sys | ||
|
||
productions = "count(/*/*[local-name()='production'])" | ||
nonterminals = "count(/*[local-name()='grammar']/*/nonterminal[not(text()=../preceding-sibling::*/nonterminal/text())])" | ||
top = "count(/*/*/nonterminal[not(text()=/*/*/*//nonterminal/text()) and not(text()=../preceding-sibling::*/nonterminal/text())])" | ||
listtop = "/*/*/nonterminal[not(text()=/*/*/*//nonterminal/text()) and not(text()=../preceding-sibling::*/nonterminal/text())]" | ||
bottom = " | (echo '<set>' ; xpath '//nonterminal[not(text()=/*/*/nonterminal/text())]' 2> /dev/null; echo '</set>' )| xpath 'count(//nonterminal[not(text()=preceding-sibling::*/text())])' " | ||
listbottom = "//nonterminal[not(text()=/*/*/nonterminal/text())]" | ||
unique = " | (echo '<set>' ; xpath '//nonterminal' 2> /dev/null; echo '</set>' )| xpath 'count(//nonterminal[not(text()=preceding-sibling::*/text())])' " | ||
|
||
def runxpath(filename,xpathexpr): | ||
os.system('xpath '+filename+' "'+xpathexpr+'" 1>TMP-res 2>/dev/null') | ||
tmp = open('TMP-res','r') | ||
res = tmp.readline().strip() | ||
tmp.close() | ||
return res | ||
|
||
def runxpathlist(filename,xpathexpr): | ||
os.system('xpath '+filename+' "'+xpathexpr+'" 1>TMP-res 2>/dev/null') | ||
tmp = open('TMP-res','r') | ||
resa = tmp.readline().strip().split('<nonterminal>') | ||
resu = [] | ||
for x in resa: | ||
if x not in resu: | ||
resu.append(x) | ||
resu.sort() | ||
return ''.join(resu).replace('</nonterminal>',', ')[:-2] | ||
tmp.close() | ||
res = res.replace('<nonterminal>','').replace('</nonterminal>',', ') | ||
return res[:-2] | ||
|
||
def runxpath2(filename,xpathexpr): | ||
os.system('cat '+filename+xpathexpr+' 1>TMP-res 2>/dev/null') | ||
tmp = open('TMP-res','r') | ||
res = tmp.readline().strip() | ||
tmp.close() | ||
return res | ||
import slpsXPath | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) != 2: | ||
print 'This tool generates an overview of a bunch of BGF sources and targets.' | ||
print 'This tool generates an overview of a BGF file.' | ||
print 'Usage:' | ||
print ' checkbgf <bgf>' | ||
sys.exit(1) | ||
print 'Productions: ',runxpath(sys.argv[1],productions) | ||
print 'Nonterminals defined:',runxpath(sys.argv[1],nonterminals) | ||
print '%20s:' % 'unique',runxpath2(sys.argv[1],unique) | ||
print '%20s:' % 'bottom',runxpath2(sys.argv[1],bottom),'(',runxpathlist(sys.argv[1],listbottom),')' | ||
print '%20s:' % 'top',runxpath(sys.argv[1],top),'(',runxpathlist(sys.argv[1],listtop),')' | ||
print 'Productions: ',slpsXPath.runxpath(sys.argv[1],slpsXPath.productions) | ||
print 'Nonterminals defined:',slpsXPath.runxpath(sys.argv[1],slpsXPath.nonterminals) | ||
print '%20s:' % 'unique',slpsXPath.runxpath2(sys.argv[1],slpsXPath.unique) | ||
print '%20s:' % 'bottom',slpsXPath.runxpath2(sys.argv[1],slpsXPath.bottom),'(',slpsXPath.runxpathlist(sys.argv[1],slpsXPath.listbottom),')' | ||
print '%20s:' % 'top',slpsXPath.runxpath(sys.argv[1],slpsXPath.top),'(',slpsXPath.runxpathlist(sys.argv[1],slpsXPath.listtop),')' | ||
sys.exit(0) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/python | ||
import os | ||
import sys | ||
import slpsXPath | ||
import slpsns | ||
import elementtree.ElementTree as ET | ||
|
||
names = [] | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) != 4: | ||
print 'This tool generates an overview of a bunch of BGF sources and targets.' | ||
print 'Usage:' | ||
print ' bgfover <lcf> <bgfs-path> <xpath>' | ||
sys.exit(1) | ||
lcf = ET.parse(sys.argv[1]) | ||
for x in lcf.findall(sys.argv[3]): | ||
name = x.findtext('name') | ||
names.append(name) | ||
path = sys.argv[2] | ||
if path[-1]!='/': | ||
path += '/' | ||
print '''\\begin{tabular}{l|c|c|c|c} | ||
&\\numberOfProductions | ||
&\\numberOfNonterminals | ||
&\\numberOfTops | ||
&\\numberOfBottoms | ||
\\\\\\hline\\hline | ||
''' | ||
for x in names: | ||
print '\\emph{'+x+'}&'+slpsXPath.runxpath(path+x+'.bgf',slpsXPath.productions)+'&'+slpsXPath.runxpath(path+x+'.bgf',slpsXPath.nonterminals)+'&'+slpsXPath.runxpath(path+x+'.bgf',slpsXPath.top)+'&'+slpsXPath.runxpath2(path+x+'.bgf',slpsXPath.bottom)+'\\\\\\hline' | ||
print '\\end{tabular}' | ||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/usr/bin/python | ||
import os | ||
import slpsns | ||
|
||
productions = "count(/*/*[local-name()='production'])" | ||
nonterminals = "count(/*[local-name()='grammar']/*/nonterminal[not(text()=../preceding-sibling::*/nonterminal/text())])" | ||
top = "count(/*/*/nonterminal[not(text()=/*/*/*//nonterminal/text()) and not(text()=../preceding-sibling::*/nonterminal/text())])" | ||
listtop = "/*/*/nonterminal[not(text()=/*/*/*//nonterminal/text()) and not(text()=../preceding-sibling::*/nonterminal/text())]" | ||
oldbottom = "count(/*/*[not(*//nonterminal)]/nonterminal[not(text()=../preceding-sibling::*/nonterminal/text())])" | ||
bottom = " | (echo '<set>' ; xpath '//nonterminal[not(text()=/*/*/nonterminal/text())]' 2> /dev/null; echo '</set>' )| xpath 'count(//nonterminal[not(text()=preceding-sibling::*/text())])' " | ||
listbottom = "//nonterminal[not(text()=/*/*/nonterminal/text())]" | ||
unique = " | (echo '<set>' ; xpath '//nonterminal' 2> /dev/null; echo '</set>' )| xpath 'count(//nonterminal[not(text()=preceding-sibling::*/text())])' " | ||
|
||
safexbgf = ('abridge','detour','anonymize','deanonymize','unlabel','designate', | ||
'deyaccify','yaccify','eliminate','introduce','inline','extract', | ||
'unfold','fold','horizontal','vertical','distribute','factor', | ||
'massage','chain','unchain','skip','reroot','import') | ||
#safexbgf = ('eliminate','introduce','chain', 'designate', 'deyaccify','distribute', | ||
# 'extract', 'factor', 'fold', 'horizontal','inline', 'massage', | ||
# 'rename', 'reroot', 'unfold','vertical', 'yaccify', 'unchain', 'skip') | ||
incdecxbgf = ('remove','add','disappear','appear','narrow','widen', | ||
'downgrade','upgrade','rassoc','lassoc','unite') | ||
#incdecxbgf = ('add', 'narrow', 'remove','unite', 'widen', 'rassoc', 'lassoc') | ||
messyxbgf = ('permute', 'dump','project','inject','concretize','abstractize') | ||
|
||
rkeys = ('LOC','NOI','NOX','NI~','NI+','NI!','SGO','COR','NI^','SID','SRE') | ||
|
||
def runxpath(filename,xpathexpr): | ||
os.system('xpath '+filename+' "'+xpathexpr+'" 1>TMP-res 2>/dev/null') | ||
tmp = open('TMP-res','r') | ||
res = tmp.readline().strip() | ||
tmp.close() | ||
return res | ||
|
||
def runxpathlist(filename,xpathexpr): | ||
os.system('xpath '+filename+' "'+xpathexpr+'" 1>TMP-res 2>/dev/null') | ||
tmp = open('TMP-res','r') | ||
resa = tmp.readline().strip().split('<nonterminal>') | ||
resu = [] | ||
for x in resa: | ||
if x not in resu: | ||
resu.append(x) | ||
resu.sort() | ||
return ''.join(resu).replace('</nonterminal>',', ')[:-2] | ||
tmp.close() | ||
res = res.replace('<nonterminal>','').replace('</nonterminal>',', ') | ||
return res[:-2] | ||
|
||
def runxpath2(filename,xpathexpr): | ||
os.system('cat '+filename+xpathexpr+' 1>TMP-res 2>/dev/null') | ||
tmp = open('TMP-res','r') | ||
res = tmp.readline().strip() | ||
tmp.close() | ||
return res | ||
|
||
def noni(xbgf,arrayxbgf): | ||
global xbgfns | ||
cx = 0 | ||
for c in arrayxbgf: | ||
cx += len(xbgf.findall('//'+slpsns.xbgf_(c))) | ||
return cx | ||
|
||
def noPartiallyUnsafe(xbgf): | ||
return len(xbgf.findall('//'+slpsns.xbgf_('strip/terminal')))+\ | ||
len(xbgf.findall('//'+slpsns.xbgf_('strip/allTerminals')))+\ | ||
len(xbgf.findall('//'+slpsns.xbgf_('rename/terminal'))) | ||
|
||
def noPartiallySafe(xbgf): | ||
return len(xbgf.findall('//'+slpsns.xbgf_('strip/selector')))+\ | ||
len(xbgf.findall('//'+slpsns.xbgf_('strip/allSelectors')))+\ | ||
len(xbgf.findall('//'+slpsns.xbgf_('strip/label')))+\ | ||
len(xbgf.findall('//'+slpsns.xbgf_('strip/allLabels')))+\ | ||
len(xbgf.findall('//'+slpsns.xbgf_('rename/nonterminal')))+\ | ||
len(xbgf.findall('//'+slpsns.xbgf_('rename/selector')))+\ | ||
len(xbgf.findall('//'+slpsns.xbgf_('rename/label'))) | ||
|
||
def loc(filename): | ||
f = open(filename,'r') | ||
c = len(f.readlines()) | ||
f.close() | ||
return c-1 | ||
|
||
def nosi(filename,keyword): | ||
f = open(filename,'r') | ||
c = ''.join(f.readlines()).count(keyword) | ||
f.close() | ||
return c | ||
|
||
def noi(filename): | ||
f = open(filename,'r') | ||
c = ''.join(f.readlines()).count('<!--') | ||
f.close() | ||
return c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#!/usr/bin/python | ||
import os | ||
import sys | ||
import slpsns | ||
import slpsXPath | ||
import elementtree.ElementTree as ET | ||
|
||
names = [] | ||
targets = {} | ||
results = {} | ||
|
||
def report(keys,key,note): | ||
print note, | ||
cx = 0 | ||
for x in keys: | ||
cx += results[key][x] | ||
if results[key][x]: | ||
print '{',results[key][x],'}' | ||
else: | ||
print '{---}', | ||
print '{'+`cx`+'}' | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) != 4: | ||
print 'This tool generates an overview of a bunch of XBGF scripts.' | ||
print 'Usage:' | ||
print ' xbgfover <xbgf.xsd> <lcf> <xbgfs-path>' | ||
sys.exit(1) | ||
lcfname = sys.argv[2].split('/')[-1].split('.')[0] | ||
xsd = ET.parse(sys.argv[1]) | ||
for x in xsd.findall('/*'): | ||
if x.attrib.has_key('name'): | ||
names.append(x.attrib['name']) | ||
lcf = ET.parse(sys.argv[2]) | ||
for x in lcf.findall('/target'): | ||
name = x.findtext('name') | ||
targets[name] = [] | ||
for y in x.findall('branch/*/perform'): | ||
targets[name].append(y.text) | ||
path = sys.argv[3] | ||
if path[-1] != '/': | ||
path += '/' | ||
for x in slpsXPath.rkeys: | ||
results[x] = {} | ||
for x in names: | ||
results[x] = {} | ||
for y in targets.keys(): | ||
results[x][y] = 0 | ||
for x in targets.keys(): | ||
for y in slpsXPath.rkeys: | ||
results[y][x] = 0 | ||
for y in targets[x]: | ||
xbgf = ET.parse(path+y+'.xbgf') | ||
results['LOC'][x] += slpsXPath.loc(path+y+'.xbgf') | ||
results['NOI'][x] += slpsXPath.nosi(path+y+'.xbgf','ISSUE') | ||
results['NI~'][x] += slpsXPath.nosi(path+y+'.xbgf','ISSUE REFACTOR') | ||
results['NI+'][x] += slpsXPath.nosi(path+y+'.xbgf','EXTEND') | ||
results['NI!'][x] += slpsXPath.nosi(path+y+'.xbgf','CORRECT') | ||
results['NI^'][x] += slpsXPath.nosi(path+y+'.xbgf','PERMISSIVENESS') | ||
results['COR'][x] += slpsXPath.nosi(path+y+'.xbgf','EXTRACTERROR') | ||
results['SGO'][x] += slpsXPath.noni(xbgf,slpsXPath.safexbgf)+\ | ||
slpsXPath.nosi(path+y+'.xbgf','BREFACTOR')+\ | ||
slpsXPath.noPartiallySafe(xbgf) | ||
results['SID'][x] += slpsXPath.noni(xbgf,slpsXPath.incdecxbgf)+\ | ||
slpsXPath.nosi(path+y+'.xbgf','GENERALITY') | ||
results['SRE'][x] += slpsXPath.noni(xbgf,slpsXPath.messyxbgf)+\ | ||
slpsXPath.nosi(path+y+'.xbgf','REVISE')+\ | ||
slpsXPath.noPartiallyUnsafe(xbgf) | ||
results['NOX'][x] += len(xbgf.findall('/*')) | ||
for z in names: | ||
results[z][x] += len(xbgf.findall('/'+slpsns.xbgf_(z))) | ||
for x in names[:]: | ||
used = False | ||
for y in targets.keys(): | ||
if results[x][y]: | ||
used = True | ||
if not used: | ||
names.remove(x) | ||
sorted = targets.keys()[:] | ||
sorted.sort() | ||
if sorted == ['doc12','doc123','jls1','jls12','jls123','jls2','jls3']: | ||
sorted = ['jls1','jls2','jls3','jls12','jls123','doc12','doc123'] | ||
elif sorted == ['abstract','concrete','java','limit','topdown']: | ||
sorted = ['topdown','concrete','java','abstract','limit'] | ||
print '\\begin{tabular}{l|'+('c|'*len(targets))+'|c}' | ||
for x in sorted: | ||
print '&\\textbf{'+x+'}', | ||
print '&\\textbf{Total}\\\\\\hline' | ||
report(sorted,'LOC','\\'+lcfname+'NumberOfLines') | ||
print '\\hline' | ||
report(sorted,'NOX','\\'+lcfname+'NumberOfTransformations') | ||
report(sorted,'SGO','\\'+lcfname+'NumberOfRefactors') | ||
report(sorted,'SID','\\'+lcfname+'NumberOfGeneralises') | ||
report(sorted,'SRE','\\'+lcfname+'NumberOfRevisings') | ||
print '\\hline' | ||
print '\\'+lcfname+'NumberOfSteps', | ||
cx = 0 | ||
for x in sorted: | ||
cx += len(targets[x]) | ||
print '{',len(targets[x]),'}' | ||
print '{'+`cx`+'}' | ||
report(sorted,'NOI','\\'+lcfname+'NumberOfIssues') | ||
report(sorted,'COR','\\'+lcfname+'IssuesPostX') | ||
report(sorted,'NI!','\\'+lcfname+'IssuesCorrect') | ||
report(sorted,'NI+','\\'+lcfname+'IssuesExtend') | ||
report(sorted,'NI^','\\'+lcfname+'IssuesPermit') | ||
# report(sorted,'NI~','\\'+lcfname+'IssuesRefactor') | ||
print '\\hline' | ||
print '\\end{tabular}' | ||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.