[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) |
---|
[2509] | 42 | return false |
---|
[1650] | 43 | end |
---|
| 44 | |
---|
| 45 | -- build names |
---|
| 46 | function classFeature:buildnames () |
---|
[2509] | 47 | if self.name and self.name~='' then |
---|
| 48 | local n = split(self.name,'@') |
---|
| 49 | self.name = n[1] |
---|
| 50 | if not n[2] then |
---|
| 51 | n[2] = applyrenaming(n[1]) |
---|
| 52 | end |
---|
| 53 | self.lname = n[2] or gsub(n[1],"%[.-%]","") |
---|
| 54 | self.original_name = self.name |
---|
| 55 | self.lname = clean_template(self.lname) |
---|
| 56 | end |
---|
| 57 | if not self.is_parameter then |
---|
| 58 | self.name = getonlynamespace() .. self.name |
---|
| 59 | end |
---|
[1650] | 60 | |
---|
[2509] | 61 | local parent = classContainer.curr |
---|
| 62 | if parent then |
---|
| 63 | self.access = parent.curr_member_access |
---|
| 64 | else |
---|
| 65 | end |
---|
[1650] | 66 | end |
---|
| 67 | |
---|
| 68 | function classFeature:check_public_access() |
---|
| 69 | |
---|
[2509] | 70 | if self.access and self.access ~= 0 then |
---|
| 71 | return false |
---|
| 72 | end |
---|
[1650] | 73 | |
---|
[2509] | 74 | local parent = classContainer.curr |
---|
| 75 | while parent do |
---|
| 76 | if parent.access and parent.access ~= 0 then |
---|
| 77 | return false |
---|
| 78 | end |
---|
| 79 | parent = parent.prox |
---|
| 80 | end |
---|
| 81 | return true |
---|
[1650] | 82 | end |
---|
| 83 | |
---|
| 84 | function clean_template(t) |
---|
| 85 | |
---|
[2509] | 86 | return string.gsub(t, "[<>:, %*]", "_") |
---|
[1650] | 87 | end |
---|
| 88 | |
---|
| 89 | -- check if feature is inside a container definition |
---|
| 90 | -- it returns the container class name or nil. |
---|
| 91 | function classFeature:incontainer (which) |
---|
[2509] | 92 | if self.parent then |
---|
| 93 | local parent = self.parent |
---|
| 94 | while parent do |
---|
| 95 | if parent.classtype == which then |
---|
| 96 | return parent.name |
---|
| 97 | end |
---|
| 98 | parent = parent.parent |
---|
| 99 | end |
---|
| 100 | end |
---|
| 101 | return nil |
---|
[1650] | 102 | end |
---|
| 103 | |
---|
| 104 | function classFeature:inclass () |
---|
[2509] | 105 | return self:incontainer('class') |
---|
[1650] | 106 | end |
---|
| 107 | |
---|
| 108 | function classFeature:inmodule () |
---|
[2509] | 109 | return self:incontainer('module') |
---|
[1650] | 110 | end |
---|
| 111 | |
---|
| 112 | function classFeature:innamespace () |
---|
[2509] | 113 | return self:incontainer('namespace') |
---|
[1650] | 114 | end |
---|
| 115 | |
---|
| 116 | -- return C binding function name based on name |
---|
| 117 | -- the client specifies a prefix |
---|
| 118 | function classFeature:cfuncname (n) |
---|
| 119 | |
---|
[2509] | 120 | if self.parent then |
---|
| 121 | n = self.parent:cfuncname(n) |
---|
| 122 | end |
---|
[1650] | 123 | |
---|
[2509] | 124 | n = string.gsub(n..'_'.. (self.lname or self.name), "[<>:, \.%*&]", "_") |
---|
[1650] | 125 | |
---|
[2509] | 126 | return n |
---|
[1650] | 127 | end |
---|
| 128 | |
---|