private void TopoVisit(ConstantData constant, List <ConstantData> sorted) { // Prevent circular references. if (constant.visiting) { Error(constant.GetInitializer(), "circular constant initialization."); } // Ignore visited constants. if (constant.visited) { return; } // Set the visiting flag. constant.visiting = true; // Visit the constant dependencies. foreach (ConstantData dep in constant.GetDependencies()) { TopoVisit(dep, sorted); } // Append the constant to the sorted list. sorted.Add(constant); // Unset the visiting flag, mark as visited. constant.visited = true; constant.visiting = false; }
public override AstNode Visit(EnumConstantDefinition node) { // Get the field. FieldVariable field = node.GetVariable(); // Ignore external constants. if (field.IsExternal()) { return(node); } // Get the initializer. Expression initializer = node.GetValue(); if (initializer == null) { Error(node, "constants must have initializers."); } // Don't allow multiple definitions. if (constants.ContainsKey(field)) { Error(node, "multiples definitions of a constant."); } // Store the constant. ConstantData data = new ConstantData(field, initializer); this.constants.Add(field, data); // Return the node. return(node); }
public override AstNode Visit(FieldDeclaration node) { // Get the field. FieldVariable field = (FieldVariable)node.GetVariable(); // Get the field type. IChelaType fieldType = field.GetVariableType(); if (!fieldType.IsConstant() || field.IsExternal()) { return(node); // Ignore not constant fields. } // Get the initializer. Expression initializer = node.GetDefaultValue(); if (initializer == null) { Error(node, "constants must have initializers."); } // Don't allow multiple definitions. if (constants.ContainsKey(field)) { Error(node, "multiples definitions of a constant."); } // Store the constant. ConstantData data = new ConstantData(field, initializer); this.constants.Add(field, data); // Return the node. return(node); }
public override AstNode Visit(FieldDeclaration node) { // Get the field. FieldVariable field = (FieldVariable)node.GetVariable(); // Get the field type. IChelaType fieldType = field.GetVariableType(); if(!fieldType.IsConstant() || field.IsExternal()) return node; // Ignore not constant fields. // Get the initializer. Expression initializer = node.GetDefaultValue(); if(initializer == null) Error(node, "constants must have initializers."); // Don't allow multiple definitions. if(constants.ContainsKey(field)) Error(node, "multiples definitions of a constant."); // Store the constant. ConstantData data = new ConstantData(field, initializer); this.constants.Add(field, data); // Return the node. return node; }
public override AstNode Visit(EnumConstantDefinition node) { // Get the field. FieldVariable field = node.GetVariable(); // Ignore external constants. if(field.IsExternal()) return node; // Get the initializer. Expression initializer = node.GetValue(); if(initializer == null) Error(node, "constants must have initializers."); // Don't allow multiple definitions. if(constants.ContainsKey(field)) Error(node, "multiples definitions of a constant."); // Store the constant. ConstantData data = new ConstantData(field, initializer); this.constants.Add(field, data); // Return the node. return node; }
public void AddDependency(ConstantData dep) { foreach(ConstantData field in dependencies) if(field == dep) return; dependencies.Add(dep); }
public void AddDependency(ConstantData dep) { foreach (ConstantData field in dependencies) { if (field == dep) { return; } } dependencies.Add(dep); }
public List<ConstantData> BuildGraph() { // First build the constants dependency graph. foreach(ConstantData constant in constants.Values) { // Store the current constant. currentConstant = constant; // Visit the initializer expression. Expression init = constant.GetInitializer(); init.Accept(this); } // Now, perform topological sort. List<ConstantData> sorted = new List<ConstantData> (); foreach(ConstantData constant in constants.Values) TopoVisit(constant, sorted); return sorted; }
public List <ConstantData> BuildGraph() { // First build the constants dependency graph. foreach (ConstantData constant in constants.Values) { // Store the current constant. currentConstant = constant; // Visit the initializer expression. Expression init = constant.GetInitializer(); init.Accept(this); } // Now, perform topological sort. List <ConstantData> sorted = new List <ConstantData> (); foreach (ConstantData constant in constants.Values) { TopoVisit(constant, sorted); } return(sorted); }
public ConstantDependencies(Dictionary <FieldVariable, ConstantData> constants) { this.constants = constants; this.currentConstant = null; }
public ConstantDependencies(Dictionary<FieldVariable, ConstantData> constants) { this.constants = constants; this.currentConstant = null; }
private void TopoVisit(ConstantData constant, List<ConstantData> sorted) { // Prevent circular references. if(constant.visiting) Error(constant.GetInitializer(), "circular constant initialization."); // Ignore visited constants. if(constant.visited) return; // Set the visiting flag. constant.visiting = true; // Visit the constant dependencies. foreach(ConstantData dep in constant.GetDependencies()) TopoVisit(dep, sorted); // Append the constant to the sorted list. sorted.Add(constant); // Unset the visiting flag, mark as visited. constant.visited = true; constant.visiting = false; }