Exemple #1
0
 public TemplateTypeParameter(int nameHash, CodeLocation nameLoc, DNode parent) : base(nameHash, nameLoc, parent)
 {
 }
Exemple #2
0
		public StaticProperty(DNode n, AbstractType bt, StaticProperties.ValueGetterHandler valueGetter) : base(n, bt, null)
		{
			this.n = n;
			this.ValueGetter = valueGetter;
		}
Exemple #3
0
		public MemberSymbol(DNode member, AbstractType memberType, ISyntaxRegion td,
			IEnumerable<TemplateParameterSymbol> deducedTypes)
			: base(member, memberType, deducedTypes, td) { }
Exemple #4
0
		void TemplateParameterList(DNode dn)
		{
			if (!Expect(OpenParenthesis))
			{
				SynErr(OpenParenthesis, "Template parameter list expected");
				dn.TemplateParameters = new TemplateParameter[0];
				return;
			}

			if (laKind == (CloseParenthesis))
			{
				Step();
				return;
			}

			var ret = new List<TemplateParameter>();

			bool init = true;
			while (init || laKind == (Comma))
			{
				if (init) init = false;
				else Step();

				if (laKind == CloseParenthesis)
					break;

				ret.Add(TemplateParameter(dn));
			}

			Expect(CloseParenthesis);

			dn.TemplateParameters = ret.ToArray();
		}
Exemple #5
0
		public DSymbol(DNode Node, AbstractType BaseType, IEnumerable<TemplateParameterSymbol> deducedTypes, ISyntaxRegion td)
			: base(BaseType, td)
		{
			if(deducedTypes!=null)
				this.DeducedTypes = new ReadOnlyCollection<TemplateParameterSymbol>(deducedTypes.ToArray());

			if (Node == null)
				throw new ArgumentNullException ("Node");

			this.definition = new WeakReference(Node);
			NameHash = Node.NameHash;
		}
Exemple #6
0
		/// <summary>
		/// Add some syntax possibilities here
		/// int (x);
		/// int(*foo);
		/// This way of declaring function pointers is deprecated
		/// </summary>
		void OldCStyleFunctionPointer(DNode ret, bool IsParam)
		{
			Step();
			//SynErr(OpenParenthesis,"C-style function pointers are deprecated. Use the function() syntax instead."); // Only deprecated in D2
			var cd = new DelegateDeclaration() as ITypeDeclaration;
			LastParsedObject = cd;
			ret.Type = cd;
			var deleg = cd as DelegateDeclaration;

			/*			 
			 * Parse all basictype2's that are following the initial '('
			 */
			while (IsBasicType2())
			{
				var ttd = BasicType2();

				if (deleg.ReturnType == null) 
					deleg.ReturnType = ttd;
				else
				{
					if(ttd!=null)
						ttd.InnerDeclaration = deleg.ReturnType;
					deleg.ReturnType = ttd;
				}
			}

			/*			
			 * Here can be an identifier with some optional DeclaratorSuffixes
			 */
			if (laKind != (CloseParenthesis))
			{
				if (IsParam && laKind != (Identifier))
				{
					/* If this Declarator is a parameter of a function, don't expect anything here
					 * except a '*' that means that here's an anonymous function pointer
					 */
					if (t.Kind != (Times))
						SynErr(Times);
				}
				else
				{
					if(Expect(Identifier))
						ret.Name = t.Value;

					/*					
					 * Just here suffixes can follow!
					 */
					if (laKind != (CloseParenthesis))
					{
						DeclaratorSuffixes(ret);
					}
				}
			}
			ret.Type = cd;
			Expect(CloseParenthesis);
		}
Exemple #7
0
		void FunctionAttributes(DNode n)
		{
			FunctionAttributes(ref n.Attributes);
		}
		private static bool DeduceParams(IEnumerable<ISemantic> givenTemplateArguments, 
			bool isMethodCall, 
			ResolutionContext ctxt, 
			DSymbol overload, 
			DNode tplNode, 
			DeducedTypeDictionary deducedTypes)
		{
			bool isLegitOverload = true;

			var paramEnum = tplNode.TemplateParameters.GetEnumerator();

			var args = givenTemplateArguments ?? new List<ISemantic> ();

			var argEnum = args.GetEnumerator();
			foreach (var expectedParam in tplNode.TemplateParameters)
				if (!DeduceParam(ctxt, overload, deducedTypes, argEnum, expectedParam))
				{
					isLegitOverload = false;
					break; // Don't check further params if mismatch has been found
				}

			if (!isMethodCall && argEnum.MoveNext())
			{
				// There are too many arguments passed - discard this overload
				isLegitOverload = false;
			}
			return isLegitOverload;
		}
		public bool MatchesConditions(DNode n)
		{
			return true;
		}
Exemple #10
0
 public TemplateParameter(string name, CodeLocation nameLoc, DNode par) : this(name.GetHashCode(), nameLoc, par)
 {
     Strings.Add(name);
 }
Exemple #11
0
 public TemplateParameter(int nameHash, CodeLocation nameLoc, DNode par)
 {
     NameHash     = nameHash;
     NameLocation = nameLoc;
     this.parent  = new WeakReference(par);
 }
Exemple #12
0
 public TemplateTupleParameter(string name, CodeLocation nameLoc, DNode parent) : base(name, nameLoc, parent)
 {
 }
Exemple #13
0
 public TemplateAliasParameter(int name, CodeLocation nameLoc, DNode parent) : base(name, nameLoc, parent)
 {
 }
Exemple #14
0
 public TemplateThisParameter(TemplateParameter followParam, DNode parent)
     : base(followParam != null ? followParam.Name : string.Empty,
            followParam != null ? followParam.NameLocation : new CodeLocation(), parent)
 {
     FollowParameter = followParam;
 }
		public override void VisitDNode(DNode n)
		{
			base.VisitDNode(n);
		}
Exemple #16
0
 void ApplyAttributes(DNode n)
 {
 	n.Attributes = GetCurrentAttributeSet();
 }
		/// <summary>
		/// Call before pushing a new indent level and before call base.Visit for the respective node!
		/// </summary>
		void FormatAttributedNode(DNode n, bool fmtStartLocation = true)
		{
			bool firstAttr = fmtStartLocation;
			if(n.Attributes != null)
			foreach(var a in n.Attributes)
			{
				if(AlreadyHandledAttributes.Contains(a))
					continue;
				AlreadyHandledAttributes.Add(a);
				
				if(a is AtAttribute || firstAttr){
					FixIndentationForceNewLine(a.Location);
					firstAttr = false;
				}
			}
			
			if(fmtStartLocation)
				FixIndentationForceNewLine(n.Location);
		}
		bool MatchesCompilationConditions(DNode n)
		{
			if((ctxt.Options & ResolutionOptions.IgnoreDeclarationConditions) != 0)
				return true;

			return ctxt.CurrentContext.MatchesDeclarationEnvironment (n.Attributes);

			return false;
		}
Exemple #19
0
		/// <summary>
		/// Note:
		/// http://www.digitalmars.com/d/2.0/declaration.html#DeclaratorSuffix
		/// The definition of a sequence of declarator suffixes is buggy here! Theoretically template parameters can be declared without a surrounding ( and )!
		/// Also, more than one parameter sequences are possible!
		/// 
		/// TemplateParameterList[opt] Parameters MemberFunctionAttributes[opt]
		/// </summary>
		void DeclaratorSuffixes(DNode dn)
		{
			FunctionAttributes(ref dn.Attributes);

			while (laKind == (OpenSquareBracket))
			{
				Step();
				var ad = new ArrayDecl() { Location=t.Location };
				LastParsedObject = ad;
				ad.InnerDeclaration = dn.Type;
				if (laKind != (CloseSquareBracket))
				{
					ad.ClampsEmpty = false;
					ITypeDeclaration keyType=null;
					Lexer.PushLookAheadBackup();
					if (!IsAssignExpression())
					{
						var weakType = AllowWeakTypeParsing;
						AllowWeakTypeParsing = true;
						
						keyType= ad.KeyType = Type();

						AllowWeakTypeParsing = weakType;
					}
					if (keyType == null || laKind != CloseSquareBracket)
					{
						Lexer.RestoreLookAheadBackup();
						keyType = ad.KeyType = null;
						ad.KeyExpression = AssignExpression();
					}
					else
						Lexer.PopLookAheadBackup();
				}
				Expect(CloseSquareBracket);
				ad.EndLocation = t.EndLocation;
				dn.Type = ad;
			}

			if (laKind == (OpenParenthesis))
			{
				if (IsTemplateParameterList())
				{
					TemplateParameterList(dn);
				}
				var dm = dn as DMethod;
				if(dm != null)
					dm.Parameters = Parameters(dm);
			}

			FunctionAttributes(ref dn.Attributes);
		}
		bool CanHandleNode(DNode dn, MemberFilter VisibleMembers, bool isBaseClass, bool isMixinAst, bool takeStaticChildrenOnly, bool publicImports, bool scopeIsInInheritanceHierarchy)
		{
			if (dn == null || !MatchesCompilationConditions(dn) ||
				!CanAddMemberOfType (VisibleMembers, dn))
				return false;

			if((ctxt.Options & ResolutionOptions.IgnoreAllProtectionAttributes) != ResolutionOptions.IgnoreAllProtectionAttributes){
				if((CanShowMember(dn, ctxt.ScopedBlock) || isBaseClass && !isMixinAst) && ((!takeStaticChildrenOnly && (!publicImports || !isBaseClass)) || IsConstOrStatic(dn)))
				{
					if (!(CheckForProtectedAttribute (dn, ctxt.ScopedBlock) || scopeIsInInheritanceHierarchy))
						return false;
				}
				else
					return false;
			}

			var dm3 = dn as DMethod; // Only show normal & delegate methods
			if (dm3 != null && !(dm3.SpecialType == DMethod.MethodType.Normal || dm3.SpecialType == DMethod.MethodType.Delegate || dm3.NameHash != 0))
				return false;

			return true;
		}
Exemple #21
0
		bool Constraint(DNode dn)
		{
			if (laKind == If) {
				Step ();
				Expect (OpenParenthesis);

				dn.TemplateConstraint = Expression ();

				Expect (CloseParenthesis);

				return true;
			}
			return false;
		}
		static bool IsConstOrStatic(DNode dn)
		{
			return dn != null && (dn.IsStatic || ((dn is DVariable) && (dn as DVariable).IsConst));
		}
Exemple #23
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;
		}
		static bool CanShowMember(DNode dn, IBlockNode scope)
		{
			if (dn.ContainsAttribute(DTokens.Deprecated) && CompletionOptions.Instance.HideDeprecatedNodes)
				return false;

			// http://dlang.org/attribute.html#ProtectionAttribute
			if (dn.ContainsAttribute(DTokens.Private))
				return dn.NodeRoot == scope.NodeRoot;
			else if (dn.ContainsAttribute(DTokens.Package))
				return dn.NodeRoot is DModule &&
					ModuleNameHelper.ExtractPackageName((dn.NodeRoot as DModule).ModuleName) ==
					ModuleNameHelper.ExtractPackageName((scope.NodeRoot as DModule).ModuleName);

			return CheckForProtectedAttribute(dn, scope);
		}
Exemple #25
0
		public UserDefinedType(DNode Node, AbstractType baseType, ReadOnlyCollection<TemplateParameterSymbol> deducedTypes, ISyntaxRegion td) : base(Node, baseType, deducedTypes, td) { }
		static bool CheckForProtectedAttribute(DNode dn, IBlockNode scope)
		{
			if(!dn.ContainsAttribute(DTokens.Protected) || dn.NodeRoot == scope.NodeRoot)
				return true;

			while(scope!=null)
			{
				if(dn == scope || dn.Parent == scope)
					return true;
				scope = scope.Parent as IBlockNode;
			}
			return false;
		}
Exemple #27
0
		public MemberSymbol(DNode member, AbstractType memberType, ISyntaxRegion td,
			ReadOnlyCollection<TemplateParameterSymbol> deducedTypes = null)
			: base(member, memberType, deducedTypes, td) { }
		/// <summary>
		/// Add 'superior' template parameters to the current symbol because 
		/// the parameters might be re-used in the nested class.
		/// </summary>
		static List<TemplateParameterSymbol> GetInvisibleTypeParameters(DNode n,ResolutionContext ctxt)
		{
			var invisibleTypeParams = new List<TemplateParameterSymbol> ();

			var tStk = new Stack<ContextFrame> ();
			do {
				var curCtxt = ctxt.Pop ();
				tStk.Push (curCtxt);
				foreach (var kv in curCtxt.DeducedTemplateParameters)
					if (!n.ContainsTemplateParameter (kv.Value.Parameter))
						invisibleTypeParams.Add (kv.Value);
			}
			while (ctxt.PrevContextIsInSameHierarchy);
			while (tStk.Count != 0)
				ctxt.Push (tStk.Pop ());

			return invisibleTypeParams;
		}
		public virtual void VisitDNode(DNode n)
		{
			if (n.TemplateParameters != null)
				foreach (var tp in n.TemplateParameters)
					tp.Accept(this);

			if (n.TemplateConstraint != null)
				n.TemplateConstraint.Accept(this);

			if (n.Attributes != null && n.Attributes.Count != 0)
				foreach (var attr in n.Attributes)
					attr.Accept(this);

			if (n.Type != null)
				n.Type.Accept(this);
		}
		/// <summary>
		/// Returns true if both template instance identifiers are matching each other or if the parameterSpeci
		/// </summary>
		bool CheckForTixIdentifierEquality(
			DNode[] expectedTemplateTypes, 
			INode controllee)
		{
			/*
			 * Note: This implementation is not 100% correct or defined in the D spec:
			 * class A(T){}
			 * class A(S:string) {}
			 * class C(U: A!W, W){ W item; }
			 * 
			 * C!(A!int) -- is possible
			 * C!(A!string) -- is not allowed somehow - because there are probably two 'matching' template types.
			 * (dmd version 2.060, August 2012)
			 */
			return expectedTemplateTypes != null && expectedTemplateTypes.Contains(controllee);
		}