Exemplo n.º 1
0
        public override AstNode Visit(AttributeInstance node)
        {
            // Create the attribute constant.
            Class attributeClass = node.GetAttributeClass();
            Method attributeCtor = node.GetAttributeConstructor();
            AttributeConstant attrConstant = new AttributeConstant(attributeClass, attributeCtor);

            // Set the attribute constant as the node value.
            node.SetNodeValue(attrConstant);

            // Store the arguments.
            AstNode arg = node.GetArguments();
            while(arg != null)
            {
                // Vist the argument.
                arg.Accept(this);

                // Add the argument.
                ConstantValue value = (ConstantValue)arg.GetNodeValue();
                AttributeArgument attrArg = (AttributeArgument)arg;
                Variable property = attrArg.GetProperty();
                if(property != null)
                    attrConstant.AddPropertyValue(property, value);
                else
                    attrConstant.AddArgument(value);

                // Check the next argument.
                arg = arg.GetNext();
            }
            return node;
        }
Exemplo n.º 2
0
        public override AstNode Visit(AttributeInstance node)
        {
            // Visit the arguments.
            VisitList(node.GetArguments());

            return node;
        }
Exemplo n.º 3
0
        public override AstNode Visit(AttributeInstance node)
        {
            // Read the attribute type.
            Expression attrExpr = node.GetAttributeExpr();
            if(attrExpr is ObjectReferenceExpression)
            {
                ObjectReferenceExpression refExpr = (ObjectReferenceExpression)attrExpr;
                refExpr.SetAttributeName(true);
            }

            attrExpr.Accept(this);

            // Get his type.
            IChelaType attrType = attrExpr.GetNodeType();
            attrType = ExtractActualType(attrExpr, attrType);
            if(!attrType.IsClass())
                Error(node, "attributes must be classes.");

            // Make sure is derived from the Attribute class.
            Class attributeClass = currentModule.GetAttributeClass();
            Class attrBuilding = (Class)attrType;
            if(!attrBuilding.IsDerivedFrom(attributeClass))
                Error(node, "invalid attribute class.");

            // Store the attribute class.
            node.SetAttributeClass(attrBuilding);

            // Visit the attribute arguments.
            AstNode arg = node.GetArguments();
            List<object> arguments = new List<object> ();
            bool readingProperties = false;
            while(arg != null)
            {
                // Store the attribute type.
                AttributeArgument attrArg = (AttributeArgument)arg;
                attrArg.SetAttributeClass(attrBuilding);

                // Visit the argument.
                arg.Accept(this);

                // Check property/vs constructor argument.
                bool propertyArgument = !string.IsNullOrEmpty(arg.GetName());
                if(propertyArgument)
                {
                    // Start/started reading properties values.
                    readingProperties = true;
                }
                else
                {
                    // Check for unnamed value.
                    if(readingProperties)
                        Error(arg, "expected attribute property value.");

                    // Store the argument.
                    arguments.Add(arg.GetNodeType());
                }

                // Visit the next argument.
                arg = arg.GetNext();
            }

            // Pick the correct attribute constructor.
            FunctionGroup ctorGroup = attrBuilding.GetConstructor();
            Function ctor = PickFunction(node, ctorGroup, false, null, arguments, false);
            if(!ctor.IsMethod())
                Error(node, "invalid constructor."); // Shouldn't reach here.

            // Store the picked constructor.
            node.SetAttributeConstructor((Method)ctor);

            return node;
        }