[cfe-commits] r58368 - /cfe/trunk/utils/FindSpecRefs

Daniel Dunbar daniel at zuster.org
Tue Oct 28 22:58:09 PDT 2008


Author: ddunbar
Date: Wed Oct 29 00:58:09 2008
New Revision: 58368

URL: http://llvm.org/viewvc/llvm-project?rev=58368&view=rev
Log:
Update FindSpecRefs to recognize named section references.
 - Unfortunately, I don't have an easy way to map from named sections
   to numbers nicely so they don't get page numbers or integrate in
   the list well.

Modified:
    cfe/trunk/utils/FindSpecRefs

Modified: cfe/trunk/utils/FindSpecRefs
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/FindSpecRefs?rev=58368&r1=58367&r2=58368&view=diff

==============================================================================
--- cfe/trunk/utils/FindSpecRefs (original)
+++ cfe/trunk/utils/FindSpecRefs Wed Oct 29 00:58:09 2008
@@ -596,6 +596,10 @@
 }
 
 def findClosestTOCEntry(data, target):
+    # FIXME: Fix for named spec references
+    if isinstance(target[0],str):
+        return ('.'.join(target),'<named>',1)
+
     offset = data[2]
     best = None
     for (name,page) in data[1]:
@@ -643,7 +647,7 @@
 
 ###
 
-nameAndSpecRefRE = re.compile(r"(C99|C90|C\+\+|H\&S) (([0-9]+)(\.[0-9]+)*(p[0-9]+)?)")
+nameAndSpecRefRE = re.compile(r"(C99|C90|C\+\+|H\&S) ((([0-9]+)(\.[0-9]+)*|\[[^]]+\])(p[0-9]+)?)")
 loneSpecRefRE = re.compile(r" (([0-9]+)(\.[0-9]+){2,100}(p[0-9]+)?)")
 def scanFile(path, filename):
     try:
@@ -673,12 +677,24 @@
 class SpecIndex:
     @staticmethod
     def fromstring(str):
-        secs = str.split('.')
-        paragraph = None
-        if 'p' in secs[-1]:
-            secs[-1],p = secs[-1].split('p',1)
-            paragraph = int(p)
-        indices = map(int, secs)
+        # Check for named sections
+        if str[0] == '[':
+            assert ']' in str
+            secs = str[1:str.index(']')].split('.')
+            tail = str[str.index(']')+1:]
+            if tail:
+                assert tail[0] == 'p'
+                paragraph = int(tail[1:])
+            else:
+                paragraph = None
+            indices = secs
+        else:
+            secs = str.split('.')
+            paragraph = None
+            if 'p' in secs[-1]:
+                secs[-1],p = secs[-1].split('p',1)
+                paragraph = int(p)
+            indices = map(int, secs)
         return SpecIndex(indices, paragraph)
 
     def __init__(self, indices, paragraph=None):
@@ -788,20 +804,26 @@
     global options
     from optparse import OptionParser
     parser = OptionParser("usage: %prog [options] CLANG_ROOT <output-dir>")
-    
-    (options, args) = parser.parse_args()
+    parser.add_option("", "--debug", dest="debug",
+                      help="Print extra debugging output",
+                      action="store_true",
+                      default=False)    
+    (opts, args) = parser.parse_args()
 
     if len(args) != 2:
         parser.error("incorrect number of arguments")
 
     references = []
     root,outputDir = args
-    for (dirpath, dirnames, filenames) in os.walk(root):
-        for filename in filenames:
-            name,ext = os.path.splitext(filename)
-            if ext in ('.c', '.cpp', '.h', '.def'):
-                fullpath = os.path.join(dirpath, filename)                
-                references.extend(list(scanFile(fullpath, filename)))
+    if os.path.isdir(root):
+        for (dirpath, dirnames, filenames) in os.walk(root):
+            for filename in filenames:
+                name,ext = os.path.splitext(filename)
+                if ext in ('.c', '.cpp', '.h', '.def'):
+                    fullpath = os.path.join(dirpath, filename)                
+                    references.extend(list(scanFile(fullpath, filename)))
+    else:
+        references.extend(list(scanFile(root, root)))
 
     refTree = buildRefTree(references)
 
@@ -813,6 +835,9 @@
 
     print 'Found %d references.'%(len(references),)
 
+    if opts.debug:
+        pprint(refTree)
+
     referencesPath = os.path.join(outputDir,'references.html')
     print 'Writing: %s'%(referencesPath,)
     f = open(referencesPath,'w')   





More information about the cfe-commits mailing list