コード例 #1
0
 public override void Visit(TemplateAliasParameter p)
 {
     if (p.NameHash == DTokens.IncompleteIdHash)
     {
         halt = true;
         explicitlyNoCompletion = true;
     }
     else
     {
         base.Visit(p);
     }
 }
コード例 #2
0
        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);
        }
コード例 #3
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);
		}
コード例 #4
0
        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.Resolve(p.DefaultType, ctxt);

                    if (res == null)
                    {
                        return(false);
                    }

                    bool ret = false;
                    foreach (var r in res)
                    {
                        if (!Set(p, r, 0))
                        {
                            ret = true;
                        }
                    }

                    if (ret)
                    {
                        return(false);
                    }
                }
                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));
        }
コード例 #5
0
ファイル: Parser_Impl.cs プロジェクト: DinrusGroup/DinrusIDE
		TemplateParameter TemplateParameter(DNode parent)
		{
			CodeLocation startLoc;

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

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

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

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

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

			// 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(0, CodeLocation.Empty, parent);
				al.Location = startLoc;
				LastParsedObject = al;

				// 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
			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 };
				LastParsedObject = tt;

				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 value parameter");
				return null;
			}

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

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

			if (laKind == (Assign))
			{
				Step();
				tv.DefaultExpression = AssignExpression();
			}
			tv.EndLocation = t.EndLocation;
			return tv;
		}
コード例 #6
0
 public ulong Visit(TemplateAliasParameter templateAliasParameter)
 {
     return(1002143);
 }
コード例 #7
0
		bool IsMoreSpecialized(TemplateAliasParameter t1, TemplateAliasParameter t2, Dictionary<int,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;
		}
コード例 #8
0
		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.Resolve(p.DefaultType, ctxt);

					if (res == null)
						return false;

					bool ret = false;
					foreach(var r in res)
						if (!Set(p, r, 0))
						{
							ret = true;
						}

					if (ret)
						return false;
				}
				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);
		}