public SwitchOperation(CompiledMethod method,BracketFragment switching,BracketFragment body):base(method){
			Body=body;
			
			if(switching.ChildCount()!=1){
				
				switching.Error("Too many entries inside this switches brackets. Should be e.g. switch(name){ .. }");
				
			}
			
			// Compile the switching frag:
			CompiledFragment variableFrag=switching.FirstChild.Compile(method);
			
			// Get the active value - this should be a variable object:
			object activeValue=variableFrag.ActiveValue();
			
			// Try and apply it:
			Switching=activeValue as Variable;
			
			if(Switching==null){
				
				switching.Error("Can only switch variables.");
				
			}
			
		}
예제 #2
0
		/// <summary>Checks if two variables are equal to each other.</summary>
		/// <param name="other">The variable to check for equality with this one.</param>
		/// <returns>True if this and the given variable is equal.</returns>
		public bool Equals(Variable other){
			
			if(other==null||other.GetType()!=GetType()){
				return false;
			}
			
			return (Name==other.Name);
		}
		/// <summary>Looks for the use of the given variable within this operation.</summary>
		/// <param name="cfrag">The fragment to look in, e.g. this.Input1.</param>
		/// <param name="findingVar">The variable being searched for.</param>
		/// <returns>True if it was found in there, false otherwise.</returns>
		public bool LookFor(CompiledFragment cfrag,Variable findingVar){
			if(cfrag==null){
				return false;
			}
			
			if(cfrag.Value==null&&Types.IsTypeOf(cfrag,typeof(Operation))){
				Operation op=(Operation)cfrag;
				
				if(LookFor(op.Input0,findingVar)){
					return true;
				}
				
				if(LookFor(op.Input1,findingVar)){
					return true;
				}
				
			}else if(cfrag.Value!=null&&Types.IsTypeOf(cfrag.Value,typeof(Variable))){
				return ((Variable)cfrag.Value).Equals(findingVar);
			}
			
			return false;
		}