public override void Visit(TemplateValueParameter p)
        {
            // Don't show on 'struct foo(int |' as well as on 'struct foo(|'
            // - if a type is wanted, the user still may press ctrl+space
            if (p.NameHash == DTokens.IncompleteIdHash)
            {
                halt = true;
                explicitlyNoCompletion = true;
                return;
            }

            VisitTemplateParameter(p);

            if (!halt && p.Type != null)
            {
                p.Type.Accept(this);
            }

            if (!halt && p.SpecializationExpression != null)             //TODO have a special completion case for specialization completion
            {
                p.SpecializationExpression.Accept(this);
            }

            if (!halt && p.DefaultExpression != null)
            {
                handlesInitializer = true;
                //initializedNode = p.Representation;
                p.DefaultExpression.Accept(this);
                handlesInitializer = false;
            }
        }
 bool IsMoreSpecialized(TemplateValueParameter t1, TemplateValueParameter t2)
 {
     if (t1.SpecializationExpression != null && t2.SpecializationExpression == null)
     {
         return(true);
     }
     return(false);
 }
        bool Handle(TemplateValueParameter p, ISemantic arg)
        {
            // Handle default arg case
            if (arg == null)
            {
                if (p.DefaultExpression != null)
                {
                    var eval = Evaluation.EvaluateValue(p.DefaultExpression, ctxt);

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

                    return(Set(p, eval));
                }
                else
                {
                    return(false);
                }
            }

            var valueArgument = arg as ISymbolValue;

            // There must be a constant expression given!
            if (valueArgument == null)
            {
                return(false);
            }

            // Check for param type <-> arg expression type match
            var paramType = TypeDeclarationResolver.Resolve(p.Type, ctxt);

            if (paramType == null || paramType.Length == 0)
            {
                return(false);
            }

            if (valueArgument.RepresentedType == null ||
                !ResultComparer.IsImplicitlyConvertible(paramType[0], valueArgument.RepresentedType))
            {
                return(false);
            }

            // If spec given, test for equality (only ?)
            if (p.SpecializationExpression != null)
            {
                var specVal = Evaluation.EvaluateValue(p.SpecializationExpression, ctxt);

                if (specVal == null || !SymbolValueComparer.IsEqual(specVal, valueArgument))
                {
                    return(false);
                }
            }

            return(Set(p, arg));
        }
 public override void Visit(TemplateValueParameter p)
 {
     if (p.Type != null && !IsIncompleteDeclaration(p.Type) &&
         p.NameHash == DTokens.IncompleteIdHash)
     {
         halt = true;
         explicitlyNoCompletion = true;
     }
     else
     {
         base.Visit(p);
     }
 }
		bool Handle(TemplateValueParameter p, ISemantic arg)
		{
			// Handle default arg case
			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
					return false;
			}

			var valueArgument = arg as ISymbolValue;

			// There must be a constant expression given!
			if (valueArgument == null)
				return false;

			// Check for param type <-> arg expression type match
			var paramType = TypeDeclarationResolver.Resolve(p.Type, ctxt);

			if (paramType == null || paramType.Length == 0)
				return false;

			if (valueArgument.RepresentedType == null ||
				!ResultComparer.IsImplicitlyConvertible(paramType[0], valueArgument.RepresentedType))
				return false;

			// If spec given, test for equality (only ?)
			if (p.SpecializationExpression != null) 
			{
				var specVal = Evaluation.EvaluateValue(p.SpecializationExpression, ctxt);

				if (specVal == null || !SymbolValueComparer.IsEqual(specVal, valueArgument))
					return false;
			}

			return Set(p, arg, 0);
		}
		public virtual void Visit(TemplateValueParameter p)
		{
			VisitTemplateParameter (p);
			if (p.Type != null)
				p.Type.Accept(this);

			if (p.SpecializationExpression != null)
				p.SpecializationExpression.Accept(this);
			if (p.DefaultExpression != null)
				p.DefaultExpression.Accept(this);
		}
Exemple #7
0
		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;
		}
 public ulong Visit(TemplateValueParameter templateValueParameter)
 {
     return(1002121);
 }
		bool IsMoreSpecialized(TemplateValueParameter t1, TemplateValueParameter t2)
		{
			if (t1.SpecializationExpression != null && t2.SpecializationExpression == null)
				return true;
			return false;
		}