Exemple #1
0
 public void PetljaForeach_IspišiZaQueue()
 {
     Foreach.Ispiši(new Queue(new string[] { "Ivo", "Tomislav", "Andrej" }));
     Assert.AreEqual("Ivo", cw.GetString());
     Assert.AreEqual("Tomislav", cw.GetString());
     Assert.AreEqual("Andrej", cw.GetString());
 }
Exemple #2
0
 public void IspišiZaNizStringova()
 {
     Foreach.Ispiši(new string[] { "Ivo", "Tomislav", "Andrej" });
     Assert.AreEqual("Ivo", cw.GetString());
     Assert.AreEqual("Tomislav", cw.GetString());
     Assert.AreEqual("Andrej", cw.GetString());
 }
        public override void OnValidate()
        {
            base.OnValidate();

            var mb = PlaneMesh.Create(gridSize, Foreach.Cell(gridSize, cellSize).Select(c => c.o));

            meshFilter.sharedMesh = mb.ToMesh();
            meshFilter.sharedMesh.RecalculateNormals();
        }
 public virtual object Visit(Foreach foreachStatement)
 {
     return(null);
 }
			public override object Visit (Foreach foreachStatement)
			{
				var result = new ForeachStatement ();
				
				var location = LocationsBag.GetLocations (foreachStatement);
				
				result.AddChild (new CSharpTokenNode (Convert (foreachStatement.loc), ForeachStatement.ForeachKeywordRole), ForeachStatement.ForeachKeywordRole);
				if (location != null)
					result.AddChild (new CSharpTokenNode (Convert (location [0]), Roles.LPar), Roles.LPar);
				
				if (foreachStatement.TypeExpression != null)
					result.AddChild (ConvertToType (foreachStatement.TypeExpression), Roles.Type);
				
				if (foreachStatement.Variable != null)
					result.AddChild (Identifier.Create (foreachStatement.Variable.Name, Convert (foreachStatement.Variable.Location)), Roles.Identifier);
				
				if (location != null && location.Count > 1)
					result.AddChild (new CSharpTokenNode (Convert (location [1]), ForeachStatement.InKeywordRole), ForeachStatement.InKeywordRole);
				
				if (foreachStatement.Expr != null)
					result.AddChild ((Expression)foreachStatement.Expr.Accept (this), Roles.Expression);
				
				if (location != null && location.Count > 2)
					result.AddChild (new CSharpTokenNode (Convert (location [2]), Roles.RPar), Roles.RPar);
				
				if (foreachStatement.Statement != null)
					result.AddChild ((Statement)foreachStatement.Statement.Accept (this), Roles.EmbeddedStatement);
				
				return result;
			}
Exemple #6
0
void case_963()
#line 6440 "cs-parser.jay"
{
		Foreach f = new Foreach ((Expression) yyVals[-1+yyTop], null, null, null, null, GetLocation (yyVals[-3+yyTop]));
		current_block.AddStatement (f);
		
		lbag.AddStatement (f, GetLocation (yyVals[-2+yyTop]));
		yyVal = f;
	  }
Exemple #7
0
void case_962()
#line 6427 "cs-parser.jay"
{
		start_block (GetLocation (yyVals[-3+yyTop]));
		current_block.IsCompilerGenerated = true;
		var lt = yyVals[-1+yyTop] as LocatedToken;
		var li = lt != null ? new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location) : null;
		
		Foreach f = new Foreach ((Expression) yyVals[-2+yyTop], li, null, null, null, GetLocation (yyVals[-4+yyTop]));
		current_block.AddStatement (f);
		
		lbag.AddStatement (f, GetLocation (yyVals[-3+yyTop]));
		yyVal = end_block (GetLocation (yyVals[0+yyTop]));
	  }
Exemple #8
0
void case_961()
#line 6416 "cs-parser.jay"
{
		if (yyVals[0+yyTop] is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
			Warning_EmptyStatement (GetLocation (yyVals[0+yyTop]));
		
		Foreach f = new Foreach ((Expression) yyVals[-6+yyTop], (LocalVariable) yyVals[-1+yyTop], (Expression) yyVals[-3+yyTop], (Statement) yyVals[0+yyTop], current_block, GetLocation (yyVals[-8+yyTop]));
		lbag.AddStatement (f, GetLocation (yyVals[-7+yyTop]), GetLocation (yyVals[-4+yyTop]), GetLocation (yyVals[-2+yyTop]));
		end_block (GetLocation (yyVals[-2+yyTop]));
		
		yyVal = f;
	  }
Exemple #9
0
void case_959()
#line 6389 "cs-parser.jay"
{
		Error_SyntaxError (yyToken);
	
		start_block (GetLocation (yyVals[-3+yyTop]));
		current_block.IsCompilerGenerated = true;
		
		var lt = (LocatedToken) yyVals[-1+yyTop];
		var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
		current_block.AddLocalName (li);
		
		Foreach f = new Foreach ((Expression) yyVals[-2+yyTop], li, null, null, null, GetLocation (yyVals[-4+yyTop]));
		current_block.AddStatement (f);
		
		lbag.AddStatement (f, GetLocation (yyVals[-3+yyTop]));
		yyVal = end_block (GetLocation (yyVals[0+yyTop]));
	  }
Exemple #10
0
void case_958()
#line 6376 "cs-parser.jay"
{
		report.Error (230, GetLocation (yyVals[-3+yyTop]), "Type and identifier are both required in a foreach statement");

		start_block (GetLocation (yyVals[-2+yyTop]));
		current_block.IsCompilerGenerated = true;
		
		Foreach f = new Foreach ((Expression) yyVals[-1+yyTop], null, null, null, null, GetLocation (yyVals[-3+yyTop]));
		current_block.AddStatement (f);
		
		lbag.AddStatement (f, GetLocation (yyVals[-2+yyTop]));
		yyVal = end_block (GetLocation (yyVals[0+yyTop]));
	  }
Exemple #11
0
		public virtual object Visit (Foreach foreachStatement)
		{
			return null;
		}
Exemple #12
0
 static void Main()
 {
     WhileLoop.Run();                                        // @MDB LINE: main
     Foreach.Run();
     MarshalByRefTest.Run();
 }
void case_900()
#line 6885 "ps-parser.jay"
{
		if (yyVals[0+yyTop] is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
			Warning_EmptyStatement (GetLocation (yyVals[0+yyTop]));

		var blockVar = yyVals[-6+yyTop] as BlockVariableDeclaration;
		if (blockVar != null) {
			if (blockVar == null || blockVar.Initializer != null || blockVar.Declarators != null) {
				report.Error (7036, GetLocation (yyVals[-6+yyTop]), "Invalid for each initializer");	
				yyVal = end_block (current_block.StartLocation);
			} else {
				Foreach f = new Foreach (blockVar.TypeExpression, blockVar.Variable, (Expression) yyVals[-3+yyTop], (Statement) yyVals[0+yyTop], current_block, AsForEachType.ForEachValue, GetLocation (yyVals[-9+yyTop]));
				lbag.AddStatement (f, GetLocation (yyVals[-7+yyTop]), GetLocation (yyVals[-5+yyTop]), GetLocation (yyVals[-2+yyTop]));
				
				end_block (GetLocation (yyVals[-5+yyTop]));
				yyVal = f;
			}
		} else {
			var expList = yyVals[-6+yyTop] as List<Expression>;
			var varRef = (yyVals[-6+yyTop] as FullNamedExpression) ?? ((expList != null && expList.Count == 1) ? (expList[0] as FullNamedExpression) : null);
			if (varRef == null) {
				report.Error (7041, GetLocation (yyVals[-6+yyTop]), "Invalid iterator initializer");		
				yyVal = end_block (current_block.StartLocation);
			} else {
				Foreach f = new Foreach (varRef, (Expression) yyVals[-3+yyTop], (Statement) yyVals[0+yyTop], current_block, AsForEachType.ForEachValue, GetLocation (yyVals[-9+yyTop]));
				lbag.AddStatement (f, GetLocation (yyVals[-7+yyTop]), GetLocation (yyVals[-5+yyTop]), GetLocation (yyVals[-2+yyTop]));
				
				end_block (GetLocation (yyVals[-5+yyTop]));
				yyVal = f;
			}
		}
	  }
Exemple #14
0
        public static ITag LoadTag(XmlNode xmlNode, IList <Include> includes)
        {
            ITag tag          = null;
            bool isIn         = !string.IsNullOrEmpty(xmlNode.GetValueInXmlAttributes("In"));
            var  prepend      = xmlNode.GetValueInXmlAttributes("Prepend");
            var  property     = xmlNode.GetValueInXmlAttributes("Property");
            var  compareValue = xmlNode.GetValueInXmlAttributes("CompareValue");

            #region Init Tag
            string lowerXmlNodeName = xmlNode.Name.ToLower();
            switch (lowerXmlNodeName)
            {
            case "#text":
            case "#cdata-section":
            {
                var bodyText = " " + xmlNode.GetInnerTextInXmlAttributes();
                return(new SqlText
                    {
                        BodyText = bodyText
                    });
            }

            //case "OrderBy":
            case "orderby":
            {
                var bodyText = " " + xmlNode.GetInnerTextInXmlAttributes();
                tag = new OrderBy
                {
                    ChildTags = new List <ITag>(),

                    BodyText = bodyText
                };
                break;
            }

            //case "Include":
            case "include":
            {
                var refId       = xmlNode.GetValueInXmlAttributes("RefId");
                var include_tag = new Include
                {
                    RefId = refId
                };
                includes.Add(include_tag);
                tag = include_tag;
                break;
            }

            //case "If":
            case "if":
            {
                var Test = xmlNode.GetValueInXmlAttributes("Test");
                tag = new IfTag
                {
                    Test      = Test,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsEmpty":
            case "isempty":
            {
                tag = new IsEmpty
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsEqual":
            case "isequal":
            {
                tag = new IsEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "IsGreaterEqual":
            case "isgreaterequal":
            {
                tag = new IsGreaterEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "IsGreaterThan":
            case "isgreaterthan":
            {
                tag = new IsGreaterThan
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "IsLessEqual":
            case "islessequal":
            {
                tag = new IsLessEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "IsLessThan":
            case "islessthan":
            {
                tag = new IsLessThan
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "IsNotEmpty":
            case "isnotempty":
            {
                tag = new IsNotEmpty
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsNotEqual":
            case "isnotequal":
            {
                tag = new IsNotEqual
                {
                    In           = isIn,
                    Prepend      = prepend,
                    Property     = property,
                    CompareValue = compareValue,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "IsNotNull":
            case "isnotnull":
            {
                tag = new IsNotNull
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsNull":
            case "isnull":
            {
                tag = new IsNull
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsTrue":
            case "istrue":
            {
                tag = new IsTrue
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsFalse":
            case "isfalse":
            {
                tag = new IsFalse
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "IsProperty":
            case "isproperty":
            {
                tag = new IsProperty
                {
                    In        = isIn,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Switch":
            case "switch":
            {
                tag = new Switch
                {
                    Property = property,
                    //Prepend = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Case":
            case "case":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.GetValueInXmlAttributes("Property");
                var switchPrepend  = switchNode.GetValueInXmlAttributes("Prepend");
                tag = new Switch.Case
                {
                    CompareValue = compareValue,
                    Property     = switchProperty,
                    Prepend      = switchPrepend,
                    ChildTags    = new List <ITag>()
                };
                break;
            }

            //case "Default":
            case "default":
            {
                var switchNode     = xmlNode.ParentNode;
                var switchProperty = switchNode.GetValueInXmlAttributes("Property");
                var switchPrepend  = switchNode.GetValueInXmlAttributes("Prepend");
                tag = new Switch.Defalut
                {
                    Property  = switchProperty,
                    Prepend   = switchPrepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Choose":
            case "choose":
            {
                tag = new ChooseTag
                {
                    //Property = property,
                    //Prepend = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "when":
            {
                var Test = xmlNode.GetValueInXmlAttributes("Test");
                //var switchNode = xmlNode.ParentNode;
                //var switchProperty = switchNode.GetValueInXmlAttributes("Property");
                //var switchPrepend = switchNode.GetValueInXmlAttributes("Prepend");
                tag = new ChooseTag.ChooseWhenTag
                {
                    Test = Test,
                    //Property = switchProperty,
                    //Prepend = switchPrepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "otherwise":
            {
                //var switchNode = xmlNode.ParentNode;
                //var switchProperty = switchNode.GetValueInXmlAttributes("Property");
                //var switchPrepend = switchNode.GetValueInXmlAttributes("Prepend");
                tag = new ChooseTag.ChooseOtherwiseTag
                {
                    //Property = switchProperty,
                    //Prepend = switchPrepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "trim":
            {
                var Prefix          = xmlNode.GetValueInXmlAttributes("Prefix", "", false);
                var Suffix          = xmlNode.GetValueInXmlAttributes("Suffix", "", false);
                var PrefixOverrides = xmlNode.GetValueInXmlAttributes("PrefixOverrides");
                var SuffixOverrides = xmlNode.GetValueInXmlAttributes("SuffixOverrides");
                tag = new TrimTag
                {
                    Prefix          = Prefix,
                    Suffix          = Suffix,
                    PrefixOverrides = PrefixOverrides,
                    SuffixOverrides = SuffixOverrides,
                    ChildTags       = new List <ITag>()
                };
                break;
            }

            case "set":
            {
                tag = new SetTag()
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            case "where":
            {
                tag = new WhereTag
                {
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Where":
            //case "where":
            //    {
            //        tag = new Where
            //        {
            //            ChildTags = new List<ITag>()
            //        };
            //        break;
            //    }
            //case "Dynamic":
            case "dynamic":
            {
                tag = new Dynamic
                {
                    Prepend   = prepend,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Variable":
            case "variable":
            {
                var bodyText = xmlNode.GetInnerTextInXmlAttributes();
                tag = new Variable
                {
                    BodyText  = bodyText,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Bind":
            case "bind":
            {
                var Name  = xmlNode.GetValueInXmlAttributes("Name");
                var Value = xmlNode.GetValueInXmlAttributes("Value");
                //var bodyText = xmlNode.GetInnerTextInXmlAttributes();
                tag = new BindTag
                {
                    Name      = Name,
                    Value     = Value,
                    Prepend   = prepend,
                    Property  = property,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Foreach":
            case "foreach":
            {
                var open      = xmlNode.GetValueInXmlAttributes("Open");
                var separator = xmlNode.GetValueInXmlAttributes("Separator");
                var close     = xmlNode.GetValueInXmlAttributes("Close");
                var item      = xmlNode.GetValueInXmlAttributes("Item");
                var index     = xmlNode.GetValueInXmlAttributes("Index");
                tag = new Foreach
                {
                    Prepend   = prepend,
                    Property  = property,
                    Open      = open,
                    Close     = close,
                    Separator = separator,
                    Item      = item,
                    Index     = index,
                    ChildTags = new List <ITag>()
                };
                break;
            }

            //case "Env":
            case "env":
            {
                var dbProvider = xmlNode.GetValueInXmlAttributes("DbProvider");
                var DbType     = xmlNode.GetValueInXmlAttributes("DbType");
                tag = new Env
                {
                    Prepend    = prepend,
                    DbProvider = dbProvider,
                    DbType     = DbType,
                    ChildTags  = new List <ITag>()
                };
                break;
            }

            case "#comment": { break; }

            default:
            {
                throw new Exception(string.Format("Statement.LoadTag unkonw tagName:{0}.", xmlNode.Name));
            };
            }
            #endregion
            //加载组合查询条件查询
            foreach (XmlNode childNode in xmlNode)
            {
                ITag childTag = LoadTag(childNode, includes);
                if (childTag != null && tag != null)
                {
                    (tag as Tag).ChildTags.Add(childTag);
                }
            }
            return(tag);
        }