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)); } }
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) ?? ""); } }
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)); } }
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); }
public override string Type(SequenceCheckingEnvironment env) { if (DestVar.Type == "") { return(""); } InheritanceType inheritanceType = TypesHelper.GetInheritanceType(DestVar.Type, env.Model); AttributeType attributeType = inheritanceType.GetAttributeType(AttributeName); return(TypesHelper.AttributeTypeToXgrsType(attributeType)); }
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) ?? ""; }
/// <summary> /// Returns a string representation of the given non-container value /// </summary> /// <param name="value">The scalar value of which to get the string representation</param> /// <param name="type">The type as string, e.g int,string,Foo </param> /// <param name="content">The content as string, e.g. 42,"foo",bar } </param> /// <param name="attrType">The attribute type of the value (may be null)</param> /// <param name="graph">The graph with the model and the element names</param> public static void ToString(object value, out string type, out string content, AttributeType attrType, IGraph graph) { if (attrType == null) { ToString(value, out type, out content, graph); return; } Debug.Assert(attrType.Kind != AttributeKind.SetAttr && attrType.Kind != AttributeKind.MapAttr && attrType.Kind != AttributeKind.ArrayAttr && attrType.Kind != AttributeKind.DequeAttr); type = TypesHelper.AttributeTypeToXgrsType(attrType); if (type == "object") { content = ToStringObject(value, attrType, graph); } else { content = ToString(value, attrType, graph); } }
/// <summary> /// Returns a string representation of the given non-container value /// </summary> /// <param name="value">The scalar value of which to get the string representation</param> /// <param name="type">The type as string, e.g int,string,Foo </param> /// <param name="content">The content as string, e.g. 42,"foo",bar } </param> /// <param name="attrType">The attribute type of the value (may be null)</param> /// <param name="graph">The graph with the model and the element names</param> /// <param name="firstLevelObjectEmitted">Prevents emitting of further objects and thus infinite regressions</param> /// <param name="nameToObject">If not null, the names of visited objects are added</param> /// <param name="procEnv">If not null, the processing environment is used for transient object unique id emitting and fetching</param> public static void ToString(object value, out string type, out string content, AttributeType attrType, IGraph graph, bool firstLevelObjectEmitted, IDictionary <string, IObject> nameToObject, IGraphProcessingEnvironment procEnv) { if (attrType == null) { ToString(value, out type, out content, graph, firstLevelObjectEmitted, nameToObject, procEnv); return; } Debug.Assert(attrType.Kind != AttributeKind.SetAttr && attrType.Kind != AttributeKind.MapAttr && attrType.Kind != AttributeKind.ArrayAttr && attrType.Kind != AttributeKind.DequeAttr); type = TypesHelper.AttributeTypeToXgrsType(attrType); if (type == "object") { content = ToStringObject(value, attrType, graph); } else { content = ToString(value, attrType, graph, firstLevelObjectEmitted, nameToObject, procEnv); } }