]> git.cworth.org Git - apitrace/blobdiff - specs/scripts/cdecl.py
Trace all d3d10.dll functions.
[apitrace] / specs / scripts / cdecl.py
index bc5bcd1a04f1d8e9acf6862f0ec951ba8111fd24..88488440cc603a9a679648d3232e27a446644ee2 100755 (executable)
@@ -36,7 +36,7 @@ import optparse
 
 class DeclParser:
 
-    token_re = re.compile(r'(\d[x0-9a-fA-F.UL]*|\w+|\s+|.)')
+    token_re = re.compile(r'(\d[x0-9a-fA-F.UL]*|\w+|\s+|"[^"]*"|.)')
 
     multi_comment_re = re.compile(r'/\*.*?\*/', flags = re.DOTALL)
     single_comment_re = re.compile(r'//.*',)
@@ -301,16 +301,38 @@ class DeclParser:
                 tag = self.consume()
                 tags.append(tag)
             self.consume(']')
-        if self.lookahead().startswith('__'):
+            if tags[0] == 'annotation':
+                assert tags[1] == '('
+                assert tags[3] == ')'
+                tags = tags[2]
+                assert tags[0] == '"'
+                assert tags[-1] == '"'
+                tags = tags[1:-1]
+                tags = parse_sal_annotation(tags)
+        token = self.lookahead()
+        if token[0] == '_' and (token[1] == '_' or token[-1] == '_'):
             # Parse __in, __out, etc tags
-            tag = self.consume()[2:]
-            args = []
+            tag = self.consume()
             if self.match('('):
-                self.consume()
+                tag += self.consume()
                 while not self.match(')'):
-                    self.consume()
-                self.consume(')')
-            tags.extend(tag.split('_'))
+                    tag += self.consume()
+                tag += self.consume(')')
+            tags.extend(self.parse_sal_annotation(tag))
+        return tags
+
+    def parse_sal_annotation(self, tags):
+        try:
+            tags, args = tags.split('(')
+        except ValueError:
+            pass
+        assert tags[0] == '_'
+        if tags[1] == '_':
+            tags = tags[2:]
+        if tags[-1] == '_':
+            tags = tags[1:-1]
+        tags = tags.lower()
+        tags = tags.split('_')
         return tags
 
     def parse_named_type(self):
@@ -322,7 +344,9 @@ class DeclParser:
             name = self.consume()
             if self.match('['):
                 self.consume()
-                length = self.consume()
+                length = ''
+                while not self.match(']'):
+                    length += self.consume()
                 self.consume(']')
                 try:
                     int(length)