Example #1
0
        public override void Check(SequenceCheckingEnvironment env)
        {
            base.Check(env);

            if (DestVar.Type == "")
            {
                return; // we can't check source and destination types if the variable is untyped, only runtime-check possible
            }
            if (TypesHelper.ExtractSrc(DestVar.Type) == null || TypesHelper.ExtractDst(DestVar.Type) == null || TypesHelper.ExtractDst(DestVar.Type) == "SetValueType")
            {
                throw new SequenceParserException(Symbol, "map<S,T> or array<T> or deque<T>", DestVar.Type);
            }
            if (DestVar.Type.StartsWith("array"))
            {
                if (!TypesHelper.IsSameOrSubtype(KeyExpression.Type(env), "int", env.Model))
                {
                    throw new SequenceParserException(Symbol, "int", KeyExpression.Type(env));
                }
            }
            else if (DestVar.Type.StartsWith("deque"))
            {
                if (!TypesHelper.IsSameOrSubtype(KeyExpression.Type(env), "int", env.Model))
                {
                    throw new SequenceParserException(Symbol, "int", KeyExpression.Type(env));
                }
            }
            else
            {
                if (!TypesHelper.IsSameOrSubtype(KeyExpression.Type(env), TypesHelper.ExtractSrc(DestVar.Type), env.Model))
                {
                    throw new SequenceParserException(Symbol, TypesHelper.ExtractSrc(DestVar.Type), KeyExpression.Type(env));
                }
            }
        }
Example #2
0
        public string ExtractEdgeType(SourceBuilder source, SequenceExpression typeExpr)
        {
            string incidentEdgeType = "graph.Model.EdgeModel.RootType";

            if (typeExpr != null)
            {
                if (typeExpr.Type(env) != "")
                {
                    if (typeExpr.Type(env) == "string")
                    {
                        incidentEdgeType = "graph.Model.EdgeModel.GetType((string)" + exprGen.GetSequenceExpression(typeExpr, source) + ")";
                    }
                    else
                    {
                        incidentEdgeType = "(GRGEN_LIBGR.EdgeType)" + exprGen.GetSequenceExpression(typeExpr, source);
                    }
                }
                else
                {
                    incidentEdgeType = exprGen.GetSequenceExpression(typeExpr, source) + " is string ? "
                                       + "graph.Model.EdgeModel.GetType((string)" + exprGen.GetSequenceExpression(typeExpr, source) + ")"
                                       + " : " + "(GRGEN_LIBGR.EdgeType)" + exprGen.GetSequenceExpression(typeExpr, source);
                }
            }
            return("(" + incidentEdgeType + ")");
        }
        public override void Check(SequenceCheckingEnvironment env)
        {
            base.Check(env);

            GrGenType nodeOrEdgeType = TypesHelper.GetNodeOrEdgeType(GraphElementVar.Type, env.Model);
            if(GraphElementVar.Type != "" && nodeOrEdgeType == null)
                throw new SequenceParserException(Symbol, "node or edge type", GraphElementVar.Type);
            if(!TypesHelper.IsSameOrSubtype(VisitedFlagExpression.Type(env), "int", env.Model))
                throw new SequenceParserException(Symbol, "int", VisitedFlagExpression.Type(env));
        }
        public override void Check(SequenceCheckingEnvironment env)
        {
            base.Check(env);

            if (DestVar.Type == "")
            {
                return; // we can't gain access to an attribute type if the variable is untyped, only runtime-check possible
            }
            InheritanceType inheritanceType = TypesHelper.GetInheritanceType(DestVar.Type, env.Model);

            if (inheritanceType == null)
            {
                throw new SequenceParserException(Symbol, "node or edge or object or transient object type (class)", DestVar.Type);
            }
            AttributeType attributeType = inheritanceType.GetAttributeType(AttributeName);

            if (attributeType == null)
            {
                throw new SequenceParserException(AttributeName, SequenceParserError.UnknownAttribute);
            }

            string ContainerType = TypesHelper.AttributeTypeToXgrsType(attributeType);

            if (TypesHelper.ExtractSrc(ContainerType) == null ||
                TypesHelper.ExtractDst(ContainerType) == null ||
                TypesHelper.ExtractDst(ContainerType) == "SetValueType")
            {
                throw new SequenceParserException(Symbol, "map<S,T> or array<T> or deque<T>", DestVar.Type);
            }
            if (ContainerType.StartsWith("array"))
            {
                if (!TypesHelper.IsSameOrSubtype(KeyExpression.Type(env), "int", env.Model))
                {
                    throw new SequenceParserException(Symbol, "int", KeyExpression.Type(env));
                }
            }
            else if (ContainerType.StartsWith("deque"))
            {
                if (!TypesHelper.IsSameOrSubtype(KeyExpression.Type(env), "int", env.Model))
                {
                    throw new SequenceParserException(Symbol, "int", KeyExpression.Type(env));
                }
            }
            else
            {
                if (!TypesHelper.IsSameOrSubtype(KeyExpression.Type(env), TypesHelper.ExtractSrc(ContainerType), env.Model))
                {
                    throw new SequenceParserException(Symbol, TypesHelper.ExtractSrc(ContainerType), KeyExpression.Type(env));
                }
            }
        }
Example #5
0
        /// <summary>
        /// Helper for checking function method calls.
        /// Checks whether called entity exists, and type checks the input.
        /// Throws an exception when an error is found.
        /// </summary>
        /// <param name="seqExprFuncMethodCall">The function method call to check</param>
        /// <param name="targetExpr">The target of the procedure function call</param>
        public void CheckFunctionMethodCall(SequenceExpression targetExpr, SequenceExpressionFunctionMethodCall seqExprFuncMethodCall)
        {
            String targetExprType = targetExpr.Type(this);

            if (targetExprType == "")
            {
                // 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(targetExprType, Model);

            if (ownerType == null)
            {
                // error, must be node or edge type
                throw new SequenceParserException(targetExprType, SequenceParserError.UserMethodsOnlyAvailableForGraphElements);
            }

            // check whether called function method exists
            if (ownerType.GetFunctionMethod(seqExprFuncMethodCall.Name) == null)
            {
                throw new SequenceParserException(seqExprFuncMethodCall, -1, SequenceParserError.UnknownProcedure);
            }

            CheckFunctionCallBase(seqExprFuncMethodCall, ownerType);
        }
Example #6
0
        protected string GetTypeString(SequenceCheckingEnvironment env, SequenceExpression typeExpr)
        {
            if (typeExpr.Type(env) == "string")
            {
                if (typeExpr is SequenceExpressionConstant)
                {
                    return((string)((SequenceExpressionConstant)typeExpr).Constant);
                }
            }
            else
            {
                return(typeExpr.Type(env));
            }

            return(null);
        }
Example #7
0
        protected void CheckEdgeTypeIsKnown(SequenceCheckingEnvironment env, SequenceExpression typeExpr, String whichArgument)
        {
            if (typeExpr == null || typeExpr.Type(env) == "")
            {
                return;
            }

            string typeString = GetTypeString(env, typeExpr);

            if (TypesHelper.GetEdgeType(typeString, env.Model) == null && typeString != null)
            {
                throw new SequenceParserException(Symbol + whichArgument, "edge type or string denoting edge type", typeString);
            }
        }