Example #1
0
        /// <summary>
        /// Processes authorization node.
        /// </summary>
        /// <param name="node">The node.</param>
        private void Process_Authorization(dynamic node)
        {
            Authorization authorization = context.GetObject(node);

            // Namespace is processed already

            // Name is processed already

            // Interface (obligatory)
            SourceLocationInfo location = new SourceLocationInfo(node.Interface, context);
            try
            {
                authorization.Interface = this.Process_NamespacedTypeReference(node.Interface, typeof(Interface));
            }
            catch (NameNotFoundException exception)
            {
                Error_NameNotFound(location, exception);
            }
            catch (NameCollisionException exception)
            {
                Error_NameCollision(location, exception);
            }

            // OperationAuthorizations are not processed in this phase
        }
Example #2
0
        /// <summary>
        /// Processes namespace node.
        /// </summary>
        /// <param name="node">The node.</param>
        private void Process_Namespace(dynamic node)
        {
            // Find or create the namespace (and its parents, if necessary)
            Namespace @namespace = this.Process_NamespaceReference(node.Name);

            // Map source location and node to object
            SourceLocationInfo location = new SourceLocationInfo(node, context);
            @namespace.AddMetaInfo(location);
            context.AddObject(node, @namespace);

            // Uri (optional)
            if (node.Uri != null)
            {
                if (@namespace.Uri != null)
                {
                    Error_NamespaceUri(location, @namespace);
                }
                else
                {
                    @namespace.Uri = node.Uri.Replace("\"", "");
                }
            }

            // Enter scope
            using (new NameContextScope(@namespace))
            {
                // Imports are not processed yet

                // Declarations (optional)
                if (node.Declarations != null)
                {
                    foreach (dynamic decl in node.Declarations)
                    {
                        this.Process(decl);
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Processes struct node.
        /// </summary>
        /// <param name="node">The node.</param>
        private void Process_StructType(dynamic node)
        {
            StructType structType = context.GetObject(node);

            // Namespace is processed already

            // Name is processed already

            // Fields (optional)
            if (node.Fields != null)
            {
                // Enter scope
                using (new NameContextScope(structType))
                {
                    foreach (dynamic field in node.Fields)
                    {
                        this.Process_StructField(field);
                    }
                }
            }

            // SuperType (optional)
            if (node.SuperType != null)
            {
                SourceLocationInfo location = new SourceLocationInfo(node.SuperType, context);
                try
                {
                    structType.SuperType = this.Process_NamespacedTypeReference(node.SuperType, typeof(StructType));
                }
                catch (NameNotFoundException exception)
                {
                    Error_NameNotFound(location, exception);
                }
                catch (NameCollisionException exception)
                {
                    Error_NameCollision(location, exception);
                }
            }
        }
Example #4
0
        private void Process_Operation(dynamic node)
        {
            Operation operation = new Operation();

            // Map source location and node to object
            operation.AddMetaInfo(new SourceLocationInfo(node, context));
            context.AddObject(node, operation);

            // Interface
            try
            {
                NameContext.Current.CheckName(node.Name, typeof(Operation));
                operation.Interface = (Interface)NameContext.Current.Scope;
            }
            catch (NameCollisionException exception)
            {
                Error_NameExists(operation, exception);
            }

            // Name (obligatory)
            operation.Name = node.Name;

            // ReturnType (obligatory)
            try
            {
                operation.ReturnType = this.Process_ReturnTypeReference(node.ReturnType);
            }
            catch (NameNotFoundException exception)
            {
                Error_NameNotFound(operation, exception);
            }
            catch (NameCollisionException exception)
            {
                Error_NameCollision(operation, exception);
            }

            // Enter scope
            using (new NameContextScope(operation))
            {
                // Parameters (optional)
                if (node.Parameters != null)
                {
                    foreach (dynamic param in node.Parameters)
                    {
                        this.Process_OperationParameter(param);
                    }
                }

                // Exceptions (optional)
                if (node.Exceptions != null)
                {
                    foreach (dynamic exc in node.Exceptions)
                    {
                        SourceLocationInfo location = new SourceLocationInfo(exc, context);
                        try
                        {
                            ExceptionType exceptionType = this.Process_NamespacedTypeReference(exc, typeof(ExceptionType));
                            if (operation.Exceptions.Contains(exceptionType))
                            {
                                Error_NameRedundant(location, typeof(ExceptionType), exceptionType.FullName);
                            }
                            else
                            {
                                operation.Exceptions.Add(exceptionType);
                            }
                        }
                        catch (NameNotFoundException exception)
                        {
                            Error_NameNotFound(location, exception);
                        }
                        catch (NameCollisionException exception)
                        {
                            Error_NameCollision(location, exception);
                        }
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// Processes namespace node.
        /// </summary>
        /// <param name="node">The node.</param>
        private void Process_Namespace(dynamic node)
        {
            // Find object
            Namespace @namespace = context.GetObject(node);

            // Uri is processed already

            // Enter scope
            using (new NameContextScope(@namespace))
            {
                // Imports (optional)
                if (node.Imports != null)
                {
                    foreach (dynamic import in node.Imports)
                    {
                        SourceLocationInfo location = new SourceLocationInfo(import, context);
                        try
                        {
                            Namespace importedNamespace = this.Process_NamespaceReference(import.Name);
                            if (!NameContext.Current.Imports.Add(importedNamespace))
                            {
                                Error_NamespaceImport(location, importedNamespace);
                            }
                        }
                        catch (NameNotFoundException exception)
                        {
                            Error_NameNotFound(location, exception);
                        }
                    }
                }

                // Declarations (optional)
                if (node.Declarations != null)
                {
                    foreach (dynamic decl in node.Declarations)
                    {
                        this.Process(decl);
                    }
                }
            }
        }
Example #6
0
        /// <summary>
        /// Processes interface node.
        /// </summary>
        /// <param name="node">The node.</param>
        private void Process_Interface(dynamic node)
        {
            Interface @interface = context.GetObject(node);

            // Namespace is processed already

            // Name is processed already

            // Version is processed already

            // Operations (optional)
            if (node.Operations != null)
            {
                // Enter scope
                using (new NameContextScope(@interface))
                {
                    foreach (dynamic op in node.Operations)
                    {
                        this.Process_Operation(op);
                    }
                }
            }

            // SuperInterfaces (optional)
            if (node.SuperInterfaces != null)
            {
                foreach (dynamic super in node.SuperInterfaces)
                {
                    SourceLocationInfo location = new SourceLocationInfo(super, context);
                    try
                    {
                        @interface.SuperInterfaces.Add(this.Process_NamespacedTypeReference(super, typeof(Interface)));
                    }
                    catch (NameNotFoundException exception)
                    {
                        Error_NameNotFound(location, exception);
                    }
                    catch (NameCollisionException exception)
                    {
                        Error_NameCollision(location, exception);
                    }
                }
            }
        }
Example #7
0
        /// <summary>
        /// Processes endpoint node.
        /// </summary>
        /// <param name="node">The node.</param>
        private void Process_Endpoint(dynamic node)
        {
            Endpoint endpoint = context.GetObject(node);

            // Namespace is processed already

            // Name is processed already

            // Interface (obligatory)
            SourceLocationInfo interfaceLocation = new SourceLocationInfo(node.Interface, context);
            try
            {
                endpoint.Interface = this.Process_NamespacedTypeReference(node.Interface, typeof(Interface));
            }
            catch (NameNotFoundException exception)
            {
                Error_NameNotFound(interfaceLocation, exception);
            }
            catch (NameCollisionException exception)
            {
                Error_NameCollision(interfaceLocation, exception);
            }

            // Binding (optional)
            if (node.Properties.Binding != null)
            {
                SourceLocationInfo bindingLocation = new SourceLocationInfo(node.Properties.Binding, context);
                try
                {
                    endpoint.Binding = this.Process_NamespacedTypeReference(node.Properties.Binding, typeof(Binding));
                }
                catch (NameNotFoundException exception)
                {
                    Error_NameNotFound(bindingLocation, exception);
                }
                catch (NameCollisionException exception)
                {
                    Error_NameCollision(bindingLocation, exception);
                }
            }

            // Authorization is not processed yet

            // Contract is not processed yet

            // Address is processed already
        }
Example #8
0
        /// <summary>
        /// Processes endpoint node.
        /// </summary>
        /// <param name="node">The node.</param>
        private void Process_Endpoint(dynamic node)
        {
            Endpoint endpoint = context.GetObject(node);

            // Namespace is processed already

            // Name is processed already

            // Interface is processed already

            // Binding is processed already

            // Authorization (optional)
            if (node.Properties.Authorization != null)
            {
                SourceLocationInfo authorizationLocation = new SourceLocationInfo(node.Properties.Authorization, context);
                try
                {
                    endpoint.Authorization = this.Process_NamespacedTypeReference(node.Properties.Authorization, typeof(Authorization));
                    if (endpoint.Authorization.Interface != endpoint.Interface)
                    {
                        if (endpoint.Authorization.Interface.GetSuperTypes().Contains(endpoint.Interface))
                        {
                            // Authorization's interface is stronger than endpoint's
                            Warning_InterfaceMismatch(authorizationLocation, typeof(Authorization));
                        } else if(endpoint.Interface.GetSuperTypes().Contains(endpoint.Authorization.Interface)) {
                            // Authorization's interface is weaker than endpoints's
                            Warning_InterfaceMismatch(authorizationLocation, typeof(Authorization));
                        }
                        else
                        {
                            // Authorization's interface does not match endpoint's
                            Error_InterfaceMismatch(authorizationLocation, typeof(Authorization));
                        }
                    }
                }
                catch (NameNotFoundException exception)
                {
                    Error_NameNotFound(authorizationLocation, exception);
                }
                catch (NameCollisionException exception)
                {
                    Error_NameCollision(authorizationLocation, exception);
                }
            }

            // Contract (optional)
            if (node.Properties.Contract != null)
            {
                SourceLocationInfo contractLocation = new SourceLocationInfo(node.Properties.Contract, context);
                try
                {
                    endpoint.Contract = this.Process_NamespacedTypeReference(node.Properties.Contract, typeof(Contract));
                    if (endpoint.Contract.Interface != endpoint.Interface)
                    {
                        if (endpoint.Contract.Interface.GetSuperTypes().Contains(endpoint.Interface))
                        {
                            // Contract's interface is stronger than endpoint's
                            Warning_InterfaceMismatch(contractLocation, typeof(Contract));
                        }
                        else if (endpoint.Interface.GetSuperTypes().Contains(endpoint.Contract.Interface))
                        {
                            // Contract's interface is weaker than endpoints's
                            Warning_InterfaceMismatch(contractLocation, typeof(Contract));
                        }
                        else
                        {
                            // Contract's interface does not match endpoint's
                            Error_InterfaceMismatch(contractLocation, typeof(Contract));
                        }
                    }
                }
                catch (NameNotFoundException exception)
                {
                    Error_NameNotFound(contractLocation, exception);
                }
                catch (NameCollisionException exception)
                {
                    Error_NameCollision(contractLocation, exception);
                }
            }

            // Address is processed already
        }