Beispiel #1
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
     {
         InheritanceType inheritanceType = TypesHelper.GetInheritanceType(matchOrGraphElementType, Model);
         AttributeType   attributeType   = inheritanceType.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) ?? "");
            }
        }
Beispiel #3
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;
            }

            InheritanceType ownerType = TypesHelper.GetInheritanceType(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);
        }
Beispiel #4
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
     {
         InheritanceType inheritanceType = TypesHelper.GetInheritanceType(matchOrGraphElementType, Model);
         AttributeType   attributeType   = inheritanceType.GetAttributeType(memberOrAttribute);
         if (attributeType == null)
         {
             throw new SequenceParserException(memberOrAttribute, SequenceParserError.UnknownAttribute);
         }
         return(TypesHelper.AttributeTypeToXgrsType(attributeType));
     }
 }
Beispiel #5
0
 protected override int NumOutputParameters(Invocation invocation, InheritanceType 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");
 }
Beispiel #6
0
 protected override string OutputParameterType(int i, Invocation invocation, InheritanceType 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 Type(SequenceCheckingEnvironment env)
        {
            if (DestVar.Type == "")
            {
                return("");
            }

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

            return(TypesHelper.AttributeTypeToXgrsType(attributeType));
        }
Beispiel #8
0
 protected override string InputParameterType(int i, Invocation invocation, InheritanceType 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");
 }
        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));
                }
            }
        }
Beispiel #10
0
 /// <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, InheritanceType 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;
 }
        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);
            }
        }
Beispiel #12
0
 protected override int NumOutputParameters(Invocation invocation, InheritanceType 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");
 }
Beispiel #13
0
        /// <summary>
        /// Helper for checking procedure calls.
        /// Type checks the input, type checks the output.
        /// Throws an exception when an error is found.
        /// </summary>
        /// <param name="seqCompProcCall">The procedure call to check</param>
        /// <param name="ownerType">Gives the owner type of the procedure method call, in case this is a method call, otherwise null</param>
        private void CheckProcedureCallBase(SequenceComputationProcedureCall seqCompProcCall, InheritanceType ownerType)
        {
            CheckInputParameters(seqCompProcCall, seqCompProcCall.ArgumentExpressions, ownerType);
            CheckOutputParameters(seqCompProcCall, seqCompProcCall.ReturnVars, ownerType);

            // ok, this is a well-formed invocation
        }
Beispiel #14
0
 protected abstract string OutputParameterType(int i, Invocation invocation, InheritanceType ownerType);
Beispiel #15
0
 protected abstract int NumOutputParameters(Invocation invocation, InheritanceType ownerType);
Beispiel #16
0
        private void CheckOutputParameters(Invocation invocation, SequenceVariable[] ReturnVars, InheritanceType ownerType)
        {
            // Check whether number of parameters and return parameters match
            if (ReturnVars.Length != 0 && NumOutputParameters(invocation, ownerType) != ReturnVars.Length)
            {
                throw new SequenceParserException(invocation, ReturnVars.Length, SequenceParserError.BadNumberOfReturnParameters);
            }

            // Check return types
            for (int i = 0; i < ReturnVars.Length; ++i)
            {
                String argumentType = ReturnVars[i].Type;
                String paramterType = OutputParameterType(i, invocation, ownerType);
                if (!TypesHelper.IsSameOrSubtype(paramterType, argumentType, Model))
                {
                    throw new SequenceParserException(invocation, -1, SequenceParserError.BadReturnParameter, i);
                }
            }
        }
Beispiel #17
0
        private void CheckInputParameters(Invocation invocation, SequenceExpression[] ArgumentExpressions, InheritanceType ownerType)
        {
            // Check whether number of parameters and return parameters match
            if (NumInputParameters(invocation, ownerType) != ArgumentExpressions.Length)
            {
                throw new SequenceParserException(invocation, ArgumentExpressions.Length, SequenceParserError.BadNumberOfParameters);
            }

            // Check parameter types
            for (int i = 0; i < ArgumentExpressions.Length; i++)
            {
                ArgumentExpressions[i].Check(this);

                String argumentType = ArgumentExpressions[i].Type(this);
                String paramterType = InputParameterType(i, invocation, ownerType);
                if (!TypesHelper.IsSameOrSubtype(argumentType, paramterType, Model))
                {
                    throw new SequenceParserException(invocation, -1, SequenceParserError.BadParameter, i);
                }
            }
        }
Beispiel #18
0
        /// <summary>
        /// Helper for checking function calls.
        /// Type checks the input.
        /// Throws an exception when an error is found.
        /// </summary>
        /// <param name="seqExprFuncCall">The function call to check</param>
        /// <param name="ownerType">Gives the owner type of the function method call, in case this is a method call, otherwise null</param>
        private void CheckFunctionCallBase(SequenceExpressionFunctionCall seqExprFuncCall, InheritanceType ownerType)
        {
            CheckInputParameters(seqExprFuncCall, seqExprFuncCall.ArgumentExpressions, ownerType);

            // ok, this is a well-formed invocation
        }