Example #1
0
 public PropertyAccessor(MemberFlags flags, AstNode children, TokenPosition position)
     : base(null, children, position)
 {
     this.flags = flags;
     this.property = null;
     this.selfLocal = null;
     this.indices = null;
     this.indexerVariables = null;
 }
Example #2
0
 public PropertyDefinition(MemberFlags flags, Expression propertyType,
                           string name, AstNode indices, AstNode accessors, TokenPosition position)
     : base(position)
 {
     SetName(name);
     this.flags = flags;
     this.propertyType = propertyType;
     this.property = null;
     this.indices = indices;
     this.accessors = accessors;
 }
Example #3
0
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal event and register it.
            PropertyVariable prop = new PropertyVariable(module);

            module.RegisterMember(prop);

            // Read the name and flags.
            prop.SetName(module.GetString(header.memberName));
            prop.flags = (MemberFlags)header.memberFlags;

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
Example #4
0
 public void SetProperty(PropertyVariable property)
 {
     this.property = property;
 }
Example #5
0
 public DirectPropertySlot(PropertyVariable property)
     : base(property.GetVariableType(), property.GetModule())
 {
     this.property = property;
 }
Example #6
0
        internal static void PreloadMember(ChelaModule module, ModuleReader reader, MemberHeader header)
        {
            // Create the temporal event and register it.
            PropertyVariable prop = new PropertyVariable(module);
            module.RegisterMember(prop);

            // Read the name and flags.
            prop.SetName(module.GetString(header.memberName));
            prop.flags = (MemberFlags)header.memberFlags;

            // Skip the structure elements.
            reader.Skip(header.memberSize);
        }
Example #7
0
 public DirectPropertySlot(PropertyVariable property)
     : base(property.GetVariableType(), property.GetModule())
 {
     this.property = property;
 }
Example #8
0
        public override AstNode Visit(PropertyDefinition node)
        {
            // Check the property security.
            bool isUnsafe = (node.GetFlags() & MemberFlags.SecurityMask) == MemberFlags.Unsafe;
            if(isUnsafe)
                PushUnsafe();

            // Generate a name for explicit contracts.
            if(node.GetNameExpression() != null)
                node.SetName(GenSym());

            // Checks for indexers.
            if(node.GetNameExpression() == null)
            {
                if(node.GetName() == "this" && node.GetIndices() == null)
                    Error(node, "indexers must have parameters.");
                else if(node.GetName() != "this" && node.GetIndices() != null)
                    Error(node, "indexers name must be 'this'");
            }

            // Use a special name for indexers.
            if(node.GetName() == "this")
                node.SetName("Op_Index");

            // Find an existing property.
            ScopeMember oldProperty = currentContainer.FindMember(node.GetName());
            if(oldProperty != null && !oldProperty.IsProperty())
                Error(node, "trying to override something with a property.");

            // Visit the type expression.
            Expression typeExpr = node.GetPropertyType();
            typeExpr.Accept(this);

            // Extract the meta type.
            IChelaType propType = typeExpr.GetNodeType();
            propType = ExtractActualType(typeExpr, propType);

            // Use references for class/interface.
            if(propType.IsPassedByReference())
                propType = ReferenceType.Create(propType);

            // Store the indices.
            List<IChelaType> indices = new List<IChelaType> ();
            AstNode index = node.GetIndices();
            while(index != null)
            {
                // Visit the index.
                index.Accept(this);

                // Store his type.
                indices.Add(index.GetNodeType());

                // Process the next index.
                index = index.GetNext();
            }

            // Make sure it is the same property.
            PropertyVariable property = null;
            if(oldProperty != null)
            {
                // Compare the property types.
                property = (PropertyVariable) oldProperty;
                if(property.GetVariableType() != propType)
                    Error(node, "trying to overwrite property.");

                // TODO: Check indices.

                // Avoid collisions.
                if(node.GetAccessor != null && property.GetAccessor != null)
                    Error(node.GetAccessor, "multiples definitions.");
                if(node.SetAccessor != null && property.SetAccessor != null)
                    Error(node.GetAccessor, "multiples definitions.");
            }
            else
            {
                // Create the property.
                property = new PropertyVariable(node.GetName(), node.GetFlags(),
                                                propType, indices.ToArray(), currentContainer);

                // Add it into the current scope.
                if(currentContainer.IsNamespace())
                {
                    Namespace space = (Namespace) currentContainer;
                    space.AddMember(property);
                }
                else if(currentContainer.IsClass() || currentContainer.IsStructure() || currentContainer.IsInterface())
                {
                    Structure building = (Structure) currentContainer;
                    building.AddProperty(property);
                }
                else
                    Error(node, "a property cannot be defined here.");
            }

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

            // Set the property in the accessors.
            if(node.GetAccessor != null)
            {
                node.GetAccessor.SetProperty(property);
                node.GetAccessor.SetIndices(node.GetIndices());
            }

            if(node.SetAccessor != null)
            {
                node.SetAccessor.SetProperty(property);
                node.SetAccessor.SetIndices(node.GetIndices());
            }

            // Visit the accessors.
            VisitList(node.GetAccessors());

            // Restore the property security.
            if(isUnsafe)
                PopUnsafe();

            return node;
        }