[1650] | 1 | -- tolua: abstract feature 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 | -- Feature class |
---|
| 14 | -- Represents the base class of all mapped feature. |
---|
| 15 | classFeature = { |
---|
| 16 | } |
---|
| 17 | classFeature.__index = classFeature |
---|
| 18 | |
---|
| 19 | -- write support code |
---|
| 20 | function classFeature:supcode () |
---|
| 21 | end |
---|
| 22 | |
---|
| 23 | -- output tag |
---|
| 24 | function classFeature:decltype () |
---|
| 25 | end |
---|
| 26 | |
---|
| 27 | -- register feature |
---|
| 28 | function classFeature:register (pre) |
---|
| 29 | end |
---|
| 30 | |
---|
| 31 | -- translate verbatim |
---|
| 32 | function classFeature:preamble () |
---|
| 33 | end |
---|
| 34 | |
---|
| 35 | -- check if it is a variable |
---|
| 36 | function classFeature:isvariable () |
---|
| 37 | return false |
---|
| 38 | end |
---|
| 39 | |
---|
| 40 | -- check if it requires collection |
---|
| 41 | function classFeature:requirecollection (t) |
---|
[2710] | 42 | return false |
---|
[1650] | 43 | end |
---|
| 44 | |
---|
| 45 | -- build names |
---|
| 46 | function classFeature:buildnames () |
---|
[2710] | 47 | if self.name and self.name~='' then |
---|
| 48 | local n = split(self.name,'@') |
---|
| 49 | self.name = n[1] |
---|
[3127] | 50 | self.name = string.gsub(self.name, ":%d*$", "") |
---|
[2710] | 51 | if not n[2] then |
---|
| 52 | n[2] = applyrenaming(n[1]) |
---|
| 53 | end |
---|
| 54 | self.lname = n[2] or gsub(n[1],"%[.-%]","") |
---|
[3127] | 55 | self.lname = string.gsub(self.lname, ":%d*$", "") |
---|
[2710] | 56 | self.original_name = self.name |
---|
| 57 | self.lname = clean_template(self.lname) |
---|
| 58 | end |
---|
| 59 | if not self.is_parameter then |
---|
| 60 | self.name = getonlynamespace() .. self.name |
---|
| 61 | end |
---|
[1650] | 62 | |
---|
[2710] | 63 | local parent = classContainer.curr |
---|
| 64 | if parent then |
---|
| 65 | self.access = parent.curr_member_access |
---|
[3127] | 66 | self.global_access = self:check_public_access() |
---|
[2710] | 67 | else |
---|
| 68 | end |
---|
[1650] | 69 | end |
---|
| 70 | |
---|
| 71 | function classFeature:check_public_access() |
---|
| 72 | |
---|
[3127] | 73 | if type(self.global_access) == "boolean" then |
---|
| 74 | return self.global_access |
---|
| 75 | end |
---|
| 76 | |
---|
[2710] | 77 | if self.access and self.access ~= 0 then |
---|
| 78 | return false |
---|
| 79 | end |
---|
[1650] | 80 | |
---|
[2710] | 81 | local parent = classContainer.curr |
---|
| 82 | while parent do |
---|
| 83 | if parent.access and parent.access ~= 0 then |
---|
| 84 | return false |
---|
| 85 | end |
---|
| 86 | parent = parent.prox |
---|
| 87 | end |
---|
| 88 | return true |
---|
[1650] | 89 | end |
---|
| 90 | |
---|
| 91 | function clean_template(t) |
---|
| 92 | |
---|
[2710] | 93 | return string.gsub(t, "[<>:, %*]", "_") |
---|
[1650] | 94 | end |
---|
| 95 | |
---|
| 96 | -- check if feature is inside a container definition |
---|
| 97 | -- it returns the container class name or nil. |
---|
| 98 | function classFeature:incontainer (which) |
---|
[2710] | 99 | if self.parent then |
---|
| 100 | local parent = self.parent |
---|
| 101 | while parent do |
---|
| 102 | if parent.classtype == which then |
---|
| 103 | return parent.name |
---|
| 104 | end |
---|
| 105 | parent = parent.parent |
---|
| 106 | end |
---|
| 107 | end |
---|
| 108 | return nil |
---|
[1650] | 109 | end |
---|
| 110 | |
---|
| 111 | function classFeature:inclass () |
---|
[2710] | 112 | return self:incontainer('class') |
---|
[1650] | 113 | end |
---|
| 114 | |
---|
| 115 | function classFeature:inmodule () |
---|
[2710] | 116 | return self:incontainer('module') |
---|
[1650] | 117 | end |
---|
| 118 | |
---|
| 119 | function classFeature:innamespace () |
---|
[2710] | 120 | return self:incontainer('namespace') |
---|
[1650] | 121 | end |
---|
| 122 | |
---|
| 123 | -- return C binding function name based on name |
---|
| 124 | -- the client specifies a prefix |
---|
| 125 | function classFeature:cfuncname (n) |
---|
| 126 | |
---|
[2710] | 127 | if self.parent then |
---|
| 128 | n = self.parent:cfuncname(n) |
---|
| 129 | end |
---|
[1650] | 130 | |
---|
[3127] | 131 | local fname = self.lname |
---|
| 132 | if not fname or fname == '' then |
---|
| 133 | fname = self.name |
---|
| 134 | end |
---|
| 135 | n = string.gsub(n..'_'.. (fname), "[<>:, \.%*&]", "_") |
---|
[1650] | 136 | |
---|
[2710] | 137 | return n |
---|
[1650] | 138 | end |
---|
| 139 | |
---|