PageRenderTime 42ms CodeModel.GetById 20ms app.highlight 3ms RepoModel.GetById 17ms app.codeStats 0ms

/Rhino.Etl.Dsl/CompilerSteps/CorrelateTypesToModuleName.cs

http://github.com/ayende/rhino-etl
C# | 54 lines | 29 code | 5 blank | 20 comment | 2 complexity | f9c54c41871bfbe8c2146c8273da77f1 MD5 | raw file
 1namespace Rhino.Etl.Dsl.CompilerSteps
 2{
 3    using System.Collections.Generic;
 4    using Boo.Lang.Compiler.Steps;
 5
 6    /// <summary>
 7    /// Correlate between the types defined in a module and their module.
 8    /// This is required to get batch compilation working.
 9    /// </summary>
10    public class CorrelateTypesToModuleName : AbstractVisitorCompilerStep
11    {
12        private readonly IDictionary<string, IList<string>> moduleNameToContainedTypes;
13        private string currentModule;
14
15        /// <summary>
16        /// Initializes a new instance of the <see cref="CorrelateTypesToModuleName"/> class.
17        /// </summary>
18        /// <param name="moduleNameToContainedTypes">The module name to contained types.</param>
19        public CorrelateTypesToModuleName(IDictionary<string, IList<string>> moduleNameToContainedTypes)
20        {
21            this.moduleNameToContainedTypes = moduleNameToContainedTypes;
22        }
23
24        /// <summary>
25        /// Runs this instance.
26        /// </summary>
27        public override void Run()
28        {
29            Visit(CompileUnit);
30        }
31
32        /// <summary>
33        /// Enters the module.
34        /// </summary>
35        /// <param name="node">The node.</param>
36        /// <returns></returns>
37        public override bool EnterModule(Boo.Lang.Compiler.Ast.Module node)
38        {
39            currentModule = node.Name;
40            if (moduleNameToContainedTypes.ContainsKey(currentModule) == false)
41                moduleNameToContainedTypes[currentModule] = new List<string>();
42            return base.EnterModule(node);
43        }
44
45        /// <summary>
46        /// Called when a class definition node is found
47        /// </summary>
48        /// <param name="node">The node.</param>
49        public override void OnClassDefinition(Boo.Lang.Compiler.Ast.ClassDefinition node)
50        {
51            moduleNameToContainedTypes[currentModule].Add(node.Name);
52        }
53    }
54}