Пример #1
0
        public IArrayType UpdateDynamicType()
        {
            int       elementCount = this.readArraySize();
            ArrayType dataType     = (ArrayType)base.DataType;
            ReadOnlyDimensionCollection dimensions = dataType.Dimensions;
            DimensionCollection         dims       = new DimensionCollection();

            for (int i = 0; i < dimensions.Count; i++)
            {
                Dimension item = null;
                item = (i != 0) ? new Dimension(dimensions[i].LowerBound, dimensions[i].ElementCount) : new Dimension(dimensions[i].LowerBound, elementCount);
                dims.Add(item);
            }
            ArrayType type2 = new ArrayType(dataType.Name, (DataType)dataType.ElementType, dims, AdsDataTypeFlags.AnySizeArray | AdsDataTypeFlags.DataType);

            base.resolvedDataType = type2;
            return(type2);
        }
Пример #2
0
            private int calcElementBaseSize(TcAdsSymbolInfo parentArrayInstance)
            {
                TcAdsDataType type      = (TcAdsDataType)parentArrayInstance.DataType.ResolveType(DataTypeResolveStrategy.AliasReference);
                int           size      = type.Size;
                bool          isBitType = parentArrayInstance.IsBitType;
                ReadOnlyDimensionCollection dimensions = type.Dimensions;

                for (int i = type.Dimensions.Count - 1; i >= 0; i--)
                {
                    if (isBitType)
                    {
                        size = 1;
                    }
                    else if (dimensions[i].ElementCount > 0)
                    {
                        size /= dimensions[i].ElementCount;
                    }
                }
                return(size);
            }
Пример #3
0
            internal TcAdsSymbolInfo CreateArrayElement(TcAdsSymbolInfo parentArrayInstance, TcAdsDataType parentArrayType, int subIndex)
            {
                if (parentArrayInstance == null)
                {
                    throw new ArgumentNullException("arrayInstance");
                }
                if (parentArrayType == null)
                {
                    throw new ArgumentNullException("parentArrayType");
                }
                TcAdsSymbolInfo info     = null;
                ITcAdsDataType  baseType = parentArrayType.BaseType;

                if (baseType == null)
                {
                    DataTypeException innerException = new DataTypeException("Base type of Array '{0}' not defined!", parentArrayType);
                    throw new AdsSymbolException("Cannot create array element!", parentArrayInstance, innerException);
                }
                bool isBitType = parentArrayInstance.IsBitType;
                ReadOnlyDimensionCollection dimensions = parentArrayType.Dimensions;
                int elementSize = this.calcElementBaseSize(parentArrayInstance);

                if (subIndex < parentArrayType.Dimensions.ElementCount)
                {
                    info = new TcAdsSymbolInfo(this._parser, parentArrayInstance, subIndex)
                    {
                        size           = (uint)elementSize,
                        typeEntryFlags = this.createElementTypeEntryFlags(parentArrayInstance, (TcAdsDataType)baseType),
                        flags          = this.createElementSymbolFlags(parentArrayInstance, (TcAdsDataType)baseType),
                        dataTypeId     = (baseType == null) ? AdsDatatypeId.ADST_BIGTYPE : baseType.DataTypeId
                    };
                    if (baseType != null)
                    {
                        info.typeName  = baseType.Name;
                        info.arrayInfo = baseType.Dimensions.ToArray();
                    }
                    else
                    {
                        info.typeName  = parentArrayType.BaseTypeName;
                        info.arrayInfo = null;
                    }
                    info.comment = parentArrayInstance.Comment;
                    this.calcArrayElementIndexGroupIndexOffset(subIndex, parentArrayInstance, elementSize, out info.indexGroup, out info.indexOffset);
                    string str = ArrayIndexConverter.SubIndexToIndexString(parentArrayType.Dimensions.LowerBounds, parentArrayType.Dimensions.UpperBounds, subIndex);
                    info.instancePath = parentArrayInstance.instancePath + str;
                    info.shortName    = parentArrayInstance.shortName + str;
                    info.attributes   = parentArrayInstance.attributes;
                }
                if ((subIndex == parentArrayType.Dimensions.ElementCount) && ((parentArrayType.Flags & (AdsDataTypeFlags.None | AdsDataTypeFlags.Oversample)) != AdsDataTypeFlags.None))
                {
                    info = new TcAdsSymbolInfo(this._parser, parentArrayInstance, subIndex)
                    {
                        size           = (uint)elementSize,
                        typeEntryFlags = this.createElementTypeEntryFlags(parentArrayInstance, (TcAdsDataType)baseType),
                        flags          = this.createElementSymbolFlags(parentArrayInstance, (TcAdsDataType)baseType)
                    };
                    if (info.typeEntryFlags.HasFlag(AdsDataTypeFlags.None | AdsDataTypeFlags.Static))
                    {
                        info.indexGroup  = 0xf019;
                        info.indexOffset = 0;
                    }
                    else
                    {
                        info.indexGroup  = parentArrayInstance.indexGroup;
                        info.indexOffset = parentArrayInstance.indexOffset;
                    }
                    if (baseType != null)
                    {
                        info.dataTypeId = baseType.DataTypeId;
                        info.typeName   = baseType.Name;
                    }
                    else
                    {
                        info.dataTypeId = AdsDatatypeId.ADST_BIGTYPE;
                        info.typeName   = parentArrayType.BaseTypeName;
                    }
                    info.comment = parentArrayInstance.Comment;
                    string str2 = ArrayIndexConverter.OversamplingSubElementToString(subIndex);
                    info.instancePath = parentArrayInstance.instancePath + str2;
                    info.shortName    = parentArrayInstance.shortName + str2;
                    if ((parentArrayType.Flags & (AdsDataTypeFlags.None | AdsDataTypeFlags.PropItem)) == (AdsDataTypeFlags.None | AdsDataTypeFlags.PropItem))
                    {
                        info.indexGroup  = 0xf017;
                        info.indexOffset = parentArrayType.TypeHashValue;
                    }
                    info.attributes = parentArrayInstance.attributes;
                }
                return(info);
            }
Пример #4
0
        public int GetSubSymbolCount(TcAdsSymbolInfo parent)
        {
            int num2;

            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            int count = 0;

            try
            {
                ITcAdsDataType type           = parent.ResolveType(DataTypeResolveStrategy.AliasReference);
                string         referencedType = null;
                if (!parent.TryGetReference(out referencedType))
                {
                    if (!parent.TryGetPointerRef(out referencedType))
                    {
                        if (((type != null) && (type.SubItems != null)) && (type.SubItems.Count > 0))
                        {
                            count = type.SubItems.Count;
                        }
                        else if (((type != null) && (type.Dimensions != null)) && (type.Dimensions.Count > 0))
                        {
                            ReadOnlyDimensionCollection dimensions = type.Dimensions;
                            if (dimensions != null)
                            {
                                count = 1;
                                int num3 = type.Dimensions.Count - 1;
                                while (true)
                                {
                                    if (num3 < 0)
                                    {
                                        if (parent.IsOversamplingArray)
                                        {
                                            count++;
                                        }
                                        break;
                                    }
                                    count *= dimensions[num3].ElementCount;
                                    num3--;
                                }
                            }
                            else
                            {
                                return(0);
                            }
                        }
                    }
                    else
                    {
                        this.SetPlatformPointerSize(parent.Size);
                        ITcAdsDataType typeByName = this.GetTypeByName(referencedType);
                        if (typeByName != null)
                        {
                            count = ((parent.typeEntryFlags & AdsDataTypeFlags.AnySizeArray) != AdsDataTypeFlags.AnySizeArray) ? ((typeByName.Size > 0) ? 1 : 0) : 1;
                        }
                        else
                        {
                            object[] args = new object[] { referencedType };
                            Module.Trace.TraceWarning("Cannot get referenced type '{0}'!", args);
                        }
                    }
                }
                else
                {
                    this.SetPlatformPointerSize(parent.Size);
                    ITcAdsDataType typeByName = this.GetTypeByName(referencedType);
                    count = (typeByName == null) ? 0 : typeByName.SubItems.Count;
                }
                return(count);
            }
            catch (Exception exception)
            {
                Module.Trace.TraceError($"SymbolParent: {parent.ToString()}", exception);
                throw;
            }
            return(num2);
        }
Пример #5
0
        private TcAdsSymbolInfo GetSubSymbol(TcAdsSymbolInfo symbol, string symbolName, int pos)
        {
            TcAdsSymbolInfo parent = null;

            if (symbol.DataType == null)
            {
                symbol.dataType = this.GetTypeByName(symbol.typeName);
            }
            if (symbol.DataType != null)
            {
                ITcAdsDataType type = symbol.ResolveType(DataTypeResolveStrategy.AliasReference);
                if (type.SubItems.Count > 0)
                {
                    string str    = symbolName;
                    char[] anyOf  = new char[] { '.', '[' };
                    int    length = str.IndexOfAny(anyOf, pos + 1);
                    if (length != -1)
                    {
                        str = str.Substring(0, length);
                    }
                    bool flag = str[str.Length - 1] == '^';
                    if (flag)
                    {
                        str = str.Substring(0, str.Length - 1);
                    }
                    for (int i = 0; i < type.SubItems.Count; i++)
                    {
                        parent = this.GetSubSymbol(symbol, i, true);
                        if (parent.instancePath.Equals(str, StringComparison.OrdinalIgnoreCase))
                        {
                            if ((parent != null) & flag)
                            {
                                parent = this.GetSubSymbol(parent, 0, true);
                            }
                            if (length != -1)
                            {
                                parent = this.GetSubSymbol(parent, symbolName, length);
                            }
                            return(parent);
                        }
                    }
                    return(null);
                }
                if (type.Dimensions.Count > 0)
                {
                    SymbolParser.ArrayIndexType type2;
                    IList <int[]> jaggedIndices = null;
                    int           index         = symbolName.IndexOf(']', pos + 1);
                    if (index == -1)
                    {
                        return(null);
                    }
                    int length = symbol.instancePath.Length;
                    if (!SymbolParser.TryParseIndices(symbolName.Substring(length, (index + 1) - length), out jaggedIndices, out type2))
                    {
                        goto TR_0013;
                    }
                    else if (jaggedIndices.Count <= 1)
                    {
                        ReadOnlyDimensionCollection dimensions = type.Dimensions;
                        bool flag3 = type2 == SymbolParser.ArrayIndexType.Oversample;
                        if (ArrayIndexConverter.TryCheckIndices(jaggedIndices, type))
                        {
                            int subIndex = -1;
                            if (ArrayIndexConverter.TryGetSubIndex(jaggedIndices[0], dimensions.LowerBounds, dimensions.UpperBounds, type2 == SymbolParser.ArrayIndexType.Oversample, out subIndex))
                            {
                                parent = this.GetSubSymbol(symbol, subIndex, true);
                                if ((parent != null) && (symbolName.Length > (index + 1)))
                                {
                                    parent = this.GetSubSymbol(parent, symbolName, index + 1);
                                }
                            }
                        }
                    }
                    else
                    {
                        goto TR_0013;
                    }
                }
            }
            return(parent);

TR_0013:
            return(null);
        }