Esempio n. 1
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);
        }
        public override void Emit(SourceBuilder sourceCode)
        {
            if (sourceCode.CommentSourceCode)
            {
                sourceCode.AppendFrontFormat("// Variable {0} assigned from expression {1} \n",
                                             VariableName, SourceExpression);
            }

            // emit declaration of variable initialized with expression
            sourceCode.AppendFrontFormat("{0} {1} = ({0}){2};\n",
                                         VariableType, NamesOfEntities.Variable(VariableName), SourceExpression);
        }
 public override void Emit(SourceBuilder sourceCode)
 {
     if (Type == EntityType.Node)
     {
         sourceCode.AppendFront(TypeOfEntity + " " + NamesOfEntities.CandidateVariable(NameOfEntity) + " = (" + TypeOfEntity + ")" + Initialization + ";\n");
     }
     else if (Type == EntityType.Edge)
     {
         sourceCode.AppendFront(TypeOfEntity + " " + NamesOfEntities.CandidateVariable(NameOfEntity) + " = (" + TypeOfEntity + ")" + Initialization + ";\n");
     }
     else //if(Type == EntityType.Variable)
     {
         sourceCode.AppendFront(TypeOfEntity + " " + NamesOfEntities.Variable(NameOfEntity) + " = (" + TypeOfEntity + ")" + Initialization + ";\n");
     }
 }
Esempio n. 4
0
        public override void Emit(SourceBuilder sourceCode)
        {
            string targetPatternElement = Type == EntityType.Variable ? NamesOfEntities.Variable(TargetPatternElementName) : NamesOfEntities.CandidateVariable(TargetPatternElementName);

            if (SourcePatternElementUnprefixedName != null)
            {
                string sourcePatternElement = NamesOfEntities.MatchName(SourcePatternElementUnprefixedName, Type);
                sourceCode.AppendFrontFormat("{0} = {1}._{2}; // bubble up (from match)\n",
                                             targetPatternElement, NestedMatchOrTaskObjectName, sourcePatternElement);
            }
            else
            {
                sourceCode.AppendFrontFormat("{0} = {1}.{0}; // bubble up (from task)\n",
                                             targetPatternElement, NestedMatchOrTaskObjectName);
            }
        }
 public override void Emit(SourceBuilder sourceCode)
 {
     sourceCode.AppendFront(VarType + " " + NamesOfEntities.Variable(VarName) + " = (" + VarType + ")" + VarName + ";\n");
 }
Esempio n. 6
0
        public override void Emit(SourceBuilder sourceCode)
        {
            string matchName = NamesOfEntities.MatchName(PatternElementUnprefixedName, Type);

            if (Type == BuildMatchObjectType.Node || Type == BuildMatchObjectType.Edge)
            {
                string variableContainingCandidate = NamesOfEntities.CandidateVariable(PatternElementName);
                sourceCode.AppendFrontFormat("{0}._{1} = {2};\n",
                                             MatchObjectName, matchName, variableContainingCandidate);
            }
            else if (Type == BuildMatchObjectType.Variable)
            {
                string variableName = NamesOfEntities.Variable(PatternElementName);
                sourceCode.AppendFrontFormat("{0}._{1} = {2};\n",
                                             MatchObjectName, matchName, variableName);
            }
            else if (Type == BuildMatchObjectType.Subpattern)
            {
                sourceCode.AppendFrontFormat("{0}._{1} = (@{2})currentFoundPartialMatch.Pop();\n",
                                             MatchObjectName, matchName, PatternElementType);
                sourceCode.AppendFrontFormat("{0}._{1}._matchOfEnclosingPattern = {0};\n",
                                             MatchObjectName, matchName);
            }
            else if (Type == BuildMatchObjectType.InlinedSubpattern)
            {
                sourceCode.AppendFrontFormat("{0}._{1} = match_{2};\n",
                                             MatchObjectName, matchName, PatternElementName);
            }
            else if (Type == BuildMatchObjectType.Iteration)
            {
                sourceCode.AppendFrontFormat("{0}._{1} = new GRGEN_LGSP.LGSPMatchesList<{2}.{3}, {2}.{4}>(null);\n",
                                             MatchObjectName, matchName,
                                             RulePatternClassName, NamesOfEntities.MatchClassName(PatternElementType), NamesOfEntities.MatchInterfaceName(PatternElementType));
                sourceCode.AppendFrontFormat("while(currentFoundPartialMatch.Count>0 && currentFoundPartialMatch.Peek() is {0}.{1}) ",
                                             RulePatternClassName, NamesOfEntities.MatchInterfaceName(PatternElementType));
                sourceCode.Append("{\n");
                sourceCode.Indent();
                sourceCode.AppendFrontFormat("{0}.{1} cfpm = ({0}.{1})currentFoundPartialMatch.Pop();\n",
                                             RulePatternClassName, NamesOfEntities.MatchClassName(PatternElementType));
                sourceCode.AppendFront("if(cfpm.IsNullMatch) break;\n");
                sourceCode.AppendFrontFormat("cfpm.SetMatchOfEnclosingPattern({0});\n",
                                             MatchObjectName);
                sourceCode.AppendFrontFormat("{0}._{1}.Add(cfpm);\n",
                                             MatchObjectName, matchName);
                sourceCode.Unindent();
                sourceCode.AppendFront("}\n");
            }
            else if (Type == BuildMatchObjectType.Alternative)
            {
                sourceCode.AppendFrontFormat("{0}._{1} = ({2}.{3})currentFoundPartialMatch.Pop();\n",
                                             MatchObjectName, matchName, RulePatternClassName, NamesOfEntities.MatchInterfaceName(PatternElementType));
                sourceCode.AppendFrontFormat("{0}._{1}.SetMatchOfEnclosingPattern({0});\n",
                                             MatchObjectName, matchName);
            }
            else //if(Type == BuildMatchObjectType.Independent)
            {
                sourceCode.AppendFrontFormat("{0}._{1} = {2};\n",
                                             MatchObjectName, matchName, NamesOfEntities.MatchedIndependentVariable(PatternElementName));
                sourceCode.AppendFrontFormat("{0} = new {1}({0});\n",
                                             NamesOfEntities.MatchedIndependentVariable(PatternElementName),
                                             RulePatternClassName + "." + NamesOfEntities.MatchClassName(MatchClassName));
                sourceCode.AppendFrontFormat("{0}._{1}.SetMatchOfEnclosingPattern({0});\n",
                                             MatchObjectName, matchName);
            }
        }