Wiki

root/cobra/trunk/Source/Property.cobra

Revision 2608, 2.3 KB (checked in by Charles.Esterbrook, 9 months ago)

Code cleanup.

  • Property svn:eol-style set to native
Line 
1class Property
2    is partial
3    inherits ProperDexer
4    implements IBoxCodeMember
5
6    cue init(token as IToken, idToken as IToken, box as Box, name as String, isNames as String*, attribs as AttributeList, coverVar as BoxVar, coverAccess as String, docString as String)
7        base.init(token, idToken, box, name, isNames, attribs, docString)
8        _coverVar = coverVar
9        _coverAccess = coverAccess
10        _isNames = isNames.toList
11
12    cue init(token as IToken, idToken as IToken, box as Box, name as String, returnTypeOrNode as INode, isNames as String*, attribs as AttributeList, docString as String)
13        base.init(token, idToken, box, name, returnTypeOrNode, isNames, attribs, docString)
14
15    def cobraSourceSignature as String is override
16        keyword = if(.getPart and .setPart, 'pro', if(.getPart, 'get', 'set'))
17        sb = StringBuilder('[keyword] [.name] as [.resultType.name]')
18        if .isShared, sb.append(' is shared')
19        return sb.toString
20
21    get isCallable as bool is override
22        return false
23
24    get englishName as String is override
25        return 'property'
26
27    def makeGetPart(token as IToken) as AbstractMethod is override
28        _getPart = PropertyGetter(token, this)
29        return _getPart to !
30
31    def makeSetPart(token as IToken) as AbstractMethod is override
32        _setPart = PropertySetter(token, this)
33        return _setPart to !
34
35
36class PropertyGetter
37    inherits ProperDexerXetter
38
39    cue init(token as IToken, prop as Property)
40        base.init(token, prop, List<of String>())  # TODO: take in docString
41
42    get englishName as String is override
43        return 'property getter'
44
45    get xetPartName as String is override
46        return 'get'
47
48    def _bindInt
49        base._bindInt
50        _returnType = .parent.returnType
51        assert _returnType
52
53
54class PropertySetter
55    inherits ProperDexerXetter
56
57    cue init(token as IToken, prop as Property)
58        base.init(token, prop, List<of String>())  # TODO: take in docString
59
60        # make a token for the Param()
61        t = token.copy
62        t.which = 'ID'
63        t.text = 'value'
64        t.value = 'value'
65
66        if prop.returnType
67            p = Param(t, prop.returnType, isImplicit=true)
68        else if prop.returnTypeNode
69            p = Param(t, prop.returnTypeNode, isImplicit=true)
70        else
71            throw FallThroughException(prop)
72        _params.add(p)
73
74    get englishName as String is override
75        return 'property setter'
76
77    get xetPartName as String is override
78        return 'set'
79
80    def _bindInt
81        base._bindInt
82        _returnType = .compiler.voidType
83        assert _returnType
Note: See TracBrowser for help on using the browser.