1-- tolua: typedef class
2-- Written by Waldemar Celes
3-- TeCGraf/PUC-Rio
4-- Jul 1998
5-- $Id: typedef.lua,v 1.1 2009-07-09 13:44:14 fabraham Exp $
6
7-- This code is free software; you can redistribute it and/or modify it.
8-- The software provided hereunder is on an "as is" basis, and
9-- the author has no obligation to provide maintenance, support, updates,
10-- enhancements, or modifications.
11
12
13
14-- Typedef class
15-- Represents a type synonym.
16-- The 'de facto' type replaces the typedef before the
17-- remaining code is parsed.
18-- The following fields are stored:
19--   utype = typedef name
20--   type = 'the facto' type
21--   mod = modifiers to the 'de facto' type
22classTypedef = {
23 utype = '',
24 mod = '',
25 type = ''
26}
27classTypedef.__index = classTypedef
28
29-- Print method
30function classTypedef:print (ident,close)
31 print(ident.."Typedef{")
32 print(ident.." utype = '"..self.utype.."',")
33 print(ident.." mod = '"..self.mod.."',")
34 print(ident.." type = '"..self.type.."',")
35 print(ident.."}"..close)
36end
37
38-- Return it's not a variable
39function classTypedef:isvariable ()
40 return false
41end
42
43-- Internal constructor
44function _Typedef (t)
45 setmetatable(t,classTypedef)
46 appendtypedef(t)
47 return t
48end
49
50-- Constructor
51-- Expects one string representing the type definition.
52function Typedef (s)
53 if strfind(s,'[%*&]') then
54  tolua_error("#invalid typedef: pointers (and references) are not supported")
55 end
56 local t = split(gsub(s,"%s%s*"," ")," ")
57	if not isbasic(t[t.n]) then
58		return _Typedef {
59			utype = t[t.n],
60			type = t[t.n-1],
61			mod = concat(t,1,t.n-2),
62		}
63	else
64	 return nil
65	end
66end
67
68
69