Now unified the actual code for introducing livelink
authorDavid Anderson <davea42@earthlink.net>
Thu, 31 May 2012 15:09:54 +0000 (08:09 -0700)
committerDavid Anderson <davea42@earthlink.net>
Thu, 31 May 2012 15:09:54 +0000 (08:09 -0700)
into a single file. Callers just pass in the crucial string
to say what to change.  new files: anylink.py attrlink.py
and test files.

dwarf5/tools/Makefile
dwarf5/tools/anylink.py [new file with mode: 0644]
dwarf5/tools/attrlink.base [new file with mode: 0644]
dwarf5/tools/attrlink.in [new file with mode: 0644]
dwarf5/tools/attrlink.py [new file with mode: 0644]
dwarf5/tools/taglink.py

index 77f82ae..f05f92d 100644 (file)
@@ -30,4 +30,9 @@ test:
        # checking for idempotence
        python tohyphen.py tohyphen.in.out
        diff tohyphen.in.out.out tohyphen.base
+       python attrlink.py attrlink.in
+       diff attrlink.in.out attrlink.base
+       # checking for idempotence
+       python attrlink.py attrlink.in.out
+       diff attrlink.in.out.out attrlink.base
      
diff --git a/dwarf5/tools/anylink.py b/dwarf5/tools/anylink.py
new file mode 100644 (file)
index 0000000..9e5927d
--- /dev/null
@@ -0,0 +1,127 @@
+# Copyright 2012 DWARF Debugging Information Format Committee
+#
+# All DW_TAG_* entries not in {} are turned into \livelink.
+
+import sys
+import fileio
+
+global myprefix
+
+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,stdname,labelname):
+
+  # output is  \livelink{label}{string}
+  t1=fileio.dwtoken()
+  t1.insertid("\livelink")
+  t2=fileio.dwtoken()
+  t2.setIndivid("{")
+  t3=fileio.dwtoken()
+  t3.insertid(labelname)
+  t4=fileio.dwtoken()
+  t4.setIndivid("}")
+  t5 = t2
+  t6=fileio.dwtoken()
+  t6.insertid(''.join(tok._tex)) 
+  t7 = t4
+  return [t1,t2,t3,t4,t5,t6,t7]
+
+def append_to_out(out,addthese):
+  for a in addthese:
+    out += [a]
+
+def isdesiredname(stdname):
+  """ If it is DW_TAG_* we return "y".
+      Else return "n"
+      We don't want something like plain DW_TAG  or 
+      plain DW_TAG_ to get modified.
+  """
+  global myprefix
+  if stdname.startswith(myprefix):
+    if len(stdname) > len(myprefix):
+      return "y"
+  return "n"
+
+def dwspace(tok):
+  if ischar(tok," ") == "y":
+    return "y"
+  if ischar(tok,"\t") == "y":
+    return "y"
+  return "n"
+  
+# Here we are a bit careful, in that accidental spaces
+# after { or before } should not be confused with
+# not having a {} around a name.
+def leaderislbrace(linetoks,num):
+  cnum = num - 1
+  while cnum >= 1:
+    tok = linetoks[cnum]
+    if dwspace(tok) == "y":
+      cnum = cnum - 1
+      continue
+    if ischar(tok,"{") == "y":
+      return "y"
+    return "n"
+  return "n"
+  
+def trailerisrbrace(linetoks,num):
+  cnum = num + 1
+  while cnum < len(linetoks) :
+    tok = linetoks[cnum]
+    if dwspace(tok) == "y":
+      cnum = cnum + 1
+      continue
+    if ischar(tok,"}") == "y":
+      return "y"
+    return "n"
+  return "n"
+
+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)
+    stdname= ''.join(t._std)
+    linkname = "chap:" + ''.join(t._label)
+    if isdesiredname(stdname) == "y":
+      #Look past spaces when looking for { or }
+      if leaderislbrace(linetoks,tnumin) == "n" or trailerisrbrace(linetoks,tnumin) == "n":
+        tmp = transformone(t,stdname,linkname);
+        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(targprefix):
+  cur = 1
+  global myprefix
+  myprefix = targprefix
+  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()
+
+  
+
+
diff --git a/dwarf5/tools/attrlink.base b/dwarf5/tools/attrlink.base
new file mode 100644 (file)
index 0000000..2ffa356
--- /dev/null
@@ -0,0 +1,18 @@
+
+appropriate    prefix (DW\_TAG\_foo, \livelink{chap:DWATfoo}{DW\_AT\_foo}, 
+DW\_END_line, DW\_ATE_x, DW\_OP_foo,
+DW\_TAG
+DW\_TAG_
+DW\_LANG, DW\_LNE, DW\_CC or DW\_CFA respectively) followed by
+\_lo\_user or \_hi\_user.
+
+\endlastfoot
+\livelink{chap:DWTAGaccessdeclaration}{  DW\-\_TAG\-\_access\-\_declaration}
+& DECL \\
+\livelink{chap:DWTAGaccessdeclaration}{  DW\-\_AT\-\_access\-\_declaration}
+
+
+information entry with the tag
+\livetarg{chap:DWTAGaccessdeclaration}{DW\_AT\_something\_declaration}.
+\livelink{chap:DWATsomethingdeclaration}{DW\_AT\_something\_declaration}
+
diff --git a/dwarf5/tools/attrlink.in b/dwarf5/tools/attrlink.in
new file mode 100644 (file)
index 0000000..bae5ac8
--- /dev/null
@@ -0,0 +1,18 @@
+
+appropriate    prefix (DW\_TAG\_foo, DW\_AT\_foo, 
+DW\_END_line, DW\_ATE_x, DW\_OP_foo,
+DW\_TAG
+DW\_TAG_
+DW\_LANG, DW\_LNE, DW\_CC or DW\_CFA respectively) followed by
+\_lo\_user or \_hi\_user.
+
+\endlastfoot
+\livelink{chap:DWTAGaccessdeclaration}{  DW\-\_TAG\-\_access\-\_declaration}
+& DECL \\
+\livelink{chap:DWTAGaccessdeclaration}{  DW\-\_AT\-\_access\-\_declaration}
+
+
+information entry with the tag
+\livetarg{chap:DWTAGaccessdeclaration}{DW\_AT\_something\_declaration}.
+DW\_AT\_something\_declaration
+
diff --git a/dwarf5/tools/attrlink.py b/dwarf5/tools/attrlink.py
new file mode 100644 (file)
index 0000000..8973ed2
--- /dev/null
@@ -0,0 +1,11 @@
+# Copyright 2012 DWARF Debugging Information Format Committee
+#
+# All DW_TAG_* entries not in {} are turned into \livelink.
+
+import sys
+import anylink
+
+if __name__ == '__main__':
+  anylink.read_args("DW_AT_")
+
+
index 1bd1d1f..64a80bc 100644 (file)
 # All DW_TAG_* entries not in {} are turned into \livelink.
 
 import sys
-import fileio
-
-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,stdname,labelname):
-
-  # output is  \livelink{label}{string}
-  t1=fileio.dwtoken()
-  t1.insertid("\livelink")
-  t2=fileio.dwtoken()
-  t2.setIndivid("{")
-  t3=fileio.dwtoken()
-  t3.insertid(labelname)
-  t4=fileio.dwtoken()
-  t4.setIndivid("}")
-  t5 = t2
-  t6=fileio.dwtoken()
-  t6.insertid(''.join(tok._tex)) 
-  t7 = t4
-  return [t1,t2,t3,t4,t5,t6,t7]
-
-def append_to_out(out,addthese):
-  for a in addthese:
-    out += [a]
-
-def isdesiredname(stdname):
-  """ If it is DW_TAG_* we return "y".
-      Else return "n"
-      We don't want something like plain DW_TAG  or 
-      plain DW_TAG_ to get modified.
-  """
-  if stdname.startswith("DW_TAG_"):
-    if len(stdname) > 7:
-      return "y"
-  return "n"
-
-def dwspace(tok):
-  if ischar(tok," ") == "y":
-    return "y"
-  if ischar(tok,"\t") == "y":
-    return "y"
-  return "n"
-  
-# Here we are a bit careful, in that accidental spaces
-# after { or before } should not be confused with
-# not having a {} around a name.
-def leaderislbrace(linetoks,num):
-  cnum = num - 1
-  while cnum >= 1:
-    tok = linetoks[cnum]
-    if dwspace(tok) == "y":
-      cnum = cnum - 1
-      continue
-    if ischar(tok,"{") == "y":
-      return "y"
-    return "n"
-  return "n"
-  
-def trailerisrbrace(linetoks,num):
-  cnum = num + 1
-  while cnum < len(linetoks) :
-    tok = linetoks[cnum]
-    if dwspace(tok) == "y":
-      cnum = cnum + 1
-      continue
-    if ischar(tok,"}") == "y":
-      return "y"
-    return "n"
-  return "n"
-
-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)
-    stdname= ''.join(t._std)
-    linkname = "chap:" + ''.join(t._label)
-    if isdesiredname(stdname) == "y":
-      #Look past spaces when looking for { or }
-      if leaderislbrace(linetoks,tnumin) == "n" or trailerisrbrace(linetoks,tnumin) == "n":
-        tmp = transformone(t,stdname,linkname);
-        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()
+import anylink
 
 if __name__ == '__main__':
-  read_args()
+  anylink.read_args("DW_TAG_")