private void TestParseForStatementInternal(Func <string, NativeXForStatement> parser) { NativeXForStatement s = parser("for (variable int i = 0; variable int j = 0; when (i - j > 5) with i+=2; j+=1;) do x();"); Assert.AreEqual(2, s.Initializer.Count); { NativeXVariableStatement s1 = (NativeXVariableStatement)s.Initializer[0]; Assert.AreEqual("i", s1.Name); Assert.AreEqual("int", ((NativeXReferenceType)s1.Type).ReferencedName); Assert.AreEqual("0", ((NativeXPrimitiveExpression)s1.Initializer).Code); } { NativeXVariableStatement s2 = (NativeXVariableStatement)s.Initializer[1]; Assert.AreEqual("j", s2.Name); Assert.AreEqual("int", ((NativeXReferenceType)s2.Type).ReferencedName); Assert.AreEqual("0", ((NativeXPrimitiveExpression)s2.Initializer).Code); } Assert.AreEqual(2, s.SideEffect.Count); { NativeXBinaryExpression e1 = (NativeXBinaryExpression)((NativeXExpressionStatement)s.SideEffect[0]).Expression; Assert.AreEqual("+=", e1.Operator); Assert.AreEqual("i", ((NativeXReferenceExpression)e1.LeftOperand).ReferencedName); Assert.AreEqual("2", ((NativeXPrimitiveExpression)e1.RightOperand).Code); } { NativeXBinaryExpression e2 = (NativeXBinaryExpression)((NativeXExpressionStatement)s.SideEffect[1]).Expression; Assert.AreEqual("+=", e2.Operator); Assert.AreEqual("j", ((NativeXReferenceExpression)e2.LeftOperand).ReferencedName); Assert.AreEqual("1", ((NativeXPrimitiveExpression)e2.RightOperand).Code); } { NativeXInvokeExpression a = (NativeXInvokeExpression)((NativeXExpressionStatement)s.Statement).Expression; Assert.AreEqual("x", ((NativeXReferenceExpression)a.Function).ReferencedName); Assert.AreEqual(0, a.Arguments.Count); } { NativeXBinaryExpression e1 = (NativeXBinaryExpression)s.Condition; Assert.AreEqual(">", e1.Operator); Assert.AreEqual("5", ((NativeXPrimitiveExpression)e1.RightOperand).Code); NativeXBinaryExpression e2 = (NativeXBinaryExpression)e1.LeftOperand; Assert.AreEqual("-", e2.Operator); Assert.AreEqual("i", ((NativeXReferenceExpression)e2.LeftOperand).ReferencedName); Assert.AreEqual("j", ((NativeXReferenceExpression)e2.RightOperand).ReferencedName); } }
private void TestParseVariableStatementInternal(Func <string, NativeXVariableStatement> parser) { { NativeXVariableStatement s = parser("variable function int(double) converter;"); Assert.AreEqual("converter", s.Name); Assert.IsNull(s.Initializer); NativeXFunctionType t = (NativeXFunctionType)s.Type; Assert.AreEqual("int", ((NativeXReferenceType)t.ReturnType).ReferencedName); Assert.AreEqual(1, t.Parameters.Count); Assert.AreEqual("double", ((NativeXReferenceType)t.Parameters[0]).ReferencedName); } { NativeXVariableStatement s = parser("variable vector<string> list = null;"); Assert.AreEqual("list", s.Name); Assert.AreEqual("null", ((NativeXPrimitiveExpression)s.Initializer).Code); NativeXInstanciatedType t = (NativeXInstanciatedType)s.Type; Assert.AreEqual("vector", ((NativeXReferenceType)t.ElementType).ReferencedName); Assert.AreEqual(1, t.GenericArguments.Count); Assert.AreEqual("string", ((NativeXReferenceType)t.GenericArguments[0]).ReferencedName); } }
protected IEnumerable <TextEditorPopupItem> CreatePopupExpressions(CodeScope scope) { Bitmap functionImage = null; Bitmap memberImage = null; Bitmap templateImage = null; Bitmap parameterImage = null; List <TextEditorPopupItem> items = new List <TextEditorPopupItem>(); foreach (CodeNode node in scope.FindAllDistinct()) { { NativeXNameTypePair parameter = node as NativeXNameTypePair; if (parameter != null && parameter.Name != null) { items.Add(new TextEditorPopupItem() { Text = parameter.Name, Image = (parameterImage ?? (parameterImage = Images.Parameter)) }); } } { NativeXVariableStatement varstat = node as NativeXVariableStatement; if (varstat != null && varstat.Name != null) { items.Add(new TextEditorPopupItem() { Text = varstat.Name, Image = (memberImage ?? (memberImage = Images.Member)) }); } } { NativeXVariableDeclaration vardecl = node as NativeXVariableDeclaration; if (vardecl != null && vardecl.Name != null) { items.Add(new TextEditorPopupItem() { Text = vardecl.Name, Image = (memberImage ?? (memberImage = Images.Member)) }); } } { NativeXFunctionDeclaration funcdecl = node as NativeXFunctionDeclaration; if (funcdecl != null && funcdecl.Name != null) { items.Add(new TextEditorPopupItem() { Text = funcdecl.Name, Image = (functionImage ?? (functionImage = Images.Function)) }); } } { NativeXConceptDeclaration conceptdecl = node as NativeXConceptDeclaration; if (conceptdecl != null && conceptdecl.Name != null) { items.Add(new TextEditorPopupItem() { Text = conceptdecl.Name, Image = (templateImage ?? (templateImage = Images.Template)) }); } } } Bitmap keywordImage = Images.Keyword; string[] keywords = new string[] { "result", "cast", "exception", "true", "false", "null", "sizeof", "offsetof" }; items.AddRange( keywords.Select(k => new TextEditorPopupItem() { Text = k, Image = keywordImage })); return(items); }