bool Handle(TemplateAliasParameter p, ISemantic arg)
		{
			#region Handle parameter defaults
			if (arg == null)
			{
				if (p.DefaultExpression != null)
				{
					var eval = Evaluation.EvaluateValue(p.DefaultExpression, ctxt);

					if (eval == null)
						return false;

					return Set(p, eval, 0);
				}
				else if (p.DefaultType != null)
				{
					var res = TypeDeclarationResolver.ResolveSingle(p.DefaultType, ctxt);

					return res != null && Set(p, res, 0);
				}
				return false;
			}
			#endregion

			#region Given argument must be a symbol - so no built-in type but a reference to a node or an expression
			var t=AbstractType.Get(arg);
			
			if (t == null)
				return false;
			
			if(!(t is DSymbol))
				while (t != null)
				{
					if (t is PrimitiveType) // arg must not base on a primitive type.
						return false;
	
					if (t is DerivedDataType)
						t = ((DerivedDataType)t).Base;
					else
						break;
				}
			#endregion

			#region Specialization check
			if (p.SpecializationExpression != null)
			{
				// LANGUAGE ISSUE: Can't do anything here - dmd won't let you use MyClass!(2) though you have class MyClass(alias X:2)
				return false;
			}
			else if (p.SpecializationType != null)
			{
				// ditto
				return false;
			}
			#endregion

			return Set(p,arg,0);
		}
        public virtual void Visit(TemplateAliasParameter p)
        {
            Visit((TemplateValueParameter)p);

            if (p.SpecializationType != null)
            {
                p.SpecializationType.Accept(this);
            }
            if (p.DefaultType != null)
            {
                p.DefaultType.Accept(this);
            }
        }
		bool IsMoreSpecialized(TemplateAliasParameter t1, TemplateAliasParameter t2, Dictionary<TemplateParameter, ISemantic> t1_DummyParamList)
		{
			if (t1.SpecializationExpression != null)
			{
				if(t2.SpecializationExpression == null)
					return true;
				// It's not needed to test both expressions for equality because they actually were equal to the given template instance argument
				// à la  'a = b, a = c => b = c'
				return false;
			}
			else if (t1.SpecializationType != null)
			{
				if (t2.SpecializationType == null)
					return true;

				return IsMoreSpecialized(t1.SpecializationType, t2, t1_DummyParamList);
			}
			return false;
		}
示例#4
0
        TemplateParameter TemplateParameter(DNode parent)
        {
            CodeLocation startLoc;

            // TemplateThisParameter
            if (laKind == (This))
            {
                Step();

                startLoc = t.Location;
                var end = t.EndLocation;

                return new TemplateThisParameter(TemplateParameter(parent), parent) { Location=startLoc, EndLocation=end };
            }

            // TemplateTupleParameter
            else if (laKind == (Identifier) && Lexer.CurrentPeekToken.Kind == TripleDot)
            {
                Step();
                startLoc = t.Location;
                var id = t.Value;
                Step();

                return new TemplateTupleParameter(id, startLoc, parent) { Location=startLoc, EndLocation=t.EndLocation	};
            }

            // TemplateAliasParameter
            else if (laKind == (Alias))
            {
                Step();

                startLoc = t.Location;
                TemplateAliasParameter al;

                if(Expect(Identifier))
                    al = new TemplateAliasParameter(t.Value, t.Location, parent);
                else
                    al = new TemplateAliasParameter(IsEOF ? DTokens.IncompleteIdHash : 0 , CodeLocation.Empty, parent);
                al.Location = startLoc;

                // TODO?:
                // alias BasicType Declarator TemplateAliasParameterSpecialization_opt TemplateAliasParameterDefault_opt

                // TemplateAliasParameterSpecialization
                if (laKind == (Colon))
                {
                    Step();

                    AllowWeakTypeParsing=true;
                    al.SpecializationType = Type();
                    AllowWeakTypeParsing=false;

                    if (al.SpecializationType==null)
                        al.SpecializationExpression = ConditionalExpression();
                }

                // TemplateAliasParameterDefault
                if (laKind == (Assign))
                {
                    Step();

                    if (IsAssignExpression ())
                        al.DefaultExpression = ConditionalExpression ();
                    else
                        al.DefaultType = Type ();
                }
                al.EndLocation = t.EndLocation;
                return al;
            }

            // TemplateTypeParameter
            else if (laKind == (Identifier) && (Lexer.CurrentPeekToken.Kind == (Colon) || Lexer.CurrentPeekToken.Kind == (Assign) || Lexer.CurrentPeekToken.Kind == (Comma) || Lexer.CurrentPeekToken.Kind == (CloseParenthesis)))
            {
                Expect(Identifier);
                var tt = new TemplateTypeParameter(t.Value, t.Location, parent) { Location = t.Location };

                if (laKind == Colon)
                {
                    Step();
                    tt.Specialization = Type();
                }

                if (laKind == Assign)
                {
                    Step();
                    tt.Default = Type();
                }
                tt.EndLocation = t.EndLocation;
                return tt;
            }

            // TemplateValueParameter
            startLoc = la.Location;
            var bt = BasicType();
            var dv = Declarator(bt,false, null);

            if (dv == null) {
                SynErr (t.Kind, "Declarator expected for parsing template parameter");
                return new TemplateTypeParameter (DTokens.IncompleteIdHash, t.Location, parent) { Location = t.Location };
            }

            var tv = new TemplateValueParameter(dv.NameHash, dv.NameLocation, parent) {
                Location=la.Location,
                Type = dv.Type
            };

            if (laKind == (Colon))
            {
                Step();
                tv.SpecializationExpression = ConditionalExpression();
            }

            if (laKind == (Assign))
            {
                Step();
                tv.DefaultExpression = AssignExpression();
            }
            tv.EndLocation = t.EndLocation;
            return tv;
        }
        public virtual void Visit(TemplateAliasParameter p)
        {
            Visit((TemplateValueParameter)p);

            if (p.SpecializationType != null)
                p.SpecializationType.Accept(this);
            if (p.DefaultType != null)
                p.DefaultType.Accept(this);
        }
示例#6
0
        ITemplateParameter TemplateParameter()
        {
            // TemplateThisParameter
            if (laKind == (This))
            {
                Step();

                var ret= new TemplateThisParameter()
                {
                    Location=t.Location,
                    FollowParameter=TemplateParameter(),
                    EndLocation=t.EndLocation
                };
                LastParsedObject = ret;
                return ret;
            }

            // TemplateTupleParameter
            if (laKind == (Identifier) && Lexer.CurrentPeekToken.Kind == TripleDot)
            {
                Step();
                var startLoc = t.Location;
                var id = t.Value;
                Step();

                var ret=new TemplateTupleParameter() { Name=id, Location=startLoc, EndLocation=t.EndLocation};
                LastParsedObject = ret;
                return ret;
            }

            // TemplateAliasParameter
            if (laKind == (Alias))
            {
                Step();
                var al = new TemplateAliasParameter() { Location=t.Location };
                LastParsedObject = al;

                Expect(Identifier);

                al.Name = t.Value;

                // TODO?:
                // alias BasicType Declarator TemplateAliasParameterSpecialization_opt TemplateAliasParameterDefault_opt

                // TemplateAliasParameterSpecialization
                if (laKind == (Colon))
                {
                    Step();

                    AllowWeakTypeParsing=true;
                    al.SpecializationType = Type();
                    AllowWeakTypeParsing=false;

                    if (al.SpecializationType==null)
                        al.SpecializationExpression = ConditionalExpression();
                }

                // TemplateAliasParameterDefault
                if (laKind == (Assign))
                {
                    Step();

                    AllowWeakTypeParsing=true;
                    al.DefaultType = Type();
                    AllowWeakTypeParsing=false;

                    if (al.DefaultType==null)
                        al.DefaultExpression = ConditionalExpression();
                }
                al.EndLocation = t.EndLocation;
                return al;
            }

            // TemplateTypeParameter
            if (laKind == (Identifier) && (Lexer.CurrentPeekToken.Kind == (Colon) || Lexer.CurrentPeekToken.Kind == (Assign) || Lexer.CurrentPeekToken.Kind == (Comma) || Lexer.CurrentPeekToken.Kind == (CloseParenthesis)))
            {
                Expect(Identifier);
                var tt = new TemplateTypeParameter() { Location=t.Location };
                LastParsedObject = tt;

                tt.Name = t.Value;

                if (laKind == Colon)
                {
                    Step();
                    tt.Specialization = Type();
                }

                if (laKind == Assign)
                {
                    Step();
                    tt.Default = Type();
                }
                tt.EndLocation = t.EndLocation;
                return tt;
            }

            // TemplateValueParameter
            var tv = new TemplateValueParameter() { Location=la.Location };
            LastParsedObject = tv;

            var bt = BasicType();
            var dv = Declarator(bt,false);

            tv.Type = dv.Type;
            tv.Name = dv.Name;

            if (laKind == (Colon))
            {
                Step();
                tv.SpecializationExpression = ConditionalExpression();
            }

            if (laKind == (Assign))
            {
                Step();
                tv.DefaultExpression = AssignExpression();
            }
            tv.EndLocation = t.EndLocation;
            return tv;
        }
 public override void Visit(TemplateAliasParameter p)
 {
     if (p.NameHash == DTokens.IncompleteIdHash) {
         halt = true;
         explicitlyNoCompletion = true;
     }
     else
         base.Visit (p);
 }
示例#8
0
		TemplateParameter TemplateParameter(DNode parent)
		{
			IBlockNode scope = parent as IBlockNode;
			CodeLocation startLoc;

			// TemplateThisParameter
			if (laKind == (This))
			{
				Step();

				startLoc = t.Location;
				var end = t.EndLocation;

				return new TemplateThisParameter(TemplateParameter(parent), parent) { Location=startLoc, EndLocation=end };
			}

			// TemplateTupleParameter
			else if (laKind == (Identifier) && Lexer.CurrentPeekToken.Kind == TripleDot)
			{
				Step();
				startLoc = t.Location;
				var id = t.Value;
				Step();

				return new TemplateTupleParameter(id, startLoc, parent) { Location=startLoc, EndLocation=t.EndLocation	};
			}

			// TemplateAliasParameter
			else if (laKind == (Alias))
			{
				Step();

				startLoc = t.Location;
				TemplateAliasParameter al;
				ITypeDeclaration bt;

				if(IsEOF)
					al = new TemplateAliasParameter(DTokens.IncompleteIdHash, CodeLocation.Empty, parent);
				else
				{
					bt = BasicType (scope);
					ParseBasicType2 (ref bt, scope);

					if (laKind == Identifier) {
						// alias BasicType Declarator TemplateAliasParameterSpecialization_opt TemplateAliasParameterDefault_opt
						var nn = Declarator (bt, false, parent);
						al = new TemplateAliasParameter (nn.NameHash, nn.NameLocation, parent);
						al.Type = nn.Type;
						//TODO: Assign other parts of the declarator? Parameters and such?
					} else if (bt is IdentifierDeclaration)
						al = new TemplateAliasParameter ((bt as IdentifierDeclaration).IdHash, bt.Location, parent);
					else
						al = new TemplateAliasParameter (0, CodeLocation.Empty, parent);
				}
				al.Location = startLoc;

				// TemplateAliasParameterSpecialization
				if (laKind == (Colon))
				{
					Step();

					AllowWeakTypeParsing=true;
					al.SpecializationType = Type(scope);
					AllowWeakTypeParsing=false;

					if (al.SpecializationType==null)
						al.SpecializationExpression = ConditionalExpression(scope);
				}

				// TemplateAliasParameterDefault
				if (laKind == (Assign))
				{
					Step();

					if (IsAssignExpression ())
						al.DefaultExpression = ConditionalExpression (scope);
					else
						al.DefaultType = Type (scope);
				}
				al.EndLocation = t.EndLocation;
				return al;
			}

			// TemplateTypeParameter
			else if (laKind == (Identifier) && (Lexer.CurrentPeekToken.Kind == (Colon) || Lexer.CurrentPeekToken.Kind == (Assign) || Lexer.CurrentPeekToken.Kind == (Comma) || Lexer.CurrentPeekToken.Kind == (CloseParenthesis)))
			{
				Expect(Identifier);
				var tt = new TemplateTypeParameter(t.Value, t.Location, parent) { Location = t.Location };

				if (laKind == Colon)
				{
					Step();
					tt.Specialization = Type(scope);
				}

				if (laKind == Assign)
				{
					Step();
					tt.Default = Type(scope);
				}
				tt.EndLocation = t.EndLocation;
				return tt;
			}

			// TemplateValueParameter
			startLoc = la.Location;
			var dv = Declarator(BasicType(scope), false, null);

			if (dv == null) {
				SynErr (t.Kind, "Declarator expected for parsing template parameter");
				return new TemplateTypeParameter (DTokens.IncompleteIdHash, t.Location, parent) { Location = t.Location };
			}

			var tv = new TemplateValueParameter(dv.NameHash, dv.NameLocation, parent) { 
				Location=startLoc,
				Type = dv.Type
			};

			if (laKind == (Colon))
			{
				Step();
				tv.SpecializationExpression = ConditionalExpression(scope);
			}

			if (laKind == (Assign))
			{
				Step();
				tv.DefaultExpression = AssignExpression(scope);
			}
			tv.EndLocation = t.EndLocation;
			return tv;
		}