public SequenceComputationAssignment(AssignmentTarget tgt, SequenceComputation srcValueProvider) : base(SequenceComputationType.Assignment) { Target = tgt; SourceValueProvider = srcValueProvider; }
public SequenceBooleanComputation(SequenceComputation comp, List<SequenceVariable> variablesFallingOutOfScopeOnLeavingComputation, bool special) : base(special, SequenceType.BooleanComputation) { Computation = comp; VariablesFallingOutOfScopeOnLeavingComputation = variablesFallingOutOfScopeOnLeavingComputation; if(VariablesFallingOutOfScopeOnLeavingComputation == null) VariablesFallingOutOfScopeOnLeavingComputation = new List<SequenceVariable>(); }
public SequenceComputationThen(SequenceComputation left, SequenceComputation right) : base(SequenceComputationType.Then) { this.left = left; this.right = right; }
public SequenceComputationBuiltinProcedureCall(SequenceComputation builtinProcedure, List<SequenceVariable> returnVars) : base(SequenceComputationType.BuiltinProcedureCall) { BuiltinProcedure = builtinProcedure; ReturnVars = returnVars; }
/// <summary> /// Helper for checking procedure method calls. /// Checks whether called entity exists, type checks the input, type checks the output. /// Throws an exception when an error is found. /// </summary> /// <param name="seq">The sequence computation to check, must be a procedure call</param> /// <param name="targetVar">The target of the procedure method call</param> public void CheckProcedureMethodCall(SequenceVariable targetVar, SequenceComputation seq) { if(targetVar.Type == "") { // only runtime checks possible (we could check whether the called procedure signature exists in at least one of the model types, if not it's a type error, can't work at runtime, but that kind of negative check is not worth the effort) return; } GrGenType ownerType = TypesHelper.GetNodeOrEdgeType(targetVar.Type, Model); if(ownerType == null) { // error, must be node or edge type throw new SequenceParserException(targetVar.Type, SequenceParserError.UserMethodsOnlyAvailableForGraphElements); } CheckProcedureCallBase(seq, ownerType); }
/// <summary> /// Helper for checking procedure calls. /// Checks whether called entity exists, type checks the input, type checks the output. /// Throws an exception when an error is found. /// </summary> /// <param name="seq">The sequence computation to check, must be a procedure call</param> public void CheckProcedureCall(SequenceComputation seq) { CheckProcedureCallBase(seq, null); }
/// <summary> /// Helper for checking procedure calls. /// Checks whether called entity exists, type checks the input, type checks the output. /// Throws an exception when an error is found. /// </summary> /// <param name="seq">The sequence computation to check, must be a procedure call</param> /// <param name="ownerType">Gives the owner type of the procedure method call, in case this is a method call, otherwise null</param> private void CheckProcedureCallBase(SequenceComputation seq, GrGenType ownerType) { InvocationParameterBindingsWithReturns paramBindings = (seq as SequenceComputationProcedureCall).ParamBindings; // check the name against the available names if(!IsCalledEntityExisting(paramBindings, ownerType)) throw new SequenceParserException(paramBindings, SequenceParserError.UnknownProcedure); // Check whether number of parameters and return parameters match if(NumInputParameters(paramBindings, ownerType) != paramBindings.ArgumentExpressions.Length || paramBindings.ReturnVars.Length != 0 && NumOutputParameters(paramBindings, ownerType) != paramBindings.ReturnVars.Length) throw new SequenceParserException(paramBindings, SequenceParserError.BadNumberOfParametersOrReturnParameters); // Check parameter types for(int i = 0; i < paramBindings.ArgumentExpressions.Length; i++) { paramBindings.ArgumentExpressions[i].Check(this); if(paramBindings.ArgumentExpressions[i] != null) { if(!TypesHelper.IsSameOrSubtype(paramBindings.ArgumentExpressions[i].Type(this), InputParameterType(i, paramBindings, ownerType), Model)) throw new SequenceParserException(paramBindings, SequenceParserError.BadParameter, i); } else { if(paramBindings.Arguments[i] != null && !TypesHelper.IsSameOrSubtype(TypesHelper.XgrsTypeOfConstant(paramBindings.Arguments[i], Model), InputParameterType(i, paramBindings, ownerType), Model)) throw new SequenceParserException(paramBindings, SequenceParserError.BadParameter, i); } } // Check return types for(int i = 0; i < paramBindings.ReturnVars.Length; ++i) { if(!TypesHelper.IsSameOrSubtype(OutputParameterType(i, paramBindings, ownerType), paramBindings.ReturnVars[i].Type, Model)) throw new SequenceParserException(paramBindings, SequenceParserError.BadReturnParameter, i); } // ok, this is a well-formed invocation }
/// <summary> /// pre-run for emitting the needed entities before emitting the real code /// - emits sequence variable declarations (only once for every variable, declaration only possible at assignment targets) /// </summary> void EmitNeededVarEntities(SequenceComputation seqComp, SourceBuilder source) { source.AppendFront(DeclareResultVar(seqComp)); switch(seqComp.SequenceComputationType) { case SequenceComputationType.Assignment: { SequenceComputationAssignment assign = (SequenceComputationAssignment)seqComp; EmitNeededVarEntities(assign.Target, source); if(assign.SourceValueProvider is SequenceComputationAssignment) EmitNeededVarEntities(assign.SourceValueProvider, source); break; } case SequenceComputationType.ProcedureCall: { SequenceComputationProcedureCall seqProc = (SequenceComputationProcedureCall)seqComp; // no handling for the input arguments seqProc.ParamBindings.ArgumentExpressions needed // because there can only be variable uses for(int i = 0; i < seqProc.ParamBindings.ReturnVars.Length; ++i) { EmitVarIfNew(seqProc.ParamBindings.ReturnVars[i], source); } break; } case SequenceComputationType.BuiltinProcedureCall: { SequenceComputationBuiltinProcedureCall seqProc = (SequenceComputationBuiltinProcedureCall)seqComp; // no handling for the input arguments seqProc.ParamBindings.ArgumentExpressions needed // because there can only be variable uses for(int i = 0; i < seqProc.ReturnVars.Count; ++i) { EmitVarIfNew(seqProc.ReturnVars[i], source); } break; } default: foreach(SequenceComputation childSeqComp in seqComp.Children) EmitNeededVarEntities(childSeqComp, source); break; } }
void EmitSequenceComputation(SequenceComputation seqComp, SourceBuilder source) { // take care that the operations returning a value are emitted similarily to expressions, // whereas the operations returning no value are emitted as statements switch(seqComp.SequenceComputationType) { case SequenceComputationType.Then: { SequenceComputationThen seqThen = (SequenceComputationThen)seqComp; EmitSequenceComputation(seqThen.left, source); EmitSequenceComputation(seqThen.right, source); source.AppendFront(SetResultVar(seqThen, GetResultVar(seqThen.right))); break; } case SequenceComputationType.Assignment: { SequenceComputationAssignment seqAssign = (SequenceComputationAssignment)seqComp; if(seqAssign.SourceValueProvider is SequenceComputationAssignment) { EmitSequenceComputation(seqAssign.SourceValueProvider, source); EmitAssignment(seqAssign.Target, GetResultVar(seqAssign.SourceValueProvider), source); source.AppendFront(SetResultVar(seqAssign, GetResultVar(seqAssign.Target))); } else { string comp = GetSequenceExpression((SequenceExpression)seqAssign.SourceValueProvider, source); EmitAssignment(seqAssign.Target, comp, source); source.AppendFront(SetResultVar(seqAssign, GetResultVar(seqAssign.Target))); } break; } case SequenceComputationType.VariableDeclaration: { SequenceComputationVariableDeclaration seqVarDecl = (SequenceComputationVariableDeclaration)seqComp; source.AppendFront(SetVar(seqVarDecl.Target, TypesHelper.DefaultValueString(seqVarDecl.Target.Type, model))); source.AppendFront(SetResultVar(seqVarDecl, GetVar(seqVarDecl.Target))); break; } case SequenceComputationType.ContainerAdd: { SequenceComputationContainerAdd seqAdd = (SequenceComputationContainerAdd)seqComp; string container = GetContainerValue(seqAdd); if(seqAdd.ContainerType(env) == "") { if(seqAdd.Attribute != null) { source.AppendFront("GRGEN_LIBGR.IGraphElement elem_" + seqAdd.Id + " = (GRGEN_LIBGR.IGraphElement)" + GetVar(seqAdd.Attribute.SourceVar) + ";\n"); source.AppendFront("GRGEN_LIBGR.AttributeType attrType_" + seqAdd.Id + " = elem_" + seqAdd.Id + ".Type.GetAttributeType(\"" + seqAdd.Attribute.AttributeName + "\");\n"); } string containerVar = "tmp_eval_once_" + seqAdd.Id; source.AppendFront("object " + containerVar + " = " + container + ";\n"); string sourceValue = "srcval_" + seqAdd.Id; source.AppendFront("object " + sourceValue + " = " + GetSequenceExpression(seqAdd.Expr, source) + ";\n"); string destinationValue = seqAdd.ExprDst == null ? null : "dstval_" + seqAdd.Id; source.AppendFront("if(" + containerVar + " is IList) {\n"); source.Indent(); if(destinationValue != null && !TypesHelper.IsSameOrSubtype(seqAdd.ExprDst.Type(env), "int", model)) source.AppendFront("throw new Exception(\"Can't add non-int key to array\");\n"); else { string array = "((System.Collections.IList)" + containerVar + ")"; if(destinationValue != null) source.AppendFront("int " + destinationValue + " = (int)" + GetSequenceExpression(seqAdd.ExprDst, source) + ";\n"); if(seqAdd.Attribute != null) { if(destinationValue != null) { source.AppendFront("if(elem_" + seqAdd.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", " + destinationValue + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", " + destinationValue + ");\n"); } else { source.AppendFront("if(elem_" + seqAdd.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", null);\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", null);\n"); } } if(destinationValue == null) source.AppendFront(array + ".Add(" + sourceValue + ");\n"); else source.AppendFront(array + ".Insert(" + destinationValue + ", " + sourceValue + ");\n"); if(seqAdd.Attribute != null) { if(gen.FireDebugEvents) { source.AppendFront("if(elem_" + seqAdd.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangedNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangedEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ");\n"); } } } source.Unindent(); source.AppendFront("} else if(" + containerVar + " is GRGEN_LIBGR.IDeque) {\n"); source.Indent(); if(destinationValue != null && !TypesHelper.IsSameOrSubtype(seqAdd.ExprDst.Type(env), "int", model)) source.AppendFront("throw new Exception(\"Can't add non-int key to deque\");\n"); else { string deque = "((GRGEN_LIBGR.IDeque)" + containerVar + ")"; if(destinationValue != null) source.AppendFront("int " + destinationValue + " = (int)" + GetSequenceExpression(seqAdd.ExprDst, source) + ";\n"); if(seqAdd.Attribute != null) { if(destinationValue != null) { source.AppendFront("if(elem_" + seqAdd.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", " + destinationValue + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", " + destinationValue + ");\n"); } else { source.AppendFront("if(elem_" + seqAdd.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", null);\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", null);\n"); } } if(destinationValue == null) source.AppendFront(deque + ".Enqueue(" + sourceValue + ");\n"); else source.AppendFront(deque + ".EnqueueAt(" + destinationValue + ", " + sourceValue + ");\n"); if(seqAdd.Attribute != null) { if(gen.FireDebugEvents) { source.AppendFront("if(elem_" + seqAdd.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangedNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangedEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ");\n"); } } } source.Unindent(); source.AppendFront("} else {\n"); source.Indent(); if(destinationValue != null) source.AppendFront("object " + destinationValue + " = " + GetSequenceExpression(seqAdd.ExprDst, source) + ";\n"); string dictionary = "((System.Collections.IDictionary)" + containerVar + ")"; if(seqAdd.Attribute != null) { if(seqAdd.ExprDst != null) // must be map { source.AppendFront("if(elem_" + seqAdd.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + destinationValue + ", " + sourceValue + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + destinationValue + ", " + sourceValue + ");\n"); } else { source.AppendFront("if(elem_" + seqAdd.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", " + destinationValue + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", " + destinationValue + ");\n"); } } if(destinationValue == null) source.AppendFront(dictionary + "[" + sourceValue + "] = null;\n"); else source.AppendFront(dictionary + "[" + sourceValue + "] = " + destinationValue + ";\n"); if(seqAdd.Attribute != null) { if(gen.FireDebugEvents) { source.AppendFront("if(elem_" + seqAdd.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangedNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangedEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ");\n"); } } source.Unindent(); source.AppendFront("}\n"); source.AppendFront(SetResultVar(seqAdd, containerVar)); } else if(seqAdd.ContainerType(env).StartsWith("array")) { string array = container; string arrayValueType = TypesHelper.XgrsTypeToCSharpType(TypesHelper.ExtractSrc(seqAdd.ContainerType(env)), model); string sourceValue = "srcval_" + seqAdd.Id; source.AppendFront(arrayValueType + " " + sourceValue + " = (" + arrayValueType + ")" + GetSequenceExpression(seqAdd.Expr, source) + ";\n"); string destinationValue = seqAdd.ExprDst == null ? null : "dstval_" + seqAdd.Id; if(destinationValue != null) source.AppendFront("int " + destinationValue + " = (int)" + GetSequenceExpression(seqAdd.ExprDst, source) + ";\n"); if(seqAdd.Attribute != null) { source.AppendFront("GRGEN_LIBGR.IGraphElement elem_" + seqAdd.Id + " = (GRGEN_LIBGR.IGraphElement)" + GetVar(seqAdd.Attribute.SourceVar) + ";\n"); source.AppendFront("GRGEN_LIBGR.AttributeType attrType_" + seqAdd.Id + " = elem_" + seqAdd.Id + ".Type.GetAttributeType(\"" + seqAdd.Attribute.AttributeName + "\");\n"); if(destinationValue != null) { source.AppendFront("if(elem_" + seqAdd.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", " + destinationValue + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", " + destinationValue + ");\n"); } else { source.AppendFront("if(elem_" + seqAdd.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", null);\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", null);\n"); } } if(destinationValue == null) source.AppendFront(array + ".Add(" + sourceValue + ");\n"); else source.AppendFront(array + ".Insert(" + destinationValue + ", " + sourceValue + ");\n"); if(seqAdd.Attribute != null) { if(gen.FireDebugEvents) { source.AppendFront("if(elem_" + seqAdd.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangedNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangedEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ");\n"); } } source.AppendFront(SetResultVar(seqAdd, container)); } else if(seqAdd.ContainerType(env).StartsWith("deque")) { string deque = container; string dequeValueType = TypesHelper.XgrsTypeToCSharpType(TypesHelper.ExtractSrc(seqAdd.ContainerType(env)), model); string sourceValue = "srcval_" + seqAdd.Id; source.AppendFront(dequeValueType + " " + sourceValue + " = (" + dequeValueType + ")" + GetSequenceExpression(seqAdd.Expr, source) + ";\n"); string destinationValue = seqAdd.ExprDst == null ? null : "dstval_" + seqAdd.Id; if(destinationValue != null) source.AppendFront("int " + destinationValue + " = (int)" + GetSequenceExpression(seqAdd.ExprDst, source) + ";\n"); if(seqAdd.Attribute != null) { source.AppendFront("GRGEN_LIBGR.IGraphElement elem_" + seqAdd.Id + " = (GRGEN_LIBGR.IGraphElement)" + GetVar(seqAdd.Attribute.SourceVar) + ";\n"); source.AppendFront("GRGEN_LIBGR.AttributeType attrType_" + seqAdd.Id + " = elem_" + seqAdd.Id + ".Type.GetAttributeType(\"" + seqAdd.Attribute.AttributeName + "\");\n"); if(destinationValue != null) { source.AppendFront("if(elem_" + seqAdd.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", " + destinationValue + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", " + destinationValue + ");\n"); } else { source.AppendFront("if(elem_" + seqAdd.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", null);\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", null);\n"); } } if(destinationValue == null) source.AppendFront(deque + ".Enqueue(" + sourceValue + ");\n"); else source.AppendFront(deque + ".EnqueueAt(" + destinationValue + ", " + sourceValue + ");\n"); if(seqAdd.Attribute != null) { if(gen.FireDebugEvents) { source.AppendFront("if(elem_" + seqAdd.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangedNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangedEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ");\n"); } } source.AppendFront(SetResultVar(seqAdd, container)); } else { string dictionary = container; string dictSrcType = TypesHelper.XgrsTypeToCSharpType(TypesHelper.ExtractSrc(seqAdd.ContainerType(env)), model); string sourceValue = " srcval_" + seqAdd.Id; source.AppendFront(dictSrcType + " " + sourceValue + " = (" + dictSrcType + ")" + GetSequenceExpression(seqAdd.Expr, source) + ";\n"); string dictDstType = TypesHelper.XgrsTypeToCSharpType(TypesHelper.ExtractDst(seqAdd.ContainerType(env)), model); string destinationValue = seqAdd.ExprDst == null ? null : "dstval_" + seqAdd.Id; if(destinationValue != null) source.AppendFront(dictDstType + " " + destinationValue + " = (" + dictDstType + ")" + GetSequenceExpression(seqAdd.ExprDst, source) + ";\n"); if(seqAdd.Attribute != null) { source.AppendFront("GRGEN_LIBGR.IGraphElement elem_" + seqAdd.Id + " = (GRGEN_LIBGR.IGraphElement)" + GetVar(seqAdd.Attribute.SourceVar) + ";\n"); source.AppendFront("GRGEN_LIBGR.AttributeType attrType_" + seqAdd.Id + " = elem_" + seqAdd.Id + ".Type.GetAttributeType(\"" + seqAdd.Attribute.AttributeName + "\");\n"); if(destinationValue != null) // must be map { source.AppendFront("if(elem_" + seqAdd.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + destinationValue + ", " + sourceValue + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + destinationValue + ", " + sourceValue + ");\n"); } else { source.AppendFront("if(elem_" + seqAdd.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", null);\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ", GRGEN_LIBGR.AttributeChangeType.PutElement, " + sourceValue + ", null);\n"); } } if(destinationValue == null) source.AppendFront(dictionary + "[" + sourceValue + "] = null;\n"); else source.AppendFront(dictionary + "[" + sourceValue + "] = " + destinationValue + ";\n"); if(seqAdd.Attribute != null) { if(gen.FireDebugEvents) { source.AppendFront("if(elem_" + seqAdd.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangedNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangedEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqAdd.Id + ", attrType_" + seqAdd.Id + ");\n"); } } source.AppendFront(SetResultVar(seqAdd, container)); } break; } case SequenceComputationType.ContainerRem: { SequenceComputationContainerRem seqDel = (SequenceComputationContainerRem)seqComp; string container = GetContainerValue(seqDel); if(seqDel.ContainerType(env) == "") { if(seqDel.Attribute != null) { source.AppendFront("GRGEN_LIBGR.IGraphElement elem_" + seqDel.Id + " = (GRGEN_LIBGR.IGraphElement)" + GetVar(seqDel.Attribute.SourceVar) + ";\n"); source.AppendFront("GRGEN_LIBGR.AttributeType attrType_" + seqDel.Id + " = elem_" + seqDel.Id + ".Type.GetAttributeType(\"" + seqDel.Attribute.AttributeName + "\");\n"); } string containerVar = "tmp_eval_once_" + seqDel.Id; source.AppendFront("object " + containerVar + " = " + container + ";\n"); string sourceValue = seqDel.Expr == null ? null : "srcval_" + seqDel.Id; source.AppendFront("if(" + containerVar + " is IList) {\n"); source.Indent(); if(sourceValue != null && !TypesHelper.IsSameOrSubtype(seqDel.Expr.Type(env), "int", model)) source.AppendFront("throw new Exception(\"Can't remove non-int index from array\");\n"); else { string array = "((System.Collections.IList)" + containerVar + ")"; if(sourceValue != null) source.AppendFront("int " + sourceValue + " = (int)" + GetSequenceExpression(seqDel.Expr, source) + ";\n"); if(seqDel.Attribute != null) { if(sourceValue != null) { source.AppendFront("if(elem_" + seqDel.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, " + sourceValue + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, " + sourceValue + ");\n"); } else { source.AppendFront("if(elem_" + seqDel.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, null);\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, null);\n"); } } if(sourceValue == null) source.AppendFront(array + ".RemoveAt(" + array + ".Count - 1);\n"); else source.AppendFront(array + ".RemoveAt(" + sourceValue + ");\n"); if(seqDel.Attribute != null) { if(gen.FireDebugEvents) { source.AppendFront("if(elem_" + seqDel.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangedNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangedEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ");\n"); } } } source.Unindent(); source.AppendFront("} else if(" + containerVar + " is GRGEN_LIBGR.IDeque) {\n"); source.Indent(); if(sourceValue != null && !TypesHelper.IsSameOrSubtype(seqDel.Expr.Type(env), "int", model)) source.AppendFront("throw new Exception(\"Can't remove non-int index from deque\");\n"); else { string deque = "((GRGEN_LIBGR.IDeque)" + containerVar + ")"; if(sourceValue != null) source.AppendFront("int " + sourceValue + " = (int)" + GetSequenceExpression(seqDel.Expr, source) + ";\n"); if(seqDel.Attribute != null) { if(sourceValue != null) { source.AppendFront("if(elem_" + seqDel.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, " + sourceValue + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, " + sourceValue + ");\n"); } else { source.AppendFront("if(elem_" + seqDel.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, null);\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, null);\n"); } } if(sourceValue == null) source.AppendFront(deque + ".Dequeue();\n"); else source.AppendFront(deque + ".DequeueAt(" + sourceValue + ");\n"); if(seqDel.Attribute != null) { if(gen.FireDebugEvents) { source.AppendFront("if(elem_" + seqDel.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangedNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangedEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ");\n"); } } } source.Unindent(); source.AppendFront("} else {\n"); source.Indent(); string dictionary = "((System.Collections.IDictionary)" + containerVar + ")"; if(sourceValue != null) source.AppendFront("object " + sourceValue + " = " + GetSequenceExpression(seqDel.Expr, source) + ";\n"); if(seqDel.Attribute != null) { source.AppendFront("if(GRGEN_LIBGR.TypesHelper.ExtractDst(GRGEN_LIBGR.TypesHelper.AttributeTypeToXgrsType(attrType_" + seqDel.Id + ")) == \"SetValueType\")\n"); source.AppendFront("{\n"); source.Indent(); source.AppendFront("if(elem_" + seqDel.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, " + sourceValue + ", null);\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, " + sourceValue + ", null);\n"); source.Unindent(); source.AppendFront("}\n"); source.AppendFront("else\n"); source.AppendFront("{\n"); source.Indent(); source.AppendFront("if(elem_" + seqDel.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, " + sourceValue + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, " + sourceValue + ");\n"); source.Unindent(); source.AppendFront("}\n"); } if(sourceValue == null) source.AppendFront("throw new Exception(\""+seqDel.Container.PureName+".rem() only possible on array or deque!\");\n"); else source.AppendFront(dictionary + ".Remove(" + sourceValue + ");\n"); if(seqDel.Attribute != null) { if(gen.FireDebugEvents) { source.AppendFront("if(elem_" + seqDel.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangedNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangedEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ");\n"); } } source.Unindent(); source.AppendFront("}\n"); source.AppendFront(SetResultVar(seqDel, containerVar)); } else if(seqDel.ContainerType(env).StartsWith("array")) { string array = container; string sourceValue = seqDel.Expr == null ? null : "srcval_" + seqDel.Id; if(sourceValue != null) source.AppendFront("int " + sourceValue + " = (int)" + GetSequenceExpression(seqDel.Expr, source) + ";\n"); if(seqDel.Attribute != null) { source.AppendFront("GRGEN_LIBGR.IGraphElement elem_" + seqDel.Id + " = (GRGEN_LIBGR.IGraphElement)" + GetVar(seqDel.Attribute.SourceVar) + ";\n"); source.AppendFront("GRGEN_LIBGR.AttributeType attrType_" + seqDel.Id + " = elem_" + seqDel.Id + ".Type.GetAttributeType(\"" + seqDel.Attribute.AttributeName + "\");\n"); if(sourceValue != null) { source.AppendFront("if(elem_" + seqDel.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, " + sourceValue + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, " + sourceValue + ");\n"); } else { source.AppendFront("if(elem_" + seqDel.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, null);\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, null);\n"); } } if(sourceValue == null) source.AppendFront(array + ".RemoveAt(" + array + ".Count - 1);\n"); else source.AppendFront(array + ".RemoveAt(" + sourceValue + ");\n"); if(seqDel.Attribute != null) { if(gen.FireDebugEvents) { source.AppendFront("if(elem_" + seqDel.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangedNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangedEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ");\n"); } } source.AppendFront(SetResultVar(seqDel, container)); } else if(seqDel.ContainerType(env).StartsWith("deque")) { string deque = container; string sourceValue = seqDel.Expr == null ? null : "srcval_" + seqDel.Id; if(sourceValue != null) source.AppendFront("int " + sourceValue + " = (int)" + GetSequenceExpression(seqDel.Expr, source) + ";\n"); if(seqDel.Attribute != null) { source.AppendFront("GRGEN_LIBGR.IGraphElement elem_" + seqDel.Id + " = (GRGEN_LIBGR.IGraphElement)" + GetVar(seqDel.Attribute.SourceVar) + ";\n"); source.AppendFront("GRGEN_LIBGR.AttributeType attrType_" + seqDel.Id + " = elem_" + seqDel.Id + ".Type.GetAttributeType(\"" + seqDel.Attribute.AttributeName + "\");\n"); if(sourceValue != null) { source.AppendFront("if(elem_" + seqDel.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, " + sourceValue + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, " + sourceValue + ");\n"); } else { source.AppendFront("if(elem_" + seqDel.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, null);\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, null);\n"); } } if(sourceValue == null) source.AppendFront(deque + ".Dequeue();\n"); else source.AppendFront(deque + ".DequeueAt(" + sourceValue + ");\n"); if(seqDel.Attribute != null) { if(gen.FireDebugEvents) { source.AppendFront("if(elem_" + seqDel.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangedNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangedEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ");\n"); } } source.AppendFront(SetResultVar(seqDel, container)); } else { string dictionary = container; string dictSrcType = TypesHelper.XgrsTypeToCSharpType(TypesHelper.ExtractSrc(seqDel.ContainerType(env)), model); string sourceValue = "srcval_" + seqDel.Id; source.AppendFront(dictSrcType + " " + sourceValue + " = (" + dictSrcType + ")" + GetSequenceExpression(seqDel.Expr, source) + ";\n"); if(seqDel.Attribute != null) { source.AppendFront("GRGEN_LIBGR.IGraphElement elem_" + seqDel.Id + " = (GRGEN_LIBGR.IGraphElement)" + GetVar(seqDel.Attribute.SourceVar) + ";\n"); source.AppendFront("GRGEN_LIBGR.AttributeType attrType_" + seqDel.Id + " = elem_" + seqDel.Id + ".Type.GetAttributeType(\"" + seqDel.Attribute.AttributeName + "\");\n"); if(TypesHelper.ExtractDst(seqDel.ContainerType(env)) == "SetValueType") { source.AppendFront("if(elem_" + seqDel.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, " + sourceValue + ", null);\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, " + sourceValue + ", null);\n"); } else { source.AppendFront("if(elem_" + seqDel.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, " + sourceValue + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, " + sourceValue + ");\n"); } } source.AppendFront(dictionary + ".Remove(" + sourceValue + ");\n"); if(seqDel.Attribute != null) { if(gen.FireDebugEvents) { source.AppendFront("if(elem_" + seqDel.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangedNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangedEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqDel.Id + ", attrType_" + seqDel.Id + ");\n"); } } source.AppendFront(SetResultVar(seqDel, container)); } break; } case SequenceComputationType.ContainerClear: { SequenceComputationContainerClear seqClear = (SequenceComputationContainerClear)seqComp; string container = GetContainerValue(seqClear); if(seqClear.ContainerType(env) == "") { if(seqClear.Attribute != null) { source.AppendFront("GRGEN_LIBGR.IGraphElement elem_" + seqClear.Id + " = (GRGEN_LIBGR.IGraphElement)" + GetVar(seqClear.Attribute.SourceVar) + ";\n"); source.AppendFront("GRGEN_LIBGR.AttributeType attrType_" + seqClear.Id + " = elem_" + seqClear.Id + ".Type.GetAttributeType(\"" + seqClear.Attribute.AttributeName + "\");\n"); } string containerVar = "tmp_eval_once_" + seqClear.Id; source.AppendFront("object " + containerVar + " = " + container + ";\n"); source.AppendFront("if(" + containerVar + " is IList) {\n"); source.Indent(); string array = "((System.Collections.IList)" + containerVar + ")"; if(seqClear.Attribute != null) { source.AppendFront("for(int i_" + seqClear.Id + " = " + array + ".Count; i_" + seqClear.Id + " >= 0; --i_" + seqClear.Id + ")\n"); source.AppendFront("\tif(elem_" + seqClear.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\t\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, i_" + seqClear.Id + ");\n"); source.AppendFront("\telse\n"); source.AppendFront("\t\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, i_" + seqClear.Id + ");\n"); } source.AppendFront(array + ".Clear();\n"); if(seqClear.Attribute != null) { if(gen.FireDebugEvents) { source.AppendFront("\tif(elem_" + seqClear.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\t\tgraph.ChangedNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ");\n"); source.AppendFront("\telse\n"); source.AppendFront("\t\tgraph.ChangedEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ");\n"); } } source.Unindent(); source.AppendFront("} else if(" + containerVar + " is GRGEN_LIBGR.IDeque) {\n"); source.Indent(); string deque = "((GRGEN_LIBGR.IDeque)" + containerVar + ")"; if(seqClear.Attribute != null) { source.AppendFront("for(int i_" + seqClear.Id + " = " + deque + ".Count; i_" + seqClear.Id + " >= 0; --i_" + seqClear.Id + ")\n"); source.AppendFront("\tif(elem_" + seqClear.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\t\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, i_" + seqClear.Id + ");\n"); source.AppendFront("\telse\n"); source.AppendFront("\t\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, i_" + seqClear.Id + ");\n"); } source.AppendFront(deque + ".Clear();\n"); if(seqClear.Attribute != null) { if(gen.FireDebugEvents) { source.AppendFront("\tif(elem_" + seqClear.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\t\tgraph.ChangedNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ");\n"); source.AppendFront("\telse\n"); source.AppendFront("\t\tgraph.ChangedEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ");\n"); } } source.Unindent(); source.AppendFront("} else {\n"); source.Indent(); string dictionary = "((System.Collections.IDictionary)" + containerVar + ")"; if(seqClear.Attribute != null) { source.AppendFront("if(GRGEN_LIBGR.TypesHelper.ExtractDst(GRGEN_LIBGR.TypesHelper.AttributeTypeToXgrsType(attrType_" + seqClear.Id + ")) == \"SetValueType\")\n"); source.AppendFront("{\n"); source.Indent(); source.AppendFront("foreach(DictionaryEntry kvp_" + seqClear.Id + " in " + dictionary + ")\n"); source.AppendFront("\tif(elem_" + seqClear.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\t\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, kvp_" + seqClear.Id + ", null);\n"); source.AppendFront("\telse\n"); source.AppendFront("\t\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, kvp_" + seqClear.Id + ", null);\n"); source.Unindent(); source.AppendFront("}\n"); source.AppendFront("else\n"); source.AppendFront("{\n"); source.Indent(); source.AppendFront("foreach(DictionaryEntry kvp_" + seqClear.Id + " in " + dictionary + ")\n"); source.AppendFront("\tif(elem_" + seqClear.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\t\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, kvp_" + seqClear.Id + ");\n"); source.AppendFront("\telse\n"); source.AppendFront("\t\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, kvp_" + seqClear.Id + ");\n"); source.Unindent(); source.AppendFront("}\n"); } source.AppendFront(dictionary + ".Clear();\n"); if(seqClear.Attribute != null) { if(gen.FireDebugEvents) { source.AppendFront("\tif(elem_" + seqClear.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\t\tgraph.ChangedNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ");\n"); source.AppendFront("\telse\n"); source.AppendFront("\t\tgraph.ChangedEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ");\n"); } } source.Unindent(); source.AppendFront("}\n"); source.AppendFront(SetResultVar(seqClear, containerVar)); } else if(seqClear.ContainerType(env).StartsWith("array")) { string array = container; if(seqClear.Attribute != null) { source.AppendFront("GRGEN_LIBGR.IGraphElement elem_" + seqClear.Id + " = (GRGEN_LIBGR.IGraphElement)" + GetVar(seqClear.Attribute.SourceVar) + ";\n"); source.AppendFront("GRGEN_LIBGR.AttributeType attrType_" + seqClear.Id + " = elem_" + seqClear.Id + ".Type.GetAttributeType(\"" + seqClear.Attribute.AttributeName + "\");\n"); source.AppendFront("for(int i_" + seqClear.Id + " = " + array + ".Count; i_" + seqClear.Id + " >= 0; --i_" + seqClear.Id + ")\n"); source.AppendFront("\tif(elem_" + seqClear.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\t\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, i_" + seqClear.Id + ");\n"); source.AppendFront("\telse\n"); source.AppendFront("\t\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, i_" + seqClear.Id + ");\n"); } source.AppendFront(array + ".Clear();\n"); if(seqClear.Attribute != null) { if(gen.FireDebugEvents) { source.AppendFront("\tif(elem_" + seqClear.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\t\tgraph.ChangedNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ");\n"); source.AppendFront("\telse\n"); source.AppendFront("\t\tgraph.ChangedEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ");\n"); } } source.AppendFront(SetResultVar(seqClear, container)); } else if(seqClear.ContainerType(env).StartsWith("deque")) { string deque = container; if(seqClear.Attribute != null) { source.AppendFront("GRGEN_LIBGR.IGraphElement elem_" + seqClear.Id + " = (GRGEN_LIBGR.IGraphElement)" + GetVar(seqClear.Attribute.SourceVar) + ";\n"); source.AppendFront("GRGEN_LIBGR.AttributeType attrType_" + seqClear.Id + " = elem_" + seqClear.Id + ".Type.GetAttributeType(\"" + seqClear.Attribute.AttributeName + "\");\n"); source.AppendFront("for(int i_" + seqClear.Id + " = " + deque + ".Count; i_" + seqClear.Id + " >= 0; --i_" + seqClear.Id + ")\n"); source.AppendFront("\tif(elem_" + seqClear.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\t\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, i_" + seqClear.Id + ");\n"); source.AppendFront("\telse\n"); source.AppendFront("\t\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, i_" + seqClear.Id + ");\n"); } source.AppendFront(deque + ".Clear();\n"); if(seqClear.Attribute != null) { if(gen.FireDebugEvents) { source.AppendFront("\tif(elem_" + seqClear.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\t\tgraph.ChangedNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ");\n"); source.AppendFront("\telse\n"); source.AppendFront("\t\tgraph.ChangedEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ");\n"); } } source.AppendFront(SetResultVar(seqClear, container)); } else { string dictionary = container; if(seqClear.Attribute != null) { source.AppendFront("GRGEN_LIBGR.IGraphElement elem_" + seqClear.Id + " = (GRGEN_LIBGR.IGraphElement)" + GetVar(seqClear.Attribute.SourceVar) + ";\n"); source.AppendFront("GRGEN_LIBGR.AttributeType attrType_" + seqClear.Id + " = elem_" + seqClear.Id + ".Type.GetAttributeType(\"" + seqClear.Attribute.AttributeName + "\");\n"); if(TypesHelper.ExtractDst(seqClear.ContainerType(env)) == "SetValueType") { source.AppendFront("foreach(DictionaryEntry kvp_" + seqClear.Id + " in " + dictionary + ")\n"); source.AppendFront("if(elem_" + seqClear.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, kvp_" + seqClear.Id + ", null);\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, kvp_" + seqClear.Id + ", null);\n"); } else { source.AppendFront("foreach(DictionaryEntry kvp_" + seqClear.Id + " in " + dictionary + ")\n"); source.AppendFront("if(elem_" + seqClear.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangingNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, kvp_" + seqClear.Id + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangingEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ", GRGEN_LIBGR.AttributeChangeType.RemoveElement, null, kvp_" + seqClear.Id + ");\n"); } } source.AppendFront(dictionary + ".Clear();\n"); if(seqClear.Attribute != null) { if(gen.FireDebugEvents) { source.AppendFront("if(elem_" + seqClear.Id + " is GRGEN_LIBGR.INode)\n"); source.AppendFront("\tgraph.ChangedNodeAttribute((GRGEN_LIBGR.INode)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tgraph.ChangedEdgeAttribute((GRGEN_LIBGR.IEdge)elem_" + seqClear.Id + ", attrType_" + seqClear.Id + ");\n"); } } source.AppendFront(SetResultVar(seqClear, container)); } break; } case SequenceComputationType.VAlloc: source.Append("graph.AllocateVisitedFlag()"); break; case SequenceComputationType.VFree: case SequenceComputationType.VFreeNonReset: { SequenceComputationVFree seqVFree = (SequenceComputationVFree)seqComp; if(seqVFree.Reset) source.AppendFront("graph.FreeVisitedFlag((int)" + GetSequenceExpression(seqVFree.VisitedFlagExpression, source) + ");\n"); else source.AppendFront("graph.FreeVisitedFlagNonReset((int)" + GetSequenceExpression(seqVFree.VisitedFlagExpression, source) + ");\n"); source.AppendFront(SetResultVar(seqVFree, "null")); break; } case SequenceComputationType.VReset: { SequenceComputationVReset seqVReset = (SequenceComputationVReset)seqComp; source.AppendFront("graph.ResetVisitedFlag((int)" + GetSequenceExpression(seqVReset.VisitedFlagExpression, source) + ");\n"); source.AppendFront(SetResultVar(seqVReset, "null")); break; } case SequenceComputationType.DebugAdd: { SequenceComputationDebugAdd seqDebug = (SequenceComputationDebugAdd)seqComp; source.AppendFront("procEnv.DebugEntering("); for(int i = 0; i < seqDebug.ArgExprs.Count; ++i) { if(i == 0) source.Append("(string)"); else source.Append(", "); source.Append(GetSequenceExpression(seqDebug.ArgExprs[i], source)); } source.Append(");\n"); source.AppendFront(SetResultVar(seqDebug, "null")); break; } case SequenceComputationType.DebugRem: { SequenceComputationDebugRem seqDebug = (SequenceComputationDebugRem)seqComp; source.AppendFront("procEnv.DebugExiting("); for(int i = 0; i < seqDebug.ArgExprs.Count; ++i) { if(i == 0) source.Append("(string)"); else source.Append(", "); source.Append(GetSequenceExpression(seqDebug.ArgExprs[i], source)); } source.Append(");\n"); source.AppendFront(SetResultVar(seqDebug, "null")); break; } case SequenceComputationType.DebugEmit: { SequenceComputationDebugEmit seqDebug = (SequenceComputationDebugEmit)seqComp; source.AppendFront("procEnv.DebugEmitting("); for(int i = 0; i < seqDebug.ArgExprs.Count; ++i) { if(i == 0) source.Append("(string)"); else source.Append(", "); source.Append(GetSequenceExpression(seqDebug.ArgExprs[i], source)); } source.Append(");\n"); source.AppendFront(SetResultVar(seqDebug, "null")); break; } case SequenceComputationType.DebugHalt: { SequenceComputationDebugHalt seqDebug = (SequenceComputationDebugHalt)seqComp; source.AppendFront("procEnv.DebugHalting("); for(int i = 0; i < seqDebug.ArgExprs.Count; ++i) { if(i == 0) source.Append("(string)"); else source.Append(", "); source.Append(GetSequenceExpression(seqDebug.ArgExprs[i], source)); } source.Append(");\n"); source.AppendFront(SetResultVar(seqDebug, "null")); break; } case SequenceComputationType.DebugHighlight: { SequenceComputationDebugHighlight seqDebug = (SequenceComputationDebugHighlight)seqComp; source.AppendFront("List<object> values = new List<object>();\n"); source.AppendFront("List<string> annotations = new List<string>();\n"); for(int i = 1; i < seqDebug.ArgExprs.Count; ++i) { if(i % 2 == 1) source.AppendFront("values.Add(" + GetSequenceExpression(seqDebug.ArgExprs[i], source) + ");\n"); else source.AppendFront("annotations.Add((string)" + GetSequenceExpression(seqDebug.ArgExprs[i], source) + ");\n"); } source.AppendFront("procEnv.DebugHighlighting(" + GetSequenceExpression(seqDebug.ArgExprs[0], source) + ", values, annotations);\n"); source.AppendFront(SetResultVar(seqDebug, "null")); break; } case SequenceComputationType.Emit: { SequenceComputationEmit seqEmit = (SequenceComputationEmit)seqComp; bool declarationEmitted = false; for(int i = 0; i < seqEmit.Expressions.Count; ++i) { if(!(seqEmit.Expressions[i] is SequenceExpressionConstant)) { string emitVal = "emitval_" + seqEmit.Id; if(!declarationEmitted) { source.AppendFront("object " + emitVal + ";\n"); declarationEmitted = true; } source.AppendFront(emitVal + " = " + GetSequenceExpression(seqEmit.Expressions[i], source) + ";\n"); if(seqEmit.Expressions[i].Type(env) == "" || seqEmit.Expressions[i].Type(env).StartsWith("set<") || seqEmit.Expressions[i].Type(env).StartsWith("map<") || seqEmit.Expressions[i].Type(env).StartsWith("array<") || seqEmit.Expressions[i].Type(env).StartsWith("deque<")) { source.AppendFront("if(" + emitVal + " is IDictionary)\n"); source.AppendFront("\tprocEnv.EmitWriter.Write(GRGEN_LIBGR.EmitHelper.ToString((IDictionary)" + emitVal + ", graph));\n"); source.AppendFront("else if(" + emitVal + " is IList)\n"); source.AppendFront("\tprocEnv.EmitWriter.Write(GRGEN_LIBGR.EmitHelper.ToString((IList)" + emitVal + ", graph));\n"); source.AppendFront("else if(" + emitVal + " is GRGEN_LIBGR.IDeque)\n"); source.AppendFront("\tprocEnv.EmitWriter.Write(GRGEN_LIBGR.EmitHelper.ToString((GRGEN_LIBGR.IDeque)" + emitVal + ", graph));\n"); source.AppendFront("else\n\t"); } source.AppendFront("procEnv.EmitWriter.Write(GRGEN_LIBGR.EmitHelper.ToString(" + emitVal + ", graph));\n"); } else { SequenceExpressionConstant constant = (SequenceExpressionConstant)seqEmit.Expressions[i]; if(constant.Constant is string) { String text = (string)constant.Constant; text = text.Replace("\n", "\\n"); text = text.Replace("\r", "\\r"); text = text.Replace("\t", "\\t"); source.AppendFront("procEnv.EmitWriter.Write(\"" + text + "\");\n"); } else source.AppendFront("procEnv.EmitWriter.Write(GRGEN_LIBGR.EmitHelper.ToString(" + GetSequenceExpression(seqEmit.Expressions[i], source) + ", graph));\n"); } } source.AppendFront(SetResultVar(seqEmit, "null")); break; } case SequenceComputationType.Record: { SequenceComputationRecord seqRec = (SequenceComputationRecord)seqComp; if(!(seqRec.Expression is SequenceExpressionConstant)) { string recVal = "recval_" + seqRec.Id; source.AppendFront("object " + recVal + " = " + GetSequenceExpression(seqRec.Expression, source) + ";\n"); if(seqRec.Expression.Type(env) == "" || seqRec.Expression.Type(env).StartsWith("set<") || seqRec.Expression.Type(env).StartsWith("map<") || seqRec.Expression.Type(env).StartsWith("array<") || seqRec.Expression.Type(env).StartsWith("deque<")) { source.AppendFront("if(" + recVal + " is IDictionary)\n"); source.AppendFront("\tprocEnv.Recorder.Write(GRGEN_LIBGR.EmitHelper.ToString((IDictionary)" + recVal + ", graph));\n"); source.AppendFront("else if(" + recVal + " is IList)\n"); source.AppendFront("\tprocEnv.Recorder.Write(GRGEN_LIBGR.EmitHelper.ToString((IList)" + recVal + ", graph));\n"); source.AppendFront("else if(" + recVal + " is GRGEN_LIBGR.IDeque)\n"); source.AppendFront("\tprocEnv.Recorder.Write(GRGEN_LIBGR.EmitHelper.ToString((GRGEN_LIBGR.IDeque)" + recVal + ", graph));\n"); source.AppendFront("else\n\t"); } source.AppendFront("procEnv.Recorder.Write(GRGEN_LIBGR.EmitHelper.ToString(" + recVal + ", graph));\n"); } else { SequenceExpressionConstant constant = (SequenceExpressionConstant)seqRec.Expression; if(constant.Constant is string) { String text = (string)constant.Constant; text = text.Replace("\n", "\\n"); text = text.Replace("\r", "\\r"); text = text.Replace("\t", "\\t"); source.AppendFront("procEnv.Recorder.Write(\"" + text + "\");\n"); } else source.AppendFront("procEnv.Recorder.Write(GRGEN_LIBGR.EmitHelper.ToString(" + GetSequenceExpression(seqRec.Expression, source) + ", graph));\n"); } source.AppendFront(SetResultVar(seqRec, "null")); break; } case SequenceComputationType.Export: { SequenceComputationExport seqExp = (SequenceComputationExport)seqComp; string expFileName = "expfilename_" + seqExp.Id; source.AppendFront("object " + expFileName + " = " + GetSequenceExpression(seqExp.Name, source) + ";\n"); string expArguments = "exparguments_" + seqExp.Id; source.AppendFront("List<string> " + expArguments + " = new List<string>();\n"); source.AppendFront(expArguments + ".Add(" + expFileName + ".ToString());\n"); string expGraph = "expgraph_" + seqExp.Id; if(seqExp.Graph != null) source.AppendFront("GRGEN_LIBGR.IGraph " + expGraph + " = (GRGEN_LIBGR.IGraph)" + GetSequenceExpression(seqExp.Graph, source) + ";\n"); else source.AppendFront("GRGEN_LIBGR.IGraph " + expGraph + " = graph;\n"); source.AppendFront(expArguments + ".Add(" + expFileName + ".ToString());\n"); source.AppendFront("if(" + expGraph + " is GRGEN_LIBGR.INamedGraph)\n"); source.AppendFront("\tGRGEN_LIBGR.Porter.Export((GRGEN_LIBGR.INamedGraph)" + expGraph + ", " + expArguments + ");\n"); source.AppendFront("else\n"); source.AppendFront("\tGRGEN_LIBGR.Porter.Export(" + expGraph + ", " + expArguments + ");\n"); source.AppendFront(SetResultVar(seqExp, "null")); break; } case SequenceComputationType.DeleteFile: { SequenceComputationDeleteFile seqDelFile = (SequenceComputationDeleteFile)seqComp; string delFileName = "delfilename_" + seqDelFile.Id; source.AppendFront("object " + delFileName + " = " + GetSequenceExpression(seqDelFile.Name, source) + ";\n"); source.AppendFront("\tSystem.IO.File.Delete((string)" + delFileName + ");\n"); source.AppendFront(SetResultVar(seqDelFile, "null")); break; } case SequenceComputationType.GraphAdd: { SequenceComputationGraphAdd seqAdd = (SequenceComputationGraphAdd)seqComp; if(seqAdd.ExprSrc == null) { string typeExpr = GetSequenceExpression(seqAdd.Expr, source); source.Append("GRGEN_LIBGR.GraphHelper.AddNodeOfType(" + typeExpr + ", graph)"); } else { string typeExpr = GetSequenceExpression(seqAdd.Expr, source); string srcExpr = GetSequenceExpression(seqAdd.ExprSrc, source); string tgtExpr = GetSequenceExpression(seqAdd.ExprDst, source); source.Append("GRGEN_LIBGR.GraphHelper.AddEdgeOfType(" + typeExpr + ", (GRGEN_LIBGR.INode)" + srcExpr + ", (GRGEN_LIBGR.INode)" + tgtExpr + ", graph)"); } break; } case SequenceComputationType.GraphRem: { SequenceComputationGraphRem seqRem = (SequenceComputationGraphRem)seqComp; string remVal = "remval_" + seqRem.Id; string seqRemExpr = GetSequenceExpression(seqRem.Expr, source); if(seqRem.Expr.Type(env) == "") { source.AppendFront("GRGEN_LIBGR.IGraphElement " + remVal + " = (GRGEN_LIBGR.IGraphElement)" + seqRemExpr + ";\n"); source.AppendFront("if(" + remVal + " is GRGEN_LIBGR.IEdge)\n"); source.AppendFront("\tgraph.Remove((GRGEN_LIBGR.IEdge)" + remVal + ");\n"); source.AppendFront("else\n"); source.AppendFront("\t{graph.RemoveEdges((GRGEN_LIBGR.INode)" + remVal + "); graph.Remove((GRGEN_LIBGR.INode)" + remVal + ");}\n"); } else { if(TypesHelper.IsSameOrSubtype(seqRem.Expr.Type(env), "Node", model)) { source.AppendFront("GRGEN_LIBGR.INode " + remVal + " = (GRGEN_LIBGR.INode)" + seqRemExpr + ";\n"); source.AppendFront("graph.RemoveEdges(" + remVal + "); graph.Remove(" + remVal + ");\n"); } else if(TypesHelper.IsSameOrSubtype(seqRem.Expr.Type(env), "Edge", model)) { source.AppendFront("GRGEN_LIBGR.IEdge " + remVal + " = (GRGEN_LIBGR.IEdge)" + seqRemExpr + ";\n"); source.AppendFront("\tgraph.Remove(" + remVal + ");\n"); } else source.AppendFront("throw new Exception(\"rem() on non-node/edge\");\n"); } source.AppendFront(SetResultVar(seqRem, "null")); break; } case SequenceComputationType.GraphClear: { SequenceComputationGraphClear seqClr = (SequenceComputationGraphClear)seqComp; source.AppendFront("graph.Clear();\n"); source.AppendFront(SetResultVar(seqClr, "null")); break; } case SequenceComputationType.GraphRetype: { SequenceComputationGraphRetype seqRetype = (SequenceComputationGraphRetype)seqComp; string typeExpr = GetSequenceExpression(seqRetype.TypeExpr, source); string elemExpr = GetSequenceExpression(seqRetype.ElemExpr, source); source.Append("GRGEN_LIBGR.GraphHelper.RetypeGraphElement((GRGEN_LIBGR.IGraphElement)" + elemExpr + ", " + typeExpr + ", graph)"); break; } case SequenceComputationType.GraphAddCopy: { SequenceComputationGraphAddCopy seqAddCopy = (SequenceComputationGraphAddCopy)seqComp; if(seqAddCopy.ExprSrc == null) { string nodeExpr = GetSequenceExpression(seqAddCopy.Expr, source); source.Append("GRGEN_LIBGR.GraphHelper.AddCopyOfNode(" + nodeExpr + ", graph)"); } else { string edgeExpr = GetSequenceExpression(seqAddCopy.Expr, source); string srcExpr = GetSequenceExpression(seqAddCopy.ExprSrc, source); string tgtExpr = GetSequenceExpression(seqAddCopy.ExprDst, source); source.Append("GRGEN_LIBGR.GraphHelper.AddCopyOfEdge(" + edgeExpr + ", (GRGEN_LIBGR.INode)" + srcExpr + ", (GRGEN_LIBGR.INode)" + tgtExpr + ", graph)"); } break; } case SequenceComputationType.GraphMerge: { SequenceComputationGraphMerge seqMrg = (SequenceComputationGraphMerge)seqComp; string tgtNodeExpr = GetSequenceExpression(seqMrg.TargetNodeExpr, source); string srcNodeExpr = GetSequenceExpression(seqMrg.SourceNodeExpr, source); source.AppendFrontFormat("graph.Merge((GRGEN_LIBGR.INode){0}, (GRGEN_LIBGR.INode){1}, \"merge\");\n", tgtNodeExpr, srcNodeExpr); source.AppendFront(SetResultVar(seqMrg, "null")); break; } case SequenceComputationType.GraphRedirectSource: { SequenceComputationGraphRedirectSource seqRedir = (SequenceComputationGraphRedirectSource)seqComp; string edgeExpr = GetSequenceExpression(seqRedir.EdgeExpr, source); string srcNodeExpr = GetSequenceExpression(seqRedir.SourceNodeExpr, source); source.AppendFrontFormat("graph.RedirectSource((GRGEN_LIBGR.IEdge){0}, (GRGEN_LIBGR.INode){1}, \"old source\");\n", edgeExpr, srcNodeExpr); source.AppendFront(SetResultVar(seqRedir, "null")); break; } case SequenceComputationType.GraphRedirectTarget: { SequenceComputationGraphRedirectTarget seqRedir = (SequenceComputationGraphRedirectTarget)seqComp; string edgeExpr = GetSequenceExpression(seqRedir.EdgeExpr, source); string tgtNodeExpr = GetSequenceExpression(seqRedir.TargetNodeExpr, source); source.AppendFrontFormat("graph.RedirectTarget((GRGEN_LIBGR.IEdge){0}, (GRGEN_LIBGR.INode){1}, \"old target\");\n", edgeExpr, tgtNodeExpr); source.AppendFront(SetResultVar(seqRedir, "null")); break; } case SequenceComputationType.GraphRedirectSourceAndTarget: { SequenceComputationGraphRedirectSourceAndTarget seqRedir = (SequenceComputationGraphRedirectSourceAndTarget)seqComp; string edgeExpr = GetSequenceExpression(seqRedir.EdgeExpr, source); string srcNodeExpr = GetSequenceExpression(seqRedir.SourceNodeExpr, source); string tgtNodeExpr = GetSequenceExpression(seqRedir.TargetNodeExpr, source); source.AppendFrontFormat("graph.RedirectSourceAndTarget((GRGEN_LIBGR.IEdge){0}, (GRGEN_LIBGR.INode){1}, (GRGEN_LIBGR.INode){2}, \"old source\", \"old target\");\n", edgeExpr, srcNodeExpr, tgtNodeExpr); source.AppendFront(SetResultVar(seqRedir, "null")); break; } case SequenceComputationType.Insert: { SequenceComputationInsert seqIns = (SequenceComputationInsert)seqComp; string graphExpr = GetSequenceExpression(seqIns.Graph, source); source.AppendFrontFormat("GRGEN_LIBGR.GraphHelper.Insert((GRGEN_LIBGR.IGraph){0}, graph);\n", graphExpr); source.AppendFront(SetResultVar(seqIns, "null")); break; } case SequenceComputationType.InsertCopy: { SequenceComputationInsertCopy seqInsCopy = (SequenceComputationInsertCopy)seqComp; string graphExpr = GetSequenceExpression(seqInsCopy.Graph, source); string rootNodeExpr = GetSequenceExpression(seqInsCopy.RootNode, source); source.AppendFormat("GRGEN_LIBGR.GraphHelper.InsertCopy((GRGEN_LIBGR.IGraph){0}, (GRGEN_LIBGR.INode){1}, graph)", graphExpr, rootNodeExpr); break; } case SequenceComputationType.InsertInduced: { SequenceComputationInsertInduced seqInsInd = (SequenceComputationInsertInduced)seqComp; source.Append("GRGEN_LIBGR.GraphHelper.InsertInduced((IDictionary<GRGEN_LIBGR.INode, GRGEN_LIBGR.SetValueType>)" + GetSequenceExpression(seqInsInd.NodeSet, source) + ", (GRGEN_LIBGR.INode)" + GetSequenceExpression(seqInsInd.RootNode, source) + ", graph)"); break; } case SequenceComputationType.InsertDefined: { SequenceComputationInsertDefined seqInsDef = (SequenceComputationInsertDefined)seqComp; source.Append("GRGEN_LIBGR.GraphHelper.InsertDefined((IDictionary<GRGEN_LIBGR.IEdge, GRGEN_LIBGR.SetValueType>)" + GetSequenceExpression(seqInsDef.EdgeSet, source) + ", (GRGEN_LIBGR.IEdge)" + GetSequenceExpression(seqInsDef.RootEdge, source) + ", graph)"); break; } case SequenceComputationType.Expression: { SequenceExpression seqExpr = (SequenceExpression)seqComp; source.AppendFront(SetResultVar(seqExpr, GetSequenceExpression(seqExpr, source))); break; } case SequenceComputationType.BuiltinProcedureCall: { SequenceComputationBuiltinProcedureCall seqCall = (SequenceComputationBuiltinProcedureCall)seqComp; SourceBuilder sb = new SourceBuilder(); EmitSequenceComputation(seqCall.BuiltinProcedure, sb); if(seqCall.ReturnVars.Count > 0) { source.AppendFront(SetVar(seqCall.ReturnVars[0], sb.ToString())); source.AppendFront(SetResultVar(seqCall, GetVar(seqCall.ReturnVars[0]))); } else { source.AppendFront(sb.ToString() + ";\n"); source.AppendFront(SetResultVar(seqCall, "null")); } break; } case SequenceComputationType.ProcedureCall: { SequenceComputationProcedureCall seqCall = (SequenceComputationProcedureCall)seqComp; String returnParameterDeclarations; String returnArguments; String returnAssignments; BuildReturnParameters(seqCall.ParamBindings, out returnParameterDeclarations, out returnArguments, out returnAssignments); if(returnParameterDeclarations.Length != 0) source.AppendFront(returnParameterDeclarations + "\n"); if(seqCall.IsExternalProcedureCalled) source.AppendFront("GRGEN_EXPR.ExternalProcedures."); else source.AppendFrontFormat("GRGEN_ACTIONS.{0}Procedures.", TypesHelper.GetPackagePrefixDot(seqCall.ParamBindings.Package)); source.Append(seqCall.ParamBindings.Name); source.Append("(procEnv, graph"); source.Append(BuildParameters(seqCall.ParamBindings)); source.Append(returnArguments); source.Append(");\n"); if(returnAssignments.Length != 0) source.AppendFront(returnAssignments + "\n"); source.AppendFront(SetResultVar(seqCall, "null")); break; } case SequenceComputationType.ProcedureMethodCall: { SequenceComputationProcedureMethodCall seqCall = (SequenceComputationProcedureMethodCall)seqComp; String type = seqCall.TargetExpr != null ? seqCall.TargetExpr.Type(env) : seqCall.TargetVar.Type; if(type == "") { string tmpVarName = "tmpvar_" + tmpVarCtr.ToString(); ++tmpVarCtr; source.AppendFront("object[] " + tmpVarName + " = "); source.Append("((GRGEN_LIBGR.IGraphElement)"); if(seqCall.TargetExpr != null) source.Append(GetSequenceExpression(seqCall.TargetExpr, source)); else source.Append(GetVar(seqCall.TargetVar)); source.Append(").ApplyProcedureMethod(procEnv, graph, "); source.Append("\"" + seqCall.ParamBindings.Name + "\""); source.Append(BuildParametersInObject(seqCall.ParamBindings)); source.Append(");\n"); for(int i = 0; i < seqCall.ParamBindings.ReturnVars.Length; i++) source.Append(SetVar(seqCall.ParamBindings.ReturnVars[i], tmpVarName)); } else { String returnParameterDeclarations; String returnArguments; String returnAssignments; BuildReturnParameters(seqCall.ParamBindings, TypesHelper.GetNodeOrEdgeType(type, model), out returnParameterDeclarations, out returnArguments, out returnAssignments); if(returnParameterDeclarations.Length != 0) source.AppendFront(returnParameterDeclarations + "\n"); source.AppendFront("(("); source.Append(TypesHelper.XgrsTypeToCSharpType(type, model)); source.Append(")"); if(seqCall.TargetExpr != null) source.Append(GetSequenceExpression(seqCall.TargetExpr, source)); else source.Append(GetVar(seqCall.TargetVar)); source.Append(")."); source.Append(seqCall.ParamBindings.Name); source.Append("(procEnv, graph"); source.Append(BuildParameters(seqCall.ParamBindings, TypesHelper.GetNodeOrEdgeType(type, model).GetProcedureMethod(seqCall.ParamBindings.Name))); source.Append(returnArguments); source.Append(");\n"); } source.AppendFront(SetResultVar(seqCall, "null")); break; } default: throw new Exception("Unknown sequence computation type: " + seqComp.SequenceComputationType); } }