Esempio n. 1
0
        public static DataTypeCollection <IDataType> CreateBuildInTypes()
        {
            DataTypeCollection <IDataType> types = new DataTypeCollection <IDataType>();
            DataType item  = new PrimitiveType("TOD", AdsDatatypeId.ADST_BIGTYPE, 4, PrimitiveTypeFlags.Time, typeof(TOD));
            DataType type2 = new PrimitiveType("DT", AdsDatatypeId.ADST_BIGTYPE, 4, PrimitiveTypeFlags.MaskDateTime, typeof(DT));
            DataType type3 = new PrimitiveType("UDINT", AdsDatatypeId.ADST_UINT32, 4, PrimitiveTypeFlags.Unsigned, typeof(uint));

            types.Add(new BitMappingType("BIT", 1, typeof(bool)));
            types.Add(new BitMappingType("BIT2", 2, typeof(byte)));
            types.Add(new BitMappingType("BIT3", 3, typeof(byte)));
            types.Add(new BitMappingType("BIT4", 4, typeof(byte)));
            types.Add(new BitMappingType("BIT5", 5, typeof(byte)));
            types.Add(new BitMappingType("BIT6", 6, typeof(byte)));
            types.Add(new BitMappingType("BIT7", 7, typeof(byte)));
            types.Add(new BitMappingType("BIT8", 8, typeof(byte)));
            types.Add(new PrimitiveType("VOID", AdsDatatypeId.ADST_VOID, 0, PrimitiveTypeFlags.None, typeof(void)));
            PointerType type4 = new PointerType("POINTER TO VOID", "VOID");

            types.Add(type4);
            AliasType type5 = new AliasType("PVOID", type4);

            types.Add(type5);
            types.Add(new PrimitiveType("SINT", AdsDatatypeId.ADST_INT8, 1, PrimitiveTypeFlags.Numeric, typeof(sbyte)));
            types.Add(new PrimitiveType("USINT", AdsDatatypeId.ADST_UINT8, 1, PrimitiveTypeFlags.MaskNumericUnsigned, typeof(byte)));
            types.Add(new PrimitiveType("BYTE", AdsDatatypeId.ADST_UINT8, 1, PrimitiveTypeFlags.Unsigned | PrimitiveTypeFlags.System, typeof(byte)));
            types.Add(new PrimitiveType("UINT8", AdsDatatypeId.ADST_UINT8, 1, PrimitiveTypeFlags.MaskNumericUnsigned, typeof(byte)));
            types.Add(new PrimitiveType("INT", AdsDatatypeId.ADST_INT16, 2, PrimitiveTypeFlags.Numeric, typeof(short)));
            types.Add(new PrimitiveType("INT16", AdsDatatypeId.ADST_INT16, 2, PrimitiveTypeFlags.Numeric, typeof(short)));
            types.Add(new PrimitiveType("UINT", AdsDatatypeId.ADST_UINT16, 2, PrimitiveTypeFlags.MaskNumericUnsigned, typeof(ushort)));
            types.Add(new PrimitiveType("WORD", AdsDatatypeId.ADST_UINT16, 2, PrimitiveTypeFlags.Unsigned | PrimitiveTypeFlags.System, typeof(ushort)));
            types.Add(new PrimitiveType("UINT16", AdsDatatypeId.ADST_UINT16, 2, PrimitiveTypeFlags.MaskNumericUnsigned, typeof(ushort)));
            types.Add(new PrimitiveType("DINT", AdsDatatypeId.ADST_INT32, 4, PrimitiveTypeFlags.Numeric, typeof(int)));
            types.Add(new PrimitiveType("INT32", AdsDatatypeId.ADST_INT32, 4, PrimitiveTypeFlags.Numeric, typeof(int)));
            types.Add(type3);
            types.Add(new PrimitiveType("UINT32", AdsDatatypeId.ADST_UINT32, 4, PrimitiveTypeFlags.Numeric, typeof(uint)));
            types.Add(new PrimitiveType("DWORD", AdsDatatypeId.ADST_UINT32, 4, PrimitiveTypeFlags.MaskNumericUnsigned, typeof(uint)));
            types.Add(new PrimitiveType("REAL", AdsDatatypeId.ADST_REAL32, 4, PrimitiveTypeFlags.Numeric | PrimitiveTypeFlags.Float, typeof(float)));
            types.Add(new PrimitiveType("FLOAT", AdsDatatypeId.ADST_REAL32, 4, PrimitiveTypeFlags.Numeric | PrimitiveTypeFlags.Float, typeof(float)));
            types.Add(new PrimitiveType("LREAL", AdsDatatypeId.ADST_REAL64, 8, PrimitiveTypeFlags.Numeric | PrimitiveTypeFlags.Float, typeof(double)));
            types.Add(new PrimitiveType("DOUBLE", AdsDatatypeId.ADST_REAL64, 8, PrimitiveTypeFlags.Numeric | PrimitiveTypeFlags.Float, typeof(double)));
            types.Add(new PrimitiveType("BOOL", AdsDatatypeId.ADST_BIT, 1, PrimitiveTypeFlags.System, typeof(bool)));
            types.Add(new PrimitiveType("TIME", AdsDatatypeId.ADST_BIGTYPE, 4, PrimitiveTypeFlags.Time, typeof(TIME)));
            types.Add(item);
            types.Add(new PrimitiveType("DATE", AdsDatatypeId.ADST_BIGTYPE, 4, PrimitiveTypeFlags.Date, typeof(DATE)));
            types.Add(type2);
            types.Add(new PrimitiveType("LTIME", AdsDatatypeId.ADST_BIGTYPE, 8, PrimitiveTypeFlags.System, typeof(LTIME)));
            types.Add(new AliasType("DATE_AND_TIME", type2));
            types.Add(new AliasType("TIME_OF_DAY", item));
            types.Add(new PrimitiveType("LINT", AdsDatatypeId.ADST_INT64, 8, PrimitiveTypeFlags.Numeric, typeof(long)));
            types.Add(new PrimitiveType("ULINT", AdsDatatypeId.ADST_UINT64, 8, PrimitiveTypeFlags.MaskNumericUnsigned, typeof(ulong)));
            types.Add(new PrimitiveType("LWORD", AdsDatatypeId.ADST_UINT64, 8, PrimitiveTypeFlags.Numeric, typeof(ulong)));
            types.Add(new AliasType("OTCID", type3));
            types.Add(new AliasType("UXINT", type5));
            return(types);
        }
Esempio n. 2
0
        private void expandDataType(IDataType type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            DataTypeCategory category = type.Category;

            if (category > DataTypeCategory.Array)
            {
                if (category == DataTypeCategory.Pointer)
                {
                    DataType referencedType = (DataType)((PointerType)type).ReferencedType;
                    if (referencedType != null)
                    {
                        this.expandDataType(referencedType);
                    }
                }
                else if (category == DataTypeCategory.Reference)
                {
                    DataType referencedType = (DataType)((ReferenceType)type).ReferencedType;
                    if (referencedType != null)
                    {
                        this.expandDataType(referencedType);
                    }
                }
            }
            else if (category != DataTypeCategory.Alias)
            {
                if (category == DataTypeCategory.Array)
                {
                    DataType elementType = (DataType)((ArrayType)type).ElementType;
                    if (elementType != null)
                    {
                        this.expandDataType(elementType);
                    }
                }
            }
            else
            {
                AliasType type2    = (AliasType)type;
                DataType  baseType = (DataType)type2.BaseType;
                if (baseType != null)
                {
                    this.expandDataType(baseType);
                }
                if ((type2.Size <= 0) && (baseType != null))
                {
                    type2.SetSize(baseType.Size, baseType.ManagedType);
                }
            }
        }
Esempio n. 3
0
        protected override ISymbol OnCreateReference(IPointerType type, ISymbol parent)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            int      fieldOffset    = 0;
            ISymbol  symbol2        = null;
            DataType referencedType = (DataType)type.ReferencedType;
            bool     flag           = (referencedType.Flags & AdsDataTypeFlags.AnySizeArray) == AdsDataTypeFlags.AnySizeArray;
            bool     flag2          = (((Symbol)parent).MemberFlags & AdsDataTypeFlags.AnySizeArray) == AdsDataTypeFlags.AnySizeArray;

            if ((referencedType == null) || ((referencedType.Size == 0) && !flag2))
            {
                return(null);
            }
            string instanceName = parent.InstanceName;
            bool   isBitType    = type.ReferencedType.IsBitType;

            if (((DataType)parent.DataType).ResolveType(DataTypeResolveStrategy.AliasReference).IsPointer)
            {
                instanceName = instanceName + "^";
            }
            if (referencedType.Category == DataTypeCategory.Struct)
            {
                StructType type3 = (StructType)referencedType;
                symbol2 = !type3.HasRpcMethods ? new StructInstance(parent, type3, instanceName, fieldOffset) : new RpcStructInstance(parent, type3, instanceName, fieldOffset);
            }
            else if (referencedType.Category == DataTypeCategory.Array)
            {
                symbol2 = !flag2 ? new ArrayInstance(parent, (ArrayType)referencedType, instanceName, fieldOffset) : new AnySizeArrayInstance(parent, (ArrayType)referencedType, instanceName, fieldOffset);
            }
            else if (referencedType.Category == DataTypeCategory.Reference)
            {
                symbol2 = new ReferenceInstance(parent, (ReferenceType)referencedType, instanceName, fieldOffset);
            }
            else if (referencedType.Category == DataTypeCategory.Pointer)
            {
                symbol2 = new PointerInstance(parent, (PointerType)referencedType, instanceName, fieldOffset);
            }
            else if (referencedType.Category == DataTypeCategory.Alias)
            {
                AliasType type4 = (AliasType)referencedType;
                DataType  type5 = (DataType)type4.ResolveType(DataTypeResolveStrategy.Alias);
                symbol2 = new AliasInstance(parent, type4, instanceName, fieldOffset);
            }
            else if (referencedType.Category == DataTypeCategory.Union)
            {
                symbol2 = new UnionInstance(parent, (UnionType)referencedType, instanceName, fieldOffset);
            }
            else if (referencedType.Category == DataTypeCategory.String)
            {
                symbol2 = new StringInstance(parent, (IStringType)referencedType, instanceName, fieldOffset);
            }
            else
            {
                if (referencedType.Category == DataTypeCategory.Union)
                {
                    Module.Trace.TraceError("Unions not supported yet!");
                }
                symbol2 = new Symbol(parent, referencedType, instanceName, fieldOffset, ((ISymbolFactoryServicesProvider)parent).FactoryServices);
            }
            return(symbol2);
        }
Esempio n. 4
0
        private Symbol createArrayElement(int[] currentIndex, bool oversample, ISymbol parent, ArrayType arrType, DataType elementType)
        {
            bool             flag    = true;
            DataTypeCategory unknown = DataTypeCategory.Unknown;

            if (elementType != null)
            {
                unknown = elementType.Category;
            }
            Symbol symbol = null;

            if (unknown == DataTypeCategory.Bitset)
            {
                symbol = new Symbol(currentIndex, oversample, parent);
            }
            else if (unknown == DataTypeCategory.Primitive)
            {
                symbol = new Symbol(currentIndex, oversample, parent);
            }
            else if (unknown == DataTypeCategory.Array)
            {
                symbol = !arrType.IsOversampled ? new ArrayInstance(currentIndex, false, parent) : new OversamplingArrayInstance(currentIndex, oversample, parent);
            }
            else if (unknown == DataTypeCategory.Struct)
            {
                symbol = !((IStructType)elementType).HasRpcMethods ? new StructInstance(currentIndex, oversample, parent) : new RpcStructInstance(currentIndex, oversample, parent);
            }
            else if (unknown == DataTypeCategory.Union)
            {
                symbol = new UnionInstance(currentIndex, oversample, parent);
            }
            else if (unknown == DataTypeCategory.Reference)
            {
                symbol = new ReferenceInstance(currentIndex, oversample, parent);
            }
            else if (unknown == DataTypeCategory.Pointer)
            {
                symbol = new PointerInstance(currentIndex, oversample, parent);
            }
            else if (unknown == DataTypeCategory.Union)
            {
                symbol = new Symbol(currentIndex, oversample, parent);
            }
            else if (unknown == DataTypeCategory.Enum)
            {
                symbol = new Symbol(currentIndex, oversample, parent);
            }
            else if (unknown == DataTypeCategory.Alias)
            {
                AliasType type3 = (AliasType)elementType;
                symbol = new AliasInstance(currentIndex, oversample, parent);
            }
            else if (unknown != DataTypeCategory.String)
            {
                symbol = new Symbol(currentIndex, oversample, parent);
            }
            else
            {
                IStringType type4 = (IStringType)elementType;
                symbol = new StringInstance(currentIndex, oversample, parent);
            }
            if (flag)
            {
                symbol.SetComment(parent.Comment);
            }
            return(symbol);
        }
Esempio n. 5
0
        public static void ParseTypes(AdsStream dataTypeStream, Encoding encoding, IBinder binder, bool buildInTypesInStream, DataTypeCollection <IDataType> buildInTypes)
        {
            AdsBinaryReader reader         = new AdsBinaryReader(dataTypeStream);
            string          referencedType = null;

            while (dataTypeStream.Position < dataTypeStream.Length)
            {
                AdsDataTypeEntry entry = new AdsDataTypeEntry(true, encoding, reader);
                try
                {
                    IDataType type  = null;
                    bool      flag1 = buildInTypes.TryGetType(entry.entryName, out type);
                    DataType  type2 = (DataType)type;
                    if (buildInTypesInStream && flag1)
                    {
                        continue;
                    }
                    DataType type3  = null;
                    int      length = 0;
                    if (DataTypeStringParser.TryParseReference(entry.entryName, out referencedType))
                    {
                        type3 = new ReferenceType(entry, referencedType);
                    }
                    else if (DataTypeStringParser.TryParsePointer(entry.entryName, out referencedType))
                    {
                        type3 = new PointerType(entry, referencedType);
                    }
                    else
                    {
                        bool flag2;
                        if (DataTypeStringParser.TryParseString(entry.entryName, out length, out flag2))
                        {
                            type3 = !flag2 ? ((DataType) new StringType(length)) : ((DataType) new WStringType(length));
                        }
                        else if (entry.methodCount > 0)
                        {
                            type3 = new RpcStructType(entry);
                        }
                        else if (entry.subItems > 0)
                        {
                            bool flag3 = false;
                            bool flag4 = false;
                            if (entry.subItems > 1)
                            {
                                int             num2       = 0;
                                AdsFieldEntry[] subEntries = entry.subEntries;
                                int             index      = 0;
                                while (true)
                                {
                                    if (index >= subEntries.Length)
                                    {
                                        flag3 = entry.BitSize < num2;
                                        break;
                                    }
                                    AdsFieldEntry entry2 = subEntries[index];
                                    if (!entry2.IsStatic && !entry2.IsProperty)
                                    {
                                        int num4 = 0;
                                        num4   = !entry2.IsBitType ? (entry2.Offset * 8) : entry2.Offset;
                                        flag4 |= num4 < num2;
                                        num2  += entry2.BitSize;
                                    }
                                    index++;
                                }
                            }
                            type3 = !flag3 ? ((DataType) new StructType(entry)) : ((DataType) new UnionType(entry));
                        }
                        else if (entry.arrayDim > 0)
                        {
                            type3 = new ArrayType(entry);
                        }
                        else if (entry.enumInfoCount <= 0)
                        {
                            if (DataTypeStringParser.TryParseSubRange(entry.entryName, out referencedType))
                            {
                                type3 = (DataType)SubRangeTypeFactory.Create(entry, binder);
                            }
                            else if (((entry.baseTypeId > AdsDatatypeId.ADST_VOID) && (entry.typeName != null)) && (entry.typeName != string.Empty))
                            {
                                type3 = new AliasType(entry);
                            }
                            else
                            {
                                DataTypeCategory cat = CategoryConverter.FromId(entry.DataTypeId);
                                if (cat != DataTypeCategory.Unknown)
                                {
                                    Type tp = null;
                                    if (PrimitiveTypeConverter.TryGetManagedType(entry.DataTypeId, out tp))
                                    {
                                        if (cat == DataTypeCategory.Primitive)
                                        {
                                            type3 = new PrimitiveType(entry, PrimitiveTypeConverter.GetPrimitiveFlags(entry.DataTypeId), tp);
                                        }
                                        else if (cat == DataTypeCategory.String)
                                        {
                                            type3 = new StringType(entry);
                                        }
                                    }
                                }
                                if (type3 == null)
                                {
                                    type3 = new DataType(cat, entry);
                                }
                            }
                        }
                        else
                        {
                            AdsDatatypeId baseTypeId = entry.baseTypeId;
                            if (baseTypeId == AdsDatatypeId.ADST_INT16)
                            {
                                type3 = new EnumType <short>(entry);
                            }
                            else if (baseTypeId == AdsDatatypeId.ADST_INT32)
                            {
                                type3 = new EnumType <int>(entry);
                            }
                            else
                            {
                                switch (baseTypeId)
                                {
                                case AdsDatatypeId.ADST_INT8:
                                    type3 = new EnumType <sbyte>(entry);
                                    break;

                                case AdsDatatypeId.ADST_UINT8:
                                    type3 = new EnumType <byte>(entry);
                                    break;

                                case AdsDatatypeId.ADST_UINT16:
                                    type3 = new EnumType <ushort>(entry);
                                    break;

                                case AdsDatatypeId.ADST_UINT32:
                                    type3 = new EnumType <uint>(entry);
                                    break;

                                case AdsDatatypeId.ADST_INT64:
                                    type3 = new EnumType <long>(entry);
                                    break;

                                case AdsDatatypeId.ADST_UINT64:
                                    type3 = new EnumType <ulong>(entry);
                                    break;

                                default:
                                    throw new AdsException("Enum base type mismatch!");
                                }
                            }
                        }
                    }
                    binder.RegisterType(type3);
                }
                catch (Exception exception)
                {
                    Module.Trace.TraceWarning($"Cannot parse DataTypeEntry. Skipping dataType '{entry.entryName}'!", exception);
                }
            }
        }