Beispiel #1
0
        public bool MustCaptureVariable(INamedBlockVariable local)
        {
            if (CurrentAnonymousMethod == null)
            {
                return(false);
            }

            //
            // Capture only if this or any of child blocks contain yield
            // or it's a parameter
            //
            if (CurrentAnonymousMethod.IsIterator)
            {
                return(local.IsParameter || local.Block.Explicit.HasYield);
            }

            //
            // Capture only if this or any of child blocks contain await
            // or it's a parameter or we need to access variable from
            // different parameter block
            //
            if (CurrentAnonymousMethod is AsyncInitializer)
            {
                return(local.IsParameter || local.Block.Explicit.HasAwait || CurrentBlock.Explicit.HasAwait ||
                       local.Block.ParametersBlock != CurrentBlock.ParametersBlock.Original);
            }

            return(local.Block.ParametersBlock != CurrentBlock.ParametersBlock.Original);
        }
Beispiel #2
0
        public bool MustCaptureVariable(INamedBlockVariable local)
        {
            if (CurrentAnonymousMethod == null)
            {
                return(false);
            }

            // FIXME: IsIterator is too aggressive, we should capture only if child
            // block contains yield
            if (CurrentAnonymousMethod.IsIterator)
            {
                return(true);
            }

            return(local.Block.ParametersBlock != CurrentBlock.ParametersBlock.Original);
        }
Beispiel #3
0
 public override void Error_AlreadyDeclared(string name, INamedBlockVariable variable)
 {
     TopBlock.Report.Error(1930, variable.Location,
                           "A range variable `{0}' has already been declared in this scope",
                           name);
 }
Beispiel #4
0
 public override void Error_AlreadyDeclared(string name, INamedBlockVariable variable, string reason)
 {
     TopBlock.Report.Error(1931, variable.Location,
                           "A range variable `{0}' conflicts with a previous declaration of `{0}'",
                           name);
 }
Beispiel #5
0
		public override void Error_AlreadyDeclared (string name, INamedBlockVariable variable)
		{
			TopBlock.Report.Error (1930, variable.Location,
				"A range variable `{0}' has already been declared in this scope",
				name);		
		}
Beispiel #6
0
		public override void Error_AlreadyDeclared (string name, INamedBlockVariable variable, string reason)
		{
			TopBlock.Report.Error (1931, variable.Location,
				"A range variable `{0}' conflicts with a previous declaration of `{0}'",
				name);
		}
Beispiel #7
0
		public bool MustCaptureVariable (INamedBlockVariable local)
		{
			if (CurrentAnonymousMethod == null)
				return false;

			//
			// Capture only if this or any of child blocks contain yield
			// or it's a parameter
			//
			if (CurrentAnonymousMethod.IsIterator)
				return local.IsParameter || CurrentBlock.Explicit.HasYield;

			//
			// Capture only if this or any of child blocks contain await
			// or it's a parameter
			//
			if (CurrentAnonymousMethod is AsyncInitializer)
				return CurrentBlock.Explicit.HasAwait;

			return local.Block.ParametersBlock != CurrentBlock.ParametersBlock.Original;
		}
Beispiel #8
0
		public bool MustCaptureVariable (INamedBlockVariable local)
		{
			if (CurrentAnonymousMethod == null)
				return false;

			// FIXME: IsIterator is too aggressive, we should capture only if child
			// block contains yield
			if (CurrentAnonymousMethod.IsIterator || CurrentAnonymousMethod is AsyncInitializer)
				return true;

			return local.Block.ParametersBlock != CurrentBlock.ParametersBlock.Original;
		}
Beispiel #9
0
		//
		// Lookup inside a block, the returned value can represent 3 states
		//
		// true+variable: A local name was found and it's valid
		// false+variable: A local name was found in a child block only
		// false+null: No local name was found
		//
		public bool GetLocalName (string name, Block block, ref INamedBlockVariable variable)
		{
			if (names == null)
				return false;

			object value;
			if (!names.TryGetValue (name, out value))
				return false;

			variable = value as INamedBlockVariable;
			Block b = block;
			if (variable != null) {
				do {
					if (variable.Block == b.Original)
						return true;

					b = b.Parent;
				} while (b != null);

				b = variable.Block;
				do {
					if (block == b)
						return false;

					b = b.Parent;
				} while (b != null);
			} else {
				List<INamedBlockVariable> list = (List<INamedBlockVariable>) value;
				for (int i = 0; i < list.Count; ++i) {
					variable = list[i];
					do {
						if (variable.Block == b.Original)
							return true;

						b = b.Parent;
					} while (b != null);

					b = variable.Block;
					do {
						if (block == b)
							return false;

						b = b.Parent;
					} while (b != null);

					b = block;
				}
			}

			variable = null;
			return false;
		}
Beispiel #10
0
		public override void AddLocalName (string name, INamedBlockVariable li)
		{
			if (names == null)
				names = new Dictionary<string, object> ();

			object value;
			if (!names.TryGetValue (name, out value)) {
				names.Add (name, li);
				return;
			}

			INamedBlockVariable existing = value as INamedBlockVariable;
			List<INamedBlockVariable> existing_list;
			if (existing != null) {
				existing_list = new List<INamedBlockVariable> ();
				existing_list.Add (existing);
				names[name] = existing_list;
			} else {
				existing_list = (List<INamedBlockVariable>) value;
			}

			//
			// A collision checking between local names
			//
			for (int i = 0; i < existing_list.Count; ++i) {
				existing = existing_list[i];
				Block b = existing.Block;

				// Collision at same level
				if (li.Block == b) {
					li.Block.Error_AlreadyDeclared (name, li);
					break;
				}

				// Collision with parent
				b = li.Block;
				while ((b = b.Parent) != null) {
					if (existing.Block == b) {
						li.Block.Error_AlreadyDeclared (name, li, "parent or current");
						i = existing_list.Count;
						break;
					}
				}

				// Collision with with children
				b = existing.Block;
				while ((b = b.Parent) != null) {
					if (li.Block == b) {
						li.Block.Error_AlreadyDeclared (name, li, "child");
						i = existing_list.Count;
						break;
					}
				}
			}

			existing_list.Add (li);
		}
Beispiel #11
0
		public virtual void Error_AlreadyDeclared (string name, INamedBlockVariable variable)
		{
			var pi = variable as ParametersBlock.ParameterInfo;
			if (pi != null) {
				var p = pi.Parameter;
				if (p is AnonymousTypeClass.GeneratedParameter) {
					ParametersBlock.TopBlock.Report.Error (833, p.Location, "`{0}': An anonymous type cannot have multiple properties with the same name",
						p.Name);
				} else {
					ParametersBlock.TopBlock.Report.Error (100, p.Location, "The parameter name `{0}' is a duplicate", p.Name);
				}

				return;
			}

			ParametersBlock.TopBlock.Report.Error (128, variable.Location,
				"A local variable named `{0}' is already defined in this scope", name);
		}
Beispiel #12
0
		public virtual void Error_AlreadyDeclared (string name, INamedBlockVariable variable, string reason)
		{
			if (reason == null) {
				Error_AlreadyDeclared (name, variable);
				return;
			}

			ParametersBlock.TopBlock.Report.Error (136, variable.Location,
				"A local variable named `{0}' cannot be declared in this scope because it would give a different meaning " +
				"to `{0}', which is already used in a `{1}' scope to denote something else",
				name, reason);
		}
Beispiel #13
0
		public virtual void AddLocalName (string name, INamedBlockVariable li)
		{
			ParametersBlock.TopBlock.AddLocalName (name, li);
		}
Beispiel #14
0
 public void AddLocalName(string name, INamedBlockVariable li, bool ignoreChildrenBlocks)
 {
     throw new NotSupportedException();
 }