public test_RuleAndMatchingPatterns() { subpatterns = new GRGEN_LGSP.LGSPMatchingPattern[0]; rules = new GRGEN_LGSP.LGSPRulePattern[1]; rulesAndSubpatterns = new GRGEN_LGSP.LGSPMatchingPattern[0 + 1]; definedSequences = new GRGEN_LIBGR.DefinedSequenceInfo[0]; functions = new GRGEN_LIBGR.FunctionInfo[0 + 0]; procedures = new GRGEN_LIBGR.ProcedureInfo[0 + 0]; packages = new string[0]; rules[0] = Rule_testRule.Instance; rulesAndSubpatterns[0 + 0] = Rule_testRule.Instance; }
public SequenceDefinitionCompiled(String sequenceName, DefinedSequenceInfo seqInfo) : base(SequenceType.SequenceDefinitionCompiled, sequenceName) { SeqInfo = seqInfo; foreach(KeyValuePair<string, string> annotation in seqInfo.annotations) SequenceAnnotations.Add(annotation.Key, annotation.Value); }
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"); }
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"); }
private void GenerateInternalDefinedSequenceApplicationMethodStub(SourceBuilder source, DefinedSequenceInfo sequence, String externalActionsExtensionFilename) { source.AppendFrontFormat("// You must implement the following function in the same partial class in ./{0}\n", externalActionsExtensionFilename); 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"); }
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); } }
private void GenerateSequenceDefinedSingleton(SourceBuilder source, DefinedSequenceInfo sequence) { String className = "Sequence_" + sequence.Name; source.AppendFront("private static "+className+" instance = null;\n"); source.AppendFront("public static "+className+" Instance { get { if(instance==null) instance = new "+className+"(); return instance; } }\n"); source.AppendFront("private "+className+"() : base(\""+sequence.PackagePrefixedName+"\", SequenceInfo_"+sequence.Name+".Instance) { }\n"); }
public bool GenerateDefinedSequence(SourceBuilder source, DefinedSequenceInfo sequence) { Dictionary<String, String> varDecls = new Dictionary<String, String>(); for(int i = 0; i < sequence.Parameters.Length; i++) { varDecls.Add(sequence.Parameters[i], TypesHelper.DotNetTypeToXgrsType(sequence.ParameterTypes[i])); } for(int i = 0; i < sequence.OutParameters.Length; i++) { varDecls.Add(sequence.OutParameters[i], TypesHelper.DotNetTypeToXgrsType(sequence.OutParameterTypes[i])); } Sequence seq; try { List<string> warnings = new List<string>(); seq = SequenceParser.ParseSequence(sequence.XGRS, sequence.Package, ruleNames, sequenceNames, procedureNames, functionNames, functionOutputTypes, filterFunctionNames, varDecls, model, warnings); foreach(string warning in warnings) { Console.Error.WriteLine("In the defined sequence " + sequence.Name + " the exec part \"" + sequence.XGRS + "\" reported back:\n" + warning); } seq.Check(env); seq.SetNeedForProfilingRecursive(gen.EmitProfiling); } catch(ParseException ex) { Console.Error.WriteLine("In the defined sequence " + sequence.Name + " the exec part \"" + sequence.XGRS + "\" caused the following error:\n" + ex.Message); return false; } catch(SequenceParserException ex) { Console.Error.WriteLine("In the defined sequence " + sequence.Name + " the exec part \"" + sequence.XGRS + "\" caused the following error:\n"); HandleSequenceParserException(ex); return false; } // exact sequence definition compiled class source.Append("\n"); if(sequence.Package != null) { source.AppendFrontFormat("namespace {0}\n", sequence.Package); source.AppendFront("{\n"); source.Indent(); } source.AppendFront("public class Sequence_" + sequence.Name + " : GRGEN_LIBGR.SequenceDefinitionCompiled\n"); source.AppendFront("{\n"); source.Indent(); GenerateSequenceDefinedSingleton(source, sequence); source.Append("\n"); GenerateInternalDefinedSequenceApplicationMethod(source, sequence, seq); source.Append("\n"); GenerateExactExternalDefinedSequenceApplicationMethod(source, sequence); source.Append("\n"); GenerateGenericExternalDefinedSequenceApplicationMethod(source, sequence); // end of exact sequence definition compiled class source.Unindent(); source.AppendFront("}\n"); if(sequence.Package != null) { source.Unindent(); source.AppendFront("}\n"); } return true; }