summaryrefslogtreecommitdiff
path: root/tolua/src/bin/lua/typedef.lua
blob: e7b4bc905ff8da11e91e2e3cd5f8df39d5250552 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
-- tolua: typedef class
-- Written by Waldemar Celes
-- TeCGraf/PUC-Rio
-- Jul 1998
-- $Id: typedef.lua,v 1.3 2009/11/24 16:45:15 fabraham Exp $

-- This code is free software; you can redistribute it and/or modify it.
-- The software provided hereunder is on an "as is" basis, and
-- the author has no obligation to provide maintenance, support, updates,
-- enhancements, or modifications. 



-- Typedef class
-- Represents a type synonym.
-- The 'de facto' type replaces the typedef before the
-- remaining code is parsed.
-- The following fields are stored:
--   utype = typedef name
--   type = 'the facto' type
--   mod = modifiers to the 'de facto' type
classTypedef = {
 utype = '',
 mod = '',
 type = ''
}
classTypedef.__index = classTypedef

-- Print method
function classTypedef:print (ident,close)
 print(ident.."Typedef{")
 print(ident.." utype = '"..self.utype.."',")
 print(ident.." mod = '"..self.mod.."',")
 print(ident.." type = '"..self.type.."',")
 print(ident.."}"..close)
end

-- Return it's not a variable
function classTypedef:isvariable ()
 return false
end

-- Internal constructor
function _Typedef (t)
 setmetatable(t,classTypedef)
 appendtypedef(t)
 return t
end

-- Constructor
-- Expects one string representing the type definition.
function Typedef (s)
 if strfind(s,'[%*&]') then
  tolua_error("#invalid typedef: pointers (and references) are not supported")
 end
 local t = split(gsub(s,"%s%s*"," ")," ")
	if not isbasic(t[t.n]) then
 return _Typedef {
  utype = t[t.n],
  type = t[t.n-1],
  mod = concat(t,1,t.n-2),
 }
	else
	 return nil
	end
end