コード例 #1
0
        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;
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: ConstantGrouping.cs プロジェクト: ronsaldo/chela
        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;
        }
コード例 #5
0
ファイル: ConstantGrouping.cs プロジェクト: ronsaldo/chela
        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;
        }
コード例 #6
0
ファイル: ConstantData.cs プロジェクト: ronsaldo/chela
        public void AddDependency(ConstantData dep)
        {
            foreach(ConstantData field in dependencies)
                if(field == dep)
                    return;

            dependencies.Add(dep);
        }
コード例 #7
0
        public void AddDependency(ConstantData dep)
        {
            foreach (ConstantData field in dependencies)
            {
                if (field == dep)
                {
                    return;
                }
            }

            dependencies.Add(dep);
        }
コード例 #8
0
        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;
        }
コード例 #9
0
        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);
        }
コード例 #10
0
 public ConstantDependencies(Dictionary <FieldVariable, ConstantData> constants)
 {
     this.constants       = constants;
     this.currentConstant = null;
 }
コード例 #11
0
 public ConstantDependencies(Dictionary<FieldVariable, ConstantData> constants)
 {
     this.constants = constants;
     this.currentConstant = null;
 }
コード例 #12
0
        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;
        }