// returns null if variable was already defined public SequenceVariable Define(String name, String type) { // a "redefinition" is allowed if the old definition was from an explicitely prefixed global if (Lookup(name) != null && Lookup(name).Type != "") { return(null); } if (type == "") { SequenceVariable var = LookupDefineGlobal(name); globalsImplicitlyDeclared.Add(var, true); return(var); } string prefix = ""; ScopeMetaInformation[] scopesMeta = this.scopesMeta.ToArray(); // holy shit! no sets, no backward iterators, no direct access to stack, // size sometimes called length, sometimes count ... c# data structures suck for (int i = scopesMeta.Length - 1; i >= 0; --i) // stack dumped in reverse ^^ { prefix += scopesMeta[i].name; } SequenceVariable newVar = new SequenceVariable(name, prefix, type); scopes.Peek().Add(name, newVar); return(newVar); }
public AssignmentTargetAttributeIndexed(SequenceVariable destVar, String attributeName, SequenceExpression keyExpr) : base(AssignmentTargetType.AttributeIndexed) { DestVar = destVar; AttributeName = attributeName; KeyExpression = keyExpr; }
public void PushFirstScope(Dictionary <String, String> predefinedVariables) { // only for initial scopes of type Globals and Sequence Debug.Assert(scopes.Count == 0); Debug.Assert(scopesMeta.Count == 0); globalsScope = new Dictionary <String, SequenceVariable>(); scopes.Push(globalsScope); Dictionary <String, SequenceVariable> sequenceScope = new Dictionary <String, SequenceVariable>(); if (predefinedVariables != null) { foreach (KeyValuePair <String, String> predefinedVariable in predefinedVariables) { String name = predefinedVariable.Key; String type = predefinedVariable.Value; SequenceVariable newVar = new SequenceVariable(name, "", type); newVar.Visited = true; // the predefined variables are parameters, don't declare them twice sequenceScope.Add(name, newVar); } } scopes.Push(sequenceScope); scopesMeta.Push(new ScopeMetaInformation("", ScopeType.Globals)); scopesMeta.Push(new ScopeMetaInformation("", ScopeType.Sequence)); }
protected AssignmentTargetAttributeIndexed(AssignmentTargetAttributeIndexed that, Dictionary <SequenceVariable, SequenceVariable> originalToCopy, IGraphProcessingEnvironment procEnv) : base(that) { DestVar = that.DestVar.Copy(originalToCopy, procEnv); AttributeName = that.AttributeName; KeyExpression = that.KeyExpression.CopyExpression(originalToCopy, procEnv); }
protected AssignmentTargetVisited(AssignmentTargetVisited that, Dictionary <SequenceVariable, SequenceVariable> originalToCopy, IGraphProcessingEnvironment procEnv) : base(that) { GraphElementVar = that.GraphElementVar.Copy(originalToCopy, procEnv); if (VisitedFlagExpression != null) { VisitedFlagExpression = that.VisitedFlagExpression.CopyExpression(originalToCopy, procEnv); } }
public FilterCallWithLambdaExpression(String packagePrefixedName, SequenceVariable arrayAccess, SequenceVariable index, SequenceVariable element, SequenceExpression lambdaExpression) : base(packagePrefixedName) { this.arrayAccess = arrayAccess; this.index = index; this.element = element; this.lambdaExpression = lambdaExpression; }
// typically used for ReturnVars protected static void CopyVars(Dictionary <SequenceVariable, SequenceVariable> originalToCopy, IGraphProcessingEnvironment procEnv, SequenceVariable[] sourceVars, out SequenceVariable[] targetVars) { targetVars = new SequenceVariable[sourceVars.Length]; for (int i = 0; i < sourceVars.Length; ++i) { targetVars[i] = sourceVars[i].Copy(originalToCopy, procEnv); } }
// returns entry for global variable, defines it in global scope if it is not yet defined there // a local variable with same name is bypassed (global prefix is not mandatory during the deprecation period) public SequenceVariable LookupDefineGlobal(String name) { if (globalsScope.ContainsKey(name)) { return(globalsScope[name]); } SequenceVariable newVar = new SequenceVariable(name, "", ""); globalsScope.Add(name, newVar); return(newVar); }
/// <summary> /// Instantiates a new RuleInvocationParameterBindings object /// </summary> /// <param name="action">The IAction instance to be used</param> /// <param name="argExprs">An array of expressions used to compute the arguments</param> /// <param name="arguments">An array of arguments.</param> /// <param name="returnVars">An array of variables used for the return values</param> public RuleInvocationParameterBindings(IAction action, SequenceExpression[] argExprs, object[] arguments, SequenceVariable[] returnVars, SequenceVariable subgraph) : base(argExprs, arguments, returnVars) { Action = action; if (action != null) { Name = action.Name; PrePackage = action.Package; Package = PrePackage; PackagePrefixedName = Package != null ? Package + "::" + Name : Name; } Subgraph = subgraph; }
/// <summary> /// Instantiates a new SequenceInvocationParameterBindings object /// </summary> /// <param name="sequenceDef">The defined sequence to be used</param> /// <param name="argExprs">An array of expressions used to compute the arguments</param> /// <param name="arguments">An array of arguments.</param> /// <param name="returnVars">An array of variables used for the return values</param> public SequenceInvocationParameterBindings(ISequenceDefinition sequenceDef, SequenceExpression[] argExprs, object[] arguments, SequenceVariable[] returnVars, SequenceVariable subgraph) : base(argExprs, arguments, returnVars) { SequenceDef = sequenceDef; if (sequenceDef != null) { Name = sequenceDef.Name; PrePackage = sequenceDef is SequenceDefinitionCompiled ? ((SequenceDefinitionCompiled)sequenceDef).SeqInfo.Package : null; Package = PrePackage; PackagePrefixedName = Package != null ? Package + "::" + Name : Name; } Subgraph = subgraph; }
/// <summary> /// Helper for checking procedure method calls. /// Checks whether called entity exists, type checks the input, type checks the output. /// Throws an exception when an error is found. /// </summary> /// <param name="seqCompProcMethodCall">The procedure method call to check</param> /// <param name="targetVar">The target of the procedure method call</param> public void CheckProcedureMethodCall(SequenceVariable targetVar, SequenceComputationProcedureMethodCall seqCompProcMethodCall) { if (targetVar.Type == "") { // only runtime checks possible (we could check whether the called procedure signature exists in at least one of the model types, if not it's a type error, can't work at runtime, but that kind of negative check is not worth the effort) return; } GrGenType ownerType = TypesHelper.GetNodeOrEdgeType(targetVar.Type, Model); if (ownerType == null) { // error, must be node or edge type throw new SequenceParserException(targetVar.Type, SequenceParserError.UserMethodsOnlyAvailableForGraphElements); } // check whether called procedure method exists if (ownerType.GetProcedureMethod(seqCompProcMethodCall.Name) == null) { throw new SequenceParserException(seqCompProcMethodCall, -1, SequenceParserError.UnknownProcedure); } CheckProcedureCallBase(seqCompProcMethodCall, ownerType); }
public AssignmentTargetYieldingVar(SequenceVariable destVar) : base(AssignmentTargetType.YieldingToVar) { DestVar = destVar; }
public bool WasImplicitelyDeclared(SequenceVariable global) { return globalsImplicitlyDeclared.ContainsKey(global); }
// returns entry for global variable, defines it in global scope if it is not yet defined there // a local variable with same name is bypassed (global prefix is not mandatory during the deprecation period) public SequenceVariable LookupDefineGlobal(String name) { if(globalsScope.ContainsKey(name)) { return globalsScope[name]; } SequenceVariable newVar = new SequenceVariable(name, "", ""); globalsScope.Add(name, newVar); return newVar; }
public bool WasImplicitelyDeclared(SequenceVariable global) { return(globalsImplicitlyDeclared.ContainsKey(global)); }
public SequenceAssignRandomDoubleToVar(SequenceVariable destVar, bool choice) : base(destVar, SequenceType.AssignRandomDoubleToVar) { this.choice = choice; }
public SequenceExpressionMatchAccess(SequenceVariable sourceVar, String elementName) : base(SequenceExpressionType.ElementOfMatch) { SourceVar = sourceVar; ElementName = elementName; }
public SequenceExpressionIsVisited(SequenceVariable graphElementVar, SequenceExpression visitedFlagExpr) : base(SequenceExpressionType.IsVisited) { GraphElementVar = graphElementVar; VisitedFlagExpr = visitedFlagExpr; }
public SequenceForIndexAccessOrdering(SequenceVariable var, bool ascending, String indexName, SequenceExpression expr, RelOpDirection dir, SequenceExpression expr2, RelOpDirection dir2, Sequence seq, List<SequenceVariable> variablesFallingOutOfScopeOnLeavingFor) : base(seq, SequenceType.ForIndexAccessOrdering) { Var = var; Ascending = ascending; IndexName = indexName; Expr = expr; Direction = dir; Expr2 = expr2; Direction2 = dir2; VariablesFallingOutOfScopeOnLeavingFor = variablesFallingOutOfScopeOnLeavingFor; }
public SequenceForIndexAccessEquality(SequenceVariable var, String indexName, SequenceExpression expr, Sequence seq, List<SequenceVariable> variablesFallingOutOfScopeOnLeavingFor) : base(seq, SequenceType.ForIndexAccessEquality) { Var = var; IndexName = indexName; Expr = expr; VariablesFallingOutOfScopeOnLeavingFor = variablesFallingOutOfScopeOnLeavingFor; }
public SequenceForIntegerRange(SequenceVariable var, SequenceExpression left, SequenceExpression right, Sequence seq, List<SequenceVariable> variablesFallingOutOfScopeOnLeavingFor) : base(seq, SequenceType.ForIntegerRange) { Var = var; Left = left; Right = right; VariablesFallingOutOfScopeOnLeavingFor = variablesFallingOutOfScopeOnLeavingFor; }
public SequenceForContainer(SequenceVariable var, SequenceVariable varDst, SequenceVariable container, Sequence seq, List<SequenceVariable> variablesFallingOutOfScopeOnLeavingFor) : base(seq, SequenceType.ForContainer) { Var = var; VarDst = varDst; Container = container; VariablesFallingOutOfScopeOnLeavingFor = variablesFallingOutOfScopeOnLeavingFor; }
public SequenceAndAssignSequenceResultToVar(SequenceVariable destVar, Sequence sequence) : base(SequenceType.AndAssignSequenceResultToVar, destVar, sequence) { }
public SequenceAssignSequenceResultToVar(SequenceType seqType, SequenceVariable destVar, Sequence sequence) : base(destVar, seqType) { Seq = sequence; }
public SequenceAssignVarToVar(SequenceVariable destVar, SequenceVariable srcVar) : base(destVar, SequenceType.AssignVarToVar) { Variable = srcVar; }
public AssignmentTargetIndexedVar(SequenceVariable destVar, SequenceExpression keyExpr) : base(AssignmentTargetType.IndexedVar) { DestVar = destVar; KeyExpression = keyExpr; }
public SequenceAssignContainerConstructorToVar(SequenceVariable destVar, SequenceExpression constructor) : base(destVar, SequenceType.AssignContainerConstructorToVar) { Constructor = constructor; }
public SequenceForFunction(SequenceVariable var, SequenceType sequenceType, List<SequenceExpression> argExprs, Sequence seq, List<SequenceVariable> variablesFallingOutOfScopeOnLeavingFor) : base(seq, sequenceType) { Var = var; ArgExprs = argExprs; VariablesFallingOutOfScopeOnLeavingFor = variablesFallingOutOfScopeOnLeavingFor; }
public SequenceExpressionAttributeAccess(SequenceVariable sourceVar, String attributeName) : base(SequenceExpressionType.GraphElementAttribute) { SourceVar = sourceVar; AttributeName = attributeName; }
public SequenceForMatch(SequenceVariable var, Sequence rule, Sequence seq, List<SequenceVariable> variablesFallingOutOfScopeOnLeavingFor) : base(seq, SequenceType.ForMatch) { Var = var; Rule = (SequenceRuleCall)rule; VariablesFallingOutOfScopeOnLeavingFor = variablesFallingOutOfScopeOnLeavingFor; }
public SequenceRuleCountAllCall(RuleInvocationParameterBindings paramBindings, bool special, bool test, SequenceVariable countResult, List<FilterCall> filters) : base(paramBindings, special, test, filters) { SequenceType = SequenceType.RuleCountAllCall; CountResult = countResult; }
public SequenceDefinitionInterpreted(String sequenceName, SequenceVariable[] inputVariables, SequenceVariable[] outputVariables, Sequence seq) : base(SequenceType.SequenceDefinitionInterpreted, sequenceName) { InputVariables = inputVariables; OutputVariables = outputVariables; Seq = seq; }
public SequenceAssignToVar(SequenceVariable destVar, SequenceType seqType) : base(seqType) { DestVar = destVar; }
public SequenceExecuteInSubgraph(SequenceVariable subgraphVar, String attributeName, Sequence seq) : base(seq, SequenceType.ExecuteInSubgraph) { SubgraphVar = subgraphVar; AttributeName = attributeName; }
public void PushFirstScope(Dictionary<String, String> predefinedVariables) { // only for initial scopes of type Globals and Sequence Debug.Assert(scopes.Count == 0); Debug.Assert(scopesMeta.Count == 0); globalsScope = new Dictionary<String, SequenceVariable>(); scopes.Push(globalsScope); Dictionary<String, SequenceVariable> sequenceScope = new Dictionary<String, SequenceVariable>(); if (predefinedVariables != null) { foreach (KeyValuePair<String, String> predefinedVariable in predefinedVariables) { String name = predefinedVariable.Key; String type = predefinedVariable.Value; SequenceVariable newVar = new SequenceVariable(name, "", type); newVar.Visited = true; // the predefined variables are parameters, don't declare them twice sequenceScope.Add(name, newVar); } } scopes.Push(sequenceScope); scopesMeta.Push(new ScopeMetaInformation("", ScopeType.Globals)); scopesMeta.Push(new ScopeMetaInformation("", ScopeType.Sequence)); }
public SequenceDeclareVariable(SequenceVariable destVar) : base(destVar, null) { SequenceType = SequenceType.DeclareVariable; }
// returns null if variable was already defined public SequenceVariable Define(String name, String type) { // a "redefinition" is allowed if the old definition was from an explicitely prefixed global if(Lookup(name)!=null && Lookup(name).Type!="") return null; if(type == "") { SequenceVariable var = LookupDefineGlobal(name); globalsImplicitlyDeclared.Add(var, true); return var; } string prefix = ""; ScopeMetaInformation[] scopesMeta = this.scopesMeta.ToArray(); // holy shit! no sets, no backward iterators, no direct access to stack, // size sometimes called length, sometimes count ... c# data structures suck for (int i = scopesMeta.Length - 1; i >= 0; --i) // stack dumped in reverse ^^ { prefix += scopesMeta[i].name; } SequenceVariable newVar = new SequenceVariable(name, prefix, type); scopes.Peek().Add(name, newVar); return newVar; }
public SequenceComputationVariableDeclaration(SequenceVariable tgt) : base(SequenceComputationType.VariableDeclaration) { Target = tgt; }
public AssignmentTargetVar(SequenceVariable destVar) : base(AssignmentTargetType.Var) { DestVar = destVar; }
public AssignmentTargetVisited(SequenceVariable graphElementVar, SequenceExpression visitedFlagExpr) : base(AssignmentTargetType.Visited) { GraphElementVar = graphElementVar; VisitedFlagExpression = visitedFlagExpr; }
protected AssignmentTargetYieldingVar(AssignmentTargetYieldingVar that, Dictionary <SequenceVariable, SequenceVariable> originalToCopy, IGraphProcessingEnvironment procEnv) : base(that) { DestVar = that.DestVar.Copy(originalToCopy, procEnv); }
public SequenceAssignRandomIntToVar(SequenceVariable destVar, int number, bool choice) : base(destVar, SequenceType.AssignRandomIntToVar) { Number = number; this.choice = choice; }
public AssignmentTargetAttribute(SequenceVariable destVar, String attributeName) : base(AssignmentTargetType.Attribute) { DestVar = destVar; AttributeName = attributeName; }
public SequenceAssignConstToVar(SequenceVariable destVar, object constant) : base(destVar, SequenceType.AssignConstToVar) { Constant = constant; }
public SequenceComputationContainerClear(SequenceVariable container) : base(SequenceComputationType.ContainerClear, container) { }
public SequenceExpressionVariable(SequenceVariable var) : base(SequenceExpressionType.Variable) { Variable = var; }
public SequenceRuleAllCall(RuleInvocationParameterBindings paramBindings, bool special, bool test, bool chooseRandom, SequenceVariable varChooseRandom, bool chooseRandom2, SequenceVariable varChooseRandom2, bool choice, List<FilterCall> filters) : base(paramBindings, special, test, filters) { SequenceType = SequenceType.RuleAllCall; ChooseRandom = chooseRandom; if(chooseRandom) { MinSpecified = chooseRandom2; if(chooseRandom2) { MinVarChooseRandom = varChooseRandom; MaxVarChooseRandom = varChooseRandom2; } else MaxVarChooseRandom = varChooseRandom; } this.choice = choice; }
public SequenceAssignUserInputToVar(SequenceVariable destVar, String type) : base(destVar, SequenceType.AssignUserInputToVar) { Type = type; }