本文整理汇总了C#中de.unika.ipd.grGen.lgsp.SourceBuilder.Indent方法的典型用法代码示例。如果您正苦于以下问题:C# SourceBuilder.Indent方法的具体用法?C# SourceBuilder.Indent怎么用?C# SourceBuilder.Indent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类de.unika.ipd.grGen.lgsp.SourceBuilder
的用法示例。
在下文中一共展示了SourceBuilder.Indent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateExternalDefinedSequence
public bool GenerateExternalDefinedSequence(SourceBuilder source, ExternalDefinedSequenceInfo sequence)
{
// exact sequence definition compiled class
source.Append("\n");
source.AppendFront("public partial class Sequence_" + sequence.Name + " : GRGEN_LIBGR.SequenceDefinitionCompiled\n");
source.AppendFront("{\n");
source.Indent();
GenerateSequenceDefinedSingleton(source, sequence);
source.Append("\n");
GenerateExactExternalDefinedSequenceApplicationMethod(source, sequence);
source.Append("\n");
GenerateGenericExternalDefinedSequenceApplicationMethod(source, sequence);
// end of exact sequence definition compiled class
source.Unindent();
source.AppendFront("}\n");
return true;
}
示例2: GenerateMatcherClassHeadSubpattern
/// <summary>
/// Generates matcher class head source code for the subpattern of the rulePattern into given source builder
/// isInitialStatic tells whether the initial static version or a dynamic version after analyze is to be generated.
/// </summary>
public void GenerateMatcherClassHeadSubpattern(SourceBuilder sb, LGSPMatchingPattern matchingPattern,
bool isInitialStatic)
{
Debug.Assert(!(matchingPattern is LGSPRulePattern));
PatternGraph patternGraph = (PatternGraph)matchingPattern.PatternGraph;
String namePrefix = (isInitialStatic ? "" : "Dyn") + "PatternAction_";
String className = namePrefix + matchingPattern.name;
String matchingPatternClassName = matchingPattern.GetType().Name;
if(patternGraph.Package != null)
{
sb.AppendFrontFormat("namespace {0}\n", patternGraph.Package);
sb.AppendFront("{\n");
sb.Indent();
}
sb.AppendFront("public class " + className + " : GRGEN_LGSP.LGSPSubpatternAction\n");
sb.AppendFront("{\n");
sb.Indent(); // class level
sb.AppendFront("private " + className + "(GRGEN_LGSP.LGSPActionExecutionEnvironment actionEnv_, Stack<GRGEN_LGSP.LGSPSubpatternAction> openTasks_) {\n");
sb.Indent(); // method body level
sb.AppendFront("actionEnv = actionEnv_; openTasks = openTasks_;\n");
sb.AppendFront("patternGraph = " + matchingPatternClassName + ".Instance.patternGraph;\n");
sb.Unindent(); // class level
sb.AppendFront("}\n\n");
GenerateTasksMemoryPool(sb, className, false, false, matchingPattern.patternGraph.branchingFactor);
for (int i = 0; i < patternGraph.nodesPlusInlined.Length; ++i)
{
PatternNode node = patternGraph.nodesPlusInlined[i];
if (node.PointOfDefinition == null)
{
sb.AppendFront("public GRGEN_LGSP.LGSPNode " + node.name + ";\n");
}
}
for (int i = 0; i < patternGraph.edgesPlusInlined.Length; ++i)
{
PatternEdge edge = patternGraph.edgesPlusInlined[i];
if (edge.PointOfDefinition == null)
{
sb.AppendFront("public GRGEN_LGSP.LGSPEdge " + edge.name + ";\n");
}
}
for (int i = 0; i < patternGraph.variablesPlusInlined.Length; ++i)
{
PatternVariable variable = patternGraph.variablesPlusInlined[i];
sb.AppendFront("public " +TypesHelper.TypeName(variable.type) + " " + variable.name + ";\n");
}
GenerateIndependentsMatchObjects(sb, matchingPattern, patternGraph);
sb.AppendFront("\n");
}
示例3: GenerateMatcherClassHeadIterated
/// <summary>
/// Generates matcher class head source code for the given iterated pattern into given source builder
/// isInitialStatic tells whether the initial static version or a dynamic version after analyze is to be generated.
/// </summary>
public void GenerateMatcherClassHeadIterated(SourceBuilder sb, LGSPMatchingPattern matchingPattern,
PatternGraph iter, bool isInitialStatic)
{
PatternGraph patternGraph = (PatternGraph)matchingPattern.PatternGraph;
String namePrefix = (isInitialStatic ? "" : "Dyn") + "IteratedAction_";
String className = namePrefix + iter.pathPrefix + iter.name;
String matchingPatternClassName = matchingPattern.GetType().Name;
if(patternGraph.Package != null)
{
sb.AppendFrontFormat("namespace {0}\n", patternGraph.Package);
sb.AppendFront("{\n");
sb.Indent();
}
sb.AppendFront("public class " + className + " : GRGEN_LGSP.LGSPSubpatternAction\n");
sb.AppendFront("{\n");
sb.Indent(); // class level
sb.AppendFront("private " + className + "(GRGEN_LGSP.LGSPActionExecutionEnvironment actionEnv_, Stack<GRGEN_LGSP.LGSPSubpatternAction> openTasks_) {\n");
sb.Indent(); // method body level
sb.AppendFront("actionEnv = actionEnv_; openTasks = openTasks_;\n");
sb.AppendFront("patternGraph = " + matchingPatternClassName + ".Instance.patternGraph;\n");
int index = -1;
for (int i=0; i<iter.embeddingGraph.iteratedsPlusInlined.Length; ++i) {
if (iter.embeddingGraph.iteratedsPlusInlined[i].iteratedPattern == iter) index = i;
}
sb.AppendFrontFormat("minMatchesIter = {0};\n", iter.embeddingGraph.iteratedsPlusInlined[index].minMatches);
sb.AppendFrontFormat("maxMatchesIter = {0};\n", iter.embeddingGraph.iteratedsPlusInlined[index].maxMatches);
sb.AppendFront("numMatchesIter = 0;\n");
if(iter.isIterationBreaking)
sb.AppendFront("breakIteration = false;\n");
sb.Unindent(); // class level
sb.AppendFront("}\n\n");
sb.AppendFront("int minMatchesIter;\n");
sb.AppendFront("int maxMatchesIter;\n");
sb.AppendFront("int numMatchesIter;\n");
if(iter.isIterationBreaking)
sb.AppendFront("bool breakIteration;\n");
sb.Append("\n");
GenerateTasksMemoryPool(sb, className, false, iter.isIterationBreaking, matchingPattern.patternGraph.branchingFactor);
Dictionary<string, bool> neededNodes = new Dictionary<string, bool>();
Dictionary<string, bool> neededEdges = new Dictionary<string, bool>();
Dictionary<string, GrGenType> neededVariables = new Dictionary<string, GrGenType>();
foreach (KeyValuePair<string, bool> neededNode in iter.neededNodes)
neededNodes[neededNode.Key] = neededNode.Value;
foreach (KeyValuePair<string, bool> neededEdge in iter.neededEdges)
neededEdges[neededEdge.Key] = neededEdge.Value;
foreach (KeyValuePair<string, GrGenType> neededVariable in iter.neededVariables)
neededVariables[neededVariable.Key] = neededVariable.Value;
foreach (KeyValuePair<string, bool> node in neededNodes)
{
sb.AppendFront("public GRGEN_LGSP.LGSPNode " + node.Key + ";\n");
}
foreach (KeyValuePair<string, bool> edge in neededEdges)
{
sb.AppendFront("public GRGEN_LGSP.LGSPEdge " + edge.Key + ";\n");
}
foreach (KeyValuePair<string, GrGenType> variable in neededVariables)
{
sb.AppendFront("public " + TypesHelper.TypeName(variable.Value) + " " + variable.Key + ";\n");
}
GenerateIndependentsMatchObjects(sb, matchingPattern, iter);
sb.AppendFront("\n");
}
示例4: GenerateActionInterface
/// <summary>
// generate the exact action interface
/// </summary>
void GenerateActionInterface(SourceBuilder sb, LGSPRulePattern matchingPattern)
{
String actionInterfaceName = "IAction_"+matchingPattern.name;
String outParameters = "";
String refParameters = "";
String allParameters = "";
for(int i = 0; i < matchingPattern.Outputs.Length; ++i)
{
outParameters += ", out " + TypesHelper.TypeName(matchingPattern.Outputs[i]) + " output_"+i;
refParameters += ", ref " + TypesHelper.TypeName(matchingPattern.Outputs[i]) + " output_"+i;
allParameters += ", List<" + TypesHelper.TypeName(matchingPattern.Outputs[i]) + "> output_"+i;
}
String inParameters = "";
for(int i=0; i<matchingPattern.Inputs.Length; ++i) {
inParameters += ", " + TypesHelper.TypeName(matchingPattern.Inputs[i]) + " " + matchingPattern.InputNames[i];
}
String matchingPatternClassName = matchingPattern.GetType().Name;
String patternName = matchingPattern.name;
String matchType = matchingPatternClassName + "." + NamesOfEntities.MatchInterfaceName(patternName);
String matchesType = "GRGEN_LIBGR.IMatchesExact<" + matchType + ">" ;
if(matchingPattern.PatternGraph.Package != null)
{
sb.AppendFrontFormat("namespace {0}\n", matchingPattern.PatternGraph.Package);
sb.AppendFront("{\n");
sb.Indent();
}
sb.AppendFront("/// <summary>\n");
sb.AppendFront("/// An object representing an executable rule - same as IAction, but with exact types and distinct parameters.\n");
sb.AppendFront("/// </summary>\n");
sb.AppendFrontFormat("public interface {0}\n", actionInterfaceName);
sb.AppendFront("{\n");
sb.Indent();
sb.AppendFront("/// <summary> same as IAction.Match, but with exact types and distinct parameters. </summary>\n");
sb.AppendFrontFormat("{0} Match(GRGEN_LIBGR.IActionExecutionEnvironment actionEnv, int maxMatches{1});\n", matchesType, inParameters);
sb.AppendFront("/// <summary> same as IAction.Modify, but with exact types and distinct parameters. </summary>\n");
sb.AppendFrontFormat("void Modify(GRGEN_LIBGR.IActionExecutionEnvironment actionEnv, {0} match{1});\n", matchType, outParameters);
sb.AppendFront("/// <summary> same as IAction.ModifyAll, but with exact types and distinct parameters. </summary>\n");
sb.AppendFrontFormat("void ModifyAll(GRGEN_LIBGR.IActionExecutionEnvironment actionEnv, {0} matches{1});\n", matchesType, allParameters);
sb.AppendFront("/// <summary> same as IAction.Apply, but with exact types and distinct parameters; returns true if applied </summary>\n");
sb.AppendFrontFormat("bool Apply(GRGEN_LIBGR.IActionExecutionEnvironment actionEnv{0}{1});\n", inParameters, refParameters);
sb.AppendFront("/// <summary> same as IAction.ApplyAll, but with exact types and distinct parameters; returns the number of matches found/applied. </summary>\n");
sb.AppendFrontFormat("int ApplyAll(int maxMatches, GRGEN_LIBGR.IActionExecutionEnvironment actionEnv{0}{1});\n", inParameters, allParameters);
sb.AppendFront("/// <summary> same as IAction.ApplyStar, but with exact types and distinct parameters. </summary>\n");
sb.AppendFrontFormat("bool ApplyStar(GRGEN_LIBGR.IActionExecutionEnvironment actionEnv{0});\n", inParameters);
sb.AppendFront("/// <summary> same as IAction.ApplyPlus, but with exact types and distinct parameters. </summary>\n");
sb.AppendFrontFormat("bool ApplyPlus(GRGEN_LIBGR.IActionExecutionEnvironment actionEnv{0});\n", inParameters);
sb.AppendFront("/// <summary> same as IAction.ApplyMinMax, but with exact types and distinct parameters. </summary>\n");
sb.AppendFrontFormat("bool ApplyMinMax(GRGEN_LIBGR.IActionExecutionEnvironment actionEnv, int min, int max{0});\n", inParameters);
sb.Unindent();
sb.AppendFront("}\n");
if(matchingPattern.PatternGraph.Package != null)
{
sb.Unindent();
sb.AppendFront("}\n");
}
sb.AppendFront("\n");
}
示例5: GenerateFileHeaderForActionsFile
/// <summary>
/// Generates file header for actions file into given source builer
/// </summary>
public void GenerateFileHeaderForActionsFile(SourceBuilder sb,
String namespaceOfModel, String namespaceOfRulePatterns)
{
sb.AppendFront("using System;\n"
+ "using System.Collections.Generic;\n"
+ "using System.Collections;\n"
+ "using System.Text;\n"
+ "using System.Threading;\n"
+ "using GRGEN_LIBGR = de.unika.ipd.grGen.libGr;\n"
+ "using GRGEN_EXPR = de.unika.ipd.grGen.expression;\n"
+ "using GRGEN_LGSP = de.unika.ipd.grGen.lgsp;\n"
+ "using GRGEN_MODEL = " + namespaceOfModel + ";\n"
+ "using GRGEN_ACTIONS = " + namespaceOfRulePatterns + ";\n"
+ "using " + namespaceOfRulePatterns + ";\n\n");
sb.AppendFront("namespace de.unika.ipd.grGen.lgspActions\n");
sb.AppendFront("{\n");
sb.Indent(); // namespace level
}
示例6: Emit
public override void Emit(SourceBuilder sourceCode)
{
sourceCode.AppendFrontFormat("foreach({0} {1} in (({2})graph.indices).{3}.Lookup",
VariableType, NamesOfEntities.Variable(Variable), IndexSetType, Index.Name);
if(Ascending)
sourceCode.Append("Ascending");
else
sourceCode.Append("Descending");
if(From != null && To != null)
{
sourceCode.Append("From");
if(IncludingFrom)
sourceCode.Append("Inclusive");
else
sourceCode.Append("Exclusive");
sourceCode.Append("To");
if(IncludingTo)
sourceCode.Append("Inclusive");
else
sourceCode.Append("Exclusive");
sourceCode.Append("(");
From.Emit(sourceCode); ;
sourceCode.Append(", ");
To.Emit(sourceCode); ;
}
else if(From != null)
{
sourceCode.Append("From");
if(IncludingFrom)
sourceCode.Append("Inclusive");
else
sourceCode.Append("Exclusive");
sourceCode.Append("(");
From.Emit(sourceCode); ;
}
else if(To != null)
{
sourceCode.Append("To");
if(IncludingTo)
sourceCode.Append("Inclusive");
else
sourceCode.Append("Exclusive");
sourceCode.Append("(");
To.Emit(sourceCode); ;
}
else
{
sourceCode.Append("(");
}
sourceCode.Append("))\n");
sourceCode.AppendFront("{\n");
sourceCode.Indent();
if(Profiling)
{
if(Parallel)
sourceCode.AppendFront("++actionEnv.PerformanceInfo.SearchStepsPerThread[threadId];\n");
else
sourceCode.AppendFront("++actionEnv.PerformanceInfo.SearchSteps;\n");
}
foreach(Yielding statement in Statements)
statement.Emit(sourceCode);
sourceCode.Unindent();
sourceCode.AppendFront("}\n");
}
示例7: GenerateFilterStubs
public void GenerateFilterStubs(SourceBuilder source, LGSPRulePattern rulePattern)
{
String rulePatternClassName = rulePattern.GetType().Name;
String matchInterfaceName = rulePatternClassName + "." + NamesOfEntities.MatchInterfaceName(rulePattern.name);
String matchesListType = "GRGEN_LIBGR.IMatchesExact<" + matchInterfaceName + ">";
foreach(IFilter filter in rulePattern.Filters)
{
if(filter is IFilterAutoGenerated)
continue;
IFilterFunction filterFunction = (IFilterFunction)filter;
if(!filterFunction.IsExternal)
continue;
if(filter.Package != null)
{
source.AppendFrontFormat("namespace {0}\n", filter.Package);
source.AppendFront("{\n");
source.Indent();
}
source.AppendFront("public partial class MatchFilters\n");
source.AppendFront("{\n");
source.Indent();
source.AppendFrontFormat("//public static void Filter_{0}(GRGEN_LGSP.LGSPGraphProcessingEnvironment procEnv, {1} matches", filter.Name, matchesListType);
for(int i = 0; i < filterFunction.Inputs.Length; ++i)
{
source.AppendFormat(", {0} {1}", TypesHelper.TypeName(filterFunction.Inputs[i]), filterFunction.InputNames[i]);
}
source.Append(")\n");
source.Unindent();
source.AppendFront("}\n");
if(filter.Package != null)
{
source.Unindent();
source.AppendFront("}\n");
}
}
}
示例8: GenerateFilters
public void GenerateFilters(SourceBuilder source, LGSPRulePattern rulePattern)
{
foreach(IFilter f in rulePattern.Filters)
{
if(f is IFilterAutoGenerated)
{
IFilterAutoGenerated filter = (IFilterAutoGenerated)f;
if(filter.Package != null)
{
source.AppendFrontFormat("namespace {0}\n", filter.Package);
source.AppendFront("{\n");
source.Indent();
}
source.AppendFront("public partial class MatchFilters\n");
source.AppendFront("{\n");
source.Indent();
if(filter.Name == "auto")
GenerateAutomorphyFilter(source, rulePattern);
else
{
if(filter.Name == "orderAscendingBy")
GenerateOrderByFilter(source, rulePattern, filter.Entity, true);
if(filter.Name == "orderDescendingBy")
GenerateOrderByFilter(source, rulePattern, filter.Entity, false);
if(filter.Name == "groupBy")
GenerateGroupByFilter(source, rulePattern, filter.Entity);
if(filter.Name == "keepSameAsFirst")
GenerateKeepSameFilter(source, rulePattern, filter.Entity, true);
if(filter.Name == "keepSameAsLast")
GenerateKeepSameFilter(source, rulePattern, filter.Entity, false);
if(filter.Name == "keepOneForEach")
GenerateKeepOneForEachFilter(source, rulePattern, filter.Entity);
}
source.Unindent();
source.AppendFront("}\n");
if(filter.Package != null)
{
source.Unindent();
source.AppendFront("}\n");
}
}
}
}
示例9: EmitRuleOrRuleAllCall
void EmitRuleOrRuleAllCall(SequenceRuleCall seqRule, SourceBuilder source)
{
RuleInvocationParameterBindings paramBindings = seqRule.ParamBindings;
String specialStr = seqRule.Special ? "true" : "false";
String parameterDeclarations = null;
String parameters = null;
if(paramBindings.Subgraph != null)
parameters = BuildParametersInDeclarations(paramBindings, out parameterDeclarations);
else
parameters = BuildParameters(paramBindings);
String matchingPatternClassName = TypesHelper.GetPackagePrefixDot(paramBindings.Package) + "Rule_" + paramBindings.Name;
String patternName = paramBindings.Name;
String matchType = matchingPatternClassName + "." + NamesOfEntities.MatchInterfaceName(patternName);
String matchName = "match_" + seqRule.Id;
String matchesType = "GRGEN_LIBGR.IMatchesExact<" + matchType + ">";
String matchesName = "matches_" + seqRule.Id;
if(paramBindings.Subgraph != null)
{
source.AppendFront(parameterDeclarations + "\n");
source.AppendFront("procEnv.SwitchToSubgraph((GRGEN_LIBGR.IGraph)" + GetVar(paramBindings.Subgraph) + ");\n");
source.AppendFront("graph = ((GRGEN_LGSP.LGSPActionExecutionEnvironment)procEnv).graph;\n");
}
source.AppendFront(matchesType + " " + matchesName + " = rule_" + TypesHelper.PackagePrefixedNameUnderscore(paramBindings.Package, paramBindings.Name)
+ ".Match(procEnv, " + (seqRule.SequenceType == SequenceType.RuleCall ? "1" : "procEnv.MaxMatches")
+ parameters + ");\n");
for(int i = 0; i < seqRule.Filters.Count; ++i)
{
EmitFilterCall(source, seqRule.Filters[i], patternName, matchesName);
}
if(gen.FireDebugEvents) source.AppendFront("procEnv.Matched(" + matchesName + ", null, " + specialStr + ");\n");
if(seqRule is SequenceRuleCountAllCall)
{
SequenceRuleCountAllCall seqRuleCountAll = (SequenceRuleCountAllCall)seqRule;
source.AppendFront(SetVar(seqRuleCountAll.CountResult, matchesName + ".Count"));
}
if(seqRule is SequenceRuleAllCall
&& ((SequenceRuleAllCall)seqRule).ChooseRandom
&& ((SequenceRuleAllCall)seqRule).MinSpecified)
{
SequenceRuleAllCall seqRuleAll = (SequenceRuleAllCall)seqRule;
source.AppendFrontFormat("int minmatchesvar_{0} = (int){1};\n", seqRuleAll.Id, GetVar(seqRuleAll.MinVarChooseRandom));
source.AppendFrontFormat("if({0}.Count < minmatchesvar_{1}) {{\n", matchesName, seqRuleAll.Id);
}
else
{
source.AppendFront("if(" + matchesName + ".Count==0) {\n");
}
source.Indent();
source.AppendFront(SetResultVar(seqRule, "false"));
source.Unindent();
source.AppendFront("} else {\n");
source.Indent();
source.AppendFront(SetResultVar(seqRule, "true"));
source.AppendFront("procEnv.PerformanceInfo.MatchesFound += " + matchesName + ".Count;\n");
if(gen.FireDebugEvents) source.AppendFront("procEnv.Finishing(" + matchesName + ", " + specialStr + ");\n");
String returnParameterDeclarations;
String returnArguments;
String returnAssignments;
String returnParameterDeclarationsAllCall;
String intermediateReturnAssignmentsAllCall;
String returnAssignmentsAllCall;
BuildReturnParameters(paramBindings,
out returnParameterDeclarations, out returnArguments, out returnAssignments,
out returnParameterDeclarationsAllCall, out intermediateReturnAssignmentsAllCall, out returnAssignmentsAllCall);
if(seqRule.SequenceType == SequenceType.RuleCall)
{
source.AppendFront(matchType + " " + matchName + " = " + matchesName + ".FirstExact;\n");
if(returnParameterDeclarations.Length!=0) source.AppendFront(returnParameterDeclarations + "\n");
source.AppendFront("rule_" + TypesHelper.PackagePrefixedNameUnderscore(paramBindings.Package, paramBindings.Name) + ".Modify(procEnv, " + matchName + returnArguments + ");\n");
if(returnAssignments.Length != 0) source.AppendFront(returnAssignments + "\n");
source.AppendFront("procEnv.PerformanceInfo.RewritesPerformed++;\n");
}
else if(seqRule.SequenceType == SequenceType.RuleCountAllCall || !((SequenceRuleAllCall)seqRule).ChooseRandom) // seq.SequenceType == SequenceType.RuleAll
{
// iterate through matches, use Modify on each, fire the next match event after the first
if(returnParameterDeclarations.Length != 0) source.AppendFront(returnParameterDeclarationsAllCall + "\n");
String enumeratorName = "enum_" + seqRule.Id;
source.AppendFront("IEnumerator<" + matchType + "> " + enumeratorName + " = " + matchesName + ".GetEnumeratorExact();\n");
source.AppendFront("while(" + enumeratorName + ".MoveNext())\n");
source.AppendFront("{\n");
source.Indent();
source.AppendFront(matchType + " " + matchName + " = " + enumeratorName + ".Current;\n");
source.AppendFront("if(" + matchName + "!=" + matchesName + ".FirstExact) procEnv.RewritingNextMatch();\n");
if(returnParameterDeclarations.Length != 0) source.AppendFront(returnParameterDeclarations + "\n");
source.AppendFront("rule_" + TypesHelper.PackagePrefixedNameUnderscore(paramBindings.Package, paramBindings.Name) + ".Modify(procEnv, " + matchName + returnArguments + ");\n");
if(returnAssignments.Length != 0) source.AppendFront(intermediateReturnAssignmentsAllCall + "\n");
source.AppendFront("procEnv.PerformanceInfo.RewritesPerformed++;\n");
source.Unindent();
source.AppendFront("}\n");
if(returnAssignments.Length != 0) source.AppendFront(returnAssignmentsAllCall + "\n");
}
else // seq.SequenceType == SequenceType.RuleAll && ((SequenceRuleAll)seqRule).ChooseRandom
{
// as long as a further rewrite has to be selected: randomly choose next match, rewrite it and remove it from available matches; fire the next match event after the first
//.........这里部分代码省略.........
示例10: GenerateGenericExternalDefinedSequenceApplicationMethod
private void GenerateGenericExternalDefinedSequenceApplicationMethod(SourceBuilder source, DefinedSequenceInfo sequence)
{
source.AppendFront("public override bool Apply(GRGEN_LIBGR.SequenceInvocationParameterBindings sequenceInvocation, GRGEN_LIBGR.IGraphProcessingEnvironment procEnv)");
source.AppendFront("{\n");
source.Indent();
source.AppendFront("GRGEN_LGSP.LGSPGraph graph = ((GRGEN_LGSP.LGSPActionExecutionEnvironment)procEnv).graph;\n");
for(int i = 0; i < sequence.Parameters.Length; ++i)
{
string typeName = TypesHelper.XgrsTypeToCSharpType(TypesHelper.DotNetTypeToXgrsType(sequence.ParameterTypes[i]), model);
source.AppendFront(typeName + " var_" + sequence.Parameters[i]);
source.Append(" = (" + typeName + ")sequenceInvocation.ArgumentExpressions[" + i + "].Evaluate((GRGEN_LGSP.LGSPGraphProcessingEnvironment)procEnv);\n");
}
for(int i = 0; i < sequence.OutParameters.Length; ++i)
{
string typeName = TypesHelper.XgrsTypeToCSharpType(TypesHelper.DotNetTypeToXgrsType(sequence.OutParameterTypes[i]), model);
source.AppendFront(typeName + " var_" + sequence.OutParameters[i]);
source.Append(" = " + TypesHelper.DefaultValueString(typeName, model) + ";\n");
}
source.AppendFront("if(sequenceInvocation.Subgraph!=null)\n");
source.AppendFront("\t{ procEnv.SwitchToSubgraph((GRGEN_LIBGR.IGraph)sequenceInvocation.Subgraph.GetVariableValue(procEnv)); graph = ((GRGEN_LGSP.LGSPActionExecutionEnvironment)procEnv).graph; }\n");
source.AppendFront("bool result = ApplyXGRS_" + sequence.Name + "((GRGEN_LGSP.LGSPGraphProcessingEnvironment)procEnv");
for(int i = 0; i < sequence.Parameters.Length; ++i)
{
source.Append(", var_" + sequence.Parameters[i]);
}
for(int i = 0; i < sequence.OutParameters.Length; ++i)
{
source.Append(", ref var_" + sequence.OutParameters[i]);
}
source.Append(");\n");
source.AppendFront("if(sequenceInvocation.Subgraph!=null)\n");
source.AppendFront("\t{ procEnv.ReturnFromSubgraph(); graph = ((GRGEN_LGSP.LGSPActionExecutionEnvironment)procEnv).graph; }\n");
if(sequence.OutParameters.Length > 0)
{
source.AppendFront("if(result) {\n");
source.Indent();
for(int i = 0; i < sequence.OutParameters.Length; ++i)
{
source.AppendFront("sequenceInvocation.ReturnVars[" + i + "].SetVariableValue(var_" + sequence.OutParameters[i] + ", procEnv);\n");
}
source.Unindent();
source.AppendFront("}\n");
}
source.AppendFront("return result;\n");
source.Unindent();
source.AppendFront("}\n");
}
示例11: GenerateExactExternalDefinedSequenceApplicationMethod
private void GenerateExactExternalDefinedSequenceApplicationMethod(SourceBuilder source, DefinedSequenceInfo sequence)
{
source.AppendFront("public static bool Apply_" + sequence.Name + "(GRGEN_LIBGR.IGraphProcessingEnvironment procEnv");
for(int i = 0; i < sequence.Parameters.Length; ++i)
{
source.Append(", " + TypesHelper.XgrsTypeToCSharpType(TypesHelper.DotNetTypeToXgrsType(sequence.ParameterTypes[i]), model) + " var_");
source.Append(sequence.Parameters[i]);
}
for(int i = 0; i < sequence.OutParameters.Length; ++i)
{
source.Append(", ref " + TypesHelper.XgrsTypeToCSharpType(TypesHelper.DotNetTypeToXgrsType(sequence.OutParameterTypes[i]), model) + " var_");
source.Append(sequence.OutParameters[i]);
}
source.Append(")\n");
source.AppendFront("{\n");
source.Indent();
for(int i = 0; i < sequence.OutParameters.Length; ++i)
{
string typeName = TypesHelper.XgrsTypeToCSharpType(TypesHelper.DotNetTypeToXgrsType(sequence.OutParameterTypes[i]), model);
source.AppendFront(typeName + " vari_" + sequence.OutParameters[i]);
source.Append(" = " + TypesHelper.DefaultValueString(typeName, model) + ";\n");
}
source.AppendFront("bool result = ApplyXGRS_" + sequence.Name + "((GRGEN_LGSP.LGSPGraphProcessingEnvironment)procEnv");
for(int i = 0; i < sequence.Parameters.Length; ++i)
{
source.Append(", var_" + sequence.Parameters[i]);
}
for(int i = 0; i < sequence.OutParameters.Length; ++i)
{
source.Append(", ref var_" + sequence.OutParameters[i]);
}
source.Append(");\n");
if(sequence.OutParameters.Length > 0)
{
source.AppendFront("if(result) {\n");
source.Indent();
for(int i = 0; i < sequence.OutParameters.Length; ++i)
{
source.AppendFront("var_" + sequence.OutParameters[i]);
source.Append(" = vari_" + sequence.OutParameters[i] + ";\n");
}
source.Unindent();
source.AppendFront("}\n");
}
source.AppendFront("return result;\n");
source.Unindent();
source.AppendFront("}\n");
}
示例12: GenerateInternalDefinedSequenceApplicationMethod
private void GenerateInternalDefinedSequenceApplicationMethod(SourceBuilder source, DefinedSequenceInfo sequence, Sequence seq)
{
source.AppendFront("public static bool ApplyXGRS_" + sequence.Name + "(GRGEN_LGSP.LGSPGraphProcessingEnvironment procEnv");
for(int i = 0; i < sequence.Parameters.Length; ++i)
{
source.Append(", " + TypesHelper.XgrsTypeToCSharpType(TypesHelper.DotNetTypeToXgrsType(sequence.ParameterTypes[i]), model) + " var_");
source.Append(sequence.Parameters[i]);
}
for(int i = 0; i < sequence.OutParameters.Length; ++i)
{
source.Append(", ref " + TypesHelper.XgrsTypeToCSharpType(TypesHelper.DotNetTypeToXgrsType(sequence.OutParameterTypes[i]), model) + " var_");
source.Append(sequence.OutParameters[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}\"", sequence.Name);
for(int i = 0; i < sequence.Parameters.Length; ++i)
{
source.Append(", var_");
source.Append(sequence.Parameters[i]);
}
source.Append(");\n");
}
EmitNeededVarAndRuleEntities(seq, source);
EmitSequence(seq, source);
if(gen.FireDebugEvents)
{
source.AppendFrontFormat("procEnv.DebugExiting(\"{0}\"", sequence.Name);
for(int i = 0; i < sequence.OutParameters.Length; ++i)
{
source.Append(", var_");
source.Append(sequence.OutParameters[i]);
}
source.Append(");\n");
}
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);
}
}
示例13: GenerateExternalDefinedSequencePlaceholder
public void GenerateExternalDefinedSequencePlaceholder(SourceBuilder source, ExternalDefinedSequenceInfo sequence, String externalActionsExtensionFilename)
{
source.Append("\n");
source.AppendFront("public partial class Sequence_" + sequence.Name + "\n");
source.AppendFront("{\n");
source.Indent();
GenerateInternalDefinedSequenceApplicationMethodStub(source, sequence, externalActionsExtensionFilename);
source.Unindent();
source.AppendFront("}\n");
}
示例14: EmitSequence
void EmitSequence(Sequence seq, SourceBuilder source)
{
switch(seq.SequenceType)
{
case SequenceType.RuleCall:
case SequenceType.RuleAllCall:
case SequenceType.RuleCountAllCall:
EmitRuleOrRuleAllCall((SequenceRuleCall)seq, source);
break;
case SequenceType.SequenceCall:
EmitSequenceCall((SequenceSequenceCall)seq, source);
break;
case SequenceType.Not:
{
SequenceNot seqNot = (SequenceNot) seq;
EmitSequence(seqNot.Seq, source);
source.AppendFront(SetResultVar(seqNot, "!"+GetResultVar(seqNot.Seq)));
break;
}
case SequenceType.LazyOr:
case SequenceType.LazyAnd:
case SequenceType.IfThen:
{
SequenceBinary seqBin = (SequenceBinary) seq;
if(seqBin.Random)
{
Debug.Assert(seq.SequenceType != SequenceType.IfThen);
source.AppendFront("if(GRGEN_LIBGR.Sequence.randomGenerator.Next(2) == 1)\n");
source.AppendFront("{\n");
source.Indent();
EmitLazyOp(seqBin, source, true);
source.Unindent();
source.AppendFront("}\n");
source.AppendFront("else\n");
source.AppendFront("{\n");
source.Indent();
EmitLazyOp(seqBin, source, false);
source.Unindent();
source.AppendFront("}\n");
}
else
{
EmitLazyOp(seqBin, source, false);
}
break;
}
case SequenceType.ThenLeft:
case SequenceType.ThenRight:
case SequenceType.StrictAnd:
case SequenceType.StrictOr:
case SequenceType.Xor:
{
SequenceBinary seqBin = (SequenceBinary) seq;
if(seqBin.Random)
{
source.AppendFront("if(GRGEN_LIBGR.Sequence.randomGenerator.Next(2) == 1)\n");
source.AppendFront("{\n");
source.Indent();
EmitSequence(seqBin.Right, source);
EmitSequence(seqBin.Left, source);
source.Unindent();
source.AppendFront("}\n");
source.AppendFront("else\n");
source.AppendFront("{\n");
source.Indent();
EmitSequence(seqBin.Left, source);
EmitSequence(seqBin.Right, source);
source.Unindent();
source.AppendFront("}\n");
}
else
{
EmitSequence(seqBin.Left, source);
EmitSequence(seqBin.Right, source);
}
if(seq.SequenceType==SequenceType.ThenLeft) {
source.AppendFront(SetResultVar(seq, GetResultVar(seqBin.Left)));
break;
} else if(seq.SequenceType==SequenceType.ThenRight) {
source.AppendFront(SetResultVar(seq, GetResultVar(seqBin.Right)));
break;
}
String op;
switch(seq.SequenceType)
{
case SequenceType.StrictAnd: op = "&"; break;
case SequenceType.StrictOr: op = "|"; break;
case SequenceType.Xor: op = "^"; break;
default: throw new Exception("Internal error in EmitSequence: Should not have reached this!");
}
source.AppendFront(SetResultVar(seq, GetResultVar(seqBin.Left) + " "+op+" " + GetResultVar(seqBin.Right)));
break;
}
//.........这里部分代码省略.........
示例15: GenerateAutomorphyFilter
private static void GenerateAutomorphyFilter(SourceBuilder source, LGSPRulePattern rulePattern)
{
String rulePatternClassName = TypesHelper.GetPackagePrefixDot(rulePattern.PatternGraph.Package) + rulePattern.GetType().Name;
String matchInterfaceName = rulePatternClassName + "." + NamesOfEntities.MatchInterfaceName(rulePattern.name);
String matchClassName = rulePatternClassName + "." + NamesOfEntities.MatchClassName(rulePattern.name);
String matchesListType = "GRGEN_LIBGR.IMatchesExact<" + matchInterfaceName + ">";
String filterName = "auto";
source.AppendFrontFormat("public static void Filter_{0}_{1}(GRGEN_LGSP.LGSPGraphProcessingEnvironment procEnv, {2} matches)\n",
rulePattern.name, filterName, matchesListType);
source.AppendFront("{\n");
source.Indent();
source.AppendFront("if(matches.Count < 2)\n");
source.AppendFront("\treturn;\n");
source.AppendFrontFormat("List<{0}> matchesArray = matches.ToList();\n", matchInterfaceName);
source.AppendFrontFormat("if(matches.Count < 5 || {0}.Instance.patternGraph.nodes.Length + {0}.Instance.patternGraph.edges.Length < 1)\n", rulePatternClassName);
source.AppendFront("{\n");
source.Indent();
source.AppendFront("for(int i = 0; i < matchesArray.Count; ++i)\n");
source.AppendFront("{\n");
source.Indent();
source.AppendFront("if(matchesArray[i] == null)\n");
source.AppendFront("\tcontinue;\n");
source.AppendFront("for(int j = i + 1; j < matchesArray.Count; ++j)\n");
source.AppendFront("{\n");
source.Indent();
source.AppendFront("if(matchesArray[j] == null)\n");
source.AppendFront("\tcontinue;\n");
source.AppendFront("if(GRGEN_LIBGR.SymmetryChecker.AreSymmetric(matchesArray[i], matchesArray[j], procEnv.graph))\n");
source.AppendFront("\tmatchesArray[j] = null;\n");
source.Unindent();
source.AppendFront("}\n");
source.Unindent();
source.AppendFront("}\n");
source.Unindent();
source.AppendFront("}\n");
source.AppendFront("else\n");
source.AppendFront("{\n");
source.Indent();
source.AppendFrontFormat("Dictionary<int, {0}> foundMatchesOfSameMainPatternHash = new Dictionary<int, {0}>();\n",
matchClassName);
source.AppendFront("for(int i = 0; i < matchesArray.Count; ++i)\n");
source.AppendFront("{\n");
source.Indent();
source.AppendFrontFormat("{0} match = ({0})matchesArray[i];\n", matchClassName);
source.AppendFront("int duplicateMatchHash = 0;\n");
source.AppendFront("for(int j = 0; j < match.NumberOfNodes; ++j) duplicateMatchHash ^= match.getNodeAt(j).GetHashCode();\n");
source.AppendFront("for(int j = 0; j < match.NumberOfEdges; ++j) duplicateMatchHash ^= match.getEdgeAt(j).GetHashCode();\n");
source.AppendFront("bool contained = foundMatchesOfSameMainPatternHash.ContainsKey(duplicateMatchHash);\n");
source.AppendFront("if(contained)\n");
source.AppendFront("{\n");
source.Indent();
source.AppendFrontFormat("{0} duplicateMatchCandidate = foundMatchesOfSameMainPatternHash[duplicateMatchHash];\n", matchClassName);
source.AppendFront("do\n");
source.AppendFront("{\n");
source.Indent();
source.AppendFront("if(GRGEN_LIBGR.SymmetryChecker.AreSymmetric(match, duplicateMatchCandidate, procEnv.graph))\n");
source.AppendFront("{\n");
source.Indent();
source.AppendFront("matchesArray[i] = null;\n");
source.AppendFrontFormat("goto label_auto_{0};\n", rulePatternClassName.Replace('.', '_'));
source.Unindent();
source.AppendFront("}\n");
source.Unindent();
source.AppendFront("}\n");
source.AppendFront("while((duplicateMatchCandidate = duplicateMatchCandidate.nextWithSameHash) != null);\n");
source.Unindent();
source.AppendFront("}\n");
source.AppendFront("if(!contained)\n");
source.AppendFront("\tfoundMatchesOfSameMainPatternHash[duplicateMatchHash] = match;\n");
source.AppendFront("else\n");
source.AppendFront("{\n");
source.Indent();
source.AppendFrontFormat("{0} duplicateMatchCandidate = foundMatchesOfSameMainPatternHash[duplicateMatchHash];\n", matchClassName);
source.AppendFront("while(duplicateMatchCandidate.nextWithSameHash != null) duplicateMatchCandidate = duplicateMatchCandidate.nextWithSameHash;\n");
source.AppendFront("duplicateMatchCandidate.nextWithSameHash = match;\n");
source.Unindent();
source.AppendFront("}\n");
source.AppendFormat("label_auto_{0}: ;\n", rulePatternClassName.Replace('.', '_'));
source.Unindent();
source.AppendFront("}\n");
source.AppendFrontFormat("foreach({0} toClean in foundMatchesOfSameMainPatternHash.Values) toClean.CleanNextWithSameHash();\n", matchClassName);
source.Unindent();
source.AppendFront("}\n");
source.AppendFront("matches.FromList();\n");
source.Unindent();
source.AppendFront("}\n");
}