Exemplo n.º 1
0
 public override string TypeOfMemberOrAttribute(string matchOrGraphElementType, string memberOrAttribute)
 {
     if (matchOrGraphElementType.StartsWith("match<class "))
     {
         String          matchClassName = TypesHelper.GetMatchClassName(matchOrGraphElementType);
         IMatchClass     matchClass     = actionsTypeInformation.matchClasses[matchClassName];
         IPatternElement element        = matchClass.GetPatternElement(memberOrAttribute);
         if (element == null)
         {
             throw new SequenceParserException(memberOrAttribute, SequenceParserError.UnknownMatchMember);
         }
         GrGenType elementType = element.Type;
         return(TypesHelper.DotNetTypeToXgrsType(elementType));
     }
     else if (matchOrGraphElementType.StartsWith("match<"))
     {
         String ruleName = TypesHelper.GetRuleName(matchOrGraphElementType);
         if (!actionsTypeInformation.rulesToTopLevelEntities[ruleName].Contains(memberOrAttribute))
         {
             throw new SequenceParserException(memberOrAttribute, SequenceParserError.UnknownMatchMember);
         }
         int indexOfEntity = actionsTypeInformation.rulesToTopLevelEntities[ruleName].IndexOf(memberOrAttribute);
         return(actionsTypeInformation.rulesToTopLevelEntityTypes[ruleName][indexOfEntity]);
     }
     else
     {
         GrGenType     graphElementType = TypesHelper.GetNodeOrEdgeType(matchOrGraphElementType, Model);
         AttributeType attributeType    = graphElementType.GetAttributeType(memberOrAttribute);
         if (attributeType == null)
         {
             throw new SequenceParserException(memberOrAttribute, SequenceParserError.UnknownAttribute);
         }
         return(TypesHelper.AttributeTypeToXgrsType(attributeType));
     }
 }
Exemplo n.º 2
0
 public override string TypeOfMemberOrAttribute(string matchOrGraphElementType, string memberOrAttribute)
 {
     if (matchOrGraphElementType.StartsWith("match<class "))
     {
         MatchClassFilterer matchClass = actions.GetMatchClass(TypesHelper.GetMatchClassName(matchOrGraphElementType));
         IPatternElement    element    = matchClass.info.GetPatternElement(memberOrAttribute);
         if (element == null)
         {
             throw new SequenceParserException(memberOrAttribute, SequenceParserError.UnknownMatchMember);
         }
         GrGenType elementType = element.Type;
         return(TypesHelper.DotNetTypeToXgrsType(elementType));
     }
     else if (matchOrGraphElementType.StartsWith("match<"))
     {
         IAction         action  = actions.GetAction(TypesHelper.GetRuleName(matchOrGraphElementType));
         IPatternElement element = action.RulePattern.PatternGraph.GetPatternElement(memberOrAttribute);
         if (element == null)
         {
             throw new SequenceParserException(memberOrAttribute, SequenceParserError.UnknownMatchMember);
         }
         GrGenType elementType = element.Type;
         return(TypesHelper.DotNetTypeToXgrsType(elementType));
     }
     else
     {
         GrGenType     graphElementType = TypesHelper.GetNodeOrEdgeType(matchOrGraphElementType, Model);
         AttributeType attributeType    = graphElementType.GetAttributeType(memberOrAttribute);
         if (attributeType == null)
         {
             throw new SequenceParserException(memberOrAttribute, SequenceParserError.UnknownAttribute);
         }
         return(TypesHelper.AttributeTypeToXgrsType(attributeType));
     }
 }
Exemplo n.º 3
0
        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) ?? "");
            }
        }
Exemplo n.º 4
0
        public override string Type(SequenceCheckingEnvironment env)
        {
            if(DestVar.Type == "")
                return "";

            GrGenType nodeOrEdgeType = TypesHelper.GetNodeOrEdgeType(DestVar.Type, env.Model);
            AttributeType attributeType = nodeOrEdgeType.GetAttributeType(AttributeName);
            return TypesHelper.AttributeTypeToXgrsType(attributeType);
        }
Exemplo n.º 5
0
        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

            GrGenType nodeOrEdgeType = TypesHelper.GetNodeOrEdgeType(DestVar.Type, env.Model);
            if(nodeOrEdgeType == null)
                throw new SequenceParserException(Symbol, "node or edge type", DestVar.Type);
            AttributeType attributeType = nodeOrEdgeType.GetAttributeType(AttributeName);
            if(attributeType == null)
                throw new SequenceParserException(AttributeName, SequenceParserError.UnknownAttribute);
        }
Exemplo n.º 6
0
        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
            }
            GrGenType nodeOrEdgeType = TypesHelper.GetNodeOrEdgeType(DestVar.Type, env.Model);

            if (nodeOrEdgeType == null)
            {
                throw new SequenceParserException(Symbol, "node or edge type", DestVar.Type);
            }
            AttributeType attributeType = nodeOrEdgeType.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));
                }
            }
        }
Exemplo n.º 7
0
        private static void ReadAttributes(IGraphElement elem, XmlElement xmlelem)
        {
            GrGenType type = elem.Type;

            foreach (XmlElement attrelem in xmlelem.GetElementsByTagName("attr"))
            {
                String        attrname = attrelem.GetAttribute("name");
                String        attrval  = attrelem.InnerText;
                AttributeType attrType = type.GetAttributeType(attrname);

                object value = null;
                switch (attrType.Kind)
                {
                case AttributeKind.BooleanAttr:
                    if (attrval.Equals("true", StringComparison.OrdinalIgnoreCase))
                    {
                        value = true;
                    }
                    else if (attrval.Equals("false", StringComparison.OrdinalIgnoreCase))
                    {
                        value = false;
                    }
                    else
                    {
                        throw new Exception("Attribute \"" + attrname + "\" must be either \"true\" or \"false\"!");
                    }
                    break;

                case AttributeKind.EnumAttr:
                {
                    int val;
                    if (Int32.TryParse(attrval, out val))
                    {
                        value = val;
                    }
                    else
                    {
                        foreach (EnumMember member in attrType.EnumType.Members)
                        {
                            if (attrval == member.Name)
                            {
                                value = member.Value;
                                break;
                            }
                        }
                        if (value == null)
                        {
                            String errorText = "Attribute \"" + attrname + "\" must be one of the following values:";
                            foreach (EnumMember member in attrType.EnumType.Members)
                            {
                                errorText += " - " + member.Name + " = " + member.Value;
                            }
                            throw new Exception(errorText);
                        }
                    }
                    break;
                }

                case AttributeKind.ByteAttr:
                {
                    sbyte val;
                    if (!SByte.TryParse(attrval, out val))
                    {
                        throw new Exception("Attribute \"" + attrname + "\" must be a byte (signed)!");
                    }
                    value = val;
                    break;
                }

                case AttributeKind.ShortAttr:
                {
                    short val;
                    if (!Int16.TryParse(attrval, out val))
                    {
                        throw new Exception("Attribute \"" + attrname + "\" must be a short!");
                    }
                    value = val;
                    break;
                }

                case AttributeKind.IntegerAttr:
                {
                    int val;
                    if (!Int32.TryParse(attrval, out val))
                    {
                        throw new Exception("Attribute \"" + attrname + "\" must be an integer!");
                    }
                    value = val;
                    break;
                }

                case AttributeKind.LongAttr:
                {
                    long val;
                    if (!Int64.TryParse(attrval, out val))
                    {
                        throw new Exception("Attribute \"" + attrname + "\" must be a long!");
                    }
                    value = val;
                    break;
                }

                case AttributeKind.StringAttr:
                    value = attrval;
                    break;

                case AttributeKind.FloatAttr:
                {
                    float val;
                    if (!Single.TryParse(attrval, System.Globalization.NumberStyles.Float,
                                         System.Globalization.CultureInfo.InvariantCulture, out val))
                    {
                        throw new Exception("Attribute \"" + attrname + "\" must be a floating point number!");
                    }
                    value = val;
                    break;
                }

                case AttributeKind.DoubleAttr:
                {
                    double val;
                    if (!Double.TryParse(attrval, System.Globalization.NumberStyles.Float,
                                         System.Globalization.CultureInfo.InvariantCulture, out val))
                    {
                        throw new Exception("Attribute \"" + attrname + "\" must be a floating point number!");
                    }
                    value = val;
                    break;
                }

                case AttributeKind.ObjectAttr:
                {
                    throw new Exception("Attribute \"" + attrname + "\" is an object type attribute!\n"
                                        + "It is not possible to assign a value to an object type attribute!");
                }

                case AttributeKind.SetAttr:
                case AttributeKind.MapAttr:
                case AttributeKind.ArrayAttr:
                case AttributeKind.DequeAttr:
                default:
                    throw new Exception("Unsupported attribute value type: \"" + attrType.Kind + "\"");     // TODO: support set=SetAttr and seq=ArrayAttr, here and in export
                }

                elem.SetAttribute(attrname, value);
            }
        }
Exemplo n.º 8
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>());
                    }
                }
            }
        }