/// <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); }
protected override string OutputParameterType(int i, Invocation invocation, GrGenType ownerType) { if (invocation is RuleInvocation) { RuleInvocation ruleInvocation = (RuleInvocation)invocation; return(actionsTypeInformation.rulesToOutputTypes[ruleInvocation.PackagePrefixedName][i]); } else if (invocation is SequenceInvocation) { SequenceInvocation seqInvocation = (SequenceInvocation)invocation; return(actionsTypeInformation.sequencesToOutputTypes[seqInvocation.PackagePrefixedName][i]); } else if (invocation is ProcedureInvocation) { ProcedureInvocation procInvocation = (ProcedureInvocation)invocation; if (ownerType != null) { IProcedureDefinition procDef = ownerType.GetProcedureMethod(procInvocation.Name); return(TypesHelper.DotNetTypeToXgrsType(procDef.Outputs[i])); } else { return(actionsTypeInformation.proceduresToOutputTypes[procInvocation.PackagePrefixedName][i]); } } throw new Exception("Internal error"); }
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 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 static Type GetType(GrGenType type, IGraphModel model) { if (type is NodeType) { NodeType nodeType = (NodeType)type; if (Type.GetType(nodeType.NodeInterfaceName) != null) // available in libGr (INode)? { return(Type.GetType(nodeType.NodeInterfaceName)); } else { return(Type.GetType(nodeType.NodeInterfaceName + "," + Assembly.GetAssembly(model.GetType()).FullName)); // no -> search model assembly } } else if (type is EdgeType) { EdgeType edgeType = (EdgeType)type; if (Type.GetType(edgeType.EdgeInterfaceName) != null) // available in libGr (INode)? { return(Type.GetType(edgeType.EdgeInterfaceName)); } else { return(Type.GetType(edgeType.EdgeInterfaceName + "," + Assembly.GetAssembly(model.GetType()).FullName)); // no -> search model assembly } } else { VarType varType = (VarType)type; return(varType.Type); } }
protected override int NumOutputParameters(Invocation invocation, GrGenType ownerType) { if (invocation is RuleInvocation) { RuleInvocation ruleInvocation = (RuleInvocation)invocation; return(actionsTypeInformation.rulesToOutputTypes[ruleInvocation.PackagePrefixedName].Count); } else if (invocation is SequenceInvocation) { SequenceInvocation seqInvocation = (SequenceInvocation)invocation; return(actionsTypeInformation.sequencesToOutputTypes[seqInvocation.PackagePrefixedName].Count); } else if (invocation is ProcedureInvocation) { ProcedureInvocation procInvocation = (ProcedureInvocation)invocation; if (ownerType != null) { IProcedureDefinition procDef = ownerType.GetProcedureMethod(procInvocation.Name); return(procDef.Outputs.Length); } else { return(actionsTypeInformation.proceduresToOutputTypes[procInvocation.PackagePrefixedName].Count); } } throw new Exception("Internal error"); }
public AttributeIndexDescription(string name, GrGenType graphElementType, AttributeType attributeType) : base(name) { GraphElementType = graphElementType; AttributeType = attributeType; }
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) ?? ""); } }
private void TypeInfotagsChanged(GrGenType type) { TypeInfotagsChangedHandler handler = OnTypeInfotagsChanged; if (handler != null) { handler(type); } }
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); }
/// <summary> /// Checks, whether this type is compatible to the given type, i.e. this type is the same type as the given type /// or it is a sub type of the given type. /// </summary> /// <param name="other">The type to be compared to.</param> /// <returns>True, if this type is compatible to the given type.</returns> public override bool IsA(GrGenType other) { VarType o = other as VarType; if (o == null) { return(false); } return(o.type.IsAssignableFrom(type)); }
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)); }
/// <summary> /// Returns the label of the given element type or null for the default case. /// </summary> /// <param name="type">The element type.</param> /// <returns>The label or null.</returns> public String GetElemTypeLabel(GrGenType type) { String res; if (!elemTypeLabel.TryGetValue(type, out res)) { return(null); } return(res); }
/// <summary> /// Associates an InfoTag to a GrGenType. /// </summary> /// <param name="type">The GrGenType to given an InfoTag</param> /// <param name="infotag">The InfoTag</param> public void AddTypeInfoTag(GrGenType type, InfoTag infoTag) { List <InfoTag> typeInfoTags; if (!infoTags.TryGetValue(type, out typeInfoTags)) { infoTags[type] = typeInfoTags = new List <InfoTag>(); } typeInfoTags.Add(infoTag); TypeInfotagsChanged(type); }
private Rule_testRule() { name = "testRule"; inputs = new GRGEN_LIBGR.GrGenType[] { }; inputNames = new string[] { }; defs = new GRGEN_LIBGR.GrGenType[] { }; defNames = new string[] { }; outputs = new GRGEN_LIBGR.GrGenType[] { }; filters = new GRGEN_LGSP.LGSPFilter[] { }; }
protected override string InputParameterType(int i, Invocation invocation, GrGenType ownerType) { if (invocation is RuleInvocation) { RuleInvocation ruleInvocation = (RuleInvocation)invocation; IAction action = SequenceBase.GetAction(ruleInvocation); return(TypesHelper.DotNetTypeToXgrsType(action.RulePattern.Inputs[i])); } else if (invocation is SequenceInvocation) { SequenceSequenceCallInterpreted seqInvocation = (SequenceSequenceCallInterpreted)invocation; if (seqInvocation.SequenceDef is SequenceDefinitionInterpreted) { SequenceDefinitionInterpreted seqDef = (SequenceDefinitionInterpreted)seqInvocation.SequenceDef; return(seqDef.InputVariables[i].Type); } else { SequenceDefinitionCompiled seqDef = (SequenceDefinitionCompiled)seqInvocation.SequenceDef; return(TypesHelper.DotNetTypeToXgrsType(seqDef.SeqInfo.ParameterTypes[i])); } } else if (invocation is ProcedureInvocation) { ProcedureInvocation procInvocation = (ProcedureInvocation)invocation; if (ownerType != null) { IProcedureDefinition procDef = ownerType.GetProcedureMethod(procInvocation.Name); return(TypesHelper.DotNetTypeToXgrsType(procDef.Inputs[i])); } else { SequenceComputationProcedureCallInterpreted procInvocationInterpreted = (SequenceComputationProcedureCallInterpreted)procInvocation; return(TypesHelper.DotNetTypeToXgrsType(procInvocationInterpreted.ProcedureDef.Inputs[i])); } } else if (invocation is FunctionInvocation) { FunctionInvocation funcInvocation = (FunctionInvocation)invocation; if (ownerType != null) { IFunctionDefinition funcDef = ownerType.GetFunctionMethod(funcInvocation.Name); return(TypesHelper.DotNetTypeToXgrsType(funcDef.Inputs[i])); } else { SequenceExpressionFunctionCallInterpreted funcInvocationInterpreted = (SequenceExpressionFunctionCallInterpreted)funcInvocation; return(TypesHelper.DotNetTypeToXgrsType(funcInvocationInterpreted.FunctionDef.Inputs[i])); } } throw new Exception("Internal error"); }
/// <summary> /// Returns a list of InfoTag objects for the given GrGenType or null. /// </summary> /// <param name="type">The GrGenType to be examined.</param> /// <returns>A list of associated InfoTag objects or null.</returns> public List <InfoTag> GetTypeInfoTags(GrGenType type) { List <InfoTag> typeInfoTags; if (!infoTags.TryGetValue(type, out typeInfoTags)) { return(null); } else { return(typeInfoTags); } }
/// <summary> /// Constructs a FunctionInfo object. /// </summary> /// <param name="name">The name the function was defined with.</param> /// <param name="package">null if this is a global pattern graph, otherwise the package the pattern graph is contained in.</param> /// <param name="packagePrefixedName">The name of the pattern graph in case of a global type, /// the name of the pattern graph is prefixed by the name of the package otherwise (package "::" name).</param> /// <param name="isExternal">Tells whether the function is an externally defined one or an internal one.</param> /// <param name="inputNames">The names of the input parameters.</param> /// <param name="inputs">The types of the input parameters.</param> /// <param name="output">The type of the output parameter.</param> public FunctionInfo(String name, String package, String packagePrefixedName, bool isExternal, String[] inputNames, GrGenType[] inputs, GrGenType output) { this.name = name; this.package = package; this.packagePrefixedName = packagePrefixedName; this.isExternal = isExternal; this.inputNames = inputNames; this.inputs = inputs; this.output = output; this.annotations = new Annotations(); }
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); }
public static String DotNetTypeToXgrsType(GrGenType type) { if (type is VarType) { Type typeOfVar = ((VarType)type).Type; if (typeOfVar.IsGenericType) { return(DotNetTypeToXgrsType(typeOfVar)); } return(DotNetTypeToXgrsType(type.Name, typeOfVar.FullName)); } return(type.PackagePrefixedName); }
/// <summary> /// Returns C# type string /// </summary> public static String TypeName(GrGenType type) { if (type is VarType) { Type typeOfVar = ((VarType)type).Type; if (typeOfVar.IsGenericType) { StringBuilder sb = new StringBuilder(); sb.Append(typeOfVar.FullName.Substring(0, typeOfVar.FullName.IndexOf('`'))); sb.Append('<'); bool first = true; foreach (Type typeArg in typeOfVar.GetGenericArguments()) { if (first) { first = false; } else { sb.Append(", "); } sb.Append(typeArg.FullName.Replace("+", ".")); } sb.Append('>'); return(sb.ToString()); } return(typeOfVar.FullName); } else { switch (type.Name) { case "Node": return("GRGEN_LIBGR.INode"); case "Edge": return("GRGEN_LIBGR.IDEdge"); case "UEdge": return("GRGEN_LIBGR.IUEdge"); case "AEdge": return("GRGEN_LIBGR.IEdge"); case "Object": return("GRGEN_LIBGR.IObject"); case "TransientObject": return("GRGEN_LIBGR.ITransientObject"); default: return("GRGEN_MODEL." + GetPackagePrefixDot(type.Package) + "I" + type.Name); } } }
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)); } } }
/// <summary> /// Initializes an AttributeType instance. /// </summary> /// <param name="name">The name for the attribute.</param> /// <param name="ownerType">The owner model type.</param> /// <param name="kind">The kind of the attribute.</param> /// <param name="enumType">The enum type description, if Kind == AttributeKind.EnumAttr, otherwise null.</param> /// <param name="valueType">The attribute type of the value of the set, if Kind == AttributeKind.SetAttr; the attribute type of the value of the map, if Kind == AttributeKind.MapAttr; the attribute type of the value of the array, if Kind == AttributeKind.ArrayAttr; the attribute type of the value of the deque, if Kind == AttributeKind.DequeAttr; otherwise null. </param> /// <param name="keyType">The attribute type of the key of the map, if Kind == AttributeKind.MapAttr; otherwise null.</param> /// <param name="typeName">The name of the attribute type, if Kind == AttributeKind.NodeAttr || Kind == AttributeKind.EdgeAttr; otherwise null.</param> /// <param name="package">The package name if this is a node or edge type that is contained in a package, otherwise null.</param> /// <param name="packagePrefixedTypeName">The name of the attribute type with the package as prefix if it is contained in a package, if Kind == AttributeKind.NodeAttr || Kind == AttributeKind.EdgeAttr.</param> /// <param name="type">The type of the attribute type.</param> public AttributeType(String name, GrGenType ownerType, AttributeKind kind, EnumAttributeType enumType, AttributeType valueType, AttributeType keyType, String typeName, String package, String packagePrefixedTypeName, Type type) { Name = name; OwnerType = ownerType; Kind = kind; EnumType = enumType; ValueType = valueType; KeyType = keyType; TypeName = typeName; Package = package; PackagePrefixedTypeName = packagePrefixedTypeName; Type = type; }
/// <summary> /// Returns an info tag with the given AttributeType registered for the given element type or null. /// </summary> /// <param name="type">The element type.</param> /// <param name="attrType">The attribute type.</param> /// <returns>The info tag or null.</returns> public InfoTag GetTypeInfoTag(GrGenType type, AttributeType attrType) { List <InfoTag> typeInfoTags; if (infoTags.TryGetValue(type, out typeInfoTags)) { foreach (InfoTag infotag in typeInfoTags) { if (infotag.AttributeType == attrType) { return(infotag); } } } return(null); }
public static String DotNetTypeToXgrsType(GrGenType type) { if (type is VarType) { Type typeOfVar = ((VarType)type).Type; if (typeOfVar.IsGenericType) { if (typeOfVar.Name == "Dictionary`2") { Type keyType; Type valueType; ContainerHelper.GetDictionaryTypes(typeOfVar, out keyType, out valueType); if (valueType.Name == "SetValueType") { return("set<" + DotNetTypeToXgrsType(keyType.Name, keyType.FullName) + ">"); } else { return("map<" + DotNetTypeToXgrsType(keyType.Name, keyType.FullName) + "," + DotNetTypeToXgrsType(valueType.Name, valueType.FullName) + ">"); } } else if (typeOfVar.Name == "List`1") { Type valueType; ContainerHelper.GetListType(typeOfVar, out valueType); return("array<" + DotNetTypeToXgrsType(valueType.Name, valueType.FullName) + ">"); } else if (typeOfVar.Name == "Deque`1") { Type valueType; ContainerHelper.GetDequeType(typeOfVar, out valueType); return("deque<" + DotNetTypeToXgrsType(valueType.Name, valueType.FullName) + ">"); } } return(DotNetTypeToXgrsType(type.Name, typeOfVar.FullName)); } return(type.PackagePrefixedName); }
protected override int NumOutputParameters(Invocation invocation, GrGenType ownerType) { if (invocation is RuleInvocation) { RuleInvocation ruleInvocation = (RuleInvocation)invocation; IAction action = SequenceBase.GetAction(ruleInvocation); return(action.RulePattern.Outputs.Length); } else if (invocation is SequenceInvocation) { SequenceSequenceCallInterpreted seqInvocation = (SequenceSequenceCallInterpreted)invocation; if (seqInvocation.SequenceDef is SequenceDefinitionInterpreted) { SequenceDefinitionInterpreted seqDef = (SequenceDefinitionInterpreted)seqInvocation.SequenceDef; return(seqDef.OutputVariables.Length); } else { SequenceDefinitionCompiled seqDef = (SequenceDefinitionCompiled)seqInvocation.SequenceDef; return(seqDef.SeqInfo.OutParameterTypes.Length); } } else if (invocation is ProcedureInvocation) { ProcedureInvocation procInvocation = (ProcedureInvocation)invocation; if (ownerType != null) { IProcedureDefinition procDef = ownerType.GetProcedureMethod(procInvocation.Name); return(procDef.Outputs.Length); } else { SequenceComputationProcedureCallInterpreted procInvocationInterpreted = (SequenceComputationProcedureCallInterpreted)procInvocation; return(procInvocationInterpreted.ProcedureDef.Outputs.Length); } } throw new Exception("Internal error"); }
/// <summary> /// Sets the labels of the given element type. /// null is the default case, which is "<elemname>:<type>". /// </summary> /// <param name="type">The element type.</param> /// <param name="label">The label or null for the default case.</param> public void SetElemTypeLabel(GrGenType type, String label) { elemTypeLabel[type] = label; }
public bool InstanceOf(GrGenType type) { return(type is VirtualNodeType); }
public override bool IsA(GrGenType other) { return(other is VirtualNodeType); }
public override bool IsA(GRGEN_LIBGR.GrGenType other) { return((this == other) || isA[other.TypeID]); }