public override AstNode Visit(ModuleNode node) { // Extract the constants. ConstantGrouping grouping = new ConstantGrouping(); node.Accept(grouping); Dictionary<FieldVariable, ConstantData> constants = grouping.GetConstants(); // Build constant dependency graph and perform a topolgical sort. ConstantDependencies deps = new ConstantDependencies(constants); List<ConstantData> sortedConstants = deps.BuildGraph(); // Expand the constants itself. foreach(ConstantData constant in sortedConstants) { // Visit the initializer. Expression initializer = constant.GetInitializer(); initializer = (Expression)initializer.Accept(this); // The initializer must be a constant. if(!initializer.IsConstant()) Error(initializer, "is not a constant expression."); // The constant expression value must be the constant itself. FieldVariable field = constant.GetVariable(); ConstantValue initValue = (ConstantValue)initializer.GetNodeValue(); field.SetInitializer(initValue.Cast(field.GetVariableType())); } // Now, perform module constant expansion. return base.Visit (node); }
public ChelaCompiler(ModuleType moduleType) { // Create the module node. moduleNode = new ModuleNode(null, null); moduleNode.SetName("global"); // Create the module. ChelaModule module = new ChelaModule(); moduleNode.SetModule(module); module.SetName("unnamed"); module.SetModuleType(moduleType); }
public override AstNode Visit(ModuleNode node) { // This is for the global namespace. currentModule = node.GetModule(); currentScope = currentModule.GetGlobalNamespace(); currentContainer = currentScope; // Create the static constructor. CreateStaticConstructor(node, currentModule.GetGlobalNamespace()); // Visit the children. VisitList(node.GetChildren()); return node; }
public override AstNode Visit(ModuleNode node) { // Store the old module. ChelaModule oldModule = this.currentModule; currentModule = node.GetModule(); // Visit the children. PushScope(currentModule.GetGlobalNamespace()); VisitList(node.GetChildren()); PopScope(); // Restore the module. currentModule = oldModule; return node; }
public override AstNode Visit(ModuleNode node) { currentModule = node.GetModule(); currentScope = currentModule.GetGlobalNamespace(); currentContainer = currentScope; VisitList(node.GetChildren()); return node; }
public virtual AstNode Visit(ModuleNode node) { throw new System.NotImplementedException(); }