예제 #1
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;
        }
예제 #2
0
        public override AstNode Visit(EnumConstantDefinition node)
        {
            // Get the value expression
            Expression valueExpression = node.GetValue();
            valueExpression.Accept(this);

            // Check the value compatibility.
            IChelaType enumType = node.GetCoercionType();
            IChelaType valueType = valueExpression.GetNodeType();
            if(!valueType.IsConstant())
                Error(valueExpression, "expected constant expresion.");
            if(valueType != enumType &&
               Coerce(valueType, enumType) != enumType)
                Error(valueExpression, "incompatible value type.");

            return node;
        }