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 override void Visit(SetQueryNode node) { Debug.Print("SetQueryNode"); ProgramCode.Append("SET "); int i = 0; foreach (var attribute in node.Attributes) { InsertComma(ref i); //ProgramCode.Append($"'{attribute.Item1.Name}' = {attribute.Item3.ExpressionString()}"); } ProgramCode.Append($" IN {node.InVariable}"); if (node.WhereCondition != null) { node.WhereCondition.Accept(this); } ProgramCode.Append(");\n"); }
public override void Visit(SetQueryNode node) { SymbolTable.SetCurrentNode(node); // It expects attributes, if there is any // visits the varaible dcl node, and the assignment expression (Item1, Item3) foreach (var Exp in node.Attributes) { if (Exp.Item1 is VariableNode) { SymbolTable.SetAssigned(Exp.Item1.Name); } Exp.Item1.Accept(this); Exp.Item3.Accept(this); } // What children does a setNode have? // Maybe variables? I dont know... if (node.HasChildren) { VisitChildren(node); } // If there is a collection which this needs to be set in, this is where it happens if (node.InVariable != null) { CheckDeclared(node.InVariable.Name); } if (node.WhereCondition != null) { // This tells the WhereCondition what type the val variable should have, if this is not set corretly, the program will crash (node.WhereCondition as WhereNode).AttributeClass = SymbolTable.RetrieveSymbol(node.InVariable.Name) ?? default(AllType); // When this is done, we will visit the WhereNode, since its now ready node.WhereCondition.Accept(this); } }
public override AbstractNode VisitSetQuery([NotNull] GiraphParser.SetQueryContext context) { SetQueryNode SetNode = new SetQueryNode(context.Start.Line, context.Start.Column); // If its Attributes being set if (context.variable() != null) { SetNode.InVariable = Visit(context.variable()); //SetNode.InVariable.Name = context.variable().GetText(); SetNode.SetAttributes = true; foreach (var ExpNode in context.setExpressionAtriSim()) { VariableAttributeNode attribute = Visit(ExpNode.attribute()) as VariableAttributeNode; attribute.ClassVariableName = SetNode.InVariable.Name; // Only set Class Variable if its an attribute attribute.IsAttribute = true; AbstractNode expression = Visit(ExpNode.simpleBoolCompOrExp()); SetNode.Attributes.Add(Tuple.Create(attribute, ExpNode.compoundAssign().GetText(), expression)); } } else { // If its variables being set SetNode.SetVariables = true; foreach (var ExpNode in context.setExpressionVari()) { VariableAttributeNode attribute = Visit(ExpNode.variable()) as VariableAttributeNode; AbstractNode expression = Visit(ExpNode.boolCompOrExp()) as AbstractNode; SetNode.Attributes.Add(Tuple.Create(attribute, ExpNode.compoundAssign().GetText(), expression)); } } if (context.where () != null) { SetNode.WhereCondition = Visit(context.where ()); } return(SetNode); }
public abstract void Visit(SetQueryNode node);
public override void Visit(SetQueryNode node) { if (node.SetAttributes) { foreach (var item in node.Attributes) { string InVaraible = node.InVariable.Name; string VariableName = item.Item1.Name.Trim('\''); string AssignOperator = item.Item2; bool IsCollection = (item.Item1 as VariableAttributeNode).IsCollection; AbstractNode expression = item.Item3; if (IsCollection) { _currentStringBuilder.Append($"foreach (var {HandleCSharpKeywords("val")} in {HandleCSharpKeywords(InVaraible)}) \n"); _currentStringBuilder.Append($"{{\n"); //Foreach body if (node.WhereCondition != null) { _currentStringBuilder.Append($"if ("); node.WhereCondition.Accept(this); _currentStringBuilder.Append($")\n {{\n"); // IfBody _currentStringBuilder.Append($"{HandleCSharpKeywords("val")}.{HandleCSharpKeywords(VariableName)} {AssignOperator} "); expression.Accept(this); _currentStringBuilder.Append($";\n }}"); } else { _currentStringBuilder.Append($"{HandleCSharpKeywords("val")}.{HandleCSharpKeywords(VariableName)} {AssignOperator} "); expression.Accept(this); _currentStringBuilder.Append($";\n"); } _currentStringBuilder.Append($"\n }}\n"); } else { _currentStringBuilder.Append($"{HandleCSharpKeywords(InVaraible)}.{HandleCSharpKeywords(VariableName)} {AssignOperator} "); expression.Accept(this); _currentStringBuilder.Append($";\n"); } } } else if (node.SetVariables) { foreach (var item in node.Attributes) { string VariableName = item.Item1.Name; string AssignOperator = item.Item2; AbstractNode expression = null; if (item.Item3 is BoolComparisonNode boolNode && boolNode.ChildCount != 0 && boolNode.Children[0] is ExpressionNode) { expression = item.Item3.Children[0]; } else { expression = item.Item3; } _currentStringBuilder.Append($"{HandleCSharpKeywords(VariableName)} {AssignOperator} "); expression.Accept(this); _currentStringBuilder.Append($";\n"); }