public bool TestUnderlyingType(Func <NIType, bool> underlyingTypePredicate, NIType expectedTypeExample)
        {
            if (!_terminalHasType)
            {
                return(false);
            }
            NIType underlyingType = _facadeVariable.Type.GetTypeOrReferentType();

            if (!underlyingTypePredicate(underlyingType))
            {
                _terminal.SetDfirMessage(TerminalUserMessages.CreateTypeConflictMessage(underlyingType, expectedTypeExample));
                return(false);
            }
            return(true);
        }
        public bool TestExpectedUnderlyingType(NIType expectedType)
        {
            if (!_terminalHasType)
            {
                return(false);
            }
            NIType underlyingType = _facadeVariable.Type.GetTypeOrReferentType();

            if (underlyingType != expectedType)
            {
                _terminal.SetDfirMessage(TerminalUserMessages.CreateTypeConflictMessage(underlyingType, expectedType));
                return(false);
            }
            return(true);
        }
        public void SetMessagesOnTerminal(Terminal terminal)
        {
            TerminalUnificationResult unificationResult;

            if (!_unificationResults.TryGetValue(terminal, out unificationResult))
            {
                return;
            }

            if (unificationResult.TypeMismatch)
            {
                NIType expectedType = unificationResult.UnifyWith.RenderNIType();
                NIType actualType   = unificationResult.TerminalTypeVariable.RenderNIType();
                terminal.SetDfirMessage(TerminalUserMessages.CreateTypeConflictMessage(actualType, expectedType));
            }
            if (unificationResult.ExpectedMutable)
            {
                terminal.SetDfirMessage(Messages.TerminalDoesNotAcceptImmutableType);
            }
            if (unificationResult.FailedConstraints != null)
            {
                foreach (var failedConstraint in unificationResult.FailedConstraints)
                {
                    var traitConstraint = failedConstraint as TraitConstraint;
                    if (traitConstraint != null)
                    {
                        if (traitConstraint.TraitName == "Copy" && terminal.ParentNode is Wire)
                        {
                            terminal.ParentNode.SetDfirMessage(Messages.WireCannotFork);
                        }
                        else
                        {
                            terminal.SetDfirMessage(Messages.CreateTypeDoesNotHaveRequiredTraitMessage(((TraitConstraint)failedConstraint).TraitName));
                        }
                    }
                    else if (failedConstraint is OutlastsLifetimeGraphConstraint)
                    {
                        terminal.SetDfirMessage(Messages.WiredReferenceDoesNotLiveLongEnough);
                    }
                    else
                    {
                        throw new NotSupportedException("Don't know how to set a terminal DfirMessage for failed constraint " + failedConstraint.GetType().Name);
                    }
                }
            }
        }
Beispiel #4
0
        public void SetMessagesOnTerminal(Terminal terminal)
        {
            TerminalUnificationResult unificationResult;

            if (!_unificationResults.TryGetValue(terminal, out unificationResult))
            {
                return;
            }

            if (unificationResult.TypeMismatch)
            {
                NIType expectedType = unificationResult.UnifyWith.RenderNIType();
                NIType actualType   = unificationResult.TerminalTypeVariable.RenderNIType();
                terminal.SetDfirMessage(TerminalUserMessages.CreateTypeConflictMessage(actualType, expectedType));
            }
            if (unificationResult.ExpectedMutable)
            {
                terminal.SetDfirMessage(Messages.TerminalDoesNotAcceptImmutableType);
            }
            if (unificationResult.FailedConstraints != null)
            {
                if (unificationResult.FailedConstraints.OfType <CopyConstraint>().Any())
                {
                    terminal.ParentNode.SetDfirMessage(Messages.WireCannotFork);
                }
                if (unificationResult.FailedConstraints.OfType <OutlastsLifetimeGraphConstraint>().Any())
                {
                    terminal.SetDfirMessage(Messages.WiredReferenceDoesNotLiveLongEnough);
                }
                if (unificationResult.FailedConstraints.OfType <DisplayTraitConstraint>().Any() ||
                    unificationResult.FailedConstraints.OfType <IteratorTraitConstraint>().Any())
                {
                    // TODO: customize message with name of missing trait
                    terminal.SetDfirMessage(Messages.TypeDoesNotHaveRequiredTrait);
                }
            }
        }