refclassfixup.py will find uses of the class terms
authorDavid Anderson <davea42@earthlink.net>
Tue, 29 May 2012 18:36:17 +0000 (11:36 -0700)
committerDavid Anderson <davea42@earthlink.net>
Tue, 29 May 2012 18:36:17 +0000 (11:36 -0700)
an turn them in to livelink (unless already transformed).

dwarf5/tools/Makefile
dwarf5/tools/copyfile.py
dwarf5/tools/fileio.py
dwarf5/tools/printtokens.py
dwarf5/tools/refclassfixup.py [new file with mode: 0644]
dwarf5/tools/test1.base
dwarf5/tools/test2.base [new file with mode: 0644]
dwarf5/tools/test2.in [new file with mode: 0644]

index 7df6de8..cd0bd9a 100644 (file)
@@ -10,3 +10,8 @@ test:
        diff test1.tmp test1.base
        python copyfile.py test1.in 
        diff test1.in test1.in.out
+       python refclassfixup.py test2.in
+       diff test2.in.out test2.base
+       python refclassfixup.py test2.in.out
+       # checking for idempotence
+       diff test2.in.out test2.in.out.out
index 0fa36c3..9b2fcf2 100644 (file)
@@ -10,7 +10,6 @@ def read_args():
   cur = 1
   filelist = []
   while  len(sys.argv) > cur:
-    print "argv[",cur,"] = ", sys.argv[cur]
     v = sys.argv[cur]
     filelist += [v]
     cur = int(cur) + 1
index 7ec0a97..692bc35 100644 (file)
@@ -60,6 +60,12 @@ class dwtoken:
     self._label = []
     # Class is "id", "ind","other","none"
     self._class = "none"
+  def insertid(self,string):
+    self._class =  "id"
+    self._tex = list(string)
+    self._underbar = self._tex
+    self._std = self._tex
+    self._label = self._tex
   def setIndivid(self,c):
     self._tex = [c]
     self._underbar = [c]
@@ -247,6 +253,9 @@ class  dwline:
     for t in self._toks:
       t.dwwrite(outfile)
     outfile.write("\n")
+  def dwtransformline(self,callfunc):
+    toks = callfunc(self._toks)
+    self._toks = toks
     
 
 class dwfile:
@@ -293,6 +302,9 @@ class dwfile:
     for l in self._lines:
       l.dwwrite(outfile,lnum)
       lnum = lnum + 1
+  def dwtransformline(self,callfunc):
+    for l in self._lines:
+      l.dwtransformline(callfunc)
     
 
 
@@ -312,7 +324,9 @@ class dwfiles:
   def dwwrite(self):
     for f in self._files:
       f.dwwrite()
-
+  def dwtransformline(self,callfunc):
+    for f in self._files:
+      f.dwtransformline(callfunc)
 
 
 def readFilelist(filelist):
index f6735b8..e38bb6f 100644 (file)
@@ -9,7 +9,6 @@ def print_args():
   cur = 1
   filelist = []
   while  len(sys.argv) > cur:
-    print "argv[",cur,"] = ", sys.argv[cur]
     v = sys.argv[cur]
     filelist += [v]
     cur = int(cur) + 1
diff --git a/dwarf5/tools/refclassfixup.py b/dwarf5/tools/refclassfixup.py
new file mode 100644 (file)
index 0000000..d8bccee
--- /dev/null
@@ -0,0 +1,95 @@
+# Copyright 2012 DWARF Debugging Information Format Committee
+# This reads the input tokens and then
+# writes them out in new files.  
+# Used to verify that the output matches the input byte-for-byte
+
+import sys
+import fileio
+
+refclass = { 
+"address":"chap:address", 
+"block":"chap:block", 
+"constant":"chap:constant", 
+"exprloc":"chap:exprloc", 
+"flag":"chap:flag",
+"lineptr":"chap:lineptr",
+"loclistptr":"chap:loclistptr",
+"macptr":"chap:macptr",
+"rangelistptr":"chap:rangelistptr",
+"reference":"chap:reference",
+"string":"chap:string" }
+
+def ischar(tok,c):
+   if tok._class != "ind":
+      return "n"
+   if len(tok._tex) != 1:
+       return "n"
+   if tok._tex[0] != c:
+       return "n"
+   return "y"
+
+def transformone(tok, string):
+  label = refclass[string]
+  # output is  \livelink{label}{string}
+  t1=fileio.dwtoken()
+  t1.insertid("\livelink")
+  t2=fileio.dwtoken()
+  t2.setIndivid("{")
+  t3=fileio.dwtoken()
+  t3.insertid(label)
+  t4=fileio.dwtoken()
+  t4.setIndivid("}")
+  t5 = t2
+  t6=fileio.dwtoken()
+  t6.insertid(string) 
+  t7 = t4
+  return [t1,t2,t3,t4,t5,t6,t7]
+
+def append_to_out(out,addthese):
+  for a in addthese:
+    out += [a]
+
+def transfunc(linetoks):
+  if len(linetoks) < 1:
+    return linetoks
+  tnumin = 0
+  changes = 0
+  lasttoknum = len(linetoks) -1
+  outtoks = []
+  for t in linetoks:
+    rawtok = ''.join(t._tex)
+    if  refclass.has_key(rawtok) == 1:
+      if tnumin == 0 or tnumin == lasttoknum:
+         tmp = transformone(t, rawtok);
+         changes = changes +  1
+         append_to_out(outtoks,tmp)
+      else:
+        if  ischar(linetoks[tnumin - 1],"{") != "y" or ischar(linetoks[tnumin+1],"}") != "y":
+          tmp = transformone(t, rawtok);
+          append_to_out(outtoks,tmp)
+          changes = changes +  1
+        else:
+          outtoks += [t]
+    else:
+      outtoks += [t]
+    tnumin = tnumin+ 1
+    # End of for loop.
+  return outtoks
+
+def read_args():
+  cur = 1
+  filelist = []
+  while  len(sys.argv) > cur:
+    v = sys.argv[cur]
+    filelist += [v]
+    cur = int(cur) + 1
+
+  dwf = fileio.readFilelist(filelist)
+  dwf.dwtransformline(transfunc)
+  dwf.dwwrite()
+
+if __name__ == '__main__':
+  read_args()
+  
+
+
index b0bde58..e094f7c 100644 (file)
@@ -1,4 +1,3 @@
-argv[ 1 ] =  test1.in
 Number of files:  1
 Number of lines in  test1.in :   16
 Number of tokens in line  1  :  0
diff --git a/dwarf5/tools/test2.base b/dwarf5/tools/test2.base
new file mode 100644 (file)
index 0000000..ad8b5fc
--- /dev/null
@@ -0,0 +1,20 @@
+
+appropriate    prefix (DW\_TAG_foo, DW\_AT_foo, 
+DW\_END_line, DW\_ATE_x, DW\_OP_foo,
+DW\_LANG, DW\_LNE, DW\_CC or DW\_CFA respectively) followed by
+\_lo\_user or \_hi\_user.
+this is \livelink{chap:macptr}{macptr} and \livelink{chap:block}{block} .  Which should transform.
+this is \livelink{chap:address}{address} and \livelink{chap:string}{string} .  Which should transform.
+this should be untouched \livelink{chap:reference}{reference} for example.
+this should be untouched \livetarg{chap:block}{block} for example.
+this should be untouched \livetargi{chap:address}{address} for example.
+
+\endlastfoot
+\livelink{chap:DWTAGaccessdeclaration}{DW\-\_TAG\-\_access\-\_declaration}
+& DECL \\
+
+information entry with the tag
+\livetarg{chap:DWTAGaccessdeclaration}{DW\_TAG\_access\_declaration}.
+Each
+such entry is a child of the class or structure type entry.
+
diff --git a/dwarf5/tools/test2.in b/dwarf5/tools/test2.in
new file mode 100644 (file)
index 0000000..bc8ce8f
--- /dev/null
@@ -0,0 +1,20 @@
+
+appropriate    prefix (DW\_TAG_foo, DW\_AT_foo, 
+DW\_END_line, DW\_ATE_x, DW\_OP_foo,
+DW\_LANG, DW\_LNE, DW\_CC or DW\_CFA respectively) followed by
+\_lo\_user or \_hi\_user.
+this is macptr and block .  Which should transform.
+this is address and string .  Which should transform.
+this should be untouched \livelink{chap:reference}{reference} for example.
+this should be untouched \livetarg{chap:block}{block} for example.
+this should be untouched \livetargi{chap:address}{address} for example.
+
+\endlastfoot
+\livelink{chap:DWTAGaccessdeclaration}{DW\-\_TAG\-\_access\-\_declaration}
+& DECL \\
+
+information entry with the tag
+\livetarg{chap:DWTAGaccessdeclaration}{DW\_TAG\_access\_declaration}.
+Each
+such entry is a child of the class or structure type entry.
+