public bool CheckDeclared(string name) { if (name != null) { // Means it is a function call, or a Attribute call on a class if (name.Contains(".")) { if (name.Contains("(")) { name = name.Substring(0, name.IndexOf('(')); } List <string> Names = name.Split('.').ToList(); if (CheckDeclared(Names[0])) { AllType type = SymbolTable.GetVariableType(Names[0]); return(SymbolTable.AttributeDefined(Names[1], type)); } else { SymbolTable.UndeclaredError(name); return(false); } } else { if (!SymbolTable.DeclaredLocally(name)) { SymbolTable.UndeclaredError(name); return(false); } return(true); } } throw new Exception("Name is null in CheckDeclared!"); }
/// <summary> /// Does the same as GetAttribyteType, but ignores the collection requirement /// </summary> /// <returns>The attribute type.</returns> /// <param name="name">Name.</param> /// <param name="type">Type.</param> public AllType?GetAttributeType(string name, AllType type) { name = name.Trim('\''); bool IsCollection; return(GetAttributeType(name, type, out IsCollection)); }
public override void Visit(SetQueryNode node) { _symbolTable.SetCurrentNode(node); // Hvis man sætter en attribute i en klasse, og kun det? if (node.InVariable != null) { AllType ClassType = _symbolTable.RetrieveSymbol(node.InVariable.Name) ?? AllType.UNKNOWNTYPE; if (!_symbolTable.IsClass(ClassType)) { _symbolTable.InvalidTypeClass(); } else { foreach (var Attribute in node.Attributes) { AllType AttributeType = _symbolTable.GetAttributeType(Attribute.Item1.Name, ClassType) ?? AllType.UNKNOWNTYPE; Attribute.Item3.Accept(this); CheckAllowedCast(AttributeType, Attribute.Item3.Type_enum); } } } else { foreach (var Attribute in node.Attributes) { AllType AttributeType = _symbolTable.RetrieveSymbol(Attribute.Item1.Name) ?? AllType.UNKNOWNTYPE; Attribute.Item3.Accept(this); CheckAllowedCast(AttributeType, Attribute.Item3.Type_enum); } } VisitChildren(node); }
public void InsertIntoSymbolTableGlobal(string varaibleName, AllType type, bool IsCollection) { SymbolTable.EnterSymbol(varaibleName, type, IsCollection); var NewType = SymbolTable.RetrieveSymbol(varaibleName); Assert.AreEqual(NewType, type); }
public override void Visit(ExtractMinQueryNode node) { _symbolTable.SetCurrentNode(node); checkCollectionFollowsCollection(node.Variable); AllType collectionNameType = _symbolTable.RetrieveSymbol(node.Variable, out bool isCollectionInQuery, false) ?? AllType.UNKNOWNTYPE; /*if (_symbolTable.IsClass(collectionNameType)) { * _symbolTable.CollectionOfClasses(); * return; * }*/ if (isCollectionInQuery) { node.Type = collectionNameType.ToString().ToLower(); if (!_symbolTable.IsClass(node.Type_enum) && node.Attribute != null && node.Attribute != "") { _symbolTable.AttributeUsedOnNonClass(); } } else { _symbolTable.NotCollection(node.Variable); } if (node.WhereCondition != null) { node.WhereCondition.Accept(this); } }
public FunctionParameterEntry(string Name, AllType Type, bool Collection = false) { this.Name = Name; this.Type = Type; this.Collection = Collection; _id = statId++; }
public override void Visit(GraphDeclEdgeNode node) { _symbolTable.SetCurrentNode(node); AllType vertexFromType = _symbolTable.RetrieveSymbol(node.VertexNameFrom, false) ?? AllType.UNKNOWNTYPE; AllType vertexToType = _symbolTable.RetrieveSymbol(node.VertexNameTo, false) ?? AllType.UNKNOWNTYPE; CheckAllowedCast(vertexFromType, vertexToType); foreach (KeyValuePair <string, AbstractNode> item in node.ValueList) { item.Value.Parent = node; item.Value.Accept(this); AllType? typeOfKey = _symbolTable.GetAttributeType(item.Key, AllType.EDGE); ExpressionNode expNode; if (item.Value is BoolComparisonNode) { expNode = (ExpressionNode)item.Value.Children[0]; } else { expNode = item.Value as ExpressionNode; } if (expNode is ExpressionNode) { if (typeOfKey != expNode.OverAllType) { _symbolTable.TypeExpressionMismatch(); } } } }
public bool CheckAllowedCast(AllType OriginalType, AllType NewType, out AllType?OverAllType, bool Expression = false) { if (OriginalType == AllType.VOID || NewType == AllType.VOID) { _symbolTable.DeclarationCantBeTypeVoid(); } if (OriginalType == NewType) { OverAllType = OriginalType; return(true); } if (CheckDecimalIntCast(OriginalType, NewType, Expression)) { OverAllType = AllType.DECIMAL; return(true); } // Check if any of the types is a string, that the other is not a class if (OriginalType == AllType.STRING || NewType == AllType.STRING) { bool Original_IsNot_Class = (_symbolTable.IsClass(OriginalType)); bool NewType_IsNot_Class = (_symbolTable.IsClass(NewType)); if (Original_IsNot_Class || NewType_IsNot_Class) { _symbolTable.CannotCastClass(); OverAllType = null; return(false); } OverAllType = AllType.STRING; return(true); } _symbolTable.IlligalCast(); OverAllType = null; return(false); }
public string ResolveTypeToCS(AllType type) { switch (type) { case (AllType.VERTEX): return("Vertex"); case (AllType.EDGE): return("Edge"); case (AllType.GRAPH): return("Graph"); case (AllType.BOOL): return("bool"); case (AllType.STRING): return("string"); case (AllType.INT): return("int"); case (AllType.DECIMAL): return("decimal"); case (AllType.VOID): return("void"); default: return(AllType.UNKNOWNTYPE.ToString()); } }
private void CachedDaliPerformanceList(int repeats) { for (int i = 0; i < repeats; i++) { AllType.GetListCached(); } }
//[TestMethod] public void CompareCachedPerformance() { var dt = AllType.GetTableCached(); const int reps = 10000; CachedDaliPerformanceParallel(1); // JIT CachedRawPerformance(1); // JIT var sw = Stopwatch.StartNew(); CachedDaliPerformanceParallel(reps); sw.Stop(); Console.WriteLine("DaLi parallel cached (" + reps + "): " + sw.ElapsedMilliseconds.ToString()); sw.Reset(); sw.Start(); CachedDaliPerformance(reps); sw.Stop(); Console.WriteLine("DaLi cached (" + reps + "): " + sw.ElapsedMilliseconds.ToString()); sw.Reset(); sw.Start(); CachedDaliPerformanceList(reps); sw.Stop(); Console.WriteLine("DaLi cached list (" + reps + "): " + sw.ElapsedMilliseconds.ToString()); sw.Reset(); sw.Start(); CachedRawPerformance(reps); sw.Stop(); Console.WriteLine("Raw implementation cached (" + reps + "): " + sw.ElapsedMilliseconds.ToString()); }
/// <summary> /// Extends the class with a long and a short name /// </summary> /// <param name="Type">Type.</param> /// <param name="longAttribute">Long attribute.</param> /// <param name="shortAttribute">Short attribute.</param> /// <param name="ClassType">Class type.</param> public void ExtendClass(AllType Type, string longAttribute, string shortAttribute, AllType ClassType, bool IsCollection = false) { if (longAttribute == shortAttribute) { AttributeIdenticalError(longAttribute, shortAttribute); } if (CheckAttributeDefined(longAttribute, ClassType)) { AlreadyDeclaredError(longAttribute); } if (CheckAttributeDefined(longAttribute, ClassType)) { AlreadyDeclaredError(shortAttribute); } if (errorOccured == false) { ClassEntry Short = new ClassEntry(shortAttribute, Type, IsCollection); ClassEntry Long = new ClassEntry(longAttribute, Type, IsCollection); Short.Collection = IsCollection; Long.Collection = IsCollection; _classesTable[ClassType].Add(shortAttribute, Short); _classesTable[ClassType].Add(longAttribute, Long); } }
/// <summary> /// Creates an all expression with argument /// </summary> /// <param name="arg">argument expression for the expression created</param> /// <param name="returnType">runtime type</param> /// <param name="selected">type of the all expression to be created</param> /// <returns>an expression representing an ALL or an ALLSELECTED DAX function</returns> private Expression GetAllExpression(Expression arg, Type returnType, AllType selected) { if (arg.NodeType == ExpressionType.Parameter) { if (selected == AllType.AllSelected) { return(new AllSelectedExpression(returnType, arg)); } return(new AllExpression(returnType, arg)); } if (arg.NodeType == ExpressionType.MemberAccess) { var m = (MemberExpression)arg; var te = TableFactory.GetTableExpression(m) as TableExpression; if (te != null && (selected == AllType.AllSelected)) { return(new AllSelectedExpression(returnType, te)); } if (te != null) { return(new AllExpression(returnType, te)); } } Expression argument = _binder.Visit(arg); if (selected == AllType.AllSelected) { return(new AllSelectedExpression(returnType, argument)); } return(new AllExpression(returnType, argument)); }
public void TestForProfiling() { // Used for profiling where the bottlenecks are (using unittest-profiler in #Develop) for (int i = 0; i < 10000; i++) { AllType.GetListCached(); } }
public override void Visit(ReturnNode node) { VisitChildren(node); _symbolTable.SetCurrentNode(node); AllType funcType = _symbolTable.RetrieveSymbol(node.FuncName, out bool FuncTypeCollection, false) ?? AllType.UNKNOWNTYPE; CheckAllowedCast(funcType, node.Children[0].Type_enum); }
public void TestLoad() { var type = new AllType(); Assert.IsTrue(type.Load(16)); Assert.IsTrue(type.ID == 16); Assert.IsTrue(!string.IsNullOrEmpty(type.Text)); }
public void TestAllDataTypesArePersistedCorrectly() { DateTime date = DateTime.Now; date = date.AddMilliseconds(1000 - date.Millisecond); // removes milliseconds string text = "Foobar"; AllType row = new AllType(); row.Bool = true; row.Date = date; row.Decimal = 4.2m; row.Double = 4.2; row.Float = 4.2f; row.Int = 42; row.Text = text; row.Uint = 42; row.Varchar = text; row.NullableInt = 42; row.NullableTime = TimeSpan.FromHours(10); Assert.IsTrue(row.Save()); Assert.IsTrue(row.ID > 0); row = new AllType(row.ID); Assert.IsTrue(row.Load()); Assert.AreEqual(row.Bool, true); Assert.AreEqual(row.Decimal, 4.2m); Assert.AreEqual(row.Double, 4.2); Assert.AreEqual(row.Float, 4.2f); Assert.AreEqual(row.Int, 42); Assert.AreEqual(row.Text, text); Assert.AreEqual(row.Uint, (uint)42); Assert.AreEqual(row.Varchar, text); Assert.IsTrue(row.NullableInt.Value.HasValue); Assert.IsTrue(row.NullableTime.Value.HasValue); Assert.AreEqual(10, row.NullableTime.Value.Value.Hours); row.NullableInt = null; row.Save(); row = new AllType(row.ID); row.Load(); Assert.IsTrue(!row.NullableInt.Value.HasValue); row.NullableInt = 42; row.Save(); row.NullableInt = (int?)null; row.Save(); row.Load(); Assert.IsTrue(!row.NullableInt.Value.HasValue); // Date validation, only compare date and hour, min, second, as it's all the DB will store Assert.AreEqual(row.Date.Value.Date, date.Date); Assert.AreEqual(row.Date.Value.Hour, date.Hour); Assert.AreEqual(row.Date.Value.Minute, date.Minute); Assert.AreEqual(row.Date.Value.Second, date.Second); row.Delete(); }
public bool IsExtended(string Name, AllType Class) { Name = Name.Trim('\''); if (IsClass(Class) && _classesTable[Class].ContainsKey(Name)) { return(true); } return(false); }
public bool CheckAttributeDefined(string name, AllType Class) { bool IsCollection; List <string> names = new List <string> { name }; return(RetrieveTypeFromClasses(names, Class, out IsCollection, false) != null); }
public void TestUpdate() { var type = new AllType(); Assert.IsTrue(type.Load(16)); type.Text = "Hello world"; Assert.IsTrue(type.Save()); type.Load(); Assert.AreEqual("Hello world", type.Text.Value); }
public void AddClassVariablesToScope(AllType type) { if (IsClass(type)) { foreach (var item in _classesTable[type]) { // Enters all attributes EnterSymbol("'" + item.Key + "'", item.Value.Type, item.Value.Collection); } } }
public override void Visit(GraphDeclVertexNode node) { _symbolTable.SetCurrentNode(node); foreach (KeyValuePair <string, AbstractNode> item in node.ValueList) { item.Value.Parent = node; item.Value.Accept(this); AllType typeOfKey = _symbolTable.GetAttributeType(item.Key, AllType.VERTEX) ?? AllType.UNKNOWNTYPE; CheckAllowedCast(typeOfKey, item.Value.Type_enum); } }
public override void Visit(DequeueQueryNode node) { _symbolTable.SetCurrentNode(node); AllType CollectionType = _symbolTable.RetrieveSymbol(node.Variable, out bool isCollection) ?? AllType.UNKNOWNTYPE; if (!isCollection) { _symbolTable.ExpectedCollection(); return; } node.Type = CollectionType.ToString().ToLower(); }
private void CachedDaliPerformance(int repeats) { var dt = AllType.GetTableCached(); for (int i = 0; i < repeats; i++) { foreach (DataRow dr in dt.Rows) { AllType inst = new AllType(); inst.Fill(dr); } } }
/// <summary> /// Gets the type of the attribute. /// </summary> /// <returns>The attribute type. returns null if it does not exist!, does not support collection</returns> /// <param name="name">Name.</param> /// <param name="type">Type.</param> public AllType?GetAttributeType(string name, AllType type, out bool IsCollection) { name = name.Trim('\''); List <string> names = new List <string>(); names.Add(name); if (type == AllType.UNKNOWNTYPE) { } AllType?output = RetrieveTypeFromClasses(names, type, out IsCollection, false); return(output); }
public bool IsClass(AllType Type) { switch (Type) { case AllType.EDGE: case AllType.GRAPH: case AllType.VERTEX: return(true); default: return(false);; } }
private void CachedDaliPerformanceParallel(int repeats) { var dt = AllType.GetTableCached(); for (int i = 0; i < repeats; i++) { var instances = dt.Rows.Cast <DataRow>() .AsParallel() .AsOrdered() .Select(dr => { AllType result = new AllType(); result.Fill(dr); return(result); }); instances.ToList(); } }
public void CheckExtendNotes(string extensionName, AllType Class) { var ExtendNodes = AST.Children.Where(x => x is ExtendNode).ToList(); var extraction = ExtendNodes.Where(x => (x as ExtendNode).ExtensionName == extensionName && (x as ExtendNode).ClassToExtend_enum == Class); if (extraction.Count() == 1) { Assert.Pass(); } else { Assert.Fail(); } }
public void HandleExpressionTypes(ExpressionNode node) { foreach (var item in node.ExpressionParts) { if (item is VariableNode) { AllType Type = SymbolTable.GetVariableType(item.Name); node.ExpressionTypes.Add(Type); } else if (item is ConstantNode) { node.ExpressionTypes.Add(((ConstantNode)item).Type_enum); } } node.FindOverAllType(); }
public bool CheckPredicateDefinitions2Parameters(string PredicateName, AllType ParameterType1, AllType ParameterType2) { var Start = AST.Children.Where(x => (x is PredicateNode) && (x as PredicateNode).Name == PredicateName).First(); if (Start != null) { if ((Start as PredicateNode).Parameters[0].Type_enum == ParameterType1 && (Start as PredicateNode).Parameters[1].Type_enum == ParameterType2) { return(true); } else { return(false); } } return(false); }