Example #1
0
        // 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;
 }
Example #3
0
        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);
     }
 }
Example #6
0
 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;
 }
Example #7
0
 // 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);
     }
 }
Example #8
0
        // 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);
        }
Example #9
0
 /// <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;
 }
Example #10
0
 /// <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;
 }
Example #11
0
        /// <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;
 }
Example #13
0
 public bool WasImplicitelyDeclared(SequenceVariable global)
 {
     return globalsImplicitlyDeclared.ContainsKey(global);
 }
Example #14
0
        // 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;
        }
Example #15
0
 public bool WasImplicitelyDeclared(SequenceVariable global)
 {
     return(globalsImplicitlyDeclared.ContainsKey(global));
 }
Example #16
0
 public SequenceAssignRandomDoubleToVar(SequenceVariable destVar, bool choice)
     : base(destVar, SequenceType.AssignRandomDoubleToVar)
 {
     this.choice = choice;
 }
Example #17
0
 public SequenceExpressionMatchAccess(SequenceVariable sourceVar, String elementName)
     : base(SequenceExpressionType.ElementOfMatch)
 {
     SourceVar = sourceVar;
     ElementName = elementName;
 }
Example #18
0
 public SequenceExpressionIsVisited(SequenceVariable graphElementVar, SequenceExpression visitedFlagExpr)
     : base(SequenceExpressionType.IsVisited)
 {
     GraphElementVar = graphElementVar;
     VisitedFlagExpr = visitedFlagExpr;
 }
Example #19
0
 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;
 }
Example #20
0
 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;
 }
Example #21
0
 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;
 }
Example #22
0
 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;
 }
Example #23
0
 public SequenceAndAssignSequenceResultToVar(SequenceVariable destVar, Sequence sequence)
     : base(SequenceType.AndAssignSequenceResultToVar, destVar, sequence)
 {
 }
Example #24
0
 public SequenceAssignSequenceResultToVar(SequenceType seqType, SequenceVariable destVar, Sequence sequence)
     : base(destVar, seqType)
 {
     Seq = sequence;
 }
Example #25
0
 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;
 }
Example #27
0
 public SequenceAssignContainerConstructorToVar(SequenceVariable destVar, SequenceExpression constructor)
     : base(destVar, SequenceType.AssignContainerConstructorToVar)
 {
     Constructor = constructor;
 }
Example #28
0
 public SequenceForFunction(SequenceVariable var, SequenceType sequenceType,
     List<SequenceExpression> argExprs, Sequence seq,
     List<SequenceVariable> variablesFallingOutOfScopeOnLeavingFor)
     : base(seq, sequenceType)
 {
     Var = var;
     ArgExprs = argExprs;
     VariablesFallingOutOfScopeOnLeavingFor = variablesFallingOutOfScopeOnLeavingFor;
 }
Example #29
0
 public SequenceExpressionAttributeAccess(SequenceVariable sourceVar, String attributeName)
     : base(SequenceExpressionType.GraphElementAttribute)
 {
     SourceVar = sourceVar;
     AttributeName = attributeName;
 }
Example #30
0
 public SequenceForMatch(SequenceVariable var, Sequence rule, Sequence seq,
     List<SequenceVariable> variablesFallingOutOfScopeOnLeavingFor)
     : base(seq, SequenceType.ForMatch)
 {
     Var = var;
     Rule = (SequenceRuleCall)rule;
     VariablesFallingOutOfScopeOnLeavingFor = variablesFallingOutOfScopeOnLeavingFor;
 }
Example #31
0
 public SequenceRuleCountAllCall(RuleInvocationParameterBindings paramBindings, 
     bool special, bool test, SequenceVariable countResult, List<FilterCall> filters)
     : base(paramBindings, special, test, filters)
 {
     SequenceType = SequenceType.RuleCountAllCall;
     CountResult = countResult;
 }
Example #32
0
 public SequenceDefinitionInterpreted(String sequenceName,
     SequenceVariable[] inputVariables,
     SequenceVariable[] outputVariables,
     Sequence seq)
     : base(SequenceType.SequenceDefinitionInterpreted, sequenceName)
 {
     InputVariables = inputVariables;
     OutputVariables = outputVariables;
     Seq = seq;
 }
Example #33
0
 public SequenceAssignToVar(SequenceVariable destVar, SequenceType seqType)
     : base(seqType)
 {
     DestVar = destVar;
 }
Example #34
0
 public SequenceExecuteInSubgraph(SequenceVariable subgraphVar, String attributeName, Sequence seq)
     : base(seq, SequenceType.ExecuteInSubgraph)
 {
     SubgraphVar = subgraphVar;
     AttributeName = attributeName;
 }
Example #35
0
        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));
		}
Example #36
0
 public SequenceDeclareVariable(SequenceVariable destVar)
     : base(destVar, null)
 {
     SequenceType = SequenceType.DeclareVariable;
 }
Example #37
0
		// 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;
		}
Example #38
0
 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);
 }
Example #42
0
 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;
 }
Example #44
0
 public SequenceAssignConstToVar(SequenceVariable destVar, object constant)
     : base(destVar, SequenceType.AssignConstToVar)
 {
     Constant = constant;
 }
Example #45
0
 public SequenceComputationContainerClear(SequenceVariable container)
     : base(SequenceComputationType.ContainerClear, container)
 {
 }
Example #46
0
 public SequenceExpressionVariable(SequenceVariable var)
     : base(SequenceExpressionType.Variable)
 {
     Variable = var;
 }
Example #47
0
 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;
 }
Example #48
0
 public SequenceAssignUserInputToVar(SequenceVariable destVar, String type)
     : base(destVar, SequenceType.AssignUserInputToVar)
 {
     Type = type;
 }