Wiki

root/cobra/trunk/Source/Module.cobra

Revision 2607, 3.3 KB (checked in by Charles.Esterbrook, 9 months ago)

Improved error checking on .main.
credit:hopscc

  • Property svn:eol-style set to native
Line 
1use System.Reflection
2
3
4class Module inherits Node is abstract, partial
5
6    # TODO: Seems that much of Module's guts should be moved down to CobraModule
7
8    var _fileName as String
9    var _docString as String?
10
11    cue init(fileName as String, verbosity as int, docString as String)
12        require fileName.length
13        base.init
14        _fileName = fileName
15        _docString = docString
16        # TODO: what's going on with verbosity?
17
18    get docString from var
19
20    get fileName from var
21
22    get isCobraLibrary as bool
23        return _fileName.endsWith('CobraLang.cobra') or _fileName.endsWith('CobraLang.cs') or _
24            _fileName.endsWith('SystemInterfaces.cobra') or _fileName.endsWith('Cobra.Lang.dll')
25
26    def addMinFields
27        base.addMinFields
28        .addField('fileName', _fileName)
29
30# Would be better named LibModule or similar
31class AssemblyModule inherits Module is partial
32    """
33    An assembly module represents a .dll, jarfile or libraryish thing
34    Basically a holder for a filename (location) and a namespace for its contents
35    """
36   
37    var _topNameSpace as NameSpace
38    var _mustBindInhList = List<of INameSpaceMember>()
39
40    cue init(location as String, globalNS as NameSpace)
41        .init(location, 0, globalNS)
42
43    cue init(location as String, verbosity as int, globalNS as NameSpace)
44        base.init(location, verbosity, '')
45        _topNameSpace = NameSpace(globalNS, '(top namespace for assemblyModule at [location])')
46
47    def addMustBindInh(what as INameSpaceMember)
48        require .compiler.curModule is this
49        _mustBindInhList.add(what)
50
51    get topNameSpace from var
52        """
53        Returns the top namespace for this module.
54        This is an implicit namespace that is not unified (its unified namespace is the global namespace).
55        """
56
57    def _bindInh
58        base._bindInh
59        # .topNameSpace.bindInh - It's too expensive to scan all types in a DLL. Do them as needed. (See Box._prepIfNeeded)
60        for item in _mustBindInhList, item.bindInh
61
62    def _bindInt
63        base._bindInt
64        # .topNameSpace.bindInt - It's too expensive to scan all types in a DLL. Do them as needed. (See Box._prepIfNeeded)
65
66
67class CobraModule inherits Module is partial
68    """
69    Module for a cobra source File.
70        Holds name, docString and the topLevelNamespace as the root of the parsed AST nodes.
71        Also handles binding by passing bind invocation onto its namespace to action.
72    """
73   
74    pro isMainWrapper from var = false
75       
76    cue init(fileName as String, verbosity as int, docString as String, globalNS as NameSpace)
77        base.init(fileName, verbosity, docString)
78        _topNameSpace = NameSpace(globalNS, '(top namespace for module [fileName])')
79
80    get topNameSpace from var as NameSpace
81        """
82        Returns the top namespace for this module.
83        This is an implicit namespace that is not unified (its unified namespace is the global namespace).
84        """
85
86    def addSubFields
87        base.addSubFields
88        .addField('topNameSpace', .topNameSpace)
89
90    def _bindInh
91        base._bindInh
92        .topNameSpace.bindInh
93
94    def _bindInt
95        base._bindInt
96        .topNameSpace.bindInt
97
98    def _computeMatchingBaseMembers
99        base._computeMatchingBaseMembers
100        .topNameSpace.computeMatchingBaseMembers
101       
102    def _bindImp
103        base._bindImp
104        assert .didBindInt
105        .topNameSpace.bindImp
106
107
108class NativeModule inherits Module is abstract
109    """
110    The abstract base class for so-called "native" modules such as SharpModule.
111    """
112
113    cue init(fileName as String, verbosity as int, docString as String)
114        base.init(fileName, verbosity, docString)
115
Note: See TracBrowser for help on using the browser.