1 | -- tolua: typedef class |
---|
2 | -- Written by Waldemar Celes |
---|
3 | -- TeCGraf/PUC-Rio |
---|
4 | -- Jul 1998 |
---|
5 | -- $Id: $ |
---|
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 |
---|
22 | classTypedef = { |
---|
23 | utype = '', |
---|
24 | mod = '', |
---|
25 | type = '' |
---|
26 | } |
---|
27 | classTypedef.__index = classTypedef |
---|
28 | |
---|
29 | -- Print method |
---|
30 | function 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) |
---|
36 | end |
---|
37 | |
---|
38 | -- Return it's not a variable |
---|
39 | function classTypedef:isvariable () |
---|
40 | return false |
---|
41 | end |
---|
42 | |
---|
43 | -- Internal constructor |
---|
44 | function _Typedef (t) |
---|
45 | setmetatable(t,classTypedef) |
---|
46 | t.type = resolve_template_types(t.type) |
---|
47 | appendtypedef(t) |
---|
48 | return t |
---|
49 | end |
---|
50 | |
---|
51 | -- Constructor |
---|
52 | -- Expects one string representing the type definition. |
---|
53 | function Typedef (s) |
---|
54 | if strfind(string.gsub(s, '%b<>', ''),'[%*&]') then |
---|
55 | tolua_error("#invalid typedef: pointers (and references) are not supported") |
---|
56 | end |
---|
57 | local o = {mod = ''} |
---|
58 | if string.find(s, "[<>]") then |
---|
59 | _,_,o.type,o.utype = string.find(s, "^%s*([^<>]+%b<>[^%s]*)%s+(.-)$") |
---|
60 | else |
---|
61 | local t = split(gsub(s,"%s%s*"," ")," ") |
---|
62 | o = { |
---|
63 | utype = t[t.n], |
---|
64 | type = t[t.n-1], |
---|
65 | mod = concat(t,1,t.n-2), |
---|
66 | } |
---|
67 | end |
---|
68 | return _Typedef(o) |
---|
69 | end |
---|
70 | |
---|
71 | |
---|