public override string Type(SequenceCheckingEnvironment env)
        {
            if (DestVar.Type == "")
            {
                return("");
            }

            InheritanceType inheritanceType = TypesHelper.GetInheritanceType(DestVar.Type, env.Model);
            AttributeType   attributeType   = inheritanceType.GetAttributeType(AttributeName);

            if (attributeType == null)
            {
                return(""); // error, will be reported by Check, just ensure we don't crash here
            }
            string ContainerType = TypesHelper.AttributeTypeToXgrsType(attributeType);

            if (DestVar.Type.StartsWith("map"))
            {
                return(TypesHelper.ExtractDst(DestVar.Type) ?? "");
            }
            else
            {
                return(TypesHelper.ExtractSrc(DestVar.Type) ?? "");
            }
        }
Esempio n. 2
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));
                }
            }
        }
 public override string Type(SequenceCheckingEnvironment env)
 {
     if(DestVar.Type.StartsWith("map"))
         return TypesHelper.ExtractDst(DestVar.Type) ?? "";
     else
         return TypesHelper.ExtractSrc(DestVar.Type) ?? "";
 }
        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));
                }
            }
        }
        public override string Type(SequenceCheckingEnvironment env)
        {
            if(DestVar.Type == "")
                return "";

            GrGenType nodeOrEdgeType = TypesHelper.GetNodeOrEdgeType(DestVar.Type, env.Model);
            AttributeType attributeType = nodeOrEdgeType.GetAttributeType(AttributeName);
            if(attributeType == null)
                return ""; // error, will be reported by Check, just ensure we don't crash here

            string ContainerType = TypesHelper.AttributeTypeToXgrsType(attributeType);

            if(DestVar.Type.StartsWith("map"))
                return TypesHelper.ExtractDst(DestVar.Type) ?? "";
            else
                return TypesHelper.ExtractSrc(DestVar.Type) ?? "";
        }
Esempio n. 6
0
        public static IList Extract(object container, string memberOrAttribute, IGraphProcessingEnvironment procEnv)
        {
            IList  array          = (IList)container;
            string arrayType      = TypesHelper.DotNetTypeToXgrsType(array.GetType());
            string arrayValueType = TypesHelper.ExtractSrc(arrayType);

            if (arrayValueType.StartsWith("match<"))
            {
                if (arrayValueType == "match<>")
                {
                    if (array.Count > 0)
                    {
                        IMatch match        = (IMatch)array[0];
                        object matchElement = match.GetMember(memberOrAttribute);
                        Type   matchElementType;
                        if (matchElement is IGraphElement)
                        {
                            matchElementType = TypesHelper.GetType(((IGraphElement)matchElement).Type, procEnv.Graph.Model);
                        }
                        else
                        {
                            matchElementType = matchElement.GetType();
                        }
                        Type  listType       = typeof(List <>).MakeGenericType(matchElementType);
                        IList extractedArray = (IList)Activator.CreateInstance(listType);
                        ExtractMatchMember(array, memberOrAttribute, extractedArray);
                        return(extractedArray);
                    }
                    else
                    {
                        return(new List <object>());
                    }
                }
                else
                {
                    if (arrayValueType.StartsWith("match<class "))
                    {
                        MatchClassFilterer matchClass  = procEnv.Actions.GetMatchClass(TypesHelper.GetMatchClassName(arrayValueType));
                        IPatternElement    element     = matchClass.info.GetPatternElement(memberOrAttribute);
                        GrGenType          elementType = element.Type;
                        Type  listType       = typeof(List <>).MakeGenericType(TypesHelper.GetType(elementType, procEnv.Graph.Model));
                        IList extractedArray = (IList)Activator.CreateInstance(listType);
                        ExtractMatchMember(array, memberOrAttribute, extractedArray);
                        return(extractedArray);
                    }
                    else
                    {
                        IAction         action         = procEnv.Actions.GetAction(TypesHelper.GetRuleName(arrayValueType));
                        IPatternElement element        = action.RulePattern.PatternGraph.GetPatternElement(memberOrAttribute);
                        GrGenType       elementType    = element.Type;
                        Type            listType       = typeof(List <>).MakeGenericType(TypesHelper.GetType(elementType, procEnv.Graph.Model));
                        IList           extractedArray = (IList)Activator.CreateInstance(listType);
                        ExtractMatchMember(array, memberOrAttribute, extractedArray);
                        return(extractedArray);
                    }
                }
            }
            else
            {
                GrGenType graphElementType = TypesHelper.GetNodeOrEdgeType(arrayValueType, procEnv.Graph.Model);
                if (graphElementType != null)
                {
                    AttributeType attributeType  = graphElementType.GetAttributeType(memberOrAttribute);
                    Type          listType       = typeof(List <>).MakeGenericType(attributeType.Type);
                    IList         extractedArray = (IList)Activator.CreateInstance(listType);
                    ExtractAttribute(array, memberOrAttribute, extractedArray);
                    return(extractedArray);
                }
                else
                {
                    if (array.Count > 0)
                    {
                        IGraphElement graphElement = (IGraphElement)array[0];
                        object        element      = graphElement.GetAttribute(memberOrAttribute);
                        Type          elementType;
                        if (element is IGraphElement)
                        {
                            elementType = TypesHelper.GetType(((IGraphElement)element).Type, procEnv.Graph.Model);
                        }
                        else
                        {
                            elementType = element.GetType();
                        }
                        Type  listType       = typeof(List <>).MakeGenericType(elementType);
                        IList extractedArray = (IList)Activator.CreateInstance(listType);
                        ExtractAttribute(array, memberOrAttribute, extractedArray);
                        return(extractedArray);
                    }
                    else
                    {
                        return(new List <object>());
                    }
                }
            }
        }