void OnTypeInfotagsChanged(GrGenType type) { if (type.IsNodeType) { if (dumpInfo.IsExcludedNodeType((NodeType)type)) { return; } foreach (INode node in graph.GetExactNodes((NodeType)type)) { ycompStream.Write("setNodeLabel \"n" + dumpInfo.GetElementName(node) + "\" \"" + GetElemLabel(node) + "\"\n"); } } else { if (dumpInfo.IsExcludedEdgeType((EdgeType)type)) { return; } foreach (IEdge edge in graph.GetExactEdges((EdgeType)type)) { ycompStream.Write("setEdgeLabel \"e" + dumpInfo.GetElementName(edge) + "\" \"" + GetElemLabel(edge) + "\"\n"); } } isDirty = true; }
private Rule_testRule() { PatternNode node_p2 = new PatternNode((int) NodeTypes.@Process, "node_p2", node_p2_AllowedTypes, node_p2_IsAllowedType, PatternElementType.Normal, -1); PatternNode node_p1 = new PatternNode((int) NodeTypes.@Process, "node_p1", node_p1_AllowedTypes, node_p1_IsAllowedType, PatternElementType.Normal, -1); PatternEdge edge__edge0 = new PatternEdge(node_p1, node_p2, (int) EdgeTypes.@connection, "edge__edge0", edge__edge0_AllowedTypes, edge__edge0_IsAllowedType, PatternElementType.Normal, -1); patternGraph = new PatternGraph( new PatternNode[] { node_p2, node_p1 }, new PatternEdge[] { edge__edge0 }, new Condition[] { }, new bool[2, 2] { { true, false, }, { false, true, }, }, new bool[1, 1] { { true, }, }, new bool[] { false, false, }, new bool[] { false, } ); negativePatternGraphs = new PatternGraph[] {}; inputs = new GrGenType[] { }; outputs = new GrGenType[] { }; }
private Rule_testRule() { PatternNode node_p2 = new PatternNode((int)NodeTypes.@Process, "node_p2", node_p2_AllowedTypes, node_p2_IsAllowedType, PatternElementType.Normal, -1); PatternNode node_p1 = new PatternNode((int)NodeTypes.@Process, "node_p1", node_p1_AllowedTypes, node_p1_IsAllowedType, PatternElementType.Normal, -1); PatternEdge edge__edge0 = new PatternEdge(node_p1, node_p2, (int)EdgeTypes.@connection, "edge__edge0", edge__edge0_AllowedTypes, edge__edge0_IsAllowedType, PatternElementType.Normal, -1); patternGraph = new PatternGraph( new PatternNode[] { node_p2, node_p1 }, new PatternEdge[] { edge__edge0 }, new Condition[] { }, new bool[2, 2] { { true, false, }, { false, true, }, }, new bool[1, 1] { { true, }, }, new bool[] { false, false, }, new bool[] { false, } ); negativePatternGraphs = new PatternGraph[] {}; inputs = new GrGenType[] { }; outputs = new GrGenType[] { }; }
public static String TypeName(GrGenType type) { if (type is VarType) { Type typeOfVar = ((VarType)type).Type; if (typeOfVar.IsGenericType) { StringBuilder sb = new StringBuilder(); sb.Append(typeOfVar.FullName.Substring(0, typeOfVar.FullName.IndexOf('`'))); sb.Append('<'); bool first = true; foreach (Type typeArg in typeOfVar.GetGenericArguments()) { if (first) first = false; else sb.Append(", "); sb.Append(typeArg.FullName); } sb.Append('>'); return sb.ToString(); } return typeOfVar.FullName; } else { switch (type.Name) { case "Node": return "GRGEN_LIBGR.INode"; case "Edge": return "GRGEN_LIBGR.IEdge"; case "UEdge": return "GRGEN_LIBGR.IEdge"; case "AEdge": return "GRGEN_LIBGR.IEdge"; default: return "GRGEN_MODEL." + GetPackagePrefixDot(type.Package) + "I" + type.Name; } } }
public SubruleDebuggingConfigurationRule(SubruleDebuggingEvent sde, GrGenType graphElementType, bool only, SubruleDebuggingDecision sdd, SequenceExpression ifClause) { this.debuggingEvent = sde; this.typeToMatch = graphElementType; this.onlyThisType = only; this.decisionOnMatch = sdd; this.ifClause = ifClause; }
/// <summary> /// Constructs an EmbeddedSequenceInfo object. /// </summary> /// <param name="parameters">The names of the needed graph elements of the containing action.</param> /// <param name="parameterTypes">The types of the needed graph elements of the containing action.</param> /// <param name="outParameters">The names of the graph elements of the containing action yielded to.</param> /// <param name="outParameterTypes">The types of the graph elements of the containing action yielded to.</param> /// <param name="package">null if this is a global embedded sequence, otherwise the package the embedded sequence is contained in.</param> /// <param name="xgrs">The XGRS string.</param> /// <param name="lineNr">The line number the sequence appears on in the source.</param> public EmbeddedSequenceInfo(String[] parameters, GrGenType[] parameterTypes, String[] outParameters, GrGenType[] outParameterTypes, String package, String xgrs, int lineNr) { Parameters = parameters; ParameterTypes = parameterTypes; OutParameters = outParameters; OutParameterTypes = outParameterTypes; Package = package; XGRS = xgrs; LineNr = lineNr; }
/// <summary> /// Constructs a FunctionInfo object. /// </summary> /// <param name="name">The name the function was defined with.</param> /// <param name="package">null if this is a global pattern graph, otherwise the package the pattern graph is contained in.</param> /// <param name="packagePrefixedName">The name of the pattern graph in case of a global type, /// the name of the pattern graph is prefixed by the name of the package otherwise (package "::" name).</param> /// <param name="isExternal">Tells whether the function is an externally defined one or an internal one.</param> /// <param name="inputNames">The names of the input parameters.</param> /// <param name="inputs">The types of the input parameters.</param> /// <param name="output">The type of the output parameter.</param> public FunctionInfo(String name, String package, String packagePrefixedName, bool isExternal, String[] inputNames, GrGenType[] inputs, GrGenType output) { this.name = name; this.package = package; this.packagePrefixedName = packagePrefixedName; this.isExternal = isExternal; this.inputNames = inputNames; this.inputs = inputs; this.output = output; this.annotations = new Dictionary<String, String>(); }
/// <summary> /// Constructs a ProcedureInfo object. /// </summary> /// <param name="name">The name the procedure was defined with.</param> /// <param name="package">null if this is a global pattern graph, otherwise the package the pattern graph is contained in.</param> /// <param name="packagePrefixedName">The name of the pattern graph in case of a global type, /// the name of the pattern graph is prefixed by the name of the package otherwise (package "::" name).</param> /// <param name="isExternal">Tells whether the procedure is an externally defined one or an internal one.</param> /// <param name="inputNames">The names of the input parameters.</param> /// <param name="inputs">The types of the input parameters.</param> /// <param name="outputs">The types of the output parameters.</param> public ProcedureInfo(String name, String package, String packagePrefixedName, bool isExternal, String[] inputNames, GrGenType[] inputs, GrGenType[] outputs) { this.name = name; this.package = package; this.packagePrefixedName = packagePrefixedName; this.isExternal = isExternal; this.inputNames = inputNames; this.inputs = inputs; this.outputs = outputs; this.annotations = new Dictionary<String, String>(); this.ReturnArray = new object[outputs.Length]; }
private bool DetermineMatchGraphElementByType(SubruleDebuggingConfigurationRule cr, out GrGenType graphElementType) { while (true) { Console.WriteLine("Enter the type of the graph element to match."); if (cr != null) { Console.WriteLine("Empty string for " + cr.TypeToMatch.PackagePrefixedName); } else { Console.WriteLine("Empty string to abort."); } String graphElementTypeName = Console.ReadLine(); if (graphElementTypeName.Length == 0) { if (cr != null) { graphElementType = cr.TypeToMatch; break; } else { graphElementType = null; return(true); } } graphElementType = env.GetGraphElementType(graphElementTypeName); if (graphElementType == null) { Console.WriteLine("Unknown graph element type: " + graphElementTypeName); } else { break; } } return(false); }
private bool DetermineMatchGraphElementMode(SubruleDebuggingConfigurationRule cr, out string graphElementName, out GrGenType graphElementType, out bool only) { graphElementName = null; graphElementType = null; only = false; SubruleDebuggingMatchGraphElementMode mode = DetermineMatchGraphElementMode(cr); if (mode == SubruleDebuggingMatchGraphElementMode.Undefined) { return(true); } if (mode == SubruleDebuggingMatchGraphElementMode.ByName) { bool abort = DetermineMatchGraphElementByName(cr, out graphElementName); if (abort) { return(true); } } else { bool abort = DetermineMatchGraphElementByType(cr, out graphElementType); if (abort) { return(true); } SubruleDebuggingMatchGraphElementByTypeMode byTypeMode = DetermineMatchGraphElementByTypeMode(cr); if (byTypeMode == SubruleDebuggingMatchGraphElementByTypeMode.Undefined) { return(true); } } return(false); }
public void RetypingElement(IGraphElement oldElem, IGraphElement newElem) { bool isNode = oldElem is INode; GrGenType oldType = oldElem.Type; GrGenType newType = newElem.Type; // TODO: Add element, if old element was excluded, but new element is not if (isNode) { INode oldNode = (INode)oldElem; if (IsNodeExcluded(oldNode)) { return; } } else { IEdge oldEdge = (IEdge)oldElem; if (IsEdgeExcluded(oldEdge)) { return; } if (hiddenEdges.ContainsKey(oldEdge)) { return; // TODO: Update group relation } } String elemKind = isNode ? "Node" : "Edge"; String elemNamePrefix = isNode ? "n" : "e"; String oldName = elemNamePrefix + graph.GetElementName(oldElem); ycompStream.Write("set" + elemKind + "Label \"" + oldName + "\" \"" + GetElemLabel(newElem) + "\"\n"); // remove the old attributes foreach (AttributeType attrType in oldType.AttributeTypes) { String attrTypeString; String attrValueString; EncodeAttr(attrType, oldElem, out attrTypeString, out attrValueString); ycompStream.Write("clear" + elemKind + "Attr \"" + oldName + "\" \"" + attrType.OwnerType.Name + "::" + attrType.Name + " : " + attrTypeString + "\"\n"); } // set the new attributes foreach (AttributeType attrType in newType.AttributeTypes) { String attrTypeString; String attrValueString; EncodeAttr(attrType, newElem, out attrTypeString, out attrValueString); ycompStream.Write("change" + elemKind + "Attr \"" + oldName + "\" \"" + attrType.OwnerType.Name + "::" + attrType.Name + " : " + attrTypeString + "\" \"" + attrValueString + "\"\n"); } if (isNode) { String oldNr = realizers.GetNodeRealizer((NodeType)oldType, dumpInfo); String newNr = realizers.GetNodeRealizer((NodeType)newType, dumpInfo); if (oldNr != newNr) { ChangeNode((INode)oldElem, newNr); } } else { String oldEr = realizers.GetEdgeRealizer((EdgeType)oldType, dumpInfo); String newEr = realizers.GetEdgeRealizer((EdgeType)newType, dumpInfo); if (oldEr != newEr) { ChangeEdge((IEdge)oldElem, newEr); } } String newName = elemNamePrefix + graph.GetElementName(newElem); ycompStream.Write("rename" + elemKind + " \"" + oldName + "\" \"" + newName + "\"\n"); isDirty = true; }
/// <summary> /// Checks, whether this type is compatible to the given type, i.e. this type is the same type as the given type /// or it is a sub type of the given type. /// </summary> /// <param name="other">The type to be compared to.</param> /// <returns>True, if this type is compatible to the given type.</returns> public abstract bool IsA(GrGenType other);
private SubruleDebuggingConfigurationRule EditOrCreateRule(SubruleDebuggingConfigurationRule cr) { // edit or keep type SubruleDebuggingEvent sde = DetermineEventTypeToConfigure(cr); if (sde == SubruleDebuggingEvent.Undefined) { return(null); } // for Add, Rem, Emit, Halt, Highlight string message = null; SubruleMesssageMatchingMode smmm = SubruleMesssageMatchingMode.Undefined; // for Match IAction action = null; // for New, Delete, Retype, SetAttributes string graphElementName = null; GrGenType graphElementType = null; bool only = false; if (sde == SubruleDebuggingEvent.Add || sde == SubruleDebuggingEvent.Rem || sde == SubruleDebuggingEvent.Emit || sde == SubruleDebuggingEvent.Halt || sde == SubruleDebuggingEvent.Highlight) { // edit or keep message matching mode and message smmm = DetermineMessageAndMessageMatchingMode(cr, out message); if (smmm == SubruleMesssageMatchingMode.Undefined) { return(null); } } else if (sde == SubruleDebuggingEvent.Match) { // edit ok keep action name action = DetermineAction(cr); if (action == null) { return(null); } } else if (sde == SubruleDebuggingEvent.New || sde == SubruleDebuggingEvent.Delete || sde == SubruleDebuggingEvent.Retype || sde == SubruleDebuggingEvent.SetAttributes) { // edit or keep choice of type, exact type, name bool abort = DetermineMatchGraphElementMode(cr, out graphElementName, out graphElementType, out only); if (abort) { return(null); } } // edit or keep decision action SubruleDebuggingDecision sdd = DetermineDecisionAction(cr); if (sdd == SubruleDebuggingDecision.Undefined) { return(null); } // edit or keep condition if type action or graph change SequenceExpression ifClause = null; if (sde != SubruleDebuggingEvent.Add && sde != SubruleDebuggingEvent.Rem && sde != SubruleDebuggingEvent.Retype && sde != SubruleDebuggingEvent.Halt && sde != SubruleDebuggingEvent.Highlight) { ifClause = DetermineCondition(cr, sde, action, graphElementType); } if (sde == SubruleDebuggingEvent.Add || sde == SubruleDebuggingEvent.Rem || sde == SubruleDebuggingEvent.Emit || sde == SubruleDebuggingEvent.Halt || sde == SubruleDebuggingEvent.Highlight) { return(new SubruleDebuggingConfigurationRule(sde, message, smmm, sdd)); } else if (sde == SubruleDebuggingEvent.Match) { return(new SubruleDebuggingConfigurationRule(sde, action, sdd, ifClause)); } else if (sde == SubruleDebuggingEvent.New || sde == SubruleDebuggingEvent.Delete || sde == SubruleDebuggingEvent.Retype || sde == SubruleDebuggingEvent.SetAttributes) { if (graphElementName != null) { return(new SubruleDebuggingConfigurationRule(sde, graphElementName, sdd, ifClause)); } else { return(new SubruleDebuggingConfigurationRule(sde, graphElementType, only, sdd, ifClause)); } } return(null); }
/// <summary> /// Constructs an ExternalDefinedSequenceInfo object. /// </summary> /// <param name="parameters">The names of the graph elements needed from the calling action.</param> /// <param name="parameterTypes">The types of the graph elements needed from the calling action.</param> /// <param name="outParameters">The names of the graph elements returned to the calling action.</param> /// <param name="outParameterTypes">The types of the graph elements returned to the calling action.</param> /// <param name="name">The name the sequence was defined with.</param> /// <param name="lineNr">The line number the sequence appears on in the source.</param> public ExternalDefinedSequenceInfo(String[] parameters, GrGenType[] parameterTypes, String[] outParameters, GrGenType[] outParameterTypes, String name, int lineNr) : base(parameters, parameterTypes, outParameters, outParameterTypes, name, null, name, "", lineNr) { }
/// <summary> /// Returns true, if the graph element is compatible to the given type /// </summary> public bool InstanceOf(GrGenType otherType) { return(lgspType.IsA(otherType)); }
/// <summary> /// Returns true, if the graph element is compatible to the given type /// </summary> public bool InstanceOf(GrGenType otherType) { return lgspType.IsA(otherType); }
public bool GenerateXGRSCode(string xgrsName, String package, String xgrsStr, String[] paramNames, GrGenType[] paramTypes, String[] defToBeYieldedToNames, GrGenType[] defToBeYieldedToTypes, SourceBuilder source, int lineNr) { Dictionary<String, String> varDecls = new Dictionary<String, String>(); for (int i = 0; i < paramNames.Length; i++) { varDecls.Add(paramNames[i], TypesHelper.DotNetTypeToXgrsType(paramTypes[i])); } for(int i = 0; i < defToBeYieldedToNames.Length; i++) { varDecls.Add(defToBeYieldedToNames[i], TypesHelper.DotNetTypeToXgrsType(defToBeYieldedToTypes[i])); } Sequence seq; try { List<string> warnings = new List<string>(); seq = SequenceParser.ParseSequence(xgrsStr, package, ruleNames, sequenceNames, procedureNames, functionNames, functionOutputTypes, filterFunctionNames, varDecls, model, warnings); foreach(string warning in warnings) { Console.Error.WriteLine("The exec statement \"" + xgrsStr + "\" given on line " + lineNr + " reported back:\n" + warning); } seq.Check(env); seq.SetNeedForProfilingRecursive(gen.EmitProfiling); } catch(ParseException ex) { Console.Error.WriteLine("The exec statement \"" + xgrsStr + "\" given on line " + lineNr + " caused the following error:\n" + ex.Message); return false; } catch(SequenceParserException ex) { Console.Error.WriteLine("The exec statement \"" + xgrsStr + "\" given on line " + lineNr + " caused the following error:\n"); HandleSequenceParserException(ex); return false; } source.Append("\n"); source.AppendFront("public static bool ApplyXGRS_" + xgrsName + "(GRGEN_LGSP.LGSPGraphProcessingEnvironment procEnv"); for(int i = 0; i < paramNames.Length; i++) { source.Append(", " + TypesHelper.XgrsTypeToCSharpType(TypesHelper.DotNetTypeToXgrsType(paramTypes[i]), model) + " var_"); source.Append(paramNames[i]); } for(int i = 0; i < defToBeYieldedToTypes.Length; i++) { source.Append(", ref " + TypesHelper.XgrsTypeToCSharpType(TypesHelper.DotNetTypeToXgrsType(defToBeYieldedToTypes[i]), model) + " var_"); source.Append(defToBeYieldedToNames[i]); } source.Append(")\n"); source.AppendFront("{\n"); source.Indent(); source.AppendFront("GRGEN_LGSP.LGSPGraph graph = procEnv.graph;\n"); source.AppendFront("GRGEN_LGSP.LGSPActions actions = procEnv.curActions;\n"); knownRules.Clear(); if(gen.FireDebugEvents) { source.AppendFrontFormat("procEnv.DebugEntering(\"{0}\", \"{1}\");\n", InjectExec(xgrsName), xgrsStr.Replace("\\", "\\\\").Replace("\"", "\\\"")); } EmitNeededVarAndRuleEntities(seq, source); EmitSequence(seq, source); if(gen.FireDebugEvents) { source.AppendFrontFormat("procEnv.DebugExiting(\"{0}\");\n", InjectExec(xgrsName)); } source.AppendFront("return " + GetResultVar(seq) + ";\n"); source.Unindent(); source.AppendFront("}\n"); List<SequenceExpressionContainerConstructor> containerConstructors = new List<SequenceExpressionContainerConstructor>(); Dictionary<SequenceVariable, SetValueType> variables = new Dictionary<SequenceVariable, SetValueType>(); seq.GetLocalVariables(variables, containerConstructors, null); foreach(SequenceExpressionContainerConstructor cc in containerConstructors) { GenerateContainerConstructor(cc, source); } return true; }
private void BuildReturnParameters(ProcedureInvocationParameterBindings paramBindings, GrGenType ownerType, out String returnParameterDeclarations, out String returnArguments, out String returnAssignments) { // can't use the normal xgrs variables for return value receiving as the type of an out-parameter must be invariant // this is bullshit, as it is perfectly safe to assign a subtype to a variable of a supertype // so we create temporary variables of exact type, which are used to receive the return values, // and finally we assign these temporary variables to the real xgrs variables returnParameterDeclarations = ""; returnArguments = ""; returnAssignments = ""; for(int i = 0; i < ownerType.GetProcedureMethod(paramBindings.Name).Outputs.Length; i++) { String varName; if(paramBindings.ReturnVars.Length != 0) varName = tmpVarCtr.ToString() + paramBindings.ReturnVars[i].PureName; else varName = tmpVarCtr.ToString(); ++tmpVarCtr; String typeName = TypesHelper.DotNetTypeToXgrsType(ownerType.GetProcedureMethod(paramBindings.Name).Outputs[i]); returnParameterDeclarations += TypesHelper.XgrsTypeToCSharpType(typeName, model) + " tmpvar_" + varName + "; "; returnArguments += ", out tmpvar_" + varName; if(paramBindings.ReturnVars.Length != 0) returnAssignments += SetVar(paramBindings.ReturnVars[i], "tmpvar_" + varName); } }
protected abstract bool IsCalledEntityExisting(InvocationParameterBindings paramBindings, GrGenType ownerType);
protected abstract int NumOutputParameters(InvocationParameterBindings paramBindings, GrGenType ownerType);
/// <summary> /// Helper for checking function calls. /// Checks whether called entity exists, and type checks the input. /// Throws an exception when an error is found. /// </summary> /// <param name="seq">The sequence expression to check, must be a function call</param> /// <param name="ownerType">Gives the owner type of the function method call, in case this is a method call, otherwise null</param> private void CheckFunctionCallBase(SequenceExpression seq, GrGenType ownerType) { InvocationParameterBindings paramBindings = (seq as SequenceExpressionFunctionCall).ParamBindings; // check the name against the available names if(!IsCalledEntityExisting(paramBindings, ownerType)) throw new SequenceParserException(paramBindings, SequenceParserError.UnknownFunction); // Check whether number of parameters and return parameters match if(NumInputParameters(paramBindings, ownerType) != paramBindings.ArgumentExpressions.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); } } // ok, this is a well-formed invocation }
protected override string OutputParameterType(int i, InvocationParameterBindings paramBindings, GrGenType ownerType) { if(paramBindings is RuleInvocationParameterBindings) { RuleInvocationParameterBindings ruleParamBindings = (RuleInvocationParameterBindings)paramBindings; return rulesToOutputTypes[ruleParamBindings.PackagePrefixedName][i]; } else if(paramBindings is SequenceInvocationParameterBindings) { SequenceInvocationParameterBindings seqParamBindings = (SequenceInvocationParameterBindings)paramBindings; return sequencesToOutputTypes[seqParamBindings.PackagePrefixedName][i]; } else if(paramBindings is ProcedureInvocationParameterBindings) { ProcedureInvocationParameterBindings procParamBindings = (ProcedureInvocationParameterBindings)paramBindings; if(ownerType != null) return TypesHelper.DotNetTypeToXgrsType(ownerType.GetProcedureMethod(procParamBindings.Name).Outputs[i]); else return proceduresToOutputTypes[procParamBindings.PackagePrefixedName][i]; } throw new Exception("Internal error"); }
public void BuildReturnParameters(ProcedureInvocation invocation, SequenceVariable[] ReturnVars, GrGenType ownerType, out String returnParameterDeclarations, out String returnArguments, out String returnAssignments) { // can't use the normal xgrs variables for return value receiving as the type of an out-parameter must be invariant // this is bullshit, as it is perfectly safe to assign a subtype to a variable of a supertype // so we create temporary variables of exact type, which are used to receive the return values, // and finally we assign these temporary variables to the real xgrs variables returnParameterDeclarations = ""; returnArguments = ""; returnAssignments = ""; for (int i = 0; i < ownerType.GetProcedureMethod(invocation.Name).Outputs.Length; ++i) { String varName; if (ReturnVars.Length != 0) { varName = GetUniqueId() + ReturnVars[i].PureName; } else { varName = GetUniqueId(); } String typeName = TypesHelper.DotNetTypeToXgrsType(ownerType.GetProcedureMethod(invocation.Name).Outputs[i]); String tmpvarName = "tmpvar_" + varName; returnParameterDeclarations += TypesHelper.XgrsTypeToCSharpType(typeName, model) + " " + tmpvarName + "; "; returnArguments += ", out " + tmpvarName; if (ReturnVars.Length != 0) { returnAssignments += SetVar(ReturnVars[i], tmpvarName); } } }
private EntityType toBubbleUpYieldAssignmentType(GrGenType type) { if(type is VarType) return EntityType.Variable; else if(type is NodeType) return EntityType.Node; else //if(type is EdgeType) return EntityType.Edge; }
public static String DotNetTypeToXgrsType(GrGenType type) { if (type is VarType) { Type typeOfVar = ((VarType)type).Type; if (typeOfVar.IsGenericType) { if(typeOfVar.Name == "Dictionary`2") { Type keyType; Type valueType; ContainerHelper.GetDictionaryTypes(typeOfVar, out keyType, out valueType); if(valueType.Name == "SetValueType") return "set<" + DotNetTypeToXgrsType(keyType.Name, keyType.FullName) + ">"; else return "map<" + DotNetTypeToXgrsType(keyType.Name, keyType.FullName) + "," + DotNetTypeToXgrsType(valueType.Name, valueType.FullName) + ">"; } else if(typeOfVar.Name == "List`1") { Type valueType; ContainerHelper.GetListType(typeOfVar, out valueType); return "array<" + DotNetTypeToXgrsType(valueType.Name, valueType.FullName) + ">"; } else if(typeOfVar.Name == "Deque`1") { Type valueType; ContainerHelper.GetDequeType(typeOfVar, out valueType); return "deque<" + DotNetTypeToXgrsType(valueType.Name, valueType.FullName) + ">"; } } return DotNetTypeToXgrsType(type.Name, typeOfVar.FullName); } return type.PackagePrefixedName; }
protected String GetElemTypeID(GrGenType type) { return type.Name; }
//////////////////////////////////////////////////////////////////////////// /// <summary> /// Instantiates a new PatternElement object. /// </summary> /// <param name="typeID">The type ID of the pattern element.</param> /// <param name="typeName">The name of the type interface of the pattern element.</param> /// <param name="name">The name of the pattern element.</param> /// <param name="unprefixedName">Pure name of the pattern element as specified in the .grg without any prefixes</param> /// <param name="allowedTypes">An array of allowed types for this pattern element. /// If it is null, all subtypes of the type specified by typeID (including itself) /// are allowed for this pattern element.</param> /// <param name="isAllowedType">An array containing a bool for each node/edge type (order defined by the TypeIDs) /// which is true iff the corresponding type is allowed for this pattern element. /// It should be null if allowedTypes is null or empty or has only one element.</param> /// <param name="cost">Default cost/priority from frontend, user priority if given.</param> /// <param name="parameterIndex">Specifies to which rule parameter this pattern element corresponds.</param> /// <param name="maybeNull">Tells whether this pattern element may be null (is a parameter if true).</param> /// <param name="storage">If not null this pattern element is to be bound by iterating the given storage.</param> /// <param name="storageIndex">If not null this pattern element is to be determined by a storage lookup, /// with the accessor given here applied as index into the storage given in the storage parameter.</param> /// <param name="indexAccess">If not null this pattern element is to be determined by an index lookup, with details specified by the concrete index access type contained in this field.</param> /// <param name="nameLookup">If not null this pattern element is to be determined by a name map lookup.</param> /// <param name="uniqueLookup">If not null this pattern element is to be determined by a unique index lookup.</param> /// <param name="elementBeforeCasting">If not null this pattern node is to be bound by casting the given elementBeforeCasting to the pattern node type or causing matching to fail.</param> /// <param name="defToBeYieldedTo">Iff true the element is only defined in its PointOfDefinition pattern, /// it gets matched in another, nested or called pattern which yields it to the containing pattern.</param> /// <param name="initialization">The initialization expression for the element if some was defined, /// only possible for defToBeYieldedTo elements, otherwise null.</param> public PatternElement(int typeID, String typeName, String name, String unprefixedName, GrGenType[] allowedTypes, bool[] isAllowedType, float cost, int parameterIndex, bool maybeNull, StorageAccess storage, StorageAccessIndex storageIndex, IndexAccess indexAccess, NameLookup nameLookup, UniqueLookup uniqueLookup, PatternElement elementBeforeCasting, bool defToBeYieldedTo, Expression initialization) { this.TypeID = typeID; this.typeName = typeName; this.name = name; this.unprefixedName = unprefixedName; this.AllowedTypes = allowedTypes; this.IsAllowedType = isAllowedType; this.Cost = cost; this.ParameterIndex = parameterIndex; this.MaybeNull = maybeNull; this.Storage = storage; this.StorageIndex = storageIndex; this.IndexAccess = indexAccess; this.NameLookup = nameLookup; this.UniqueLookup = uniqueLookup; this.ElementBeforeCasting = elementBeforeCasting; this.defToBeYieldedTo = defToBeYieldedTo; this.initialization = initialization; // TODO: the last parameters are (mostly) mutually exclusive, // introduce some abstract details class with specialized classed for the different cases, // only one instance needed instead of the large amount of mostly null valued variables now // better now with the introduction of helper classes for StorageAccess and StorageAccessIndex, but could be improved further }
public override bool IsA(GrGenType other) { return (this == other) || isA[other.TypeID]; }
/// <summary> /// Determines which homomorphy check operations are necessary /// at the operation of the given position within the scheduled search plan /// and appends them. /// </summary> private static void DetermineAndAppendHomomorphyChecks(IGraphModel model, ScheduledSearchPlan ssp, int j) { // take care of global homomorphy FillInGlobalHomomorphyPatternElements(ssp, j); /////////////////////////////////////////////////////////////////////////// // first handle special case pure homomorphy SearchPlanNode spn_j = (SearchPlanNode)ssp.Operations[j].Element; if (spn_j.ElementID == -1) { // inlined from independent for better matching, independent from the rest return; } bool homToAll = true; if (spn_j.NodeType == PlanNodeType.Node) { for (int i = 0; i < ssp.PatternGraph.nodesPlusInlined.Length; ++i) { if (!ssp.PatternGraph.homomorphicNodes[spn_j.ElementID - 1, i]) { homToAll = false; break; } } } else //(spn_j.NodeType == PlanNodeType.Edge) { for (int i = 0; i < ssp.PatternGraph.edgesPlusInlined.Length; ++i) { if (!ssp.PatternGraph.homomorphicEdges[spn_j.ElementID - 1, i]) { homToAll = false; break; } } } if (homToAll) { // operation is allowed to be homomorph with everything // no checks for isomorphy or restricted homomorphy needed at all return; } /////////////////////////////////////////////////////////////////////////// // no pure homomorphy, so we have restricted homomorphy or isomorphy // and need to inspect the operations before, together with the homomorphy matrix // for determining the necessary homomorphy checks GrGenType[] types; bool[,] hom; if (spn_j.NodeType == PlanNodeType.Node) { types = model.NodeModel.Types; hom = ssp.PatternGraph.homomorphicNodes; } else // (spn_j.NodeType == PlanNodeType.Edge) { types = model.EdgeModel.Types; hom = ssp.PatternGraph.homomorphicEdges; } // order operation to check against all elements it's not allowed to be homomorph to // iterate through the operations before our position bool homomorphyPossibleAndAllowed = false; for (int i = 0; i < j; ++i) { // only check operations computing nodes or edges if (ssp.Operations[i].Type == SearchOperationType.Condition || ssp.Operations[i].Type == SearchOperationType.NegativePattern || ssp.Operations[i].Type == SearchOperationType.IndependentPattern || ssp.Operations[i].Type == SearchOperationType.Assign || ssp.Operations[i].Type == SearchOperationType.AssignVar || ssp.Operations[i].Type == SearchOperationType.DefToBeYieldedTo || ssp.Operations[i].Type == SearchOperationType.InlinedIndependentCheckForDuplicateMatch) { continue; } SearchPlanNode spn_i = (SearchPlanNode)ssp.Operations[i].Element; if (spn_i.NodeType != spn_j.NodeType) { // don't compare nodes with edges continue; } if (spn_i.ElementID == -1) { // inlined from independent for better matching, independent from the rest continue; } // find out whether element types are disjoint GrGenType type_i = types[spn_i.PatternElement.TypeID]; GrGenType type_j = types[spn_j.PatternElement.TypeID]; bool disjoint = true; foreach (GrGenType subtype_i in type_i.SubOrSameTypes) { if (type_j.IsA(subtype_i) || subtype_i.IsA(type_j)) // IsA==IsSuperTypeOrSameType { disjoint = false; break; } } if (disjoint) { // don't check elements if their types are disjoint continue; } // at this position we found out that spn_i and spn_j // might get matched to the same host graph element, i.e. homomorphy is possible // if that's ok we don't need to insert checks to prevent this from happening if (hom[spn_i.ElementID - 1, spn_j.ElementID - 1]) { homomorphyPossibleAndAllowed = true; continue; } // otherwise the generated matcher code has to check // that pattern element j doesn't get bound to the same graph element // the pattern element i is already bound to if (ssp.Operations[j].Isomorphy.PatternElementsToCheckAgainst == null) { ssp.Operations[j].Isomorphy.PatternElementsToCheckAgainst = new List <SearchPlanNode>(); } ssp.Operations[j].Isomorphy.PatternElementsToCheckAgainst.Add(spn_i); // if spn_j might get matched to the same host graph element as spn_i and this is not allowed // make spn_i set the is-matched-bit so that spn_j can detect this situation ssp.Operations[i].Isomorphy.SetIsMatchedBit = true; } // only if elements, the operation must be isomorph to, were matched before // (otherwise there were only elements, the operation is allowed to be homomorph to, // matched before, so no check needed here) if (ssp.Operations[j].Isomorphy.PatternElementsToCheckAgainst != null && ssp.Operations[j].Isomorphy.PatternElementsToCheckAgainst.Count > 0) { // order operation to check whether the is-matched-bit is set ssp.Operations[j].Isomorphy.CheckIsMatchedBit = true; } // if no check for isomorphy was skipped due to homomorphy being allowed // pure isomorphy is to be guaranteed - simply check the is-matched-bit and be done // the pattern elements to check against are only needed // if spn_j is allowed to be homomorph to some elements but must be isomorph to some others if (ssp.Operations[j].Isomorphy.CheckIsMatchedBit && !homomorphyPossibleAndAllowed) { ssp.Operations[j].Isomorphy.PatternElementsToCheckAgainst = null; } }
public override bool IsA(GrGenType other) { return((this == other) || isA[other.TypeID]); }
public override bool IsA(GrGenType other) { return other is VirtualNodeType; }
protected abstract string OutputParameterType(int i, InvocationParameterBindings paramBindings, GrGenType ownerType);
/// <summary> /// Constructs an DefinedSequenceInfo object. /// </summary> /// <param name="parameters">The names of the graph elements needed from the calling action.</param> /// <param name="parameterTypes">The types of the graph elements needed from the calling action.</param> /// <param name="outParameters">The names of the graph elements returned to the calling action.</param> /// <param name="outParameterTypes">The types of the graph elements returned to the calling action.</param> /// <param name="name">The name the sequence was defined with.</param> /// <param name="package">null if this is a global sequence, otherwise the package the sequence is contained in.</param> /// <param name="packagePrefixedName">The name of the type in case of a global type, /// the name of the type prefixed by the name of the package otherwise.</param> /// <param name="xgrs">The XGRS string.</param> /// <param name="lineNr">The line number the sequence appears on in the source.</param> public DefinedSequenceInfo(String[] parameters, GrGenType[] parameterTypes, String[] outParameters, GrGenType[] outParameterTypes, String name, String package, String packagePrefixedName, String xgrs, int lineNr) : base(parameters, parameterTypes, outParameters, outParameterTypes, package, xgrs, lineNr) { Name = name; PackagePrefixedName = packagePrefixedName; annotations = new Dictionary<String, String>(); }
private SequenceExpression DetermineCondition(SubruleDebuggingConfigurationRule cr, SubruleDebuggingEvent sde, IAction action, GrGenType graphElementType) { // edit or keep condition if type action or graph change do { Console.WriteLine("Conditional rule via sequence expression?"); if (cr != null && cr.IfClause != null) { Console.WriteLine("Press enter to take over " + cr.IfClause.Symbol + ", enter \"-\" to clear the condition, otherwise enter the sequence expression to apply."); } else { Console.WriteLine("Press enter if you don't want to add an if part, otherwise enter the sequence expression to apply."); } String ifClauseStr = Console.ReadLine(); if (ifClauseStr.Length == 0) { if (cr != null) { return(cr.IfClause); } else { return(null); } } if (ifClauseStr == "-") { return(null); } Dictionary <String, String> predefinedVariables = new Dictionary <String, String>(); predefinedVariables.Add("this", ""); string ruleOfMatchThis = null; if (sde == SubruleDebuggingEvent.Match) { ruleOfMatchThis = action.Name; } string typeOfGraphElementThis = null; if (sde == SubruleDebuggingEvent.New || sde == SubruleDebuggingEvent.Delete || sde == SubruleDebuggingEvent.Retype || sde == SubruleDebuggingEvent.SetAttributes) { typeOfGraphElementThis = ""; if (graphElementType != null) { typeOfGraphElementThis = graphElementType.PackagePrefixedName; } } try { SequenceParserEnvironmentInterpretedDebugEventCondition parserEnv = new SequenceParserEnvironmentInterpretedDebugEventCondition(shellProcEnv.ProcEnv.Actions, ruleOfMatchThis, typeOfGraphElementThis); List <String> warnings = new List <String>(); SequenceExpression ifClause = SequenceParser.ParseSequenceExpression(ifClauseStr, predefinedVariables, parserEnv, warnings); foreach (string warning in warnings) { Console.WriteLine("The sequence expression for the if clause reported back: " + warning); } return(ifClause); } catch (SequenceParserException ex) { Console.WriteLine("Unable to parse sequence expression"); env.HandleSequenceParserException(ex); } catch (de.unika.ipd.grGen.libGr.sequenceParser.ParseException ex) { Console.WriteLine("Unable to parse sequence expression: " + ex.Message); } catch (Exception ex) { Console.WriteLine("Unable to parse sequence expression : " + ex); } }while(true); }
protected override bool IsCalledEntityExisting(InvocationParameterBindings paramBindings, GrGenType ownerType) { if(paramBindings is RuleInvocationParameterBindings) { RuleInvocationParameterBindings ruleParamBindings = (RuleInvocationParameterBindings)paramBindings; return ruleParamBindings.Action != null; } else if(paramBindings is SequenceInvocationParameterBindings) { SequenceInvocationParameterBindings seqParamBindings = (SequenceInvocationParameterBindings)paramBindings; return seqParamBindings.SequenceDef != null; } else if(paramBindings is ProcedureInvocationParameterBindings) { ProcedureInvocationParameterBindings procParamBindings = (ProcedureInvocationParameterBindings)paramBindings; if(ownerType != null) return ownerType.GetProcedureMethod(procParamBindings.Name) != null; else return procParamBindings.ProcedureDef != null; } else if(paramBindings is FunctionInvocationParameterBindings) { FunctionInvocationParameterBindings funcParamBindings = (FunctionInvocationParameterBindings)paramBindings; if(ownerType != null) return ownerType.GetFunctionMethod(funcParamBindings.Name) != null; else return funcParamBindings.FunctionDef != null; } throw new Exception("Internal error"); }
protected override int NumOutputParameters(InvocationParameterBindings paramBindings, GrGenType ownerType) { if(paramBindings is RuleInvocationParameterBindings) { RuleInvocationParameterBindings ruleParamBindings = (RuleInvocationParameterBindings)paramBindings; return ruleParamBindings.Action.RulePattern.Outputs.Length; } else if(paramBindings is SequenceInvocationParameterBindings) { SequenceInvocationParameterBindings seqParamBindings = (SequenceInvocationParameterBindings)paramBindings; if(seqParamBindings.SequenceDef is SequenceDefinitionInterpreted) { SequenceDefinitionInterpreted seqDef = (SequenceDefinitionInterpreted)seqParamBindings.SequenceDef; return seqDef.OutputVariables.Length; } else { SequenceDefinitionCompiled seqDef = (SequenceDefinitionCompiled)seqParamBindings.SequenceDef; return seqDef.SeqInfo.OutParameterTypes.Length; } } else if(paramBindings is ProcedureInvocationParameterBindings) { ProcedureInvocationParameterBindings procParamBindings = (ProcedureInvocationParameterBindings)paramBindings; if(ownerType != null) return ownerType.GetProcedureMethod(procParamBindings.Name).Outputs.Length; else return procParamBindings.ProcedureDef.Outputs.Length; } throw new Exception("Internal error"); }
protected override string OutputParameterType(int i, InvocationParameterBindings paramBindings, GrGenType ownerType) { if(paramBindings is RuleInvocationParameterBindings) { RuleInvocationParameterBindings ruleParamBindings = (RuleInvocationParameterBindings)paramBindings; return TypesHelper.DotNetTypeToXgrsType(ruleParamBindings.Action.RulePattern.Outputs[i]); } else if(paramBindings is SequenceInvocationParameterBindings) { SequenceInvocationParameterBindings seqParamBindings = (SequenceInvocationParameterBindings)paramBindings; if(seqParamBindings.SequenceDef is SequenceDefinitionInterpreted) { SequenceDefinitionInterpreted seqDef = (SequenceDefinitionInterpreted)seqParamBindings.SequenceDef; return seqDef.OutputVariables[i].Type; } else { SequenceDefinitionCompiled seqDef = (SequenceDefinitionCompiled)seqParamBindings.SequenceDef; return TypesHelper.DotNetTypeToXgrsType(seqDef.SeqInfo.OutParameterTypes[i]); } } else if(paramBindings is ProcedureInvocationParameterBindings) { ProcedureInvocationParameterBindings procParamBindings = (ProcedureInvocationParameterBindings)paramBindings; if(ownerType != null) return TypesHelper.DotNetTypeToXgrsType(ownerType.GetProcedureMethod(procParamBindings.Name).Outputs[i]); else return TypesHelper.DotNetTypeToXgrsType(procParamBindings.ProcedureDef.Outputs[i]); } throw new Exception("Internal error"); }
void OnTypeInfotagsChanged(GrGenType type) { if(type.IsNodeType) { if(dumpInfo.IsExcludedNodeType((NodeType) type)) return; foreach(INode node in graph.GetExactNodes((NodeType) type)) ycompStream.Write("setNodeLabel \"n" + dumpInfo.GetElementName(node) + "\" \"" + GetElemLabel(node) + "\"\n"); } else { if(dumpInfo.IsExcludedEdgeType((EdgeType) type)) return; foreach(IEdge edge in graph.GetExactEdges((EdgeType) type)) { if(IsEdgeExcluded(edge)) return; // additionally checks incident nodes ycompStream.Write("setEdgeLabel \"e" + dumpInfo.GetElementName(edge) + "\" \"" + GetElemLabel(edge) + "\"\n"); } } isDirty = true; }
protected override bool IsCalledEntityExisting(InvocationParameterBindings paramBindings, GrGenType ownerType) { // besides determining whether the called entity exists, this function // resolves pre- and context packages to packages, i.e. calls of entities from packages // without package prefix are changed to package calls (may occur for entities from the same package) if(paramBindings is RuleInvocationParameterBindings) { RuleInvocationParameterBindings ruleParamBindings = (RuleInvocationParameterBindings)paramBindings; if(ruleParamBindings.PrePackage != null) { ruleParamBindings.Package = ruleParamBindings.PrePackage; ruleParamBindings.PackagePrefixedName = ruleParamBindings.PrePackage + "::" + ruleParamBindings.Name; return Array.IndexOf(ruleNames, ruleParamBindings.PrePackage + "::" + ruleParamBindings.Name) != -1; } else { if(Array.IndexOf(ruleNames, ruleParamBindings.Name) != -1) { ruleParamBindings.Package = null; ruleParamBindings.PackagePrefixedName = ruleParamBindings.Name; return true; } if(ruleParamBindings.PrePackageContext != null) { ruleParamBindings.Package = ruleParamBindings.PrePackageContext; ruleParamBindings.PackagePrefixedName = ruleParamBindings.PrePackageContext + "::" + ruleParamBindings.Name; return Array.IndexOf(ruleNames, ruleParamBindings.PrePackageContext + "::" + ruleParamBindings.Name) != -1; } return false; } } else if(paramBindings is SequenceInvocationParameterBindings) { SequenceInvocationParameterBindings seqParamBindings = (SequenceInvocationParameterBindings)paramBindings; if(seqParamBindings.PrePackage != null) { seqParamBindings.Package = seqParamBindings.PrePackage; seqParamBindings.PackagePrefixedName = seqParamBindings.PrePackage + "::" + seqParamBindings.Name; return Array.IndexOf(sequenceNames, seqParamBindings.PrePackage + "::" + seqParamBindings.Name) != -1; } else { if(Array.IndexOf(sequenceNames, seqParamBindings.Name) != -1) { seqParamBindings.Package = null; seqParamBindings.PackagePrefixedName = seqParamBindings.Name; return true; } if(seqParamBindings.PrePackageContext != null) { seqParamBindings.Package = seqParamBindings.PrePackageContext; seqParamBindings.PackagePrefixedName = seqParamBindings.PrePackageContext + "::" + seqParamBindings.Name; return Array.IndexOf(sequenceNames, seqParamBindings.PrePackageContext + "::" + seqParamBindings.Name) != -1; } return false; } } else if(paramBindings is ProcedureInvocationParameterBindings) { ProcedureInvocationParameterBindings procParamBindings = (ProcedureInvocationParameterBindings)paramBindings; if(ownerType != null) { return ownerType.GetProcedureMethod(procParamBindings.Name) != null; } else { if(procParamBindings.PrePackage != null) { procParamBindings.Package = procParamBindings.PrePackage; procParamBindings.PackagePrefixedName = procParamBindings.PrePackage + "::" + procParamBindings.Name; return Array.IndexOf(procedureNames, procParamBindings.PrePackage + "::" + procParamBindings.Name) != -1; } else { if(Array.IndexOf(procedureNames, procParamBindings.Name) != -1) { procParamBindings.Package = null; procParamBindings.PackagePrefixedName = procParamBindings.Name; return true; } if(procParamBindings.PrePackageContext != null) { procParamBindings.Package = procParamBindings.PrePackageContext; procParamBindings.PackagePrefixedName = procParamBindings.PrePackageContext + "::" + procParamBindings.Name; return Array.IndexOf(procedureNames, procParamBindings.PrePackageContext + "::" + procParamBindings.Name) != -1; } return false; } } } else if(paramBindings is FunctionInvocationParameterBindings) { FunctionInvocationParameterBindings funcParamBindings = (FunctionInvocationParameterBindings)paramBindings; if(ownerType != null) { return ownerType.GetFunctionMethod(funcParamBindings.Name) != null; } else { if(funcParamBindings.PrePackage != null) { funcParamBindings.Package = funcParamBindings.PrePackage; funcParamBindings.PackagePrefixedName = funcParamBindings.PrePackage + "::" + funcParamBindings.Name; return Array.IndexOf(functionNames, funcParamBindings.PrePackage + "::" + funcParamBindings.Name) != -1; } else { if(Array.IndexOf(functionNames, funcParamBindings.Name) != -1) { funcParamBindings.Package = null; funcParamBindings.PackagePrefixedName = funcParamBindings.Name; return true; } if(funcParamBindings.PrePackageContext != null) { funcParamBindings.Package = funcParamBindings.PrePackageContext; funcParamBindings.PackagePrefixedName = funcParamBindings.PrePackageContext + "::" + funcParamBindings.Name; return Array.IndexOf(functionNames, funcParamBindings.PrePackageContext + "::" + funcParamBindings.Name) != -1; } return false; } } } throw new Exception("Internal error"); }
/// <summary> /// Instantiates a new PatternEdge object /// </summary> /// <param name="fixedDirection">Whether this pattern edge should be matched with a fixed direction or not.</param> /// <param name="typeID">The type ID of the pattern edge.</param> /// <param name="type">The GrGen type of the pattern edge.</param> /// <param name="typeName">The name of the type interface of the pattern element.</param> /// <param name="name">The name of the pattern edge.</param> /// <param name="unprefixedName">Pure name of the pattern element as specified in the .grg without any prefixes</param> /// <param name="allowedTypes">An array of allowed types for this pattern element. /// If it is null, all subtypes of the type specified by typeID (including itself) /// are allowed for this pattern element.</param> /// <param name="isAllowedType">An array containing a bool for each edge type (order defined by the TypeIDs) /// which is true iff the corresponding type is allowed for this pattern element. /// It should be null if allowedTypes is null or empty or has only one element.</param> /// <param name="cost"> default cost/priority from frontend, user priority if given</param> /// <param name="parameterIndex">Specifies to which rule parameter this pattern element corresponds</param> /// <param name="maybeNull">Tells whether this pattern edge may be null (is a parameter if true).</param> /// <param name="storage">If not null this edge is to be bound by iterating the given storage.</param> /// <param name="storageIndex">If not null this edge is to be determined by a storage lookup, /// with the accessor given here applied as index into the storage given in the storage parameter.</param> /// <param name="indexAccess">If not null this pattern element is to be determined by an index lookup, with details specified by the concrete index access type contained in this field.</param> /// <param name="nameLookup">If not null this pattern element is to be determined by a name map lookup.</param> /// <param name="uniqueLookup">If not null this pattern element is to be determined by a unique index lookup.</param> /// <param name="elementBeforeCasting">If not null this pattern node is to be bound by casting the given elementBeforeCasting to the pattern node type or causing matching to fail.</param> /// <param name="defToBeYieldedTo">Iff true the element is only defined in its PointOfDefinition pattern, /// it gets matched in another, nested or called pattern which yields it to the containing pattern.</param> /// <param name="initialization">The initialization expression for the edge if some was defined, /// only possible for defToBeYieldedTo edges, otherwise null.</param> public PatternEdge(bool fixedDirection, int typeID, EdgeType type, String typeName, String name, String unprefixedName, GrGenType[] allowedTypes, bool[] isAllowedType, float cost, int parameterIndex, bool maybeNull, StorageAccess storage, StorageAccessIndex storageIndex, IndexAccess indexAccess, NameLookup nameLookup, UniqueLookup uniqueLookup, PatternElement elementBeforeCasting, bool defToBeYieldedTo, Expression initialization) : base(typeID, typeName, name, unprefixedName, allowedTypes, isAllowedType, cost, parameterIndex, maybeNull, storage, storageIndex, indexAccess, nameLookup, uniqueLookup, elementBeforeCasting, defToBeYieldedTo, initialization) { this.fixedDirection = fixedDirection; this.type = type; }
protected override int NumOutputParameters(InvocationParameterBindings paramBindings, GrGenType ownerType) { if(paramBindings is RuleInvocationParameterBindings) { RuleInvocationParameterBindings ruleParamBindings = (RuleInvocationParameterBindings)paramBindings; return rulesToOutputTypes[ruleParamBindings.PackagePrefixedName].Count; } else if(paramBindings is SequenceInvocationParameterBindings) { SequenceInvocationParameterBindings seqParamBindings = (SequenceInvocationParameterBindings)paramBindings; return sequencesToOutputTypes[seqParamBindings.PackagePrefixedName].Count; } else if(paramBindings is ProcedureInvocationParameterBindings) { ProcedureInvocationParameterBindings procParamBindings = (ProcedureInvocationParameterBindings)paramBindings; if(ownerType != null) return ownerType.GetProcedureMethod(procParamBindings.Name).Outputs.Length; else return proceduresToOutputTypes[procParamBindings.PackagePrefixedName].Count; } throw new Exception("Internal error"); }
public void RetypingElement(IGraphElement oldElem, IGraphElement newElem) { bool isNode = oldElem is INode; GrGenType oldType = oldElem.Type; GrGenType newType = newElem.Type; if (isNode) { if (dumpInfo.IsExcludedNodeType((NodeType)oldType)) { return; } } else { if (dumpInfo.IsExcludedEdgeType((EdgeType)oldType)) { return; } } String elemKind = isNode ? "Node" : "Edge"; String elemNamePrefix = isNode ? "n" : "e"; String name = elemNamePrefix + graph.GetElementName(oldElem); ycompStream.Write("set" + elemKind + "Label \"" + name + "\" \"" + GetElemLabel(newElem) + "\"\n"); // remove the old attributes foreach (AttributeType attrType in oldType.AttributeTypes) { ycompStream.Write("clear" + elemKind + "Attr \"" + name + "\" \"" + attrType.OwnerType.Name + "::" + attrType.Name + " : " + GetKindName(attrType) + "\"\n"); } // set the new attributes foreach (AttributeType attrType in newType.AttributeTypes) { object attr = newElem.GetAttribute(attrType.Name); String attrString = (attr != null) ? attr.ToString() : "<Not initialized>"; ycompStream.Write("change" + elemKind + "Attr \"" + name + "\" \"" + attrType.OwnerType.Name + "::" + attrType.Name + " : " + GetKindName(attrType) + "\" \"" + attrString + "\"\n"); } if (isNode) { String oldNr = GetNodeRealizer((NodeType)oldType); String newNr = GetNodeRealizer((NodeType)newType); if (oldNr != newNr) { ChangeNode((INode)oldElem, newNr); } } else { String oldEr = GetEdgeRealizer((EdgeType)oldType); String newEr = GetEdgeRealizer((EdgeType)newType); if (oldEr != newEr) { ChangeEdge((IEdge)oldElem, newEr); } } isDirty = true; }
public bool InstanceOf(GrGenType type) { return type is VirtualNodeType; }