bool IDfirNodeVisitor <bool> .VisitStructFieldAccessorNode(StructFieldAccessorNode structFieldAccessorNode)
 {
     MarkFacadeVariableOfTerminalInterrupted(structFieldAccessorNode.StructInputTerminal);
     MarkTrueVariableOfTerminalConsumed(structFieldAccessorNode.StructInputTerminal);
     structFieldAccessorNode.OutputTerminals.ForEach(MarkFacadeVariableOfTerminalLive);
     return(true);
 }
Beispiel #2
0
        public void VisitStructFieldAccessor(StructFieldAccessor structFieldAccessor)
        {
            var structFieldAccessorDfir = new StructFieldAccessorNode(
                _currentDiagram,
                structFieldAccessor.FieldTerminals.Select(fieldTerminal => fieldTerminal.FieldName).ToArray());

            _map.AddMapping(structFieldAccessor, structFieldAccessorDfir);
            _map.MapTerminalsInOrder(structFieldAccessor, structFieldAccessorDfir);
        }
Beispiel #3
0
        public void StructConstructorIntoStructFieldAccessorWithNullFieldName_SetVariableTypes_VoidFieldVariableType()
        {
            DfirRoot function = DfirRoot.Create();
            var      structConstructorNode = new StructConstructorNode(function.BlockDiagram, StructType);

            ConnectConstantToInputTerminal(structConstructorNode.InputTerminals[0], NITypes.Int32, false);
            ConnectConstantToInputTerminal(structConstructorNode.InputTerminals[1], NITypes.Boolean, false);
            var structFieldAccessor = new StructFieldAccessorNode(function.BlockDiagram, new string[] { null });

            Wire.Create(function.BlockDiagram, structConstructorNode.OutputTerminals[0], structFieldAccessor.StructInputTerminal);

            RunSemanticAnalysisUpToSetVariableTypes(function);

            VariableReference fieldVariable = structFieldAccessor.OutputTerminals[0].GetTrueVariable();

            Assert.IsTrue(fieldVariable.Type.GetReferentType().IsVoid());
        }
 public bool VisitStructFieldAccessorNode(StructFieldAccessorNode structFieldAccessorNode)
 {
     ValidateRequiredInputTerminal(structFieldAccessorNode.StructInputTerminal);
     if (structFieldAccessorNode.StructInputTerminal.IsConnected)
     {
         NIType inputType = structFieldAccessorNode.StructInputTerminal.GetTrueVariable().Type.GetReferentType();
         if (!(inputType.IsValueClass() && inputType.GetFields().Any()))
         {
             structFieldAccessorNode.StructInputTerminal.SetDfirMessage(Messages.TypeIsNotStructType);
         }
     }
     foreach (Terminal outputTerminal in structFieldAccessorNode.OutputTerminals)
     {
         if (outputTerminal.GetTrueVariable().TypeVariableReference.IsOrContainsTypeVariable)
         {
             outputTerminal.SetDfirMessage(Messages.TypeNotDetermined);
         }
     }
     return(true);
 }
        public void StructConstructorIntoStructFieldAccessor_Execute_FieldValuesAccessed()
        {
            DfirRoot function = DfirRoot.Create();
            var      structConstructorNode = new StructConstructorNode(function.BlockDiagram, StructType);

            ConnectConstantToInputTerminal(structConstructorNode.InputTerminals[0], NITypes.Int32, 5, false);
            ConnectConstantToInputTerminal(structConstructorNode.InputTerminals[1], NITypes.Boolean, true, false);
            var structFieldAccessor = new StructFieldAccessorNode(function.BlockDiagram, new string[] { "_0", "_1" });

            Wire.Create(function.BlockDiagram, structConstructorNode.OutputTerminals[0], structFieldAccessor.StructInputTerminal);
            FunctionalNode inspect0 = ConnectInspectToOutputTerminal(structFieldAccessor.OutputTerminals[0]);
            FunctionalNode inspect1 = ConnectInspectToOutputTerminal(structFieldAccessor.OutputTerminals[1]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect0);
            AssertByteArrayIsInt32(inspectValue, 5);
            inspectValue = executionInstance.GetLastValueFromInspectNode(inspect1);
            AssertByteArrayIsBoolean(inspectValue, true);
        }
        bool IDfirNodeVisitor <bool> .VisitStructFieldAccessorNode(StructFieldAccessorNode structFieldAccessorNode)
        {
            TypeVariableReference mutabilityType = _typeVariableSet.CreateReferenceToMutabilityType();
            var lifetimeVariableGroup            = LifetimeTypeVariableGroup.CreateFromNode(structFieldAccessorNode);
            ReferenceInputTerminalLifetimeGroup inputTerminalGroup = CreateTerminalLifetimeGroup(
                InputReferenceMutability.Polymorphic,
                lifetimeVariableGroup);

            var fieldTypes = new Dictionary <string, TypeVariableReference>();

            foreach (var terminalPair in structFieldAccessorNode.OutputTerminals.Zip(structFieldAccessorNode.FieldNames))
            {
                string fieldName = terminalPair.Value;
                TypeVariableReference fieldType;
                if (string.IsNullOrEmpty(fieldName))
                {
                    fieldType = _typeVariableSet.CreateReferenceToNewTypeVariable();
                }
                else if (!fieldTypes.TryGetValue(fieldName, out fieldType))
                {
                    fieldType             = _typeVariableSet.CreateReferenceToNewTypeVariable();
                    fieldTypes[fieldName] = fieldType;
                }
                TypeVariableReference terminalTypeVariable = _typeVariableSet.CreateReferenceToPolymorphicReferenceType(
                    mutabilityType,
                    fieldType,
                    inputTerminalGroup.LifetimeType);
                Terminal outputTerminal = terminalPair.Key;
                _nodeFacade[outputTerminal] = new SimpleTerminalFacade(outputTerminal, terminalTypeVariable);
            }

            TypeVariableReference fieldedType = _typeVariableSet.CreateReferenceToIndefiniteFieldedType(fieldTypes);

            inputTerminalGroup.AddTerminalFacade(
                structFieldAccessorNode.StructInputTerminal,
                fieldedType,
                mutabilityType);

            return(true);
        }
 bool IDfirNodeVisitor <bool> .VisitStructFieldAccessorNode(StructFieldAccessorNode structFieldAccessorNode)
 {
     structFieldAccessorNode.UnifyNodeInputTerminalTypes(_typeUnificationResults);
     return(true);
 }