示例#1
0
 public GenericSignature(GenericParameter parameters, GenericConstraint constraints,
                          TokenPosition position)
     : base(position)
 {
     this.parameters = parameters;
     this.constraints = constraints;
 }
示例#2
0
 public GenericSignature(GenericParameter parameters, GenericConstraint constraints,
                         TokenPosition position)
     : base(position)
 {
     this.parameters  = parameters;
     this.constraints = constraints;
 }
示例#3
0
 public void SetConstraints(GenericConstraint constraints)
 {
     this.constraints = constraints;
 }
示例#4
0
        public override AstNode Visit(GenericConstraint node)
        {
            // Find the parameter.
            GenericSignature signature = node.GetSignature();
            AstNode current = signature.GetParameters();
            GenericParameter parameter = null;
            while(current != null)
            {
                if(current.GetName() == node.GetName())
                {
                    // Found.
                    parameter = (GenericParameter) current;
                    break;
                }

                // Check the next parameter.
                current = current.GetNext();
            }

            // Raise an error for unknown parameter.
            if(parameter == null)
                Error(node, "unknown generic parameter '{0}'", node.GetName());

            // Fetch the bases.
            List<Structure> bases = new List<Structure> ();
            current = node.GetBases();
            bool hasClass = false;
            while(current != null)
            {
                // Visit the base expression.
                current.Accept(this);

                // Get the base type.
                IChelaType nodeType = current.GetNodeType();
                if(!nodeType.IsMetaType())
                    Error(current, "expected class/interface type.");

                // Remove the meta layer.
                nodeType = ExtractActualType(current, nodeType);

                // Make sure is a class or a structure.
                if(!nodeType.IsClass() && !nodeType.IsStructure() && !nodeType.IsInterface())
                    Error(current, "expected class/struct/interface type.");

                // Enforce single inheritance.
                if(nodeType.IsClass())
                {
                    if(hasClass)
                        Error(current, "only single inheritance is supported.");
                    hasClass = true;
                }

                // Store the base.
                bases.Add((Structure)nodeType);

                // Check the next base.
                current = current.GetNext();
            }

            // Store the constraint data in the parameter.
            parameter.SetValueType(node.IsValueType());
            parameter.SetBases(bases);

            return node;
        }
示例#5
0
 public virtual AstNode Visit(GenericConstraint node)
 {
     throw new System.NotImplementedException();
 }
示例#6
0
 public virtual AstNode Visit(GenericConstraint node)
 {
     throw new System.NotImplementedException();
 }
示例#7
0
 public void SetConstraints(GenericConstraint constraints)
 {
     this.constraints = constraints;
 }