Ejemplo n.º 1
0
        public override void Dump(SourceBuilder builder)
        {
            // first dump check
            builder.AppendFront("CheckCandidate ForType ");
            if (Type == CheckCandidateForTypeType.ByIsAllowedType)
            {
                builder.Append("ByIsAllowedType ");
                builder.AppendFormat("on {0} in {1} node:{2}\n",
                                     PatternElementName, RulePatternTypeName, IsNode);
            }
            else if (Type == CheckCandidateForTypeType.ByIsMyType)
            {
                builder.Append("ByIsMyType ");
                builder.AppendFormat("on {0} in {1} node:{2}\n",
                                     PatternElementName, TypeName, IsNode);
            }
            else // Type == CheckCandidateForTypeType.ByTypeID
            {
                builder.Append("ByTypeID ");
                builder.AppendFormat("on {0} ids:{1} node:{2}\n",
                                     PatternElementName, string.Join(",", TypeIDs), IsNode);
            }

            // then operations for case check failed
            if (CheckFailedOperations != null)
            {
                builder.Indent();
                CheckFailedOperations.Dump(builder);
                builder.Unindent();
            }
        }
Ejemplo n.º 2
0
 public override void Dump(SourceBuilder builder)
 {
     // first dump check
     builder.AppendFront("CheckCandidate ForIsomorphy ");
     builder.AppendFormat("on {0} negNamePrefix:{1} node:{2} ",
                          PatternElementName, NegativeIndependentNamePrefix, IsNode);
     if (NamesOfPatternElementsToCheckAgainst != null)
     {
         builder.Append("against ");
         foreach (string name in NamesOfPatternElementsToCheckAgainst)
         {
             builder.AppendFormat("{0} ", name);
         }
     }
     builder.AppendFormat("parallel:{0} first for all:{1} ",
                          Parallel, LockForAllThreads);
     builder.Append("\n");
     // then operations for case check failed
     if (CheckFailedOperations != null)
     {
         builder.Indent();
         CheckFailedOperations.Dump(builder);
         builder.Unindent();
     }
 }
Ejemplo n.º 3
0
        public override void Emit(SourceBuilder sourceCode)
        {
            // open decision whether to fail
            sourceCode.AppendFront("if(");

            // fail if graph element contained within candidate was already matched
            // (previously on the pattern derivation path to another pattern element)
            // as this would cause a inter-pattern-homomorphic match
            string variableContainingCandidate = NamesOfEntities.CandidateVariable(PatternElementName);
            string isMatchedBySomeBit          = "(uint)GRGEN_LGSP.LGSPElemFlags.IS_MATCHED_BY_SOME_ENCLOSING_PATTERN";

            if (!Always)
            {
                sourceCode.Append("searchPatternpath && ");
            }

            sourceCode.AppendFormat("({0}.lgspFlags & {1})=={1} && GRGEN_LGSP.PatternpathIsomorphyChecker.IsMatched({0}, {2})",
                                    variableContainingCandidate, isMatchedBySomeBit, LastMatchAtPreviousNestingLevel);

            sourceCode.Append(")\n");

            // emit check failed code
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();
            CheckFailedOperations.Emit(sourceCode);
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
Ejemplo n.º 4
0
        public override void Emit(SourceBuilder sourceCode)
        {
            // emit initialization with element mapped from storage
            string variableContainingStorage       = NamesOfEntities.Variable(StorageName);
            string variableContainingSourceElement = NamesOfEntities.CandidateVariable(SourcePatternElementName);
            string tempVariableForMapResult        = NamesOfEntities.MapWithStorageTemporary(PatternElementName);

            sourceCode.AppendFrontFormat("if(!{0}.TryGetValue(({1}){2}, out {3})) ",
                                         variableContainingStorage, StorageKeyTypeName,
                                         variableContainingSourceElement, tempVariableForMapResult);

            // emit check failed code
            sourceCode.Append("{\n");
            sourceCode.Indent();
            CheckFailedOperations.Emit(sourceCode);
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");

            // assign the value to the candidate variable, cast it to the variable type
            string typeOfVariableContainingCandidate = "GRGEN_LGSP."
                                                       + (IsNode ? "LGSPNode" : "LGSPEdge");
            string variableContainingCandidate = NamesOfEntities.CandidateVariable(PatternElementName);

            sourceCode.AppendFrontFormat("{0} = ({1}){2};\n",
                                         variableContainingCandidate, typeOfVariableContainingCandidate, tempVariableForMapResult);
        }
Ejemplo n.º 5
0
        public override void Dump(SourceBuilder builder)
        {
            // first dump check
            if (Type == CheckMaximumMatchesType.Action)
            {
                builder.AppendFront("CheckContinueMatching MaximumMatchesReached at Action level ");
            }
            else if (Type == CheckMaximumMatchesType.Subpattern)
            {
                builder.AppendFront("CheckContinueMatching MaximumMatchesReached at Subpattern level ");
            }
            else if (Type == CheckMaximumMatchesType.Iterated)
            {
                builder.AppendFront("CheckContinueMatching MaximumMatchesReached if Iterated ");
            }
            if (ListHeadAdjustment)
            {
                builder.Append("ListHeadAdjustment ");
            }
            if (InParallelizedBody)
            {
                builder.Append("InParallelizedBody ");
            }
            builder.Append("\n");

            // then operations for case check failed
            if (CheckFailedOperations != null)
            {
                builder.Indent();
                CheckFailedOperations.Dump(builder);
                builder.Unindent();
            }
        }
Ejemplo n.º 6
0
        public override void Emit(SourceBuilder sourceCode)
        {
            if (IsIterationBreaking)
            {
                sourceCode.AppendFront("breakIteration = true;\n");
            }

            CheckFailedOperations.Emit(sourceCode);
        }
Ejemplo n.º 7
0
 public override void Dump(SourceBuilder builder)
 {
     // first dump check
     builder.AppendFront("CheckPartialMatch ForSubpatternsFound\n");
     // then operations for case check failed
     if (CheckFailedOperations != null)
     {
         builder.Indent();
         CheckFailedOperations.Dump(builder);
         builder.Unindent();
     }
 }
Ejemplo n.º 8
0
 public override void Dump(SourceBuilder builder)
 {
     // first dump check
     builder.AppendFront("CheckContinueMatching OfIndependentSucceeded \n");
     // then operations for case check failed .. wording a bit rotten
     if (CheckFailedOperations != null)
     {
         builder.Indent();
         CheckFailedOperations.Dump(builder);
         builder.Unindent();
     }
 }
Ejemplo n.º 9
0
 public override void Dump(SourceBuilder builder)
 {
     // first dump check
     builder.AppendFront("CheckCandidate Failed \n");
     // then operations for case check failed
     if (CheckFailedOperations != null)
     {
         builder.Indent();
         CheckFailedOperations.Dump(builder);
         builder.Unindent();
     }
 }
Ejemplo n.º 10
0
 public override void Dump(SourceBuilder builder)
 {
     // first dump check
     builder.AppendFront("CheckContinueMatching OfIndependentFailed ");
     builder.Append(IsIterationBreaking ? "IterationBreaking\n" : "\n");
     // then operations for case check failed
     if (CheckFailedOperations != null)
     {
         builder.Indent();
         CheckFailedOperations.Dump(builder);
         builder.Unindent();
     }
 }
Ejemplo n.º 11
0
 public override void Dump(SourceBuilder builder)
 {
     // first dump check
     builder.AppendFrontFormat("CheckContinueMatching IteratedPatternFound {0}\n",
                               IsIterationBreaking ? "IterationBreaking" : "");
     // then operations for case check failed
     if (CheckFailedOperations != null)
     {
         builder.Indent();
         CheckFailedOperations.Dump(builder);
         builder.Unindent();
     }
 }
Ejemplo n.º 12
0
        public override void Dump(SourceBuilder builder)
        {
            // first dump check
            builder.Append("CheckCandidate ForIdentity ");
            builder.AppendFormat("by {0} == {1}\n", PatternElementName, OtherPatternElementName);

            // then operations for case check failed
            if (CheckFailedOperations != null)
            {
                builder.Indent();
                CheckFailedOperations.Dump(builder);
                builder.Unindent();
            }
        }
Ejemplo n.º 13
0
 public override void Dump(SourceBuilder builder)
 {
     // first dump check
     builder.AppendFront("CheckCandidate ForConnectedness ");
     builder.AppendFormat("{0}=={1}.{2}\n",
                          PatternNodeName, PatternEdgeName, ConnectednessType.ToString());
     // then operations for case check failed
     if (CheckFailedOperations != null)
     {
         builder.Indent();
         CheckFailedOperations.Dump(builder);
         builder.Unindent();
     }
 }
Ejemplo n.º 14
0
 public override void Dump(SourceBuilder builder)
 {
     // first dump check
     builder.AppendFront("CheckCandidate MapByUnique ");
     builder.AppendFormat("on {0} node:{1}\n",
                          PatternElementName, IsNode);
     // then operations for case check failed
     if (CheckFailedOperations != null)
     {
         builder.Indent();
         CheckFailedOperations.Dump(builder);
         builder.Unindent();
     }
 }
Ejemplo n.º 15
0
 public override void Dump(SourceBuilder builder)
 {
     // first dump check
     builder.AppendFront("CheckCandidate ForIsomorphyPatternPath ");
     builder.AppendFormat("on {0} node:{1} last match at previous nesting level in:{2}",
                          PatternElementName, IsNode, LastMatchAtPreviousNestingLevel);
     builder.Append("\n");
     // then operations for case check failed
     if (CheckFailedOperations != null)
     {
         builder.Indent();
         CheckFailedOperations.Dump(builder);
         builder.Unindent();
     }
 }
Ejemplo n.º 16
0
        public override void Emit(SourceBuilder sourceCode)
        {
            if (sourceCode.CommentSourceCode)
            {
                sourceCode.AppendFront("// Check whether there are subpattern matching tasks left to execute\n");
            }

            sourceCode.AppendFront("if(openTasks.Count==0)\n");
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            CheckFailedOperations.Emit(sourceCode);

            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
Ejemplo n.º 17
0
        public override void Emit(SourceBuilder sourceCode)
        {
            // emit check decision
            string variableContainingCandidate    = NamesOfEntities.CandidateVariable(PatternElementName);
            string variableContainingOtherElement = NamesOfEntities.CandidateVariable(OtherPatternElementName);

            sourceCode.AppendFrontFormat("if({0}!={1}) ",
                                         variableContainingCandidate, variableContainingOtherElement);

            // emit check failed code
            sourceCode.Append("{\n");
            sourceCode.Indent();
            CheckFailedOperations.Emit(sourceCode);
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
Ejemplo n.º 18
0
 public override void Dump(SourceBuilder builder)
 {
     // first dump local content
     builder.AppendFront("CheckPartialMatch ForDuplicate with ");
     foreach (string neededElement in NeededElements)
     {
         builder.AppendFormat("{0} ", neededElement);
     }
     builder.Append("\n");
     // then operations for case check failed
     if (CheckFailedOperations != null)
     {
         builder.Indent();
         CheckFailedOperations.Dump(builder);
         builder.Unindent();
     }
 }
Ejemplo n.º 19
0
        public override void Emit(SourceBuilder sourceCode)
        {
            if (sourceCode.CommentSourceCode)
            {
                sourceCode.AppendFront("// Check whether subpatterns were found \n");
            }

            // emit decision
            sourceCode.AppendFrontFormat("if({0}matchesList.Count>0) ", NegativeIndependentNamePrefix);

            // emit check failed code
            sourceCode.Append("{\n");
            sourceCode.Indent();
            CheckFailedOperations.Emit(sourceCode);
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
Ejemplo n.º 20
0
        public override void Emit(SourceBuilder sourceCode)
        {
            // emit check decision
            string variableContainingCandidate = NamesOfEntities.CandidateVariable(PatternElementName);

            if (Type == CheckCandidateForTypeType.ByIsAllowedType)
            {
                string isAllowedTypeArrayMemberOfRulePattern =
                    IsAllowedArrayName + "_IsAllowedType";
                sourceCode.AppendFrontFormat("if(!{0}.{1}[{2}.lgspType.TypeID]) ",
                                             RulePatternTypeName, isAllowedTypeArrayMemberOfRulePattern,
                                             variableContainingCandidate);
            }
            else if (Type == CheckCandidateForTypeType.ByIsMyType)
            {
                sourceCode.AppendFrontFormat("if(!{0}.isMyType[{1}.lgspType.TypeID]) ",
                                             TypeName, variableContainingCandidate);
            }
            else // Type == CheckCandidateForTypeType.ByTypeID)
            {
                sourceCode.AppendFront("if(");
                bool first = true;
                foreach (string typeID in TypeIDs)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sourceCode.Append(" && ");
                    }

                    sourceCode.AppendFormat("{0}.lgspType.TypeID!={1}",
                                            variableContainingCandidate, typeID);
                }
                sourceCode.Append(") ");
            }
            // emit check failed code
            sourceCode.Append("{\n");
            sourceCode.Indent();
            CheckFailedOperations.Emit(sourceCode);
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
Ejemplo n.º 21
0
        public override void Emit(SourceBuilder sourceCode)
        {
            if (sourceCode.CommentSourceCode)
            {
                sourceCode.AppendFront("// Condition \n");
            }

            // open decision
            sourceCode.AppendFront("if(");
            // emit condition expression
            sourceCode.AppendFormat("!({0})", ConditionExpression);
            // close decision
            sourceCode.Append(") ");

            // emit check failed code
            sourceCode.Append("{\n");
            sourceCode.Indent();
            CheckFailedOperations.Emit(sourceCode);
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
Ejemplo n.º 22
0
        public override void Emit(SourceBuilder sourceCode)
        {
            if (ConnectednessType == CheckCandidateForConnectednessType.Source)
            {
                // emit check decision for is candidate connected to already found partial match, i.e. edge source equals node
                sourceCode.AppendFrontFormat("if({0}.lgspSource != {1}) ",
                                             NamesOfEntities.CandidateVariable(PatternEdgeName),
                                             NamesOfEntities.CandidateVariable(PatternNodeName));
            }
            else if (ConnectednessType == CheckCandidateForConnectednessType.Target)
            {
                // emit check decision for is candidate connected to already found partial match, i.e. edge target equals node
                sourceCode.AppendFrontFormat("if({0}.lgspTarget != {1}) ",
                                             NamesOfEntities.CandidateVariable(PatternEdgeName),
                                             NamesOfEntities.CandidateVariable(PatternNodeName));
            }
            else if (ConnectednessType == CheckCandidateForConnectednessType.SourceOrTarget)
            {
                // we've to check both node positions of the edge, we do so by checking source or target dependent on the direction run
                sourceCode.AppendFrontFormat("if( ({0}==0 ? {1}.lgspSource : {1}.lgspTarget) != {2}) ",
                                             NamesOfEntities.DirectionRunCounterVariable(PatternEdgeName),
                                             NamesOfEntities.CandidateVariable(PatternEdgeName),
                                             NamesOfEntities.CandidateVariable(PatternNodeName));
            }
            else //ConnectednessType == CheckCandidateForConnectednessType.TheOther
            {
                // we've to check the node position of the edge the first node is not assigned to
                sourceCode.AppendFrontFormat("if( ({0}=={1}.lgspSource ? {1}.lgspTarget : {1}.lgspSource) != {2}) ",
                                             NamesOfEntities.CandidateVariable(TheOtherPatternNodeName),
                                             NamesOfEntities.CandidateVariable(PatternEdgeName),
                                             NamesOfEntities.CandidateVariable(PatternNodeName));
            }

            // emit check failed code
            sourceCode.Append("{\n");
            sourceCode.Indent();
            CheckFailedOperations.Emit(sourceCode);
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
Ejemplo n.º 23
0
        public override void Emit(SourceBuilder sourceCode)
        {
            // emit initialization with element mapped from unique index
            string tempVariableForUniqueResult = NamesOfEntities.MapByUniqueTemporary(PatternElementName);

            sourceCode.AppendFrontFormat("if({0}==null || !({0} is {1}))",
                                         tempVariableForUniqueResult, IsNode ? "GRGEN_LIBGR.INode" : "GRGEN_LIBGR.IEdge");

            // emit check failed code
            sourceCode.Append("{\n");
            sourceCode.Indent();
            CheckFailedOperations.Emit(sourceCode);
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");

            // assign the value to the candidate variable, cast it to the variable type
            string typeOfVariableContainingCandidate = "GRGEN_LGSP."
                                                       + (IsNode ? "LGSPNode" : "LGSPEdge");
            string variableContainingCandidate = NamesOfEntities.CandidateVariable(PatternElementName);

            sourceCode.AppendFrontFormat("{0} = ({1}){2};\n",
                                         variableContainingCandidate, typeOfVariableContainingCandidate, tempVariableForUniqueResult);
        }
Ejemplo n.º 24
0
 public override void Dump(SourceBuilder builder)
 {
     // first dump check
     builder.AppendFront("CheckCandidate ForIsomorphyGlobal ");
     builder.AppendFormat("on {0} node:{1} ",
                          PatternElementName, IsNode);
     if (GloballyHomomorphElements != null)
     {
         builder.Append("but accept if ");
         foreach (string name in GloballyHomomorphElements)
         {
             builder.AppendFormat("{0} ", name);
         }
     }
     builder.Append("\n");
     // then operations for case check failed
     if (CheckFailedOperations != null)
     {
         builder.Indent();
         CheckFailedOperations.Dump(builder);
         builder.Unindent();
     }
 }
Ejemplo n.º 25
0
        public override void Emit(SourceBuilder sourceCode)
        {
            if (sourceCode.CommentSourceCode)
            {
                sourceCode.AppendFront("// Check whether the iterated pattern null match was found\n");
            }

            sourceCode.Append("maxMatchesIterReached:\n");
            if (IsIterationBreaking)
            {
                sourceCode.AppendFront("if(!patternFound && numMatchesIter>=minMatchesIter && !breakIteration)\n");
            }
            else
            {
                sourceCode.AppendFront("if(!patternFound && numMatchesIter>=minMatchesIter)\n");
            }
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            CheckFailedOperations.Emit(sourceCode);

            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
Ejemplo n.º 26
0
 public override void Dump(SourceBuilder builder)
 {
     // first dump check
     builder.AppendFront("CheckPartialMatch ByCondition ");
     builder.AppendFormat("{0} with ", ConditionExpression);
     foreach (string neededElement in NeededElements)
     {
         builder.Append(neededElement);
         builder.Append(" ");
     }
     foreach (string neededVar in NeededVariables)
     {
         builder.Append(neededVar);
         builder.Append(" ");
     }
     builder.Append("\n");
     // then operations for case check failed
     if (CheckFailedOperations != null)
     {
         builder.Indent();
         CheckFailedOperations.Dump(builder);
         builder.Unindent();
     }
 }
Ejemplo n.º 27
0
        public override void Emit(SourceBuilder sourceCode)
        {
            // open decision whether to fail
            sourceCode.AppendFront("if(");

            // fail if graph element contained within candidate was already matched
            // (in another subpattern to another pattern element)
            // as this would cause a inter-pattern-homomorphic match
            string variableContainingCandidate = NamesOfEntities.CandidateVariable(PatternElementName);

            if (Parallel)
            {
                if (!NeverAboveMaxIsoSpace)
                {
                    sourceCode.Append("(isoSpace < (int) GRGEN_LGSP.LGSPElemFlagsParallel.MAX_ISO_SPACE ? ");
                }

                string isMatchedBit = "(uint)GRGEN_LGSP.LGSPElemFlagsParallel.IS_MATCHED_BY_ENCLOSING_PATTERN << isoSpace";
                sourceCode.AppendFormat("( flagsPerElementGlobal[{0}.uniqueId] & {1} ) == {1}",
                                        variableContainingCandidate,
                                        isMatchedBit);

                if (!NeverAboveMaxIsoSpace)
                {
                    sourceCode.Append(" : ");
                    sourceCode.AppendFormat("graph.perThreadInIsoSpaceMatchedElementsGlobal[threadId][isoSpace - (int)"
                                            + "GRGEN_LGSP.LGSPElemFlagsParallel.MAX_ISO_SPACE]"
                                            + ".ContainsKey({0}))", variableContainingCandidate);
                }
            }
            else
            {
                if (!NeverAboveMaxIsoSpace)
                {
                    sourceCode.Append("(isoSpace < (int) GRGEN_LGSP.LGSPElemFlags.MAX_ISO_SPACE ? ");
                }

                string isMatchedBit = "(uint)GRGEN_LGSP.LGSPElemFlags.IS_MATCHED_BY_ENCLOSING_PATTERN << isoSpace";
                sourceCode.AppendFormat("({0}.lgspFlags & {1})=={1}",
                                        variableContainingCandidate, isMatchedBit);

                if (!NeverAboveMaxIsoSpace)
                {
                    sourceCode.Append(" : ");
                    sourceCode.AppendFormat("graph.inIsoSpaceMatchedElementsGlobal[isoSpace - (int)"
                                            + "GRGEN_LGSP.LGSPElemFlags.MAX_ISO_SPACE]"
                                            + ".ContainsKey({0}))", variableContainingCandidate);
                }
            }

            if (GloballyHomomorphElements != null)
            {
                // don't fail if candidate was globally matched by an element
                // it is allowed to be globally homomorph to
                // (element from alternative case declared to be non-isomorph to element from enclosing pattern)
                foreach (string name in GloballyHomomorphElements)
                {
                    sourceCode.AppendFormat(" && {0}!={1}",
                                            variableContainingCandidate, NamesOfEntities.CandidateVariable(name));
                }
            }
            sourceCode.Append(")\n");

            // emit check failed code
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();
            CheckFailedOperations.Emit(sourceCode);
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
Ejemplo n.º 28
0
        public override void Emit(SourceBuilder sourceCode)
        {
            // open decision whether to fail
            sourceCode.AppendFront("if(");

            // fail if graph element contained within candidate was already matched
            // (to another pattern element)
            // as this would cause a homomorphic match
            string variableContainingCandidate = NamesOfEntities.CandidateVariable(PatternElementName);

            if (Parallel)
            {
                if (!NeverAboveMaxIsoSpace)
                {
                    sourceCode.Append("(isoSpace < (int) GRGEN_LGSP.LGSPElemFlagsParallel.MAX_ISO_SPACE ? ");
                }

                string isMatchedBit = "(uint)GRGEN_LGSP.LGSPElemFlagsParallel.IS_MATCHED << isoSpace";
                if (LockForAllThreads)
                {
                    sourceCode.AppendFormat("( flagsPerElement0[{0}.uniqueId] & {1} ) != 0",
                                            variableContainingCandidate, isMatchedBit);
                }
                else
                {
                    sourceCode.AppendFormat("( flagsPerElement[{0}.uniqueId] & {1} ) != 0",
                                            variableContainingCandidate, isMatchedBit);
                }

                if (!NeverAboveMaxIsoSpace)
                {
                    sourceCode.Append(" : ");
                    sourceCode.AppendFormat("graph.perThreadInIsoSpaceMatchedElements[{0}][isoSpace - (int)"
                                            + "GRGEN_LGSP.LGSPElemFlagsParallel.MAX_ISO_SPACE]"
                                            + ".ContainsKey({1}))",
                                            LockForAllThreads ? "0" : "threadId",
                                            variableContainingCandidate);
                }
            }
            else
            {
                if (!NeverAboveMaxIsoSpace)
                {
                    sourceCode.Append("(isoSpace < (int) GRGEN_LGSP.LGSPElemFlags.MAX_ISO_SPACE ? ");
                }

                string isMatchedBit = "(uint)GRGEN_LGSP.LGSPElemFlags.IS_MATCHED << isoSpace";
                sourceCode.AppendFormat("({0}.lgspFlags & {1}) != 0", variableContainingCandidate, isMatchedBit);

                if (!NeverAboveMaxIsoSpace)
                {
                    sourceCode.Append(" : ");
                    sourceCode.AppendFormat("graph.inIsoSpaceMatchedElements[isoSpace - (int)"
                                            + "GRGEN_LGSP.LGSPElemFlags.MAX_ISO_SPACE]"
                                            + ".ContainsKey({0}))", variableContainingCandidate);
                }
            }

            // but only if isomorphy is demanded (NamesOfPatternElementsToCheckAgainst empty)
            // otherwise homomorphy to certain elements is allowed,
            // so we only fail if the graph element is matched to one of the not allowed elements,
            // given in NamesOfPatternElementsToCheckAgainst
            if (NamesOfPatternElementsToCheckAgainst != null)
            {
                Debug.Assert(NamesOfPatternElementsToCheckAgainst.Count > 0);

                sourceCode.Append("\n");
                sourceCode.Indent();

                if (NamesOfPatternElementsToCheckAgainst.Count == 1)
                {
                    string name = NamesOfPatternElementsToCheckAgainst[0];
                    sourceCode.AppendFrontFormat("&& {0}=={1}\n", variableContainingCandidate,
                                                 NamesOfEntities.CandidateVariable(name));
                }
                else
                {
                    bool first = true;
                    foreach (string name in NamesOfPatternElementsToCheckAgainst)
                    {
                        if (first)
                        {
                            sourceCode.AppendFrontFormat("&& ({0}=={1}\n", variableContainingCandidate,
                                                         NamesOfEntities.CandidateVariable(name));
                            sourceCode.Indent();
                            first = false;
                        }
                        else
                        {
                            sourceCode.AppendFrontFormat("|| {0}=={1}\n", variableContainingCandidate,
                                                         NamesOfEntities.CandidateVariable(name));
                        }
                    }
                    sourceCode.AppendFront(")\n");
                    sourceCode.Unindent();
                }

                // close decision
                sourceCode.AppendFront(")\n");
                sourceCode.Unindent();
            }
            else
            {
                // close decision
                sourceCode.Append(")\n");
            }

            // emit check failed code
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();
            CheckFailedOperations.Emit(sourceCode);
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
Ejemplo n.º 29
0
        public override void Emit(SourceBuilder sourceCode)
        {
            if (sourceCode.CommentSourceCode)
            {
                sourceCode.AppendFront("// Check whether a duplicate match to be purged was found or will be found\n");
            }

            // emit hash variable declaration
            sourceCode.AppendFrontFormat("int {0} = 0;\n", NamesOfEntities.DuplicateMatchHashVariable());

            // only do the rest if more than one match is requested
            sourceCode.AppendFront("if(maxMatches!=1) {\n");
            sourceCode.Indent();

            // emit found matches hash map initialization as needed
            sourceCode.AppendFrontFormat("if({0}==null) {0} = new Dictionary<int, {1}>();\n",
                                         NamesOfEntities.FoundMatchesForFilteringVariable(),
                                         RulePatternClassName + "." + NamesOfEntities.MatchClassName(PatternName));

            // emit hash variable initialization with result of hash computation
            sourceCode.AppendFrontFormat("{0} = unchecked(",
                                         NamesOfEntities.DuplicateMatchHashVariable());
            EmitHashComputation(sourceCode, NeededElements.Length - 1);
            sourceCode.Append(");\n");

            // emit check whether hash is contained in found matches hash map
            sourceCode.AppendFrontFormat("if({0}.ContainsKey({1}))\n",
                                         NamesOfEntities.FoundMatchesForFilteringVariable(),
                                         NamesOfEntities.DuplicateMatchHashVariable());
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();

            // emit check whether one of the matches in the hash map with same hash is equal to the locally matched elements
            sourceCode.AppendFrontFormat("{0} {1} = {2}[{3}];\n",
                                         RulePatternClassName + "." + NamesOfEntities.MatchClassName(PatternName),
                                         NamesOfEntities.DuplicateMatchCandidateVariable(),
                                         NamesOfEntities.FoundMatchesForFilteringVariable(),
                                         NamesOfEntities.DuplicateMatchHashVariable());
            sourceCode.AppendFront("do {\n");
            sourceCode.Indent();

            // emit check for same elements
            sourceCode.AppendFront("if(");
            for (int i = 0; i < NeededElements.Length; ++i)
            {
                if (i != 0)
                {
                    sourceCode.Append(" && ");
                }
                sourceCode.AppendFormat("{0}._{1} == {2}",
                                        NamesOfEntities.DuplicateMatchCandidateVariable() + MatchObjectPaths[i],
                                        NamesOfEntities.MatchName(NeededElementsUnprefixedName[i], NeededElementsIsNode[i] ? BuildMatchObjectType.Node : BuildMatchObjectType.Edge),
                                        NamesOfEntities.CandidateVariable(NeededElements[i]));
            }
            sourceCode.Append(")\n");

            // emit check failed code, i.e. the current local match is equivalent to one of the already found ones, a duplicate
            sourceCode.AppendFront("{\n");
            sourceCode.Indent();
            CheckFailedOperations.Emit(sourceCode);
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");

            // close "emit check whether one of the matches in the hash map with same hash is equal to the locally matched elements"
            // switching to next match with the same hash, if available
            sourceCode.Unindent();
            sourceCode.AppendFront("} ");
            sourceCode.AppendFormat("while(({0} = {0}.nextWithSameHash) != null);\n",
                                    NamesOfEntities.DuplicateMatchCandidateVariable());

            // close "emit check whether hash is contained in found matches hash map"
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");

            // close "only do the rest if more than one match is requested"
            sourceCode.Unindent();
            sourceCode.AppendFront("}\n");
        }
Ejemplo n.º 30
0
 public override void Emit(SourceBuilder sourceCode)
 {
     // emit check failed code
     CheckFailedOperations.Emit(sourceCode);
 }