3 # $Id: apiparser.py,v 1.1 2001/11/18 22:42:57 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
):
86 for line
in f
.readlines():
88 # split line into tokens
89 tokens
= string
.split(line
)
91 if len(tokens
) > 0 and line
[0] != '#':
93 if tokens
[0] == 'name':
95 # Verify entry has offset or alias
104 print 'XXXXXXXXXX bad entry for %s' % funcName
106 # process the function now
107 userFunc (funcName
, returnType
, argTypeList
, argNameList
, alias
, offset
)
117 elif tokens
[0] == 'return':
118 returnType
= tokens
[1]
120 returnType
= returnType
+ ' ' + tokens
[2]
122 returnType
= returnType
+ ' ' + tokens
[3]
124 elif tokens
[0] == 'param':
125 argNameList
.append(tokens
[1])
128 type = type + ' ' + tokens
[3]
130 type = type + ' ' + tokens
[4]
131 argTypeList
.append(type)
133 elif tokens
[0] == 'category':
136 elif tokens
[0] == 'offset':
140 offset
= int(tokens
[1])
141 if offset
> maxOffset
:
144 # print 'Unassigned offset for %s' % funcName
146 elif tokens
[0] == 'alias':
150 print 'Invalid token %s after function %s' % (tokens
[0], funcName
)