3 # $Id: apiparser.py,v 1.2 2003/08/19 01:06:24 brianp Exp $
5 # Mesa 3-D graphics library
8 # Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
10 # Permission is hereby granted, free of charge, to any person obtaining a
11 # copy of this software and associated documentation files (the "Software"),
12 # to deal in the Software without restriction, including without limitation
13 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 # and/or sell copies of the Software, and to permit persons to whom the
15 # Software is furnished to do so, subject to the following conditions:
17 # The above copyright notice and this permission notice shall be included
18 # in all copies or substantial portions of the Software.
20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 # BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
24 # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 # These helper functions are used by the other Mesa Python scripts.
29 # The main function is ProcessSpecFile(spedFile, function) which parses
30 # the named spec file and calls function() for each entry in the spec file.
36 # Given parallel arrays of types and names, make a C-style parameter string
37 def MakeArgList(typeList
, nameList
):
42 result
= result
+ typ
+ ' ' + nameList
[i
- 1]
44 result
= result
+ ', '
57 # Example callback function for ProcessSpecFile()
59 def PrintRecord(name
, returnType
, argTypeList
, argNameList
, alias
, offset
):
60 argList
= MakeArgList(argTypeList
, argNameList
)
61 if category
!= prevCategory
or prevCategory
== '':
62 print '\n/* %s */' % category
63 prevCategory
= category
65 print '%s gl%s(%s); /* %d */' % (returnType
, name
, argList
, offset
)
70 # Process the api spec file
72 def ProcessSpecFile(specFile
, userFunc
):
88 for line
in f
.readlines():
90 # split line into tokens
91 tokens
= string
.split(line
)
93 if len(tokens
) > 0 and line
[0] != '#':
95 if tokens
[0] == 'name':
97 # Verify entry has offset or alias
99 if offset
== NO_OFFSET
:
106 print 'XXXXXXXXXX bad entry for %s' % funcName
108 # process the function now
109 userFunc (funcName
, returnType
, argTypeList
, argNameList
, alias
, offset
)
119 elif tokens
[0] == 'return':
120 returnType
= string
.join(tokens
[1:], ' ')
122 elif tokens
[0] == 'param':
123 argNameList
.append(tokens
[1])
124 argTypeList
.append(string
.join(tokens
[2:], ' '))
126 elif tokens
[0] == 'category':
129 elif tokens
[0] == 'offset':
133 offset
= int(tokens
[1])
134 if offset
> maxOffset
:
137 # print 'Unassigned offset for %s' % funcName
139 elif tokens
[0] == 'alias':
143 print 'Invalid token %s after function %s' % (tokens
[0], funcName
)