예제 #1
0
        public override AstNode Visit(AttributeArgument node)
        {
            // Set the node value.
            Expression valueExpr = node.GetValueExpression();
            node.SetNodeValue(valueExpr.GetNodeValue());

            return node;
        }
예제 #2
0
        public override AstNode Visit(AttributeArgument node)
        {
            // Expand the argument value.
            Expression argValue = node.GetValueExpression();
            argValue = (Expression)argValue.Accept(this);
            node.SetValueExpression(argValue);

            return node;
        }
예제 #3
0
        public override AstNode Visit(AttributeArgument node)
        {
            // Process the value expression.
            Expression expr = node.GetValueExpression();
            expr.Accept(this);

            // Store the node type temporarily.
            IChelaType valueType = expr.GetNodeType();
            node.SetNodeType(valueType);

            // Check the property compatibility.
            string propName = node.GetName();
            if(string.IsNullOrEmpty(propName))
                return node;

            // Find the property member.
            Class attributeClass = node.GetAttributeClass();
            ScopeMember propMember = attributeClass.FindMemberRecursive(propName);
            if(propMember == null)
                Error(node, "cannot find attribute property.");
            if(!propMember.IsVariable())
                Error(node, "cannot set something that isn't an attribute property.");

            // Only support settable properties and fields.
            Variable propVar = (Variable)propMember;
            if(propVar.IsProperty())
            {
                PropertyVariable property = (PropertyVariable)propVar;
                if(property.SetAccessor == null)
                    Error(node, "the attribute property is not settable.");
            }
            else if(!propVar.IsField())
                Error(node, "the attribute is not a field nor a settable property.");

            // Check the property visibility
            CheckMemberVisibility(node, propVar);

            // Store the property
            node.SetProperty(propVar);

            // Perform coercion.
            IChelaType propType = propVar.GetVariableType();
            if(valueType != propType &&
               Coerce(propType, valueType) != propType)
                Error(node, "unexistent implicit cast for property assignment.");

            // Make sure the value is constant.
            if(!valueType.IsConstant())
                Error(node, "expected constant value.");

            // Store the coercion type.
            node.SetCoercionType(propType);

            // Store the node type.
            node.SetNodeType(propType);

            return node;
        }