public virtual void Visit(TemplateValueParameter 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);
            }
        }
        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);
        }
		bool IsMoreSpecialized(TemplateValueParameter t1, TemplateValueParameter t2)
		{
			if (t1.SpecializationExpression != null && t2.SpecializationExpression == null)
				return true;
			return false;
		}
Exemple #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(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 #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(TemplateValueParameter p)
 {
     if (p.Type != null && !IsIncompleteDeclaration(p.Type) &&
         p.NameHash == DTokens.IncompleteIdHash) {
         halt = true;
         explicitlyNoCompletion = true;
     }
     else
         base.Visit (p);
 }
Exemple #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;
		}
		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;
			}
		}